:root {
  --bg: #080b11;
  --bg-elev: #0e1420;
  --panel: #111a27;
  --panel-2: #16202f;
  --border: #1f2c3e;
  --border-soft: #18232f;
  --text: #ccd7e4;
  --text-strong: #eef4fb;
  --muted: #6c8199;
  --accent: #38bdf8;
  --accent-dim: #0e7490;
  --ok: #34d399;
  --warn: #fbbf24;
  --hot: #fb923c;
  --crit: #f87171;
  --crit-deep: #dc2626;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Trama sutil de fundo: dá textura de console sem competir com os dados. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(1200px 600px at 20% -10%, rgba(56, 189, 248, .07), transparent 60%),
    radial-gradient(900px 500px at 90% 0%, rgba(220, 38, 38, .05), transparent 60%);
  pointer-events: none;
  z-index: 0;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .92em; color: var(--accent); }

/* ------------------------------------------------------------------ topo */

.topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  background: rgba(8, 11, 17, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  font-size: 26px; color: var(--crit);
  animation: pulse 2.6s ease-in-out infinite;
  text-shadow: 0 0 18px rgba(248, 113, 113, .6);
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.brand h1 {
  margin: 0; font-size: 19px; letter-spacing: .22em; font-weight: 700;
  color: var(--text-strong); font-family: var(--mono);
}
.brand p { margin: 0; font-size: 11.5px; color: var(--muted); letter-spacing: .04em; }

.topbar-right { display: flex; align-items: center; gap: 20px; }
.livebox {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-family: var(--mono); color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
  background: var(--panel);
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); flex: none;
}
.dot.on  { background: var(--ok);   box-shadow: 0 0 10px var(--ok);   animation: pulse 2s infinite; }
.dot.off { background: var(--crit); box-shadow: 0 0 10px var(--crit); }
.clock { text-align: right; font-family: var(--mono); line-height: 1.1; }
.clock strong { font-size: 16px; color: var(--text-strong); letter-spacing: .06em; }
.clock small { display: block; font-size: 10px; color: var(--muted); letter-spacing: .18em; }

/* ------------------------------------------------------------------ abas */

.tabs {
  position: sticky; top: 61px; z-index: 400;
  display: flex; gap: 2px; padding: 0 20px;
  background: rgba(8, 11, 17, .92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  appearance: none; background: none; border: 0; cursor: pointer;
  padding: 11px 18px; color: var(--muted);
  font-family: var(--mono); font-size: 12px; letter-spacing: .1em;
  text-transform: uppercase; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { position: relative; z-index: 1; padding: 20px; max-width: 1680px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* ----------------------------------------------------------------- cards */

.cards {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.card {
  background: linear-gradient(160deg, var(--panel), var(--bg-elev));
  border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  position: relative; overflow: hidden;
}
.card::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent-dim);
}
.card.hot::after  { background: var(--hot); }
.card.crit::after { background: var(--crit); }
.card .label {
  font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted); font-family: var(--mono);
}
.card .value {
  font-size: 30px; font-weight: 700; font-family: var(--mono);
  color: var(--text-strong); line-height: 1.15; margin-top: 4px;
}
.card .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* --------------------------------------------------------------- painéis */

.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 16px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border-soft);
  background: var(--panel-2);
}
.panel-head h2 {
  margin: 0; font-size: 12.5px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--text-strong); font-family: var(--mono); font-weight: 600;
}
.panel-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-tools label {
  font-size: 11px; color: var(--muted); font-family: var(--mono);
  display: flex; align-items: center; gap: 6px;
}
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }

select, input[type="search"], input[type="date"] {
  background: var(--bg-elev); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 9px; font-size: 12px; font-family: var(--mono);
}
select:focus, input:focus { outline: 1px solid var(--accent); }
input[type="search"] { min-width: 170px; }
.check { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }

