:root {
  /* ── Panel UI ── */
  --panel-bg: #ffffff;
  --panel-border: #e8e4dd;
  --surface: #f7f5f2;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --text-muted: #757575; /* antes #aaa (2.3:1); #757575 cumple WCAG AA (4.6:1) sobre blanco */
  --accent: #2d6a00;
  --radius: 16px;
  --panel-width: 380px;
  --font: "Plus Jakarta Sans", sans-serif;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.1), 0 1px 4px rgba(0, 0, 0, 0.06);

  /* ── Mapa: escala de 6 clases (todas las capas) ─────────────────────────
     Para densidad: <3,315 (p50) · 6k · 12k · 24k · 48k hab/mi²              */
  --escala-0: #dedede;
  --escala-1: #b4b4b4;
  --escala-2: #8c8c8c;
  --escala-3: #646464;
  --escala-4: #3e3e3e;
  --escala-5: #1a1a1a;
  --density-excluded: #ffffff; /* "mayormente sin edificar" — no activa el lente */
  --nodata-fill: #f3efe8;      /* sin datos: tono cálido + borde punteado */

  /* ── Mapa: opacidad base del fill de densidad ── */
  --density-fill-opacity: 0.7;

  /* ── Mapa: bordes base de block groups ── */
  --density-stroke: rgba(0, 0, 0, 0.22);
  --density-stroke-weight: 0.6;
  --density-stroke-opacity: 1;

  /* ── Mapa: bordes de municipios ── */
  --muni-stroke: #111111;
  --muni-stroke-weight: 2;
  --muni-stroke-opacity: 0.75;

  /* ── Mapa: estado lente (bloques incluidos) — un solo color ─────────────
     El percentil del sector se comunica en texto, no con el color del lente */
  --lente-fill: #3d7a00;
  --lente-fill-opacity: 0.8;
  --lente-stroke: #1a4000;
  --lente-weight: 0.8;

  /* ── Mapa: estado hover (bloque bajo el cursor) ── */
  --hover-fill: #1f4d00;
  --hover-fill-opacity: 0.9;
  --hover-stroke: #0a1a00;
  --hover-weight: 0.8;

  /* ── Mapa: estado lockeado (click fijado) ── */
  --lock-fill: #0f2e00;
  --lock-fill-opacity: 0.95;
  --lock-stroke: #000000;
  --lock-weight: 2.5;

  /* ── Mapa: estado warning (densidad baja) ── */
  --warn-fill: #a90d0d;
  --warn-fill-opacity: 0.9;
  --warn-stroke: #850a0a;
  --warn-weight: 1;

  /* ── Borde de census tract (SVG overlay) ── */
  --tract-stroke: rgba(0, 0, 0, 0.85);
  --tract-stroke-weight: 2.5;
  --tract-hatch: rgba(0, 0, 0, 0.3);

  /* ── Mapa de fondo (sin tiles raster) ── */
  --agua: #e4eaec;            /* fondo del mapa = mar */
  --tierra: #fbfaf8;          /* isla debajo de la densidad */

  /* ── Huellas de edificios encima de la densidad (Stadia · OpenMapTiles) ── */
  --edificios-fill: #2b2b2b;
  --edificios-opacity: 0.45;  /* visibles desde zoom 14 */

  /* ── Histograma ── */
  --hist-bar-active: #2d6a00;
  --hist-bar-inactive: #d0cbc4;
  --hist-marker: #0f2e00;

  /* ── Lente apagado: azul equivalente al verde (misma luminosidad) ── */
  --hover-fill-off: #00334d;
  --hover-stroke-off: #001a26;
  --lock-fill-off: #001f30;
  --lock-stroke-off: #000d14;
}

[hidden] {
  display: none !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
}

/* ── Layout: barra lateral fija a la izquierda + mapa a la derecha ── */
#map {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--panel-width);
  z-index: 1;
}

#panel {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--panel-width);
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  z-index: 1000;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.06);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Detalles del Censo: una sola columna dentro del scroll del panel */
#details-body {
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--panel-border);
}
#details-body.visible {
  display: block;
}

