/* ==========================================================================
   regime-engine investor dashboard — design tokens & components
   Dark-only theme (committed, explicit colors everywhere).
   ========================================================================== */
:root {
  color-scheme: dark;
  /* surfaces */
  --bg: #0a0d12;
  --bg-elev: #0e131a;
  --surface: #121922;
  --surface-2: #182230;
  --surface-3: #1e2a3a;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);
  --grid: #1f2937;
  /* ink */
  --ink: #e8ecf1;
  --ink-2: #aab4c3;
  --ink-3: #7d8796;
  --ink-4: #5b6573;
  /* brand / accent */
  --accent: #5b9cf6;
  --accent-strong: #3b82f6;
  --accent-soft: rgba(91, 156, 246, 0.14);
  --amber: #e0a72a;
  --amber-soft: rgba(224, 167, 42, 0.14);
  /* status (never used as series) */
  --good: #22b573;
  --good-soft: rgba(34, 181, 115, 0.14);
  --warn: #e0a72a;
  --warn-soft: rgba(224, 167, 42, 0.14);
  --bad: #e5605e;
  --bad-soft: rgba(229, 96, 94, 0.14);
  /* series (validated adjacent triple, dark surface) */
  --s-engine: #3987e5;
  --s-spy: #d95926;
  --s-qqq: #199e70;
  --s-base5: #9085e9;
  --s-6040: #c9578a;
  --s-muted: #6b7280;
  /* regime chips */
  --r-bull: #22b573;
  --r-neutral: #e0a72a;
  --r-bear: #e5605e;
  /* type */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* shape */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 0 rgba(255,255,255,0.03) inset, 0 8px 24px rgba(0,0,0,0.28);
  --sidebar-w: 236px;
  --topbar-h: 60px;
  --ease: cubic-bezier(.2,.7,.2,1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 10px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
small, .small { font-size: 13px; }
.muted { color: var(--ink-3); }
.sub { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface-3); padding: 8px 12px; z-index: 1000; border-radius: 6px; }
.skip:focus { left: 8px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100dvh; }
.sidebar {
  background: var(--bg-elev); border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column;
  padding: 18px 14px; gap: 6px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(145deg, #2f6fe4, #1c3f8c); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 0 0 1px rgba(255,255,255,.08) inset;
}
.brand .name { font-weight: 600; font-size: 15px; line-height: 1.15; }
.brand .tag { font-size: 11.5px; color: var(--ink-3); letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--ink-2); font-size: 14px; font-weight: 500; transition: background .15s var(--ease), color .15s var(--ease);
}
.nav a svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: #dbe8ff; }
.nav a.active svg { opacity: 1; }
.nav .sep { height: 1px; background: var(--line); margin: 8px 6px; }
.sidebar .foot { margin-top: auto; padding: 10px 8px 0; font-size: 12px; color: var(--ink-3); line-height: 1.45; }
.sidebar .foot strong { color: var(--ink-2); font-weight: 600; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 14px; padding: 0 24px;
  border-bottom: 1px solid var(--line); background: rgba(10,13,18,.85); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .grow { flex: 1; }
.topbar .menu-btn { display: none; }
.topbar .pill { min-width: 0; overflow: hidden; text-overflow: ellipsis; flex-shrink: 1; }
.topbar .chip { flex-shrink: 0; }
.content { padding: 22px 24px 48px; max-width: 1380px; width: 100%; margin: 0 auto; }
.footer { padding: 18px 24px 28px; border-top: 1px solid var(--line); color: var(--ink-3); font-size: 12.5px; }

/* ---------- status pill ---------- */
.pill { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 500; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-4); }
.pill.ok .dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.pill.warn .dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.pill.bad .dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

/* ---------- banners ---------- */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); font-size: 13.5px; margin-bottom: 16px; }
.banner svg { width: 18px; height: 18px; flex: 0 0 18px; margin-top: 1px; }
.banner.amber { border-color: rgba(224,167,42,.45); background: var(--amber-soft); color: #f1d7a0; }
.banner.red { border-color: rgba(229,96,94,.45); background: var(--bad-soft); color: #ffd0cf; }
.banner.blue { border-color: rgba(91,156,246,.45); background: var(--accent-soft); color: #cfe0ff; }

/* ---------- grid & cards ---------- */
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-h h2 { font-size: 15px; }
.card-h .hint { font-size: 12.5px; color: var(--ink-3); }
.section-title { margin: 26px 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }

/* KPI tiles */
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi .label { font-size: 12.5px; color: var(--ink-3); font-weight: 500; letter-spacing: .01em; }
.kpi .value { font-size: 27px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.kpi .delta { font-size: 12.5px; color: var(--ink-2); display: flex; gap: 10px; flex-wrap: wrap; }
.kpi .delta b { font-weight: 600; }
.up { color: var(--good); } .down { color: var(--bad); } .flat { color: var(--ink-2); }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; letter-spacing: .02em; border: 1px solid transparent; white-space: nowrap; }
.chip .sq { width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.chip.bull { color: #8fe7bd; background: rgba(34,181,115,.13); border-color: rgba(34,181,115,.35); }
.chip.neutral { color: #f2d28a; background: rgba(224,167,42,.13); border-color: rgba(224,167,42,.38); }
.chip.bear { color: #ffb3b1; background: rgba(229,96,94,.13); border-color: rgba(229,96,94,.38); }
.chip.grey { color: var(--ink-2); background: var(--surface-2); border-color: var(--line-strong); }
.chip.hypo { color: #f2d28a; background: var(--amber-soft); border-color: rgba(224,167,42,.38); }
.chip.paper { color: #cfe0ff; background: var(--accent-soft); border-color: rgba(91,156,246,.38); }
.chip.live { color: #8fe7bd; background: var(--good-soft); border-color: rgba(34,181,115,.35); }

/* tables */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; background: var(--surface); position: sticky; top: 0; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tr:hover td { background: rgba(255,255,255,.02); }
.tbl tr.hl td { background: var(--accent-soft); }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--line-strong); }
.tbl .sym { font-weight: 600; }
.tbl.dense th, .tbl.dense td { padding: 6px 8px; font-size: 12.5px; }
.tbl.wrap th, .tbl.wrap td { white-space: normal; }
.tbl td.note-cell { white-space: normal; min-width: 180px; color: var(--ink-3); }
.tbl.compact td { padding: 5px 8px; }

/* bars inside tables */
.bar { height: 6px; background: var(--surface-3); border-radius: 3px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.def > i { background: var(--s-base5); }

/* charts */
.chart { position: relative; width: 100%; height: 320px; }
.chart.tall { height: 420px; }
.chart.short { height: 200px; }
.chart.xs { height: 140px; }
.chart canvas { width: 100% !important; height: 100% !important; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin: 4px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.sq { width: 10px; height: 10px; border-radius: 2px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); font-size: 13px; }

/* regime strip */
.strip { display: flex; height: 14px; border-radius: 4px; overflow: hidden; gap: 1px; background: var(--surface-3); }
.strip i { display: block; height: 100%; }
.strip i.BULL { background: var(--r-bull); } .strip i.NEUTRAL { background: var(--r-neutral); } .strip i.BEAR { background: var(--r-bear); }
.strip-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-3); margin-top: 4px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink); font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease); user-select: none; touch-action: manipulation; }
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-3); border-color: rgba(255,255,255,.2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--accent-strong); border-color: transparent; color: #fff; }
.btn.primary:hover { background: #2f74ea; }
.btn.danger { background: var(--bad-soft); border-color: rgba(229,96,94,.45); color: #ffd0cf; }
.btn.danger:hover { background: rgba(229,96,94,.25); }
.btn.good { background: var(--good-soft); border-color: rgba(34,181,115,.4); color: #c9f3df; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 12.5px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
.spin { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* console (SSE output) */
.console { background: #070a0e; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; color: #b9c4d3; max-height: 420px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.console .ok { color: #8fe7bd; } .console .err { color: #ffb3b1; } .console .dim { color: var(--ink-4); }

/* definition lists */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); } .kv dd { margin: 0; }

/* prose */
.prose { max-width: 78ch; color: var(--ink-2); font-size: 14.5px; }
.prose h3 { color: var(--ink); margin: 18px 0 6px; font-size: 15px; }
.prose ul { padding-left: 18px; } .prose li { margin: 3px 0; }
.prose strong { color: var(--ink); }
.prose table { font-size: 13.5px; }

/* pipeline diagram */
.pipe { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px; }
.pipe .step { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; position: relative; }
.pipe .step .n { font-size: 11px; color: var(--accent); font-weight: 700; letter-spacing: .08em; }
.pipe .step h4 { font-size: 14px; margin: 4px 0 6px; }
.pipe .step p { font-size: 12.5px; color: var(--ink-2); margin: 0; }
.pipe .step::after { content: ""; position: absolute; right: -8px; top: 50%; width: 8px; height: 1px; background: var(--line-strong); }
.pipe .step:last-child::after { display: none; }

/* login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 20% -10%, rgba(59,130,246,.14), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; }
.input { width: 100%; min-height: 44px; padding: 10px 12px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--bg-elev); color: var(--ink); font: inherit; font-size: 16px; }
.input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
label.lbl { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 500; }
.err-text { color: #ffb3b1; font-size: 13px; margin-top: 8px; }

/* misc */
.tag-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.note { font-size: 12.5px; color: var(--ink-3); }
.divider { height: 1px; background: var(--line); margin: 14px 0; }
.two-col { columns: 2; column-gap: 28px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
details summary { cursor: pointer; color: var(--ink-2); font-size: 13.5px; }
.toast { position: fixed; right: 18px; bottom: 18px; background: var(--surface-3); border: 1px solid var(--line-strong); padding: 10px 14px; border-radius: 10px; font-size: 13.5px; z-index: 100; box-shadow: var(--shadow); max-width: 380px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .span-4, .span-5, .span-7, .span-8 { grid-column: span 12; }
  .span-6 { grid-column: span 12; }
  .pipe { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .pipe .step::after { display: none; }
}
@media (max-width: 1023px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 280px; transform: translateX(-100%); transition: transform .22s var(--ease); z-index: 50; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.55); }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px 14px 40px; }
  .topbar { padding: 0 14px; }
  .g-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 640px) {
  .g-4, .g-3, .g-2 { grid-template-columns: 1fr; }
  .kpi .value { font-size: 24px; }
  .chart { height: 260px; } .chart.tall { height: 320px; }
  .two-col { columns: 1; }
  .topbar h1 { font-size: 15px; }
  .topbar h1 .muted, .topbar .pill .muted { display: none; }
  .topbar .chip.paper { display: none; }
}
html, body { max-width: 100%; overflow-x: hidden; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
@media print {
  .sidebar, .topbar, .btn, .footer { display: none !important; }
  .app { display: block; } body { background: #fff; color: #000; }
}
