/* Pruma - site público (pruma.org).
   Mesma linguagem visual do painel (app): tema escuro default, claro via
   [data-theme="light"]. Paleta: skill dataviz (validada CVD).
   Regra: cor de estado NUNCA sozinha - sempre ícone + rótulo junto.
   Público é calmo e informativo (arquitetura.md §7): sem cota, sem config,
   estados reduzidos a normal | atenção. */

:root {
  color-scheme: dark;
  --surface-1: #1a1a19;      /* superfície de gráfico/cards */
  --surface-2: #222221;      /* card elevado */
  --page: #0d0d0d;           /* plano da página */
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;           /* hairline de grid */
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;       /* azul - nível (slot 1 dark) */
  --series-2: #d95926;       /* laranja - 2º contexto sequencial (chuva) */
  --wash-percentil: rgba(57, 135, 229, 0.10);
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --focus: #3987e5;
}

:root[data-theme="light"] {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #ffffff;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --wash-percentil: rgba(42, 120, 214, 0.10);
  --focus: #2a78d6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Header ---------- */

.header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 1rem;
  height: 52px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1100;
}

.header__marca {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}
.header__marca:hover { text-decoration: none; }
.header__municipio {
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.header__nav { display: flex; gap: 0.25rem; margin-left: auto; }
.header__nav a {
  color: var(--text-secondary);
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.header__nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text-primary); }
.header__nav a[aria-current="page"] { color: var(--text-primary); font-weight: 600; }

.header__cta {
  margin-left: 0.25rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: var(--series-1);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  flex: none;
}
.header__cta:hover { filter: brightness(1.1); text-decoration: none; }

.header__botao {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.header__botao:hover { color: var(--text-primary); background: var(--surface-2); }
.header__botao svg { width: 16px; height: 16px; }

/* ---------- Aviso público (destaque em TODA página - arquitetura.md §7) ---------- */

.aviso-publico {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-primary);
  background: color-mix(in srgb, var(--status-warning) 14%, var(--surface-1));
  border-bottom: 1px solid color-mix(in srgb, var(--status-warning) 45%, transparent);
  position: relative;
  z-index: 1090;
}
.aviso-publico svg { width: 16px; height: 16px; flex: none; color: var(--status-warning); }
.aviso-publico__fonte { font-weight: 400; font-size: 0.78rem; color: var(--text-secondary); }

/* ---------- Leva da landing: uma linha sobre o produto, sem esconder o mapa ---------- */

.leva {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.55rem 1.25rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.leva__texto { margin: 0; color: var(--text-secondary); }
.leva__texto b { color: var(--text-primary); }
.leva__acoes { display: flex; gap: 1rem; margin-left: auto; white-space: nowrap; }

/* ---------- Faixa da frase interpretada (a que circula no WhatsApp) ---------- */

.frase-municipio {
  padding: 0.85rem 1rem;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.frase-municipio__texto {
  max-width: 980px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
  font-size: 1.02rem;
}
.frase-municipio__texto b { font-variant-numeric: tabular-nums; }

/* ---------- Busca de município (home) ---------- */

.busca-municipio {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(360px, calc(100vw - 110px));
}
.busca-municipio input {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.busca-municipio input:focus { border-color: var(--focus); outline: none; }
.busca-municipio__lista {
  margin-top: 0.3rem;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.busca-municipio__lista a {
  display: block;
  padding: 0.45rem 1rem;
  color: var(--text-primary);
  font-size: 0.9rem;
}
.busca-municipio__lista a:hover, .busca-municipio__lista a.ativo {
  background: var(--surface-2);
  text-decoration: none;
}

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

.tela-mapa {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* páginas do site empilham header + aviso + (frase) + mapa + rodapé */
.pagina-coluna { display: flex; flex-direction: column; height: 100vh; }

#mapa { flex: 1; height: 100%; background: var(--page); }

/* rebaixa o tile em dark pra não estourar o painel */
:root:not([data-theme="light"]) .leaflet-layer.camada-mapa-base { filter: brightness(0.7) contrast(1.05) saturate(0.7); }

.rodape-aviso {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--surface-1);
  border-top: 1px solid var(--border);
  padding: 0.3rem 1rem;
  text-align: center;
}

/* ---------- Marcadores do mapa (ícone + cor + rótulo) ---------- */

.marcador { text-align: center; transform: translate(-50%, -50%); position: absolute; }
.marcador__circulo {
  width: 34px;
  height: 34px;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--cor-estado);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface-1); /* anel de superfície */
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.45);
}
.marcador__circulo svg { width: 18px; height: 18px; }
.marcador--planejado .marcador__circulo {
  background: var(--surface-2);
  color: var(--text-muted);
  border: 2px dashed var(--text-muted);
}
.marcador__rotulo {
  margin-top: 2px;
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  .copo__agua { transition: none !important; }
}

/* legenda do mapa */
.legenda {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 1000;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
}
.legenda__titulo { font-weight: 600; margin-bottom: 0.3rem; color: var(--text-secondary); }
.legenda__item { display: flex; align-items: center; gap: 0.45rem; padding: 0.12rem 0; color: var(--text-secondary); }
.legenda__cor {
  width: 14px; height: 14px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  flex: none;
}
.legenda__cor svg { width: 9px; height: 9px; }
.legenda__cor--planejado { background: var(--surface-2) !important; border: 1.5px dashed var(--text-muted); color: var(--text-muted); }

/* ---------- Badge de semáforo ---------- */

.semaforo-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem 0.2rem 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-2);
}
.semaforo-badge__icone { display: inline-flex; }
.semaforo-badge__icone svg { width: 16px; height: 16px; }

