:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f0efec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --hover: rgba(11, 11, 11, 0.04);
  --series-1: #2a78d6;
  --series-1-wash: rgba(42, 120, 214, 0.12);
  --series-1-area: rgba(42, 120, 214, 0.1);
  --series-2: #eb6834;
  --seq-0: #f0efec;
  --seq-1: #cde2fb;
  --seq-2: #86b6ef;
  --seq-3: #3987e5;
  --seq-4: #1c5cab;
  --seq-5: #0d366b;
  --good: #006300;
  --bad: #d03b3b;
  --live: #0ca30c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #262624;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --hover: rgba(255, 255, 255, 0.05);
    --series-1: #3987e5;
    --series-1-wash: rgba(57, 135, 229, 0.18);
    --series-1-area: rgba(57, 135, 229, 0.14);
    --series-2: #d95926;
    --seq-0: #262624;
    --seq-1: #104281;
    --seq-2: #1c5cab;
    --seq-3: #2a78d6;
    --seq-4: #6da7ec;
    --seq-5: #b7d3f6;
    --good: #0ca30c;
    --bad: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #262624;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --hover: rgba(255, 255, 255, 0.05);
  --series-1: #3987e5;
  --series-1-wash: rgba(57, 135, 229, 0.18);
  --series-1-area: rgba(57, 135, 229, 0.14);
  --series-2: #d95926;
  --seq-0: #262624;
  --seq-1: #104281;
  --seq-2: #1c5cab;
  --seq-3: #2a78d6;
  --seq-4: #6da7ec;
  --seq-5: #b7d3f6;
  --good: #0ca30c;
  --bad: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--bad); min-height: 1.4em; margin: 0; }

/* Sign-in dialog over the public dashboard */
.gate { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; }
.gate-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); }
.gate-card { position: relative; }
.gate-card button.link { background: none; color: var(--text-secondary); font-weight: 500; padding: 4px; }
.gate-card button.link:hover { color: var(--text-primary); }
.gate-card {
  width: min(380px, 100%);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
}
.gate-card h1 { margin: 0; font-size: 20px; }
.gate-card p { margin: 0; }
.gate-card pre { background: var(--surface-2); padding: 12px; border-radius: 8px; margin: 0; white-space: pre-wrap; }
.gate-card input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
}
.gate-card button, .ghost {
  padding: 9px 14px;
  border-radius: 8px;
  border: 0;
  background: var(--series-1);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); font-weight: 500; padding: 6px 12px; }
.ghost:hover { background: var(--hover); }
.ghost.primary { background: var(--series-1); border-color: var(--series-1); color: #fff; font-weight: 600; }
.ghost.primary:hover { background: var(--series-1); filter: brightness(1.08); }
.notice { margin: 10px max(16px, calc((100vw - 1280px) / 2)) 0; padding: 8px 12px; border-radius: 8px; background: var(--series-1-wash); font-size: 13px; }
.hidden-note { margin: 8px 8px 0; }

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px max(16px, calc((100vw - 1280px) / 2));
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; margin-right: 6px; }
.select select {
  appearance: none;
  padding: 7px 30px 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23898781' stroke-width='1.5'/%3E%3C/svg%3E") no-repeat right 11px center;
  cursor: pointer;
  font-weight: 500;
}
.live-pill { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); font-size: 13px; }
.live-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--live); box-shadow: 0 0 0 0 var(--live); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0.5); } 70% { box-shadow: 0 0 0 7px rgba(12, 163, 12, 0); } 100% { box-shadow: 0 0 0 0 rgba(12, 163, 12, 0); } }
@media (prefers-reduced-motion: reduce) { .live-pill .dot { animation: none; } }
.spacer { flex: 1; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px max(16px, calc((100vw - 1280px) / 2)) 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: var(--series-1-wash);
  border: 1px solid var(--border);
  font-size: 13px;
  max-width: 100%;
}
.chip b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--text-secondary); padding: 0 4px; font-size: 15px; line-height: 1; }
.chip.clear { background: none; cursor: pointer; padding-right: 10px; color: var(--text-secondary); }

main { max-width: 1280px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi {
  text-align: left;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  display: grid;
  gap: 2px;
  box-shadow: var(--shadow);
  position: relative;
}
.kpi:hover { background: color-mix(in srgb, var(--surface-1) 92%, var(--series-1)); }
.kpi[aria-pressed="true"] { border-color: var(--series-1); box-shadow: inset 0 0 0 1px var(--series-1); }
.kpi .label { color: var(--text-secondary); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 650; letter-spacing: -0.01em; }
.kpi .delta { font-size: 12px; color: var(--text-muted); display: flex; gap: 4px; align-items: center; }
.kpi .delta.good { color: var(--good); }
.kpi .delta.bad { color: var(--bad); }
.kpi svg.spark { width: 100%; height: 26px; display: block; margin-top: 4px; }

/* Cards */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 16px;
  min-width: 0;
  box-shadow: var(--shadow);
}
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.wide { grid-column: 1 / -1; }
@media (max-width: 860px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 14px; height: 0; border-top: 2px solid var(--series-1); }
.key-prev { border-top: 2px dashed var(--text-muted); }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; }
.tabs button {
  border: 0;
  background: none;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 550;
}
.tabs button:hover { background: var(--hover); color: var(--text-secondary); }
.tabs button[aria-selected="true"] { color: var(--text-primary); background: var(--surface-2); }

