/* Northgate coding workbench: the design system for every page.
   Loaded after style.css and overrides its tokens, so any page that links this file gets the same look.

   Contents
     1. Tokens        colours, type, spacing, radii (light and dark)
     2. Base          page, headings, links, tables, form controls, buttons
     3. Components    top bar, tags and pills, cards, banners
     4. Queue         filter tiles, visit table
     5. Visit         verdict, the note sheet and its highlights, code cards, review form, history

   Design idea: the note is a sheet of chart paper marked with a highlighter; everything
   around it is a quiet ledger. Colour is reserved for four states:
     refused (red)   needs review (amber)   passed / clean (green)   neutral (slate)  */

/* ------------------------------------------------------------------ 1. Tokens */
:root {
  color-scheme: light dark;

  --bg:            oklch(96% 0.006 220);
  --surface:       oklch(99.5% 0.002 220);
  --surface-2:     oklch(97.5% 0.005 220);
  --text:          oklch(26% 0.03 225);
  --text-muted:    oklch(46% 0.03 225);
  --border:        oklch(88% 0.012 220);
  --border-strong: oklch(76% 0.02 220);
  --accent:        oklch(47% 0.085 205);   /* the one accent: clinical teal */
  --accent-ink:    oklch(99% 0 0);         /* text on the accent */

  --refused:    oklch(45% 0.15 27);   --refused-bg: oklch(95% 0.03 27);
  --review:     oklch(46% 0.10 75);   --review-bg:  oklch(95% 0.05 88);
  --passed:     oklch(45% 0.10 155);  --passed-bg:  oklch(95% 0.04 155);
  --neutral-bg: oklch(93% 0.008 220);

  --paper:     oklch(99% 0.006 95);    /* the note sheet */
  --hl:        oklch(91% 0.13 98);     /* highlighter: sentence a code rests on */
  --hl-active: oklch(85% 0.16 88);     /* the sentence for the code you are pointing at */
  --hl-not:    oklch(91% 0.012 220);   /* sentence behind a "not coded" decision */

  --font-ui:   "Avenir Next", "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --font-note: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  /* type scale, ratio 1.2 */
  --text-xs: 0.8125rem;  --text-sm: 0.875rem;  --text-md: 1rem;
  --text-lg: 1.2rem;     --text-xl: 1.44rem;   --text-2xl: 1.728rem;

  /* 8pt spacing */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;

  --radius-tag: 4px;    /* rule and code tags */
  --radius: 8px;        /* controls */
  --radius-card: 12px;  /* cards and panels */

  /* names the older pages use */
  --ok: var(--passed);  --warn: var(--review);  --danger: var(--refused);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:            oklch(21% 0.018 225);
    --surface:       oklch(26% 0.02 225);
    --surface-2:     oklch(29% 0.022 225);
    --text:          oklch(93% 0.01 220);
    --text-muted:    oklch(77% 0.02 220);
    --border:        oklch(37% 0.025 225);
    --border-strong: oklch(48% 0.03 225);
    --accent:        oklch(78% 0.09 200);
    --accent-ink:    oklch(22% 0.03 205);

    --refused:    oklch(80% 0.10 27);   --refused-bg: oklch(33% 0.07 27);
    --review:     oklch(85% 0.10 85);   --review-bg:  oklch(34% 0.055 85);
    --passed:     oklch(82% 0.10 155);  --passed-bg:  oklch(32% 0.05 155);
    --neutral-bg: oklch(31% 0.02 225);

    --paper:     oklch(27% 0.018 225);
    --hl:        oklch(40% 0.08 95);
    --hl-active: oklch(48% 0.11 88);   /* kept dark enough for 4.5:1 against the light text on top */
    --hl-not:    oklch(33% 0.02 225);
  }
}

/* ------------------------------------------------------------------ 2. Base */
body {
  padding: 0 0 var(--s7);
  background: var(--bg);
  color: var(--text);
  font: var(--text-md)/1.5 var(--font-ui);
  font-variant-numeric: tabular-nums;
}
main { max-width: 880px; margin: 0 auto; padding: var(--s5) var(--s5) 0; }
main.wide { max-width: 1320px; }

