:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #dddcd7;
  --grid: #e8e7e3;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --row-hover: #eef4fc;
  /* Policy colors: N (not accepted) -> Y (required) */
  --pol-N: #1baf7a;
  --pol-O: #2a78d6;
  --pol-R: #eda100;
  --pol-Y: #e34948;
  /* Cost chart series (categorical slots, fixed order) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #6250d6;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232322;
    --border: #3a3a37;
    --grid: #2c2c2a;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a998f;
    --accent: #3987e5;
    --row-hover: #1f2a38;
    --pol-N: #199e70;
    --pol-O: #3987e5;
    --pol-R: #c2880a;
    --pol-Y: #e5585c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232322; --border: #3a3a37; --grid: #2c2c2a;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #9a998f; --accent: #3987e5; --row-hover: #1f2a38;
  --pol-N: #199e70; --pol-O: #3987e5; --pol-R: #c2880a; --pol-Y: #e5585c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent); }
.wrap { max-width: 1480px; margin: 0 auto; padding: 0 16px; }
.visually-hidden, .hp {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header */
.site-header { padding: 28px 0 18px; }
.site-header h1 { margin: 0 0 8px; font-size: clamp(1.4rem, 2.6vw, 2rem); letter-spacing: -0.01em; text-wrap: balance; }
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.theme-btn { display: inline-flex; align-items: center; gap: 6px; flex: none; margin-top: 4px; }
.theme-btn .icon-sun { display: none; }
.theme-btn[aria-pressed="true"] .icon-sun { display: inline; }
.theme-btn[aria-pressed="true"] .icon-moon { display: none; }
@media (max-width: 520px) { .theme-btn .theme-label { display: none; } }
.lede { margin: 0 0 12px; color: var(--text-2); max-width: 78ch; }
.meta-line { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 0; color: var(--text-3); font-size: .9rem; }

