/*
 * FinSight demo — stylesheet.
 * Carries the product's two-state visual language (see dashboard/render.py):
 *   stable    — calm: quiet slate, no accent. "Nothing needs you here."
 *   divergent — signal: an amber rail + dot. "A standing belief is contested."
 * Severity graduates the signal (low -> amber, high -> red). This is an
 * instrument for an analyst, not a marketing page: fast, legible, dense where
 * it earns it. Theme-aware, responsive, reduced-motion respected.
 */

:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #fbfcfd; --ink: #16191d; --muted: #66707b;
  --line: #e4e7eb; --line-strong: #cdd2d9;
  --calm: #3f7d63; --calm-bg: #eef4f0;
  --signal: #b45309; --signal-bg: #fdf3e7; --signal-line: #e6a256;
  --high: #b3261e; --high-bg: #fbecea;
  --meter: #64748b; --meter-track: #e9edf1;
  --link: #1f5fa8; --mono: #475569;
  --good: #3f7d63; --good-bg: #eef4f0;
  --shadow: 0 1px 2px rgba(16,19,29,.04), 0 1px 3px rgba(16,19,29,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --panel-2: #141922; --ink: #e6e9ed; --muted: #949daa;
    --line: #262c34; --line-strong: #333b45;
    --calm: #7fc3a3; --calm-bg: #17251f;
    --signal: #e8a15b; --signal-bg: #241a10; --signal-line: #7a5427;
    --high: #f0837a; --high-bg: #2a1512;
    --meter: #8b97a6; --meter-track: #232932;
    --link: #6fa8e6; --mono: #98a4b3;
    --good: #7fc3a3; --good-bg: #17251f;
    --shadow: none;
  }
}
:root[data-theme="light"] {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #fbfcfd; --ink: #16191d; --muted: #66707b;
  --line: #e4e7eb; --line-strong: #cdd2d9;
  --calm: #3f7d63; --calm-bg: #eef4f0; --signal: #b45309; --signal-bg: #fdf3e7;
  --signal-line: #e6a256; --high: #b3261e; --high-bg: #fbecea; --meter: #64748b;
  --meter-track: #e9edf1; --link: #1f5fa8; --mono: #475569; --good: #3f7d63;
  --good-bg: #eef4f0; --shadow: 0 1px 2px rgba(16,19,29,.04), 0 1px 3px rgba(16,19,29,.06);
}
:root[data-theme="dark"] {
  --bg: #0f1216; --panel: #171b21; --panel-2: #141922; --ink: #e6e9ed; --muted: #949daa;
  --line: #262c34; --line-strong: #333b45; --calm: #7fc3a3; --calm-bg: #17251f;
  --signal: #e8a15b; --signal-bg: #241a10; --signal-line: #7a5427; --high: #f0837a;
  --high-bg: #2a1512; --meter: #8b97a6; --meter-track: #232932; --link: #6fa8e6;
  --mono: #98a4b3; --good: #7fc3a3; --good-bg: #17251f; --shadow: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 3px; }
.mono { font-family: ui-monospace, SFMono-Regular, "Cascadia Code", Consolas, monospace;
  font-size: 0.86em; color: var(--mono); }
.skip { position: absolute; left: -999px; top: 0; background: var(--panel); padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 6px; z-index: 20; }
.skip:focus { left: 12px; top: 8px; }

/* ---- demo banner (honesty marker) ---- */
.demobar {
  background: var(--panel-2); border-bottom: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted);
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 7px 24px;
}
.demobar .tag {
  font-weight: 700; color: var(--signal); background: var(--signal-bg);
  border: 1px solid var(--signal-line); border-radius: 20px;
  padding: 1px 10px; letter-spacing: 0.02em; text-transform: uppercase; font-size: 11px;
}
.demobar .how { flex: 1; min-width: 200px; }
.demobar a { color: var(--link); }