h1 { font-size: var(--text-2xl); font-weight: 650; letter-spacing: -0.01em; line-height: 1.2; margin: 0 0 var(--s2);
     display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }
h2 { font-size: var(--text-lg); font-weight: 650; line-height: 1.3; margin: var(--s6) 0 var(--s2);
     display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
h3 { font-size: var(--text-md); font-weight: 650; margin: 0 0 var(--s1); }
p { margin: 0 0 var(--s3); max-width: 78ch; }
.muted { color: var(--text-muted); }
.small { font-size: var(--text-sm); }
.error { color: var(--refused); }
a { color: var(--accent); text-underline-offset: 2px; }

:is(a, button, select, input, textarea, tr, mark, .card, summary):focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

table { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: var(--s3); background: var(--surface);
        border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
th, td { text-align: left; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
th { background: var(--surface-2); color: var(--text-muted); font-weight: 600; font-size: var(--text-sm); }

select, input[type="text"], input[type="search"], textarea {
  min-height: 44px; padding: var(--s2) var(--s3); border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
}
textarea { width: 100%; min-height: 72px; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }

button {
  min-height: 44px; padding: var(--s2) var(--s4); border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
button.danger { color: var(--refused); border-color: var(--refused); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ------------------------------------------------------------------ 3. Components */

/* Top bar, shared by every page:
   <header class="topbar"><a class="brand" href="/">…</a><nav>…</nav></header> */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s6);
          padding: 0 var(--s5); background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { display: inline-flex; align-items: center; gap: var(--s2); min-height: 56px;
                 color: var(--text); font-weight: 700; text-decoration: none; letter-spacing: -0.01em; }
.topbar .brand::before { content: ""; width: 12px; height: 20px; border-radius: 2px; background: var(--hl-active);
                         box-shadow: inset 0 -4px 0 var(--accent); }   /* a highlighter nib */
.topbar .brand span { color: var(--text-muted); font-weight: 500; }
.topbar nav { display: flex; flex-wrap: wrap; gap: var(--s1); margin: 0; }
.topbar nav a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s3);
                border-radius: var(--radius); color: var(--text-muted); font-weight: 600; text-decoration: none; }
.topbar nav a:hover { background: var(--neutral-bg); color: var(--text); }
.topbar nav a[aria-current="page"] { color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); border-radius: 0; }

/* Status pill: what state something is in */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
         font-size: var(--text-sm); font-weight: 600; white-space: nowrap; line-height: 1.5;
         background: var(--neutral-bg); color: var(--text); }
.badge.denial, .badge.reduced, .badge.none, .badge.unknown { padding-left: 8px; }
.badge.denial::before, .badge.reduced::before, .badge.none::before, .badge.unknown::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.denial  { background: var(--refused-bg); color: var(--refused); }
.badge.reduced { background: var(--review-bg);  color: var(--review); }
.badge.unknown { background: var(--review-bg);  color: var(--review); }
.badge.none    { background: var(--passed-bg);  color: var(--passed); }
/* Rule tag: a reference to a numbered rule (G5, HR-02). Square, outlined, like a form field reference. */
.badge.rule { border-radius: var(--radius-tag); background: transparent; border: 1px solid var(--border-strong);
              color: var(--text); font-weight: 650; padding: 1px 8px; }
/* A billing code */
.code { font-weight: 700; letter-spacing: 0.01em; white-space: nowrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
        padding: var(--s4) var(--s5); margin-top: var(--s4); }
.placeholder { border: 2px dashed var(--border-strong); border-radius: var(--radius-card); padding: var(--s6) var(--s5);
               text-align: center; color: var(--text-muted); }

.banner { border: 1px solid var(--review); border-left-width: 6px; background: var(--review-bg);
          padding: var(--s3) var(--s4); border-radius: var(--radius); margin-top: var(--s3); }
.banner.danger { border-color: var(--refused); background: var(--refused-bg); }
.banner ul { margin: var(--s1) 0 0; padding-left: 20px; }

