/* Direção A — Placa de rua paulistana */
@font-face { font-family: 'Overpass'; src: url('/fonts/overpass-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Overpass'; src: url('/fonts/overpass-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'Overpass'; src: url('/fonts/overpass-latin-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Overpass'; src: url('/fonts/overpass-latin-800-normal.woff2') format('woff2'); font-weight: 800; font-display: swap; }

:root {
  /* placa: verde das placas rodoviárias de cidade */
  --enamel: #0b5c3e;
  --enamel-deep: #084630;
  --enamel-ink: #ffffff;
  --enamel-soft: #d3eadf;
  --enamel-line: rgba(255, 255, 255, 0.12);
  /* comando: grafite esverdeado */
  --deck: #111d1a;
  --deck-2: #182724;
  --deck-3: #22332f;
  --deck-ink: #eef3f0;
  --deck-muted: #a3b5ae;
  --deck-accent: #8cc3a6;
  --deck-on: #0d3f2c;
  /* um único degrau tonal frio para todos os neutros */
  --n0: #ffffff;
  --n1: #f4f6fa;
  --n2: #e8ecf3;
  --n3: #d2d9e4;
  --n4: #9ba6b8;
  --n5: #5b687c;
  --n6: #384356;
  --n7: #182131;
  /* estados do dado */
  --ver: #1d7a4e;
  --ver-bg: #e3f2ea;
  --est: #9a5b0d;
  --est-bg: #fbefd9;
  --unk: #5b687c;
  --unk-bg: #eceff4;
  /* tintas do mapa lidas pelo núcleo */
  --map-select: #0f1d19;
  --map-hover: #182131;
  --map-context: #5b687c;
  --map-stroke: #ffffff;
  --chrome: #111d1a;
  --nodata: #c5c9ce;
  --map-ground: #dfe3e9;
  --tiles: grayscale(1) contrast(0.88) brightness(1.06);
  --pill-bg: var(--n7);
  --pill-ink: #ffffff;
  --pill-muted: #d6deea;
  --ghost: rgba(24, 33, 49, 0.55);
  --attrib-bg: rgba(255, 255, 255, 0.86);
  --error-bg: #ffffff;
  --error-ink: #8a1c1c;

  --font: 'Overpass', 'Segoe UI', system-ui, sans-serif;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --inspector-w: 400px;
  --shadow-float: 0 6px 18px -6px rgba(8, 18, 15, 0.28), 0 1px 3px rgba(8, 18, 15, 0.12);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--n7);
  background: var(--n1);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}
::selection { background: var(--enamel); color: var(--enamel-ink); }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--enamel); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
svg.lucide { width: 18px; height: 18px; flex: none; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--inspector-w);
  height: 100dvh;
}

/* ---------- Mapa ---------- */
.stage { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: var(--map-ground); }
.leaflet-container { font-family: var(--font); }
.leaflet-tile-pane { filter: var(--tiles); }
.leaflet-control-attribution { font-size: 10.5px; background: var(--attrib-bg) !important; color: var(--n5); }
.leaflet-control-attribution a { color: var(--n6); }
.leaflet-bar { border: 0 !important; box-shadow: var(--shadow-float) !important; border-radius: var(--r-md) !important; overflow: hidden; }
.leaflet-bar a { width: 36px !important; height: 36px !important; line-height: 34px !important; color: var(--n7) !important; font-weight: 600; }
.leaflet-bar a:hover { background: var(--n1) !important; }
.leaflet-control-zoom { margin-right: 16px !important; margin-bottom: 64px !important; }

.map-reset {
  position: absolute; right: 16px; bottom: 148px; z-index: 800;
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 0; border-radius: var(--r-md); background: var(--n0); color: var(--n7);
  box-shadow: var(--shadow-float);
}
.map-reset:hover { background: var(--n1); }

/* ---------- Bloco de comando (casca azul) ---------- */
.command {
  position: absolute; z-index: 900; top: 16px; left: 16px;
  width: 392px;
  background: var(--deck);
  color: var(--deck-ink);
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 18px 40px -18px rgba(8, 20, 16, 0.7), 0 2px 6px rgba(8, 20, 16, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: grid; gap: 10px;
}
.command > * { position: relative; z-index: 1; }
.command-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 0 6px; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }

