:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --border: #e3e2de;
  --grid: #ecebe7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-1-fill: rgba(42, 120, 214, 0.12);
  --ref: #9a9993;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;
  --critical-ink: #b42a2a;
  --pill-bg: #ebeae6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --border: #2c2c2a;
    --grid: #262624;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e88;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-1-fill: rgba(57, 135, 229, 0.18);
    --ref: #6f6e69;
    --good-ink: #4cc84c;
    --critical-ink: #ef7b7b;
    --pill-bg: #2a2a28;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --border: #2c2c2a;
  --grid: #262624;
  --text-primary: #f0efec;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e88;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-1-fill: rgba(57, 135, 229, 0.18);
  --ref: #6f6e69;
  --good-ink: #4cc84c;
  --critical-ink: #ef7b7b;
  --pill-bg: #2a2a28;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--surface-0); }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  color: var(--text-primary);
  -webkit-text-size-adjust: 100%;
}
.num, td.n, .kpi .v { font-variant-numeric: tabular-nums; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px 32px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.title { display: flex; align-items: center; gap: 8px; }
h1 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; margin: 0; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.meta { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 12px; }
.meta button { background: none; border: 1px solid var(--border); color: var(--text-secondary); border-radius: 8px; width: 30px; height: 30px; font-size: 15px; cursor: pointer; }

.pill { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; padding: 2px 8px; border-radius: 999px; background: var(--pill-bg); color: var(--text-secondary); text-transform: uppercase; }
.pill.live { background: var(--critical); color: #fff; }

.notice { background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--warning); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; color: var(--text-secondary); }

.status { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; font-size: 12px; color: var(--text-secondary); }
.chip b { color: var(--text-primary); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.good { background: var(--good); } .dot.warning { background: var(--warning); }
.dot.serious { background: var(--serious); } .dot.critical { background: var(--critical); }
.dot.muted { background: var(--ref); }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
@media (min-width: 560px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.kpi .l { font-size: 12px; color: var(--text-secondary); }
.kpi .v { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.up { color: var(--good-ink); } .down { color: var(--critical-ink); }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 10px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.sub { font-size: 12px; color: var(--text-muted); }
.caption { margin: 6px 0 0; font-size: 12px; color: var(--text-muted); }

.seg { display: inline-flex; background: var(--surface-0); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; color: var(--text-secondary); font: inherit; font-size: 12px; padding: 4px 9px; border-radius: 6px; cursor: pointer; }
.seg button.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--border); }

.chart { position: relative; width: 100%; height: 190px; touch-action: pan-y; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .empty { display: flex; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); font-size: 13px; }
.axis text { fill: var(--text-muted); font-size: 10px; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.refline { stroke: var(--ref); stroke-width: 1; stroke-dasharray: 3 3; }
.reflabel { fill: var(--text-muted); font-size: 10px; }
.cross { stroke: var(--text-muted); stroke-width: 1; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

.tip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,0.12); color: var(--text-primary); }
.tip .d { color: var(--text-muted); font-size: 11px; margin-bottom: 2px; }
.tip .row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.tip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.gate-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.gate-row { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.gate-row .what { color: var(--text-secondary); }
.gate-row .val { font-variant-numeric: tabular-nums; color: var(--text-primary); text-align: right; }
.icon { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; color: #fff; font-weight: 700; }
.icon.good { background: var(--good); } .icon.warning { background: var(--warning); color: #3a2a00; }
.icon.critical { background: var(--critical); } .icon.muted { background: var(--ref); }
.bar { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; margin-top: 4px; grid-column: 2 / 4; }
.bar > div { height: 100%; background: var(--series-1); border-radius: 3px; }
.next { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-secondary); }

.mini-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.mini-kpis div { font-size: 12px; color: var(--text-secondary); }
.mini-kpis b { display: block; font-size: 15px; color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }

.table-wrap { overflow-x: auto; margin: 0 -12px; padding: 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-weight: 500; color: var(--text-muted); font-size: 11px; padding: 4px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 6px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.n, th.n { text-align: right; white-space: nowrap; }
td.t { color: var(--text-muted); white-space: nowrap; }
td.msg { min-width: 160px; }
tr:last-child td { border-bottom: 0; }
.lvl { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }

footer { text-align: center; color: var(--text-muted); font-size: 12px; margin-top: 16px; }

/* ---- v2: four views, bottom tabs ------------------------------------------------------ */
main { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.top { margin-bottom: 0; }
p.sub#updated { margin: 2px 0 12px; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: center; gap: 0; background: var(--surface-1); border-top: 1px solid var(--border); padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); }
.tabs button { flex: 1 1 0; max-width: 190px; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: none; border: 0; color: var(--text-muted); font: inherit; font-size: 11px; font-weight: 600; cursor: pointer; }
.tabs button.on { color: var(--series-1); }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.meta button { width: 44px; height: 44px; border-radius: 10px; }

.seg.full { display: flex; width: 100%; margin-bottom: 10px; border-radius: 10px; padding: 3px; }
.seg.full button { flex: 1 1 0; min-width: 0; height: 36px; font-size: 13px; font-weight: 600; padding: 0 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chips button { height: 32px; padding: 0 11px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary); }
.chips button.on { background: var(--text-primary); color: var(--surface-1); border-color: var(--text-primary); }

.hero .row1 { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.hero .big { display: flex; align-items: baseline; gap: 10px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero .big b { font-size: 34px; font-weight: 650; letter-spacing: -0.02em; }
.hero .big span { font-size: 17px; font-weight: 600; }
.hero .note { margin: 4px 0 0; font-size: 12px; color: #8a5a00; }
:root[data-theme="dark"] .hero .note { color: #e0b04c; }
.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); }
.split .l { font-size: 12px; color: var(--text-secondary); }
.split .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.split .s { font-size: 11px; color: var(--text-muted); }
.sleeves { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.sleeves div { background: var(--surface-0); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--text-secondary); }
.sleeves b { display: flex; align-items: center; gap: 6px; font-size: 15px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 3px; border-radius: 2px; display: inline-block; flex: none; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.tiles .kpi { cursor: default; }
.tiles button.kpi { text-align: left; font: inherit; color: inherit; cursor: pointer; }
.kpi .v.sm { font-size: 17px; }

.pos { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 8px; }
.pos .h { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.pos .sym { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pos .sym b { font-size: 16px; }
.side { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: #dcebfb; color: #1c3a5e; }
.side.short { background: #fbe3d9; color: #6b2a10; }
:root[data-theme="dark"] .side { background: #1d3550; color: #cfe2fa; }
:root[data-theme="dark"] .side.short { background: #4a2516; color: #f6d4c5; }
.pos .r { text-align: right; flex: none; font-variant-numeric: tabular-nums; }
.pos .r b { font-size: 16px; }
.pos .r div { font-size: 12px; }
.pos .g { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--grid); }
.pos .g .l { font-size: 11px; color: var(--text-muted); }
.pos .g .v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.empty-card { background: var(--surface-1); border: 1px dashed var(--border); border-radius: 14px; padding: 22px 14px; text-align: center; color: var(--text-secondary); font-size: 13px; }

.deploy-bar { display: flex; gap: 2px; height: 18px; border-radius: 6px; background: var(--grid); overflow: hidden; margin-top: 12px; }
.deploy-bar div { height: 100%; }
.deploy-scale { position: relative; height: 16px; font-size: 10px; color: var(--text-muted); }
.deploy-scale span { position: absolute; top: 2px; white-space: nowrap; }
.legend.sm { font-size: 12px; margin-top: 2px; flex-wrap: wrap; }
.legend.sm i { width: 10px; height: 10px; border-radius: 3px; }
.hbar { display: grid; grid-template-columns: 96px minmax(0, 1fr) 96px; gap: 8px; align-items: center; font-size: 13px; margin-bottom: 8px; }
.hbar .track { position: relative; height: 8px; border-radius: 4px; background: var(--grid); }
.hbar .fill { height: 100%; border-radius: 4px; }
.hbar .tick { position: absolute; top: -3px; width: 2px; height: 14px; background: var(--critical); }
.hbar .n { text-align: right; font-variant-numeric: tabular-nums; }
.lbl { font-size: 12px; color: var(--text-muted); margin: 0 0 6px; }

.rt { width: 100%; }
.rt .row { display: grid; grid-template-columns: minmax(0, 1.5fr) repeat(3, minmax(0, 1fr)); gap: 6px; padding: 9px 0; border-bottom: 1px solid var(--grid); align-items: baseline; font-variant-numeric: tabular-nums; }
.rt .row.head { font-size: 11px; color: var(--text-muted); border-bottom-color: var(--border); padding: 6px 0; }
.rt .row > :not(:first-child) { text-align: right; }
.rt .row .k { font-weight: 600; }
.rt .row .d { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.months { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.months div { border-radius: 10px; padding: 8px 4px; text-align: center; background: var(--surface-0); }
.months .n { font-size: 11px; color: var(--text-secondary); }
.months .v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.months .pos-bg { background: rgba(12, 163, 12, 0.10); }
.months .neg-bg { background: rgba(208, 59, 59, 0.10); }
.yr { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--grid); font-size: 14px; }
p.note { margin: 4px 0 0; font-size: 12px; color: #8a5a00; }
:root[data-theme="dark"] p.note { color: #e0b04c; }