/* ------------------------------------------------------------------ 4. Queue */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--s3); margin: var(--s4) 0 var(--s5); }
.tile { text-align: left; min-height: 80px; padding: var(--s3) var(--s4); font-weight: 500; color: var(--text-muted);
        border-color: var(--border); border-radius: var(--radius-card); border-top: 4px solid var(--border-strong); }
.tile strong { display: block; font-size: var(--text-2xl); line-height: 1.15; font-weight: 650; color: var(--text); }
.tile.refused { border-top-color: var(--refused); }  .tile.refused strong { color: var(--refused); }
.tile.review  { border-top-color: var(--review); }   .tile.review strong  { color: var(--review); }
.tile[aria-pressed="true"] { background: var(--neutral-bg); border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.filters { display: flex; flex-wrap: wrap; gap: var(--s3) var(--s4); align-items: end; }
.filters label { display: flex; flex-direction: column; gap: var(--s1); font-size: var(--text-sm); color: var(--text-muted); font-weight: 600; }
.filters label.check { flex-direction: row; align-items: center; min-height: 44px; gap: var(--s2); color: var(--text); font-weight: 500; }
.filters input[type="search"] { min-width: 280px; }

table.queue td { padding: var(--s3); }
table.queue tbody tr { cursor: pointer; }
table.queue tbody tr:hover { background: var(--surface-2); }
/* The coloured rail at the left of each row is the visit's payer check. */
table.queue td:first-child { border-left: 6px solid var(--border); padding-left: var(--s4); white-space: nowrap; }
table.queue tr.risk-denial  td:first-child { border-left-color: var(--refused); }
table.queue tr.risk-reduced td:first-child,
table.queue tr.risk-unknown td:first-child { border-left-color: var(--review); }
table.queue tr.risk-none    td:first-child { border-left-color: var(--passed); }
table.queue td:first-child a { font-weight: 700; }
table.queue .codes span { display: inline-block; margin-right: var(--s2); }
table.queue .reason { color: var(--review); font-size: var(--text-sm); max-width: 44ch; }

/* ------------------------------------------------------------------ 5. Visit */
.facts { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); margin: var(--s2) 0 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.facts li { color: var(--text); }
.facts b { color: var(--text-muted); font-weight: 600; margin-right: var(--s1); }

/* The verdict: one sentence at the top of a visit that says what the payer will do and why. */
.verdict { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s4); align-items: start;
           margin-top: var(--s4); padding: var(--s4) var(--s5); border-radius: var(--radius-card);
           border: 1px solid var(--passed); background: var(--passed-bg); }
.verdict.refused { border-color: var(--refused); background: var(--refused-bg); }
.verdict.review  { border-color: var(--review);  background: var(--review-bg); }
.verdict .mark { grid-row: span 2; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
                 font-weight: 800; font-size: var(--text-lg); background: var(--passed); color: var(--passed-bg); }
.verdict.refused .mark { background: var(--refused); color: var(--refused-bg); }
.verdict.review .mark  { background: var(--review);  color: var(--review-bg); }
.verdict .title { font-size: var(--text-lg); font-weight: 650; line-height: 1.3; }
.verdict .why { margin: 0; padding: 0; list-style: none; }
.verdict .why li { margin-top: var(--s1); }

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s6); align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }
.note-col { position: sticky; top: var(--s4); }
@media (max-width: 900px) { .note-col { position: static; } }

/* The note: a sheet of chart paper, set in a serif so it reads as the provider's document, not as our UI. */
.note.card { background: var(--paper); border-color: var(--border-strong); padding: var(--s5) var(--s6);
             box-shadow: 0 1px 0 var(--border-strong), 0 12px 24px -18px oklch(26% 0.03 225 / 0.45); }
.note { white-space: pre-wrap; overflow-wrap: anywhere; font: 1.0625rem/1.9 var(--font-note);
        max-height: 72vh; overflow: auto; max-width: none; }
