:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --bad-text: #b02a2a;
  --seq-100: #cde2fb; --seq-250: #86b6ef; --seq-450: #2a78d6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-text: #0ca30c;
    --bad-text: #e66767;
    --seq-100: #184f95; --seq-250: #2a78d6; --seq-450: #86b6ef;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.good { color: var(--good-text); }
.bad { color: var(--bad-text); }

/* Layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.nav { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.nav a { color: var(--ink-2); padding: 8px 10px; border-radius: 8px; display: flex; justify-content: space-between; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.nav .spacer { flex: 1; }
.nav .badge { font-size: 11px; background: var(--surface-2); border-radius: 10px; padding: 0 7px; }
.main { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-detail { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .g2, .g3, .g-detail { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .shell { grid-template-columns: 1fr; } .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; } .nav .spacer { display: none; } }
.stack > * + * { margin-top: 16px; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; }
.tile .sub { color: var(--muted); font-size: 12px; }

/* Verdict pills: status colour + icon + label, never colour alone */
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 9px 2px 7px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.strong { color: var(--good-text); }
.pill.strong::before { background: var(--good); }
.pill.investigate { color: var(--ink-2); }
.pill.investigate::before { background: var(--warning); }
.pill.pass { color: var(--muted); }
.pill.pass::before { background: var(--axis); }
.pill.high::before { background: var(--critical); }
.pill.medium::before { background: var(--serious); }
.status-tag { font-size: 11px; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); text-transform: capitalize; }

.score { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 26px; border-radius: 7px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--surface-2); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--grid); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
.thumb { width: 44px; height: 44px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--border); }
.title-cell { min-width: 240px; max-width: 380px; }
.title-cell .t { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Forms */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 7px 10px; min-width: 0; }
textarea { width: 100%; min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button, .btn { background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 7px 14px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: progress; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea { width: 100%; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 3px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }

/* Banners & toasts */
.banner { border: 1px solid var(--border); border-left: 4px solid var(--warning); background: var(--surface); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.banner.info { border-left-color: var(--accent); }
.banner.error { border-left-color: var(--critical); }
#toast { position: fixed; bottom: 20px; right: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 8px; max-width: 420px; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.error { background: var(--critical); color: #fff; }

/* Lists */
ul.insights { margin: 0; padding-left: 18px; }
ul.insights li { margin-bottom: 6px; }
.risk { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 6px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.kv div:nth-child(odd) { color: var(--ink-2); }
.kv div:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }
.kv .total { font-weight: 700; border-top: 1px solid var(--grid); padding-top: 4px; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--surface-2); border-radius: 6px; padding: 2px 8px; font-size: 12px; }

/* Opportunity cards */
.opp-list { display: grid; gap: 10px; }
.opp { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px; border-radius: 8px; border: 1px solid var(--grid); color: inherit; }
.opp:hover { background: var(--surface-2); text-decoration: none; }
.opp .thumb { width: 56px; height: 56px; }
.opp .meta { color: var(--ink-2); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
.opp .why { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* Sub-score bars */
.bars .row { display: grid; grid-template-columns: 100px 1fr 34px; gap: 10px; align-items: center; margin-bottom: 8px; }
.bars .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--seq-450); border-radius: 0 4px 4px 0; }

/* Charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--s1); opacity: 0.08; }
.chart .bar { fill: var(--s1); }
.chart .bar.dim { opacity: 0.35; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .dot { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
.chart-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.12); border-radius: 8px; padding: 6px 9px; font-size: 12px; white-space: nowrap; z-index: 5; display: none; }
.chart-tip b { font-variant-numeric: tabular-nums; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 30px 0; text-align: center; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }
.stackbar { display: flex; height: 22px; border-radius: 5px; overflow: hidden; gap: 2px; background: var(--surface); }
.stackbar div { height: 100%; }
details.toggle summary { cursor: pointer; color: var(--accent-ink); font-size: 12px; margin-top: 8px; }

/* Pipeline board */
.board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 200px; }
.col h3 { text-transform: capitalize; display: flex; justify-content: space-between; }
.pcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; display: block; color: inherit; }
.pcard:hover { text-decoration: none; border-color: var(--accent); }
.pcard .t { font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

pre.log { background: var(--surface-2); padding: 10px; border-radius: 8px; font-size: 12px; max-height: 320px; overflow: auto; white-space: pre-wrap; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; }
.login .field { margin-bottom: 12px; }
.login button { width: 100%; justify-content: center; }
.error-text { color: var(--bad-text); font-size: 13px; min-height: 18px; }
.hidden { display: none !important; }
