/* Tema dark navy — mismos tokens que la app srs (PULSE) */
:root {
  --navy: #111827;
  --panel: #161f2e;
  --raised: #1b2638;
  --line: #283449;
  --ink: #e8edf5;
  --muted: #8b98ad;
  --faint: #5d6a80;
  --green: #22c55e;
  --green-dark: #16a34a;
  --teal: #14b8a6;
  --blue: #3b82f6;
  --orange: #f59e0b;
  --red: #ef4444;
  --grad: linear-gradient(135deg, #22c55e, #14b8a6);
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--navy);
  color: var(--ink);
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ------------------------------------------------------------ header */
.app-header {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px; padding: 0 14px;
  background: var(--navy);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,0.35);
  z-index: 20;
}
.sidebar-toggle-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; flex: 0 0 auto;
}
.sidebar-toggle-btn:hover { color: var(--ink); background: var(--raised); }
.app-title { font-weight: 700; font-size: 14px; letter-spacing: 0.2px; display: flex; align-items: center; gap: 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-dot {
  width: 11px; height: 11px; border-radius: 50%; flex: 0 0 auto;
  background: var(--grad);
  box-shadow: 0 0 10px rgba(34,197,94,0.8);
}
.app-kpis { margin-left: auto; display: flex; gap: 8px; }
.kpi-chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 4px 10px; text-align: center; min-width: 74px;
}
.kpi-value { color: #fff; font-family: var(--mono); font-size: 14px; font-weight: 700; }
.kpi-label { color: var(--muted); text-transform: uppercase; font-size: 9px; letter-spacing: 0.6px; }
@media (max-width: 900px) { .app-kpis { display: none; } }

/* ------------------------------------------------------------ layout */
.app-body { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 350px; flex: 0 0 350px;
  background: var(--navy);
  border-right: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden;
  padding: 14px;
  transition: margin-left 0.25s ease;
}
.sidebar.collapsed { margin-left: -350px; }
.map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

/* ------------------------------------------------------------ sidebar */
.sidebar-header .title { font-weight: 800; font-size: 15px; }
.sidebar-header .title i { color: var(--green); margin-right: 6px; }
.sidebar-header .subtitle { color: var(--muted); font-size: 11.5px; margin-top: 3px; }

.filters-header h5 {
  margin: 18px 0 8px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.8px; color: var(--muted); font-weight: 700;
}
.filters-header h5 i { color: var(--teal); margin-right: 6px; }

.layers-section {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 6px 12px;
}
.layer-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.layer-row:last-child { border-bottom: none; }
.layer-dot { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.layer-dot.round { border-radius: 50%; }
.layer-name { font-size: 12.5px; font-weight: 600; flex: 1; }
.layer-name .info { color: var(--faint); font-size: 10.5px; margin-left: 5px; cursor: help; }

.toggle {
  position: relative; width: 44px; height: 24px; flex: 0 0 auto; cursor: pointer;
  background: var(--raised); border: 1px solid var(--line); border-radius: 24px;
  transition: background 0.18s ease;
}
.toggle .knob {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  background: #fff; border-radius: 50%; transition: left 0.18s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.toggle.on { background: var(--green); border-color: var(--green-dark); }
.toggle.on .knob { left: 22px; }

.ctl-label { display: block; color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px; margin: 10px 0 4px; font-weight: 600; }
/* Dropdown con búsqueda — mismo diseño que el SearchableDropdown de srs */
.searchable-dropdown { width: 100%; }
.dropdown-container { position: relative; width: 100%; }
.dropdown-toggle {
  width: 100%; padding: 8px 10px;
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; display: flex; justify-content: space-between; align-items: center;
  font-family: inherit; font-size: 12.5px; text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropdown-toggle:hover { border-color: var(--teal); background: var(--panel); }
.dropdown-toggle:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(20,184,166,0.2); }
.dropdown-value { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown-arrow { margin-left: 8px; color: var(--muted); font-size: 9px; }
.dropdown-menu {
  display: none;
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.45);
  z-index: 100; max-height: 320px;
  flex-direction: column; overflow: hidden;
  animation: sd-slideDown 0.18s ease;
}
.dropdown-menu.open { display: flex; }
@keyframes sd-slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
.dropdown-search { padding: 8px; border-bottom: 1px solid var(--line); background: var(--navy); }
.search-input {
  width: 100%; padding: 7px 9px; box-sizing: border-box;
  background: var(--raised); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  font-family: inherit; font-size: 12px;
  transition: border-color 0.15s ease;
}
.search-input::placeholder { color: var(--faint); }
.search-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 2px rgba(20,184,166,0.2); }
.dropdown-options { overflow-y: auto; max-height: 250px; }
.dropdown-option {
  padding: 8px 10px; cursor: pointer; font-size: 12px; color: var(--ink);
  border-bottom: 1px solid var(--line);
  transition: background-color 0.12s ease;
}
.dropdown-option:last-child { border-bottom: none; }
.dropdown-option:hover { background: var(--raised); }
.dropdown-option.selected { background: rgba(20,184,166,0.15); color: #5eead4; font-weight: 600; }
.dropdown-no-results { padding: 12px; text-align: center; color: var(--faint); font-style: italic; font-size: 12px; }
.dropdown-options::-webkit-scrollbar { width: 8px; }
.dropdown-options::-webkit-scrollbar-track { background: var(--navy); }
.dropdown-options::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(20,184,166,0.12); color: #5eead4;
  border: 1px solid rgba(20,184,166,0.4); border-radius: 20px;
  padding: 3px 6px 3px 10px; font-size: 11px; font-weight: 600;
}
.filter-chip button {
  background: rgba(20,184,166,0.25); color: #5eead4; border: none; cursor: pointer;
  width: 16px; height: 16px; border-radius: 50%; font-size: 10px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.filter-chip button:hover { background: var(--red); color: #fff; }
.clear-filters {
  background: transparent; border: 1px solid rgba(239,68,68,0.5); color: var(--red);
  border-radius: 20px; padding: 3px 12px; font-size: 11px; font-weight: 600; cursor: pointer;
  font-family: inherit;
}
.clear-filters:hover { background: rgba(239,68,68,0.12); }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.stat-number { color: #fff; font-family: var(--mono); font-size: 16px; font-weight: 700; }
.stat-label { color: var(--muted); text-transform: uppercase; font-size: 9.5px; letter-spacing: 0.5px; margin-top: 2px; }

.bar-section { display: flex; flex-direction: column; gap: 5px; }
.bar-row { cursor: pointer; border-radius: 7px; padding: 3px 5px; }
.bar-row:hover { background: var(--raised); }
.bar-row.active { outline: 1px solid var(--teal); background: var(--raised); }
.bar-top { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 3px; gap: 8px; }
.bar-top .bar-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-top .bar-value { color: var(--muted); font-family: var(--mono); flex: 0 0 auto; }
.bar-track { background: var(--raised); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--grad); }
.bar-fill.seg { background: linear-gradient(135deg, #3b82f6, #14b8a6); }
.bar-empty { color: var(--faint); font-size: 11.5px; padding: 4px 5px; }

.sidebar-foot { color: var(--faint); font-size: 10px; margin-top: 20px; line-height: 1.5; }

/* ------------------------------------------------------------ mapa */
.gl-zoom-chip {
  position: absolute; top: 10px; left: 52px; z-index: 5;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  font-family: var(--mono); font-size: 11px; padding: 4px 9px; border-radius: 7px;
}
.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line); }
.maplibregl-ctrl-group button { background: var(--panel) !important; }
.maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(0.85); }
.maplibregl-ctrl-attrib { background: rgba(22,31,46,0.75) !important; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib a { color: var(--muted) !important; font-size: 10px; }

.map-legend {
  position: absolute; top: 10px; right: 10px; z-index: 6; width: 232px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5); font-size: 11px;
}
.legend-head { padding: 8px 12px; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 7px; }
.legend-head i:first-child { color: var(--teal); }
.legend-head .caret { margin-left: auto; color: var(--muted); transition: transform 0.2s; }
.map-legend.collapsed .caret { transform: rotate(180deg); }
.map-legend.collapsed .legend-body { display: none; }
.legend-body { padding: 0 12px 10px; }
.legend-sec { margin-bottom: 10px; }
.legend-sec:last-child { margin-bottom: 0; }
.legend-title { color: var(--muted); font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 5px; }
.legend-gradbar { height: 10px; border-radius: 5px; }
.legend-scale { display: flex; justify-content: space-between; color: var(--faint); font-family: var(--mono); font-size: 9.5px; margin-top: 3px; }
.legend-dot-row { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.legend-dot { width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid #fff; }

/* popups */
.maplibregl-popup.gl-popup .maplibregl-popup-content,
.maplibregl-popup.gl-tooltip .maplibregl-popup-content {
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  font-family: 'Montserrat', sans-serif; font-size: 12px;
  padding: 12px 14px;
}
.maplibregl-popup.gl-tooltip .maplibregl-popup-content { padding: 7px 10px; font-size: 11.5px; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: var(--panel) !important; }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: var(--panel) !important; }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--panel) !important; }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--panel) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 16px; right: 4px; top: 2px; }
.maplibregl-popup-close-button:hover { color: var(--ink); background: transparent; }