.note mark { background: var(--hl); color: inherit; padding: 3px 1px; border-radius: 2px; cursor: pointer;
             -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.note mark.notcoded { background: var(--hl-not); text-decoration: underline dashed var(--border-strong); text-underline-offset: 4px; }
.note mark.warning { background: var(--refused-bg); text-decoration: underline wavy var(--refused); text-underline-offset: 4px; }
.note mark.active { background: var(--hl-active); box-shadow: 0 0 0 2px var(--hl-active); }
.note mark sup { font: 700 0.6875rem/1 var(--font-ui); margin-left: 3px; padding: 2px 4px; border-radius: var(--radius-tag);
                 background: var(--text); color: var(--paper); vertical-align: 6px; white-space: nowrap; }
.note mark.warning sup { background: var(--refused); color: var(--refused-bg); }
.note mark.notcoded sup { background: var(--text-muted); }

.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); font-size: var(--text-sm); color: var(--text-muted); margin: 0 0 var(--s2); }
.legend i { display: inline-block; width: 28px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--hl); }
.legend i.notcoded { background: var(--hl-not); border-bottom: 1px dashed var(--border-strong); }
.legend i.warning { background: var(--refused-bg); border-bottom: 2px solid var(--refused); }

/* One card per code, payer flag or "not coded" item */
.card.item { padding: var(--s3) var(--s4); margin-top: var(--s3); border-left-width: 6px; cursor: pointer; }
.card.item.flag { cursor: default; }
.card.item.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.card.item.denial  { border-left-color: var(--refused); }
.card.item.reduced { border-left-color: var(--review); }
.card.item.unknown { border-left-color: var(--review); border-left-style: dashed; }
.card.item.none    { border-left-color: var(--passed); }
.card .head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-bottom: var(--s1); }
.card .head .code { font-size: var(--text-lg); }

/* A quote from the note, shown as highlighted text in the note's own typeface */
blockquote { margin: var(--s2) 0 0; padding: 0; font: 1rem/1.8 var(--font-note); }
blockquote span { background: var(--hl); padding: 3px 4px; border-radius: 2px;
                  -webkit-box-decoration-break: clone; box-decoration-break: clone; }
blockquote.notcoded span { background: var(--hl-not); }
blockquote.warning span { background: transparent; text-decoration: underline wavy var(--refused); text-underline-offset: 4px; padding: 0; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px var(--s3); margin: var(--s2) 0; font-size: var(--text-sm); }
dl.kv dt { color: var(--text-muted); }
dl.kv dd { margin: 0; }
.fix { margin-top: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--radius); background: var(--surface-2); font-size: var(--text-sm); }

/* Review form */
.decision { margin-top: var(--s6); border-top: 4px solid var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s2) 0; }
.chip { display: inline-flex; align-items: center; padding-left: var(--s3); border: 1px solid var(--border-strong);
        border-radius: var(--radius); background: var(--surface-2); }
.chip.added { border-color: var(--accent); background: var(--surface); box-shadow: inset 0 0 0 1px var(--accent); }
.chip button { min-width: 44px; padding: 0; border: 0; background: transparent; color: var(--text-muted); }
.row { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: end; margin-top: var(--s3); }
.row label { display: flex; flex-direction: column; gap: var(--s1); font-size: var(--text-sm); color: var(--text-muted); font-weight: 600; }

/* History: a timeline, oldest first */
ol.history { list-style: none; padding: 0; margin: var(--s2) 0 0 var(--s2); border-left: 2px solid var(--border-strong); }
ol.history li { position: relative; padding: 0 0 var(--s4) var(--s5); }
ol.history li::before { content: ""; position: absolute; left: -8px; top: 6px; width: 10px; height: 10px; border-radius: 50%;
                        background: var(--surface); border: 2px solid var(--border-strong); }
ol.history li.human::before { background: var(--accent); border-color: var(--accent); }

/* Coder assists */
kbd { display: inline-block; min-width: 1.6em; padding: 0 6px; text-align: center; border: 1px solid var(--border-strong);
      border-bottom-width: 2px; border-radius: var(--radius-tag); background: var(--surface); font: 600 var(--text-xs)/1.6 var(--font-ui); color: var(--text); }
