:root {
  --bg: #F5F6F5;
  --surface: #FFFFFF;
  --surface-2: #ECEFED;
  --line: #DCE1DE;
  --line-2: #C5CCC8;
  --text: #0B0D0C;
  --text-2: #444C48;
  --text-3: #69716D;
  --accent: #0D7A6F;
  --accent-hover: #0A665D;
  --accent-ink: #FFFFFF;
  --accent-soft: #E0EFEB;
  --detect: #CF4A36;
  --detect-soft: rgba(207, 74, 54, 0.12);
  --trace: #262C29;
  --grid: rgba(11, 13, 12, 0.05);
  --grid-2: rgba(11, 13, 12, 0.12);
  --ok-bg: #DDF1EA;
  --ok-fg: #0B6B57;
  --warn-bg: #FBE9E4;
  --warn-fg: #A63A28;
  --pend-bg: #FBF1D9;
  --pend-fg: #8A6410;
  --shadow-1: 0 1px 2px rgba(11, 13, 12, 0.05), 0 4px 16px rgba(11, 13, 12, 0.05);
  --shadow-2: 0 1px 2px rgba(11, 13, 12, 0.06), 0 24px 64px rgba(11, 13, 12, 0.12);
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #181818; --surface: #1F1F1F; --surface-2: #272727; --line: #313131; --line-2: #404040;
    --text: #F1F3F2; --text-2: #B3BAB6; --text-3: #868D89;
    --accent: #3FC1B0; --accent-hover: #5DD0C1; --accent-ink: #0A1A17; --accent-soft: rgba(63, 193, 176, 0.12);
    --detect: #F0745D; --detect-soft: rgba(240, 116, 93, 0.16); --trace: #CDD4D0;
    --grid: rgba(255, 255, 255, 0.04); --grid-2: rgba(255, 255, 255, 0.10);
    --ok-bg: rgba(63, 193, 176, 0.14); --ok-fg: #7FDCCF; --warn-bg: rgba(240, 116, 93, 0.14); --warn-fg: #F59A88;
    --pend-bg: rgba(240, 190, 80, 0.14); --pend-fg: #F1C66B;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.5), 0 24px 64px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #181818; --surface: #1F1F1F; --surface-2: #272727; --line: #313131; --line-2: #404040;
  --text: #F1F3F2; --text-2: #B3BAB6; --text-3: #868D89;
  --accent: #3FC1B0; --accent-hover: #5DD0C1; --accent-ink: #0A1A17; --accent-soft: rgba(63, 193, 176, 0.12);
  --detect: #F0745D; --detect-soft: rgba(240, 116, 93, 0.16); --trace: #CDD4D0;
  --grid: rgba(255, 255, 255, 0.04); --grid-2: rgba(255, 255, 255, 0.10);
  --ok-bg: rgba(63, 193, 176, 0.14); --ok-fg: #7FDCCF; --warn-bg: rgba(240, 116, 93, 0.14); --warn-fg: #F59A88;
  --pend-bg: rgba(240, 190, 80, 0.14); --pend-fg: #F1C66B;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.5), 0 24px 64px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/20px var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; text-wrap: balance; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--accent); }
.hidden { display: none !important; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- buttons, inputs, pills */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--warn-fg); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field small { color: var(--text-3); font-size: 12px; line-height: 16px; }
.input, select.input, textarea.input {
  width: 100%; height: 38px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); outline: none;
}
textarea.input { height: auto; min-height: 64px; padding: 8px 12px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.check input { margin-top: 3px; accent-color: var(--accent); }
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--surface-2); color: var(--text-2);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); }
.pill.pend { background: var(--pend-bg); color: var(--pend-fg); }
.pill.plain::before { display: none; }
.err { color: var(--warn-fg); font-size: 13px; }

/* ---------- top bar */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  height: 56px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; text-decoration: none; color: var(--text); }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.top .clinic { color: var(--text-2); font-size: 13px; display: flex; gap: 8px; align-items: center; min-width: 0; }
.top .clinic b { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .spacer { flex: 1; }
.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: 42px; min-width: 220px; padding: 6px; display: grid; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-2);
}
.menu-panel .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-panel .who small { display: block; color: var(--text-3); }
.menu-panel button { justify-content: flex-start; }

