/* =============================================================================
 * VCF Desk - one stylesheet, both themes, system fonts only, no remote assets.
 *
 * Structure:
 *   1.  Design tokens (dark default, light override)
 *   2.  Base elements + utilities
 *   3.  Top bar
 *   4.  Lane bar (Inspect / Interpret / Load)
 *   5.  Buttons + focus
 *   6.  Layout, hero, cards
 *   7.  Form controls, dropzone, run row, gates
 *   8.  Prescan
 *   9.  Progress
 *   10. Result head: verdict, headline, lane chip, facts, handoff
 *   11. Chips: severity, check status, readiness, metric reading, coverage
 *   12. Lane panes
 *   13. Findings, commands, copy buttons
 *   14. Gene cards
 *   15. Tables + exports
 *   16. Prescan reconciliation
 *   17. History, footer, toasts
 *   18. Docs pages (api.html, tokens.html)
 *   19. Responsive
 *   20. Print
 *   21. Reduced motion
 *
 * Every colour is a custom property declared in BOTH themes, so nothing goes
 * unreadable when the theme flips. The theme is set by /theme.js as a
 * data-theme attribute on :root; dark is the default and needs no attribute.
 * ========================================================================== */

/* -----------------------------------------------------------------------------
 * 1. Design tokens
 * -------------------------------------------------------------------------- */

:root {
  /* surfaces + ink */
  --bg: #0d1117;
  --panel: #161b22;
  --panel2: #1c2330;
  --code-bg: #0a0e14;
  --ink: #e6edf3;
  --ink-dim: #9aa7b4;
  --line: #2a3441;
  --line-soft: #212a35;

  /* semantic colour */
  --accent: #4c9aff;
  --accent-ink: #08131f;
  --ok: #3fb950;
  --ok-ink: #04160a;
  --warn: #d29922;
  --warn-ink: #1a1204;
  --bad: #f85149;
  --bad-ink: #1e0605;
  --crit: #ff6a60;
  --crit-ink: #2a0604;
  --info: #8fa3b8;
  --info-ink: #0c141c;

  /* translucent washes - declared per theme so nothing is hard-coded inline */
  --accent-wash: rgba(76, 154, 255, 0.10);
  --ok-wash: rgba(63, 185, 80, 0.10);
  --warn-wash: rgba(210, 153, 34, 0.10);
  --bad-wash: rgba(248, 81, 73, 0.10);
  --crit-wash: rgba(255, 106, 96, 0.14);
  --info-wash: rgba(143, 163, 184, 0.10);
  --shadow: rgba(0, 0, 0, 0.32);

  /* type + geometry */
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --pill: 20px;
}

/* theme.js always writes an explicit data-theme, so dark is restated here as
 * well as being the :root default - an attribute flip is then total either way. */
:root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c2330; --code-bg: #0a0e14;
  --ink: #e6edf3; --ink-dim: #9aa7b4; --line: #2a3441; --line-soft: #212a35;
  --accent: #4c9aff; --accent-ink: #08131f;
  --ok: #3fb950; --ok-ink: #04160a; --warn: #d29922; --warn-ink: #1a1204;
  --bad: #f85149; --bad-ink: #1e0605; --crit: #ff6a60; --crit-ink: #2a0604;
  --info: #8fa3b8; --info-ink: #0c141c;
  --accent-wash: rgba(76, 154, 255, 0.10); --ok-wash: rgba(63, 185, 80, 0.10);
  --warn-wash: rgba(210, 153, 34, 0.10); --bad-wash: rgba(248, 81, 73, 0.10);
  --crit-wash: rgba(255, 106, 96, 0.14); --info-wash: rgba(143, 163, 184, 0.10);
  --shadow: rgba(0, 0, 0, 0.32);
}

:root[data-theme="light"] {
  --bg: #f6f8fa;
  --panel: #ffffff;
  --panel2: #f0f3f6;
  --code-bg: #f4f6f9;
  --ink: #1f2328;
  --ink-dim: #5b6570;
  --line: #d8dee4;
  --line-soft: #e6eaee;
  --accent: #0969da;
  --accent-ink: #ffffff;
  --ok: #1a7f37;
  --ok-ink: #ffffff;
  --warn: #9a6700;
  --warn-ink: #ffffff;
  --bad: #cf222e;
  --bad-ink: #ffffff;
  --crit: #96101f;
  --crit-ink: #ffffff;
  --info: #4d5a68;
  --info-ink: #ffffff;
  --accent-wash: rgba(9, 105, 218, 0.07);
  --ok-wash: rgba(26, 127, 55, 0.08);
  --warn-wash: rgba(154, 103, 0, 0.09);
  --bad-wash: rgba(207, 34, 46, 0.07);
  --crit-wash: rgba(150, 16, 31, 0.09);
  --info-wash: rgba(77, 90, 104, 0.07);
  --shadow: rgba(31, 35, 40, 0.14);
}