/* ---- top nav ---- */
header.top {
  position: sticky; top: 0; z-index: 10; background: var(--panel);
  border-bottom: 1px solid var(--line); padding: 0 24px;
  display: flex; align-items: center; gap: 6px; height: 54px;
}
header.top .brand { font-weight: 700; letter-spacing: -0.01em; margin-right: 14px; }
header.top .brand span { color: var(--muted); font-weight: 400; }
header.top nav { display: flex; gap: 2px; flex-wrap: wrap; }
header.top nav a {
  color: var(--muted); font-weight: 500; padding: 6px 11px; border-radius: 7px;
  font-size: 14px; white-space: nowrap;
}
header.top nav a:hover { color: var(--ink); background: var(--panel-2); text-decoration: none; }
header.top nav a.active { color: var(--ink); background: var(--meter-track); }
header.top nav a .n { color: var(--signal); font-weight: 700; }
.theme-btn {
  margin-left: auto; background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.theme-btn:hover { color: var(--ink); border-color: var(--line-strong); }

main { max-width: 980px; margin: 0 auto; padding: 26px 24px 90px; }
h1 { font-size: 22px; margin: 0 0 3px; letter-spacing: -0.01em; }
h1 .sub-inline { font-size: 14px; color: var(--muted); font-weight: 400; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 36px 0 12px; font-weight: 600; }
h2:first-of-type { margin-top: 22px; }
.sub { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.lead-note { color: var(--ink); font-size: 13.5px; margin: 2px 0 16px; max-width: 720px; line-height: 1.55; }
.lead-note b { font-weight: 600; }
.muted-note { color: var(--muted); }
.h2-note { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted);
  font-size: 12.5px; }
.nm-inline { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; max-width: 190px; }

/* ---- severity legend (what high/medium/low mean, in plain words) ---- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  padding: 12px 15px; margin: 4px 0 16px; }
.legend-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 700; width: 100%; margin-bottom: 2px; }
.legend-item { display: flex; align-items: baseline; gap: 8px; flex: 1 1 220px; }
.legend-txt { font-size: 12.5px; color: var(--muted); line-height: 1.4; }

/* ---- plain-English summary line on a divergence ---- */
.plain { display: flex; gap: 9px; align-items: baseline; flex-wrap: wrap;
  font-size: 14.5px; color: var(--ink); font-weight: 600; line-height: 1.4;
  margin: 10px 0 2px; }
.plain-tag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--signal); background: var(--signal-bg); border: 1px solid var(--signal-line);
  border-radius: 5px; padding: 2px 7px; flex: 0 0 auto; }

