:root {
  color-scheme: light;
  --surface-0: #f4f4f2;
  --surface-1: #fcfcfb;
  --border: #e3e2de;
  --grid: #ebeae6;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #77766f;
  --series-1: #2a78d6; /* major / gross */
  --series-2: #eb6834; /* long-tail / net */
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --zero: #9a9992;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --border: #2e2e2b;
    --grid: #262624;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --series-1: #3987e5;
    --series-2: #d95926;
    --accent: #3987e5;
    --zero: #6d6c66;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #111110;
  --surface-1: #1a1a19;
  --border: #2e2e2b;
  --grid: #262624;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8e86;
  --series-1: #3987e5;
  --series-2: #d95926;
  --accent: #3987e5;
  --zero: #6d6c66;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 8px; font-weight: 600; }
.sub, .note { color: var(--text-secondary); margin: 2px 0 10px; font-size: 13px; }
a { color: var(--accent); }

.top {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 16px 20px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.top .theme { order: 3; font-size: 12px; padding: 4px 10px; }
.top .brand { flex: 1 1 auto; }
.range { color: var(--text-secondary); font-size: 13px; }
select, button {
  font: inherit; color: var(--text-primary); background: var(--surface-1);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; cursor: pointer;
}
button:hover { border-color: var(--text-muted); }
button.danger { border-color: var(--critical); color: var(--critical); font-weight: 600; }
.pill {
  display: inline-block; padding: 4px 10px; border-radius: 999px; font-weight: 600; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface-0);
}

.banner { margin: 12px 20px 0; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--critical); background: var(--surface-1); }
.banner.warn { border-color: var(--warning); }

main {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; padding: 16px 20px 40px;
  max-width: 1400px; margin: 0 auto;
}
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.wide { grid-column: 1 / -1; }
.tiles { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.tile .label { color: var(--text-secondary); font-size: 12px; }
.tile .value { font-size: 24px; font-weight: 600; margin-top: 2px; }
.tile .hint { color: var(--text-muted); font-size: 12px; }

.chart { width: 100%; height: 220px; }
.chart.tall { height: 320px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.axis text, .tick text { fill: var(--text-muted); font-size: 11px; }
.gridline { stroke: var(--grid); stroke-width: 1; }
.zeroline { stroke: var(--zero); stroke-width: 1; }
.empty { fill: var(--text-muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; min-height: 18px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.sw.dia { transform: rotate(45deg); border-radius: 1px; width: 8px; height: 8px; }

.tip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 320px;
  background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}
.tip b { font-weight: 600; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--text-secondary); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.pos { color: var(--text-primary); }
.neg { color: var(--text-secondary); }
.muted { color: var(--text-muted); }
.route { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; }
.status .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status.good .dot { background: var(--good); }
.status.warning .dot { background: var(--warning); }
.status.critical .dot { background: var(--critical); }
.status.none .dot { background: var(--zero); }
.why { color: var(--text-secondary); font-size: 12px; margin-top: 2px; }

.exports { margin: 0 0 8px; }

.setup { max-width: 720px; margin: 16px auto; padding: 0 20px; }
.form { display: grid; gap: 10px; margin: 14px 0 6px; padding-top: 12px; border-top: 1px solid var(--grid); }
.form h3 { font-size: 14px; margin: 0; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--text-secondary); }
.form label.check { display: flex; align-items: center; gap: 8px; }
.form input[type="password"], .form input[type="text"], .form select {
  font: inherit; color: var(--text-primary); background: var(--surface-0);
  border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%;
}
.form .actions { display: flex; gap: 8px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button:disabled { opacity: 0.6; cursor: default; }
.banner.inline { margin: 8px 0; }
code { font-size: 12px; }
details { margin-top: 6px; }
summary { cursor: pointer; color: var(--text-secondary); }
.log {
  max-height: 360px; overflow: auto; background: var(--surface-0); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px; font-size: 11px; white-space: pre-wrap; word-break: break-all;
}

@media (max-width: 800px) {
  main { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 32px; }
  .top { padding: 12px 16px; }
  .banner { margin: 12px 16px 0; }
}

/* ------------------------------------------------------------ plain summary */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.simple { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.live { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); min-height: 20px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--zero); flex: none; }
.live-dot.on { background: var(--good); animation: pulse 2s ease-out 1; }
.live-dot.off { background: var(--warning); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(12 163 12 / 0.6); } 100% { box-shadow: 0 0 0 10px rgb(12 163 12 / 0); } }
@media (prefers-reduced-motion: reduce) { .live-dot.on { animation: none; } }
.hero { margin: 14px 0 6px; }
.hero-label { color: var(--text-secondary); font-size: 15px; }
.hero-value { font-size: 52px; font-weight: 700; line-height: 1.1; margin: 4px 0; letter-spacing: -0.5px; }
.hero-sub { color: var(--text-muted); font-size: 13px; }
.verdict-line { font-size: 16px; margin: 12px 0 14px; max-width: 70ch; }
.verdict-line .status { margin-right: 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cards .tile .value { font-size: 20px; }
h3.minor { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 6px 0 6px; }
.feed { list-style: none; margin: 0 0 8px; padding: 0; }
.feed li { padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 14px; display: flex; gap: 10px; align-items: baseline; }
.feed li:last-child { border-bottom: none; }
.feed .when { color: var(--text-muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 44px; }
.feed .what { flex: 1; min-width: 0; }
.feed .amt { white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
.feed .why { display: block; }

/* ------------------------------------------------------------ expandable sections */
details.section { background: var(--surface-1); border: 1px solid var(--border); border-radius: 10px; padding: 0 16px; }
details.section > summary {
  list-style: none; cursor: pointer; padding: 14px 0; display: flex; align-items: center; justify-content: space-between;
  -webkit-tap-highlight-color: transparent; min-height: 44px;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary h2 { margin: 0; font-size: 15px; }
details.section > summary::after { content: "›"; font-size: 22px; color: var(--text-muted); transform: rotate(90deg); transition: transform 0.15s; }
details.section[open] > summary::after { transform: rotate(-90deg); }
details.section[open] { padding-bottom: 14px; }
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.chart-card { min-width: 0; }
.chart-card.wide { grid-column: 1 / -1; }

/* ------------------------------------------------------------ sign-in page */
.login { max-width: 420px; margin: 12vh auto 0; padding: 0 16px; }
.login h1 { margin-bottom: 6px; }

/* ------------------------------------------------------------ phones (iOS Safari included) */
body { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); -webkit-text-size-adjust: 100%; }
/* 16px inputs stop iOS from zooming the page when a field is tapped. */
input, select, button, textarea { font-size: 16px; }
button { min-height: 38px; }
@media (max-width: 800px) {
  .top { flex-direction: column; align-items: stretch; }
  .top .brand { order: 1; }
  .top .theme { order: 2; align-self: flex-start; }
  .controls { order: 3; }
  .controls .range { flex: 1 1 auto; }
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .hero-value { font-size: 42px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .cards .tile { padding: 10px 12px; }
  .cards .tile .value { font-size: 18px; }
  .simple { padding: 16px; }
  details.section { padding: 0 12px; }
  .tile .value { font-size: 20px; }
}
