/* ==========================================================================
   fraudgraph investigation console -- design system
   --------------------------------------------------------------------------
   A case file, not a dashboard. The product's claim is that a score is a
   reason to look and never a verdict, and that every conclusion carries its
   evidence. So the page is set like an investigation file: ink on paper,
   ruled sections, identifiers in type you would copy, and colour reserved
   for verdicts -- the only saturated marks on the page, used like stamps.

   Rules, so the next change does not undo this:
   * No colour literals outside the token blocks (print excepted). Every pair of text and
     surface tokens below measures >= 4.5:1 (WCAG AA) in both themes;
     tests/test_design_tokens.py and tests/test_frontend.py hold it to that.
   * Type scale is fixed: 12 13 14 16 20 26 34. Nothing smaller than 12px.
   * Spacing is a 4px scale: 4 8 12 16 24 32 48.
   * Two radii: 2px on controls and marks, 4px on containers.
   * A box means containment. Sections are separated by rules and space,
     not wrapped in cards.
   * Uppercase is used in exactly one component: the verdict stamp.
   * Motion only reports state. Two durations, one easing.
   ========================================================================== */

:root {
  /* surfaces */
  --paper: #f6f4ee;
  --sheet: #fffdf8;
  --wash: #ece8df;
  --rule: #dcd7cc;
  --rule-strong: #b8b1a3;
  --grid: #e6e1d7;
  --band: rgba(27, 26, 23, 0.05);

  /* ink */
  --ink: #1b1a17;
  --ink-2: #4d4a43;
  --ink-3: #66625a;

  /* interaction -- the only accent, and only for things you can act on */
  --accent: #274690;
  --accent-strong: #1d3673;
  --accent-wash: #e3e8f3;
  --on-accent: #fffdf8;

  /* verdicts: stamp inks */
  --fraud: #a3261b;
  --fraud-wash: #f5e3df;
  --legit: #2c6639;
  --legit-wash: #e1ede3;
  --uncertain: #855606;
  --uncertain-wash: #f4ead6;

  /* graph entity kinds: categorical, muted, distinct in both themes */
  --n-card: #274690;
  --n-customer: #6b4c9a;
  --n-txn: #8c877c;
  --n-device: #9c6a12;
  --n-region: #2c6639;
  --n-case: #8a3d6b;
  --n-agent: #a3261b;

  --shadow: 0 6px 24px rgba(27, 26, 23, 0.14);

  /* type */
  --serif: "Charter", "Bitstream Charter", "Sitka Text", "Iowan Old Style", Cambria, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, "Liberation Mono", monospace;
  --fs-12: 0.75rem;
  --fs-13: 0.8125rem;
  --fs-14: 0.875rem;
  --fs-16: 1rem;
  --fs-20: 1.25rem;
  --fs-26: 1.625rem;
  --fs-34: 2.125rem;

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

  --r1: 2px;
  --r2: 4px;

  --t-fast: 120ms;
  --t: 180ms;
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);

  --header-h: 52px;
  --measure: 68ch;

  color-scheme: light;
}

/* Dark: graphite, not navy. Follows the system unless the toggle overrides. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141412; --sheet: #1c1b19; --wash: #282622;
    --rule: #33312c; --rule-strong: #4b4841; --grid: #2a2825;
    --band: rgba(236, 233, 225, 0.05);
    --ink: #ece9e1; --ink-2: #bdb9ae; --ink-3: #9d988c;
    --accent: #9bb1e6; --accent-strong: #b6c7ef; --accent-wash: #232a3a; --on-accent: #141412;
    --fraud: #f08d7f; --fraud-wash: #3a211d;
    --legit: #86c596; --legit-wash: #1e2d22;
    --uncertain: #dfae5c; --uncertain-wash: #33291a;
    --n-card: #9bb1e6; --n-customer: #b59ae0; --n-txn: #7d786e; --n-device: #dfae5c;
    --n-region: #86c596; --n-case: #d99bbf; --n-agent: #f08d7f;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #141412; --sheet: #1c1b19; --wash: #282622;
  --rule: #33312c; --rule-strong: #4b4841; --grid: #2a2825;
  --band: rgba(236, 233, 225, 0.05);
  --ink: #ece9e1; --ink-2: #bdb9ae; --ink-3: #9d988c;
  --accent: #9bb1e6; --accent-strong: #b6c7ef; --accent-wash: #232a3a; --on-accent: #141412;
  --fraud: #f08d7f; --fraud-wash: #3a211d;
  --legit: #86c596; --legit-wash: #1e2d22;
  --uncertain: #dfae5c; --uncertain-wash: #33291a;
  --n-card: #9bb1e6; --n-customer: #b59ae0; --n-txn: #7d786e; --n-device: #dfae5c;
  --n-region: #86c596; --n-case: #d99bbf; --n-agent: #f08d7f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
/* clip, not hidden: `hidden` on both html and body makes body a scroll
   container that never scrolls, and the sticky header then scrolls away with
   the page. `hidden` stays only as the fallback for browsers without clip. */
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; overflow-x: clip; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--fs-14)/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
p { margin: 0; }
a { color: var(--accent); }
b, strong { font-weight: 600; }
::selection { background: var(--accent-wash); color: var(--ink); }

