/* Admin dashboard. Colours are tokens; dark mode is selected values from the same ramps, not a flip. Chart hues were
   checked with the dataviz validator (CVD and contrast) on these surfaces. */
:root {
  color-scheme: light;
  --page: #f2f7fa;
  --surface: #ffffff;
  --surface-2: #eef4f8;
  --line: #d9e3ea;
  --line-strong: #b7c6d1;
  --text: #15222c;
  --text-2: #4a5b68;
  --text-3: #6b7c89;
  --accent: #1f7a4d;
  --accent-soft: #e0f3e8;
  --on-accent: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #1a7f37;
  --good-soft: #e3f4e7;
  --warn: #8a5a00;
  --warn-soft: #fbf0d4;
  --bad: #c0352f;
  --bad-soft: #fbe6e4;
  --info: #1f62b3;
  --info-soft: #e2eefb;
  --shadow: 0 1px 2px rgb(21 34 44 / 8%), 0 8px 28px rgb(21 34 44 / 7%);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #11161c;
    --surface: #1a2029;
    --surface-2: #232b35;
    --line: #2f3945;
    --line-strong: #46535f;
    --text: #edf2f6;
    --text-2: #b5c1cb;
    --text-3: #91a0ac;
    --accent: #47c483;
    --accent-soft: #173a29;
    --on-accent: #0b1a12;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good: #5ccf7e;
    --good-soft: #17331f;
    --warn: #e9b949;
    --warn-soft: #3a2f12;
    --bad: #f0827c;
    --bad-soft: #3c1b19;
    --info: #79b2f2;
    --info-soft: #17293d;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 28px rgb(0 0 0 / 30%);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--text-2); }
:focus-visible { outline: 2px solid var(--info); outline-offset: 2px; }

/* Shell */
.shell { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: 4px; padding: 16px 12px;
  background: var(--surface); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 650; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.brand small { display: block; font-weight: 400; color: var(--text-3); font-size: 11px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; padding: 6px 10px;
  border-radius: 8px; color: var(--text-2); text-decoration: none;
}
.nav a:hover { background: var(--surface-2); }
.nav a.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav .count { min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); font-size: 12px; font-weight: 650; text-align: center; }
.side-foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--line); color: var(--text-3); font-size: 12px; display: grid; gap: 8px; }
.main { padding: 18px 24px 40px; min-width: 0; }
.top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.top p { margin: 2px 0 0; color: var(--text-3); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; flex-wrap: wrap; width: fit-content; max-width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { min-height: 32px; padding: 4px 11px; border: 0; background: none; cursor: pointer; color: var(--text-2); white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); cursor: pointer; }
.banner { margin-bottom: 14px; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }

/* Blocks */
.grid { display: grid; gap: 12px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; }
.card > h2 { margin-bottom: 2px; }
.card > .sub { margin: 0 0 10px; color: var(--text-3); font-size: 12px; }
.stack { display: grid; gap: 12px; }
.tile .label { color: var(--text-2); font-size: 12.5px; }
.tile .value { font-size: 24px; font-weight: 650; margin: 2px 0; letter-spacing: -0.01em; }
.tile .note { color: var(--text-3); font-size: 12px; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.section-title { margin: 20px 0 8px; font-size: 13px; color: var(--text-2); font-weight: 650; text-transform: none; }
.insight { display: flex; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px; background: var(--info-soft); color: var(--text); font-size: 13px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-3); background: var(--surface); position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 24px; text-align: center; color: var(--text-3); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 10px; color: var(--text-3); font-size: 12.5px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
input.wide { flex: 1 1 420px; max-width: 640px; }
.toolbar input[type="search"] { flex: 1 1 180px; min-width: 0; max-width: 340px; }
.toolbar select.active { border-color: var(--accent); background: var(--accent-soft); }
.toolbar .btn[hidden] { display: none; }
.count-note { color: var(--text-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 140px; }
.bar-cell .bar { height: 8px; border-radius: 4px; background: var(--series-1); }
.bar-cell span { font-variant-numeric: tabular-nums; color: var(--text-2); }

/* Controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 34px; padding: 5px 12px;
  border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); cursor: pointer; font-weight: 550;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: var(--surface); }
.btn.primary.armed { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.small { min-height: 28px; padding: 2px 9px; font-size: 12.5px; }
input[type="text"], input[type="search"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  min-height: 34px; padding: 5px 9px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); max-width: 100%;
}
textarea { width: 100%; min-height: 60px; resize: vertical; }
.field { display: grid; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--text-2); }
.form { display: grid; gap: 10px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.error { padding: 8px 10px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: 13px; }
.ok { padding: 8px 10px; border-radius: 8px; background: var(--good-soft); color: var(--good); font-size: 13px; }

/* Status: always a word with its colour */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgb(10 18 26 / 40%); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); z-index: 21; overflow-y: auto;
  background: var(--surface); box-shadow: var(--shadow); padding: 16px 18px 40px;
}
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.drawer-head p { margin: 2px 0 0; color: var(--text-3); }
.hero { font-size: 34px; font-weight: 650; letter-spacing: -0.015em; margin: 4px 0; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.kv div { background: var(--surface-2); padding: 8px 10px; border-radius: 8px; min-width: 0; }
.kv b { display: block; font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }
.kv span { color: var(--text-3); font-size: 12px; }
.block { margin-top: 16px; }
.block > h3 { margin-bottom: 6px; }
.flag-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.flag-list li { display: grid; gap: 1px; padding: 7px 10px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.flag-list li span { color: var(--text-2); font-size: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.timeline li { display: grid; gap: 1px; padding-left: 12px; border-left: 2px solid var(--line-strong); }
.timeline small { color: var(--text-3); }
.secret { padding: 10px 12px; border: 1px dashed var(--warn); border-radius: 8px; background: var(--warn-soft); overflow-wrap: anywhere; display: grid; gap: 4px; }
.secret code { font-size: 14px; font-weight: 600; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(400px, 100%); padding: 22px; box-shadow: var(--shadow); }
.login .brand { padding: 0 0 14px; }
.login img.qr { display: block; width: 180px; height: 180px; margin: 6px auto; background: #fff; border-radius: 8px; padding: 6px; }

/* Charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .end-text { font-size: 11.5px; fill: var(--text-2); font-weight: 600; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .cross { stroke: var(--line-strong); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; }
.series-1 { stroke: var(--series-1); }
.series-2 { stroke: var(--series-2); }
.series-3 { stroke: var(--series-3); }
.fill-1 { fill: var(--series-1); }
.fill-2 { fill: var(--series-2); }
.fill-3 { fill: var(--series-3); }
.tip {
  position: absolute; z-index: 5; pointer-events: none; padding: 6px 9px; border-radius: 8px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 12px;
}
.tip b { display: block; font-weight: 650; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.bg-1 { background: var(--series-1); }
.bg-2 { background: var(--series-2); }
.bg-3 { background: var(--series-3); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 6px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
details.tableview { margin-top: 8px; font-size: 12.5px; }
details.tableview summary { cursor: pointer; color: var(--text-3); }
details.tableview .table-wrap { max-height: 240px; overflow-y: auto; }

@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .brand { padding-bottom: 6px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { flex: 0 0 auto; }
  .side-foot { flex-direction: row; display: flex; align-items: center; justify-content: space-between; margin-top: 6px; padding-top: 6px; }
  .main { padding: 14px 16px 32px; }
  .two { grid-template-columns: minmax(0, 1fr); }
}
