/* WebGIS Ambiental PE | Neto Pimentel | 2026-11-15 | v0.8
   Release v0.8 (2026-11-18): título acadêmico (serifa, sobretítulo, bandeira 48×32), paleta da bandeira
     (azul como destaque), temas claro/escuro/automático via data-theme (+ prefers-color-scheme).
   Release v0.7 (2026-11-18): barra superior (bandeira oficial, busca, horário da coleta), painel em
     abas, legenda flutuante no mapa (sem rolagem: rolagem sobre o canvas WebGL causa área sem repintar),
     tiles de KPI e listas da aba "Agora".
   Release v0.6: cards, chaves de camada, details; fix painel mobile preso em 45vh.
   Release v0.4.1: ficha responsiva; rótulo de hover.
   Release v0.3.1: ficha do município no painel; popup sem rolagem. */
:root {
  /* Paleta da bandeira de PE (Lei 75/1917; construção do Commons) */
  --pe-azul: #3155a4; --pe-amarelo: #ffb511; --pe-verde: #00ad4a; --pe-vermelho: #c34342;
  --bg: #f3f5f8; --surface: #ffffff; --text: #141c2b; --muted: #5a6475; --border: #dde3ec;
  --accent: #3155a4; --accent-soft: #e7edf9; --blue: #3155a4; --warn-bg: #fff4d6; --warn: #6f5200;
  --bad: #b3261e; --shadow: 0 1px 2px rgba(20,28,43,.05), 0 6px 20px rgba(20,28,43,.07); --r: 14px;
  --bar: 76px; --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  color-scheme: light;
}
/* escuro: pelo sistema (modo automático) ou forçado pelo seletor */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0d121b; --surface: #151c28; --text: #e8ecf3; --muted: #9aa5b8; --border: #263044;
  --accent: #8fb0ff; --accent-soft: #1d2a45; --blue: #8fb0ff; --warn-bg: #352d10; --warn: #f0d58a; --bad: #ff8a80;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.3); color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #0d121b; --surface: #151c28; --text: #e8ecf3; --muted: #9aa5b8; --border: #263044;
  --accent: #8fb0ff; --accent-soft: #1d2a45; --blue: #8fb0ff; --warn-bg: #352d10; --warn: #f0d58a; --bad: #ff8a80;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 8px 24px rgba(0,0,0,.3); color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; }
body { display: grid; grid-template-columns: 390px 1fr; grid-template-rows: var(--bar) 1fr; }

/* barra superior */
.appbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 5; }
.appbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px;
  background: linear-gradient(90deg, var(--pe-azul) 0 60%, var(--pe-amarelo) 60% 73.3%, var(--pe-verde) 73.3% 86.6%, var(--pe-vermelho) 86.6%);
  height: 3px; opacity: .85; }
.bandeira { width: 48px; height: 32px; border-radius: 4px; flex: none;
  box-shadow: 0 0 0 1px rgba(0,0,0,.10), 0 2px 6px rgba(20,28,43,.18); }
.marca { display: flex; flex-direction: column; justify-content: center; min-width: 0;
  padding-left: 12px; border-left: 1px solid var(--border); }
.sobretitulo { font-size: 10.5px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: var(--accent); line-height: 1.2; }
.marca h1 { font-family: var(--serif); font-size: 22px; line-height: 1.15; margin: 1px 0 1px; font-weight: 600;
  letter-spacing: -.005em; white-space: nowrap; }