.keys { margin-top: var(--s3); }
.bulk { align-items: center; margin-bottom: var(--s2); }
table.queue tbody tr:focus { background: var(--neutral-bg); }
.context h3 { margin-top: var(--s4); }
.context table { margin-top: var(--s2); font-size: var(--text-sm); }
.context td, .context th { padding: var(--s2) var(--s3); }
.context tr.same-day { background: var(--refused-bg); }

/* Narrow screens: wide tables scroll sideways inside their own box instead of breaking the page. */
@media (max-width: 900px) { table { display: block; overflow-x: auto; } }
td a[href^="#/visit/"] { white-space: nowrap; }
@media (max-width: 900px) { table.queue td { min-width: 120px; } table.queue td:last-child { min-width: 260px; } }

/* ------------------------------------------------------------------ 6. Copilot dock (static/copilot.js)
   A chat panel fixed to the right edge. Wide screens: the page makes room for it. Medium: it slides over
   the page. Phones: a full-screen sheet. The header is the one dark surface in the product. */
[hidden] { display: none !important; }
:root { --dock: 400px; }
#copilot { position: fixed; inset: 0 0 0 auto; width: var(--dock); max-width: 100vw; z-index: 30; display: flex; flex-direction: column;
           background: var(--surface); border-left: 1px solid var(--border-strong);
           box-shadow: -18px 0 36px -28px oklch(26% 0.03 225 / 0.55); }
@media (min-width: 1101px) { body.dock-open { padding-right: var(--dock); } }
@media (max-width: 700px) { #copilot { width: 100vw; border-left: 0; } }

#copilot > header { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 57px;
                    padding: 0 var(--s2) 0 var(--s4); background: oklch(26% 0.03 225); color: oklch(96% 0.006 220); }
#copilot > header strong { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--text-lg); letter-spacing: -0.01em; }
#copilot > header strong::before { content: ""; width: 12px; height: 20px; border-radius: 2px; background: oklch(85% 0.16 88);
                                   box-shadow: inset 0 -4px 0 oklch(78% 0.09 200); }
#copilot .looking { margin-left: var(--s3); font-size: var(--text-sm); color: oklch(82% 0.02 220); }
#copilot .close { min-width: 44px; font-weight: 500; border: 0; background: transparent; color: inherit; }
#copilot .close:hover { background: oklch(34% 0.03 225); }

#copilot .log { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); background: var(--surface-2); }
#copilot .empty h2 { margin: var(--s4) 0 var(--s1); font-size: var(--text-xl); }
#copilot .prompt { display: block; width: 100%; text-align: left; margin-top: var(--s2); font-weight: 500;
                   border-color: var(--border); border-left: 4px solid var(--hl-active); }
#copilot .prompt:hover { border-color: var(--accent); border-left-color: var(--accent); }

.msg { max-width: 92%; padding: var(--s3) var(--s4); border-radius: var(--radius-card); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: var(--radius-tag); white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: var(--radius-tag); }
.msg.assistant .text { white-space: pre-wrap; }
.msg.assistant.off { border-color: var(--review); background: var(--review-bg); }
.msg .extras { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s3); }
.msg .extras:empty { display: none; }

/* A citation: a piece of the note, in the note's typeface and highlighter colour */
.cites { display: flex; flex-direction: column; gap: var(--s2); align-items: flex-start; }
.cite { min-height: 44px; text-align: left; font: 0.9375rem/1.5 var(--font-note); font-weight: 400; padding: var(--s1) var(--s2);
        background: var(--hl); border: 0; border-left: 3px solid var(--hl-active); border-radius: 2px; color: var(--text); }
.cite:hover:not(:disabled) { background: var(--hl-active); }
.cite b { font-family: var(--font-ui); }
.cite.unverified { background: var(--review-bg); border-left-color: var(--review); text-decoration: line-through; }
::highlight(cite) { background-color: oklch(78% 0.17 62); color: oklch(20% 0.03 225); }

/* A proposed action: waits for a click */
.action-card { padding: var(--s3); border: 1px dashed var(--accent); border-radius: var(--radius); background: var(--surface-2); }
.action-card .label { font-weight: 650; }
.action-card .row { margin-top: var(--s2); align-items: center; }