/* ── Header ── */
#panel-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel-bg);
  flex-shrink: 0;
  padding: 15px 18px 11px;
  border-bottom: 1px solid var(--panel-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
h1 {
  font-family: var(--font);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.03em;
}
.subtitle {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
  font-weight: 500;
}

/* ── Main block (always visible) ── */
#main-block {
  padding: 12px 18px 14px;
  border-bottom: 1px solid var(--panel-border);
}

/* Slider */
#pop-control label {
  display: block;
  margin-bottom: 0;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}
#pop-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
#pop-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(45, 106, 0, 0.12);
  transition: box-shadow 0.15s;
}
#pop-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 6px rgba(45, 106, 0, 0.18);
}
#pop-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
}
#slider-labels {
  position: relative;
  height: 14px;
  margin: 5px 9px 0;
  font-size: 10px;
  color: var(--text-muted);
}
#slider-labels span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

/* Numbers row */
#result-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  margin-top: 14px;
}
.result-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result-col-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
}
.big-number {
  font-family: var(--font);
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
  white-space: nowrap;
}
#area-big {
  color: var(--accent);
}
#dens-big {
  color: var(--text-primary);
}
.result-col-right {
  text-align: right;
}
.big-number .area-unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0;
}
.result-divider {
  width: 1px;
  height: 36px;
  background: var(--panel-border);
  flex-shrink: 0;
  align-self: center;
}

/* ── Result details (valid state only) ── */
#result-details {
  padding: 12px 18px;
  border-bottom: 1px solid var(--panel-border);
}

#insight {
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text-secondary);
}
#insight b {
  color: var(--text-primary);
  font-weight: 600;
}
#insight .nota {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-muted);
}
/* ── Status messages ── */
#status-msg {
  border-bottom: 1px solid var(--panel-border);
}

#state-idle,
#state-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 12px 18px;
}
#state-idle {
  color: var(--text-muted);
}
#state-warning {
  color: #b03224;
  align-items: flex-start;
  line-height: 1.45;
}
#state-warning .pulse-dot {
  margin-top: 5px;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse-green 2s ease-in-out infinite;
  background: var(--accent);
}
.pulse-dot--warn {
  background: #c0392b;
  animation: pulse-red 2s ease-in-out infinite;
}
@keyframes pulse-green {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(45, 106, 0, 0.3);
  }
  50% {
    opacity: 0.6;
    box-shadow: 0 0 0 7px rgba(45, 106, 0, 0);
  }
}
@keyframes pulse-red {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.35);
  }
  50% {
    opacity: 0.6;
    box-shadow: 0 0 0 7px rgba(192, 57, 43, 0);
  }
}

/* ── Details toggle ── */
#details-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: none;
  border-top: 1px solid var(--panel-border);
  padding: 9px 18px;
  cursor: pointer;
  font-family: var(--font);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 500;
}
#details-toggle {
  scroll-margin-top: 56px; /* no quedar debajo del header fijo */
}
#details-toggle:hover {
  background: var(--surface);
  color: var(--text-secondary);
}
#toggle-arrow {
  transition: transform 0.2s ease;
  font-size: 9px;
}
#details-toggle.open #toggle-arrow {
  transform: rotate(180deg);
}

.details-col {
  padding: 11px 18px 13px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.details-col:first-child {
  border-bottom: 1px solid var(--panel-border);
}
.detail-section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 10px 0 4px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.detail-section-label:first-child {
  margin-top: 0;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}
.detail-row .dlabel {
  color: var(--text-muted);
}
.detail-row .dval {
  font-weight: 700;
  color: var(--text-primary);
}
.stat-link {
  color: var(--text-primary);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 1px solid var(--panel-border);
  transition:
    border-color 0.15s,
    color 0.15s;
}
.stat-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.detail-divider {
  height: 1px;
  background: var(--panel-border);
  margin: 4px 0;
}

.detail-section-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin: 2px 0 4px;
}

.detail-row-percentil {
  align-items: center;
}
#stat-percentil {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.pct-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.pct-0 {
  background: #f0ece7;
  color: #999;
}
.pct-1 {
  background: #e8f0e0;
  color: #5a8a1a;
}
.pct-2 {
  background: #d4e8c0;
  color: #3d6e0a;
}
.pct-3 {
  background: #b8d99a;
  color: #1f4500;
}

