:root {
  --ink: #16202b;
  --muted: #6b7a89;
  --line: #dde4ea;
  --bg: #f6f8fa;
  --card: #fff;
  --blue: #1b4f8a;
  --blue-soft: #e8f0f9;
  --green: #1d7a4c;
  --green-soft: #e6f4ec;
  --amber: #a15c00;
  --amber-soft: #fdf2e0;
  --red: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--blue); }

/* ------------------------------------------------------------------ chrome */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .7rem 1.4rem;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-weight: 650; text-decoration: none; color: var(--ink); }
.brand span { color: var(--muted); font-weight: 400; margin-left: .4rem; font-size: .85em; }

.topbar nav { display: flex; align-items: center; gap: 1.1rem; font-size: .92rem; }
.deadline { color: var(--amber); background: var(--amber-soft); padding: .15rem .5rem; border-radius: 4px; }

.live {
  font-size: .75rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
}
.live.off { background: #eef1f4; color: var(--muted); }

main { max-width: 1500px; margin: 0 auto; padding: 1.5rem 1.4rem 3rem; }

footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 1.4rem 2.5rem;
  color: var(--muted);
  font-size: .82rem;
}

h1 { font-size: 1.5rem; margin: 0 0 .35rem; }
.lede { color: var(--muted); margin: 0 0 1.2rem; max-width: 70ch; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; max-width: 80ch; }

.banner {
  padding: .7rem .9rem;
  border-radius: 6px;
  background: var(--blue-soft);
  margin: 0 0 1.2rem;
}
.banner.warn { background: var(--amber-soft); color: var(--amber); }
.banner code { background: rgba(0, 0, 0, .06); padding: 0 .25rem; border-radius: 3px; }

/* -------------------------------------------------------------- PI picker */

.pi-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: .8rem;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
}

.pi-card a {
  display: block;
  padding: .9rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  height: 100%;
}
.pi-card a:hover { border-color: var(--blue); }
.pi-card.confirmed a { border-left: 3px solid var(--green); }
.pi-card strong { display: block; font-size: 1.05rem; }
.pi-card .counts { display: block; color: var(--muted); font-size: .82rem; margin: .15rem 0 .5rem; }

.bar { display: block; height: 5px; background: #eaeef2; border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); transition: width .25s ease; }

.progress { font-size: .82rem; color: var(--muted); }
.pi-card .progress { display: block; margin-top: .35rem; }
.pi-card .warn { display: block; color: var(--amber); font-size: .78rem; margin-top: .3rem; }
.tick { color: var(--green); font-size: .78rem; }

/* -------------------------------------------------------------- PI header */

.pi-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.pi-status { display: flex; align-items: center; gap: .8rem; }

.confirm {
  font: inherit;
  font-size: .9rem;
  padding: .45rem .9rem;
  border-radius: 6px;
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.confirm:hover { filter: brightness(1.08); }
.confirm.on { background: var(--green); border-color: var(--green); }

/* ----------------------------------------------------------------- tables */

.grid {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  font-size: .9rem;
}

.grid th, .grid td {
  padding: .5rem .6rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.grid thead th {
  background: #f0f3f6;
  font-size: .76rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  white-space: nowrap;
}
.grid tbody tr:last-child td { border-bottom: none; }
.grid .num { text-align: right; }
.grid td.cost { font-variant-numeric: tabular-nums; color: var(--muted); }

.grid tr.done { background: linear-gradient(90deg, var(--green-soft) 0 3px, transparent 3px); }
.grid tr.todo td:first-child { box-shadow: inset 3px 0 0 var(--amber); }
.grid tr.saving { opacity: .6; }
.grid tr.error { background: #fdecea; }

@keyframes flash { from { background-color: #fff8d6; } to { background-color: transparent; } }
.grid tr.flash td { animation: flash 1.1s ease-out; }

.student b { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.sname { margin-left: .4rem; }
.tags { display: block; }
.tag {
  display: inline-block;
  font-style: normal;
  font-size: .72rem;
  padding: .05rem .35rem;
  border-radius: 3px;
  margin-right: .3rem;
}
.tag.incoming { background: var(--blue-soft); color: var(--blue); }
.tag.co { background: #f3ecfa; color: #5b3a86; }

.grid select, .grid input {
  font: inherit;
  font-size: .85rem;
  padding: .3rem .35rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: inherit;
  width: 100%;
  max-width: 100%;
}
.grid select:focus, .grid input:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.grid input.pct { width: 4.5rem; text-align: right; }
.grid td.num input { display: inline-block; }

/* ------------------------------------------------------ add funding source */

.add-source {
  margin: .9rem 0 0;
  padding: .8rem .9rem;
  background: var(--card);
  border: 1px solid var(--blue);
  border-radius: 8px;
}
.add-source > strong { display: block; }
.add-source > .muted { display: block; font-size: .82rem; margin-bottom: .55rem; }
.add-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.add-row input {
  font: inherit;
  font-size: .88rem;
  padding: .4rem .55rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: inherit;
  min-width: 16rem;
}
.linkish {
  font: inherit;
  font-size: .88rem;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
}
.add-error { color: var(--red); font-size: .85rem; }

.source-cell .fellow-other { margin-top: .3rem; }
.relabel { display: block; font-size: .74rem; color: var(--amber); margin-top: .25rem; }
.warn-tag { background: var(--amber-soft); color: var(--amber); }

/* ----------------------------------------------------------------- admin */

.summary {
  list-style: none;
  margin: 0 0 1.2rem;
  padding: 0;
  display: grid;
  gap: .4rem;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
}
.summary li {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .35rem .6rem;
  font-size: .85rem;
}
.summary li.confirmed { border-left: 3px solid var(--green); }
.summary li a { text-decoration: none; font-weight: 550; }
.summary .progress { margin-left: auto; }

.tools {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 0 .7rem;
  flex-wrap: wrap;
  font-size: .88rem;
}
#filter {
  font: inherit;
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 20rem;
  background: #fff;
}

.datatable thead th { cursor: pointer; user-select: none; }
.datatable thead th:hover { color: var(--ink); }
.datatable thead th.asc::after { content: " ▲"; font-size: .7em; }
.datatable thead th.desc::after { content: " ▼"; font-size: .7em; }
.datatable td.uni { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.datatable td.funding { font-size: .82rem; }

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e7edf3;
    --muted: #94a3b3;
    --line: #2a3644;
    --bg: #10161d;
    --card: #171f28;
    --blue: #7fb2ee;
    --blue-soft: #1c2c3f;
    --green: #5cc48d;
    --green-soft: #162b21;
    --amber: #e0a95c;
    --amber-soft: #2e2415;
    --red: #f28b82;
  }
  .grid thead th { background: #1d2733; }
  .grid select, .grid input, #filter, .add-row input { background: #10161d; border-color: var(--line); }
  .grid tr.error { background: #3a1d1a; }
  .live.off { background: #222c37; }
  .bar { background: #222c37; }
  @keyframes flash { from { background-color: #3a3520; } to { background-color: transparent; } }
}