/* ---- summary stats ---- */
.row-summary { display: flex; gap: 22px; margin: 16px 0 6px; flex-wrap: wrap; }
.stat { display: flex; align-items: baseline; gap: 7px; }
.stat b { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.sig b { color: var(--signal); }

/* ---- cards ---- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 15px 17px; margin: 10px 0; box-shadow: var(--shadow); }
.card.divergent { border-left: 3px solid var(--signal-line); }
.card.high { border-left: 3px solid var(--high); }
.grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.card-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { margin-left: auto; }

/* ---- coverage rows / grid ---- */
.covgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.cov { display: flex; align-items: center; gap: 13px; padding: 14px 16px; }
a.cov:hover { text-decoration: none; border-color: var(--line-strong); }
.cov .tk { font-weight: 700; font-size: 15px; color: var(--ink); }
.cov .nm { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
.cov .col { flex: 1; min-width: 0; }
.cov .meta { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; }
.cov .sector { font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.04em; }

/* ---- state dot + badges ---- */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.dot.stable { background: var(--calm); }
.dot.divergent { background: var(--signal); box-shadow: 0 0 0 3px var(--signal-bg); }
.badge { font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 20px;
  letter-spacing: 0.02em; text-transform: uppercase; white-space: nowrap; }
.badge.stable { color: var(--calm); background: var(--calm-bg); }
.badge.divergent { color: var(--signal); background: var(--signal-bg); }

/* ---- pills / severity ---- */
.pill { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 5px;
  border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; }
.pill.weakened { color: var(--signal); border-color: var(--signal-line); background: var(--signal-bg); }
.pill.contradicted { color: var(--high); border-color: var(--high); background: var(--high-bg); }
.pill.retired { text-decoration: line-through; }
.sev { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 4px;
  text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
.sev.high { color: #fff; background: var(--high); }
.sev.medium { color: var(--signal); background: var(--signal-bg); border: 1px solid var(--signal-line); }
.sev.low { color: var(--muted); background: var(--meter-track); }

/* ---- confidence meter ---- */
.meter { display: inline-flex; align-items: center; gap: 8px; }
.meter .track { width: 88px; height: 6px; border-radius: 3px; background: var(--meter-track);
  overflow: hidden; }
.meter .fill { height: 100%; background: var(--meter); }
.meter .val { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- claims + evidence drill-down ---- */
.claim .cat { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 600; }
.stmt { font-size: 15.5px; line-height: 1.45; margin: 8px 0 4px; }
.claim .stmt { margin: 6px 0 8px; }
.ev-toggle {
  display: flex; align-items: center; gap: 9px; width: 100%; text-align: left;
  border: none; background: none; color: var(--muted); font: inherit; font-size: 12.5px;
  cursor: pointer; padding: 9px 0 5px; border-top: 1px dashed var(--line); margin-top: 6px;
}
.ev-toggle:hover { color: var(--ink); }
.ev-toggle .stance { font-weight: 700; text-transform: uppercase; font-size: 10.5px;
  letter-spacing: 0.04em; }
.ev-toggle .stance.contradicts { color: var(--signal); }
.ev-toggle .stance.supports { color: var(--calm); }
.ev-toggle .stance.contextual { color: var(--muted); }
.ev-toggle .chev { transition: transform .18s ease; display: inline-block; color: var(--muted); }
.ev-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.ev-toggle .caret-hint { margin-left: auto; color: var(--link); font-weight: 500; }
.ev-body { display: none; padding: 4px 0 2px; }
.ev-body.open { display: block; }
.ev-body blockquote {
  margin: 6px 0 8px; padding: 9px 13px; border-left: 2px solid var(--signal-line);
  background: var(--panel-2); border-radius: 0 6px 6px 0; font-size: 13.5px;
  color: var(--ink); line-height: 1.55;
}
.ev-body.supports blockquote { border-left-color: var(--calm); }
.ev-body mark { background: var(--signal-bg); color: var(--ink);
  border-bottom: 2px solid var(--signal-line); padding: 0 1px; border-radius: 2px; }
.ev-body.supports mark { background: var(--calm-bg); border-bottom-color: var(--calm); }
.ev-src { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 12px;
  color: var(--muted); margin-bottom: 6px; }
.ev-note { font-size: 12.5px; color: var(--muted); font-style: italic; margin: 2px 0 4px; }

/* ---- side-by-side stance (was / now) ---- */
.stance-cmp { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: stretch;
  margin: 12px 0 4px; }
.stance-box { border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px;
  background: var(--panel-2); }
.stance-box.was { border-left: 3px solid var(--line-strong); }
.stance-box.now { border-left: 3px solid var(--signal-line); }
.stance-box .lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); font-weight: 700; margin-bottom: 5px; }
.stance-box.now .lbl { color: var(--signal); }
.stance-box .txt { font-size: 13.5px; line-height: 1.45; }
.stance-box .cf { font-size: 12px; color: var(--muted); margin-top: 7px;
  font-variant-numeric: tabular-nums; }
.stance-arrow { display: flex; align-items: center; color: var(--signal); font-size: 20px; }
@media (max-width: 620px) {
  .stance-cmp { grid-template-columns: 1fr; }
  .stance-arrow { transform: rotate(90deg); justify-content: center; padding: 2px 0; }
}

/* ---- version-history timeline ---- */
.timeline { position: relative; margin: 6px 0 0; padding-left: 4px; }
.tl { position: relative; padding: 0 0 20px 26px; border-left: 2px solid var(--line); }
.tl:last-child { border-left-color: transparent; padding-bottom: 2px; }
.tl .node { position: absolute; left: -8px; top: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--panel); border: 2px solid var(--meter); }
.tl.divergence .node { border-color: var(--signal); background: var(--signal-bg); }
.tl.head .node { border-color: var(--calm); background: var(--calm); box-shadow: 0 0 0 3px var(--calm-bg); }
.tl .vhead { display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap; }
.tl .vn { font-weight: 700; font-size: 14px; }
.tl .kind { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; }
.tl .kind.divergence_resolution { color: var(--signal); }
.tl .when { font-size: 12px; color: var(--muted); margin-left: auto; }
.tl .trig { font-size: 13.5px; margin: 4px 0 3px; line-height: 1.45; }
.tl .delta { font-size: 12.5px; color: var(--muted); }
.delta ins { color: var(--calm); text-decoration: none; }
.delta del { color: var(--high); text-decoration: none; }
.tl .inforce { font-size: 10.5px; font-weight: 700; color: var(--calm); text-transform: uppercase;
  letter-spacing: 0.04em; }

/* ---- passage view ---- */
.passage { font-size: 14.5px; line-height: 1.65; white-space: pre-wrap;
  padding: 16px 18px; }
.passage mark { background: var(--signal-bg); color: var(--ink);
  border-bottom: 2px solid var(--signal-line); padding: 1px 1px; border-radius: 2px; }
.kv { display: flex; gap: 8px; font-size: 13px; margin: 4px 0; }
.kv .k { color: var(--muted); min-width: 96px; flex: 0 0 auto; }
.empty { color: var(--muted); padding: 20px 4px; font-style: italic; }
.notice { padding: 11px 14px; border-radius: 8px; background: var(--signal-bg);
  color: var(--signal); font-size: 13px; margin: 12px 0; border: 1px solid var(--signal-line); }
.backlink { font-size: 13px; color: var(--muted); margin: 0 0 10px; }

/* ---- eval scorecard ---- */
.eval-hero { display: flex; gap: 22px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 16px 18px; margin: 16px 0 8px; box-shadow: var(--shadow); }
.gate { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px;
  color: var(--good); background: var(--good-bg); border: 1px solid var(--good);
  padding: 6px 13px; border-radius: 8px; }
.gate .g-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--good); }
.eval-hero .txt { font-size: 13px; color: var(--muted); flex: 1; min-width: 220px; }
.eval-group { margin: 20px 0; }
.eval-group h3 { font-size: 15px; margin: 0 0 3px; }
.eval-group .blurb { font-size: 12.5px; color: var(--muted); margin: 0 0 12px; max-width: 660px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.metric { border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px;
  background: var(--panel); box-shadow: var(--shadow); }
.metric.lead { border-color: var(--line-strong); background: var(--panel-2); }
.metric .m-val { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em; line-height: 1.1; }
.metric .m-val.pass { color: var(--good); }
.metric .m-label { font-size: 12px; color: var(--muted); margin-top: 3px; }
.metric .m-bar { height: 5px; border-radius: 3px; background: var(--meter-track);
  overflow: hidden; margin: 9px 0 6px; }
.metric .m-fill { height: 100%; background: var(--good); }
.metric .m-floor { font-size: 10.5px; color: var(--muted); }
.metric .m-floor.na { visibility: hidden; }

footer { color: var(--muted); font-size: 12px; margin-top: 46px;
  border-top: 1px solid var(--line); padding-top: 16px; line-height: 1.7; }
footer a { color: var(--link); }

/* ---- reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .ev-toggle .chev { transition: none; }
}