.detail-histogram {
  margin-top: 6px;
  padding: 6px 0 2px;
  position: relative;
}
.detail-histogram svg {
  width: 100%;
  height: auto;
}

/* ── Footer ── */
#panel-footer {
  margin-top: auto; /* se queda abajo cuando el contenido es corto */
  flex-shrink: 0;
  padding: 10px 18px;
  background: var(--surface);
  border-top: 1px solid var(--panel-border);
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
}

/* ── Leaflet ── */
.leaflet-control-attribution {
  font-size: 10px !important;
  background: rgba(255, 255, 255, 0.8) !important;
}

/* ── Intro overlay ── */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(20, 30, 15, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
#intro-box {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px 24px;
  max-width: 400px;
  width: 100%;
}
#intro-box h2 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin-bottom: 2px;
}
.intro-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 14px;
}
#intro-box > p:not(.intro-sub):not(.intro-credit) {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 18px;
}
.intro-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
}
.intro-step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.intro-icon {
  font-size: 15px;
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 1px;
  width: 18px;
  text-align: center;
}
.intro-step span:last-child {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.intro-step strong {
  color: var(--text-primary);
  font-weight: 600;
}
.intro-credit {
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--panel-border);
  text-align: center;
  line-height: 1.7;
}
.intro-credit a,
#panel-footer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.intro-credit a:hover,
#panel-footer a:hover {
  text-decoration: underline;
}
#intro-close {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: -0.01em;
  transition: background 0.15s, opacity 0.15s;
}
#intro-close:hover:not(:disabled) {
  background: #1f4d00;
  border: 1.5px solid #1f4d00;
}
#intro-close:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#intro-como-funciona {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 11px;
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  letter-spacing: -0.01em;
  transition: background 0.15s, color 0.15s;
  box-sizing: border-box;
}
#intro-como-funciona:hover {
  background: var(--accent);
  color: #fff;
}

/* ── Layer control ── */
/* #layer-control {
  padding: 9px 18px 10px;
  border-bottom: 1px solid var(--panel-border); 
}*/
#layer-control label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
}
#layer-select {
  width: 100%;
  padding: 6px 28px 6px 10px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23aaa'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
#layer-select:hover {
  border-color: var(--accent);
}
#layer-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 0, 0.1);
}

/* ── Lente toggle (vive dentro de #result-row) ── */
#lente-toggle-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
#lente-toggle {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
}
.toggle-track {
  display: flex;
  align-items: center;
  width: 36px;
  height: 20px;
  border-radius: 10px;
  background: #ddd;
  padding: 2px;
  transition: background 0.2s ease;
}
.toggle-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease;
}
#lente-toggle.toggle-on .toggle-track {
  background: var(--accent);
}
#lente-toggle.toggle-on .toggle-thumb {
  transform: translateX(16px);
}
#lente-toggle.toggle-off .toggle-track {
  background: #ccc;
}
#lente-toggle.toggle-off .toggle-thumb {
  transform: translateX(0);
}

/* ── Lente apagado: slider y números en gris ── */
#pop-control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0;
}
#pop-control-header label {
  margin-bottom: 0;
}
#lente-toggle-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
#lente-toggle-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 600;
}

.disabled-control {
  opacity: 0.35;
  pointer-events: none;
}

#area-big.value-off {
  color: #bbb !important;
}

/* ── Clickable detail labels ── */
.dlabel-layer {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--panel-border);
  text-underline-offset: 2px;
  transition: color 0.15s, font-weight 0.1s;
}
.dlabel-layer:hover {
  color: var(--accent);
  text-decoration-color: var(--accent);
}
.dlabel-layer.layer-active {
  color: var(--text-primary);
  font-weight: 700;
  text-decoration-color: var(--text-primary);
}

@media (max-width: 768px) {
  #map {
    left: 0;
  }
  /* El panel pasa a ser una hoja inferior con scroll */
  #panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-right: none;
    border-top: 1px solid var(--panel-border);
    border-radius: var(--radius) var(--radius) 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    max-height: 85vh;
  }
  #panel-header {
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .result-divider {
    display: none;
  }
}