.popup-content h6 { margin: 0 0 7px; font-size: 13px; font-weight: 800; }
.popup-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.pbadge { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; border-radius: 20px; padding: 2px 8px; }
.pbadge.tta { background: rgba(33,113,181,0.25); color: #9ecae1; border: 1px solid #2171b5; }
.pbadge.growth { background: rgba(49,163,84,0.22); color: #a1d99b; border: 1px solid #31a354; }
.pbadge.reclaim { background: rgba(227,26,28,0.2); color: #fca5a5; border: 1px solid #e31a1c; }
.pbadge.comp { background: rgba(106,81,163,0.28); color: #bcbddc; border: 1px solid #6a51a3; }
.stat-row { display: flex; justify-content: space-between; gap: 14px; padding: 2.5px 0; }
.stat-row .k { color: var(--muted); }
.stat-row .v { font-family: var(--mono); font-weight: 600; }
.popup-breakdown { border-top: 1px solid var(--line); margin-top: 7px; padding-top: 7px; }
.popup-breakdown .bd-title { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700; margin-bottom: 4px; }
.seg-list { margin: 0; padding: 0; list-style: none; }
.seg-list li { padding: 1.5px 0; color: var(--ink); font-size: 11.5px; }
.seg-list li .rank { color: var(--faint); font-family: var(--mono); margin-right: 5px; }
.popup-btn {
  margin-top: 9px; width: 100%; border: none; border-radius: 8px; cursor: pointer;
  background: var(--grad); color: #06220f; font-weight: 700; font-size: 11.5px;
  padding: 7px 10px; font-family: inherit;
}
.popup-btn:hover { filter: brightness(1.08); }

.loading-overlay {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(17,24,39,0.85);
  display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px;
}
.spinner {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* scrollbar */
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
