/* RiskLens review desk — "audit working paper" visual system.
   Ledger-pad green desk, lighter ruled sheets, red pencil (raises score) and
   blue pencil (lowers score). One typeface: Schibsted Grotesk. */

@font-face {
  font-family: "Schibsted Grotesk";
  src: url("fonts/SchibstedGrotesk-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
}

:root {
  --desk: #e3ebe0;
  --sheet: #f8fbf6;
  --rule: #c7d8c2;
  --rule-strong: #8fb089;
  --ink: #17263a;
  --ink-soft: #4b5c6c;
  --ink-faint: #74838f;
  --red: #b3261e;
  --red-wash: #f6dcd8;
  --blue: #2456a6;
  --blue-wash: #dbe5f5;
  --volume: #9fb8ae;
  --focus: #2456a6;
  --paper-shadow: 0 1px 0 #c7d8c2, 0 14px 30px -18px rgba(23, 38, 58, 0.35);

  --f: "Schibsted Grotesk", "Segoe UI", system-ui, sans-serif;
  --t-xs: 0.8125rem;   /* 13 */
  --t-s: 0.9375rem;    /* 15 */
  --t-m: 1rem;         /* 16 body */
  --t-l: 1.25rem;      /* 20 */
  --t-xl: 1.5625rem;   /* 25 */
  --t-xxl: clamp(1.75rem, 1.1rem + 2.6vw, 2.75rem);
  --line: 1.75rem;     /* ruled-line rhythm: 28px */
  --gutter: clamp(1rem, 0.5rem + 2vw, 2.5rem);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --desk: #0e1714; --sheet: #15211d; --rule: #26382f; --rule-strong: #3e5a4b;
    --ink: #e6eee8; --ink-soft: #a9bcb1; --ink-faint: #7f948a;
    --red: #f08a80; --red-wash: #3a1f1c; --blue: #8db2f5; --blue-wash: #1b2a44;
    --volume: #3f5c52; --focus: #8db2f5;
    --paper-shadow: 0 1px 0 #26382f, 0 18px 36px -20px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --desk: #0e1714; --sheet: #15211d; --rule: #26382f; --rule-strong: #3e5a4b;
  --ink: #e6eee8; --ink-soft: #a9bcb1; --ink-faint: #7f948a;
  --red: #f08a80; --red-wash: #3a1f1c; --blue: #8db2f5; --blue-wash: #1b2a44;
  --volume: #3f5c52; --focus: #8db2f5;
  --paper-shadow: 0 1px 0 #26382f, 0 18px 36px -20px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--desk);
  color: var(--ink);
  font: 400 var(--t-m)/1.55 var(--f);
  font-variant-numeric: lining-nums proportional-nums;
  overflow-x: hidden;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.skip { position: absolute; left: -999px; top: 0.5rem; background: var(--sheet); padding: 0.5rem 0.75rem; z-index: 10; }
.skip:focus { left: 0.5rem; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0; }

/* ---------------------------------------------------------------- masthead */
.masthead {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.5rem 1.5rem;
  padding: 1rem var(--gutter) 0.75rem;
  border-bottom: 1px solid var(--rule-strong);
}
.brand { display: inline-flex; align-items: center; gap: 0.5rem; text-decoration: none; font-weight: 800; font-size: var(--t-l); letter-spacing: -0.02em; }
.brand svg { width: 1.6rem; height: 1.6rem; fill: none; stroke: var(--red); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }
.masthead nav { display: flex; gap: 0.25rem; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.masthead nav a { white-space: nowrap; }
.masthead nav a {
  text-decoration: none; font-size: var(--t-s); color: var(--ink-soft);
  padding: 0.35rem 0.7rem; border-radius: 3px;
}
.masthead nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--sheet) 60%, transparent); }
.masthead nav a[aria-current="page"] { color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--red); border-radius: 0; }
.theme { background: none; border: 1px solid var(--rule-strong); border-radius: 50%; width: 2.25rem; height: 2.25rem; display: grid; place-items: center; cursor: pointer; }
.theme svg { width: 1.1rem; height: 1.1rem; fill: var(--ink); stroke: var(--ink); stroke-width: 1.4; }
.theme svg circle { fill: none; }

.provenance {
  padding: 0.5rem var(--gutter);
  font-size: var(--t-xs); color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
}

main { padding: var(--gutter); max-width: 1440px; margin: 0 auto; outline: none; }
.loading, .noscript, .fatal { padding: 3rem 0; color: var(--ink-soft); }
.fatal strong { color: var(--red); }

.colophon { padding: 1.5rem var(--gutter) 2.5rem; border-top: 1px solid var(--rule-strong); color: var(--ink-soft); font-size: var(--t-xs); display: grid; gap: 0.25rem; }