.mono { font-family: var(--mono); font-size: 0.93em; }
.muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 60;
  background: var(--accent); color: var(--on-accent); padding: var(--s2) var(--s3);
}
.skip-link:focus { left: var(--s2); top: var(--s2); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r1); }

/* ---------------------------------------------------------------- header
   One bar: brand, sections, system status. It used to be two stacked
   sticky bars coupled by a hard-coded `top: 61px`. */
.app-header {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--s5);
  min-height: var(--header-h); padding: 0 var(--s5);
  background: var(--paper); border-bottom: 1px solid var(--rule-strong);
}
.brand { display: flex; align-items: center; gap: var(--s2); flex: none; color: var(--ink); text-decoration: none; }
.brand-mark { width: 22px; height: 22px; flex: none; color: var(--ink); }
.brand-name { font-family: var(--mono); font-size: var(--fs-14); font-weight: 600; letter-spacing: -0.01em; }
.brand-desc { font-size: var(--fs-13); color: var(--ink-3); }

.tabs { display: flex; flex: none; align-self: stretch; gap: var(--s1); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  appearance: none; background: none; border: 0; border-bottom: 2px solid transparent;
  margin-bottom: -1px; padding: 0 var(--s3);
  font: 500 var(--fs-14) var(--sans); color: var(--ink-2); cursor: pointer; white-space: nowrap;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--ink); }
.tabs button:focus-visible { outline-offset: -4px; }

.status {
  margin-left: auto; flex: 0 1 auto;
  display: flex; align-items: center; gap: var(--s3); min-width: 0;
  font-size: var(--fs-12); color: var(--ink-3); white-space: nowrap; overflow-x: auto; scrollbar-width: none;
}
.status::-webkit-scrollbar { display: none; }
.st { display: inline-flex; align-items: center; gap: 6px; }
.st b { color: var(--ink-2); font-weight: 600; }
.st + .st::before { content: ""; width: 1px; height: 12px; background: var(--rule-strong); margin-right: var(--s3); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.ok { background: var(--legit); }
.dot.warn { background: var(--uncertain); }
.dot.bad { background: var(--fraud); }

.icon-btn {
  appearance: none; display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none;
  background: none; border: 1px solid var(--rule); border-radius: var(--r1); color: var(--ink-2); cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--wash); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ page */
main { max-width: 1440px; margin: 0 auto; padding: var(--s6) var(--s5) var(--s7); }
.view { display: none; }
.view.active { display: block; }

.view-head { margin-bottom: var(--s6); max-width: 900px; }
.view-kicker { font-size: var(--fs-13); color: var(--ink-3); margin-bottom: var(--s2); }
.view-title { font-family: var(--serif); font-weight: 400; font-size: var(--fs-34); line-height: 1.15; letter-spacing: -0.01em; }
.view-lede { margin-top: var(--s3); font-size: var(--fs-16); line-height: 1.55; color: var(--ink-2); max-width: var(--measure); }
.view-lede .n { color: var(--ink); font-weight: 600; }
.view-lede .n.fraud { color: var(--fraud); }
.view-lede .n.legit { color: var(--legit); }

/* A section is a heading on a rule, then content. Not a box. */
.sec { border-top: 1px solid var(--rule-strong); padding-top: var(--s4); margin-bottom: var(--s6); }
.sec:last-child { margin-bottom: 0; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s3); }
.sec-head h2 { font-size: var(--fs-16); }
.sec-head h3, .sec h3 { font-size: var(--fs-14); }
.sec-meta { font-size: var(--fs-12); color: var(--ink-3); }
.sec-note { font-size: var(--fs-13); color: var(--ink-2); max-width: var(--measure); margin: calc(-1 * var(--s1)) 0 var(--s3); }
.sub { margin-top: var(--s5); }
.sub > h3 { margin-bottom: var(--s2); }
.sub-tight { margin-top: var(--s2); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s6); }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: var(--s6); align-items: start; }