/* ---------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login {
  width: 100%; max-width: 380px; display: grid; gap: 20px; padding: 32px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-2);
}
.login h1 { font-size: 22px; line-height: 28px; }
.login p { color: var(--text-2); }
.login .foot { font-size: 12px; color: var(--text-3); line-height: 18px; }

/* ---------- recordings page */
.page { max-width: 1240px; margin: 0 auto; padding: 28px 24px 64px; display: grid; gap: 24px; }
.page-head { display: flex; align-items: end; gap: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; line-height: 30px; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.page-head .spacer { flex: 1; }
.layout { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 24px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.upload { padding: 20px; display: grid; gap: 14px; }
.upload h2 { font-size: 16px; }
.drop {
  display: grid; place-items: center; gap: 6px; text-align: center; padding: 24px 16px; min-height: 132px;
  border: 1.5px dashed var(--line-2); border-radius: var(--radius); background: var(--bg); cursor: pointer;
  color: var(--text-2); transition: border-color 120ms, background 120ms;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop b { color: var(--text); font-weight: 500; }
.drop small { color: var(--text-3); font-size: 12px; }
.notice.privacy { background: var(--accent-soft); color: var(--text); }
.notice.privacy b { font-weight: 600; }

/* upload queue: one card per file, checked and anonymised on this computer */
.queue { display: grid; gap: 8px; }
.queue:empty { display: none; }
.qitem { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.qitem[data-status="blocked"] { border-color: var(--warn-bg); }
.qitem[data-status="done"] { border-color: var(--ok-bg); }
.q-head { display: flex; align-items: flex-start; gap: 8px; }
.q-file { flex: 1; min-width: 0; display: grid; gap: 2px; }
.q-file b { font-weight: 500; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-file small { font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.q-x { flex: none; width: 22px; height: 22px; border: 0; border-radius: 6px; background: transparent; color: var(--text-3); font-size: 16px; line-height: 1; cursor: pointer; }
.q-x:hover { background: var(--surface-2); color: var(--text); }
.q-fields { display: grid; grid-template-columns: 2fr 3fr; gap: 8px; }
.q-fields .field { gap: 4px; }
.q-fields .field > span { font-size: 12px; }
.input.sm { height: 32px; padding: 0 10px; font-size: 13px; }
.q-msg { font-size: 12px; line-height: 17px; color: var(--text-2); }
.q-msg.err { color: var(--warn-fg); }
.q-msg[hidden] { display: none; }
.q-msg a { color: var(--accent); }
.q-ref { font-size: 12px; color: var(--text-3); }
.qitem > .btn { justify-self: start; }
.queue-opts { display: grid; gap: 12px; }
.queue-actions { display: flex; align-items: center; gap: 8px; }
.queue-actions .btn.primary { flex: 1; }
details.help { font-size: 13px; color: var(--text-2); border-top: 1px solid var(--line); padding-top: 12px; }
details.help summary { cursor: pointer; color: var(--text); font-weight: 500; }
details.help ol { margin: 8px 0 0; padding-left: 18px; display: grid; gap: 4px; line-height: 19px; }
.flag .t small { margin-left: 8px; font-size: 11px; font-weight: 400; color: var(--text-3); }
#print-sheet { display: none; }
.notice { font-size: 12px; line-height: 18px; color: var(--text-2); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.bar { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); transition: width 200ms; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-3); padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--bg); }
td .title { font-weight: 500; }
td .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
td.r, th.r { text-align: right; }
.flags-cell { display: flex; align-items: baseline; justify-content: flex-end; gap: 6px; }
.flags-cell b { font-family: var(--mono); font-weight: 500; font-size: 15px; }
.flags-cell b.hot { color: var(--detect); }
.empty { padding: 48px 24px; text-align: center; color: var(--text-3); display: grid; gap: 6px; }
.empty b { color: var(--text-2); font-weight: 500; }
.mini-bar { width: 72px; }

/* ---------- review page */
.review { display: grid; grid-template-rows: auto auto auto 1fr; height: calc(100vh - 56px); }
.rv-head { display: flex; align-items: center; gap: 16px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.rv-head h1 { font-size: 17px; line-height: 24px; }
.rv-head .meta { display: flex; gap: 14px; color: var(--text-3); font-size: 13px; flex-wrap: wrap; }
.rv-head .spacer { flex: 1; }
.rv-tools { display: flex; align-items: center; gap: 10px; padding: 10px 24px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.seg button { height: 30px; padding: 0 10px; border: 0; background: var(--surface); cursor: pointer; font-size: 13px; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.tool-label { font-size: 12px; color: var(--text-3); }
.tool { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.btn.icon { width: 30px; padding: 0; justify-content: center; font-size: 16px; line-height: 1; }
.rv-tools .nav { display: inline-flex; align-items: center; gap: 6px; }
.review:fullscreen { height: 100vh; background: var(--bg); }
#eeg { cursor: crosshair; }
select.compact { height: 30px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--surface); padding: 0 8px; font-size: 13px; }
.clock { font-family: var(--mono); font-size: 13px; color: var(--text-2); min-width: 150px; text-align: center; }
.timeline-wrap { padding: 10px 24px 8px; border-bottom: 1px solid var(--line); background: var(--surface); }
.timeline-wrap .lbl { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-3); margin-bottom: 4px; }
#timeline { display: block; width: 100%; height: 44px; cursor: pointer; }
.rv-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 0; }
.eeg { position: relative; min-height: 0; background: var(--surface); }
#eeg { display: block; width: 100%; height: 100%; }
.eeg .overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--text-2); background: var(--surface); }
.eeg .overlay div { max-width: 420px; display: grid; gap: 8px; }
.side { border-left: 1px solid var(--line); background: var(--bg); display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.side-head { padding: 14px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.side-head h2 { font-size: 14px; }
.side-head .counts { display: flex; gap: 6px; flex-wrap: wrap; }
.flag-list { overflow-y: auto; padding: 8px; display: grid; gap: 6px; align-content: start; }
.flag {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); cursor: pointer;
}
.flag:hover { border-color: var(--line-2); }
.flag.current { border-color: var(--detect); box-shadow: 0 0 0 3px var(--detect-soft); }
.flag .t { font-family: var(--mono); font-size: 13px; font-weight: 500; }
.flag .p { font-family: var(--mono); font-size: 12px; color: var(--detect); text-align: right; }
.flag .verdicts { grid-column: 1 / -1; display: flex; gap: 4px; }
.flag .verdicts button {
  flex: 1; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg);
  font-size: 12px; cursor: pointer; color: var(--text-2);
}
.flag .verdicts button:hover { border-color: var(--line-2); }
.flag .verdicts button.on.confirmed { background: var(--warn-bg); color: var(--warn-fg); border-color: transparent; font-weight: 500; }
.flag .verdicts button.on.rejected { background: var(--ok-bg); color: var(--ok-fg); border-color: transparent; font-weight: 500; }
.flag .verdicts button.on.unsure { background: var(--pend-bg); color: var(--pend-fg); border-color: transparent; font-weight: 500; }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--text-3); line-height: 18px; display: grid; gap: 6px; }
.side-foot p { margin: 0; }
.kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border: 1px solid var(--line-2); border-radius: 4px; background: var(--surface); color: var(--text-2); }
.details { padding: 12px 16px; display: grid; gap: 6px; font-size: 12px; color: var(--text-2); border-top: 1px solid var(--line); }