/* ---------------------------------------------------------------- shared */
.lede { max-width: 62ch; color: var(--ink-soft); margin-top: 0.75rem; }
.headline { font-size: var(--t-xxl); font-weight: 800; letter-spacing: -0.03em; max-width: 22ch; }
.headline .figure { font-weight: 900; }
.section-title { font-size: var(--t-xl); margin-bottom: 0.25rem; }
.sub { font-size: var(--t-l); font-weight: 650; }
.note { font-size: var(--t-xs); color: var(--ink-soft); max-width: 70ch; }
.muted { color: var(--ink-soft); }

.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--paper-shadow);
}

/* Ledger tables: ruled rows on the 28px rhythm, figures right-aligned. */
.ledger { width: 100%; border-collapse: collapse; font-size: var(--t-s); }
.ledger th, .ledger td { text-align: left; padding: 0 0.75rem; height: var(--line); border-bottom: 1px solid var(--rule); vertical-align: middle; }
.ledger thead th { font-weight: 600; color: var(--ink-soft); font-size: var(--t-xs); border-bottom: 2px solid var(--rule-strong); }
.ledger td.num, .ledger th.num { text-align: right; white-space: nowrap; }
.ledger tbody th { font-weight: 500; color: var(--ink-soft); }
.ledger tr:last-child td, .ledger tr:last-child th { border-bottom: 0; }

details.sql { margin-top: 0.75rem; font-size: var(--t-s); }
details.sql summary { cursor: pointer; color: var(--ink-soft); }
details.sql pre { margin: 0.5rem 0 0; padding: 0.75rem 1rem; background: var(--desk); border-left: 3px solid var(--rule-strong); overflow-x: auto; font-size: var(--t-xs); line-height: 1.5; }

/* ---------------------------------------------------------------- queue view */
.desk-head { display: grid; gap: 0.5rem; margin-bottom: 1.75rem; }
.desk { display: grid; grid-template-columns: minmax(17rem, 21rem) minmax(0, 1fr); gap: var(--gutter); align-items: start; }

.queue { position: sticky; top: 1rem; display: grid; gap: 0.75rem; }
.queue-tools { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 3px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 0.3rem 0.65rem; font-size: var(--t-xs); cursor: pointer; color: var(--ink-soft); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--sheet); }
.queue input[type="search"] {
  flex: 1; min-width: 8rem; padding: 0.3rem 0.6rem; font-size: var(--t-xs);
  border: 1px solid var(--rule-strong); border-radius: 3px; background: var(--sheet);
}
.queue ol { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 12rem); overflow-y: auto; border-top: 2px solid var(--rule-strong); }
.queue li + li { border-top: 1px solid var(--rule); }
.qrow {
  width: 100%; background: none; border: 0; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: 2.25rem 1fr auto; gap: 0 0.5rem; align-items: center;
  padding: 0.5rem 0.5rem 0.55rem 0.25rem;
}
.qrow:hover { background: color-mix(in srgb, var(--sheet) 70%, transparent); }
.qrow[aria-current="true"] { background: var(--sheet); box-shadow: inset 3px 0 0 var(--red); }
.qrow .rank { color: var(--ink-faint); font-size: var(--t-xs); text-align: right; }
.qrow .id { font-weight: 600; font-size: var(--t-s); }
.qrow .meta { grid-column: 2; font-size: var(--t-xs); color: var(--ink-soft); }
.qrow .score { grid-row: 1 / span 2; grid-column: 3; display: grid; justify-items: end; gap: 0.15rem; font-size: var(--t-xs); }
.qrow .score svg { width: 4.5rem; height: 0.5rem; }
.qrow.below .id { font-weight: 500; color: var(--ink-soft); }
.queue .empty { padding: 1rem 0.5rem; color: var(--ink-soft); font-size: var(--t-s); }

/* Working paper */
.paper { padding: clamp(1.25rem, 0.8rem + 2vw, 2.5rem); display: grid; gap: 2.25rem; position: relative; }
.paper-head { display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: start; }
.paper-head .ref { font-size: var(--t-xs); color: var(--ink-soft); }
.paper-head h2 { font-size: var(--t-xl); font-weight: 800; letter-spacing: -0.02em; }
.paper-head .summary { margin-top: 0.4rem; color: var(--ink-soft); max-width: 60ch; }

.stamp {
  justify-self: end; align-self: start;
  border: 2.5px solid var(--red); color: var(--red);
  border-radius: 6px; padding: 0.45rem 0.8rem 0.4rem;
  transform: rotate(-4deg);
  text-align: center; line-height: 1.15;
  font-weight: 800; font-size: var(--t-s); letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 2px var(--sheet), inset 0 0 0 3.5px color-mix(in srgb, var(--red) 55%, transparent);
  max-width: 11rem;
}
.stamp small { display: block; font-weight: 500; font-size: 0.6875rem; letter-spacing: 0; margin-top: 0.2rem; }
.stamp.below { border-color: var(--ink-faint); color: var(--ink-faint); box-shadow: none; }
.stamp.landing { animation: stamp 420ms cubic-bezier(.2, .9, .3, 1.2) both; }
@keyframes stamp { from { transform: rotate(-11deg) scale(1.35); opacity: 0; } to { transform: rotate(-4deg) scale(1); opacity: 1; } }