/* A sheet is containment that means something: a chart, a log, a table, the
   decision column. */
.sheet { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r2); }
.sheet.pad { padding: var(--s4); }
.aside { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r2); padding: var(--s4) var(--s4) var(--s5); }
.aside .sec { border-top-color: var(--rule); }
.aside .sec:first-child { border-top: 0; padding-top: 0; }

/* ---------------------------------------------------------------- ledger
   One component for every "label, value" readout. It replaces eight KPI
   tiles, the three hero-stat tiles, the fact tiles in every case header and
   the tiles inside the backtest cards. */
.ledger {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  margin: 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
}
/* Short ledgers (three or four figures) opt in to their own width, so three
   figures are not stretched a third of a page apart. Opt-in, because capping
   every ledger's tracks made auto-fit budget for the cap and wrap the
   eight-figure case-pack row into six and two. */
.ledger.fit { grid-template-columns: repeat(auto-fit, minmax(128px, 220px)); width: fit-content; max-width: 100%; }
.ledger > div { padding: var(--s3) var(--s4) var(--s3) 0; }
.ledger > div + div { padding-left: var(--s4); border-left: 1px solid var(--rule); }
.ledger dt { font-size: var(--fs-12); color: var(--ink-3); }
.ledger dd { margin: 2px 0 0; font-size: var(--fs-20); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.ledger dd small { display: block; margin-top: 2px; font-size: var(--fs-12); font-weight: 400; letter-spacing: 0; color: var(--ink-3); }
.ledger.compact dd { font-size: var(--fs-16); }
.ledger .fraud { color: var(--fraud); }
.ledger .legit { color: var(--legit); }
.ledger .uncertain { color: var(--uncertain); }

/* --------------------------------------------------------- marks, stamps */
/* The verdict stamp: the one uppercase element, the one place verdict colour
   appears as a mark. */
.stamp {
  display: inline-block; vertical-align: 0.1em;
  padding: 1px 6px; border: 1.5px solid currentColor; border-radius: var(--r1);
  font: 700 var(--fs-12)/1.35 var(--sans); letter-spacing: 0.06em; text-transform: uppercase;
  white-space: nowrap; color: var(--ink-2);
}
.stamp.fraud { color: var(--fraud); background: var(--fraud-wash); }
.stamp.legitimate { color: var(--legit); background: var(--legit-wash); }
.stamp.uncertain { color: var(--uncertain); background: var(--uncertain-wash); }
.stamp.lg { font-size: var(--fs-13); padding: 2px 10px; border-width: 2px; }

/* Neutral metadata: trigger, status, source, route. No colour unless the
   colour carries meaning (an L2 route is the one that needs a senior). */
.tag {
  display: inline-block; padding: 1px 6px; border-radius: var(--r1);
  background: var(--wash); color: var(--ink-2); font-size: var(--fs-12); line-height: 1.5; white-space: nowrap;
}
.tag.route { font-family: var(--mono); font-size: var(--fs-12); background: none; border: 1px solid var(--rule-strong); padding: 0 5px; }
.tag.route.L1 { color: var(--uncertain); border-color: currentColor; }
.tag.route.L2 { color: var(--fraud); border-color: currentColor; font-weight: 700; }
.tag.route.auto { color: var(--ink-3); }
.tag.fraud { background: var(--fraud-wash); color: var(--fraud); }
.tag.legitimate { background: var(--legit-wash); color: var(--legit); }
.tag.uncertain { background: var(--uncertain-wash); color: var(--uncertain); }
.tag.pending { background: var(--uncertain-wash); color: var(--uncertain); }
.tag.done-yes { background: var(--legit-wash); color: var(--legit); }
.tag.done-no { background: var(--fraud-wash); color: var(--fraud); }

.prob { display: inline-flex; align-items: center; gap: 6px; }
.prob i { display: inline-block; width: 32px; height: 4px; background: var(--wash); border-radius: 1px; position: relative; overflow: hidden; }
.prob i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--w, 0%); background: var(--c, var(--ink-3)); }

/* ---------------------------------------------------------------- prose
   The agent's written conclusions -- the summary and the SAR narrative -- are
   set in serif, like a signed finding. Data and interface are not. */
.prose { font-family: var(--serif); font-size: var(--fs-16); line-height: 1.6; color: var(--ink); max-width: var(--measure); }