.marca h1 em { font-style: italic; font-weight: 500; color: var(--muted); }
.marca p { margin: 0; font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tema { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 12px; font-weight: 600;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; white-space: nowrap; }
.tema:hover { border-color: var(--accent); }
/* ícones do tema em CSS puro (caracteres ◐☀☾ não existem em todas as fontes) */
.tema span { width: 14px; height: 14px; border-radius: 50%; flex: none; position: relative; }
.tema[data-modo="auto"] span { border: 2px solid currentColor; background: linear-gradient(90deg, currentColor 50%, transparent 50%); }
.tema[data-modo="claro"] span { background: var(--pe-amarelo); box-shadow: 0 0 0 3px rgba(255,181,17,.28); }
.tema[data-modo="escuro"] span { background: transparent; box-shadow: inset -4px -2px 0 0 var(--accent); transform: rotate(-20deg); }
.busca { flex: 1; max-width: 420px; margin-left: auto; }
.busca input { width: 100%; padding: 8px 12px 8px 34px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237a8a82' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E") 12px 50% no-repeat;
  color: var(--text); font: inherit; outline: none; }
.busca input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chip-at { font-size: 11.5px; color: var(--muted); white-space: nowrap; padding: 4px 10px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--border); }
.chip-at:empty { display: none; }

/* painel + abas */
#painel { overflow-y: auto; background: var(--bg); border-right: 1px solid var(--border); scrollbar-width: thin; }
.abas { position: sticky; top: 0; z-index: 2; display: flex; gap: 4px; padding: 10px 12px; background: var(--bg); }
.abas button { flex: 1; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); background: transparent;
  border: 0; border-radius: 10px; padding: 7px 6px; cursor: pointer; display: inline-flex; align-items: center;
  justify-content: center; gap: 5px; }
.abas button:hover { background: var(--surface); color: var(--text); }
.abas button[aria-selected="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.ponto { width: 7px; height: 7px; border-radius: 50%; background: var(--pe-vermelho); display: inline-block;
  box-shadow: 0 0 0 3px rgba(195,67,66,.18); }
.aba { padding: 0 12px 16px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 14px; margin-bottom: 10px; }
.card.vazio { color: var(--muted); text-align: center; padding: 28px 14px; }
h2 { font-family: var(--serif); font-size: 15px; margin: 0 0 8px; font-weight: 600; letter-spacing: -.005em; }
h2 small, .desc, .fonte { color: var(--muted); font-weight: 400; }
label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 11.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; }
select { width: 100%; padding: 9px 11px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; outline: none; }
select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.desc { font-size: 12.5px; margin: 8px 0 0; }
.fonte { font-size: 11.5px; margin: 8px 0 0; }

/* chaves de camada */
.tg { display: flex; align-items: center; gap: 10px; text-transform: none; letter-spacing: 0; font-size: 13.5px;
  font-weight: 500; color: var(--text); margin: 9px 0 0; cursor: pointer; position: relative; }
.tg small { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.tg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.tg span { position: relative; width: 36px; height: 21px; border-radius: 999px; background: var(--border); flex: none; transition: background .15s; }
.tg span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.tg input:checked + span { background: var(--accent); }
.tg input:checked + span::after { transform: translateX(15px); }
.tg input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }
.tg input:disabled + span { opacity: .4; }

.aviso { background: var(--warn-bg); color: var(--warn); padding: 9px 11px; border-radius: 10px; font-size: 12.5px; }
#ranking { margin: 0; padding-left: 22px; font-size: 13px; }
#ranking li { cursor: pointer; padding: 3px 0; }
#ranking li:hover { color: var(--accent); }
#ranking b { float: right; font-variant-numeric: tabular-nums; font-weight: 650; }

