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

:root {
  --accent: #01f3b3;
  --text:   #1c1917;
  --muted:  #78716c;
  --bg:     #ffffff;
  --shadow: 0 4px 24px rgba(0,0,0,0.10);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.14);
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', Arial, sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  scrollbar-width: none;
}
html::-webkit-scrollbar,
body::-webkit-scrollbar { display: none; }

/* ── Mapa ── */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* ── Header ── */
#header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

.header-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text);
}

#leyenda {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px;
  padding-top: 8px;
  margin-top: 4px;
  border-top: 1px solid rgba(0,0,0,0.08);
}

.leg-step { flex: 1; min-width: 0; }
.leg-titulo {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding-top: 1px;
}
.leg-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.leg-step-color {
  width: 100%;
  height: 9px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
}
.leg-step-label {
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  width: 100%;
}


/* ── Zoom control: bajar para no tapar header ── */
.maplibregl-ctrl-top-right {
  top: 60px !important;
}

/* ── Geocoder ── */
#geocoder {
  position: fixed;
  top: 60px;
  right: 56px;
  z-index: 10;
  width: 230px;
}
#geocoder-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  font-size: 13px;
  font-family: var(--font);
  box-shadow: var(--shadow);
  outline: none;
  box-sizing: border-box;
}
#geocoder-input:focus {
  border-color: rgba(0,0,0,0.3);
}
#geocoder-results {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(10px);
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: var(--shadow);
  display: none;
  overflow: hidden;
}
#geocoder-results li {
  padding: 8px 12px;
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
#geocoder-results li:last-child { border-bottom: none; }
#geocoder-results li:hover { background: #f5f5f5; }

/* ── Controles de continente ── */
#controls-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  padding: 0 2px 4px;
  line-height: 1;
  align-self: flex-end;
  transition: color 0.12s;
}
#controls-toggle:hover { color: var(--text); }
#controls.collapsed #controls-toggle { padding-bottom: 0; }
#controls.collapsed #controls-body  { display: none; }

#controls-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#controls {
  position: fixed;
  top: 72px;
  left: 16px;
  z-index: 10;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pill {
  background: var(--bg);
  color: var(--text);
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.pill:hover:not(.active) { background: #f0f0f0; }
.pill.active {
  background: #000;
  color: #fff;
  border-color: #000;
}

/* ── Slider de umbral ── */
#slider-wrap {
  display: none;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(0,0,0,0.08);
  flex-direction: column;
  gap: 4px;
}
#slider-wrap.visible { display: flex; }
#slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#slider-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
#slider-value {
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
}
#umbral {
  width: 100%;
  accent-color: #000;
  cursor: pointer;
  margin: 0;
}

/* ── Tooltip ── */
.map-tooltip {
  position: fixed;
  z-index: 300;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.1);
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.1s;
}
.map-tooltip.visible { opacity: 1; }

/* ── Popup ── */
.maplibregl-popup {
  font: 13px/1.4 var(--font);
}
.maplibregl-popup-content {
  padding: 0;
  border-radius: 14px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid rgba(0,0,0,0.1);
  box-shadow: var(--shadow-lg);
  min-width: 260px;
}
.maplibregl-popup-close-button {
  color: var(--muted);
  font-size: 16px;
  padding: 6px 10px;
}
.maplibregl-popup-close-button:hover { color: #000; background: transparent; }

.pp-top-bar { height: 4px; }
.pp-inner {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pp-nombre {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.2;
}
.pp-seccion {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
  margin: 0;
}

.pp-provincia {
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}
.pp-ratio {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pp-ratio-stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 9px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.pp-ratio-bar {
  height: 5px;
  background: #374151;
  border-radius: 999px;
  overflow: hidden;
}
.pp-ratio-esp {
  height: 100%;
  background: #01f3b3;
  border-radius: 999px;
}

.pp-continentes {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-top: 10px;
  border-top: 1px solid rgba(0,0,0,0.07);
}
.pp-cont-row {
  display: grid;
  grid-template-columns: 10px 1fr auto auto;
  align-items: center;
  gap: 8px;
}
.pp-cont-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.12);
  flex-shrink: 0;
}
.pp-cont-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}
.pp-cont-pct {
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  text-align: right;
  min-width: 46px;
}
.pp-cont-abs {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
  min-width: 64px;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  #header { padding: 8px 12px; }
  .header-title { font-size: 10px; }

  #controls {
    top: 56px;
    padding: 7px 9px;
    gap: 3px;
  }
  .pill {
    font-size: 10px;
    padding: 3px 9px;
  }

  .leg-step-color {
    width: 14px;
    height: 7px;
  }
  .leg-step-label { font-size: 7px; }
  .leg-titulo     { font-size: 8px; }
  #leyenda        { gap: 3px; }

  #slider-wrap { margin-top: 4px; padding-top: 6px; }
  #slider-label, #slider-value { font-size: 9px; }

  /* Geocoder: abajo centrado para no solaparse con los controles */
  #geocoder {
    top: auto;
    bottom: 36px;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    width: 220px;
  }
  #geocoder-input { text-align: center; }
}
