/* Admin dashboard: summary first (KPI row), then trend, then breakdown tables. */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #18222d;
  --muted: #5a6877;
  --line: #dde3ea;
  --primary: #1565c0;
  --primary-ink: #ffffff;
  --danger: #c62828;
  --good-state: #2e7d32;
  --warn-state: #b26a00;
  /* rating series (validated for colour-blind separation) */
  --r-excellent: #0b8a72;
  --r-good: #d99a1e;
  --r-poor: #b8322a;
  --font: "Segoe UI", Roboto, "Noto Sans", "Noto Sans Myanmar", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f151b; --surface: #17202a; --ink: #e3e9ef; --muted: #98a6b4; --line: #2b3846;
    --primary: #5aa9e6; --primary-ink: #0b1520; --danger: #ef6b6b; --good-state: #66bb6a; --warn-state: #f0b04a;
    --r-excellent: #2ea58c; --r-good: #bb872b; --r-poor: #d94b6a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f151b; --surface: #17202a; --ink: #e3e9ef; --muted: #98a6b4; --line: #2b3846;
  --primary: #5aa9e6; --primary-ink: #0b1520; --danger: #ef6b6b; --good-state: #66bb6a; --warn-state: #f0b04a;
  --r-excellent: #2ea58c; --r-good: #bb872b; --r-poor: #d94b6a;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
[hidden] { display: none !important; }
h1, h2 { text-wrap: balance; }
h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); font-weight: 600; margin: 8px 0; }

/* Buttons and inputs */
.btn {
  border: 1px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
  border-radius: 6px;
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.link { border: 0; padding: 2px 4px; background: none; }
.btn.danger-link { border: 0; background: none; color: var(--danger); padding: 2px 4px; }
.btn:focus-visible, input:focus-visible, select:focus-visible, [role="tab"]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input, select {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 10px;
  min-width: 0;
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 8px; }
.login h1 { margin: 0; font-size: 22px; }
.login label { font-weight: 600; margin-top: 6px; }
.login .btn { margin-top: 12px; padding: 10px; }

/* Top bar */
.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.title strong { font-size: 16px; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs [role="tab"] {
  border: 0;
  background: none;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--primary); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }

/* Filters: one row above the charts */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.field.grow { flex: 1; }
.field.actions { flex-direction: row; gap: 8px; flex-wrap: wrap; }

.demo-bar {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  padding: 10px 14px; border: 1px dashed var(--warn-state); border-radius: 8px; color: var(--muted);
}
.demo-bar span { flex: 1; min-width: 220px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.pill.demo { color: var(--warn-state); }
.pill.on { color: var(--good-state); }
.pill.off { color: var(--warn-state); }
.pill.never, .pill.inactive { color: var(--muted); }

/* KPI row */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.k-label { color: var(--muted); font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.k-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.k-sub { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.sw.excellent { background: var(--r-excellent); }
.sw.good { background: var(--r-good); }
.sw.poor { background: var(--r-poor); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card p { margin: 0; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 13px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.chart-box { position: relative; height: 300px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
table.data td.n, table.data th.n { text-align: right; }
table.data tr.total td { font-weight: 700; border-top: 2px solid var(--line); }
.bar { display: inline-block; height: 8px; border-radius: 2px; background: var(--r-poor); vertical-align: middle; margin-left: 8px; }
code.key { font-size: 12.5px; background: var(--bg); padding: 2px 6px; border-radius: 4px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.inline-form .field { flex: 1; min-width: 180px; }
.inline-form .field.actions { flex: 0 0 auto; min-width: 0; }

/* Print = "Export PDF" */
@media print {
  :root { --bg: #fff; --surface: #fff; --ink: #000; --muted: #444; --line: #ccc; color-scheme: light; }
  .topbar, .filters .actions, .demo-bar, #panel-tablets { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .card, .kpi { break-inside: avoid; border-color: #ccc; }
  .filters input, .filters select { border: 0; padding: 0; }
  @page { size: A4 landscape; margin: 12mm; }
}
