:root {
  color-scheme: dark;
  --page: #0b0b0b;
  --surface: #191919;
  --surface-2: #222222;
  --text: #efefef;
  --text-2: #9c9c9c;
  --grid: #303030;
  --axis: #474747;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #338ced;
  --accent-track: #0e3d7e;
  --good: #0aac23;
  --warning: #fbb315;
  --serious: #f18a59;
  --critical: #dc3c3d;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--text); font: 15px/1.45 var(--sans); -webkit-text-size-adjust: 100%; }
body { padding-bottom: env(safe-area-inset-bottom); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h2 { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); margin: 28px 0 10px; }
h3 { font-size: 15px; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; gap: 10px; align-items: center; }

/* ---------- frame ---------- */
header.top { position: sticky; top: 0; z-index: 5; background: rgba(11, 11, 11, 0.92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.top-inner { max-width: 1120px; margin: 0 auto; padding: 10px 16px 0; }
.brand { font-family: var(--mono); font-weight: 700; letter-spacing: 0.18em; font-size: 15px; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; margin-top: 8px; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--text-2); cursor: pointer; white-space: nowrap; }
nav.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 1120px; margin: 0 auto; padding: 4px 16px 60px; }

/* ---------- status marks: always an icon and a word, never colour alone ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.status::before { content: "●"; font-size: 11px; }
.status.good::before { color: var(--good); }
.status.warning::before { content: "▲"; color: var(--warning); }
.status.critical::before { content: "✕"; color: var(--critical); font-weight: 700; }
.status.idle::before { content: "○"; color: var(--text-2); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; font-family: var(--mono); }

/* ---------- cards and tiles ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; line-height: 1.2; overflow-wrap: anywhere; }
.tile .value.text { font-size: 17px; }
.tile .sub { color: var(--text-2); font-size: 12.5px; margin-top: 4px; overflow-wrap: anywhere; }
.hero { display: flex; gap: 28px; align-items: flex-end; flex-wrap: wrap; }
.hero .figure { font-size: 56px; font-weight: 600; line-height: 1; }
.hero .figure small { font-size: 22px; font-weight: 500; color: var(--text-2); margin-left: 4px; }

/* ---------- meter: the track is a darker step of the fill's own hue ---------- */
.meter { height: 8px; border-radius: 999px; background: var(--accent-track); overflow: hidden; margin-top: 10px; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--accent); min-width: 2px; }
.meter.warning { background: #5a4208; } .meter.warning > i { background: var(--warning); }
.meter.critical { background: #551819; } .meter.critical > i { background: var(--critical); }

/* ---------- controls ---------- */
.btn { white-space: nowrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; cursor: pointer; min-height: 36px; }
.btn:hover { border-color: var(--axis); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: #ff8f8f; }
.btn.ghost { background: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.icon { min-width: 40px; padding: 7px 8px; text-align: center; }
input[type="text"], input[type="password"], input[type="number"], select, textarea { background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 36px; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 84px; resize: vertical; }
select { width: auto; }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
input[type="color"] { width: 44px; height: 36px; padding: 2px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; }
label.field { display: block; font-size: 13px; color: var(--text-2); margin-top: 10px; }
label.field > input, label.field > select, label.field > textarea { display: block; width: 100%; margin-top: 4px; color: var(--text); }
label.check { display: inline-flex; gap: 6px; align-items: center; margin: 4px 12px 4px 0; font-size: 14px; }
.switch { position: relative; width: 46px; height: 28px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--text-2); transition: left 0.12s; }
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { left: 21px; background: #fff; }
.switch:disabled { opacity: 0.45; cursor: default; }
.ctl { display: grid; grid-template-columns: 92px 1fr auto; gap: 10px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.ctl output { color: var(--text); font-family: var(--mono); font-size: 12.5px; min-width: 52px; text-align: right; }

/* ---------- command box ---------- */
.command { display: flex; gap: 8px; }
.reply { margin-top: 10px; padding: 10px 12px; border-left: 2px solid var(--accent); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.reply.error { border-left-color: var(--critical); }

/* ---------- lists ---------- */
.list > .item { padding: 12px 0; border-top: 1px solid var(--border); }
.list > .item:first-child { border-top: 0; }
.item .meta { color: var(--text-2); font-size: 12.5px; font-family: var(--mono); display: flex; gap: 10px; flex-wrap: wrap; }
.item .said { margin-top: 3px; overflow-wrap: anywhere; }
.item .answer { color: var(--text-2); overflow-wrap: anywhere; }
.item button.more { background: none; border: 0; color: var(--accent); padding: 4px 0; cursor: pointer; font-size: 13px; }
.trace { margin-top: 6px; padding: 8px 10px; background: var(--page); border-radius: 8px; overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line { display: grid; grid-template-columns: 138px 76px 96px 1fr; gap: 8px; padding: 5px 0; border-top: 1px solid var(--border); font-family: var(--mono); font-size: 12.5px; }
.log-line .msg { overflow-wrap: anywhere; font-family: var(--sans); font-size: 13.5px; }
.log-line .data { grid-column: 4; color: var(--text-2); overflow-wrap: anywhere; }
@media (max-width: 640px) { .log-line { grid-template-columns: 1fr auto; } .log-line .msg, .log-line .data { grid-column: 1 / -1; } }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 5px 8px; border-top: 1px solid var(--border); }
table.data th { color: var(--text-2); font-weight: 500; border-top: 0; }
table.data th:first-child, table.data td:first-child { text-align: left; }

/* ---------- charts ---------- */
figure.chart { margin: 0; }
figure.chart figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 6px; }
figure.chart figcaption b { font-weight: 600; }
figure.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
figure.chart .plot { position: relative; }
.chart text { fill: var(--text-2); font-size: 11px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart .bar { fill: var(--accent); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart .bar.on { fill: #6aabf1; }
.tooltip { position: absolute; pointer-events: none; background: #2b2b2b; border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -100%); z-index: 3; }
.tooltip b { font-weight: 600; }

/* ---------- misc ---------- */
.toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2b2b2b; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; max-width: min(92vw, 560px); z-index: 20; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); }
.toast.error { border-color: var(--critical); }
.login { max-width: 420px; margin: 12vh auto 0; }
.qr { background: #fff; border-radius: 8px; padding: 6px; width: 220px; max-width: 100%; }
.qr svg { display: block; width: 100%; height: auto; }
.token { font-family: var(--mono); font-size: 12.5px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; user-select: all; }
ol.steps { padding-left: 22px; margin: 8px 0; }
ol.steps li { margin: 7px 0; }
ol.steps code, p code { font-family: var(--mono); font-size: 12.5px; background: var(--page); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; overflow-wrap: anywhere; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--border); vertical-align: -1px; margin-right: 4px; }