/* ---------- Painel de detalhe ---------- */

.painel-detalhe {
  width: 420px;
  max-width: 100vw;
  height: 100%;
  overflow-y: auto;
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  padding: 1rem;
  display: none;
  flex-direction: column;
  gap: 1rem;
}
.painel-detalhe.aberto { display: flex; }

.painel-detalhe__topo { display: flex; align-items: flex-start; gap: 0.6rem; }
.painel-detalhe__titulo { margin: 0; font-size: 1.1rem; line-height: 1.3; }
.painel-detalhe__sub { color: var(--text-secondary); font-size: 0.82rem; margin-top: 2px; }
.painel-detalhe__fechar {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  line-height: 1;
  padding: 0.2rem 0.4rem;
  border-radius: 6px;
}
.painel-detalhe__fechar:hover { color: var(--text-primary); background: var(--surface-2); }

.card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
}
.card__titulo {
  margin: 0 0 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

/* stat "nível atual": copo + hero number lado a lado */
.nivel-atual { display: flex; gap: 1rem; align-items: center; }
.nivel-atual__num {
  font-size: 2.6rem;          /* hero figure: sans, proporcional */
  font-weight: 650;
  line-height: 1;
  color: var(--text-primary);
}
.nivel-atual__unidade { font-size: 1.1rem; color: var(--text-secondary); font-weight: 400; }
.nivel-atual__meta { display: flex; flex-direction: column; gap: 0.45rem; font-size: 0.82rem; color: var(--text-secondary); }
.nivel-atual__meta b { color: var(--text-primary); font-weight: 600; }

/* ---------- Copo animado ---------- */

.copo { flex: none; }
.copo svg { display: block; }
.copo__vidro { fill: none; stroke: var(--axis); stroke-width: 2; }
.copo__agua { transition: y 1.2s cubic-bezier(0.25, 0.6, 0.3, 1), height 1.2s cubic-bezier(0.25, 0.6, 0.3, 1); }
.copo__faixa { fill: var(--wash-percentil); }
.copo__cota { stroke: var(--status-critical); stroke-width: 1.5; }
.copo__cota-rotulo { font-size: 8.5px; fill: var(--text-muted); }
.copo__marca { stroke: var(--grid); stroke-width: 1; }

/* ---------- Gráfico ---------- */

.grafico { position: relative; }
.grafico svg { display: block; width: 100%; height: auto; }
.grafico .eixo { stroke: var(--axis); stroke-width: 1; }
.grafico .grade { stroke: var(--grid); stroke-width: 1; }
.grafico .tick { font-size: 10px; fill: var(--text-muted); font-variant-numeric: tabular-nums; }
.grafico .linha-nivel { stroke: var(--series-1); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; }
.grafico .area-nivel { fill: var(--series-1); opacity: 0.1; }
.grafico .faixa-percentil { fill: var(--wash-percentil); }
.grafico .linha-percentil { stroke: var(--series-1); stroke-width: 1; opacity: 0.45; }
.grafico .rotulo-percentil { font-size: 9px; fill: var(--text-muted); }
.grafico .linha-cota { stroke: var(--status-critical); stroke-width: 1.5; }
.grafico .rotulo-cota { font-size: 9px; fill: var(--text-secondary); }
.grafico .barra-chuva { fill: var(--series-2); }
.grafico .cursor { stroke: var(--text-muted); stroke-width: 1; }
.grafico .cursor-dot { fill: var(--series-1); stroke: var(--surface-2); stroke-width: 2; }

.grafico-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  z-index: 10;
  white-space: nowrap;
  display: none;
}
.grafico-tooltip b { font-variant-numeric: tabular-nums; }
.grafico-tooltip .chip { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

/* slider de data */
.slider-data { margin-top: 0.5rem; }
.slider-data input[type="range"] { width: 100%; accent-color: var(--series-1); }
.slider-data__valor {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* filtros de período (uma linha, acima do gráfico) */
.filtros { display: flex; gap: 0.3rem; margin-bottom: 0.6rem; flex-wrap: wrap; }
.filtros button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 0.15rem 0.65rem;
  font-size: 0.78rem;
}
.filtros button[aria-pressed="true"] {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
  font-weight: 600;
}

/* tabela-espelho do gráfico */
.tabela-wrap { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
table.tabela {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.tabela th, .tabela td {
  text-align: right;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tabela th:first-child, .tabela td:first-child { text-align: left; }
.tabela th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tabela tbody tr:hover { background: var(--surface-1); }

.botao-link {
  background: none;
  border: none;
  color: var(--series-1);
  font-size: 0.8rem;
  padding: 0.2rem 0;
}
.botao-link:hover { text-decoration: underline; }

/* ---------- Chat IA ---------- */

.chat-botao {
  position: fixed;
  right: 18px;
  bottom: 52px;
  z-index: 1200;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--series-1);
  color: #fff;
  border: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-botao svg { width: 24px; height: 24px; }
.chat-botao:hover { filter: brightness(1.1); }

.chat-janela {
  position: fixed;
  right: 18px;
  bottom: 116px;
  z-index: 1200;
  width: 360px;
  max-width: calc(100vw - 36px);
  height: 480px;
  max-height: calc(100vh - 140px);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.chat-janela.aberto { display: flex; }
.chat-janela__topo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.92rem;
}
.chat-janela__topo svg { width: 17px; height: 17px; color: var(--series-1); }
.chat-janela__fechar { margin-left: auto; background: none; border: none; color: var(--text-muted); font-size: 1.2rem; line-height: 1; }
.chat-janela__aviso { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 0.9rem; display: flex; flex-direction: column; gap: 0.6rem; }
.chat-msg { max-width: 85%; padding: 0.5rem 0.7rem; border-radius: 12px; font-size: 0.86rem; white-space: pre-wrap; }
.chat-msg--eu { align-self: flex-end; background: var(--series-1); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg--ia { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg--pensando { color: var(--text-muted); font-style: italic; }
.chat-form { display: flex; gap: 0.5rem; padding: 0.7rem; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.86rem;
}
.chat-form input:focus { border-color: var(--focus); outline: none; }
.chat-form button {
  background: var(--series-1);
  border: none;
  color: #fff;
  border-radius: 50%;
  width: 38px;
  height: 38px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-form button svg { width: 17px; height: 17px; }

/* ---------- Aviso/estado vazio + página de erro ---------- */

.vazio { color: var(--text-muted); text-align: center; padding: 2rem 1rem; font-size: 0.9rem; }

.erro-tela {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.erro-caixa {
  width: 100%;
  max-width: 360px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  text-align: center;
}
.erro-caixa h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.02em; }

/* ---------- Páginas institucionais (/produtos, /empresa, /contato) ---------- */

.pagina-institucional { min-height: 100vh; display: flex; flex-direction: column; }
.institucional { width: 100%; max-width: 880px; margin: 0 auto; padding: 2.25rem 1.25rem 3.5rem; flex: 1; }
.institucional h1 { font-size: 1.55rem; margin: 0 0 0.5rem; }
.institucional h2 { font-size: 1.05rem; margin: 2rem 0 0.6rem; }
.institucional p, .institucional li { color: var(--text-secondary); max-width: 64ch; }
.institucional b { color: var(--text-primary); }
.institucional .intro { font-size: 1.02rem; margin: 0 0 1.6rem; }

.grade-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; margin: 1.4rem 0; }
.grade-cards .card p { font-size: 0.88rem; margin: 0.4rem 0 0; }
.grade-cards .card ul { font-size: 0.88rem; margin: 0.4rem 0 0; padding-left: 1.1rem; }
.grade-cards .card li { margin: 0.15rem 0; }
.card--destaque { border-color: var(--series-1); }
.selo {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--series-1);
  border: 1px solid var(--series-1);
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  margin-bottom: 0.5rem;
}

.rodape-institucional {
  border-top: 1px solid var(--border);
  padding: 1rem 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* ---------- Responsivo ---------- */

@media (max-width: 760px) {
  .tela-mapa { flex-direction: column; }
  .painel-detalhe {
    position: absolute;
    inset: auto 0 0 0;
    width: 100%;
    height: 70%;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 14px 14px 0 0;
    z-index: 1050;
  }
  .header__nav a { padding: 0.4rem 0.45rem; font-size: 0.82rem; }
  .header { gap: 0.5rem; flex-wrap: wrap; }
  .header__municipio { display: none; }
  .header__nav { margin-left: 0; }
  .header__cta { margin-left: auto; font-size: 0.76rem; padding: 0.3rem 0.6rem; }
  .leva__acoes { margin-left: 0; }
  .frase-municipio__texto { font-size: 0.92rem; }
}
