/* ============================================================
   style.css  –  Visor Cartográfico GIS
   Paleta: oscura / índigo-azul / acentos cian
   ============================================================ */

/* ── 1. Design tokens ────────────────────────────────────── */
:root {
  /* Colores base */
  --bg-app:        #0d1117;
  --bg-panel:      #161b22;
  --bg-panel-deep: #0d1117;
  --bg-section:    #1c2128;
  --bg-hover:      #21262d;
  --bg-active:     #1f3a5f;

  /* Bordes */
  --border-subtle: #30363d;
  --border-muted:  #21262d;

  /* Texto */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  /* Acentos */
  --accent-primary:   #58a6ff;
  --accent-secondary: #3fb950;
  --accent-warning:   #d29922;
  --accent-danger:    #f85149;
  --accent-glow:      rgba(88, 166, 255, 0.15);

  /* Colores de capas */
  --color-seccion:  #e8a838;
  --color-distrito: #4f9cf9;
  --color-colonia:  #3fb950;

  /* Header */
  --header-h: 52px;

  /* Sidebar */
  --sidebar-w: 280px;

  /* Misc */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.6);
  --transition: 200ms cubic-bezier(.4,0,.2,1);
}

/* ── 2. Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  background: var(--bg-app);
  color: var(--text-primary);
  overflow: hidden;
}

/* Accesibilidad: ocultar visualmente pero no del DOM */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── 3. Header ───────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: linear-gradient(135deg, #161b22 0%, #1a2332 100%);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 28px; height: 28px;
  color: var(--accent-primary);
  filter: drop-shadow(0 0 6px var(--accent-primary));
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  background: linear-gradient(90deg, var(--accent-primary), #79c0ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.5px;
}

/* ── 4. Layout principal ─────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
}

/* ── 5. Panel lateral ────────────────────────────────────── */
.control-panel {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.panel-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 14px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}

.panel-tab:hover {
  color: var(--text-secondary);
}

.panel-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.panel-content-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}

.control-panel::-webkit-scrollbar { width: 4px; }
.control-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 4px;
}

/* Secciones del panel */
.panel-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-muted);
}

.panel-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.panel-section-title svg {
  width: 14px; height: 14px;
  flex-shrink: 0;
  color: var(--accent-primary);
}

/* Indicador de capa fija */
.layer-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-section);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-muted);
}

.indicator-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}

.indicator-label {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
}

.indicator-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.indicator-badge.active {
  background: rgba(63, 185, 80, 0.2);
  color: var(--accent-secondary);
  border: 1px solid rgba(63, 185, 80, 0.4);
}

/* ── 6. Toggle group (radio buttons estilizados) ─────────── */
.toggle-group {
  border: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-muted);
  background: var(--bg-section);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
  position: relative;
}

.toggle-option:hover {
  background: var(--bg-hover);
  border-color: var(--border-subtle);
}

/* Estado seleccionado */
.toggle-option:has(input:checked) {
  background: var(--bg-active);
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 1px var(--accent-primary), inset 0 0 12px var(--accent-glow);
}

/* Ocultar radio nativo */
.toggle-option input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}

/* Pill visual */
.toggle-pill {
  width: 36px;
  height: 20px;
  border-radius: 20px;
  background: var(--bg-app);
  border: 1.5px solid var(--border-subtle);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  padding: 2px;
  transition: background var(--transition), border-color var(--transition);
  margin-top: 1px;
}

.toggle-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform var(--transition), background var(--transition);
}

.toggle-option:has(input:checked) .toggle-pill {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.toggle-option:has(input:checked) .toggle-dot {
  background: white;
  transform: translateX(16px);
}

/* Focus visible para accesibilidad */
.toggle-option:has(input:focus-visible) {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.toggle-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}

.toggle-text strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-text small {
  font-size: 10px;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ── 7. Loading indicator ────────────────────────────────── */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-section);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border-muted);
  animation: fadeIn 200ms ease;
}

.loading-indicator[hidden] { display: none; }

.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── 8. Perspectiva ──────────────────────────────────────── */
.perspectiva-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-app);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-muted);
}

.perspectiva-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.perspectiva-label > span > svg {
  color: var(--accent-primary);
}

.perspectiva-controls {
  display: flex;
  gap: 8px;
}

.perspectiva-controls select {
  flex: 1;
  background: var(--bg-section);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
}

.perspectiva-controls select:focus {
  border-color: var(--accent-primary);
}

.perspectiva-clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: rgba(248, 81, 73, 0.1);
  color: var(--accent-danger);
  border: 1px solid rgba(248, 81, 73, 0.2);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.perspectiva-clear-btn:hover {
  background: rgba(248, 81, 73, 0.2);
  border-color: rgba(248, 81, 73, 0.4);
}

.perspectiva-clear-btn[hidden] {
  display: none !important;
}

.prioridad-legend {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--border-muted);
}

.prioridad-legend[hidden] {
  display: none !important;
}

.prioridad-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.prio-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.1) inset;
}

/* ── 9. Archivo Externo ──────────────────────────────────── */
.ext-file-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-app);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-muted);
}

.ext-file-input {
  width: 100%;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-section);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px;
  cursor: pointer;
}