/* ------------------------------------------------------------- controls */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 var(--s3); border-radius: var(--r1);
  font: 600 var(--fs-13)/1 var(--sans); white-space: nowrap; cursor: pointer; text-decoration: none;
  background: var(--sheet); color: var(--ink); border: 1px solid var(--rule-strong);
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--wash); border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.sm { height: 26px; padding: 0 var(--s2); font-size: var(--fs-12); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.danger { color: var(--fraud); }
.btn .glyph { width: 0; height: 0; border-style: solid; border-width: 4.5px 0 4.5px 7px; border-color: transparent transparent transparent currentColor; }

.linkish {
  appearance: none; background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; color: var(--accent); text-decoration: underline; text-decoration-color: var(--accent-wash);
  text-underline-offset: 2px;
}
.linkish:hover { text-decoration-color: currentColor; }
.linkish.mono { font-family: var(--mono); }

input, select, textarea {
  height: 32px; padding: 0 var(--s2); border-radius: var(--r1);
  background: var(--sheet); color: var(--ink); border: 1px solid var(--rule-strong);
  font: 400 var(--fs-13) var(--sans); outline: none;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input::placeholder { color: var(--ink-3); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
input[type="checkbox"] { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); box-shadow: none; }
label { font-size: var(--fs-13); color: var(--ink-2); }
.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; white-space: nowrap; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin-bottom: var(--s5); }
.toolbar select { min-width: 280px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.controls input[type="search"] { width: 240px; }

.field { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.field input { width: 220px; }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
/* tables with a few columns keep their natural width instead of spreading
   four values across 1,400px */
.table-wrap.fit { width: fit-content; max-width: 100%; }
.table-wrap.fit table { width: auto; min-width: 480px; }
.table-wrap.fit th, .table-wrap.fit td { padding-left: var(--s4); padding-right: var(--s4); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-13); }
/* nowrap by default: an identifier broken across two lines ("C13487-" / "K1")
   is misread. Cells that hold prose opt in with .wrap. */
th, td { text-align: left; padding: var(--s2); border-bottom: 1px solid var(--rule); vertical-align: baseline; white-space: nowrap; }
th:first-child, td:first-child { padding-left: var(--s3); }
th:last-child, td:last-child { padding-right: var(--s3); }
/* not sticky: inside a horizontally scrolling wrapper, a sticky header pins
   relative to the wrapper, not the page, and lands inside the table body */
th {
  background: transparent;   /* takes the surface it sits on: sheet or paper */
  font-size: var(--fs-12); font-weight: 600; color: var(--ink-3); white-space: nowrap;
  border-bottom: 1px solid var(--rule-strong);
}
th.num, td.num { text-align: right; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--ink); }
th[aria-sort]::after { content: " \2193"; color: var(--ink-2); }
th[aria-sort="ascending"]::after { content: " \2191"; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr[data-case] { cursor: pointer; transition: background-color var(--t-fast) var(--ease); }
tbody tr[data-case]:hover, tbody tr[data-case]:focus-visible { background: var(--wash); }
tbody tr[data-case]:focus-visible { outline-offset: -2px; }
td .sub-line { display: block; font-size: var(--fs-12); color: var(--ink-3); }
/* descriptive labels may wrap when space runs out; identifiers never do */
td.wrap { white-space: normal; min-width: 72px; }
/* a qualifier under an id, rather than beside it widening the whole column */
.tag-under { display: block; width: fit-content; margin-top: 2px; }

/* ----------------------------------------------------------------- alerts
   Reserved for things the analyst must notice. It had been used for plain
   information -- policy text, model notes -- which taught the eye to skip it. */
.alert {
  border-left: 3px solid var(--uncertain); background: var(--uncertain-wash);
  padding: var(--s2) var(--s3); font-size: var(--fs-13); color: var(--ink); max-width: var(--measure);
  margin: var(--s3) 0;
}
.alert b { color: var(--uncertain); }
.alert.ok { border-left-color: var(--legit); background: var(--legit-wash); }
.alert.ok b { color: var(--legit); }
.alert.bad, .errorbox { border-left: 3px solid var(--fraud); background: var(--fraud-wash); }
.alert.bad b { color: var(--fraud); }
.errorbox {
  display: flex; gap: var(--s3); align-items: flex-start; justify-content: space-between;
  padding: var(--s3); margin-bottom: var(--s5); font-size: var(--fs-13);
}
.errorbox .msg b { display: block; color: var(--fraud); }

/* An annotation: a margin note with a rule, not a card. */
.note { border-left: 2px solid var(--rule-strong); padding: 0 0 0 var(--s3); }
.note.fraud { border-left-color: var(--fraud); }
.note.legitimate { border-left-color: var(--legit); }
.note.uncertain { border-left-color: var(--uncertain); }

/* ------------------------------------------------------------ overview */
.finding { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: var(--s6); align-items: start; margin-bottom: var(--s7); }
.chart-frame { margin: 0; position: relative; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r2); padding: var(--s3) var(--s3) var(--s2); }
#divergenceChart { display: block; width: 100%; height: auto; }
#divergenceChart:empty { min-height: 320px; background: var(--wash); border-radius: var(--r1); animation: hold 1.4s var(--ease) infinite alternate; }
#divergenceChart .pt { cursor: pointer; }
#divergenceChart .pt circle { transition: r var(--t-fast) var(--ease); }
#divergenceChart .pt:hover circle, #divergenceChart .pt:focus circle { r: 10; }
#divergenceChart .pt:focus { outline: none; }
#divergenceChart .pt:focus circle { stroke: var(--ink); stroke-width: 2; }
.chart-key { display: flex; flex-wrap: wrap; gap: var(--s4); margin-top: var(--s2); font-size: var(--fs-12); color: var(--ink-3); }
.chart-key span { display: inline-flex; align-items: center; gap: 6px; }
.chart-key i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chart-key i.fraud { background: var(--fraud); }
.chart-key i.uncertain { background: var(--uncertain); }
.chart-key i.legit { background: var(--legit); }
.chart-key i.band { width: 14px; height: 9px; border-radius: 0; background: var(--band); border: 1px dashed var(--rule-strong); }

.tip {
  position: absolute; z-index: 6; display: none; pointer-events: none;
  max-width: 240px; padding: var(--s2) var(--s3);
  background: var(--sheet); border: 1px solid var(--rule-strong); border-radius: var(--r2); box-shadow: var(--shadow);
  font-size: var(--fs-12); line-height: 1.5; color: var(--ink);
}
.tip .muted { color: var(--ink-3); }

.margin-notes { display: flex; flex-direction: column; gap: var(--s5); }
.margin-notes h3 { font-size: var(--fs-13); color: var(--ink-3); font-weight: 600; margin-bottom: calc(-1 * var(--s2)); }
.callout {
  appearance: none; display: block; width: 100%; text-align: left; cursor: pointer;
  background: none; border: 0; border-left: 2px solid var(--rule-strong); padding: 0 0 0 var(--s3);
  font: inherit; color: var(--ink);
}
.callout.up { border-left-color: var(--fraud); }
.callout.down { border-left-color: var(--legit); }
.callout-label { display: block; font-size: var(--fs-12); color: var(--ink-3); }
.callout-move { display: flex; align-items: baseline; gap: var(--s2); margin: var(--s1) 0; font-variant-numeric: tabular-nums; }
.callout-move .from { font-size: var(--fs-16); color: var(--ink-3); }
.callout-move .to { font-size: var(--fs-26); font-weight: 600; letter-spacing: -0.01em; }
.callout-move .to.fraud { color: var(--fraud); }
.callout-move .to.legitimate { color: var(--legit); }
.callout-why { display: block; font-size: var(--fs-13); color: var(--ink-2); }
.callout-open { display: inline-block; margin-top: var(--s2); font-size: var(--fs-13); color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-color: var(--accent-wash); }
.callout:hover .callout-open { text-decoration-color: currentColor; }

.dist { display: flex; flex-direction: column; gap: var(--s2); }
.dist-row { display: grid; grid-template-columns: 76px minmax(0, 1fr) 28px; align-items: center; gap: var(--s3); font-size: var(--fs-13); }
.dist-row .band-label { color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: var(--wash); border-radius: 1px; overflow: hidden; }
.bar > i { display: block; height: 100%; width: var(--w, 0%); background: var(--c, var(--ink-3)); }
.dist-row .n { text-align: right; color: var(--ink-2); }

.log { font-size: var(--fs-13); }
.log-row { display: grid; grid-template-columns: 76px 96px minmax(0, 1fr); gap: var(--s3); padding: 6px 0; border-bottom: 1px solid var(--rule); align-items: baseline; }
.log-row:last-child { border-bottom: 0; }
.log-kind { font-size: var(--fs-12); color: var(--ink-3); }
.log-detail { color: var(--ink-2); }
.scroll { max-height: 360px; overflow-y: auto; }

/* ------------------------------------------------------------ case view */
.case-head { margin-bottom: var(--s6); }
.case-id { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.case-id h1 { font-family: var(--mono); font-size: var(--fs-26); font-weight: 600; letter-spacing: -0.02em; }
.case-id .meta { font-size: var(--fs-12); color: var(--ink-3); margin-left: auto; }
.case-trigger { font-size: var(--fs-14); color: var(--ink-2); max-width: var(--measure); margin-bottom: var(--s4); }
.case-head .prose { margin-bottom: var(--s5); }
.case-head .ledger { margin-bottom: var(--s3); }
.case-notes { display: flex; flex-direction: column; gap: 0; }

.provenance { font-size: var(--fs-12); color: var(--ink-3); margin: var(--s3) 0 0; }
.provenance b { color: var(--ink-2); }
.provenance.drifted { color: var(--ink); border-left: 3px solid var(--uncertain); background: var(--uncertain-wash); padding: var(--s2) var(--s3); }
.drift-list { margin: var(--s2) 0 0; padding: 0; list-style: none; font-family: var(--mono); font-size: var(--fs-12); }
.drift-list li { padding: 2px 0; color: var(--ink-2); word-break: break-word; }
.drift-list .p { color: var(--ink-3); }

.ev-list { display: flex; flex-direction: column; }
.ev { padding: var(--s3) 0 var(--s3) var(--s3); border-left: 2px solid var(--rule); }
.ev + .ev { border-top: 1px solid var(--rule); }
.ev.source-graph { border-left-color: var(--accent); }
.ev.source-customer { border-left-color: var(--uncertain); }
.ev.source-document { border-left-color: var(--n-customer); }
.ev-claim { font-size: var(--fs-14); }
.ev-meta { margin-top: var(--s1); font-family: var(--mono); font-size: var(--fs-12); color: var(--ink-3); word-break: break-word; }
.ev-meta .src { font-family: var(--sans); color: var(--ink-2); }

.graph-frame { position: relative; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r2); overflow: hidden; }
#graphSvg { display: block; width: 100%; height: 420px; cursor: grab; touch-action: none; }
#graphSvg:active { cursor: grabbing; }
.graph-controls { position: absolute; top: var(--s2); right: var(--s2); }
.graph-legend { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); margin-top: var(--s2); font-size: var(--fs-12); color: var(--ink-3); }
.graph-legend span { display: inline-flex; align-items: center; gap: 6px; }
.graph-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.graph-legend i.ring-flag { width: 11px; height: 11px; border: 2.5px solid var(--fraud); }
.graph-legend i.ring-ep { width: 11px; height: 11px; border: 2px solid var(--uncertain); }
#graphSvg circle { cursor: pointer; }