/* ════════════════════════════════════════════════════════════════════════
   Componentes nuevos
   ════════════════════════════════════════════════════════════════════════ */

/* Unidades pequeñas dentro de valores (reemplaza estilos inline del JS) */
small.u {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.85em;
}
small.u.nivel {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 0 4px;
  border: 1px solid var(--panel-border);
  border-radius: 99px;
  vertical-align: 1px;
}
.dval.unreliable {
  color: var(--text-muted);
  font-weight: 500;
  cursor: help;
  text-decoration: underline dotted var(--text-muted);
  text-underline-offset: 3px;
}
.acs-nota {
  font-size: 10px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.acs-nota b {
  color: var(--text-secondary);
  font-weight: 600;
}

/* Header del slider: label + campo numérico */
#pop-control-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
#pop-input {
  width: 110px;
  padding: 3px 8px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-align: right;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  background: var(--surface);
  letter-spacing: -0.01em;
}
#pop-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(45, 106, 0, 0.1);
}

/* Poblaciones de referencia */
#presets {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.preset {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  border: 1px solid var(--panel-border);
  background: var(--panel-bg);
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.preset:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.preset.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Selector de unidades */
#unit-switch {
  display: flex;
  justify-content: flex-end;
  gap: 2px;
  margin-top: 8px;
}
#unit-switch button {
  font-family: var(--font);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
}
#unit-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text-primary);
}

/* Foco visible para teclado */
button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
.dlabel-layer:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Buscador */
#search {
  position: fixed;
  top: 16px;
  left: calc(var(--panel-width) + 16px);
  z-index: 1000;
  width: 260px;
}
#search-input {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text-primary);
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
#search-input:focus {
  outline: none;
  border-color: var(--accent);
}
#search-results {
  list-style: none;
  margin-top: 4px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#search-results li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
}
#search-results li span {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
}
#search-results li b {
  font-weight: 600;
}
#search-results li:hover,
#search-results li[aria-selected="true"] {
  background: var(--surface);
}

/* Tooltip de ubicación que sigue al cursor */
#hover-tip {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1100;
  display: none;
  pointer-events: none;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
}

/* Etiquetas de municipios (zoom bajo) */
.muni-label {
  pointer-events: none;
}
.muni-label span {
  display: block;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
}

/* Census tract: borde + rayado */
.tract-path {
  fill: url(#tract-hatch);
}
.tract-hatch-line {
  stroke: var(--tract-hatch);
  stroke-width: 1;
}

/* Histograma: ejes */
.hist-axis {
  font-family: var(--font);
  font-size: 9px;
  fill: var(--text-muted);
}

/* Botones del mapa */
.map-buttons a {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary) !important;
}

/* Leyenda + selector de capa */
#map-legend {
  position: fixed;
  bottom: 28px;
  left: calc(var(--panel-width) + 16px);
  z-index: 900;
  width: 230px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 8px 12px 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}
.legend-title {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}
#map-legend #layer-select {
  margin-bottom: 8px;
}
#legend-scale {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  height: 10px;
  border-radius: 3px;
  overflow: hidden;
}
#legend-labels {
  position: relative;
  height: 14px;
  margin-top: 2px;
  font-size: 9.5px;
  color: var(--text-secondary);
  font-weight: 500;
}
#legend-labels span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}
#legend-extra {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  margin-top: 4px;
  font-size: 9.5px;
  color: var(--text-secondary);
}
#legend-extra span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
#legend-extra .legend-units {
  color: var(--text-muted);
}
.sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}
.sw-excluido {
  background: var(--density-excluded);
  border: 1px solid #bbb;
}
.sw-nodata {
  background: var(--nodata-fill);
  border: 1px dashed #999;
}
#legend-nivel {
  margin-top: 4px;
  font-size: 9px;
  color: var(--text-muted);
}

.leaflet-control-scale-line {
  font-family: var(--font);
  font-size: 9px;
}