.btn {
  font: inherit; font-size: .9rem; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 14px; border-radius: 8px;
}
.btn:hover { border-color: var(--text-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn:disabled { opacity: .6; cursor: progress; }
.icon-btn { font: inherit; font-size: 1.5rem; line-height: 1; border: 0; background: none; color: var(--text-2); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }

/* Layout */
/* Two columns of equal height: the chart column sets the row height and the table scroller stretches to fill it. */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 20px; align-items: stretch; }
.table-col { display: flex; flex-direction: column; min-width: 0; }
@media (max-width: 1100px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.charts-col { display: grid; gap: 16px; align-content: start; }
@media (max-width: 1100px) {
  .charts-col { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}
.card {
  margin: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.card h2, .card figcaption { margin: 0 0 8px; font-size: .95rem; font-weight: 600; }
.card h3 { margin: 12px 0 6px; font-size: .85rem; font-weight: 600; color: var(--text-2); }
.card .sub { display: block; font-weight: 400; color: var(--text-3); font-size: .8rem; }

/* Toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.search { flex: 1 1 260px; }
.search input {
  width: 100%; font: inherit; padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: inherit; font-size: .82rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  padding: 4px 10px; border-radius: 999px;
}
.chip[aria-pressed="false"] { opacity: .5; text-decoration: line-through; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.count { color: var(--text-3); font-size: .85rem; margin-left: auto; }

/* Table */
.table-scroll {
  overflow: auto;
  /* Contributes no intrinsic height, so the row is sized by the chart column; then grows to fill it. */
  flex: 1 1 0; height: 0; min-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
@media (max-width: 1100px) { .table-scroll { flex: none; height: auto; min-height: 0; max-height: 80vh; } }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .875rem; font-variant-numeric: tabular-nums; }
thead th {
  position: sticky; background: var(--surface-2); z-index: 2; text-align: left;
  font-weight: 600; color: var(--text-2); white-space: nowrap; border-bottom: 1px solid var(--border);
}
.group-row th { top: 0; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding: 6px 7px 2px; color: var(--text-3); border-bottom: 0; }
#header-row th { top: 26px; padding: 0; }
th button.sort {
  all: unset; box-sizing: border-box; display: flex; align-items: center; gap: 4px; width: 100%;
  padding: 6px 7px 8px; cursor: pointer;
}
th button.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
th button.sort .arrow { font-size: .7rem; color: var(--text-3); width: 1em; }
th[aria-sort="ascending"] .arrow::after { content: "▲"; color: var(--accent); }
th[aria-sort="descending"] .arrow::after { content: "▼"; color: var(--accent); }
th.num button.sort { justify-content: flex-end; }
td { padding: 6px 7px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num { text-align: right; white-space: nowrap; }
td.uni { font-weight: 500; min-width: 150px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
#header-row th[data-key="university"] { left: 0; z-index: 3; }
td.dept { color: var(--text-2); min-width: 120px; }
td.who, td.date { color: var(--text-3); white-space: nowrap; }
tbody tr:hover td { background: var(--row-hover); }
tbody tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--accent) 25%, transparent); } }
/* bottom: -1px (with 1px extra padding) covers the sub-pixel gap a fractional scroller height can leave below the footer. */
tfoot td { font-weight: 600; background: var(--surface-2); border-bottom: 0; position: sticky; bottom: -1px; padding-bottom: 7px; }
/* Footer label sits in the frozen University column: pinned to the bottom and the left, above the body's frozen cells. */
tfoot td.uni { background: var(--surface-2); z-index: 3; }
tfoot td.uni .sub { display: block; font-weight: 400; font-size: .75rem; color: var(--text-3); }
.empty td { text-align: center; color: var(--text-3); padding: 24px; }

.pol {
  display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px;
  border-radius: 6px; font-weight: 700; font-size: .8rem; color: #fff; padding: 0 6px;
  background: var(--pol-c);
}
.pol-N { --pol-c: var(--pol-N); }
.pol-O { --pol-c: var(--pol-O); }
.pol-R { --pol-c: var(--pol-R); color: #1b1300; }
.pol-Y { --pol-c: var(--pol-Y); }
.pol-none { color: var(--text-3); }
.yn { font-weight: 600; }
.yn-Y { color: var(--pol-N); }
.yn-N { color: var(--text-3); }

sup.flag {
  font-size: .7rem; color: var(--accent); cursor: help; margin-left: 1px; font-weight: 600;
  text-decoration: underline dotted; text-underline-offset: 2px;
}
.note-btn {
  all: unset; cursor: pointer; display: inline-grid; place-items: center;
  width: 16px; height: 16px; border-radius: 50%; margin-left: 4px; vertical-align: -2px;
  font-size: 10px; font-weight: 700; font-style: italic; font-family: Georgia, serif;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.note-btn:hover, .note-btn:focus-visible { background: var(--accent); color: #fff; border-color: var(--accent); }
.cad { color: var(--text-3); font-size: .75rem; margin-left: 2px; }
.edit-btn {
  font: inherit; font-size: .78rem; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border); background: none; color: var(--text-2); padding: 2px 8px; border-radius: 6px;
}
.edit-btn:hover { border-color: var(--accent); color: var(--accent); }
.hint { color: var(--text-3); font-size: .82rem; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 50; max-width: 360px; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 8px 10px; border-radius: 8px;
  font-size: .8rem; line-height: 1.4; white-space: pre-line; overflow-wrap: anywhere;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.tooltip.pinned { pointer-events: auto; }
.tooltip a { color: inherit; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 2px; }
.tooltip .tt-row { display: flex; gap: 8px; justify-content: space-between; align-items: center; }
.tooltip .tt-sw { width: 10px; height: 2px; display: inline-block; margin-right: 6px; vertical-align: middle; }

/* Charts */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-2); font: 11px var(--font); }
.chart .slice-label { fill: #fff; font-weight: 700; font-size: 12px; pointer-events: none; }
.chart .slice-label.dark { fill: #1b1300; }
.chart .slice { stroke: var(--surface); stroke-width: 2; cursor: default; transition: opacity .15s; }
.chart .slice.dim { opacity: .35; }
.chart .center-num { fill: var(--text); font-size: 20px; font-weight: 700; }
.chart .center-sub { fill: var(--text-3); font-size: 10px; }
.chart .axis line, .chart .gridline { stroke: var(--grid); }
.chart .axis path { stroke: none; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .crosshair { stroke: var(--text-3); stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; font-size: .78rem; color: var(--text-2); padding: 0; list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .ln { width: 16px; height: 0; border-top: 2px solid; }
.legend button { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.legend button[aria-pressed="false"] { opacity: .4; }
.chart-note { margin: 6px 0 0; color: var(--text-3); font-size: .75rem; }

.key-list { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: .82rem; }
.key-list dt { font-weight: 700; }
.key-list dd { margin: 0; color: var(--text-2); }
.key-list.flags dt { color: var(--accent); }

/* Footer */
.site-footer { padding: 28px 16px 48px; color: var(--text-2); font-size: .88rem; }
.site-footer h2 { font-size: 1rem; margin: 22px 0 6px; color: var(--text); }
.site-footer ul { margin: 0; padding-left: 20px; }
.site-footer li { margin: 2px 0; overflow-wrap: anywhere; }
.site-footer .fns p { margin: 6px 0; }
.site-footer .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 32px; }

/* Dialog */
dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(0,0,0,.4); }
#suggest-form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dlg-head, .dlg-foot { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; }
.dlg-head { border-bottom: 1px solid var(--border); }
.dlg-head h2 { margin: 0; font-size: 1.1rem; }
.dlg-foot { border-top: 1px solid var(--border); justify-content: flex-end; gap: 8px; }
.dlg-body { padding: 14px 18px; overflow: auto; display: grid; gap: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.field { display: grid; gap: 3px; font-size: .82rem; color: var(--text-2); font-weight: 500; }
.field em { font-weight: 400; color: var(--text-3); font-style: normal; }
.field input, .field select, .field textarea {
  font: inherit; font-size: .9rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.current { margin: -4px 0 0; font-size: .8rem; color: var(--text-3); }
.current:empty { display: none; }
.status { margin: 0; font-size: .88rem; min-height: 1.2em; }
.status.ok { color: var(--pol-N); }
.status.err { color: var(--pol-Y); }
