:root {
  color-scheme: light;
  --bg: #f4f5f2;
  --surface-1: #ffffff;
  --surface-2: #f8f8f6;
  --line: #e2e3de;
  --grid: #ececea;
  --text-primary: #191919;
  --text-secondary: #666666;
  --accent: #257de0;
  --accent-ink: #1757ac;
  --series-1: #257de0;
  --series-2: #f47230;
  --series-3: #00b894;
  --series-4: #f2a600;
  --dry: #ec4647;
  --neutral: #c4c4c0;
  --seq: #cce3fd, #9dc8f7, #6aabf1, #338ced, #2370cd, #1757ac, #0e3d7e;
  --radius: 10px;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  font-family: "IBM Plex Sans", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111211;
    --surface-1: #191919;
    --surface-2: #202120;
    --line: #2e2f2d;
    --grid: #2a2a2a;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --accent: #338ced;
    --accent-ink: #84b9f3;
    --series-1: #338ced;
    --series-2: #e76624;
    --series-3: #00a888;
    --series-4: #d28e05;
    --dry: #eb6263;
    --neutral: #4a4a48;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111211;
  --surface-1: #191919;
  --surface-2: #202120;
  --line: #2e2f2d;
  --grid: #2a2a2a;
  --text-primary: #efefef;
  --text-secondary: #9c9c9c;
  --accent: #338ced;
  --accent-ink: #84b9f3;
  --series-1: #338ced;
  --series-2: #e76624;
  --series-3: #00a888;
  --series-4: #d28e05;
  --dry: #eb6263;
  --neutral: #4a4a48;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary); font-size: 14px; line-height: 1.45; }
a { color: var(--accent-ink); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; margin-top: 18px; }
.note, .muted { color: var(--text-secondary); font-size: 12px; margin: 2px 0 6px; }
code { font-family: var(--mono); font-size: 12px; }

.top {
  display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  background: var(--surface-1); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand strong { display: block; font-size: 16px; }
.brand span { font-size: 12px; color: var(--text-secondary); }
.query { display: flex; gap: 12px; align-items: end; }
label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.inline label { flex-direction: row; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-size: 13px; }
select, input, button, .btn {
  font: inherit; font-size: 13px; color: var(--text-primary); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; min-height: 32px;
}
input[type=number] { width: 86px; font-family: var(--mono); }
button, .btn { cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; }
button[type=submit] { background: var(--accent); color: #fff; border-color: transparent; font-weight: 500; }
button:disabled { opacity: .5; cursor: progress; }
.ghost { background: transparent; font-size: 18px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

main { padding: 20px 24px; max-width: 1600px; margin: 0 auto; }
.empty { max-width: 680px; margin: 10vh auto; }
.empty h1 { font-size: 28px; margin-bottom: 12px; }
.loading { text-align: center; margin: 15vh auto; color: var(--text-secondary); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-family: var(--mono); font-size: 24px; font-weight: 500; }
.kpi .v small { font-size: 13px; color: var(--text-secondary); margin-left: 2px; }
.kpi .l { font-size: 12px; color: var(--text-secondary); }

.grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .grid { grid-template-columns: 1fr; } .top { flex-wrap: wrap; } }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.map-card { display: flex; flex-direction: column; }
#map { flex: 1; min-height: 520px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
.side { max-height: calc(100vh - 220px); min-height: 640px; overflow-y: auto; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; min-height: 28px; font-size: 12px; }
.seg button.on { background: var(--accent); color: #fff; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { font-size: 12px; padding: 3px 10px; min-height: 26px; border-radius: 999px; }
.chip[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.chip b { font-family: var(--mono); font-weight: 500; margin-left: 4px; color: var(--text-secondary); }

.legend-bins { display: flex; align-items: center; gap: 0; margin-top: 8px; font-size: 11px; color: var(--text-secondary); flex-wrap: wrap; }
.legend-bins .sw { display: inline-flex; flex-direction: column; align-items: flex-start; }
.legend-bins i { display: block; width: 52px; height: 10px; margin-right: 2px; }
.legend-bins .sw:first-child i { border-radius: 3px 0 0 3px; }
.legend-bins .sw:last-child i { border-radius: 0 3px 3px 0; }
.legend-bins span { font-family: var(--mono); padding-top: 2px; }
.legend-bins .title { margin-right: 10px; align-self: center; }
.legend-bins .nodata { margin-left: 14px; display: inline-flex; align-items: center; gap: 4px; }
.legend-bins .nodata i { width: 10px; border-radius: 50%; background: transparent; border: 1.5px solid var(--text-secondary); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px -4px 10px; position: sticky; top: -14px; background: var(--surface-1); z-index: 2; padding-top: 4px; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--text-secondary); }
.tabs button.on { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 500; }

.chart { width: 100%; height: 240px; }
.chart.short { height: 170px; }
.chart.tall { height: 460px; }
.placeholder { color: var(--text-secondary); padding: 60px 0; text-align: center; }

.station-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.station-head h3 { margin: 0; font-size: 17px; }
.indices { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; margin: 12px 0 0; }
.indices div { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }
.indices dt { font-size: 11px; color: var(--text-secondary); }
.indices dd { margin: 0; font-family: var(--mono); font-size: 16px; }
.history { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 4px; }
.inline { display: flex; gap: 10px; align-items: center; margin: 8px 0 2px; flex-wrap: wrap; }

.table-tools { display: flex; gap: 8px; margin-bottom: 8px; }
.table-tools input { flex: 1; }
.table-wrap { overflow: auto; max-height: calc(100vh - 330px); }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-1); cursor: pointer; font-weight: 500; color: var(--text-secondary); user-select: none; }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
.num { text-align: right; font-family: var(--mono); }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.sel { background: var(--surface-2); }

.foot { color: var(--text-secondary); font-size: 12px; padding: 16px 24px 28px; max-width: 1600px; margin: 0 auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-1); padding: 10px 16px; border-radius: 8px; z-index: 2000; }

.leaflet-container { font-family: inherit; }
.leaflet-tooltip { font-family: inherit; font-size: 12px; }
:root[data-theme="dark"] .leaflet-tile-pane { filter: none; }

/* ---------------- navegação entre visões ---------------- */
.views { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 3px; }
.views a { color: var(--text-secondary); text-decoration: none; padding: 5px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; }
.views a:hover { color: var(--text-primary); }
.site { display: flex; gap: 14px; font-size: 13px; }
.site a { color: var(--text-secondary); text-decoration: none; font-weight: 500; }
.site a:hover { color: var(--text-primary); }
.views a.on { background: var(--surface-1); color: var(--text-primary); box-shadow: 0 0 0 1px var(--line); }

.page-head { margin: 4px 0 14px; }
.page-head h1 { font-size: 22px; }

.filters { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; margin-bottom: 8px; }
.filters .grow { flex: 1; min-width: 220px; }
.filters .grow input { width: 100%; }
.filters input[type=number] { width: 96px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.lbl { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
label.check { flex-direction: row; align-items: center; gap: 6px; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text-primary); min-height: 32px; }
label.check input { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); }

.ychip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 4px 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface-2); font-family: var(--mono); font-size: 13px; min-height: 30px; }
.ychip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.ychip button { border: 0; background: transparent; min-height: 22px; padding: 0 6px; font-size: 14px; color: var(--text-secondary); border-radius: 999px; }
.ychip button:hover { background: var(--line); color: var(--text-primary); }