.detectors { display: flex; flex-direction: column; }
.det { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--rule); font-size: var(--fs-13); }
.det:last-child { border-bottom: 0; }
.det-name { font-family: var(--mono); font-size: var(--fs-12); color: var(--ink-2); padding-top: 1px; }
.det-name .s { display: block; font-family: var(--sans); color: var(--ink-3); }
.det.matched .det-name { color: var(--ink); font-weight: 600; }
.det.matched .det-name .s { color: var(--fraud); font-weight: 600; }
.det-why { color: var(--ink-2); }
.det.matched .det-why { color: var(--ink); }
.det-lim { display: block; margin-top: 2px; font-size: var(--fs-12); color: var(--ink-3); }
.det-group { margin-top: var(--s3); }

.actions { display: flex; flex-direction: column; }
.act-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s2) var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--rule); align-items: start; }
.act-row:last-child { border-bottom: 0; }
.act-name { font-family: var(--mono); font-size: var(--fs-13); font-weight: 600; display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.act-why { margin-top: 2px; font-size: var(--fs-12); color: var(--ink-2); }
.act-exec { margin-top: var(--s1); font-size: var(--fs-12); color: var(--ink-3); }
.approve { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 240px; }
.approve input { height: 26px; width: 120px; font-size: var(--fs-12); }
.initial-list { margin: 0; padding-left: 18px; font-size: var(--fs-13); color: var(--ink-2); }
.initial-list li { margin: 2px 0; }
.initial-list .mono { color: var(--ink); }
.changed { font-size: var(--fs-13); color: var(--ink-2); }
.changed b { color: var(--ink); }

.req + .req { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--rule); }
.req-head { font-size: var(--fs-13); font-weight: 600; display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.req p { font-size: var(--fs-13); color: var(--ink-2); margin-top: var(--s1); }
.req p.basis { font-size: var(--fs-12); color: var(--ink-3); }

.id-list { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); font-family: var(--mono); font-size: var(--fs-12); color: var(--ink-2); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s1) var(--s4); margin: 0; font-size: var(--fs-13); }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); }
.kv dd.mono { color: var(--ink-2); }