.block { display: grid; gap: 0.75rem; }
.block > header { display: grid; gap: 0.2rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); column-gap: 2rem; }
.facts .ledger tbody th { width: 55%; }

.scoreline { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; }
.scoreline .big { font-size: var(--t-xl); font-weight: 800; }

/* SHAP rows: label | diverging bar | signed value */
.shap { display: grid; gap: 0; border-top: 2px solid var(--rule-strong); }
.shap-row { display: grid; grid-template-columns: minmax(9rem, 15rem) minmax(0, 1fr) 4.5rem; gap: 0.75rem; align-items: center; min-height: var(--line); border-bottom: 1px solid var(--rule); font-size: var(--t-s); }
.shap-row .lab { display: flex; flex-direction: column; line-height: 1.25; padding: 0.3rem 0; }
.shap-row .lab span { font-size: var(--t-xs); color: var(--ink-soft); }
.shap-row svg { width: 100%; height: 14px; overflow: visible; }
.shap-row .val { text-align: right; font-size: var(--t-xs); white-space: nowrap; }
.shap-row .val.up { color: var(--red); }
.shap-row .val.down { color: var(--blue); }
.shap-legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1.25rem; font-size: var(--t-xs); color: var(--ink-soft); }
.key { display: inline-flex; align-items: center; gap: 0.4rem; }
.key i { width: 0.9rem; height: 0.55rem; border-radius: 1px; display: inline-block; }
.key .up { background: var(--red); }
.key .down { background: var(--blue); }
.key .vol-key { background: var(--volume); }

/* Evidence ticks */
.evidence { list-style: none; margin: 0; padding: 0; border-top: 2px solid var(--rule-strong); }
.evidence li { display: grid; grid-template-columns: 1.5rem 1fr auto; gap: 0.6rem; align-items: start; padding: 0.45rem 0; border-bottom: 1px solid var(--rule); font-size: var(--t-s); }
.evidence svg { width: 1.1rem; height: 1.1rem; margin-top: 0.15rem; fill: none; stroke: var(--red); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.evidence li.none svg { stroke: var(--ink-faint); }
.polref {
  background: none; border: 1px solid var(--rule-strong); border-radius: 3px;
  font-size: var(--t-xs); font-weight: 600; padding: 0.05rem 0.4rem; cursor: pointer; white-space: nowrap;
}
.polref:hover, .polref[aria-expanded="true"] { border-color: var(--ink); }
.policy-text { grid-column: 2 / -1; font-size: var(--t-xs); color: var(--ink-soft); border-left: 3px solid var(--rule-strong); padding: 0.4rem 0 0.4rem 0.75rem; margin-top: 0.25rem; max-width: 70ch; }
.policy-text strong { color: var(--ink); }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); gap: 2.25rem; }
.cols > *, .desk > *, .paper > * { min-width: 0; }
.scroll-x { overflow-x: auto; }
.ledger.compact td, .ledger.compact th { white-space: nowrap; }

/* Sign-off box */
.signoff { border: 1.5px dashed var(--rule-strong); border-radius: 3px; padding: 1rem 1.25rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 1rem 2rem; }
.signoff div { display: grid; gap: 0.35rem; font-size: var(--t-xs); color: var(--ink-soft); }
.signoff .line { border-bottom: 1px solid var(--ink-soft); height: 1.6rem; }
.signoff .filled { color: var(--ink); font-size: var(--t-s); }

/* Live draft */
.live { border-top: 2px solid var(--ink); padding-top: 1rem; display: grid; gap: 0.75rem; }
.live form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.live input { padding: 0.4rem 0.6rem; border: 1px solid var(--rule-strong); border-radius: 3px; background: var(--desk); min-width: 10rem; }
.btn {
  background: var(--ink); color: var(--sheet); border: 0; border-radius: 3px;
  padding: 0.5rem 0.95rem; font-weight: 600; font-size: var(--t-s); cursor: pointer;
}
.btn:disabled { opacity: 0.55; cursor: progress; }
.trace { display: flex; flex-wrap: wrap; gap: 0.4rem; list-style: none; margin: 0; padding: 0; }
.trace li { font-size: var(--t-xs); border: 1px solid var(--rule-strong); border-radius: 3px; padding: 0.1rem 0.5rem; color: var(--ink-soft); }
.trace li.bad { border-color: var(--red); color: var(--red); }
.draft { white-space: pre-wrap; font-size: var(--t-s); max-width: 72ch; min-height: 1.5rem; }
.draft.final { white-space: normal; }
.draft.final h4 { font-size: var(--t-s); margin: 0.9rem 0 0.25rem; }
.draft.final ul { margin: 0.25rem 0; padding-left: 1.2rem; }
.draft.final p { margin: 0.4rem 0; }
.warn { font-size: var(--t-xs); color: var(--red); }

