:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --line: #e4e2dc;
  --grid: #ecebe6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --series-1: #2a78d6;   /* casa / potência */
  --series-2: #eb6834;   /* público */
  --ref: #7a7974;
  --warn-bg: #fdf1dc; --warn-text: #7a4b00;
  --bad-bg: #fbe7e6;  --bad-text: #8e1f1e;
  --ok-bg: #e2f4ea;   --ok-text: #0c5a36;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f0f0e; --surface: #1a1a19; --line: #2c2c2a; --grid: #262624;
    --text: #fff; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --ref: #8f8e86;
    --warn-bg: #3a2b0c; --warn-text: #f5c56a; --bad-bg: #3b1716; --bad-text: #f3a3a2;
    --ok-bg: #0f2e20; --ok-text: #86d9ae;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f0e; --surface: #1a1a19; --line: #2c2c2a; --grid: #262624;
  --text: #fff; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --series-1: #3987e5; --series-2: #d95926; --ref: #8f8e86;
  --warn-bg: #3a2b0c; --warn-text: #f5c56a; --bad-bg: #3b1716; --bad-text: #f3a3a2;
  --ok-bg: #0f2e20; --ok-text: #86d9ae;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 4px 0 2px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 600; color: var(--text-2); }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 8px; align-items: center; font-weight: 650; color: var(--text); text-decoration: none; }
.brand svg { color: var(--accent); }
.live { font-size: 13px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.live.on { background: var(--ok-bg); color: var(--ok-text); border-color: transparent; }
.live.err { background: var(--bad-bg); color: var(--bad-text); border-color: transparent; }

main { max-width: 860px; margin: 0 auto; padding: 16px; outline: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--surface);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; text-align: center; padding: 14px 4px; color: var(--text-2); text-decoration: none; font-size: 14px; font-weight: 550; }
.tabs a.active { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

select, input, textarea, button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; min-height: 42px;
}
textarea { width: 100%; min-height: 70px; }
button { cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.danger { color: var(--bad-text); }
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid2 > div > input, .grid2 > div > select { width: 100%; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 560px) { .tiles { grid-template-columns: 1fr 1fr; } .tiles .tile:first-child { grid-column: 1 / -1; } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.tile .k { font-size: 13px; color: var(--text-2); }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tile .key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin: 0 0 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.box { height: 10px; width: 10px; border-radius: 3px; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--ref) 0 4px, transparent 4px 7px) !important; }

.chart { width: 100%; display: block; touch-action: pan-y; }
.chart text { fill: var(--text-3); font: 12px var(--font); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--line); }
.chart .hair { stroke: var(--text-3); stroke-width: 1; }

.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; line-height: 1.4;
  box-shadow: 0 6px 20px rgba(0,0,0,.12); min-width: 120px;
}
.tip b { font-size: 15px; font-variant-numeric: tabular-nums; }
.tip .l { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 2px; color: var(--text); text-decoration: none; }
.list .t { font-weight: 600; }
.list .d { font-size: 13px; color: var(--text-2); }
.list .r { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.list .rs { text-align: right; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--grid); color: var(--text-2); }
.pill.casa { background: color-mix(in srgb, var(--series-1) 16%, transparent); color: var(--text); }
.pill.publico { background: color-mix(in srgb, var(--series-2) 18%, transparent); color: var(--text); }
.banner { border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.bad { background: var(--bad-bg); color: var(--bad-text); }
.banner.ok { background: var(--ok-bg); color: var(--ok-text); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr 1fr; } }
.stats div { background: var(--bg); border-radius: 10px; padding: 10px; }
.stats .k { font-size: 12px; color: var(--text-2); }
.stats .v { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.seg { display: flex; height: 10px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--surface); margin: 8px 0 4px; }
.seg span { display: block; height: 100%; }
details summary { cursor: pointer; color: var(--text-2); font-size: 14px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.data th, table.data td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); }
table.data th:first-child, table.data td:first-child { text-align: left; }
.empty { text-align: center; padding: 30px 10px; color: var(--text-2); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
