:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;
  --series-1-ghost: #86b6ef;
  --series-2: #eb6834;
  --good: #006300;
  --bad: #d03b3b;
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #256abf;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --ink-muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5; --series-1-ghost: #1c5cab; --series-2: #d95926;
    --good: #0ca30c; --bad: #ec835a; --wash: rgba(255, 255, 255, 0.07); --accent: #6da7ec;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #f0efec; --ink-2: #c3c2b7; --ink-muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --ring: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5; --series-1-ghost: #1c5cab; --series-2: #d95926;
  --good: #0ca30c; --bad: #ec835a; --wash: rgba(255, 255, 255, 0.07); --accent: #6da7ec;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.45 var(--font); }
h1, h2, h3 { margin: 0; font-weight: 600; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.noscript { padding: 16px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 16px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }

/* controls */
.btn { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
.btn:hover { background: var(--wash); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tab:focus-visible, svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[aria-pressed="true"], .btn.on { background: var(--wash); font-weight: 600; }
input, select { background: var(--surface); border: 1px solid var(--ring); border-radius: 8px; padding: 7px 10px; }
label { display: block; font-size: 13px; color: var(--ink-2); margin: 10px 0 4px; }
.field input { width: 100%; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* header + filters */
.top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.top h1 { font-size: 20px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.seg { display: inline-flex; border: 1px solid var(--ring); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg .btn { border: 0; border-radius: 0; }
.seg .btn + .btn { border-left: 1px solid var(--ring); }
.spacer { flex: 1; }
.custom-range { display: none; gap: 6px; align-items: center; }
.custom-range.on { display: inline-flex; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 600; line-height: 1.2; margin-top: 2px; }
.tile .delta { font-size: 12px; margin-top: 2px; min-height: 16px; color: var(--ink-2); }
.delta .good { color: var(--good); }
.delta .bad { color: var(--bad); }

/* chart */
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); }
.legend .key { display: inline-block; width: 16px; height: 0; border-top: 2px solid; vertical-align: middle; margin-right: 6px; border-radius: 2px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-muted); font: 11px var(--font); }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .ring { stroke: var(--surface); stroke-width: 2; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--ring); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); min-width: 150px; z-index: 5; display: none; }
.tip.on { display: block; }
.tip .when { color: var(--ink-2); margin-bottom: 4px; }
.tip .row { display: flex; align-items: center; gap: 6px; }
.tip .row b { font-size: 13px; margin-left: auto; padding-left: 12px; }
.tip .key { display: inline-block; width: 12px; border-top: 2px solid; }
main.loading { opacity: 0.55; transition: opacity 0.15s; }

/* sections */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin: 20px 0 12px; }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--ink-2); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card h2 { font-size: 15px; margin-bottom: 10px; }
.card.wide { grid-column: 1 / -1; }
.empty { color: var(--ink-muted); padding: 8px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: right; color: var(--ink-2); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--grid); }
td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: right; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th, td { white-space: nowrap; }
td.path { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.table-scroll { overflow-x: auto; }

.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 38%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 10px; background: transparent; }
.bar span { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row:hover .bar span { filter: brightness(1.12); }
.bar-row .val { font-variant-numeric: tabular-nums; color: var(--ink); }

/* login + dialogs */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: 100%; max-width: 380px; }
.auth h1 { font-size: 20px; margin-bottom: 4px; }
dialog { background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 12px; padding: 20px; width: min(520px, 94vw); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { font-size: 17px; margin-bottom: 8px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; word-break: break-all; }
.codebox { background: var(--wash); border-radius: 8px; padding: 10px; margin: 8px 0; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--ring);
  border-radius: 8px; min-width: 200px; padding: 4px; z-index: 10; display: none; }
.menu-list.on { display: block; }
.menu-list button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: var(--wash); }
.foot { margin-top: 20px; color: var(--ink-muted); font-size: 12px; }

@media (max-width: 560px) {
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-row .bar { grid-column: 1 / -1; order: 3; }
  td.path { max-width: 150px; }
  .seg { flex-wrap: wrap; border: 0; background: transparent; gap: 4px; overflow: visible; }
  .seg .btn, .seg .btn + .btn { border: 1px solid var(--ring); border-radius: 8px; }
  .filters select { flex: 1 1 100%; }
}

/* two-factor QR code: always on a white card so scanners keep their contrast in the dark theme */
.qr-card { width: fit-content; margin: 12px auto; padding: 10px; background: #fff; border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(23, 50, 74, 0.14); }
.qr-card img { display: block; width: 232px; height: 232px; max-width: 100%; }

/* site identity and management */
.brand { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.site-switch { display: grid; gap: 2px; }
.site-switch select { font-weight: 600; max-width: 280px; }
.context { margin: 0 0 12px; font-size: 14px; }
.btn.danger { color: #fff; background: #b3261e; border-color: transparent; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.deleter { margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--grid); }
.deleter input { width: 100%; margin: 6px 0 8px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; margin-top: 12px; }
textarea { width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--ring); border-radius: 8px; padding: 7px 10px; font: inherit; }
dialog select, dialog input:not([type=checkbox]) { width: 100%; }
