:root {
  --ink: #2b1e1c;
  --muted: #746865;
  --paper: #fffdfb;
  --brand: #8f2f2a;
  --brand-dark: #651c1a;
  --brand-soft: #f7e9e6;
  --line: rgba(72, 43, 39, 0.14);
  --shadow: 0 18px 46px rgba(49, 28, 25, 0.16);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background: #e7e3df;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }

.site-shell { min-height: 100dvh; overflow: hidden; }

.topbar {
  height: 82px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 253, 251, 0.96);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: white;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(145deg, #a43a33, #651c1a);
  box-shadow: 0 8px 20px rgba(101, 28, 26, 0.24);
}

.brand-copy { min-width: 0; }
.eyebrow { margin: 0 0 3px; color: var(--brand); font-size: 0.7rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.brand-copy h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.1rem, 2vw, 1.55rem); line-height: 1.05; letter-spacing: -0.02em; }

.total-pill {
  margin-left: auto;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  text-align: right;
  background: white;
}

.total-pill span { color: var(--muted); font-size: 0.67rem; }
.total-pill strong { color: var(--brand-dark); font-size: 1.1rem; line-height: 1.1; }

.map-stage { height: calc(100dvh - 82px); position: relative; overflow: hidden; }
.map-frame { width: 100%; height: 100%; display: block; border: 0; background: #eeeae6; }

.control-card {
  position: absolute;
  z-index: 10;
  top: 20px;
  right: 20px;
  width: min(360px, calc(100vw - 40px));
  max-height: calc(100% - 40px);
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 22px;
  background: rgba(255, 253, 251, 0.95);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.search-block label { display: block; margin-bottom: 8px; font-size: 0.78rem; font-weight: 800; }
.search-form { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.search-form input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: white;
}
.search-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(143, 47, 42, 0.12); }
.search-form button, .back-button {
  border: 0;
  border-radius: 12px;
  color: white;
  background: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
}
.search-form button { padding: 0 13px; }
.search-form button:hover { background: var(--brand-dark); }
.back-button { width: 100%; padding: 10px 12px; margin-bottom: 14px; background: var(--brand-dark); }

.welcome-card, .municipio-card { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--line); }
.welcome-card h2, .municipio-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; letter-spacing: -0.025em; }
.welcome-card h2 { font-size: 1.45rem; }
.welcome-card p { color: var(--muted); font-size: 0.88rem; line-height: 1.55; }

.quick-links { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-links button {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--brand-dark);
  background: white;
  font-size: 0.76rem;
  font-weight: 750;
}
.quick-links button:hover { border-color: var(--brand); background: var(--brand-soft); }

