/* Baseline Cognitive design system: tokens + components (PRD §9.5–9.6).
   One file for the clinician app, the patient runtime and the report.
   No framework. Fonts: system stacks until the self-hosted brand fonts arrive. */

:root {
  --paper: #faf8f4;
  --card: #ffffff;
  --ink: #1b1f22;
  --ink-2: #4a5157;
  --ink-3: #6b7378;
  --line: #e3dfd7;
  --line-2: #d1ccc2;
  --brand: #134e5e;        /* midnight teal */
  --brand-ink: #ffffff;
  --brand-tint: #e4eff1;
  --band: #eef4f5;          /* typical-range band */
  --amber: #8a5a00;         /* the only alert colour: text */
  --amber-bg: #fdf3dc;
  --amber-line: #e8c56d;
  --focus: #1d6fa5;

  --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
  --sans: "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r1: 6px; --r2: 10px;
  --target: 44px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 var(--s4); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; margin-top: var(--s5); }
h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--s4); }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.muted { color: var(--ink-3); }
.small { font-size: 0.875rem; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- App shell --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s4);
  padding: var(--s3) var(--s5); background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-family: var(--serif); font-size: 1.15rem; color: var(--ink); text-decoration: none; font-weight: 600; }
.topbar nav { display: flex; gap: var(--s4); align-items: center; }
.topbar form { margin: 0; }
main.page { max-width: 960px; margin: 0 auto; padding: var(--s6) var(--s4) var(--s7); }
main.narrow { max-width: 480px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r2);
  padding: var(--s5); margin-bottom: var(--s5);
}
.row { display: flex; gap: var(--s4); flex-wrap: wrap; align-items: center; }
.spread { justify-content: space-between; }

/* --- Forms --- */
label { display: block; font-weight: 600; margin-bottom: var(--s1); }
.field { margin-bottom: var(--s4); }
.hint { display: block; font-weight: 400; color: var(--ink-3); font-size: 0.875rem; }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: var(--target); padding: var(--s2) var(--s3);
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line-2); border-radius: var(--r1);
}
textarea { font-family: var(--mono); font-size: 0.85rem; min-height: 14rem; }
.check { display: flex; gap: var(--s2); align-items: flex-start; font-weight: 400; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.error-text { color: var(--amber); font-weight: 600; font-size: 0.9rem; margin-top: var(--s1); }
fieldset { border: 0; padding: 0; margin: 0 0 var(--s4); }
legend { font-weight: 600; margin-bottom: var(--s1); }
.radios { display: flex; gap: var(--s4); flex-wrap: wrap; }
.radios label { font-weight: 400; display: flex; gap: var(--s2); align-items: center; min-height: var(--target); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--target); padding: var(--s2) var(--s5);
  font: 600 1rem/1 var(--sans); text-decoration: none; cursor: pointer;
  border-radius: var(--r1); border: 1px solid var(--brand);
  background: var(--brand); color: var(--brand-ink);
}
.btn.secondary { background: var(--card); color: var(--brand); }
.btn.link { background: none; border: 0; color: var(--brand); padding: 0; min-height: 0; text-decoration: underline; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* --- Notices --- */
.notice { border-radius: var(--r1); padding: var(--s3) var(--s4); margin-bottom: var(--s4); border: 1px solid var(--line); background: var(--card); }
.notice.alert { background: var(--amber-bg); border-color: var(--amber-line); color: var(--ink); }
.notice.alert strong { color: var(--amber); }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-3); font-weight: 600; }
td.num, th.num { text-align: right; }
tr.unavailable td { color: var(--ink-3); }

/* --- Status pills --- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--brand-tint); color: var(--brand); }
.pill.caution, .pill.invalid { background: var(--amber-bg); color: var(--amber); }
.pill.muted { background: var(--line); color: var(--ink-2); }

/* --- Report --- */
.report-head { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
.report-head .who { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.trust { display: flex; gap: var(--s4); flex-wrap: wrap; justify-content: space-between; padding: var(--s3) 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: var(--s5); }
.trust .valid { color: var(--brand); font-weight: 600; }
.trust .caution, .trust .invalid { color: var(--amber); font-weight: 600; }
.section-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); font-weight: 600; margin: var(--s5) 0 var(--s2); }