.trace { font-size: var(--text-sm); color: var(--text-muted); }
.trace summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.trace ol { margin: var(--s1) 0 0; padding-left: 20px; }
.trace li { margin-bottom: var(--s1); overflow-wrap: anywhere; }

.msg.typing { display: flex; gap: 6px; padding: var(--s4); }
.msg.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
@media (prefers-reduced-motion: no-preference) {
  .msg.typing i { animation: copilot-dot 1.1s infinite ease-in-out; }
  .msg.typing i:nth-child(2) { animation-delay: 0.15s; }
  .msg.typing i:nth-child(3) { animation-delay: 0.3s; }
}
@keyframes copilot-dot { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

#copilot > footer { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); background: var(--surface); }
#copilot .composer { display: flex; gap: var(--s2); align-items: flex-end; }
#copilot .composer textarea { min-height: 44px; resize: none; }
#copilot footer p { margin: var(--s2) 0 0; }

.copilot-tab { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 25; min-height: 48px; padding: 0 var(--s5);
               border-radius: 999px; border: 0; background: oklch(26% 0.03 225); color: oklch(96% 0.006 220);
               box-shadow: 0 10px 24px -10px oklch(26% 0.03 225 / 0.7); display: inline-flex; align-items: center; gap: var(--s2); }
.copilot-tab::before { content: ""; width: 10px; height: 16px; border-radius: 2px; background: oklch(85% 0.16 88); }
.copilot-tab:hover:not(:disabled) { background: oklch(34% 0.03 225); }

/* AI agent section on the visit */
.agent h3 { margin-top: var(--s4); }
.agent-code { padding: var(--s2) 0; border-top: 1px solid var(--border); }
.agent-code .cites { margin-top: var(--s1); }
.agent textarea, .action-card textarea { margin-top: var(--s2); font: 0.9375rem/1.5 var(--font-ui); }
div.tile { background: var(--surface); border: 1px solid var(--border); }

/* Clarifying questions */
.questions { margin-top: var(--s4); }
.questions h2 { margin-top: var(--s4); }
.card.item.question { cursor: default; }
.question .cites { margin: var(--s2) 0; }
.question .row { align-items: center; }

/* ------------------------------------------------------------------ 7. First impression, loading, confirmations */
.lead { font-size: var(--text-lg); line-height: 1.5; max-width: 70ch; color: var(--text); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0; margin: var(--s4) 0 var(--s2);
        background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); overflow: hidden; }
.kpi { padding: var(--s4) var(--s5); border-left: 6px solid var(--border-strong); display: flex; flex-direction: column; gap: var(--s1); }
.kpi strong { font-size: 2.488rem; line-height: 1; font-weight: 650; letter-spacing: -0.02em; }
.kpi span { color: var(--text-muted); }
.kpi.refused { border-left-color: var(--refused); }  .kpi.refused strong { color: var(--refused); }
.kpi.review  { border-left-color: var(--review); }   .kpi.review strong  { color: var(--review); }
.kpi.passed  { border-left-color: var(--passed); }   .kpi.passed strong  { color: var(--passed); }

.skel { max-width: 100%; margin-top: var(--s3); border-radius: var(--radius); background: var(--neutral-bg); }
.tiles .skel { margin-top: 0; }

.toast { position: fixed; left: var(--s5); bottom: var(--s5); z-index: 40; max-width: min(520px, calc(100vw - 2 * var(--s5)));
         padding: var(--s3) var(--s4); border-radius: var(--radius); background: oklch(26% 0.03 225); color: oklch(96% 0.006 220);
         border-left: 6px solid oklch(82% 0.10 155); box-shadow: 0 10px 24px -10px oklch(26% 0.03 225 / 0.7); }

.skip { position: absolute; left: var(--s4); top: -100px; z-index: 50; padding: var(--s3) var(--s4); background: var(--surface);
        border: 2px solid var(--accent); border-radius: var(--radius); }
.skip:focus { top: var(--s2); }