.ext-file-input::file-selector-button {
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: 3px;
  padding: 4px 8px;
  margin-right: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}

.ext-file-input::file-selector-button:hover {
  opacity: 0.85;
}

.ext-clear-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}

.ext-clear-btn:hover {
  color: var(--accent-danger);
  border-color: rgba(248, 81, 73, 0.4);
}

.ext-filters-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  background: var(--bg-app);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-muted);
}

.ext-filters-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ext-filter-row {
  display: flex;
  gap: 6px;
}

.ext-select, .ext-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-section);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  outline: none;
  transition: border-color var(--transition);
}

.ext-select:focus, .ext-input:focus {
  border-color: var(--accent-primary);
}

.ext-btn-primary {
  background: var(--accent-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition);
}

.ext-btn-primary:hover {
  opacity: 0.85;
}

/* ── 10. Footer del panel ─────────────────────────────────── */
.panel-footer {
  margin-top: auto;
  padding: 14px 16px;
  border-top: 1px solid var(--border-muted);
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── 10. Contenedor del mapa ─────────────────────────────── */
.map-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: #1a1f2e;
}

/* Sobrescribir z-index de controles Leaflet para no solapar header */
.leaflet-top { top: 10px; }
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-control-zoom a {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border-color: var(--border-subtle) !important;
  font-size: 16px !important;
  transition: background var(--transition), color var(--transition);
}

.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
  color: var(--accent-primary) !important;
}

/* Control personalizado: selector Calle / Satélite */
.map-style-control {
  margin-top: 8px !important;   /* separación visual del zoom */
}

.map-style-btn {
  display: flex !important;
  align-items: center;
  gap: 5px;
  padding: 0 10px !important;
  height: 30px !important;
  line-height: 1 !important;
  background: var(--bg-panel) !important;
  color: var(--text-secondary) !important;
  border-color: var(--border-subtle) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  letter-spacing: 0.3px;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition) !important;
  text-decoration: none !important;
}

.map-style-btn:hover {
  background: var(--bg-hover) !important;
  color: var(--text-primary) !important;
}

.map-style-btn.active {
  background: var(--bg-active) !important;
  color: var(--accent-primary) !important;
  box-shadow: inset 0 0 10px var(--accent-glow) !important;
}

.map-style-btn svg {
  flex-shrink: 0;
}

/* Popup del mapa */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-subtle) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 13px !important;
}

.leaflet-popup-tip { background: var(--bg-panel) !important; }

.popup-header {
  font-weight: 600;
  font-size: 13px;
  color: var(--accent-primary);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-muted);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  font-size: 12px;
}

.popup-label { color: var(--text-secondary); }
.popup-value { color: var(--text-primary); font-weight: 500; }

/* Tooltip de hover individual (reservado para uso futuro) */
.gis-tooltip {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 8px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.gis-tooltip::before { border-top-color: var(--border-subtle); }

/* Etiqueta flotante compartida: sección + colonia simultáneos */
.map-hover-label {
  display: none;
  position: absolute;
  z-index: 500;
  pointer-events: none;
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  box-shadow: var(--shadow-md);
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.mhl-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.mhl-tag {
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  min-width: 52px;
}

.mhl-val {
  font-weight: 700;
  color: var(--text-primary);
}

/* Etiquetas fijas en centroides de polígonos de distrito */
.distrito-label {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  pointer-events: none;
}

.distrito-label span {
  display: inline-block;
  transform: translateX(-50%);   /* centrar horizontalmente sobre el punto */
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  text-shadow:
    0 0 3px rgba(0,0,0,0.9),
    0 0 6px rgba(0,0,0,0.7),
    1px 1px 0 rgba(0,0,0,0.8);
}

/* ── 11. Toast de errores ────────────────────────────────── */
.toast-container {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 900;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  pointer-events: auto;
  animation: toastIn 250ms cubic-bezier(.34,1.56,.64,1) forwards;
  white-space: nowrap;
}

.toast.error { border-color: var(--accent-danger); color: var(--accent-danger); }
.toast.info  { border-color: var(--accent-primary); color: var(--accent-primary); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── 12. Responsive básico ───────────────────────────────── */
@media (max-width: 680px) {
  :root { --sidebar-w: 100%; }

  .app-layout {
    flex-direction: column;
  }

  .control-panel {
    width: 100%;
    max-height: 45vh;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    flex-direction: row;
    flex-wrap: wrap;
    overflow-x: auto;
  }

  .panel-section { min-width: 200px; flex: 1; }

  .map-wrapper { flex: 1; }
}

/* ── 15. Login Overlay ─────────────────────────────────────── */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background-color: rgba(13, 17, 23, 0.7); /* Transparencia sobre el --bg-app (#0d1117) */
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.login-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.login-header {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.login-icon {
  width: 48px;
  height: 48px;
  color: var(--accent-primary);
}

.login-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.login-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.login-field input {
  background: var(--bg-body);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

.login-field input:focus {
  border-color: var(--accent-primary);
}

.login-error {
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 10px;
  border-radius: 4px;
  font-size: 12px;
  text-align: center;
}

.login-btn {
  background: var(--accent-primary);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition);
  margin-top: 8px;
}

.login-btn:hover {
  background: var(--accent-hover);
}

.login-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}