.timeline { display: flex; flex-direction: column; }
.tl { display: grid; grid-template-columns: 24px 72px minmax(0, 1fr); gap: var(--s2); padding: 6px 0; border-bottom: 1px solid var(--rule); font-size: var(--fs-13); }
.tl:last-child { border-bottom: 0; }
.tl .step { font-family: var(--mono); font-size: var(--fs-12); color: var(--ink-3); text-align: right; }
.tl .k { font-size: var(--fs-12); color: var(--ink-3); }
.tl.kind-decision .k, .tl.kind-policy .k { color: var(--accent); }
.tl.kind-finding .k { color: var(--uncertain); }
.tl .d { color: var(--ink-2); }

details { margin-top: var(--s3); }
summary { cursor: pointer; font-size: var(--fs-13); color: var(--accent); width: fit-content; }
summary:hover { text-decoration: underline; text-underline-offset: 2px; }
.code {
  margin: var(--s2) 0 0; padding: var(--s3); max-height: 340px; overflow: auto;
  background: var(--wash); border-radius: var(--r2);
  font: 400 var(--fs-12)/1.55 var(--mono); color: var(--ink-2); white-space: pre;
}
.code.wrap { white-space: pre-wrap; }

.empty { padding: var(--s7) 0; color: var(--ink-3); text-align: center; }