/* -----------------------------------------------------------------------------
 * 2. Base elements + utilities
 * -------------------------------------------------------------------------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  overflow-x: hidden; /* nothing in this app may scroll the page sideways */
}

h1, h2, h3 { overflow-wrap: break-word; }

code, pre, .mono { font-family: var(--mono); }
.mono { font-size: 0.92em; }
.small { font-size: 0.85em; }
.muted { color: var(--ink-dim); }
.hidden { display: none !important; }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

em { font-style: italic; }

p code, li code, td code, .lede code, .explain code {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 0.88em;
  overflow-wrap: break-word;
}

/* -----------------------------------------------------------------------------
 * 3. Top bar
 * -------------------------------------------------------------------------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 20;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.brand strong { white-space: nowrap; }
.brand .sep { color: var(--ink-dim); }
.backlink { text-decoration: none; white-space: nowrap; }
.topactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.credits { font-family: var(--mono); font-size: 0.85em; color: var(--ink-dim); }
.topup {
  font-size: 0.85em; padding: 4px 10px; white-space: nowrap;
  border: 1px solid var(--line); border-radius: var(--radius-sm); text-decoration: none;
}
.topup:hover { border-color: var(--accent); text-decoration: none; }

/* -----------------------------------------------------------------------------
 * 4. Lane bar - the three lanes over the same file
 *
 * This sits directly under the header and is visible before sign-in. It has to
 * read as one instrument with three stages, not as three separate products, so:
 * the whole strip shares a single surface and border, the tabs are equal width,
 * and a drawn chevron between the groups carries the Inspect -> Interpret ->
 * Load progression. It never wraps: it scrolls inside itself on narrow screens
 * so the page itself never scrolls sideways.
 * -------------------------------------------------------------------------- */

.lanebar {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 0;
  padding: 10px 20px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.lanegroup {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  flex: 1 1 14rem; min-width: 11.5rem;
}
.lanegroup + .lanegroup { padding-left: 22px; }

/* the drawn chevron - no unicode, no image, so nothing can fail to load */
.lanegroup + .lanegroup::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 58%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--line);
  border-top: 2px solid var(--line);
  transform: translateY(-50%) rotate(45deg);
}

.lanestage {
  font-family: var(--mono); font-size: 0.68rem; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--ink-dim); padding-left: 2px; white-space: nowrap;
}

.lanetab {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  height: 100%;
  text-align: left;
  background: var(--panel2);
  color: var(--ink-dim);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px 9px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.lanetab strong {
  font-size: 0.97rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.3;
}
.lanetab span {
  font-size: 0.8rem;
  line-height: 1.35;
  color: var(--ink-dim);
}
.lanetab:hover {
  background: var(--bg);
  border-color: var(--accent);
  border-left-color: var(--accent);
}
.lanetab.active,
.lanetab[aria-pressed="true"],
.lanetab[aria-selected="true"] {
  background: var(--accent-wash);
  border-color: var(--accent);
  border-left-color: var(--accent);
  color: var(--ink);
}
.lanetab.active strong,
.lanetab[aria-pressed="true"] strong,
.lanetab[aria-selected="true"] strong { font-weight: 700; }
.lanetab.active span,
.lanetab[aria-pressed="true"] span,
.lanetab[aria-selected="true"] span { color: var(--ink); }
.lanetab:disabled { opacity: 0.5; cursor: not-allowed; }

/* -----------------------------------------------------------------------------
 * 5. Buttons + focus
 * -------------------------------------------------------------------------- */

button { font-family: inherit; font-size: 1em; cursor: pointer; }

.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 11px;
}
.ghost:hover { background: var(--panel2); border-color: var(--accent); }

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 11px 22px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }

.big {
  background: var(--panel2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
}
.big:hover { border-color: var(--accent); }

.mini {
  background: var(--panel2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.85em;
}
.mini:hover { border-color: var(--accent); }
.mini:disabled { opacity: 0.5; cursor: not-allowed; }

.linkish {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: inherit;
  text-decoration: underline;
}
.linkish:hover { color: var(--ink); }

/* one focus treatment for everything that can take focus */
a:focus-visible,
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.lanetab:focus-visible { outline-offset: 3px; }
.histbtn:focus-visible,
.copybtn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* -----------------------------------------------------------------------------
 * 6. Layout, hero, cards
 * -------------------------------------------------------------------------- */

main { max-width: 1000px; margin: 0 auto; padding: 24px 20px 60px; }

.hero h1 { font-size: 1.9rem; line-height: 1.25; margin: 14px 0 10px; }
.lede { font-size: 1.05rem; color: var(--ink); max-width: 74ch; }
.herobtns { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 8px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 18px 0;
}
.card h2 { font-size: 1.15rem; margin: 0 0 10px; }
.card h3 { font-size: 1.05rem; margin: 0 0 10px; }
.card > ul, .card > ol { margin: 8px 0 0; padding-left: 20px; }
.card > ul li, .card > ol li { margin: 4px 0; max-width: 80ch; overflow-wrap: break-word; }
.card > ul:empty, .card > ol:empty { display: none; }

.count {
  font-family: var(--mono); font-size: 0.8em; font-weight: 400; color: var(--ink-dim);
  border: 1px solid var(--line); border-radius: var(--pill);
  padding: 1px 9px; margin-left: 6px; white-space: nowrap;
}
/* a count the script has not filled in yet must not show as an empty pill */
.count:empty { display: none; }

.prose p { margin: 10px 0; max-width: 80ch; }
.prose p:first-child { margin-top: 0; }
.prose p:last-child { margin-bottom: 0; }

.explain p { max-width: 78ch; }

/* -----------------------------------------------------------------------------
 * 7. Form controls, dropzone, run row, gates
 * -------------------------------------------------------------------------- */

.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field > p { margin: 6px 0 0; }

.labelrow {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap; margin-bottom: 6px;
}
.labelrow label { font-weight: 600; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row .field { flex: 1 1 260px; min-width: 0; }

textarea, select,
input[type="text"], input[type="search"], input[type="file"] {
  width: 100%; max-width: 100%; padding: 10px;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  font-family: var(--mono); font-size: 0.88rem; line-height: 1.5;
}
select { font-family: var(--sans); font-size: 0.95rem; }
input[type="text"], input[type="search"] { font-size: 0.9rem; }
textarea { resize: vertical; min-height: 4.5rem; }
textarea::placeholder,
input::placeholder { color: var(--ink-dim); opacity: 1; }
textarea:focus,
select:focus,
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.dropzone {
  border: 1px dashed transparent;
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragging { border-color: var(--accent); background: var(--accent-wash); }
.droprow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.droprow input[type="file"] { width: auto; flex: 0 1 auto; font-size: 0.8rem; padding: 4px; }
.droprow > span { flex: 1 1 16rem; min-width: 0; }

.runrow { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 6px; }

.rungate {
  margin: 10px 0 0; padding: 10px 12px; font-size: 0.92em;
  border: 1px solid var(--warn); border-radius: 8px; background: var(--warn-wash);
}
.gateaction { font-weight: 600; cursor: pointer; margin-left: 6px; }

.warnline {
  border: 1px solid var(--warn); border-radius: 8px; padding: 9px 12px;
  background: var(--warn-wash); overflow-wrap: break-word;
}
.warnline ul { margin: 6px 0 0; padding-left: 18px; }
.warnline li { margin: 2px 0; word-break: break-word; }

.delta {
  border: 1px solid var(--accent); border-radius: 8px; padding: 9px 12px;
  background: var(--accent-wash); font-size: 0.92em;
}

/* -----------------------------------------------------------------------------
 * 8. Prescan - the free in-browser VCF reader's own output
 * -------------------------------------------------------------------------- */

.prescan {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; background: var(--panel2); margin-bottom: 14px;
}
.prescan h2 { font-size: 1rem; margin: 0 0 6px; }
.prescan > p { margin: 4px 0 0; overflow-wrap: break-word; }

.flaglist { list-style: none; padding: 0; margin: 8px 0 0; }
.flaglist li {
  padding: 7px 0;
  border-top: 1px solid var(--line);
  font-size: 0.92em;
  overflow-wrap: break-word;
}
.flaglist li:first-child { border-top: none; }
.flaglist li p { margin: 3px 0 0; }
.flagid {
  display: inline-block; padding: 0 5px; margin-right: 6px; white-space: nowrap;
  background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
  font-family: var(--mono); font-size: 0.82em; color: var(--ink-dim);
}

/* the reader's per-flag severity, shown as a left rule on the row */
.flaglist li.sev-blocker { box-shadow: inset 3px 0 0 var(--crit); padding-left: 9px; }
.flaglist li.sev-high { box-shadow: inset 3px 0 0 var(--bad); padding-left: 9px; }
.flaglist li.sev-medium { box-shadow: inset 3px 0 0 var(--warn); padding-left: 9px; }
.flaglist li.sev-low { box-shadow: inset 3px 0 0 var(--line); padding-left: 9px; }
.flaglist li.sev-info { box-shadow: inset 3px 0 0 var(--info); padding-left: 9px; }

/* the header inventory the reader lists (contigs, INFO, FORMAT declarations) */
.reslist { list-style: none; padding: 0; margin: 8px 0 0; }
.reslist li {
  padding: 5px 0;
  border-top: 1px solid var(--line);
  font-size: 0.88em;
  color: var(--ink-dim);
  overflow-wrap: break-word;
}
.reslist li:first-child { border-top: none; }

/* -----------------------------------------------------------------------------
 * 9. Progress
 * -------------------------------------------------------------------------- */

.progress { border-color: var(--line); }
.progresshead {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px; flex-wrap: wrap;
}
.steps { list-style: none; padding: 0; margin: 12px 0 0; }
.step { display: flex; align-items: center; gap: 10px; padding: 5px 0; color: var(--ink-dim); }
.step-ic {
  width: 11px; height: 11px; flex: 0 0 auto;
  border: 2px solid var(--line); border-radius: 50%;
}
.step.done { color: var(--ink); }
.step.done .step-ic { background: var(--ok); border-color: var(--ok); }
.step.live { color: var(--ink); }
.step.live .step-ic {
  border-color: var(--accent);
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}
.step.fail { color: var(--ink); }
.step.fail .step-ic { background: var(--bad); border-color: var(--bad); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* -----------------------------------------------------------------------------
 * 10. Result head: lane chip, verdict, headline, facts, handoff
 * -------------------------------------------------------------------------- */

.result { scroll-margin-top: 80px; }
.resulthead h2 { font-size: 1.35rem; margin: 4px 0 0; }

/* which lane produced what is on screen */
.lanechip {
  display: inline-block; margin: 0; padding: 1px 10px; white-space: nowrap;
  font-family: var(--mono); font-size: 0.7rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--accent); background: var(--accent-wash);
  border: 1px solid var(--accent); border-radius: var(--pill);
}
.lanechip:empty { display: none; }

.verdict {
  font-size: 1.03rem;
  border-left: 3px solid var(--line);
  padding-left: 12px;
  margin: 10px 0;
  overflow-wrap: break-word;
}
.verdict:empty { display: none; }
/* generic tone hooks */
.verdict.good, .verdict.tone-ok { border-left-color: var(--ok); }
.verdict.warn, .verdict.tone-warn { border-left-color: var(--warn); }
.verdict.bad, .verdict.tone-bad { border-left-color: var(--bad); }
.verdict.crit, .verdict.tone-crit { border-left-color: var(--crit); }

/* triage verdicts */
.verdict.v-release { border-left-color: var(--ok); }
.verdict.v-filter { border-left-color: var(--warn); }
.verdict.v-recall { border-left-color: var(--bad); }
/* interpret verdicts */
.verdict.v-ready-to-prioritise { border-left-color: var(--ok); }
.verdict.v-annotate-first { border-left-color: var(--warn); }
.verdict.v-not-interpretable { border-left-color: var(--bad); }
/* cohort verdicts */
.verdict.v-ingest { border-left-color: var(--ok); }
.verdict.v-fix-first { border-left-color: var(--warn); }
.verdict.v-do-not-ingest { border-left-color: var(--crit); }

/* the one sentence the user most needs - bigger than body, smaller than h2 */
.headline {
  font-size: 1.16rem; line-height: 1.45; font-weight: 500; color: var(--ink);
  margin: 10px 0 4px; max-width: 68ch; overflow-wrap: break-word;
}
.headline:empty { display: none; }

.sdkstrip {
  display: flex; align-items: flex-start; gap: 12px 18px; flex-wrap: wrap;
  margin: 14px 0; padding: 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel2);
}
.sdkbox { display: flex; flex-direction: column; min-width: 5.5rem; flex: 0 1 auto; }
.sdkbox strong { font-size: 1.16rem; line-height: 1.3; overflow-wrap: break-word; }
.sdkbox strong:empty::before { content: "-"; color: var(--ink-dim); }
.sdkarrow { color: var(--ink-dim); font-size: 1.3rem; }

/* "run the next lane on this file" - separated from the summary above it */
.handoffrow {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
}
.handoffrow > span:first-child { flex: 0 0 auto; }

/* -----------------------------------------------------------------------------
 * 11. Chips
 *
 * One geometry, several vocabularies. `.chip` is the base; `.sev`, `.badge` and
 * `.tag` are aliases so markup can read naturally (class="chip sev-blocker" or
 * class="sev sev-blocker" both work). Modifiers are always written scoped to a
 * base class, so putting `.sev-blocker` on a card colours the card's rule and
 * not its background.
 *
 * Ranking is carried by fill as well as hue: a blocker is a solid chip, high is
 * an outlined red one. That keeps the order readable to anyone who cannot
 * separate the two reds.
 * -------------------------------------------------------------------------- */

.chip, .sev, .badge, .tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  line-height: 1.7;
  border: 1px solid var(--line);
  border-radius: var(--pill);
  padding: 0 8px;
  color: var(--ink-dim);
  background: transparent;
  white-space: nowrap;
}
.chip:empty, .sev:empty, .badge:empty, .tag:empty { display: none; }

/* severity ------------------------------------------------------------------ */
.chip.sev-blocker, .sev.sev-blocker, .badge.sev-blocker, .tag.sev-blocker
  { color: var(--crit-ink); background: var(--crit); border-color: var(--crit); font-weight: 700; }
.chip.sev-high, .sev.sev-high, .badge.sev-high, .tag.sev-high
  { color: var(--bad); background: var(--bad-wash); border-color: var(--bad); }
.chip.sev-medium, .sev.sev-medium, .badge.sev-medium, .tag.sev-medium
  { color: var(--warn); background: var(--warn-wash); border-color: var(--warn); }
.chip.sev-low, .sev.sev-low, .badge.sev-low, .tag.sev-low
  { color: var(--ink-dim); background: transparent; border-color: var(--line); }
.chip.sev-info, .sev.sev-info, .badge.sev-info, .tag.sev-info
  { color: var(--info); background: var(--info-wash); border-color: var(--info); }

/* check status -------------------------------------------------------------- */
.chip.st-pass, .badge.st-pass, .tag.st-pass
  { color: var(--ok); background: var(--ok-wash); border-color: var(--ok); }
.chip.st-fail, .badge.st-fail, .tag.st-fail
  { color: var(--bad); background: var(--bad-wash); border-color: var(--bad); }
.chip.st-partial, .badge.st-partial, .tag.st-partial
  { color: var(--warn); background: var(--warn-wash); border-color: var(--warn); }
.chip.st-unknown, .badge.st-unknown, .tag.st-unknown
  { color: var(--ink-dim); background: transparent; border-color: var(--line); }

/* ingestion readiness ------------------------------------------------------- */
.chip.st-ready, .badge.st-ready, .tag.st-ready
  { color: var(--ok); background: var(--ok-wash); border-color: var(--ok); }
.chip.st-blocked, .badge.st-blocked, .tag.st-blocked
  { color: var(--bad); background: var(--bad-wash); border-color: var(--bad); }

/* metric readings ----------------------------------------------------------- */
.chip.rd-consistent, .badge.rd-consistent, .tag.rd-consistent
  { color: var(--ok); background: var(--ok-wash); border-color: var(--ok); }
.chip.rd-borderline, .badge.rd-borderline, .tag.rd-borderline
  { color: var(--warn); background: var(--warn-wash); border-color: var(--warn); }
.chip.rd-inconsistent, .badge.rd-inconsistent, .tag.rd-inconsistent
  { color: var(--bad); background: var(--bad-wash); border-color: var(--bad); }
.chip.rd-na, .badge.rd-na, .tag.rd-na
  { color: var(--ink-dim); background: transparent; border-color: var(--line);
    text-transform: none; letter-spacing: 0.02em; }

/* prescan flag handling ----------------------------------------------------- */
.chip.cov-addressed, .badge.cov-addressed, .tag.cov-addressed
  { color: var(--ok); background: var(--ok-wash); border-color: var(--ok); }
.chip.cov-set-aside, .badge.cov-set-aside, .tag.cov-set-aside
  { color: var(--warn); background: var(--warn-wash); border-color: var(--warn); }
/* a flag the model never mentioned - this one must be impossible to miss */
.chip.cov-missing, .badge.cov-missing, .tag.cov-missing
  { color: var(--crit-ink); background: var(--crit); border-color: var(--crit); font-weight: 700; }

/* confidence + risk, used by the shortlist and the plans -------------------- */
.chip.cf-high, .badge.cf-high { color: var(--ok); border-color: var(--ok); }
.chip.cf-medium, .badge.cf-medium { color: var(--warn); border-color: var(--warn); }
.chip.cf-low, .badge.cf-low { color: var(--ink-dim); border-color: var(--line); }
.chip.rk-high, .badge.rk-high { color: var(--bad); border-color: var(--bad); }
.chip.rk-medium, .badge.rk-medium { color: var(--warn); border-color: var(--warn); }
.chip.rk-low, .badge.rk-low { color: var(--ok); border-color: var(--ok); }
.chip.area, .badge.area, .tag.area { text-transform: lowercase; letter-spacing: 0.02em; }

/* -----------------------------------------------------------------------------
 * 12. Lane panes
 * -------------------------------------------------------------------------- */

.pane { display: block; }
.pane > .card:first-child { margin-top: 18px; }

/* -----------------------------------------------------------------------------
 * 13. Findings
 *
 * One card shape serves triage findings, cohort blockers, filter steps, ingest
 * steps and lookup rows: a head line with ids and chips, a meta line of small
 * facts, a body of prose, and any number of command blocks.
 * -------------------------------------------------------------------------- */

.finding {
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px;
  padding: 12px 14px; margin-bottom: 12px; background: var(--panel2);
}
.finding:last-child { margin-bottom: 0; }

.finding.sev-blocker { border-left-color: var(--crit); }
.finding.sev-high { border-left-color: var(--bad); }
.finding.sev-medium { border-left-color: var(--warn); }
.finding.sev-low { border-left-color: var(--line); }
.finding.sev-info { border-left-color: var(--info); }
/* the same shape when it is an ordered plan step rather than a defect */
.finding.step-card { border-left-color: var(--accent); }
.finding.rk-high { border-left-color: var(--bad); }
.finding.rk-medium { border-left-color: var(--warn); }
.finding.rk-low { border-left-color: var(--ok); }

.findinghead {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px;
}
.findinghead strong {
  font-size: 1rem; line-height: 1.35; flex: 1 1 14rem; min-width: 0; overflow-wrap: break-word;
}
.findinghead code, .findinghead .fid {
  font-family: var(--mono); font-size: 0.82em; font-weight: 700;
  color: var(--ink-dim); white-space: nowrap;
}
.findinghead .ord {
  font-family: var(--mono); font-weight: 700; color: var(--accent); white-space: nowrap;
}
.findinghead .chip,
.findinghead .sev,
.findinghead .badge { flex: 0 0 auto; }

.findingmeta {
  display: flex; align-items: baseline; gap: 6px 12px; flex-wrap: wrap;
  margin: 2px 0 8px; font-size: 0.85em; color: var(--ink-dim); overflow-wrap: break-word;
}
.findingmeta code { font-size: 0.95em; overflow-wrap: break-word; }

.findingbody { font-size: 0.95em; }
.findingbody p { margin: 6px 0; max-width: 80ch; overflow-wrap: break-word; }
.findingbody p:first-child { margin-top: 0; }
.findingbody ul { margin: 6px 0; padding-left: 20px; }
.findingbody li { margin: 3px 0; overflow-wrap: break-word; }
.flabel { color: var(--ink-dim); font-weight: 600; }

/* a shell one-liner. Scrolls inside itself; the page never moves. */
.cmd {
  display: block; margin: 8px 0 0; padding: 8px 10px; max-width: 100%;
  background: var(--code-bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 0.83rem; line-height: 1.5;
  white-space: pre; overflow-x: auto; overflow-y: hidden;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.cmd + .cmd { margin-top: 6px; }

/* command with its own copy button beside it */
.cmdrow { display: flex; align-items: flex-start; gap: 8px; margin: 8px 0 0; }
.cmdrow .cmd { flex: 1 1 auto; min-width: 0; margin: 0; }

.copybtn {
  margin-left: auto; flex: 0 0 auto; align-self: flex-start; cursor: pointer;
  background: var(--panel); color: var(--ink-dim);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 2px 9px;
  font-family: var(--mono); font-size: 0.74rem; letter-spacing: 0.04em; text-transform: uppercase;
}
.copybtn:hover { color: var(--ink); border-color: var(--accent); }
.copybtn.done { color: var(--ok); border-color: var(--ok); }

/* preformatted blocks, including the raw-reply fallback */
pre.bigpre, pre.snippet {
  margin: 0; padding: 12px; max-width: 100%;
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px;
  font-size: 0.85rem; line-height: 1.5; white-space: pre;
  overflow-x: auto; overflow-y: auto; scrollbar-width: thin;
}
pre.bigpre { max-height: 30rem; }

/* -----------------------------------------------------------------------------
 * 14. Gene cards
 * -------------------------------------------------------------------------- */

.genecard {
  border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 8px;
  padding: 12px 14px; margin-bottom: 10px; background: var(--panel2);
}
.genecard:last-child { margin-bottom: 0; }
.genecard > header, .genehead {
  display: flex; align-items: baseline; gap: 8px 10px; flex-wrap: wrap; margin-bottom: 6px;
}
.genesym {
  font-family: var(--mono); font-size: 1.14rem; font-weight: 700;
  letter-spacing: 0.02em; color: var(--ink); overflow-wrap: break-word;
}
.genecount {
  font-family: var(--mono); font-size: 0.78rem; color: var(--ink-dim);
  border: 1px solid var(--line); border-radius: var(--pill); padding: 0 9px; white-space: nowrap;
}
.geneloci {
  font-family: var(--mono); font-size: 0.8rem; color: var(--ink-dim);
  margin: 6px 0 0; overflow-wrap: anywhere;
}
.genecard p { margin: 6px 0 0; font-size: 0.95em; max-width: 80ch; }
.genecard p:first-of-type { margin-top: 0; }
.geneunknown { color: var(--ink-dim); }

/* -----------------------------------------------------------------------------
 * 15. Tables + export rows
 * -------------------------------------------------------------------------- */

.tablewrap {
  overflow-x: auto; overflow-y: hidden; max-width: 100%;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
table.inv {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em;
  min-width: 40rem;
}
table.inv th, table.inv td {
  text-align: left; padding: 7px 9px; vertical-align: top;
  border-bottom: 1px solid var(--line); overflow-wrap: break-word;
}
table.inv th { color: var(--ink-dim); font-weight: 600; font-size: 0.85em; white-space: nowrap; }
table.inv tbody tr:last-child td { border-bottom: none; }
table.inv td.mono { font-family: var(--mono); font-size: 0.92em; }
table.inv td.num { font-family: var(--mono); text-align: right; white-space: nowrap; }
table.inv td.nowrap { white-space: nowrap; }
table.inv tr.row-fail td, table.inv tr.row-blocked td { background: var(--bad-wash); }
table.inv tr.row-partial td { background: var(--warn-wash); }

.exportrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.exportrow:last-child { margin-bottom: 0; }

.filterrow {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
.filterrow label { font-weight: 600; }
.filterrow select { width: auto; min-width: 10rem; flex: 0 1 14rem; }

/* -----------------------------------------------------------------------------
 * 16. Prescan reconciliation
 *
 * One row per flag the reader raised: its id, what the model did with it, and
 * the note. A missing row is the failure case and is styled as an alarm.
 * -------------------------------------------------------------------------- */

.covrow {
  display: flex; align-items: baseline; gap: 8px 10px; flex-wrap: wrap;
  padding: 8px 0; border-top: 1px solid var(--line); font-size: 0.92em;
}
.covrow:first-child { border-top: none; }
.covrow code,
.covrow .flagid { flex: 0 0 auto; }
.covrow .chip { flex: 0 0 auto; }
.covnote { flex: 1 1 18rem; min-width: 0; color: var(--ink-dim); overflow-wrap: break-word; }
.covwhere { font-family: var(--mono); font-size: 0.82em; color: var(--ink-dim); }

.covrow.cov-addressed code { color: var(--ok); }
.covrow.cov-set-aside code { color: var(--warn); }
.covrow.cov-missing {
  background: var(--crit-wash); border-left: 3px solid var(--crit);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 8px 8px 10px; margin-top: 4px;
}
.covrow.cov-missing code { color: var(--crit); font-weight: 700; }
.covrow.cov-missing .covnote { color: var(--ink); }

/* -----------------------------------------------------------------------------
 * 17. History, footer, toasts
 * -------------------------------------------------------------------------- */

.history { list-style: none; padding: 0; margin: 0 0 10px; }
.history li {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 9px 2px; border-top: 1px solid var(--line);
}
.history li:first-child { border-top: none; }
.history li .mini { margin-left: auto; }
.history li .chip { flex: 0 0 auto; }

.histbtn {
  flex: 1 1 16rem; min-width: 0; text-align: left; cursor: pointer;
  background: none; border: none; color: var(--ink); padding: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.histbtn:hover .histtitle { color: var(--accent); }
.histtitle { font-weight: 600; overflow-wrap: break-word; }
.histmeta { color: var(--ink-dim); font-size: 0.85em; }
.histload { margin: 0 0 10px 2px; }

.foot {
  border-top: 1px solid var(--line); padding: 20px;
  text-align: center; color: var(--ink-dim); font-size: 0.9em;
}
.foot p { margin: 6px auto; max-width: 80ch; }

.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(27rem, calc(100vw - 2rem));
}
.toast {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px;
  padding: 10px 14px; box-shadow: 0 6px 22px var(--shadow);
  font-size: 0.92em; transition: opacity 0.5s; overflow-wrap: break-word;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
.toast.gone { opacity: 0; }
.toast a { margin-left: 8px; font-weight: 600; }

/* -----------------------------------------------------------------------------
 * 18. Docs pages - api.html and tokens.html share this shell
 * -------------------------------------------------------------------------- */

.doc { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; }
.doc h1 { font-size: 1.7rem; line-height: 1.25; }
.doc h2 { font-size: 1.2rem; margin-top: 30px; }
.doc h3 { font-size: 1rem; margin-top: 22px; }
.doc p, .doc li { max-width: 80ch; overflow-wrap: break-word; }
.doc table { width: 100%; border-collapse: collapse; font-size: 0.9em; margin: 12px 0; }
.doc th, .doc td {
  text-align: left; padding: 7px 9px; vertical-align: top;
  border-bottom: 1px solid var(--line); overflow-wrap: break-word;
}
.doc th { color: var(--ink-dim); }
.doc code {
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px; font-size: 0.88em;
}
.doc pre {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; overflow-x: auto; font-size: 0.85rem; line-height: 1.5;
  max-width: 100%; scrollbar-width: thin;
}
.doc pre code { background: none; border: none; padding: 0; font-size: 1em; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 12px 0 0; }
.tab {
  background: var(--panel2); color: var(--ink-dim); cursor: pointer;
  border: 1px solid var(--line); border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 5px 12px; font-size: 0.85em;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.codegroup pre { border-radius: 0 8px 8px 8px; margin-top: 0; }
.codegroup pre[hidden] { display: none; }

.tokenrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.tokenbox {
  flex: 1 1 20rem; min-width: 0; min-height: 2.75rem;
  background: var(--code-bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  font-family: var(--mono); font-size: 0.85rem; word-break: break-all;
}
.statebox {
  border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; background: var(--panel2); margin: 12px 0;
}
.statebox p { margin: 4px 0 0; }

/* -----------------------------------------------------------------------------
 * 19. Responsive
 *
 * Checked down to 360px: the lane bar scrolls inside itself, .row stacks, the
 * header wraps rather than overflowing, and every table, command and pre block
 * keeps its own scrollbar so the document body never moves sideways.
 * -------------------------------------------------------------------------- */

@media (max-width: 860px) {
  .lanebar { padding: 10px 14px 12px; }
  .lanegroup { flex: 1 0 13rem; }
}

@media (max-width: 620px) {
  main { padding: 16px 14px 48px; }
  .doc { padding: 16px 14px 48px; }
  .topbar { padding: 10px 14px; }
  .hero h1 { font-size: 1.5rem; }
  .lede { font-size: 1rem; }
  .headline { font-size: 1.08rem; }
  .resulthead h2 { font-size: 1.2rem; }
  .card { padding: 14px; }
  .row { gap: 0; }
  .row .field { flex: 1 1 100%; }
  .herobtns .big { flex: 1 1 100%; }
  .sdkstrip { gap: 10px 14px; padding: 10px; }
  .sdkbox { flex: 1 1 42%; min-width: 0; }
  .sdkbox strong { font-size: 1.05rem; }
  .handoffrow .mini { flex: 1 1 100%; }
  .lanegroup { flex: 1 0 12rem; min-width: 12rem; }
  .lanetab span { font-size: 0.78rem; }
  table.inv { min-width: 34rem; }
}

@media (max-width: 420px) {
  .topbar { gap: 8px; }
  .topactions { gap: 6px; }
  .credits { font-size: 0.8em; }
  .hero h1 { font-size: 1.35rem; }
  .lanebar { padding: 8px 12px 10px; }
  .lanegroup { flex: 1 0 11rem; min-width: 11rem; }
  .lanegroup + .lanegroup { padding-left: 18px; }
  .lanetab { padding: 7px 10px 8px; }
  .lanetab strong { font-size: 0.92rem; }
  .finding, .genecard { padding: 10px 12px; }
  .cmd { font-size: 0.78rem; }
  .exportrow .mini { flex: 1 1 100%; }
  .toasts { right: 10px; bottom: 10px; left: 10px; max-width: none; }
}

/* -----------------------------------------------------------------------------
 * 20. Print - the result panels, on white, with the chrome removed
 * -------------------------------------------------------------------------- */

@media print {
  .topbar,
  .lanebar,
  .herobtns,
  .exportrow,
  .handoffrow,
  .toasts,
  form,
  .dropzone,
  .filterrow,
  #progressPanel,
  #historyZone,
  #how,
  .foot { display: none !important; }

  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
    overflow-x: visible;
  }
  main { max-width: none; padding: 0; }

  .card {
    background: #fff;
    border: 1px solid #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
    margin: 10pt 0;
    padding: 10pt;
  }
  .hero { break-after: avoid; }
  .pane { display: block !important; }
  .pane.hidden { display: none !important; }

  .finding, .genecard, .prescan, .sdkstrip, .statebox {
    background: #fff;
    border-color: #ccc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .cmd, pre.bigpre, pre.snippet {
    background: #f4f4f4;
    border-color: #ccc;
    color: #000;
    white-space: pre-wrap;
    overflow: visible;
    max-height: none;
  }
  .chip, .sev, .badge, .tag, .count, .lanechip, .genecount {
    color: #000 !important;
    background: #fff !important;
    border-color: #999 !important;
  }
  /* colour is gone on paper, so the two loudest states keep a heavier rule */
  .chip.sev-blocker, .sev.sev-blocker, .chip.cov-missing, .chip.st-fail, .chip.st-blocked {
    border-width: 2px !important;
    font-weight: 700;
  }
  .muted, .covnote, .histmeta, .findingmeta { color: #333; }
  .verdict { border-left-color: #666; }
  .covrow.cov-missing { background: #fff; border-left-color: #000; }
  .covrow.cov-missing code { color: #000; }
  .tablewrap { overflow: visible; }
  table.inv { min-width: 0; font-size: 9.5pt; }
  table.inv th, table.inv td { border-bottom-color: #ccc; }
  table.inv tr.row-fail td,
  table.inv tr.row-blocked td,
  table.inv tr.row-partial td { background: #fff; }
  a { color: #000; text-decoration: none; }
}

/* -----------------------------------------------------------------------------
 * 21. Reduced motion
 * -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
  .step.live .step-ic { opacity: 1; }
}
