:root {
  --bg: #eef2f5;
  --ink: #0f1720;
  --muted: #5c6b7a;
  --line: #dfe6ec;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --shadow: 0 10px 30px rgba(15, 23, 32, 0.12), 0 2px 8px rgba(15, 23, 32, 0.06);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 0;
}

/* ---------- Painéis ---------- */
.panel {
  position: absolute;
  z-index: 5;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Cabeçalho */
.panel--top {
  top: 16px;
  left: 16px;
  max-width: 340px;
  padding: 16px 18px;
}
.panel--top h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}
.panel--top .sub {
  margin: 6px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

/* Controles */
.panel--controls {
  top: 128px;
  left: 16px;
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search { position: relative; }
.search input,
.panel--controls select {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  outline: none;
}
.search input:focus,
.panel--controls select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}
.panel--controls select { cursor: pointer; }

.results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 260px;
  overflow-y: auto;
}
.results li {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.results li:hover,
.results li.active { background: #eef4f3; }
.results li .uf { color: var(--muted); font-size: 0.78rem; }
.results li.empty { color: var(--muted); cursor: default; }

/* Legenda */
.panel--legend {
  right: 16px;
  bottom: 16px;
  padding: 14px 16px;
  min-width: 168px;
}
.panel--legend h2 {
  margin: 0 0 10px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}
#legend-items {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#legend-items li {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}
#legend-items li:hover { background: #eef4f3; }
#legend-items li .swatch {
  width: 20px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  flex: none;
}
#legend-items li.dim { opacity: 0.35; }

.credit {
  margin-top: 10px;
  font-size: 0.64rem;
  color: var(--muted);
  line-height: 1.35;
}

/* Painel de detalhes */
.panel--info {
  z-index: 6;
  top: 16px;
  right: 16px;
  width: 300px;
  padding: 18px;
}
.panel--info h3 {
  margin: 0 0 2px;
  font-size: 1.05rem;
  line-height: 1.25;
}
.panel--info .info-uf {
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 14px;
}
.panel--info .big {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}
.panel--info .big-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.info-rows {
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  font-size: 0.85rem;
}
.info-rows dt { color: var(--muted); }
.info-rows dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.delta { font-weight: 600; }
.delta.up { color: #b10026; }
.delta.down { color: #0f766e; }
.delta.zero { color: var(--muted); }

#info-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px;
}
#info-close:hover { background: #eef4f3; color: var(--ink); }

/* Barra comparativa */
.bars { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.bar-row { font-size: 0.72rem; color: var(--muted); }
.bar-track {
  height: 7px;
  background: #e8eef2;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 3px;
}
.bar-fill { height: 100%; border-radius: 5px; }

/* Painel "Sobre este mapa" */
.panel--about {
  left: 16px;
  bottom: 96px;
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
}
.panel--about > summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel--about > summary::-webkit-details-marker { display: none; }
.panel--about > summary::before {
  content: "?";
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  flex: none;
}
.about-body {
  margin-top: 10px;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #34404c;
  max-height: 46vh;
  overflow-y: auto;
}
.about-body p { margin: 0 0 9px; }
.about-body table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin: 6px 0 10px;
}
.about-body caption {
  text-align: left;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 5px;
}
.about-body th, .about-body td {
  border-bottom: 1px solid var(--line);
  padding: 3px 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.about-body th:first-child, .about-body td:first-child { text-align: left; }
.about-body a { color: var(--accent); font-weight: 600; }

/* ---------- Responsivo ---------- */
@media (max-width: 720px) {
  .panel--top { left: 10px; right: 10px; top: 10px; max-width: none; padding: 11px 14px; }
  .panel--top h1 { font-size: 0.98rem; }
  .panel--controls { left: 10px; right: 10px; top: 82px; bottom: auto; width: auto; }
  .panel--legend {
    right: 10px; left: auto; top: auto; bottom: 62px; padding: 10px 12px; min-width: 0;
  }
  #legend-items { gap: 3px; }
  #legend-items li { font-size: 0.72rem; gap: 7px; }
  #legend-items li .swatch { width: 16px; height: 11px; }
  .panel--about {
    left: 10px; right: 10px; bottom: 10px; width: auto; padding: 9px 13px;
  }
  .about-body { max-height: 42vh; }
  .panel--info {
    left: 10px; right: 10px; top: auto; bottom: 10px; width: auto;
    max-height: 60vh; overflow-y: auto;
  }
}
