/* Layout: sticky top bar, single centered column (max 1180px), cards only for KPIs and forms. */
:root {
  --bg: #F3F4F6; --panel: #FFFFFF; --sunk: #ECEEF2; --fg: #15181E; --muted: #5A6170; --line: #DDE1E7;
  --accent: #2F5BD3; --accent-fg: #FFFFFF;
  --s0: #2F5BD3; --s1: #C77C12; --s2: #13897A; --s3: #8B4CB3; --s4: #C2410C; --s5: #4B5563;
  --ok: #1E7F4F; --warn: #B26A00; --bad: #C0362C; --ok-bg: #E4F3EB; --warn-bg: #FBF0DC; --bad-bg: #FBE6E4;
  --grid: #E6E9EE; --ref: #6B7280;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "IBM Plex Serif", Georgia, serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1014; --panel: #161920; --sunk: #1C2029; --fg: #E7E9ED; --muted: #9AA1AD; --line: #2A2F3A;
    --accent: #7C9BFF; --accent-fg: #0E1014;
    --s0: #7C9BFF; --s1: #F0B04A; --s2: #38C2AE; --s3: #C190E8; --s4: #FF8A5B; --s5: #A1A8B5;
    --ok: #4CC38A; --warn: #F0B04A; --bad: #FF7A6E; --ok-bg: #12291F; --warn-bg: #2E2410; --bad-bg: #321715;
    --grid: #252A34; --ref: #9AA1AD; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1014; --panel: #161920; --sunk: #1C2029; --fg: #E7E9ED; --muted: #9AA1AD; --line: #2A2F3A;
  --accent: #7C9BFF; --accent-fg: #0E1014;
  --s0: #7C9BFF; --s1: #F0B04A; --s2: #38C2AE; --s3: #C190E8; --s4: #FF8A5B; --s5: #A1A8B5;
  --ok: #4CC38A; --warn: #F0B04A; --bad: #FF7A6E; --ok-bg: #12291F; --warn-bg: #2E2410; --bad-bg: #321715;
  --grid: #252A34; --ref: #9AA1AD; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 15px; line-height: 1.5; }
body { min-height: 100vh; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
.num, td.num, .tnum { font-variant-numeric: tabular-nums; }

/* Top bar */
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); background: var(--panel); z-index: 30; }
.bar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--panel); border-bottom: 1px solid var(--line); }
.bar-in { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 20px; min-height: 56px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; text-decoration: none; color: var(--fg); }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { display: block; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { text-decoration: none; color: var(--muted); padding: 16px 12px 14px; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.nav a:hover { color: var(--fg); }
.nav a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }
.who { position: relative; }
.who-btn { background: none; border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 4px; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--sunk); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px; padding: 6px; display: grid; }
.menu .meta { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--sunk); }

