:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #f8f8f6;
  --border: #e3e2dc;
  --text: #16160f;
  --text-2: #5a5950;
  --muted: #8a897f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #1a7f37; --good-bg: #e6f4ea;
  --warn: #9a6700; --warn-bg: #fff4d6;
  --crit: #b42318; --crit-bg: #fde8e6;
  --info: #2a5db0; --info-bg: #e8f0fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141412; --surface: #1d1d1a; --surface-2: #232320; --border: #31312c;
    --text: #f2f1ea; --text-2: #b9b8ad; --muted: #85847a; --accent: #3987e5;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #2a9d2a; --s7: #9085e9; --s8: #e66767;
    --good: #4cc26b; --good-bg: #16301d; --warn: #e5b53b; --warn-bg: #342a10; --crit: #f0776c; --crit-bg: #3a1a17; --info: #7fb0f5; --info-bg: #17243a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141412; --surface: #1d1d1a; --surface-2: #232320; --border: #31312c;
  --text: #f2f1ea; --text-2: #b9b8ad; --muted: #85847a; --accent: #3987e5;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #2a9d2a; --s7: #9085e9; --s8: #e66767;
  --good: #4cc26b; --good-bg: #16301d; --warn: #e5b53b; --warn-bg: #342a10; --crit: #f0776c; --crit-bg: #3a1a17; --info: #7fb0f5; --info-bg: #17243a;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 18px; }
h3 { font-size: 14px; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--crit); }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 24px; display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-mark { width: 10px; height: 10px; border-radius: 3px; background: linear-gradient(135deg, var(--s1), var(--s3)); display: inline-block; }
.topbar .spacer { flex: 1; }
.topbar .meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 4px 8px; font-size: 12px; }

/* tabs */
.tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { padding: 12px 14px; border: 0; background: none; color: var(--text-2); font: inherit; font-size: 13.5px; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab:hover { color: var(--text); }

main { max-width: 1280px; margin: 0 auto; padding: 24px 16px 64px; }
.page { display: none; }
.page.active { display: block; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--text-2); max-width: 70ch; }

/* cards & grids */
.grid { display: grid; gap: 16px; }
.grid.tiles { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .grid.tiles { grid-template-columns: repeat(2, 1fr); } }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 900px) { .grid.two, .grid.three { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 0; }
.section { margin-top: 24px; }
.section > h2 { margin-bottom: 12px; }
.card h3 { margin-bottom: 10px; }
.tile .label { color: var(--text-2); font-size: 12.5px; }
.tile .value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }
.tile .delta { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.delta.up { background: var(--good-bg); color: var(--good); }
.delta.down { background: var(--crit-bg); color: var(--crit); }
.delta.flat { background: var(--surface-2); color: var(--text-2); }

.chart-wrap { position: relative; height: 300px; }
.chart-wrap.tall { height: 360px; }
.chart-wrap.short { height: 220px; }

/* tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { color: var(--text-2); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; background: var(--surface); }
th.num, td.num { text-align: right; }
tbody tr:hover { background: var(--surface-2); }
tr.total td { font-weight: 600; border-top: 2px solid var(--border); }
tr.sub td { color: var(--text-2); }
td .bar { display: inline-block; height: 6px; border-radius: 3px; background: var(--s1); vertical-align: middle; margin-right: 6px; opacity: .8; }
.table-wrap { overflow-x: auto; }
.table-wrap.scroll { max-height: 600px; overflow-y: auto; }
.clickable { cursor: pointer; }
.clickable:hover td:first-child { color: var(--accent); }
.spark { width: 110px; height: 22px; vertical-align: middle; }

/* notes */
.note { display: grid; grid-template-columns: 8px 1fr; gap: 14px; padding: 14px 16px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); margin-bottom: 10px; }
.note .stripe { border-radius: 4px; }
.note.critical .stripe { background: var(--crit); } .note.warning .stripe { background: var(--warn); }
.note.good .stripe { background: var(--good); } .note.info .stripe { background: var(--info); }
.note .area { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.note .title { font-weight: 600; font-size: 14.5px; margin: 2px 0 4px; }
.note .body { color: var(--text-2); }
.badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.badge.critical { background: var(--crit-bg); color: var(--crit); } .badge.warning { background: var(--warn-bg); color: var(--warn); }
.badge.good { background: var(--good-bg); color: var(--good); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.new { background: var(--info-bg); color: var(--info); }

/* breakdown list (safe to draw) */
.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); gap: 12px; }
.breakdown li.total { font-weight: 600; border-bottom: 0; border-top: 2px solid var(--border); margin-top: 4px; padding-top: 12px; font-size: 15px; }
.breakdown li .why { color: var(--muted); font-size: 12px; display: block; }
.hero { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.hero-sub { color: var(--text-2); margin-top: 6px; }

/* upload / empty */
.empty { text-align: center; padding: 64px 24px; }
.empty h2 { margin-bottom: 8px; }
.empty p { color: var(--text-2); max-width: 56ch; margin: 0 auto 20px; }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 36px; background: var(--surface); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--info-bg); }
.progress { margin-top: 12px; color: var(--text-2); }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 24px; max-width: 520px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog.wide { max-width: 1000px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

/* controls */
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
select, input[type=search], input[type=password] { font: inherit; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
label { font-size: 12px; color: var(--text-2); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(380px, calc(100% - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.login-card .brand { font-size: 18px; margin-bottom: 4px; }
.login-card form { display: grid; gap: 8px; margin-top: 16px; }
.login-card input { padding: 10px 12px; }
.login-card .btn { margin-top: 6px; padding: 10px; }
.error { color: var(--crit); }
.caveat { font-size: 12px; color: var(--muted); margin-top: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-2); } .kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) { .topbar { padding: 0 12px; gap: 10px; } .topbar .meta { display: none; } main { padding: 16px 12px 48px; } .tile .value { font-size: 22px; } .hero { font-size: 32px; } }

.expand-btn { position: absolute; top: 12px; right: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 6px; width: 26px; height: 26px; font-size: 14px; line-height: 1; cursor: pointer; opacity: .6; }
.expand-btn:hover { opacity: 1; color: var(--text); }
dialog.full { max-width: calc(100vw - 48px); width: calc(100vw - 48px); height: calc(100vh - 48px); }
.chart-wrap.big { height: calc(100vh - 140px); }
.media-strip { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; }
@media (max-width: 800px) { .media-strip { grid-template-columns: 1fr; } }

td.mono { white-space: nowrap; }
