/* Rio Negro — dashboard. Tokens da paleta de referência do skill dataviz. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --blue: #2a78d6;          /* série 1 / enchente */
  --red: #e34948;           /* vazante (par divergente azul↔vermelho) */
  --series-2: #eb6834;      /* laranja — 1º ano comparado */
  --series-3: #1baf7a;      /* água — 2º ano comparado */
  --series-4: #eda100;      /* amarelo — 3º ano comparado */
  --gray-series: #898781;   /* série de contexto */
  --blue-wash: rgba(42, 120, 214, 0.10);
  --hero-bg: #123c6b;
  --hero-ink: #f2f6fb;
  --wave-1: rgba(42, 120, 214, 0.35);
  --wave-2: rgba(42, 120, 214, 0.55);
  --wave-3: #f9f9f7;        /* onda da frente funde com a página */
  --focus: #0085f2;
}
/* tema claro é o padrão do site; escuro só via toggle (persistido) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --blue: #3987e5;
  --red: #e66767;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --blue-wash: rgba(57, 135, 229, 0.10);
  --hero-bg: #0e2947;
  --hero-ink: #eaf1fa;
  --wave-1: rgba(57, 135, 229, 0.30);
  --wave-2: rgba(57, 135, 229, 0.50);
  --wave-3: #0d0d0d;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--blue); }
.muted { color: var(--muted); }

/* ---------- hero com ondas + clima ---------- */
.hero { background: var(--hero-bg); color: var(--hero-ink); position: relative; overflow: hidden; }
.hero-inner {
  max-width: 1200px; margin: 0 auto; padding: 28px 24px 66px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 20px; flex-wrap: wrap;
}
.hero h1 { margin: 0; font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }
.hero-sub { margin: 6px 0 0; opacity: 0.82; font-size: 14.5px; }
.icon-btn {
  position: absolute; top: 14px; right: 16px; z-index: 3;
  background: rgba(255, 255, 255, 0.12); color: var(--hero-ink);
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 10px;
  width: 38px; height: 38px; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.2); }
:root:not([data-theme="dark"]) .icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }

