:root {
  --fundo: #0e0f13;
  --painel: rgba(20, 21, 27, 0.94);
  --borda: rgba(255, 255, 255, 0.08);
  --grade: rgba(255, 255, 255, 0.07);
  --texto: #ecebe7;
  --texto-2: #a3a2a9;
  --acento: #9ec5f4;
  /* Categorias validadas contra o fundo escuro (CVD ΔE ≥ 9,4 entre todos os pares). */
  --cat-0: #3987e5;
  --cat-1: #199e70;
  --cat-2: #d95926;
  --cat-3: #8a8a92;
  --serie: #3987e5;
  --serie-fraca: rgba(57, 135, 229, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fundo);
  color: var(--texto);
  font: 14px/1.45 Inter, system-ui, sans-serif;
}

#mapa { position: fixed; inset: 0; }

#painel {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 360px;
  overflow-y: auto;
  padding: 20px;
  background: var(--painel);
  backdrop-filter: blur(8px);
  border: 1px solid var(--borda);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

h1 { font-size: 20px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
.sub, .dica, .fonte { color: var(--texto-2); font-size: 12px; margin: 4px 0 0; }
.dica { margin: 0; font-weight: 400; }
.rotulo { color: var(--texto-2); font-size: 12px; font-weight: 500; }
a { color: var(--acento); }

.controles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.controles-topo { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; margin-bottom: -2px; }
.controles .largo { grid-column: 1 / -1; }
.controles label { display: flex; flex-direction: column; gap: 4px; color: var(--texto-2); font-size: 12px; font-weight: 500; }
button.link { border: 0; background: none; color: var(--acento); padding: 0; font-size: 12px; font-weight: 500; }
button.link:hover { text-decoration: underline; }
.recorte { margin: -6px 0 0; display: flex; gap: 8px; align-items: baseline; }
.recorte strong { font-weight: 600; }

select, button, input {
  font: inherit;
  color: var(--texto);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--borda);
  border-radius: 8px;
}
select, input { padding: 7px 8px; width: 100%; }
input::placeholder { color: var(--texto-2); }
button { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, .barra-h:focus-visible {
  outline: 2px solid var(--acento);
  outline-offset: 1px;
}

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { padding: 12px; border: 1px solid var(--borda); border-radius: 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card strong { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; white-space: nowrap; }

.grafico { display: flex; flex-direction: column; gap: 6px; }
.grafico-topo { display: flex; justify-content: space-between; align-items: baseline; }
#serie { width: 100%; height: 140px; display: block; cursor: pointer; }
#serie text { fill: var(--texto-2); font-size: 10px; font-variant-numeric: tabular-nums; }
#serie .grade { stroke: var(--grade); stroke-width: 1; }
#serie .linha { fill: none; stroke: var(--serie-fraca); stroke-width: 1.5; }
#serie .linha-ano { fill: none; stroke: var(--serie); stroke-width: 2; }
#serie .faixa-ano { fill: rgba(255, 255, 255, 0.05); }
#serie .evento { stroke: var(--texto-2); stroke-width: 1; }
#serie .evento-texto { fill: var(--texto); font-size: 10px; }
#serie .mira { stroke: var(--texto-2); stroke-width: 1; }
#serie .ponto { fill: var(--serie); stroke: var(--painel); stroke-width: 2; }

.barras-h { display: flex; flex-direction: column; gap: 2px; }
.barra-h {
  display: grid;
  grid-template-columns: 112px 1fr 58px;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font-size: 12px;
}
.barra-h:hover { background: rgba(255, 255, 255, 0.05); }
.barra-h .nome { color: var(--texto); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-h .trilho { height: 8px; }
.barra-h .valor { height: 8px; background: var(--serie); border-radius: 0 4px 4px 0; min-width: 2px; }
.barra-h .numero { color: var(--texto-2); text-align: right; font-variant-numeric: tabular-nums; }
.barra-h.apagada .valor { background: var(--serie-fraca); }
.barra-h.ativa .nome { font-weight: 600; }

.rotas { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; counter-reset: rota; }
.rotas li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 4px;
  border-radius: 6px;
  font-size: 12px;
  cursor: default;
}
.rotas li:hover { background: rgba(255, 255, 255, 0.05); }
.rotas .sw { width: 10px; height: 10px; border-radius: 2px; align-self: center; }
.rotas .trecho { min-width: 0; }
.rotas .trecho span { color: var(--texto-2); }
.rotas .numero { color: var(--texto-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.vazio { color: var(--texto-2); font-size: 12px; }

.estacao { border-top: 1px solid var(--borda); padding-top: 14px; }
.estacao-topo { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
#est-fechar { width: 28px; height: 28px; padding: 0; font-size: 18px; line-height: 1; flex: none; }
#est-resumo { margin: 6px 0 0; color: var(--texto-2); font-size: 13px; }
#est-resumo strong { color: var(--texto); font-weight: 600; }

footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
#legenda { list-style: none; margin: 6px 0 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 12px; }
#legenda li { display: flex; align-items: center; gap: 6px; }
#legenda .sw { width: 14px; height: 4px; border-radius: 2px; }

#tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 10;
  padding: 7px 10px;
  background: #1b1c22;
  border: 1px solid var(--borda);
  border-radius: 7px;
  font-size: 12px;
  max-width: 280px;
}
#tooltip strong { font-weight: 600; }
#tooltip .t2 { color: var(--texto-2); }

.abas { display: flex; gap: 4px; margin-bottom: 12px; }
.abas a {
  padding: 4px 10px;
  border: 1px solid var(--borda);
  border-radius: 999px;
  color: var(--texto-2);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
}
.abas a:hover { color: var(--texto); }
.abas a[aria-current="page"] { color: var(--texto); background: rgba(255, 255, 255, 0.08); }

#serie .barra { fill: var(--serie-fraca); }
#serie .barra.ativa { fill: var(--serie); }
#serie .barra.incompleta { fill: rgba(255, 255, 255, 0.12); }

.rotas li.clicavel { cursor: pointer; }
.rotas li.clicavel:focus-visible { outline: 2px solid var(--acento); outline-offset: 1px; }
.rotas li.ativa .trecho { font-weight: 600; }
#legenda .sw.ponto { width: 10px; height: 10px; border-radius: 50%; }

.nota {
  padding: 12px;
  border: 1px solid var(--borda);
  border-radius: 10px;
  font-size: 12px;
  color: var(--texto-2);
}
.nota p { margin: 0; }
.nota p + p { margin-top: 6px; }
.nota strong { color: var(--texto); }

.maplibregl-ctrl-attrib { font-size: 10px; }

@media (max-width: 720px) {
  #painel {
    top: auto;
    left: 16px;
    right: 16px;
    bottom: 16px;
    width: auto;
    max-height: 50vh;
    padding: 16px;
    gap: 14px;
  }
  h1 { font-size: 17px; }
  .card strong { font-size: 19px; }
  #serie { height: 110px; }
}

/* Página de Juiz de Fora */
.lead { margin: -6px 0 0; font-size: 13px; color: var(--texto-2); }
.lead strong { color: var(--texto); font-weight: 600; }
#ranking { width: 100%; display: block; }
#ranking text { fill: var(--texto-2); font-size: 10px; font-variant-numeric: tabular-nums; }
#ranking .grade { stroke: var(--grade); stroke-width: 1; }
#ranking .alvo { fill: transparent; }
#ranking .linha-ranking { cursor: pointer; }
#ranking .linha-ranking:hover .alvo, #ranking .linha-ranking.ativa .alvo { fill: rgba(255, 255, 255, 0.05); }
#ranking .linha-ranking:focus-visible { outline: 2px solid var(--acento); }
#ranking .nome { fill: var(--texto); font-size: 12px; }
#ranking .linha-ranking.ativa .nome { font-weight: 600; }
#ranking .valor { fill: var(--texto); font-size: 12px; }
#ranking .intervalo { stroke: rgba(217, 89, 38, 0.55); stroke-width: 2; stroke-linecap: round; }
#ranking .esperado { stroke: var(--texto-2); stroke-width: 2; stroke-linecap: round; }
#ranking .estimado { fill: var(--cat-2); stroke: var(--painel); stroke-width: 2; }
#d-fechar { width: 28px; height: 28px; padding: 0; font-size: 18px; line-height: 1; flex: none; }
.d-texto { margin: 8px 0 0; color: var(--texto-2); font-size: 13px; }
.d-texto strong { color: var(--texto); font-weight: 600; }
#d-horas-bloco { margin-top: 12px; }
#d-horas { width: 100%; height: 90px; display: block; }
#d-horas .barra { fill: var(--serie); }
#d-horas text { fill: var(--texto-2); font-size: 10px; font-variant-numeric: tabular-nums; }
.memo ol { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.memo li::marker { color: var(--texto-2); }