@media (prefers-reduced-motion: no-preference) {
  .skel { animation: skel-pulse 1.2s infinite ease-in-out; }
  .toast:not([hidden]) { animation: rise 0.18s ease-out; }
  #copilot:not([hidden]) { animation: dock-in 0.2s ease-out; }
  .card.item, .tile, button { transition: border-color 0.12s, box-shadow 0.12s, background-color 0.12s; }
}
@keyframes skel-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes dock-in { from { transform: translateX(24px); opacity: 0; } }
.copilot-tab { border: 1px solid oklch(48% 0.03 225); }   /* stays visible on the dark theme */
#copilot > header > div { display: flex; align-items: center; min-width: 0; }
#copilot > header > div:last-child { flex: none; }
#copilot .looking { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ 8. Focus mode (#/review) */
.row.start { align-items: center; margin: var(--s4) 0 var(--s2); }
button.big { min-height: 56px; padding: var(--s3) var(--s5); font-size: var(--text-lg); }
.push { margin-left: auto; }
.review-bar { position: sticky; top: 0; z-index: 10; margin: calc(-1 * var(--s3)) 0 var(--s4); padding: var(--s2) 0 0; background: var(--bg); }
.review-bar .row { align-items: center; margin-top: 0; }
.review-bar progress { display: block; width: 100%; height: 8px; margin-top: var(--s2); border: 0; border-radius: 999px;
                       background: var(--neutral-bg); accent-color: var(--accent); overflow: hidden; }
.review-bar progress::-webkit-progress-bar { background: var(--neutral-bg); }
.review-bar progress::-webkit-progress-value { background: var(--accent); }
.review-bar progress::-moz-progress-bar { background: var(--accent); }
.review-actions { position: sticky; bottom: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; justify-content: flex-end;
                  margin-top: var(--s6); padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--border-strong);
                  border-bottom: 0; border-radius: var(--radius-card) var(--radius-card) 0 0; box-shadow: 0 -12px 24px -18px oklch(26% 0.03 225 / 0.5); }
.review-actions kbd { margin-left: var(--s1); }
button.primary kbd { background: transparent; color: inherit; border-color: currentColor; }
.tally { list-style: none; padding: 0; font-size: var(--text-lg); }
.tally strong { display: inline-block; min-width: 2.5em; font-size: var(--text-xl); }
body:has(.review-actions) .copilot-tab { bottom: 88px; }   /* sit above the action bar, not on top of Skip */

/* Scanned source page with evidence boxes */
.scan { position: relative; line-height: 0; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; background: oklch(99% 0 0); }
.scan img { width: 100%; height: auto; display: block; }
.scan .box { position: absolute; box-sizing: content-box; margin: -2px; padding: 2px; border-radius: 2px; cursor: pointer;
             background: oklch(91% 0.13 98 / 0.4); outline: 2px solid oklch(70% 0.16 88); }
.scan .box.low { outline: 2px dashed oklch(50% 0.17 27); }
.scan .box.active { background: oklch(85% 0.16 88 / 0.6); outline: 3px solid oklch(47% 0.085 205); }
.note-col { max-height: none; }
@media (min-width: 901px) { .note-col:has(.scan) { position: static; } }   /* note plus scan is too tall to stick */

/* Phones: the nav scrolls sideways on one line, and focus mode gives the screen back to the visit. */
@media (max-width: 700px) {
  .topbar { gap: 0; }
  .topbar nav { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .topbar nav a { white-space: nowrap; }
  .review-bar { position: static; }
  .review-actions { gap: var(--s2); padding: var(--s2); justify-content: space-between; }
  .review-actions kbd, .review-actions > span { display: none; }
  .review-actions button { padding: var(--s2) var(--s3); }
  body:has(.review-actions) .copilot-tab { bottom: 132px; }   /* the action bar wraps to two rows here */
}
#copilot .running { padding: var(--s1) var(--s4); font-size: var(--text-xs); color: oklch(82% 0.02 220); background: oklch(31% 0.03 225); }

/* ------------------------------------------------------------------ 9. First-run experience */
@media (max-width: 1439px) { :root { --dock: 360px; } }   /* laptops: a slimmer dock leaves room for the page */

/* "More" menu in the top bar */
.topbar nav { align-items: center; }
.topbar .more { position: relative; }
.topbar .more summary { display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s3); border-radius: var(--radius);
                        color: var(--text-muted); font-weight: 600; cursor: pointer; list-style: none; }