/* --- Patient runtime (iPad) --- */
body.runtime {
  background: var(--paper);
  font-size: 22px;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}
.rt {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--s6); text-align: center; gap: var(--s5);
}
.rt h1 { font-size: 2.2rem; }
.rt p { max-width: 34em; font-size: 1.4rem; line-height: 1.5; }
.rt .btn { min-height: 72px; min-width: 260px; font-size: 1.4rem; border-radius: var(--r2); }
.rt .progress { position: fixed; top: 0; left: 0; right: 0; height: 8px; background: var(--line); }
.rt .progress > div { height: 100%; background: var(--brand); width: 0; transition: width 300ms; }
.rt .stop { position: fixed; bottom: var(--s4); right: var(--s4); }
.rt .stop .btn { min-width: 0; min-height: 52px; font-size: 1rem; }
.stage {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  touch-action: none; background: var(--paper);
}
.stimulus { font: 700 160px/1 var(--sans); color: var(--ink); }
.countdown { font: 600 120px/1 var(--serif); color: var(--brand); }
.feedback { position: fixed; bottom: 18%; left: 0; right: 0; font-size: 1.6rem; font-weight: 600; color: var(--brand); min-height: 2em; }
.feedback.miss { color: var(--amber); }
.tap-target {
  width: 260px; height: 260px; border-radius: 50%;
  background: var(--brand); border: 0; touch-action: none;
}
.tap-target:active { background: #0d3a46; }
.hand { font-size: 1.6rem; font-weight: 600; }
.timebar { position: fixed; bottom: 0; left: 0; height: 10px; background: var(--brand); width: 0; }
.q-options { display: grid; gap: var(--s3); width: min(640px, 100%); }
.q-options .btn { width: 100%; justify-content: flex-start; text-align: left; background: var(--card); color: var(--ink); border-color: var(--line-2); min-height: 76px; }
.q-options .btn[aria-pressed=true] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.q-item { font-family: var(--serif); font-size: 1.7rem; max-width: 30em; }
.q-nav { display: flex; gap: var(--s4); }

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}

.secret { display: inline-block; font: 600 1.2rem/1.4 var(--mono); letter-spacing: 0.08em; word-break: break-all; background: var(--brand-tint); padding: var(--s2) var(--s3); border-radius: var(--r1); }
details code { word-break: break-all; }

/* --- Admin console --- */
.subnav { display: flex; gap: var(--s5); flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: var(--s5); }
.subnav a { padding: var(--s2) 0; text-decoration: none; color: var(--ink-2); border-bottom: 3px solid transparent; }
.subnav a[aria-current=page] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r2); padding: var(--s4); display: grid; gap: var(--s1); }
.stat-n { font: 600 1.8rem/1 var(--serif); }
.stat-l { color: var(--ink-3); font-size: 0.85rem; }
.table-scroll { overflow-x: auto; }
td.actions { display: flex; flex-wrap: wrap; gap: var(--s3); }
td.actions form { margin: 0; }
textarea.plain { font-family: var(--sans); font-size: 1rem; min-height: 6rem; }
textarea.link-box { min-height: 4.5rem; word-break: break-all; }
.row .field { flex: 1 1 180px; }
.qr { width: min(240px, 70vw); margin: var(--s4) 0; padding: var(--s2); background: #fff; border: 1px solid var(--line); border-radius: var(--r1); }
.qr svg { display: block; width: 100%; height: auto; }
.steps { padding-left: 1.2em; }
.dob { display: grid; grid-template-columns: 2fr 1fr 1.4fr; gap: var(--s3); width: min(640px, 100%); }
.dob-select { min-height: 72px; font-size: 1.3rem; }