.brand-text { display: grid; gap: 1px; min-width: 0; }
.brand-line { display: flex; align-items: baseline; gap: 0; white-space: nowrap; }
.brand-tag { font-size: 12.5px; font-weight: 600; color: var(--deck-muted); letter-spacing: 0.005em; }
.brand-name { font-weight: 800; font-size: 18px; line-height: 1.15; letter-spacing: 0.005em; }
.brand-scope { font-weight: 600; font-size: 18px; line-height: 1.15; color: var(--deck-muted); margin-left: 0.3em; }
.brand-by { margin-left: 10px; padding-left: 10px; border-left: 1px solid rgba(255, 255, 255, 0.18); font-size: 12px; font-weight: 600; line-height: 1; color: var(--deck-muted); letter-spacing: 0.01em; align-self: center; }
.command-tools { display: flex; gap: 2px; }
.tool {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--r-md); background: transparent; color: inherit;
}
.command .tool { color: var(--deck-muted); }
.command .tool:hover { background: var(--deck-2); color: var(--deck-ink); }
.command :focus-visible { outline-color: #fff; }

.search-box {
  position: relative; display: flex; align-items: center;
  height: 44px; background: var(--n0); color: var(--n7);
  border-radius: 10px;
  padding: 0 4px 0 10px; gap: 2px;
}
.search-ico { color: var(--n5); width: 18px; height: 18px; }
.search-box input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent;
  padding: 2px 4px 0; font-size: 14.5px;
}
.search-box input::placeholder { color: var(--n5); }
.search-box input::-webkit-search-cancel-button { display: none; }
.search-box:focus-within { box-shadow: 0 0 0 2px var(--deck-accent); }
.command .search-box { z-index: 5; }
.field-btn, .field-go {
  display: grid; place-items: center; width: 34px; height: 36px; flex: none;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--n6);
}
.field-btn:hover { background: var(--n2); }
.field-go { background: var(--deck-on); color: #fff; border-radius: 7px; }
.field-go:hover { background: #0a3324; }
.search-box :focus-visible { outline-color: var(--enamel); }

.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 1000;
  background: var(--n0); color: var(--n7); border-radius: var(--r-md);
  box-shadow: 0 16px 36px -12px rgba(8, 18, 15, 0.4), 0 1px 3px rgba(8, 18, 15, 0.15);
  padding: 4px; max-height: min(60vh, 420px); overflow-y: auto;
}
.search-result {
  display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; border: 0; border-radius: var(--r-sm); background: transparent; text-align: left;
}
.search-result:hover, .search-result.active { background: var(--n1); }
.search-result .ico { color: var(--n5); width: 17px; height: 17px; }
.search-result.geocode .ico { color: var(--enamel); }
.r-main { display: grid; min-width: 0; }
.r-main strong { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-main small { color: var(--n5); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.r-kind { font-size: 11.5px; font-weight: 700; color: var(--n5); text-transform: uppercase; letter-spacing: 0.04em; }
.search-result.geocode { border-bottom: 1px solid var(--n2); border-radius: var(--r-sm) var(--r-sm) 0 0; margin-bottom: 2px; }
.search-message { padding: 12px; color: var(--n6); font-size: 13.5px; }

/* Duas faces: Renda / Segurança */
.faces {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.faces button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--deck-muted);
  font-weight: 700; font-size: 14.5px;
  transition: background-color 0.18s var(--ease-out), color 0.18s var(--ease-out);
}
.faces button:hover { background: var(--deck-3); color: var(--deck-ink); }
.faces button[aria-pressed='true'] { background: var(--deck-on); color: #fff; border-color: rgba(255, 255, 255, 0.08); }

.metric-row { display: flex; }
.seg {
  display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%;
  background: var(--deck-2); border-radius: 10px; padding: 3px; gap: 3px;
}
.seg button {
  height: 32px; border: 0; border-radius: 7px; background: transparent;
  color: var(--deck-muted); font-weight: 600; font-size: 13px; padding: 2px 10px 0;
}
.seg button:hover { color: #fff; }
.seg button[aria-pressed='true'] { background: var(--deck-3); color: #fff; }

.crumbs {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 2px;
  padding: 8px 4px 2px; border-top: 1px solid var(--enamel-line);
  font-size: 13px;
}
.crumbs > button {
  border: 0; background: transparent; color: var(--deck-muted); padding: 4px 6px 2px; border-radius: var(--r-sm); font-weight: 600;
}
.crumbs > button:hover { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.crumbs > button[aria-current='page'] { color: #fff; font-weight: 800; }
.crumb-sep { width: 6px; height: 6px; border-right: 1.5px solid var(--deck-muted); border-top: 1.5px solid var(--deck-muted); transform: rotate(45deg); margin: 0 4px; opacity: 0.8; }
.crumb-levels { display: inline-flex; gap: 4px; margin-left: 4px; }
.crumb-levels button {
  border: 1px solid rgba(255, 255, 255, 0.16); background: var(--deck-2); color: var(--deck-ink);
  height: 28px; padding: 2px 10px 0; border-radius: 14px; font-size: 12.5px; font-weight: 700;
}
.crumb-levels button[aria-pressed='true'] { background: var(--deck-on); color: #fff; border-color: rgba(255, 255, 255, 0.12); }
.crumb-levels button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- Legenda ---------- */
.legend {
  position: absolute; z-index: 800; left: 16px; bottom: 28px; width: 392px;
  background: var(--n0); border-radius: var(--r-lg); padding: 12px 16px 12px;
  box-shadow: var(--shadow-float);
}
.legend-head h2 { margin: 0; font-size: 14px; font-weight: 800; line-height: 1.25; }
.legend-head p { margin: 2px 0 0; color: var(--n5); font-size: 12.5px; }
.legend-note { margin: 6px 0 0; color: var(--n5); font-size: 12px; }
.legend-bands { list-style: none; margin: 10px 0 0; padding: 0; display: grid; grid-template-columns: repeat(6, auto); gap: 6px 10px; font-size: 12px; color: var(--n6); }
.legend-bands li { display: grid; gap: 4px; }
.legend-bands i { display: block; height: 10px; border-radius: 2px; }
.legend-bands .nodata i { background: var(--nodata); }
.legend-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 0; margin-top: 10px; background: var(--n1); border-radius: var(--r-md); padding: 3px; }
.legend-toggle button { height: 30px; border: 0; border-radius: var(--r-sm); background: transparent; font-weight: 700; font-size: 12.5px; color: var(--n5); padding-top: 2px; }
.legend-opacity { display: grid; grid-template-columns: auto 1fr 40px; align-items: center; gap: 10px; margin-top: 10px; font-size: 12.5px; color: var(--n6); font-weight: 600; }
.legend-opacity output { text-align: right; font-weight: 800; color: var(--n7); }
.legend-opacity input[type='range'] { width: 100%; accent-color: var(--deck-on); height: 24px; margin: 0; cursor: pointer; }
.legend-toggle button[aria-pressed='true'] { background: var(--n0); color: var(--n7); box-shadow: 0 1px 2px rgba(8, 18, 15, 0.16); }

/* ---------- Régua de percentis ---------- */
.ruler-wrap { margin-top: 10px; }
.ruler { position: relative; height: 46px; margin: 0 6px; }
.ruler-track { position: absolute; left: 0; right: 0; top: 18px; height: 10px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(8, 18, 15, 0.08); }
.tick { position: absolute; top: 28px; width: 0; height: 18px; }
.tick::before { content: ''; position: absolute; left: -0.5px; top: 0; width: 1px; height: 4px; background: var(--n4); }
.tick em { position: absolute; top: 5px; left: 0; transform: translateX(-50%); font-style: normal; font-size: 11px; color: var(--n5); font-weight: 600; }
.mk { position: absolute; top: 12px; width: 0; height: 22px; }
.mk::before { content: ''; position: absolute; left: -2px; top: 0; width: 4px; height: 22px; border-radius: 2px; background: var(--n7); box-shadow: 0 0 0 1.5px #fff; }
.mk b { position: absolute; bottom: 24px; left: 0; transform: translateX(-50%); font-size: 12px; font-weight: 800; background: var(--pill-bg); color: var(--pill-ink); padding: 1px 5px 0; border-radius: 3px; white-space: nowrap; }
.mk-ref::before { background: #fff; box-shadow: inset 0 0 0 2px var(--enamel), 0 0 0 1px #fff; width: 6px; left: -3px; }
.mk-ref b { bottom: auto; top: 48px; background: #fff; color: var(--enamel); box-shadow: inset 0 0 0 1.5px var(--enamel); }
.mk-cur::before { background: var(--enamel); }
.mk-cur b { background: var(--enamel); }
.ruler:has(.mk-ref) { margin-bottom: 34px; }
.mk-ghost::before { background: var(--ghost); box-shadow: none; width: 2px; left: -1px; }
.ruler-hover { margin: 4px 6px 0; font-size: 12px; color: var(--n6); }
.ruler-wrap.compact .ruler { height: 40px; }
.legend .ruler { height: 40px; }
.legend .ruler-track { top: 6px; height: 12px; }
.legend .tick { top: 18px; }

/* ---------- Inspetor ---------- */
.inspector {
  position: relative; display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0;
  background: var(--n0); border-left: 1px solid var(--n3);
  z-index: 950;
}
.sheet-handle { display: none; }
.inspector-body { overflow-y: auto; padding: 18px 20px 24px; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--n3) transparent; }
.inspector-body > * + * { margin-top: 16px; }

.place {
  position: relative; background: var(--enamel); color: #fff; border-radius: var(--r-lg);
  padding: 14px 16px 10px;
  box-shadow: 0 1px 0 rgba(8, 18, 15, 0.2);
}
.place::after { content: ''; position: absolute; inset: 4px; border: 1.5px solid rgba(255, 255, 255, 0.85); border-radius: 7px; pointer-events: none; }
.place-name {
  margin: 0; font-size: 24px; line-height: 1.12; font-weight: 800; letter-spacing: 0.01em; text-transform: uppercase;
  overflow-wrap: anywhere; text-wrap: balance; padding: 2px 2px 0;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.place-band {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin: 10px 0 0; padding: 7px 2px 0; border-top: 1.5px solid rgba(255, 255, 255, 0.85);
  font-size: 12.5px; font-weight: 600; color: #e3ebf8;
}
.place-band span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-code { flex: none; font-weight: 800; color: #fff; letter-spacing: 0.02em; }

.btn-back {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--n5);
  font-weight: 700; font-size: 13px; padding: 4px 6px 2px 2px; border-radius: var(--r-sm); margin-left: -2px;
}
.btn-back:hover { color: var(--enamel); }
.btn-back .ico { width: 16px; height: 16px; }
.btn-back + .place { margin-top: 8px; }

.reading { padding: 2px 2px 0; }
.reading + .reading { border-top: 1px solid var(--n2); padding-top: 16px; }
.reading-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.reading-head h3 { margin: 0; font-size: 13.5px; font-weight: 700; color: var(--n6); }
.reading-value { margin: 6px 0 0; display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.reading-value strong { font-size: 34px; line-height: 1.05; font-weight: 800; letter-spacing: -0.01em; }
.reading-value span { color: var(--n5); font-size: 13px; }
.reading-pos { margin: 6px 0 0; color: var(--n6); font-size: 14px; }
.reading-pos strong { color: var(--n7); }

.state {
  display: inline; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  white-space: nowrap; background: none !important; padding: 0; border-radius: 0;
}
.summary { margin-bottom: 0; font-size: 14px; line-height: 1.55; color: var(--n6); max-width: 46ch; }
.summary strong { color: var(--n7); font-weight: 800; }
.summary .state { margin-left: 2px; }
.state i { width: 7px; height: 7px; border-radius: 50%; margin-top: -1px; }
.state-ver { background: var(--ver-bg); color: var(--ver); }
.state-ver i { background: var(--ver); }
.state-est { background: var(--est-bg); color: var(--est); }
.state-est i { border: 1.5px solid var(--est); background: linear-gradient(90deg, var(--est) 50%, transparent 50%); }
.state-unk { background: var(--unk-bg); color: var(--unk); }
.state-unk i { border: 1.5px solid var(--unk); }

.actions { display: grid; gap: 8px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; width: 100%;
  border-radius: var(--r-md); font-weight: 800; font-size: 14px; padding: 2px 14px 0;
  transition: background-color 0.16s var(--ease-out);
}
.btn-primary { border: 0; background: var(--enamel); color: #fff; }
.btn-primary:hover { background: var(--enamel-deep); }
.btn-quiet { border: 1.5px solid var(--n3); background: var(--n0); color: var(--n7); }
.btn-quiet:hover { border-color: var(--enamel); color: var(--enamel); }
.btn-link { border: 0; background: transparent; color: var(--enamel); font-weight: 700; font-size: 12.5px; padding: 2px 0 0; text-decoration: underline; text-underline-offset: 3px; }

.facts { margin: 0; display: grid; border-top: 1px solid var(--n2); }
.facts > div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 8px 2px; border-bottom: 1px solid var(--n2); }
.facts dt { color: var(--n5); font-size: 13px; }
.facts dd { margin: 0; font-weight: 700; text-align: right; white-space: nowrap; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 4px; vertical-align: 1px; }
.dot-ver { background: var(--ver); }
.dot-est { border: 1.5px solid var(--est); background: linear-gradient(90deg, var(--est) 50%, transparent 50%); }
.dot-unk { border: 1.5px solid var(--unk); }

.compare { background: var(--n1); border-radius: var(--r-lg); padding: 12px 14px; }
.compare-empty { display: grid; gap: 8px; }
.compare-empty p { margin: 0; font-size: 12.5px; color: var(--n5); }
.compare-head { display: flex; justify-content: space-between; align-items: baseline; }
.compare-head h3 { margin: 0; font-size: 13.5px; font-weight: 800; }
.compare table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.compare th, .compare td { padding: 5px 0; text-align: right; }
.compare thead th { font-size: 11.5px; color: var(--n5); font-weight: 700; }
.compare tbody th { text-align: left; font-weight: 700; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare td { padding-left: 10px; white-space: nowrap; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.key-cur { background: var(--enamel); }
.key-ref { background: #fff; box-shadow: inset 0 0 0 2px var(--enamel); }
.compare-delta { margin: 4px 0 0; font-size: 13px; color: var(--n6); }
.compare-delta strong { font-size: 18px; color: var(--n7); font-weight: 800; }

.note { margin: 0; color: var(--n5); font-size: 12.5px; line-height: 1.5; max-width: 62ch; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stats div { display: grid; align-content: start; justify-items: start; gap: 5px; padding: 2px; }
.stats strong { font-size: 26px; font-weight: 800; line-height: 1; }
.stats span { color: var(--n5); font-size: 12.5px; }

.rank-head, .dist .rank-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px 6px; border-bottom: 1.5px solid var(--n7); }
.rank-head h3 { margin: 0; font-size: 13.5px; font-weight: 800; }
.rank-head span { font-size: 11.5px; color: var(--n5); font-weight: 600; }
.rank ol { list-style: none; margin: 0; padding: 0; }
.rank li button {
  display: grid; grid-template-columns: 18px 10px minmax(0, 1fr) auto 52px; align-items: center; gap: 8px;
  width: 100%; padding: 7px 2px; border: 0; border-bottom: 1px solid var(--n2); background: transparent; text-align: left; font-size: 13.5px;
}
.rank li button:hover { background: var(--n1); }
.rank-n { color: var(--n4); font-size: 11.5px; font-weight: 700; }
.sw { width: 10px; height: 10px; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(8, 18, 15, 0.12); }
.rank-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { font-weight: 600; color: var(--n6); }
.rank-pct { text-align: right; color: var(--n5); font-size: 12.5px; }

.dist ul { list-style: none; margin: 0; padding: 0; }
.dist li { display: grid; grid-template-columns: 88px 1fr 48px; align-items: center; gap: 10px; padding: 6px 2px; border-bottom: 1px solid var(--n2); font-size: 13px; }
.dist-label { color: var(--n6); font-weight: 600; }
.dist-bar { height: 10px; background: var(--n1); border-radius: 2px; overflow: hidden; }
.dist-bar i { display: block; height: 100%; }
.dist-n { text-align: right; font-weight: 700; }

.source-line {
  display: grid; gap: 3px; padding: 10px 20px 12px; border-top: 1px solid var(--n3); background: var(--n1);
  font-size: 12px; color: var(--n6);
}
.source-line span { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; }
.source-line b { font-weight: 800; color: var(--n7); min-width: 66px; }
.source-line .state { font-size: 10.5px; }

/* ---------- Estados do mapa ---------- */
.map-status {
  position: absolute; z-index: 850; top: 16px; left: 50%; transform: translateX(-50%);
  margin-left: 204px;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px 6px; border-radius: 18px;
  background: var(--pill-bg); color: var(--pill-ink); font-weight: 700; font-size: 13px; box-shadow: var(--shadow-float); overflow: hidden;
}
.map-status .bar { display: none; }
.map-status.error { background: #8a1c1c; }
.map-error {
  position: absolute; z-index: 850; top: 64px; left: 50%; transform: translateX(-50%); margin-left: 204px;
  display: flex; gap: 8px; align-items: center; max-width: 420px; padding: 10px 14px; border-radius: var(--r-md);
  background: var(--error-bg); color: var(--error-ink); font-weight: 600; box-shadow: var(--shadow-float);
}

.hover-chip {
  position: absolute; z-index: 860; left: 0; top: 0; pointer-events: none;
  display: grid; gap: 1px; max-width: 280px; padding: 8px 10px 6px; border-radius: var(--r-md);
  background: var(--pill-bg); color: var(--pill-ink); font-size: 12.5px; box-shadow: var(--shadow-float);
}
.hover-chip strong { font-size: 13.5px; font-weight: 800; }
.hover-chip span { color: var(--pill-muted); }
.hover-chip .chip-delta { color: var(--pill-ink); font-weight: 700; margin-top: 2px; padding-top: 3px; border-top: 1px solid rgba(255, 255, 255, 0.2); }

.location-icon { background: none; border: 0; }
.loc-pin {
  width: 26px; height: 26px; border-radius: 6px; background: var(--enamel);
  box-shadow: 0 0 0 2px #fff, 0 4px 10px rgba(8, 18, 15, 0.5); display: grid; place-items: center;
}
.loc-pin span { width: 16px; height: 16px; border: 1.5px solid #fff; border-radius: 3px; }

/* ---------- Metodologia ---------- */
.method {
  width: min(560px, 100vw); max-width: none; height: 100dvh; max-height: none; margin: 0 0 0 auto;
  padding: 0; border: 0; background: var(--n0); color: var(--n7); box-shadow: -18px 0 40px -20px rgba(8, 18, 15, 0.5);
}
.method[open] { display: grid; grid-template-rows: auto 1fr; animation: drawer 0.24s var(--ease-out); }
@keyframes drawer { from { transform: translateX(32px); opacity: 0.4; } to { transform: none; opacity: 1; } }
.method::backdrop { background: rgba(8, 18, 15, 0.38); }
.method-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 14px; background: var(--deck); color: #fff; }
.method-head h2 { margin: 0; font-size: 20px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.02em; }
.method-head .tool:hover { background: rgba(255, 255, 255, 0.14); }
.method-body { overflow-y: auto; padding: 8px 24px 32px; }
.method-body section { padding: 14px 0; border-bottom: 1px solid var(--n2); }
.method-body h3 { margin: 0 0 4px; font-size: 16px; font-weight: 800; }
.method-body p { margin: 0; color: var(--n6); line-height: 1.6; max-width: 68ch; }
.method-body .warn { background: var(--est-bg); margin: 12px -12px; padding: 14px 12px; border-radius: var(--r-md); border: 0; }
.hash { font-size: 12px; overflow-wrap: anywhere; }

.skeleton { height: 120px; border-radius: var(--r-lg); background: linear-gradient(90deg, var(--n1), var(--n2), var(--n1)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Alternância de esquema ---------- */
.scheme-toggle .when-dark { display: none; }
:root[data-scheme='dark'] .scheme-toggle .when-light { display: none; }
:root[data-scheme='dark'] .scheme-toggle .when-dark { display: contents; }
.scheme-toggle span { display: contents; }
:root[data-scheme='dark'] .scheme-toggle .when-light { display: none; }

/* ---------- Modo escuro ---------- */
:root[data-scheme='dark'] {
  color-scheme: dark;
  --n0: #111a17;
  --n1: #0c1412;
  --n2: #1c2824;
  --n3: #2a3833;
  --n4: #6f837c;
  --n5: #9aaea7;
  --n6: #c1cfca;
  --n7: #ecf3ef;
  --ver: #8cc3a6;
  --ver-bg: transparent;
  --est: #f1b862;
  --est-bg: rgba(241, 184, 98, 0.14);
  --unk: #9aaea7;
  --unk-bg: rgba(154, 174, 167, 0.14);
  --deck: #121d1a;
  --deck-2: #1a2824;
  --deck-3: #24342f;
  --chrome: #0c1412;
  --map-select: #ffffff;
  --map-hover: #ecf3ef;
  --map-context: #8ea39b;
  --map-stroke: #0c1412;
  --nodata: #39433f;
  --map-ground: #1a2421;
  --tiles: grayscale(1) invert(1) brightness(0.78) contrast(1.12);
  --pill-bg: #ecf3ef;
  --pill-ink: #0c1412;
  --pill-muted: #3d4f49;
  --ghost: rgba(236, 243, 239, 0.6);
  --attrib-bg: rgba(12, 20, 18, 0.82);
  --error-bg: #2a1416;
  --error-ink: #ff9a9a;
  --shadow-float: 0 8px 22px -8px rgba(0, 0, 0, 0.7), 0 1px 3px rgba(0, 0, 0, 0.5);
}
:root[data-scheme='dark'] .command { border-color: rgba(255, 255, 255, 0.08); box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.85), 0 0 0 1px rgba(0, 0, 0, 0.4); }
:root[data-scheme='dark'] .search-box { background: #0b1311; color: var(--n7); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1); }
:root[data-scheme='dark'] .search-box:focus-within { box-shadow: inset 0 0 0 1px var(--deck-accent); }
:root[data-scheme='dark'] .field-btn:hover { background: var(--n2); }
:root[data-scheme='dark'] .search-results { background: var(--n0); box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.8), 0 0 0 1px var(--n3); }
:root[data-scheme='dark'] .search-result:hover, :root[data-scheme='dark'] .search-result.active { background: var(--n2); }
:root[data-scheme='dark'] .search-result.geocode .ico { color: var(--deck-accent); }
:root[data-scheme='dark'] .leaflet-bar a { background: var(--n0) !important; border-bottom-color: var(--n3) !important; }
:root[data-scheme='dark'] .leaflet-bar a:hover { background: var(--n2) !important; }
:root[data-scheme='dark'] .leaflet-control-attribution a { color: var(--n6); }
:root[data-scheme='dark'] .legend, :root[data-scheme='dark'] .map-reset { box-shadow: var(--shadow-float), 0 0 0 1px var(--n3); }
:root[data-scheme='dark'] .legend-toggle { background: var(--n1); }
:root[data-scheme='dark'] .legend-toggle button[aria-pressed='true'] { background: var(--n3); color: var(--n7); box-shadow: none; }
:root[data-scheme='dark'] .legend-opacity input[type='range'] { accent-color: var(--deck-accent); }
:root[data-scheme='dark'] .ruler-track { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08); }
:root[data-scheme='dark'] .mk::before { box-shadow: 0 0 0 1.5px var(--n0); }
:root[data-scheme='dark'] .mk-cur::before { background: var(--deck-accent); }
:root[data-scheme='dark'] .mk-cur b { background: var(--enamel); color: #fff; }
:root[data-scheme='dark'] .mk-ref::before { background: var(--n0); box-shadow: inset 0 0 0 2px var(--deck-accent), 0 0 0 1px var(--n0); }
:root[data-scheme='dark'] .mk-ref b { background: var(--n0); color: var(--deck-accent); box-shadow: inset 0 0 0 1.5px var(--deck-accent); }
:root[data-scheme='dark'] .key-cur { background: var(--deck-accent); }
:root[data-scheme='dark'] .key-ref { background: transparent; box-shadow: inset 0 0 0 2px var(--deck-accent); }
:root[data-scheme='dark'] .place { box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06); }
:root[data-scheme='dark'] .btn-back:hover, :root[data-scheme='dark'] .btn-link { color: var(--deck-accent); }
:root[data-scheme='dark'] .btn-quiet:hover { border-color: var(--deck-accent); color: var(--deck-accent); }
:root[data-scheme='dark'] .rank-head { border-bottom-color: var(--n6); }
:root[data-scheme='dark'] .sw { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12); }
:root[data-scheme='dark'] .inspector { border-left-color: var(--n2); }
:root[data-scheme='dark'] .source-line { border-top-color: var(--n2); }
:root[data-scheme='dark'] .loc-pin { box-shadow: 0 0 0 2px #fff, 0 0 0 4px rgba(0, 0, 0, 0.6), 0 4px 10px rgba(0, 0, 0, 0.6); }
:root[data-scheme='dark'] .method::backdrop { background: rgba(0, 0, 0, 0.6); }
:root[data-scheme='dark'] ::selection { background: var(--deck-accent); color: #0c1412; }
:root[data-scheme='dark'] :focus-visible { outline-color: var(--deck-accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- Telas médias ---------- */
@media (max-width: 1180px) and (min-width: 761px) {
  :root { --inspector-w: 360px; }
  .command, .legend { width: 344px; }
  .map-status, .map-error { margin-left: 180px; }
}

/* ---------- Celular: mapa dominante + folha inferior ---------- */
@media (max-width: 760px) {
  body { font-size: 14px; }
  .app { display: block; height: 100dvh; }
  .stage { position: absolute; inset: 0; }
  .command {
    top: 0; left: 0; right: 0; width: auto; border-radius: 0 0 var(--r-lg) var(--r-lg);
    padding: calc(8px + env(safe-area-inset-top)) 10px 8px; gap: 8px;
  }
  .command::after { display: none; }
  .command-top { padding: 0 2px; }
  .brand-name { font-size: 17px; }

  .brand-tag { font-size: 12px; }
  .search-box input { font-size: 14px; padding-left: 4px; }
  .tool { width: 40px; height: 40px; }
  .faces { grid-template-columns: 1fr 1fr; }
  .faces button { height: 40px; font-size: 13px; }
  .metric-row { display: none; }
  body[data-theme='renda'] .metric-row:has(#income-metric-group:not([hidden])),
  body[data-theme='seguranca'][data-level='municipio'] .metric-row { display: flex; }
  .seg button { height: 32px; }
  .crumbs { flex-wrap: nowrap; overflow-x: auto; padding: 6px 2px 0; scrollbar-width: none; }
  .crumbs > button, .crumb-levels button { flex: none; white-space: nowrap; }
  .crumbs::-webkit-scrollbar { display: none; }

  .legend {
    left: 8px; right: 8px; width: auto; bottom: calc(var(--sheet-peek) + 22px);
    padding: 8px 12px 6px; border-radius: var(--r-md);
  }
  .legend-head p, .legend-note { display: none; }
  .legend-head h2 { font-size: 12.5px; }
  .legend .ruler-wrap { margin-top: 4px; }
  .legend-bands { margin-top: 6px; grid-template-columns: repeat(3, 1fr); font-size: 11px; gap: 4px 8px; }
  .legend-toggle { margin-top: 6px; }
  .legend-toggle button { height: 30px; }

  .leaflet-control-zoom { display: none; }
  .map-reset { top: auto; bottom: calc(var(--sheet-peek) + 132px); right: 10px; }
  body[data-level='zona_seguranca'] .map-reset { bottom: calc(var(--sheet-peek) + 196px); }
  .map-status, .map-error { margin-left: 0; top: auto; bottom: calc(var(--sheet-peek) + 140px); white-space: nowrap; max-width: calc(100vw - 32px); }

  :root { --sheet-peek: 156px; }
  .inspector {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
    height: var(--sheet-peek); border: 0; border-radius: 14px 14px 0 0;
    box-shadow: 0 -10px 28px -10px rgba(8, 18, 15, 0.4);
    transition: height 0.26s var(--ease-out);
    grid-template-rows: 22px 1fr;
  }
  .inspector[data-sheet='half'] { height: 48dvh; }
  .inspector[data-sheet='full'] { height: calc(100dvh - 64px); }
  .sheet-handle { display: grid; place-items: center; height: 22px; border: 0; background: transparent; touch-action: none; }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 2px; background: var(--n3); }
  .inspector-body { padding: 4px 14px 20px; }
  .inspector[data-sheet='peek'] .inspector-body { overflow: hidden; }
  .source-line { display: none; }
  .inspector[data-sheet='full'] .source-line, .inspector[data-sheet='half'] .source-line { display: grid; padding: 8px 14px calc(10px + env(safe-area-inset-bottom)); }
  .inspector[data-sheet='half'], .inspector[data-sheet='full'] { grid-template-rows: 22px minmax(0, 1fr) auto; }
  .inspector-body { display: flex; flex-direction: column; }
  .inspector-body > .place { order: -2; }
  .inspector-body > .btn-back { order: -1; margin-top: 8px; align-self: flex-start; }
  .btn-back + .place { margin-top: 0; }
  .leaflet-bottom.leaflet-right { bottom: var(--sheet-peek); }
  .leaflet-control-attribution { font-size: 9.5px; }
  .place { padding: 10px 12px 8px; }
  .place-name { font-size: 19px; -webkit-line-clamp: 2; }
  .place-band { margin-top: 6px; padding-top: 5px; font-size: 12px; }
  .btn-back + .place { margin-top: 4px; }
  .reading-value strong { font-size: 28px; }
  .rank li button { grid-template-columns: 16px 10px minmax(0, 1fr) auto 46px; }
  .method { width: 100vw; }
}
.facts dt .state { margin-left: 6px; font-size: 10px; }

.search-note { margin-top: 2px; padding: 8px 10px 6px; border-top: 1px solid var(--n2); font-size: 11.5px; line-height: 1.4; color: var(--n5); }
.source-line .legal { margin-top: 3px; padding-top: 5px; border-top: 1px solid var(--n3); font-size: 11.5px; color: var(--n5); }
.source-line .legal a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