.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1100px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.grid2 > .card, .grid3 > .card { margin: 0; }
#view-comparar > .card, #view-destaques > .card { margin-bottom: 16px; }

.table-wrap.plain { max-height: none; }
table.rank td, table.rank th { padding: 6px 6px; }
table.rank th { position: static; cursor: default; }
table.rank .pos { color: var(--text-secondary); font-family: var(--mono); width: 26px; }
table.rank .val { font-family: var(--mono); font-weight: 500; text-align: right; }
table.rank .where small { display: block; color: var(--text-secondary); font-size: 11px; }
table.rank tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.badge { display: inline-block; font-size: 10.5px; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--text-secondary); margin-left: 4px; white-space: nowrap; }
.badge.warn::before { content: "⚠ "; }

.kpi .sub { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }
.kpi.hero .v { font-size: 28px; }

#cmpTable th { position: static; cursor: default; }
#cmpTable td.year { font-family: var(--mono); font-weight: 500; }
#cmpTable td.year i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 8px; }
.delta-up { color: var(--accent-ink); }
.delta-down { color: var(--dry); }

.qc-note summary { cursor: pointer; font-weight: 500; }
.qc-note ul { margin: 10px 0 0; padding-left: 18px; color: var(--text-secondary); font-size: 13px; }
.qc-note li { margin-bottom: 4px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

[hidden] { display: none !important; }
table.rank td.where { white-space: normal; }
table.rank td.num { font-size: 12px; }

.notice { grid-column: 1 / -1; background: var(--surface-1); border: 1px solid var(--line); border-left: 3px solid var(--series-4); border-radius: var(--radius); padding: 10px 14px; font-size: 13px; color: var(--text-secondary); }
.notice b { color: var(--text-primary); }

/* previsão */
#fcMap { flex: 1; min-height: 560px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
.filters .grow { flex: 1; }
#fcSkill td, #fcSkill th, #fcNational td, #fcNational th { position: static; cursor: default; }
.skill-pos { color: var(--accent-ink); font-weight: 500; }
.skill-neg { color: var(--dry); }

/* início, destaques e bacias */
a.brand { color: inherit; text-decoration: none; border-radius: 8px; }
a.brand:hover strong { color: var(--accent-ink); }
#hlFcMap, #bsMap { flex: 1; min-height: 460px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); }
#bsMap { min-height: 600px; }
h3.big { font-size: 17px; margin-top: 0; }
#bsResTable tr, #bsDams tr { cursor: default; }
#bsResTable tbody tr { cursor: pointer; }
#bsResTable th, #bsDams th { position: static; }
.leaflet-interactive:focus { outline: none; }