/* model card */
.wt { display: inline-block; position: relative; width: 56px; height: 6px; margin-right: var(--s2); vertical-align: 1px; background: var(--wash); }
.wt::before { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--rule-strong); }
.wt i { position: absolute; top: 0; bottom: 0; left: 50%; width: var(--w, 0%); background: var(--fraud); }
.wt i.neg { left: auto; right: 50%; background: var(--legit); }
td .basis { font-size: var(--fs-12); color: var(--ink-2); }
td.wrap .tag { margin-right: var(--s1); }
.caveats { margin: var(--s2) 0 0; padding-left: 18px; font-size: var(--fs-13); color: var(--ink-2); max-width: var(--measure); }
.caveats li { margin-bottom: 6px; }

/* ------------------------------------------------------ live investigation */
.live { margin-bottom: var(--s6); }
.live-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s2); }
.live-head h2 { font-size: var(--fs-16); display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.live-counters { display: flex; flex-wrap: wrap; gap: var(--s4); font-size: var(--fs-12); color: var(--ink-3); }
.live-counters b { color: var(--ink); font-size: var(--fs-14); margin-right: 2px; }
#liveState.running::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; vertical-align: middle;
  border-radius: 50%; background: currentColor; animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.live-feed { max-height: 340px; overflow-y: auto; padding: var(--s2) var(--s3); background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--r2); }