@media (max-width: 768px) {
  /* ── Móvil: solo lo esencial; el resto al expandir el panel ── */

  /* Buscador: un botón con lupa que se abre al tocarlo */
  #search {
    top: 10px;
    left: 10px;
    width: auto;
  }
  #search.open {
    right: 10px;
  }
  #search #search-open {
    display: flex;
  }
  #search:not(.open) #search-input,
  #search:not(.open) #search-results,
  #search.open #search-open {
    display: none;
  }

  /* Leyenda: solo la escala; al tocarla muestra el selector de capa */
  #map-legend {
    top: 10px;
    right: 10px;
    bottom: auto;
    left: auto;
    width: 160px;
    padding: 6px 9px 4px;
  }
  #map-legend #legend-current {
    display: flex;
  }
  #legend-nivel,
  .legend-title,
  #legend-extra,
  #map-legend:not(.open) #layer-select,
  #map-legend:not(.open) #edificios-control {
    display: none;
  }
  #map-legend.open {
    width: 210px;
  }
  #map-legend #layer-select {
    font-size: 12px;
    padding: 5px 24px 5px 8px;
    margin: 4px 0 6px;
  }

  /* Controles del mapa: sin zoom (pellizcar) ni escala; encima de la hoja */
  .leaflet-control-zoom,
  .leaflet-control-scale {
    display: none;
  }
  .leaflet-bottom.leaflet-right {
    bottom: var(--sheet-h, 0px);
  }
  .leaflet-control-attribution {
    font-size: 8px !important;
  }
  #hover-tip {
    display: none !important;
  }

  /* Hoja inferior: manija para expandir */
  #panel #sheet-handle {
    display: flex;
  }
  #panel-header {
    position: static;
    padding: 4px 16px 8px;
  }
  #main-block {
    padding: 10px 16px 12px;
  }

  /* Hoja cerrada: población, slider, área y densidad (+ estado en 2 líneas) */
  #panel:not(.sheet-open) #panel-header,
  #panel:not(.sheet-open) #slider-labels,
  #panel:not(.sheet-open) #presets,
  #panel:not(.sheet-open) #unit-switch,
  #panel:not(.sheet-open) #result-details,
  #panel:not(.sheet-open) #details-toggle,
  #panel:not(.sheet-open) #details-body,
  #panel:not(.sheet-open) #panel-footer {
    display: none;
  }
  /* el JS muestra la oración con style="display:block": solo va con la hoja abierta */
  #panel:not(.sheet-open) #result-details {
    display: none !important;
  }
  /* Hoja abierta: los botones del mapa quedarían encima de la leyenda */
  body.hoja-abierta .map-buttons {
    display: none;
  }
  /* Buscador abierto: ocultar la leyenda para que no se encimen */
  #search.open ~ #map-legend {
    display: none;
  }
  #panel:not(.sheet-open) #main-block {
    padding: 0 16px 16px;
    border-bottom: none;
  }
  #panel:not(.sheet-open) #pop-control-header {
    margin-bottom: 4px;
  }
  #panel:not(.sheet-open) #result-row {
    margin-top: 8px;
  }
  #panel:not(.sheet-open) .big-number {
    font-size: 22px;
  }
  #panel:not(.sheet-open) #status-msg {
    border-bottom: none;
  }
  #panel:not(.sheet-open) #state-idle,
  #panel:not(.sheet-open) #state-warning {
    padding: 0 16px 16px;
    font-size: 12px;
  }
  #panel:not(.sheet-open) #warning-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
}

/* Fondo del mapa = agua */
#map {
  background: var(--agua);
}
#edificios-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--panel-border);
  font-size: 10px;
  color: var(--text-secondary);
  cursor: pointer;
}
#edificios-control input {
  accent-color: var(--accent);
  margin: 0;
}

/* Etiquetas de barrios (zoom ≥ 13) */
.barrio-label {
  pointer-events: none;
}
.barrio-label span {
  display: block;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-family: var(--font);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
}

/* ── Elementos que solo existen en móvil (ocultos en escritorio) ── */
#sheet-handle {
  display: none;
  position: sticky;
  top: 0;
  z-index: 3;
  justify-content: center;
  width: 100%;
  padding: 9px 0 7px;
  background: var(--panel-bg);
  border: none;
  cursor: pointer;
}
#sheet-handle span {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #cfcac2;
}
#search-open {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  color: var(--text-primary);
  cursor: pointer;
}
#legend-current {
  display: none;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 0 4px;
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
}
