:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;   /* series 1 blue   */
  --s2: #eb6834;   /* series 2 orange */
  --s3: #1baf7a;   /* series 3 aqua   */
  --pos: #2a78d6;  /* diverging: positive pole */
  --neg: #e34948;  /* diverging: negative pole */
  --mid: #f0efec;  /* diverging: neutral midpoint */
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --bad-text: #b42323;
  --focus: #2a78d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --pos: #3987e5; --neg: #e66767; --mid: #383835;
    --good-text: #0ca30c; --bad-text: #f08a8a; --focus: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #f0efec; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --pos: #3987e5; --neg: #e66767; --mid: #383835;
  --good-text: #0ca30c; --bad-text: #f08a8a; --focus: #3987e5;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--s1); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.up { color: var(--good-text); }
.down { color: var(--bad-text); }

/* layout */
header.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in oklab, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--grid);
}
.top-inner { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand h1 { font-size: 16px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; min-width: 0; }
nav.tabs a {
  padding: 6px 10px; border-radius: 8px; color: var(--ink-2); white-space: nowrap; font-weight: 500;
}
nav.tabs a:hover { background: var(--surface-2); text-decoration: none; }
nav.tabs a[aria-current="page"] { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--ring); }
.top-actions { display: flex; align-items: center; gap: 8px; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
.grid { display: grid; gap: 12px; }
.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-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 960px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-3, .g-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .g-2 { grid-template-columns: minmax(0, 1fr); }
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card.tile { padding: 12px; }
  .card.tile .value { font-size: 19px; }
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: inset 0 0 0 1px var(--ring), var(--shadow);
  padding: 14px 16px; min-width: 0;
}
.card > h2 { margin-bottom: 10px; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: -6px; margin-bottom: 10px; }

/* stat tiles */
.tile .label { font-size: 12px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; margin: 4px 0 2px; }
.tile .meta { font-size: 12px; color: var(--muted); }

/* badges: colour carried by the icon; text stays ink */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 6px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink); white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--ring);
}
.badge .ic { font-size: 10px; line-height: 1; }
.b-good .ic { color: var(--good); }
.b-critical .ic { color: var(--critical); }
.b-serious .ic { color: var(--serious); }
.b-warning .ic { color: var(--warning); }
.b-neutral .ic { color: var(--muted); }

/* diverging score bar */
.score { display: inline-flex; align-items: center; gap: 6px; }
.score .bar { position: relative; width: 56px; height: 6px; border-radius: 3px; background: var(--mid); }
.score .bar::after { content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 1px; background: var(--axis); }
.score .fill { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.score .v { min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; color: var(--ink-2); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 8px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { font-weight: 600; color: var(--ink-2); font-size: 12px; position: sticky; top: 0; background: var(--surface); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th[aria-sort="ascending"]::after { content: " ↑"; }
th[aria-sort="descending"]::after { content: " ↓"; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="date"], input[type="number"], input[type="url"], input[type="search"], select, textarea {
  background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 7px 10px; min-width: 0; width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.form-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
button, .btn {
  border: 1px solid var(--axis); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer;
  font-weight: 500; display: inline-flex; align-items: center; gap: 6px;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
button.primary:hover { opacity: 0.88; }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
button:disabled { opacity: 0.5; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--axis); border-radius: 8px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 7px 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); font-weight: 500; }
.seg label + input + label, .seg label + label { border-left: 1px solid var(--axis); }
.seg input:checked + label { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 -2px 0 var(--ink); }
.seg input:focus-visible + label { outline: 2px solid var(--focus); outline-offset: -2px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--ring); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters > * { width: auto; }
.filters input[type="search"] { width: 200px; }

/* charts */
.chart { position: relative; width: 100%; }
.chart-h-lg { height: 360px; }
.chart-h-md { height: 260px; }
.chart-h-sm { height: 120px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-bottom: 8px; }
.legend .k { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.legend .sw.box { height: 10px; width: 10px; border-radius: 2px; }
details.tv { margin-top: 8px; }
details.tv summary { cursor: pointer; color: var(--muted); font-size: 12px; }
details.tv[open] summary { margin-bottom: 6px; }
.tv .table-wrap { max-height: 280px; overflow-y: auto; }

/* regime component bars */
.comp { display: grid; grid-template-columns: 130px minmax(0, 1fr) 44px; gap: 8px; align-items: center; font-size: 12px; padding: 3px 0; }
.comp .track { position: relative; height: 8px; background: var(--mid); border-radius: 4px; }
.comp .track::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.comp .fill { position: absolute; top: 0; bottom: 0; border-radius: 4px; }
.comp .v { text-align: right; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* sector tiles */
.sectors { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.sector {
  border-radius: 8px; padding: 10px 12px; box-shadow: inset 0 0 0 1px var(--ring); cursor: pointer;
  display: flex; flex-direction: column; gap: 4px; min-height: 92px;
}
.sector:hover { box-shadow: inset 0 0 0 1px var(--axis); }
.sector .name { font-weight: 600; font-size: 12px; line-height: 1.25; }
.sector .stats { display: flex; gap: 10px; font-size: 12px; color: var(--ink-2); flex-wrap: wrap; }

/* lists */
.list { display: flex; flex-direction: column; }
.list .it { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--grid); align-items: center; }
.list .it:last-child { border-bottom: none; }
.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
.note { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface);
  padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
.md h1 { font-size: 18px; margin: 0 0 10px; }
.md h2 { margin: 16px 0 6px; }
.md pre { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, monospace; background: var(--surface-2); padding: 10px; border-radius: 8px; }
.md ul { padding-left: 18px; margin: 6px 0; }
.hidden { display: none !important; }
.stale { opacity: 0.55; transition: opacity .15s; }

/* planner result tables: let long cells wrap instead of clipping */
#planResult td, #planEarn td { white-space: normal; }
#planResult td:first-child, #planEarn td:first-child { width: 42%; }

/* ---------- sign-in, re-confirmation, 2FA ---------- */
.login-page { min-height: 100vh; display: grid; place-items: start center; padding: 48px 16px; }
.login-wrap { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.login-brand { display: flex; align-items: center; gap: 10px; justify-content: center; }
.login-brand h1 { font-size: 20px; }
.login-wrap .card { gap: 12px; }
.login-wrap input, dialog.sudo input { width: 100%; font-size: 16px; } /* 16px stops iOS zooming in */
.login-foot { text-align: center; }
.stack { display: flex; flex-direction: column; }
.qr { display: flex; justify-content: center; }
.qr svg { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
pre.codes { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.7;
  background: var(--surface-2); padding: 10px 14px; border-radius: 8px; margin: 8px 0; user-select: all; white-space: pre-wrap; }
dialog.sudo { border: 1px solid var(--grid); max-width: 360px; width: calc(100% - 32px); color: var(--ink); }
dialog.sudo::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog.sudo form { gap: 12px; }
#whoami { margin-right: 4px; }
@media (max-width: 640px) { #whoami { display: none; } }

/* the hidden attribute must win over component display rules (login steps, admin-only nav) */
[hidden] { display: none !important; }