dialog {
  border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-2);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog form { display: grid; gap: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; padding: 10px 16px;
  border-radius: 10px; background: var(--text); color: var(--bg); font-size: 13px; box-shadow: var(--shadow-2);
}

.layout > * { min-width: 0; }
td .num { white-space: nowrap; }
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .upload { position: static; }
  .rv-body { grid-template-columns: 1fr; grid-template-rows: minmax(360px, 1fr) auto; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .review { height: auto; min-height: calc(100vh - 56px); }
}
@media (max-width: 639px) {
  .top { padding: 0 16px; }
  .top .clinic { display: none; }
  .page { padding: 20px 16px 48px; }
  .rv-head, .rv-tools, .timeline-wrap { padding-left: 16px; padding-right: 16px; }
  .hide-sm { display: none; }
}
@media (max-width: 420px) { .q-fields { grid-template-columns: 1fr; } }

/* print: only the summary sheet, black on white */
@media print {
  @page { margin: 16mm; }
  body > *:not(#print-sheet) { display: none !important; }
  #print-sheet { display: block; color: #000; background: #fff; font-size: 11pt; line-height: 1.45; }
  #print-sheet header { display: flex; justify-content: space-between; border-bottom: 1.5pt solid #000; padding-bottom: 6pt; margin-bottom: 14pt; }
  #print-sheet h1 { font-size: 18pt; margin-bottom: 8pt; }
  #print-sheet h2 { font-size: 12pt; margin: 14pt 0 4pt; }
  #print-sheet dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6pt 18pt; margin: 0 0 12pt; }
  #print-sheet dt { font-size: 8.5pt; text-transform: uppercase; letter-spacing: 0.06em; color: #555; }
  #print-sheet dd { margin: 0; }
  #print-sheet table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
  #print-sheet th, #print-sheet td { text-align: left; padding: 3pt 6pt; border-bottom: 0.5pt solid #999; font-size: 10pt; color: #000; }
  #print-sheet th { text-transform: none; letter-spacing: 0; font-weight: 600; }
  #print-sheet tr { break-inside: avoid; }
  #print-sheet .ps-disc { margin-top: 14pt; font-size: 9pt; color: #444; }
  #print-sheet .ps-sign { display: grid; grid-template-columns: 2fr 2fr 1fr; gap: 18pt; margin-top: 36pt; }
  #print-sheet .ps-sign span { border-top: 0.75pt solid #000; padding-top: 3pt; font-size: 9pt; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
