:root {
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e2e1dc;
  --grid: #e7e6e1;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6e69;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-1-soft: #cde2fb;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #7a5200;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #a32121;
  --focus: #2a78d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / .04), 0 1px 1px rgb(0 0 0 / .03);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #242422;
    --border: #33332f;
    --grid: #2c2c29;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #9a998f;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-1-soft: #184f95;
    --good-ink: #5fd35f;
    --warning-ink: #fab219;
    --critical-ink: #ff8a8a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--surface-0); color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
h1 { font-size: 22px; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface-1); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a { color: var(--text-secondary); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.topbar nav a[aria-current="page"], .topbar nav a:hover { background: var(--surface-2); color: var(--text-primary); }
.signout { display: flex; align-items: center; gap: 10px; margin: 0; }
.who { color: var(--text-secondary); }

main { padding: 20px 24px 48px; max-width: 1480px; margin: 0 auto; }
main.narrow { max-width: 560px; padding-top: 10vh; }

/* ---------- cards, forms, buttons ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card.auth { padding: 28px; }
.card.auth.wide { max-width: 640px; }
main.narrow:has(.wide) { max-width: 680px; }
.muted, .fine { color: var(--text-secondary); }
.fine { font-size: 12.5px; }
label { display: block; font-weight: 550; margin: 0 0 14px; }
input, select {
  display: block; width: 100%; margin-top: 6px; padding: 9px 11px; font: inherit; color: var(--text-primary);
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 7px;
}
input:focus, select:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 25%, transparent); outline-offset: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; font: inherit; font-weight: 550;
  color: var(--text-primary); background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; text-decoration: none; white-space: nowrap; list-style: none;
}
.btn:hover { border-color: var(--text-muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.link { background: none; border: 0; color: var(--accent); padding: 8px 0; }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.danger { color: var(--critical-ink); }
.card.auth .btn.primary { width: 100%; margin-top: 4px; }
summary.btn::-webkit-details-marker { display: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row input { width: auto; margin: 0; flex: 1 1 200px; }
form.inline, details.inline { display: inline-flex; gap: 6px; align-items: center; margin: 2px 4px 2px 0; }
form.inline input, form.inline select { width: auto; margin: 0; padding: 4px 8px; }
.grid-form { max-width: 420px; }
.grid-form.cols { max-width: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; align-items: end; }
.grid-form.cols .btn { margin-bottom: 14px; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; border: 1px solid; }
.alert.error { border-color: var(--critical); color: var(--critical-ink); background: color-mix(in srgb, var(--critical) 8%, var(--surface-1)); }
.alert.ok { border-color: var(--good); color: var(--good-ink); background: color-mix(in srgb, var(--good) 8%, var(--surface-1)); }
.alert.warn { border-color: var(--warning); color: var(--text-primary); background: color-mix(in srgb, var(--warning) 14%, var(--surface-1)); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.good { color: var(--good-ink); } .pill.good::before { background: var(--good); }
.pill.warn { color: var(--warning-ink); } .pill.warn::before { background: var(--warning); }
.pill.bad { color: var(--critical-ink); } .pill.bad::before { background: var(--critical); }

.enroll { display: grid; grid-template-columns: 200px 1fr; gap: 24px; align-items: start; margin: 8px 0 16px; }
.qr { background: #fff; border-radius: 8px; padding: 4px; width: 200px; height: 200px; }
.qr svg { width: 100%; height: 100%; display: block; }
code.secret { font-size: 15px; letter-spacing: .04em; background: var(--surface-2); padding: 6px 10px; border-radius: 6px; display: inline-block; word-break: break-all; }
ol.codes { columns: 2; font-size: 15px; padding-left: 22px; margin: 16px 0 20px; }
ol.codes li { margin-bottom: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.ua { color: var(--text-secondary); max-width: 420px; overflow-wrap: anywhere; }
td.path { max-width: 520px; overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
td.nowrap { white-space: nowrap; }
tr.flag td:first-child { box-shadow: inset 3px 0 var(--critical); }
td.actions { min-width: 360px; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 10px; }

/* ---------- dashboard ---------- */
.dash-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.dash-head h1 { margin: 0; }
.dash-head .spacer { flex: 1; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.seg button { font: inherit; font-weight: 550; border: 0; background: none; color: var(--text-secondary); padding: 5px 11px; border-radius: 6px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }
.freshness { color: var(--text-secondary); font-size: 12.5px; }
.banner { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-1); margin-bottom: 16px; }
.banner .big { font-weight: 650; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.banner .sym { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700; }
.banner.up .sym { background: var(--good); }
.banner.down { border-color: var(--critical); }
.banner.down .sym { background: var(--critical); }
.banner.degraded { border-color: var(--warning); }
.banner.degraded .sym { background: var(--warning); color: #000; }

.section-label { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 22px 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { color: var(--text-secondary); font-size: 12.5px; font-weight: 550; display: flex; justify-content: space-between; gap: 8px; }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -.01em; margin: 4px 0 2px; white-space: nowrap; }
.tile .value small { font-size: 14px; font-weight: 550; color: var(--text-secondary); margin-left: 2px; }
.tile .sub { color: var(--text-secondary); font-size: 12px; min-height: 17px; }
.tile .delta.bad { color: var(--critical-ink); }
.tile .delta.good { color: var(--good-ink); }
.tile svg.spark { display: block; width: 100%; height: 30px; margin-top: 8px; }
.tile.status-warn { border-top: 3px solid var(--warning); }
.tile.status-bad { border-top: 3px solid var(--critical); }
.meter { height: 6px; border-radius: 3px; background: var(--series-1-soft); margin-top: 10px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
.meter.warn > span { background: var(--warning); }
.meter.bad > span { background: var(--critical); }

.charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.charts .card { margin: 0; }
.charts .card.full { grid-column: 1 / -1; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.chart-head h2 { margin: 0; }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chart { position: relative; height: 220px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: 13px; }
.axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.endlabel { font-size: 11.5px; font-weight: 600; fill: var(--text-secondary); }
.tooltip {
  position: absolute; pointer-events: none; z-index: 3; min-width: 140px; padding: 8px 10px; border-radius: 8px;
  background: var(--surface-1); border: 1px solid var(--border); box-shadow: 0 4px 16px rgb(0 0 0 / .12); font-size: 12.5px;
}
.tooltip .tt-time { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .tt-row i { width: 10px; height: 3px; border-radius: 2px; display: inline-block; margin-right: 4px; }
.tooltip .tt-row b { font-variant-numeric: tabular-nums; }
.tables { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tables .card { margin: 0; }
.tables .card.full { grid-column: 1 / -1; }
.note { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 900px) {
  .charts, .tables { grid-template-columns: minmax(0, 1fr); }
  .enroll { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  main { padding: 14px 16px 40px; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .who { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px; }
  .tile .value { font-size: 21px; }
  ol.codes { columns: 1; }
}
@media (max-width: 700px) {
  .table-wrap table { min-width: 620px; }
  td.path { max-width: 280px; }
}