/* clima na parte superior (dentro do hero) */
.hero-weather {
  background: rgba(255, 255, 255, 0.09); border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px; padding: 12px 16px; min-width: 300px;
  backdrop-filter: blur(4px);
}
.hero-weather .muted { color: rgba(255, 255, 255, 0.6); margin: 4px 0; }
.w-now { display: flex; align-items: center; gap: 12px; }
.w-icon { color: #9ec5f4; flex: none; display: grid; }
.w-temp { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; line-height: 1; }
.w-desc { opacity: 0.85; font-size: 13px; margin-top: 3px; }
.w-meta { display: flex; gap: 12px; flex-wrap: wrap; opacity: 0.85; font-size: 12.5px; margin: 8px 0 10px; }
.w-days { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; text-align: center; }
.w-day { padding: 4px 2px; border-radius: 10px; }
.w-day .d-name { font-size: 11px; opacity: 0.7; text-transform: capitalize; }
.w-day .d-icon { margin: 3px 0 1px; color: #9ec5f4; display: grid; place-items: center; }
.w-day .d-temps { font-size: 11.5px; }
.w-day .d-min { opacity: 0.6; }

.waves { position: absolute; inset: auto 0 0 0; height: 64px; pointer-events: none; }
.wave { position: absolute; inset: 0; width: 100%; height: 100%; }
.wave path { animation: drift 14s linear infinite; }
.wave-back path { fill: var(--wave-1); animation-duration: 22s; }
.wave-mid path { fill: var(--wave-2); animation-duration: 15s; animation-direction: reverse; }
.wave-front path { fill: var(--wave-3); animation-duration: 10s; }
@keyframes drift { to { transform: translateX(-1440px); } }
@media (prefers-reduced-motion: reduce) {
  .wave path { animation: none; }
}

/* ---------- layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; }

.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding: 4px 2px 16px;
}
.preset-group { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.preset {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13.5px;
  padding: 5px 11px; border-radius: 7px; cursor: pointer;
}
.preset:hover { background: var(--blue-wash); }
.preset.is-active { background: var(--blue); color: #fff; font-weight: 600; }
.custom-range { display: flex; gap: 10px; align-items: center; color: var(--ink-2); font-size: 13.5px; }
.custom-range input {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px;
}
.check-filter { display: flex; gap: 7px; align-items: center; color: var(--ink-2); font-size: 13.5px; cursor: pointer; }
.check-filter input { accent-color: var(--blue); width: 15px; height: 15px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* dropdown de comparação de anos */
.compare-dd { position: relative; font-size: 13.5px; color: var(--ink-2); }
.compare-dd summary {
  list-style: none; cursor: pointer; user-select: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 12px; display: inline-flex; align-items: center; gap: 7px;
}
.compare-dd summary::-webkit-details-marker { display: none; }
.compare-dd summary::after { content: "▾"; font-size: 10px; opacity: 0.7; }
.compare-dd[open] summary { border-color: var(--blue); }
.dd-badge {
  background: var(--blue); color: #fff; border-radius: 99px;
  font-size: 11px; font-weight: 650; padding: 1px 7px;
}
.dd-list {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  padding: 8px; width: 208px; max-height: 300px; overflow: auto;
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px;
}
.dd-item {
  display: flex; align-items: center; gap: 7px; padding: 5px 8px;
  border-radius: 8px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.dd-item:hover { background: var(--blue-wash); }
.dd-item input { accent-color: var(--blue); margin: 0; width: 14px; height: 14px; }
.dd-item .dd-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; background: transparent; }
.dd-item.is-disabled { opacity: 0.45; cursor: not-allowed; }
.compare-dd.is-blocked { opacity: 0.55; }
.compare-dd.is-blocked summary { cursor: not-allowed; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px 14px; position: relative; overflow: hidden;
}
.tile-label { margin: 0 0 4px; font-size: 13px; color: var(--ink-2); }
.tile-value { margin: 0; font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }
.tile-hero .tile-value { font-size: 38px; }
.tile-unit { font-size: 0.55em; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.tile-trend { font-size: 24px; }
.tile-delta { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }
.tile-hero .tile-delta { padding-right: 120px; }
.delta-up { color: var(--blue); font-weight: 600; }
.delta-down { color: var(--red); font-weight: 600; }
.spark { position: absolute; right: 14px; bottom: 10px; opacity: 0.9; }

/* ---------- cards / grid ---------- */
.grid-main { display: grid; grid-template-columns: 1fr 320px; gap: 14px; margin-bottom: 14px; }
.side-col { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px 18px; margin-bottom: 14px;
}
.grid-main .card { margin-bottom: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.card-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; }
.key-line { width: 16px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
.key-rect { width: 10px; height: 10px; border-radius: 3px; }
.key-up { background: var(--blue); }
.key-down { background: var(--red); }

.chart-wrap { position: relative; width: 100%; }
.chart-wrap.is-loading { opacity: 0.5; transition: opacity 0.2s; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.card-chart { display: flex; flex-direction: column; }
.card-chart .chart-wrap { flex: 1; }
#level-chart { min-height: 300px; }
#var-chart { min-height: 180px; }

/* ---------- régua (gauge) ---------- */
.gauge-wrap { display: flex; justify-content: center; }
.gauge-wrap svg { display: block; }
.g-water-wave { animation: drift-g 7s linear infinite; }
.g-water-wave2 { animation: drift-g 11s linear infinite reverse; }
@keyframes drift-g { to { transform: translateX(-160px); } }
@media (prefers-reduced-motion: reduce) {
  .g-water-wave, .g-water-wave2 { animation: none; }
}

/* ---------- animações dos gráficos ---------- */
.pulse {
  transform-box: fill-box; transform-origin: center;
  animation: ripple 2.4s ease-out infinite;
}
@keyframes ripple {
  0% { transform: scale(0.5); opacity: 0.65; }
  75% { transform: scale(2.4); opacity: 0; }
  100% { transform: scale(2.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; opacity: 0; }
}

/* ---------- tabela ---------- */
.table-scroll { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
#data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
#data-table th, #data-table td {
  text-align: right; padding: 7px 14px; border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
}
#data-table th:first-child, #data-table td:first-child { text-align: left; }
#data-table thead th {
  position: sticky; top: 0; background: var(--surface); color: var(--ink-2);
  font-weight: 600; border-bottom: 1px solid var(--baseline);
}

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed; z-index: 30; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.15);
  padding: 8px 12px; font-size: 13px; max-width: 240px;
}
.tooltip .tt-date { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; margin-top: 2px; }
.tooltip .tt-key { width: 12px; border-top: 2.5px solid; border-radius: 2px; flex: none; }
.tooltip .tt-val { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt-name { color: var(--ink-2); }

/* ---------- footer ---------- */
.foot { padding-top: 8px; font-size: 13px; color: var(--ink-2); }
.foot p { margin: 4px 0; }

/* ---------- responsivo ---------- */
@media (max-width: 980px) {
  .grid-main { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .spark { display: none; }
  .tile-hero .tile-delta { padding-right: 0; }
}
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 13px 14px 12px; }
  .tile-value { font-size: 25px; }
  .tile-hero .tile-value { font-size: 30px; }
  .hero-inner { padding: 22px 16px 50px; gap: 14px; }
  .hero h1 { font-size: 26px; }
  .hero-weather { min-width: 0; width: 100%; }
  .page { padding: 14px 14px 32px; }
  .card { padding: 14px; }
  .filters { gap: 8px 12px; }
}
