:root {
  --bg: #f4f7fb;
  --panel-bg: rgba(255, 255, 255, 0.96);
  --panel-border: rgba(15, 23, 42, 0.08);
  --panel-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);

  --text: #0f172a;
  --muted: #475569;
  --muted-2: #64748b;

  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --blue-border: #bfdbfe;

  --card-bg: #f8fafc;
  --card-border: #e2e8f0;

  --danger: #dc2626;
  --warning: #f97316;
  --caution: #eab308;
  --archived: #111111;

  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --panel-width: 380px;
  --panel-gap: 16px;
  --transition-fast: 0.2s ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100vh;
  background: #dde7f0;
}

/* =============================================================================
   PANEL
   ============================================================================= */

#info-panel {
  position: absolute;
  top: var(--panel-gap);
  left: var(--panel-gap);
  z-index: 1000;

  width: var(--panel-width);
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;

  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow);

  padding: 16px;

  color: var(--text);

  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  transition:
    transform var(--transition-fast),
    opacity var(--transition-fast),
    max-height var(--transition-fast);
}

#info-panel.panel-collapsed .panel-body {
  display: none;
}

#info-panel.panel-hidden {
  transform: translateX(-120%);
  opacity: 0;
  pointer-events: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.panel-header-text {
  min-width: 0;
}

.panel-eyebrow {
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--blue);
}

.panel-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
  color: var(--text);
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;

  padding: 6px 10px;
  border-radius: 999px;

  font-size: 12px;
  font-weight: 600;

  background: var(--blue-soft);
  color: #1d4ed8;
  border: 1px solid var(--blue-border);
}

.panel-icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid #dbe4f0;
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.panel-icon-btn:hover {
  background: #f8fafc;
}

.panel-icon-btn:active {
  transform: scale(0.97);
}

.panel-body {
  margin-top: 12px;
}

.panel-lead {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.panel-status {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.panel-summary {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-card {
  padding: 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  background: var(--card-bg);
}

.metric-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.metric-value {
  margin-top: 6px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}

.panel-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--card-border);
}

.panel-section-title {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted-2);
}

.panel-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.panel-note:first-of-type {
  margin-top: 0;
}

.panel-footer-note {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--card-border);
  color: var(--muted-2);
  font-size: 12px;
  line-height: 1.55;
}

/* =============================================================================
   LEYENDA
   ============================================================================= */

.legend-card {
  background: #ffffff;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 12px;
}

.legend-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: #334155;
  margin-bottom: 10px;
}

.legend-row:last-child {
  margin-bottom: 0;
}

.legend-row strong {
  display: block;
  margin-bottom: 2px;
  color: var(--text);
  font-size: 14px;
}

.legend-row div {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.legend-dot,
.legend-square {
  flex: 0 0 auto;
  margin-top: 4px;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.legend-red {
  background: var(--danger);
}

.legend-orange {
  background: var(--warning);
}

.legend-yellow {
  background: var(--caution);
}

.legend-square {
  width: 10px;
  height: 10px;
  background: var(--archived);
  border: 1px solid #000000;
}

/* Indicadores inline en el texto explicativo */
.inline-dot,
.inline-square {
  display: inline-block;
  vertical-align: middle;
  margin: 0 2px;
}

.inline-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.inline-red    { background: var(--danger); }
.inline-orange { background: var(--warning); }
.inline-yellow { background: var(--caution); }

.inline-square {
  width: 9px;
  height: 9px;
  background: var(--archived);
  border: 1px solid #000;
}

.panel-note-muted {
  color: var(--muted-2);
  font-size: 13px;
  border-top: 1px solid var(--card-border);
  padding-top: 8px;
  margin-top: 12px;
}

/* =============================================================================
   DETALLE DE SELECCIÓN
   ============================================================================= */

.selected-grid {
  display: grid;
  gap: 10px;
}

.selected-card {
  padding: 12px;
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  background: #ffffff;
}

.selected-label {
  font-size: 14px;
  color: var(--muted-2);
}

.selected-big-value {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.selected-value {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.selected-text {
  margin-top: 6px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.muted-text {
  color: var(--muted-2);
}

/* =============================================================================
   BOTÓN FLOTANTE PARA REABRIR PANEL
   ============================================================================= */

.panel-fab {
  position: absolute;
  left: 16px;
  top: 16px;
  z-index: 1100;

  width: 46px;
  height: 46px;
  border: none;
  border-radius: 999px;

  background: var(--blue);
  color: #ffffff;

  font-size: 22px;
  font-weight: 700;
  cursor: pointer;

  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.28);
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}

.panel-fab:active {
  transform: scale(0.96);
}

.panel-fab.hidden {
  display: none;
}

/* =============================================================================
   MARCADOR ARCHIVADO
   ============================================================================= */

.archived-square-marker {
  width: 10px;
  height: 10px;
  background: var(--archived);
  border: 1px solid #000000;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.45);
}

/* =============================================================================
   LEAFLET / POPUPS
   ============================================================================= */

.leaflet-popup-content-wrapper {
  border-radius: 14px;
  box-shadow: 0 16px 30px rgba(15, 23, 42, 0.14);
}

.leaflet-popup-content {
  margin: 14px 16px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.leaflet-popup-content a {
  color: var(--blue);
  text-decoration: none;
}

.leaflet-popup-content a:hover {
  text-decoration: underline;
}

.leaflet-control-zoom {
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
  border-radius: 12px;
  overflow: hidden;
}

.leaflet-control-zoom a {
  width: 36px;
  height: 36px;
  line-height: 36px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  border: none;
}

.leaflet-control-zoom a:hover {
  background: #f8fafc;
}

/* =============================================================================
   MOBILE / iOS / ANDROID
   ============================================================================= */

@media (max-width: 768px) {
  #info-panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: 12px;

    width: auto;
    max-width: none;
    max-height: min(72vh, 520px);

    border-radius: 20px;
    padding: 14px;
  }

  #info-panel.panel-hidden {
    transform: translateY(120%);
    opacity: 0;
  }

  .panel-title {
    font-size: 16px;
  }

  .panel-summary {
    grid-template-columns: 1fr 1fr;
  }

  .panel-fab {
    top: auto;
    left: 12px;
    bottom: 12px;
  }
}

/* Mejora para pantallas muy pequeñas */
@media (max-width: 420px) {
  #info-panel {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-height: min(76vh, 540px);
    padding: 12px;
  }

  .panel-summary {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .metric-value {
    font-size: 20px;
  }

  .panel-icon-btn {
    width: 32px;
    height: 32px;
  }

  .panel-badge {
    padding: 5px 8px;
    font-size: 11px;
  }
}