.topbar .more summary::-webkit-details-marker { display: none; }
.topbar .more summary::after { content: "▾"; margin-left: 6px; font-size: 0.8em; }
.topbar .more summary:hover, .topbar .more[open] summary { background: var(--neutral-bg); color: var(--text); }
.topbar .more .menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 35; min-width: 220px; padding: var(--s2);
                      display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-strong);
                      border-radius: var(--radius-card); box-shadow: 0 16px 32px -16px oklch(26% 0.03 225 / 0.55); }
.topbar .who { margin-left: auto; min-height: 36px; padding: 0 var(--s3); border-radius: 999px; font-size: var(--text-sm); font-weight: 600;
               border-color: var(--border); color: var(--text-muted); background: var(--surface-2); }
@media (max-width: 700px) { .topbar .more .menu { position: fixed; left: var(--s4); right: var(--s4); top: 110px; } .topbar nav { overflow: visible; flex-wrap: wrap; } }

/* Dialogs: initials, confirmations, shortcuts */
dialog.ask { width: min(460px, calc(100vw - 32px)); padding: var(--s5); border: 1px solid var(--border-strong); border-radius: var(--radius-card);
             background: var(--surface); color: var(--text); box-shadow: 0 24px 48px -20px oklch(26% 0.03 225 / 0.6); }
dialog.ask::backdrop { background: oklch(26% 0.03 225 / 0.45); }
dialog.ask h2 { margin-top: 0; }
dialog.ask input { width: 100%; }
dialog.ask table { font-size: var(--text-sm); }
dialog.ask td { padding: var(--s2) var(--s3); }
dialog.ask td:first-child { white-space: nowrap; }

/* First-visit guide */
.guide { margin: var(--s3) 0; padding: var(--s4) var(--s5); border-radius: var(--radius-card); background: var(--surface);
         border: 1px solid var(--accent); border-left-width: 6px; }
.guide ol { margin: var(--s2) 0 var(--s3); padding-left: 20px; }
.guide li { margin-bottom: var(--s1); max-width: 80ch; }

.verdict .ask-why { grid-column: 2; justify-self: start; margin-top: var(--s2); min-height: 36px; padding: 0 var(--s3); font-size: var(--text-sm);
                    background: transparent; border-color: currentColor; color: inherit; }
button.quiet { min-width: 44px; padding: 0; border-color: var(--border); color: var(--text-muted); font-weight: 700; }
.row.start { gap: var(--s3); }

/* ------------------------------------------------------------------ 10. Welcome, personas, folded sections */
.welcome { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 4fr); gap: var(--s5); margin-bottom: var(--s6); padding: var(--s5);
           border-radius: var(--radius-card); background: var(--surface); border: 1px solid var(--accent); border-top-width: 6px; }
@media (max-width: 1000px) { .welcome { grid-template-columns: minmax(0, 1fr); } }
.welcome h2 { margin-top: 0; font-size: var(--text-xl); }
.personas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s3); align-content: start; }
.personas > p { grid-column: 1 / -1; margin: 0; }
@media (max-width: 700px) { .personas { grid-template-columns: minmax(0, 1fr); } }
.persona { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s3) var(--s4); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.persona p { flex: 1; margin: 0; }

details.fold { margin-top: var(--s5); border-top: 1px solid var(--border); }
details.fold > summary { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); min-height: 48px; padding: var(--s2) 0; cursor: pointer; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "▸"; color: var(--text-muted); width: 1em; }
details.fold[open] > summary::before { content: "▾"; }
details.fold > summary h2 { margin: 0; }
details.fold > summary .hint { margin-left: auto; }
details.fold > summary:hover h2 { color: var(--accent); }