/* Bar lists */
.list-head, .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(var(--cols, 2), minmax(52px, auto));
  gap: 12px;
  align-items: center;
}
.list-head { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 0 8px 6px; }
.list-head span:not(:first-child), .row .num { text-align: right; font-variant-numeric: tabular-nums; }
.row {
  position: relative;
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  min-height: 30px;
}
.row:hover { background: var(--hover); }
.row .bar {
  position: absolute;
  inset: 2px auto 2px 0;
  background: var(--series-1-wash);
  border-radius: 4px;
  pointer-events: none;
}
.row .name { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; }
.row .name span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .name .sub { color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.row .num { position: relative; color: var(--text-secondary); }
.row .num.strong { color: var(--text-primary); font-weight: 600; }
.row a.out { position: relative; color: var(--text-muted); text-decoration: none; flex-shrink: 0; padding: 0 2px; }
.row a.out:hover { color: var(--series-1); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.on { background: var(--live); }
.status-dot.stale { background: #fab219; }
.status-dot.off { background: var(--axis); }
.more { margin-top: 6px; border: 0; background: none; color: var(--series-1); cursor: pointer; font-size: 12px; font-weight: 600; padding: 4px 8px; }
.empty { color: var(--text-muted); padding: 24px 8px; text-align: center; }

/* Charts */
.chart { position: relative; height: 280px; }
.chart svg, .map svg, .heatmap svg { display: block; width: 100%; height: 100%; overflow: visible; }
.axis text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.axis line, .axis path { stroke: none; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.line-current { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.area-current { fill: var(--series-1-area); }
.line-prev { fill: none; stroke: var(--text-muted); stroke-width: 1.5; stroke-dasharray: 4 4; }
.crosshair { stroke: var(--axis); stroke-width: 1; }
.marker { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.spark-line { fill: none; stroke: var(--series-1); stroke-width: 1.5; }
.spark-area { fill: var(--series-1-area); }

.loc-body { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 860px) { .loc-body { grid-template-columns: minmax(0, 1fr); } }
.map { position: relative; aspect-ratio: 1.9; }
.country { stroke: var(--surface-1); stroke-width: 0.6; cursor: pointer; }
.country:hover { stroke: var(--text-primary); stroke-width: 1; }
.city-dot { fill: var(--series-2); fill-opacity: 0.85; stroke: var(--surface-1); stroke-width: 1.5; cursor: pointer; }
.city-dot:hover { fill-opacity: 1; stroke: var(--text-primary); }
.map-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); margin-top: 6px; flex-wrap: wrap; }
.map-legend i { display: inline-block; width: 18px; height: 8px; border-radius: 2px; }
.map-legend .city-key { width: 9px; height: 9px; border-radius: 50%; background: var(--series-2); margin-left: 10px; }

.heatmap { position: relative; }
.cell { stroke: var(--surface-1); stroke-width: 2; rx: 3; }
.cell:hover { stroke: var(--text-primary); stroke-width: 1.5; }

.live-pages { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.live-pages .chip { background: var(--surface-2); }
.feed { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow-y: auto; }
.feed li { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 10px; padding: 7px 4px; border-top: 1px solid var(--grid); font-size: 13px; }
.feed li:first-child { border-top: 0; }
.feed .when { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 12px; padding-top: 1px; }
.feed .what { min-width: 0; }
.feed .what .p { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .what .meta { color: var(--text-secondary); font-size: 12px; }
.badge { display: inline-block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 1px 5px; border-radius: 4px; background: var(--series-1-wash); color: var(--text-secondary); margin-left: 4px; vertical-align: 1px; }

.tooltip {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  min-width: 120px;
  max-width: 280px;
}
.tooltip .tt-title { color: var(--text-secondary); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; }
.tooltip .tt-row b { font-size: 14px; font-variant-numeric: tabular-nums; }
.tooltip .tt-row span { color: var(--text-secondary); }
.tooltip .tt-key { width: 12px; border-top: 2px solid var(--series-1); }
.tooltip .tt-key.prev { border-top: 2px dashed var(--text-muted); }

.badge.you { background: var(--series-2); color: #0b0b0b; }
.foot { line-height: 1.6; padding: 4px 2px 24px; }
.foot code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

@media (max-width: 600px) {
  .top { gap: 8px; }
  .brand span, #updated { display: none; }
  .select select { padding-right: 26px; max-width: 46vw; }
  .chart { height: 220px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 20px; }
  .kpi:last-child { grid-column: span 2; }
}