.municipio-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.municipio-heading h2 { font-size: 1.7rem; }
.vote-badge { padding: 8px 10px; border-radius: 12px; color: white; background: var(--brand-dark); font-weight: 850; }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0 0; }
.stats-grid div { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.stats-grid dt { margin-bottom: 4px; color: var(--muted); font-size: 0.65rem; }
.stats-grid dd { margin: 0; font-weight: 850; }
.stats-grid .positive dd { color: #287a50; }
.stats-grid .negative dd { color: #b13c36; }

.neighborhood-button {
  width: 100%;
  margin-top: 12px;
  padding: 11px 14px;
  border: 0;
  border-radius: 13px;
  color: white;
  background: var(--brand);
  font-weight: 850;
}
.neighborhood-button:hover { background: var(--brand-dark); }
.neighborhood-button:disabled { cursor: default; opacity: 0.72; }
.muted-note { margin: 13px 0 0; color: var(--muted); font-size: 0.76rem; }

.data-note { margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.72rem; line-height: 1.45; }
.data-note summary { color: var(--ink); cursor: pointer; font-weight: 800; }
.data-note p { margin: 8px 0 0; }

.map-legend {
  position: absolute;
  z-index: 8;
  left: 20px;
  bottom: 20px;
  min-width: 340px;
  padding: 13px 15px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 16px;
  background: rgba(255, 253, 251, 0.94);
  box-shadow: 0 12px 28px rgba(49, 28, 25, 0.13);
  backdrop-filter: blur(12px);
}
.legend-title { display: flex; justify-content: space-between; align-items: baseline; gap: 20px; margin-bottom: 8px; }
.legend-title strong { font-size: 0.77rem; }
.legend-title span { color: var(--muted); font-size: 0.65rem; }
.legend-scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.legend-scale div { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 0.66rem; white-space: nowrap; }
.color-swatch { width: 18px; height: 10px; border: 1px solid rgba(43, 30, 28, 0.16); border-radius: 3px; }

@media (max-width: 720px) {
  .topbar { height: 72px; padding: 0 12px; gap: 10px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 0.9rem; }
  .brand-copy .eyebrow { display: none; }
  .brand-copy h1 { max-width: 210px; font-size: 1rem; }
  .total-pill { padding: 6px 9px; border-radius: 11px; }
  .total-pill span { display: none; }
  .total-pill strong { font-size: 0.9rem; }
  .map-stage { height: calc(100dvh - 72px); }
  .control-card { top: 10px; right: 10px; width: calc(100vw - 20px); max-height: 44%; padding: 13px; border-radius: 17px; }
  .welcome-card, .municipio-card { margin-top: 12px; padding-top: 12px; }
  .welcome-card p { margin-bottom: 10px; }
  .municipio-heading h2 { font-size: 1.35rem; }
  .stats-grid { margin-top: 11px; }
  .stats-grid div { padding: 7px 9px; }
  .data-note { display: none; }
  .map-legend { left: 10px; bottom: 10px; min-width: 0; width: calc(100vw - 20px); padding: 10px 12px; }
  .legend-title { margin-bottom: 7px; }
  .legend-scale { gap: 4px; }
  .legend-scale div { display: grid; justify-items: center; gap: 3px; }
  .color-swatch { width: 100%; height: 8px; }
}

@media (max-height: 620px) and (min-width: 721px) {
  .control-card { max-height: calc(100% - 24px); top: 12px; right: 12px; }
  .map-legend { left: 12px; bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

[hidden] { display: none !important; }

/* ======================= v2 — mapa nativo, timeline, comparação ======================= */
#mapa.map-frame { position: relative; z-index: 0; background: #eeeae6; }
.leaflet-container { font: inherit; background: #eeeae6; }

/* Modo de visualização */
.mode-block { margin-top: 14px; }
.seg { display: flex; background: #efe7e4; border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; font-size: 0.78rem; font-weight: 800; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.comp-picker { margin-top: 9px; font-size: 0.78rem; color: var(--muted); }
.comp-picker select { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; margin: 0 3px; background: #fff; color: var(--ink); }

/* Filtros */
.filtros-block { margin-top: 15px; }
.bloco-titulo { display: block; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); margin-bottom: 7px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--brand-dark); font-size: 0.75rem; font-weight: 750; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

/* Série histórica no card do município */
.hist-line { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-top: 15px; }
.hist-line div { padding: 9px 6px; border: 1px solid var(--line); border-radius: 11px; background: #fff; text-align: center; }
.hist-line div.on { border-color: var(--brand); background: var(--brand-soft); }
.hist-line dt { color: var(--muted); font-size: 0.66rem; margin-bottom: 3px; }
.hist-line dd { margin: 0; font-weight: 850; font-size: 0.95rem; }
.var-frase { margin: 12px 0 0; font-size: 0.83rem; font-weight: 700; line-height: 1.4; }
.var-frase.positive { color: #287a50; }
.var-frase.negative { color: #b13c36; }
.vote-badge.positive { background: #287a50; }
.vote-badge.negative { background: #b13c36; }

/* Rankings de variação */
.rank-wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; padding-top: 15px; border-top: 1px solid var(--line); }
.rank-col .bloco-titulo { margin-bottom: 5px; }
.rank-row { display: flex; justify-content: space-between; gap: 8px; width: 100%; padding: 6px 8px; border: 0; background: transparent; border-radius: 8px; font-size: 0.77rem; text-align: left; color: var(--ink); }
.rank-row:hover { background: var(--brand-soft); }
.rank-row .up { color: #287a50; font-weight: 800; }
.rank-row .down { color: #b13c36; font-weight: 800; }

/* Linha do tempo */
.timeline { position: absolute; z-index: 15; left: 50%; bottom: 18px; transform: translateX(-50%); display: flex; align-items: center; padding: 7px 12px; background: rgba(255, 253, 251, 0.96); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.tl-label { font-size: 0.68rem; color: var(--muted); font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; margin-right: 6px; }
.tl-stop { display: grid; justify-items: center; gap: 1px; border: 0; background: transparent; padding: 6px 14px; border-radius: 999px; line-height: 1; }
.tl-stop strong { font-size: 0.98rem; color: var(--ink); font-family: Georgia, serif; }
.tl-stop small { font-size: 0.58rem; letter-spacing: 0.04em; color: var(--muted); text-transform: uppercase; }
.tl-stop.on { background: var(--brand); }
.tl-stop.on strong, .tl-stop.on small { color: #fff; }
.tl-stop.comp { background: var(--brand-soft); }
.tl-stop.comp strong { color: var(--brand-dark); }
.tl-line { width: 20px; height: 2px; background: var(--line); }

/* Tooltip flutuante */
.map-tooltip { position: fixed; z-index: 1200; pointer-events: none; background: rgba(43, 30, 28, 0.95); color: #fff; padding: 8px 11px; border-radius: 10px; font-size: 0.82rem; line-height: 1.35; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3); max-width: 240px; opacity: 0; transition: opacity 0.12s; }
.map-tooltip.on { opacity: 1; }
.map-tooltip em { font-style: normal; }
.map-tooltip em.up { color: #8fe0c6; font-weight: 700; }
.map-tooltip em.down { color: #f6b3a9; font-weight: 700; }

@media (max-width: 720px) {
  .mode-block, .filtros-block { margin-top: 11px; }
  .rank-wrap { gap: 8px; }
  .map-legend { bottom: 78px; }
  .timeline { left: 8px; right: 8px; bottom: 12px; transform: none; justify-content: center; border-radius: 16px; padding: 6px 8px; }
  .tl-label { display: none; }
  .tl-stop { padding: 6px 12px; }
  .map-tooltip { max-width: calc(100vw - 24px); }
}