/* KPIs */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kpi { background: var(--bg); border: 1px solid var(--border); border-radius: 11px; padding: 9px 11px; }
.kpi .v { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .r { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.kpi .d { font-size: 11px; color: var(--accent); margin-top: 2px; }
.kpi.ruim .v { color: var(--bad); }

/* listas da aba Agora */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li { display: flex; align-items: baseline; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border);
  cursor: pointer; font-size: 13px; }
.lista li:first-child { border-top: 0; }
.lista li:hover .n { color: var(--accent); }
.lista .n { flex: 1; min-width: 0; }
.lista .n small { display: block; color: var(--muted); font-size: 11.5px; }
.lista .v { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.tag.ok { background: var(--accent-soft); color: var(--accent); }
.tag.falha { background: var(--warn-bg); color: var(--warn); }

/* links e consultas */
.links { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.links a, .consultas a { font-size: 12px; text-decoration: none; color: var(--accent); background: var(--accent-soft);
  padding: 3px 10px; border-radius: 999px; font-weight: 600; }
.links a:hover, .consultas a:hover { text-decoration: underline; }
.consultas .item { border-top: 1px solid var(--border); padding: 9px 0 3px; }
.consultas .item:first-child { border-top: 0; padding-top: 0; }
.consultas b { font-size: 13px; }
.consultas p { margin: 3px 0 7px; font-size: 12px; color: var(--muted); }

/* legenda flutuante (sem overflow!) */
#mapa { position: relative; height: 100%; min-height: 0; }
.legenda-box { position: absolute; left: 12px; bottom: 28px; z-index: 2; width: 260px; max-width: calc(100% - 24px);
  background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 10px 12px; font-size: 12px; }
#legenda-titulo { font-weight: 700; font-size: 12.5px; margin-bottom: 6px; line-height: 1.3; }
#legenda .barra { display: flex; height: 10px; border-radius: 5px; overflow: hidden; }
#legenda .barra span { flex: 1; }
#legenda .rotulos { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted);
  margin-top: 4px; font-variant-numeric: tabular-nums; gap: 4px; }
#legenda .cat { display: flex; align-items: center; gap: 7px; font-size: 12px; padding: 1px 0; line-height: 1.3; }
#legenda .cat .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
#legenda .cat b { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 650; }

/* popup, ficha, dica */
.maplibregl-popup-content { color: #17211c; font: 13px/1.4 system-ui, sans-serif; min-width: 220px; border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 12px 14px; }
.maplibregl-popup-content h3 { margin: 0 0 6px; font-size: 14px; }
.na { color: #8a948e; font-style: italic; }
#ficha-tab { font-size: 12.5px; }
.resumo .lin, #ficha .lin { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 10px; padding: 3px 0; }
#ficha .lin { padding: 4px 0; border-bottom: 1px dotted var(--border); }
.resumo .rot, #ficha .rot { flex: 1 1 55%; min-width: 0; }
.resumo .val, #ficha .val { flex: 0 1 auto; max-width: 100%; text-align: right; font-weight: 650;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.resumo .val.cat { flex: 1 1 100%; text-align: left; font-weight: 500; color: #3155a4; }
#ficha .val.cat { flex: 1 1 100%; text-align: left; font-weight: 500; color: var(--accent); }
#ficha .grp { padding-top: 12px; font-weight: 750; font-size: 11px; color: var(--accent);
  text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); }
.dica { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 3; display: flex; flex-direction: column;
  background: rgba(255,255,255,.97); color: #17211c; border-radius: 9px; padding: 6px 10px; font-size: 12.5px;
  box-shadow: 0 4px 14px rgba(0,0,0,.18); white-space: nowrap; max-width: 300px; }
.dica[hidden] { display: none; }
.dica span { color: #5a6961; font-size: 12px; white-space: normal; }
@media (hover: none) { .dica { display: none; } }

@media (max-width: 860px) {
  html, body { height: auto; }
  body { grid-template-columns: 1fr; grid-template-rows: auto 58vh auto; }
  .appbar { flex-wrap: wrap; padding: 10px 12px; gap: 8px 10px; }
  .bandeira { width: 39px; height: 26px; }
  .marca { padding-left: 10px; }
  .marca h1 { font-size: 18px; white-space: normal; }
  .marca p { display: none; }
  .tema b { display: none; }
  .busca { order: 3; flex: 1 1 100%; max-width: none; margin: 0; }
  .chip-at { margin-left: auto; }
  #mapa { grid-row: 2; height: 58vh; }
  #painel { grid-row: 3; overflow: visible; border-right: 0; }
  .abas { position: sticky; top: 0; }
  .legenda-box { width: 210px; bottom: 26px; left: 8px; padding: 8px 10px; }
  #legenda .cat { font-size: 11px; }
}