.btn {
  background: var(--accent-dim); color: #e6f7ff; border: 1px solid #0891b2;
  border-radius: 6px; padding: 5px 14px; font-size: 12px; cursor: pointer;
  font-family: var(--mono); letter-spacing: .05em;
}
.btn:hover { background: #0891b2; }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn.ghost:hover { color: var(--text); border-color: var(--accent); }
.btn:disabled { opacity: .35; cursor: default; }

.muted { color: var(--muted); }
.pad { padding: 16px; }
.chip {
  font-family: var(--mono); font-size: 11px; color: var(--accent);
  border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px;
  background: var(--bg-elev);
}
.footnote { margin: 0; padding: 10px 16px 14px; font-size: 11.5px; color: var(--muted); }

/* -------------------------------------------------------------- anomalia */

.anomaly-panel { border-color: #24344a; }

.verdict {
  padding: 20px 16px; text-align: center;
  border-bottom: 1px solid var(--border-soft);
}
.verdict-spinner { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.verdict .headline {
  font-size: clamp(18px, 3.4vw, 30px); font-weight: 700; font-family: var(--mono);
  letter-spacing: .06em; margin: 0 0 6px;
}
.verdict .detail { font-size: 13px; color: var(--muted); margin: 0; }
.verdict.v-normal .headline { color: var(--ok); }
.verdict.v-acima .headline, .verdict.v-abaixo .headline { color: var(--warn); }
.verdict.v-muito_acima .headline, .verdict.v-muito_abaixo .headline { color: var(--crit); }

.anomaly-grid {
  display: grid; gap: 10px; padding: 14px 16px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}
.acell {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 13px; background: var(--bg-elev);
  border-left-width: 3px;
}
.acell.normal        { border-left-color: var(--ok); }
.acell.acima,
.acell.abaixo        { border-left-color: var(--warn); }
.acell.muito_acima,
.acell.muito_abaixo  { border-left-color: var(--crit); }
.acell .ahead {
  display: flex; justify-content: space-between; align-items: baseline;
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  letter-spacing: .08em; text-transform: uppercase;
}
.acell .az { font-size: 13px; font-weight: 700; }
.acell.normal .az { color: var(--ok); }
.acell.acima .az, .acell.abaixo .az { color: var(--warn); }
.acell.muito_acima .az, .acell.muito_abaixo .az { color: var(--crit); }
.acell .anum {
  font-family: var(--mono); font-size: 24px; font-weight: 700;
  color: var(--text-strong); margin: 4px 0 1px;
}
.acell .anum { margin-bottom: 0; }
.acell .aexp { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.acell .abar {
  height: 5px; border-radius: 3px; margin: 8px 0 5px;
  background: linear-gradient(90deg, #1e3a5f 0%, #1e3a5f 100%);
  position: relative; overflow: hidden;
}
.acell .abar i {
  position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text-strong);
  box-shadow: 0 0 6px rgba(255, 255, 255, .8);
}
.acell .abar u {
  position: absolute; top: 0; bottom: 0; background: rgba(56, 189, 248, .25);
}
.acell .afoot { font-size: 11px; color: var(--muted); font-family: var(--mono); }

.explain {
  border-top: 1px solid var(--border-soft); padding: 0 16px;
  font-size: 12.5px; color: var(--muted);
}
.explain summary {
  cursor: pointer; padding: 11px 0; color: var(--accent);
  font-family: var(--mono); font-size: 11.5px; letter-spacing: .08em;
  text-transform: uppercase;
}
.explain p, .explain ul { margin: 0 0 10px; }
.explain li { margin-bottom: 4px; }
.explain b { color: var(--text); }
.warn {
  border-left: 2px solid var(--warn); padding-left: 10px; color: #d3b169;
}

/* --------------------------------------------------------------- gráficos */

.chart-wrap { padding: 14px 16px; height: 300px; position: relative; }
.chart-wrap.tall { height: 400px; }

/* ------------------------------------------------------------------ mapa */

.map-panel { margin-bottom: 0; }
#map {
  height: calc(100vh - 260px); min-height: 460px; width: 100%;
  background: #0b1017;
}
.leaflet-container { background: #0b1017; font-family: var(--sans); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 8px 30px rgba(0, 0, 0, .6);
}
.leaflet-popup-content { margin: 12px 14px; font-size: 12.5px; }
.leaflet-popup-content h3 {
  margin: 0 0 6px; font-size: 15px; color: var(--text-strong); font-family: var(--mono);
}
.leaflet-popup-content dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; }
.leaflet-popup-content dt { color: var(--muted); font-size: 11px; }
.leaflet-popup-content dd { margin: 0; font-family: var(--mono); font-size: 11.5px; }
.leaflet-control-attribution {
  background: rgba(8, 11, 17, .8) !important; color: var(--muted) !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control-zoom a {
  background: var(--panel) !important; color: var(--text) !important;
  border-color: var(--border) !important;
}

.legend {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; border-top: 1px solid var(--border-soft);
  font-size: 11px; color: var(--muted); font-family: var(--mono);
  background: var(--panel-2);
}
.legend-title { letter-spacing: .1em; text-transform: uppercase; }
.lg { display: flex; align-items: center; gap: 5px; }
.lg i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }

/* ---------------------------------------------------------------- listas */

.scroll-list { max-height: 330px; overflow-y: auto; }
.qrow {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 16px; border-bottom: 1px solid var(--border-soft);
}
.qrow:last-child { border-bottom: 0; }
.qrow:hover { background: var(--panel-2); }
.qmag {
  flex: none; width: 46px; height: 34px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-weight: 700; font-size: 14px; color: #0b0f16;
}
.qbody { min-width: 0; flex: 1; }
.qplace {
  color: var(--text-strong); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.qmeta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.qrow.flash { animation: flash 2.4s ease-out; }
@keyframes flash {
  0%   { background: rgba(56, 189, 248, .28); }
  100% { background: transparent; }
}
.badge {
  display: inline-block; font-size: 9.5px; font-family: var(--mono);
  padding: 1px 6px; border-radius: 3px; letter-spacing: .08em;
  text-transform: uppercase; margin-left: 6px; vertical-align: middle;
}
.badge.tsunami { background: #1e3a8a; color: #bfdbfe; }
.badge.alert-yellow { background: #78350f; color: #fde68a; }
.badge.alert-orange { background: #7c2d12; color: #fed7aa; }
.badge.alert-red    { background: #7f1d1d; color: #fecaca; }
.badge.novo         { background: #064e3b; color: #6ee7b7; }

/* --------------------------------------------------------------- tabelas */

.table-wrap { overflow-x: auto; max-height: 640px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-2); color: var(--muted);
  text-align: left; padding: 9px 12px; white-space: nowrap;
  font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em;
  text-transform: uppercase; border-bottom: 1px solid var(--border);
}
tbody td { padding: 8px 12px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; }
tbody td.place { white-space: normal; min-width: 200px; color: var(--text-strong); }
tbody tr:hover { background: var(--panel-2); }
td.num { font-family: var(--mono); text-align: right; }
.magpill {
  display: inline-block; min-width: 42px; text-align: center;
  padding: 2px 7px; border-radius: 4px; font-family: var(--mono);
  font-weight: 700; color: #0b0f16;
}
.pager {
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: 12px; border-top: 1px solid var(--border-soft); font-size: 12px;
}

/* --------------------------------------------------------------- sistema */

.kv { padding: 6px 16px 14px; }
.kv .row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 7px 0; border-bottom: 1px solid var(--border-soft); font-size: 12.5px;
}
.kv .row:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); }
.kv .v { font-family: var(--mono); color: var(--text-strong); text-align: right; }
.about { padding: 12px 16px 16px; font-size: 12.5px; color: var(--muted); }
.about p { margin: 0 0 9px; }
.about b { color: var(--text); }
.bvalue {
  padding: 10px 16px 14px; font-size: 12px; color: var(--muted);
  border-top: 1px solid var(--border-soft); font-family: var(--mono);
}
.bvalue b { color: var(--text-strong); font-size: 15px; }

footer {
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px 20px 28px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--muted); font-family: var(--mono);
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #22344a; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #2f4a68; }

@media (max-width: 720px) {
  main { padding: 12px; }
  .topbar { padding: 10px 12px; }
  .tabs { padding: 0 12px; top: 57px; }
  .grid-2 { grid-template-columns: 1fr; }
  #map { height: 60vh; }
  .clock strong { font-size: 14px; }
}