/* Page */
.page { max-width: 1180px; margin: 0 auto; padding-block: 28px 64px; display: grid; gap: 40px;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.head { display: grid; gap: 8px; }
.eyebrow { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0; }
.title { font-family: var(--serif); font-weight: 500; font-size: clamp(26px, 3.4vw, 34px); letter-spacing: -.01em; }
.lede { margin: 0; max-width: 70ch; font-size: 16px; }
.lede b { font-weight: 600; font-variant-numeric: tabular-nums; }
.small { font-size: 13px; color: var(--muted); margin: 0; }
.sec { display: grid; gap: 14px; min-width: 0; align-content: start; }
.sec-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px; }
.sec-head > div:first-child { max-width: 70ch; min-width: 0; }
.h2 { font-size: 18px; font-weight: 600; }
.note { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 40px; }
.two > * { min-width: 0; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: grid; gap: 4px; min-width: 0; }
.kpi-l { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.kpi-v { font-family: var(--serif); font-size: 30px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-v small { font-family: var(--sans); font-size: 13px; color: var(--muted); margin-left: 4px; }
.kpi-s { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chg { font-weight: 600; color: var(--fg); }

/* Controls */
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.field { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.input, .select, textarea.input { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; color: var(--fg); min-width: 0; }
.input[type=number] { width: 8em; font-variant-numeric: tabular-nums; }
.select { padding-right: 28px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 7px 14px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--sunk); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.chip[aria-pressed="true"] { border-color: var(--fg); background: var(--sunk); font-weight: 500; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }

/* Tables */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--panel); font-family: var(--mono); text-transform: uppercase; letter-spacing: .04em; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--fg); }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
td.name { font-weight: 500; }
tr.thin td { color: var(--muted); }
.wrap { white-space: normal; min-width: 220px; }
.pill { display: inline-block; font-size: 12px; border-radius: 999px; padding: 1px 9px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }

/* Charts */
.chart { position: relative; min-height: 200px; min-width: 0; }
.chart svg { display: block; overflow: visible; }
.grid { stroke: var(--grid); }
.tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; font-family: var(--sans); }
.lab { fill: var(--fg); font-size: 12.5px; font-family: var(--sans); }
.val { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; font-family: var(--sans); }
.span { stroke: var(--grid); stroke-width: 4; stroke-linecap: round; }
.stem { stroke: var(--grid); stroke-width: 2; }
.dotm { stroke: var(--panel); stroke-width: 1.5; cursor: pointer; }
.ref { stroke: var(--ref); stroke-width: 1.5; stroke-dasharray: 4 3; }
.ref-t { fill: var(--muted); font-size: 12px; }
.your { stroke: var(--bad); stroke-width: 2; }
.your-t { fill: var(--bad); font-size: 12px; font-weight: 600; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sw.hollow { border: 2px solid var(--s0); background: transparent; }
.sw.line { width: 16px; height: 0; border-radius: 0; border-top: 2px dashed var(--ref); }
.sw.yl { width: 16px; height: 0; border-radius: 0; border-top: 2px solid var(--bad); }
.tip { position: absolute; z-index: 5; pointer-events: none; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 6px 20px rgba(0,0,0,.14); border-radius: 6px; padding: 8px 10px; font-size: 12.5px; color: var(--muted); max-width: 260px; }
.tip b { color: var(--fg); font-weight: 600; display: block; }
.empty { display: grid; place-items: center; min-height: 160px; color: var(--muted); font-size: 14px; text-align: center; padding: 16px; border: 1px dashed var(--line); border-radius: var(--r); }
.skeleton { background: linear-gradient(90deg, var(--sunk), var(--line), var(--sunk)); background-size: 200% 100%; border-radius: var(--r); min-height: 160px; }
@media (prefers-reduced-motion: no-preference) { .skeleton { animation: sh 1.4s linear infinite; } }
@keyframes sh { to { background-position: -200% 0; } }

/* Calculator */
.out { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }

/* Auth */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.auth-side { background: var(--panel); border-right: 1px solid var(--line); padding: 48px max(24px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; justify-content: space-between; gap: 32px; }
.auth-side .big { font-family: var(--serif); font-size: clamp(28px, 3.6vw, 42px); line-height: 1.15; max-width: 16ch; }
.ticker { display: grid; gap: 2px; font-family: var(--mono); font-size: 13px; max-width: 380px; }
.ticker div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); padding: 8px 0; color: var(--muted); }
.ticker span:last-child { color: var(--fg); }
.auth-main { display: grid; place-items: center; padding: 32px max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px)); }
.form { width: 100%; max-width: 380px; display: grid; gap: 14px; }
.form h1 { font-size: 24px; font-weight: 600; }
.form .field { color: var(--fg); font-size: 14px; font-weight: 500; }
.form .input { width: 100%; padding: 9px 12px; }
.form .btn.primary { padding: 10px; width: 100%; }
.msg { border-radius: 6px; padding: 10px 12px; font-size: 14px; }
.msg.bad { background: var(--bad-bg); color: var(--bad); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.links { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; flex-wrap: wrap; }
@media (max-width: 760px) { .auth { grid-template-columns: 1fr; } .auth-side { border-right: 0; border-bottom: 1px solid var(--line); padding-block: 28px; } .ticker { display: none; } }

/* Admin */
.subnav { display: flex; gap: 6px; flex-wrap: wrap; }
.subnav a { text-decoration: none; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; font-size: 14px; background: var(--panel); }
.subnav a[aria-current="page"] { color: var(--fg); border-color: var(--fg); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; display: grid; gap: 12px; min-width: 0; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.code { font-family: var(--mono); font-size: 12.5px; background: var(--sunk); border-radius: 6px; padding: 8px 10px; overflow-x: auto; white-space: pre; }
textarea.input { width: 100%; min-height: 140px; font-family: var(--mono); font-size: 12.5px; }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); }
dialog { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--fg); padding: 20px; max-width: min(460px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
details.foot { font-size: 13px; color: var(--muted); }
details.foot summary { cursor: pointer; color: var(--fg); font-weight: 500; }
details.foot ul { padding-left: 18px; display: grid; gap: 4px; }
[hidden] { display: none !important; }
@media (max-width: 640px) {
  .bar-in { gap: 0 12px; padding-top: 8px; }
  .who { margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; }
  .nav a { padding: 10px 10px 10px; }
}
