/* Tokens ------------------------------------------------------------------------------------------------------- */
/* Plum Night. Every hex value lives in these two blocks; component rules use var(--…) only. */
:root {
  color-scheme: light;
  --brand-purple: #7f2596;
  --brand-light: #8f48b0;
  --brand-pink: #dd4f75;
  --brand-teal: #88e4db;
  --night: #1a1d23;
  --paper: #f7f5f1;
  /* The one signature. --grad is the full purple to pink; --grad-fill stops short of the pink end so white text on it
     keeps 4.5:1. */
  --grad: linear-gradient(90deg, #8f48b0, #dd4f75);
  --grad-fill: linear-gradient(135deg, #8f48b0 0%, #dd4f75 190%);
  --bg: #f7f5f1;
  --surface: #ffffff;
  --ink: #262223;
  --ink-2: #4a4546;
  --muted: #625c5e;
  --axis-text: #6b6567;
  --grid: #e8e4dd;
  --baseline: #8e888c;
  --border: rgba(38, 34, 35, 0.14);
  --hover: rgba(127, 37, 150, 0.08);
  --accent: #7f2596;
  --on-accent: #ffffff;
  --link: #7f2596;
  --series-1: #8f48b0;
  --series-sel: #dd4f75;
  --bar: #8f48b0;
  --band: #88e4db;
  --band-opacity: 0.35;
  --info: #2563b0;
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #cf2a22;
  --good-ink: #006300;
  --critical-ink: #a42525;
  --flash: rgba(143, 72, 176, 0.12);
  --shadow: 0 6px 18px rgba(38, 34, 35, 0.1);
  --gold: #8f48b0;
  --silver: #9ca3af;
  --bronze: #e3a18f;
  --medal-ink: #1a1d23;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --space-5: 40px;
  --radius: 14px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Set on <html> by theme_boot.js / ThemeController. Brand styles override tokens under this and `data-brand`. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1d23;
  --surface: #23202c;
  --ink: #f7f5f1;
  --ink-2: #d2ccd3;
  --muted: #a8a1b0;
  --axis-text: #a39cab;
  --grid: #302b3b;
  --baseline: #7a7385;
  --border: rgba(143, 72, 176, 0.35);
  --hover: rgba(143, 72, 176, 0.22);
  --accent: #88e4db;
  --on-accent: #1a1d23;
  --link: #88e4db;
  --series-1: #b57fd6;
  --bar: #a566c6;
  --band-opacity: 0.2;
  --info: #6aa5f0;
  --critical: #f0463c;
  --good-ink: #5fd35f;
  --critical-ink: #ff8575;
  --flash: rgba(143, 72, 176, 0.3);
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* Base --------------------------------------------------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
}
a { color: var(--link); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.9rem; margin: var(--space-4) 0 var(--space-2); }
p { margin: 0; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--space-2); top: -60px; background: var(--surface); padding: var(--space-2);
}
.skip-link:focus { top: var(--space-2); z-index: 10; }
[hidden] { display: none !important; }

/* Header ------------------------------------------------------------------------------------------------------- */
.site-header {
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
  box-shadow: var(--shadow);
}
.site-header::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--grad);
  pointer-events: none;
}
.site-header__inner {
  max-width: 1100px; margin: 0 auto; padding: var(--space-2) var(--space-3);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title account" "nav nav";
  align-items: center; gap: var(--space-1) var(--space-3);
}
.site-title { grid-area: title; font-size: 1.25rem; min-width: 0; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; }
.site-nav {
  grid-area: nav; display: flex; justify-content: center; gap: var(--space-1); min-width: 0;
  overflow-x: auto; scrollbar-width: none;
}
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a {
  display: inline-flex; align-items: center; white-space: nowrap; min-height: 36px;
  padding: var(--space-1) var(--space-3); border-radius: var(--radius-sm); color: var(--ink-2);
  text-decoration: none; font-weight: 600; transition: background-color 150ms, color 150ms;
}
.site-nav a:hover { background: var(--hover); color: var(--ink); }
.site-nav a[aria-current="page"] { background: var(--grad-fill); color: #fff; }
.site-nav a[aria-disabled="true"] { opacity: 0.75; cursor: not-allowed; }
.badge-soon {
  flex: none; margin-left: var(--space-2); padding: 0 var(--space-2); border: 1px solid currentColor;
  border-radius: 999px; font-size: 0.65rem; font-weight: 600; line-height: 1.5; text-transform: uppercase;
  white-space: nowrap;
}
@media (min-width: 720px) {
  .site-header__inner {
    grid-template-columns: auto minmax(0, 1fr) auto; grid-template-areas: "title nav account";
    height: 56px; gap: var(--space-4);
  }
}
.banner {
  background: var(--critical-ink); color: var(--surface); text-align: center; padding: var(--space-2);
  font-size: 0.875rem; font-weight: 600;
}

/* Layout ------------------------------------------------------------------------------------------------------- */
.view { max-width: 1100px; margin: 0 auto; padding: var(--space-4) var(--space-3) var(--space-5); outline: none; }
.view > * + * { margin-top: var(--space-4); }
.view-head {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--space-2);
}
.subtle { color: var(--muted); font-size: 0.875rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3);
}
.card > h3 { margin-bottom: var(--space-2); }
.grid-2 { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.empty { text-align: center; color: var(--ink-2); padding: var(--space-5) var(--space-3); }
.empty h3 { color: var(--ink); margin-bottom: var(--space-1); }

/* Tiles -------------------------------------------------------------------------------------------------------- */
.tiles { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3);
}
.tile__label {
  color: var(--muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.tile__value {
  font: 700 2rem/1.2 system-ui, sans-serif; letter-spacing: -0.02em;
}

/* Table -------------------------------------------------------------------------------------------------------- */
.table-scroll {
  overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
table { border-collapse: collapse; width: 100%; min-width: 640px; font-variant-numeric: tabular-nums; }
th, td { padding: var(--space-2) var(--space-3); text-align: left; white-space: nowrap; }
thead th {
  color: var(--muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
tbody tr + tr td { border-top: 1px solid var(--grid); }
td.num, th.num { text-align: right; }
td.pending-cell { color: var(--muted); }
tr.is-changed td { animation: flash 1.6s ease-out; }
@media (prefers-reduced-motion: reduce) {
  tr.is-changed td { animation: none; }
  .site-nav a, .button, .chip, .tab, .account-menu__toggle, .account-menu__item { transition: none; }
}
@keyframes flash { from { background: var(--flash); } to { background: transparent; } }

.rank {
  display: inline-grid; place-items: center; min-width: 28px; height: 28px; border-radius: 50%; font-weight: 700;
  color: var(--ink);
}
.rank--1 { background: var(--grad-fill); color: #fff; }
.rank--2 { background: var(--silver); color: var(--medal-ink); }
.rank--3 { background: var(--bronze); color: var(--medal-ink); }

/* Detailed report ---------------------------------------------------------------------------------------------- */
.feedback { display: grid; gap: var(--space-4); }
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-bottom: var(--space-3); }
.chip, .sort-button {
  font: inherit; color: inherit; cursor: pointer; background: none; border: 1px solid var(--baseline);
}
.chip {
  padding: 2px var(--space-3); border-radius: 999px; font-size: 0.8125rem;
  transition: background-color 150ms, border-color 150ms, color 150ms;
}
.chip:hover { background: var(--hover); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--link); font-weight: 600; }
.sort-button { border: 0; padding: 0; font-size: inherit; font-weight: inherit; color: inherit; }
th[aria-sort="ascending"] .sort-button::after { content: " ▲"; }
th[aria-sort="descending"] .sort-button::after { content: " ▼"; }
tr.selectable { cursor: pointer; }
tr.is-selected { background: var(--flash); box-shadow: inset 3px 0 0 var(--accent); }
tr.selectable:focus-visible, .chip:focus-visible, .sort-button:focus-visible { outline: 2px solid var(--accent); }
.caption { padding-left: var(--space-4); }

/* Badges ------------------------------------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px var(--space-2); border-radius: 999px;
  border: 1px solid var(--baseline); font-size: 0.8125rem; font-weight: 600; color: var(--ink-2);
}
.badge--completed { border-color: var(--good); color: var(--good-ink); }
.badge--failed { border-color: var(--critical); color: var(--critical-ink); }
.badge--running { border-color: var(--info); color: var(--info); }
.badge--pending { border-style: dashed; }

/* Meter and charts --------------------------------------------------------------------------------------------- */
.meter { display: inline-flex; align-items: center; gap: var(--space-2); }
.meter svg { width: 80px; height: 8px; display: block; }
.meter-track { fill: var(--grid); }
.meter-fill { fill: var(--bar); }
.meter .band-meter { width: 120px; }
.meter-over { fill: var(--critical); }
.meter-mark { stroke: var(--ink-2); stroke-width: 1; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--axis-text); font: 11px var(--font); }
.chart .tick-label-x { text-anchor: middle; }
.chart .tick-label-y { text-anchor: end; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .bar { fill: var(--bar); }
.chart .bar:hover { fill: var(--brand-pink); }
.chart .ref-line { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .ref-label { text-anchor: end; fill: var(--ink-2); }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .series { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-line { stroke: var(--series-1); stroke-width: 2; }
.chart .series-faded { stroke: var(--axis-text); stroke-width: 1.5; opacity: 0.35; }
.chart .series-selected { stroke: var(--series-sel); stroke-width: 3; }
.chart .band { fill: var(--band); opacity: var(--band-opacity); }
.chart .marker-reached { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--ink-2); stroke-width: 1; }
.chart .tooltip-box { fill: var(--surface); stroke: var(--baseline); stroke-width: 1; }
.chart .tooltip-text { fill: var(--ink); text-anchor: middle; }
.chart .series-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; }
.chart .series-tip { pointer-events: none; }
.chart .is-hidden { display: none; }
.chart-time-series:focus-visible { outline: 2px solid var(--accent); }
.chart-stack { height: auto; }
.seg { stroke: var(--surface); stroke-width: 2; }
.seg--completed { fill: var(--good); }
.seg--failed { fill: var(--critical); }
.seg--running { fill: var(--info); }
.seg--queued { fill: var(--axis-text); }
.legend {
  display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); margin-top: var(--space-2); list-style: none;
  padding: 0;
}
.legend li { display: flex; align-items: center; gap: var(--space-2); color: var(--ink-2); font-size: 0.875rem; }
.legend-swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend-swatch.seg--completed { background: var(--good); }
.legend-swatch.seg--failed { background: var(--critical); }
.legend-swatch.seg--running { background: var(--info); }
.legend-swatch.seg--queued { background: var(--axis-text); }

.strip-seg { stroke: var(--surface); stroke-width: 1; }
.strip-seg:focus-visible { outline: none; stroke: var(--ink); stroke-width: 3; }
.status-ok { fill: var(--grid); }
.status-student-exception { fill: var(--critical); }
.status-invalid-output { fill: var(--warning); }
.status-timeout { fill: var(--info); }
.status-unreachable { fill: var(--ink-2); }
.status-distributor-dead { fill: var(--axis-text); opacity: 0.6; }
.legend-swatch.status-ok { background: var(--grid); }
.legend-swatch.status-student-exception { background: var(--critical); }
.legend-swatch.status-invalid-output { background: var(--warning); }
.legend-swatch.status-timeout { background: var(--info); }
.legend-swatch.status-unreachable { background: var(--ink-2); }
.legend-swatch.status-distributor-dead { background: var(--axis-text); opacity: 0.6; }

/* Summary ------------------------------------------------------------------------------------------------------ */
.summary { display: flex; flex-wrap: wrap; gap: var(--space-4); align-items: center; }
.summary dl { margin: 0; }
.summary dt { color: var(--muted); font-size: 0.8125rem; }
.summary dd { margin: 0; font-size: 1.25rem; font-weight: 650; }
.kv { display: flex; flex-wrap: wrap; gap: var(--space-4); }

@media (max-width: 480px) {
  .tile__value { font-size: 1.5rem; }
}

/* Account ------------------------------------------------------------------------------------------------------ */
.account {
  grid-area: account; display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2);
  min-width: 0; white-space: nowrap; font-size: 0.875rem; color: var(--ink-2);
}
.account > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.account .button { flex: none; }
.account-menu { position: relative; min-width: 0; max-width: 100%; overflow: visible; }
.account-menu__toggle {
  display: inline-flex; align-items: center; gap: var(--space-1); max-width: 100%; font: inherit; cursor: pointer;
  padding: var(--space-1) var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink); font-weight: 600; transition: background-color 150ms;
}
.account-menu__toggle:hover { background: var(--hover); }
.account-menu__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.account-menu__chevron { flex: none; width: 10px; height: 6px; }
.account-menu__toggle[aria-expanded="true"] .account-menu__chevron { transform: rotate(180deg); }
.account-menu__panel {
  position: absolute; top: calc(100% + var(--space-1)); right: 0; z-index: 20; width: max-content;
  min-width: 160px; max-width: min(260px, calc(100vw - 2 * var(--space-3))); padding: var(--space-1);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); white-space: normal; overflow-wrap: anywhere;
}
.account-menu__who { margin: 0; padding: var(--space-1) var(--space-2); color: var(--muted); font-size: 0.8125rem; }
.account-menu__who strong { color: var(--ink); }
.account-menu__item {
  display: block; width: 100%; text-align: left; font: inherit; cursor: pointer; color: var(--ink);
  padding: var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent;
  transition: background-color 150ms;
}
.account-menu__item:hover, .account-menu__item:focus-visible { background: var(--hover); }
.account-menu__label { margin: 0; padding: var(--space-1) var(--space-2); color: var(--muted); font-size: 0.8125rem; }
.account-menu__item--radio { position: relative; padding-left: calc(var(--space-2) + 1.25rem); }
.account-menu__item--radio[aria-checked="true"]::before {
  content: "\2713"; position: absolute; left: var(--space-2); font-weight: 700;
}
.account-menu__separator { height: 1px; margin: var(--space-1) 0; background: var(--border); }
.button {
  font: inherit; font-weight: 600; cursor: pointer; padding: var(--space-2) var(--space-3);
  border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--grad-fill); color: #fff;
  transition: filter 150ms, background-color 150ms;
}
.button:hover:not(:disabled) { filter: brightness(1.08); }
.button:disabled { opacity: 0.6; cursor: progress; }
.button--small {
  padding: var(--space-1) var(--space-2); background: var(--surface); color: var(--ink); border-color: var(--border);
}
.button--small:hover:not(:disabled) { background: var(--hover); filter: none; }
.auth-card { max-width: 420px; display: grid; gap: var(--space-3); }
.grid-2 > .auth-card { max-width: none; align-content: start; }
.view > .auth-card { margin-inline: auto; }
.kit-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-1); }
.kit-row {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
  gap: var(--space-1) var(--space-3);
  padding: var(--space-2); border-left: 3px solid transparent; border-radius: var(--radius-sm);
}
.kit-row--selected { border-left-color: var(--accent); background: var(--bg); font-weight: 600; }
.tabs { display: flex; gap: var(--space-1); }
.tab {
  font: inherit; font-weight: 600; cursor: pointer; flex: 1; padding: var(--space-2); color: var(--ink-2);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.tab[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.auth-form { display: grid; gap: var(--space-3); }
.field { display: grid; gap: var(--space-1); }
.field label { font-weight: 600; }
.field select, .field input {
  font: inherit; width: 100%; padding: var(--space-2); color: var(--ink); background: var(--bg);
  border: 1px solid var(--baseline); border-radius: var(--radius-sm);
}
.field input[aria-invalid="true"] { border-color: var(--critical-ink); border-width: 2px; }
.hint { color: var(--muted); font-size: 0.8125rem; }
.field-error, .form-error { color: var(--critical-ink); font-size: 0.875rem; font-weight: 600; }
.field-error:empty, .form-error:empty { display: none; }

/* Own row ------------------------------------------------------------------------------------------------------ */
tr.is-me { background: var(--flash); box-shadow: inset 4px 0 0 var(--accent); }
.badge-you {
  margin-left: var(--space-2); padding: 1px var(--space-2); border-radius: 999px; font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; background: var(--accent); color: var(--on-accent);
}
.help { display: inline; cursor: help; border-radius: 3px; white-space: nowrap; }
.badge .help { display: inline-flex; align-items: center; gap: var(--space-1); }
.help-icon {
  display: inline-block; vertical-align: super; margin-left: 2px; width: 1.2em; height: 1.2em; line-height: 1.2em;
  border: 1px solid var(--muted); border-radius: 50%; color: var(--muted); font-size: 0.6rem; font-weight: 700;
  text-align: center;
}
.help-popup {
  display: none; position: fixed; top: 0; left: 0; z-index: 20; max-width: min(280px, calc(100vw - 16px));
  padding: var(--space-2) var(--space-3); background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow);
  font-size: 0.8125rem; line-height: 1.4; overflow-wrap: anywhere; pointer-events: none;
}
.help-popup.is-visible { display: block; }

/* Footer ------------------------------------------------------------------------------------------------------- */
.site-footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--surface);
  padding: var(--space-2) var(--space-3); text-align: center;
  color: var(--muted); font-size: 0.8125rem; border-top: 1px solid var(--border);
}
body { padding-bottom: 3rem; }
.site-footer[hidden] { display: none; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; border-radius: 3px; }
.site-footer a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