/* ---------------------------------------------------------------- overview / model */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); border-top: 2px solid var(--ink); border-bottom: 1px solid var(--rule-strong); margin: 1.5rem 0 2.5rem; }
.figures div { padding: 0.75rem 1rem 0.9rem 0; display: grid; gap: 0.1rem; }
.figures div + div { padding-left: 1rem; border-left: 1px solid var(--rule); }
.figures dt { font-size: var(--t-xs); color: var(--ink-soft); }
.figures dd { margin: 0; font-size: var(--t-xl); font-weight: 750; letter-spacing: -0.02em; }
.figures dd small { font-size: var(--t-xs); font-weight: 400; color: var(--ink-soft); letter-spacing: 0; display: block; }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2.5rem var(--gutter); }
.panel.wide { grid-column: 1 / -1; }
.panel.lead { order: -1; }
.panel.wide .chart { max-height: 16rem; }
.panel { padding: 1.25rem 1.5rem 1.5rem; display: grid; gap: 0.9rem; align-content: start; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink-soft); font: 400 11px var(--f); }
.chart .axis { stroke: var(--rule-strong); stroke-width: 1; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .vol { fill: var(--volume); opacity: 0.55; }
.chart .flag { fill: var(--red); }
.chart .curve { fill: none; stroke: var(--ink); stroke-width: 2; }
.chart .base { stroke: var(--ink-faint); stroke-dasharray: 4 4; }
.chart .pt { fill: var(--red); stroke: var(--sheet); stroke-width: 2; }
.chart .lbl { fill: var(--ink); font-weight: 600; }
.bar-ink { fill: var(--ink-soft); }
.bar-red { fill: var(--red); }
.bar-blue { fill: var(--blue); }
.spaced { margin-top: 2.5rem; }
.bar-track { fill: var(--rule); }
.split-train { fill: var(--ink); }
.split-val { fill: var(--blue); }
.split-test { fill: var(--red); }

.cm { display: grid; grid-template-columns: auto 1fr 1fr; border-top: 2px solid var(--ink); font-size: var(--t-s); }
.cm > * { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--rule); }
.cm .h { font-size: var(--t-xs); color: var(--ink-soft); font-weight: 600; }
.cm .cell { display: grid; gap: 0.15rem; }
.cm .cell b { font-size: var(--t-xl); font-weight: 800; }
.cm .cell span { font-size: var(--t-xs); color: var(--ink-soft); }
.cm .hit b { color: var(--red); }

.prose { max-width: 68ch; display: grid; gap: 0.9rem; }
.prose h2 { font-size: var(--t-xl); margin-top: 1.5rem; }
.prose ul { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.35rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chips span { font-size: var(--t-xs); border: 1px solid var(--rule-strong); border-radius: 3px; padding: 0.05rem 0.45rem; }
.chips.out span { text-decoration: line-through; color: var(--ink-soft); }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .desk, .grid2 { grid-template-columns: 1fr; }
  .queue { position: static; }
  .queue ol { max-height: 18rem; }
  .paper-head { grid-template-columns: 1fr; }
  .stamp { justify-self: start; }
}
@media (max-width: 700px) {
  .masthead { grid-template-columns: 1fr auto; }
  .masthead nav { grid-column: 1 / -1; grid-row: 2; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
}
@media (max-width: 560px) {
  .shap-row { grid-template-columns: minmax(7rem, 9rem) minmax(0, 1fr) 3.75rem; gap: 0.5rem; }
  .figures div + div { border-left: 0; padding-left: 0; }
  .figures div { border-top: 1px solid var(--rule); }
  .cm { font-size: var(--t-xs); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* split timeline */
.split-bar { height: 1.1rem; }
.split-key { list-style: none; margin: 0.25rem 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 0.75rem 2rem; font-size: var(--t-s); }
.split-key li { display: grid; grid-template-columns: 0.8rem 1fr; column-gap: 0.6rem; align-items: baseline; }
.split-key li .muted { grid-column: 2; font-size: var(--t-xs); }
.split-key i { width: 0.8rem; height: 0.8rem; border-radius: 2px; display: inline-block; }
.split-key i.split-train { background: var(--ink); }
.split-key i.split-val { background: var(--blue); }
.split-key i.split-test { background: var(--red); }
.ledger td:first-child { white-space: nowrap; }