.lf { display: grid; gap: var(--s3); padding: 5px 0; border-bottom: 1px solid var(--rule); font-size: var(--fs-13); align-items: baseline; animation: enter var(--t) var(--ease) both; }
.lf:last-child { border-bottom: 0; }
@keyframes enter { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.lf-k { font-size: var(--fs-12); color: var(--ink-3); }
.lf.q { grid-template-columns: 56px minmax(0, 2fr) minmax(0, 1.2fr) 72px; }
.lf.q .lf-k { color: var(--accent); }
.lf.q .lf-ref { font-family: var(--mono); font-size: var(--fs-12); color: var(--ink-2); word-break: break-all; }
.lf.q .lf-res { font-size: var(--fs-12); color: var(--ink-2); }
.lf.q .lf-ms { text-align: right; font-size: var(--fs-12); color: var(--ink-3); }
.lf.s { grid-template-columns: 90px minmax(0, 1fr); }
.lf.s .lf-detail { color: var(--ink); }
.lf.s.kind-decision .lf-k, .lf.s.kind-policy .lf-k { color: var(--accent); }
.lf.s.kind-finding .lf-k { color: var(--uncertain); }
.lf.s.kind-stop .lf-k { color: var(--legit); }
.lf.bad .lf-res, .lf.bad .lf-detail { color: var(--fraud); }

/* ------------------------------------------------------------- feedback */
.toast {
  position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); z-index: 100; display: none;
  max-width: calc(100vw - 32px); padding: var(--s2) var(--s4);
  background: var(--ink); color: var(--paper); border-radius: var(--r2); box-shadow: var(--shadow); font-size: var(--fs-13);
}
.spinner {
  display: inline-block; width: 12px; height: 12px; vertical-align: -1px;
  border: 2px solid var(--rule-strong); border-top-color: var(--ink); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading placeholders: a quiet hold, not a shimmer sweep. */
.sk { background: var(--wash); border-radius: var(--r1); animation: hold 1.4s var(--ease) infinite alternate; }
@keyframes hold { from { opacity: 1; } to { opacity: 0.5; } }
.sk-line { height: 14px; width: 100%; margin: 6px 0; }
.sk-line.short { width: 60%; }
.sk-block { height: 280px; }
.sk-num { height: 22px; width: 50%; margin-top: 4px; }

/* ----------------------------------------------------------- responsive */
@media (max-width: 1320px) {
  .brand-desc { display: none; }
}
/* a 12-column table at laptop widths: drop the two columns an analyst needs
   least rather than make every row scroll sideways */
@media (min-width: 961px) and (max-width: 1320px) {
  #queueTable .opt { display: none; }
}

@media (max-width: 1180px) {
  main { padding-left: var(--s4); padding-right: var(--s4); }
  .finding { grid-template-columns: 1fr; gap: var(--s5); }
  .margin-notes { flex-direction: row; flex-wrap: wrap; }
  .margin-notes > h3 { flex-basis: 100%; }
  .margin-notes > .callout { flex: 1 1 240px; }
  .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  /* Three rows: brand and theme, sections, status. Static rather than
     sticky, because three sticky rows would take a sixth of a phone screen.
     The status row stays: "actions: simulated" is not something to hide. */
  .app-header { position: static; flex-wrap: wrap; gap: 0; padding: 0 var(--s4); }
  .brand { order: 1; min-height: 44px; }
  #themeToggle { order: 2; margin-left: auto; }
  .tabs { order: 3; width: calc(100% + 2 * var(--s4)); margin: 0 calc(-1 * var(--s4)); padding: 0 var(--s2); height: 40px; border-top: 1px solid var(--rule); }
  .status { order: 4; width: calc(100% + 2 * var(--s4)); margin: 0 calc(-1 * var(--s4)); padding: var(--s2) var(--s4); border-top: 1px solid var(--rule); }
  main { padding: var(--s5) var(--s4) var(--s7); }
  .view-title { font-size: var(--fs-26); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 > .sec { margin-bottom: var(--s6); }

  /* the queue table becomes one card per case: a 12-column analyst table
     cannot shrink to 320px and stay a table */
  .table-wrap.stack-sm { overflow: visible; }
  .stack-sm thead { display: none; }
  .stack-sm table, .stack-sm tbody, .stack-sm tr, .stack-sm td { display: block; width: 100%; }
  .stack-sm tr[data-case] { padding: var(--s3) 0; border-bottom: 1px solid var(--rule-strong); }
  .stack-sm td { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: var(--s3); padding: 2px 0; border: 0; white-space: normal; text-align: left; }
  .stack-sm td::before { content: attr(data-label); font-size: var(--fs-12); color: var(--ink-3); }
  .stack-sm td > * { justify-self: start; }
  .stack-sm td.num { text-align: left; }

  .controls { width: 100%; }
  .controls input[type="search"] { flex: 1 1 100%; width: auto; }
  .controls select { flex: 1 1 140px; }
  .toolbar select { min-width: 0; flex: 1 1 100%; }
  .field input { flex: 1 1 160px; width: auto; }
  .lf.q { grid-template-columns: 48px minmax(0, 1fr); }
  .lf.q .lf-res, .lf.q .lf-ms { grid-column: 2; text-align: left; }
  #graphSvg { height: 320px; }
}

@media (max-width: 640px) {
  .brand-desc { display: none; }
  .tabs button { padding: 0 var(--s2); font-size: var(--fs-13); }
  .margin-notes { flex-direction: column; }
  .ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger > div, .ledger > div + div { padding: var(--s3) var(--s3) var(--s3) 0; border-left: 0; }
  .ledger > div:nth-child(even) { padding-left: var(--s3); border-left: 1px solid var(--rule); }
  .ledger > div:nth-child(n+3) { border-top: 1px solid var(--rule); }
  .case-id h1 { font-size: var(--fs-20); }
  .case-id .meta { margin-left: 0; width: 100%; }
  .det { grid-template-columns: 1fr; gap: 2px; }
  .log-row { grid-template-columns: 64px minmax(0, 1fr); }
  .log-row .log-kind { display: none; }
  .tl { grid-template-columns: 20px minmax(0, 1fr); }
  .tl .k { display: none; }
  .act-row { grid-template-columns: 1fr; }
  .approve { justify-content: flex-start; max-width: none; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: var(--s2); }
}

/* touch: controls at fingertip size */
@media (hover: none) {
  .btn { height: 40px; }
  .btn.sm { height: 34px; }
  input:not([type="checkbox"]), select { height: 40px; }
  .approve input { height: 34px; }
  .tabs button { min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media print {
  .app-header, .toolbar, .graph-frame, .approve, #livePanel { display: none !important; }
  body { background: #fff; }  /* print: real paper, deliberately literal */
}
