:root {
  --bg: #0f0f13;
  --surface: #18181f;
  --surface2: #1f1f28;
  --border: #2a2a36;
  --accent: #e05c7a;
  --accent2: #f0a0b0;
  --accent3: #7c6af7;
  --text: #f0eef5;
  --text-muted: #8a8799;
  --emergency: #ff4757;
  --legal: #7c6af7;
  --psicologico: #2ecc71;
  --albergue: #f39c12;
  --policial: #3498db;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* HEADER */
header {
  position: relative;
  padding: 2rem 2rem 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.logo-area h1 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(1.4rem, 3vw, 2.2rem);
  font-weight: 800;
  line-height: 1.1;
  color: var(--text);
}

.logo-area h1 span { color: var(--accent); }

.logo-area p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  font-weight: 300;
  max-width: 420px;
}

.sos-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, #c0392b, var(--emergency));
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(255,71,87,0.35);
  flex-shrink: 0;
}

.sos-badge:hover { transform: translateY(-2px); box-shadow: 0 8px 30px rgba(255,71,87,0.5); }
.sos-badge .phone-icon { font-size: 1.4rem; }
.sos-badge .sos-text { display: flex; flex-direction: column; }
.sos-badge .sos-number { font-family: 'Syne', sans-serif; font-size: 1.5rem; font-weight: 800; color: #fff; line-height: 1; }
.sos-badge .sos-label { font-size: 0.7rem; color: rgba(255,255,255,0.8); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }

/* NAV TABS */
.nav-tabs { display: flex; gap: 0; margin-top: 1.5rem; border-bottom: none; }

.nav-tab {
  font-family: 'Syne', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* MAIN LAYOUT */
.main-layout {
  display: flex;
  height: calc(100vh - 140px);
  max-width: 1400px;
  margin: 0 auto;
}

/* SIDEBAR */
.sidebar {
  width: 380px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header { padding: 1rem 1.25rem 0.75rem; border-bottom: 1px solid var(--border); }

.search-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  transition: border-color 0.2s;
}

.search-box:focus-within { border-color: var(--accent); }
.search-box input { flex: 1; background: none; border: none; outline: none; color: var(--text); font-family: 'DM Sans', sans-serif; font-size: 0.85rem; }
.search-box input::placeholder { color: var(--text-muted); }

/* SELECT DEPARTAMENTO - NUEVO, CON ESTILO OSCURO */
#departamentoFilter {
  width: 100%;
  margin-top: 0.5rem;
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.85rem;
  outline: none;
}
#departamentoFilter:focus { border-color: var(--accent); }

.filter-chips { display: flex; gap: 0.4rem; flex-wrap: wrap; padding: 0.75rem 1.25rem; border-bottom: 1px solid var(--border); }

.chip {
  font-size: 0.72rem;
  font-weight: 500;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
}

.chip:hover { color: var(--text); border-color: #555; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip[data-cat="legal"].active { background: var(--legal); border-color: var(--legal); }
.chip[data-cat="psicologico"].active { background: var(--psicologico); border-color: var(--psicologico); }
.chip[data-cat="albergue"].active { background: var(--albergue); border-color: var(--albergue); }
.chip[data-cat="policial"].active { background: var(--policial); border-color: var(--policial); }
.chip[data-cat="emergencia"].active { background: var(--emergency); border-color: var(--emergency); }

.results-count { padding: 0.5rem 1.25rem; font-size: 0.75rem; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.places-list { flex: 1; overflow-y: auto; padding: 0.5rem 0; }
.places-list::-webkit-scrollbar { width: 4px; }
.places-list::-webkit-scrollbar-track { background: transparent; }
.places-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.place-card { padding: 0.9rem 1.25rem; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.15s; position: relative; }
.place-card:hover, .place-card.active { background: var(--surface2); }
.place-card-top { display: flex; align-items: flex-start; gap: 0.75rem; }
.place-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.place-name { font-family: 'Syne', sans-serif; font-size: 0.88rem; font-weight: 700; color: var(--text); line-height: 1.2; flex: 1; }
.place-type-badge { font-size: 0.65rem; font-weight: 600; padding: 0.15rem 0.5rem; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.04em; flex-shrink: 0; }
.place-address { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.3rem; margin-left: 3rem; line-height: 1.4; }
.place-tags { display: flex; gap: 0.3rem; flex-wrap: wrap; margin-top: 0.4rem; margin-left: 3rem; }
.tag { font-size: 0.65rem; padding: 0.15rem 0.45rem; border-radius: 4px; font-weight: 500; }
.place-phone { font-size: 0.78rem; margin-top: 0.35rem; margin-left: 3rem; font-weight: 500; }

/* MAP */
#map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

/* POPUP */
.popup-content { font-family: 'DM Sans', sans-serif; min-width: 220px; max-width: 280px; }
.popup-content h3 { font-family: 'Syne', sans-serif; font-size: 0.95rem; font-weight: 700; margin-bottom: 0.4rem; color: #1a1a2e; }
.popup-content p { font-size: 0.78rem; color: #444; line-height: 1.4; margin-bottom: 0.25rem; }
.popup-content .popup-phone { font-weight: 600; color: #c0392b; }
.popup-content .popup-hours { font-size: 0.72rem; color: #666; }

/* DETAIL PANEL */
.detail-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 1.25rem;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 50;
  max-height: 45%;
  overflow-y: auto;
}
.detail-panel.open { transform: translateY(0); }
.detail-close { position: absolute; top: 0.75rem; right: 1rem; background: none; border: none; color: var(--text-muted); font-size: 1.2rem; cursor: pointer; padding: 0.2rem; }
.detail-close:hover { color: var(--text); }
.detail-name { font-family: 'Syne', sans-serif; font-size: 1.1rem; font-weight: 800; color: var(--text); margin-bottom: 0.25rem; padding-right: 2rem; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.75rem; }
.detail-item label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }
.detail-item p { font-size: 0.82rem; color: var(--text); margin-top: 0.1rem; line-height: 1.4; }
.detail-services { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.75rem; }
.service-tag { font-size: 0.72rem; padding: 0.25rem 0.6rem; border-radius: 6px; font-weight: 500; }
.btn-directions { display: inline-flex; align-items: center; gap: 0.4rem; margin-top: 0.75rem; background: var(--accent); color: #fff; font-family: 'Syne', sans-serif; font-size: 0.78rem; font-weight: 700; padding: 0.5rem 1rem; border-radius: 8px; text-decoration: none; transition: background 0.2s; }
.btn-directions:hover { background: #c94d6a; }

/* EMERGENCY BANNER */
.emergency-bar {
  background: linear-gradient(90deg, #c0392b, var(--emergency), #c0392b);
  background-size: 200% 100%;
  animation: gradShift 4s linear infinite;
  padding: 0.5rem 1rem;
  text-align: center;
  font-family: 'Syne', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.08em;
}
@keyframes gradShift { 0% { background-position: 0% 0%; } 100% { background-position: 200% 0%; } }

/* LEGEND */
.map-legend { position: absolute; top: 1rem; right: 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem; z-index: 40; min-width: 150px; }
.legend-title { font-family: 'Syne', sans-serif; font-size: 0.7rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.5rem; }
.legend-item { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.35rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-label { font-size: 0.72rem; color: var(--text-muted); }

/* PANEL VIEW */
.panel-view { display: none; padding: 1.25rem; overflow-y: auto; flex: 1; }
.panel-view.visible { display: block; }
.places-list.hidden { display: none; }
.hotline-grid { display: grid; gap: 0.75rem; }
.hotline-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 1rem 1.25rem; }
.hotline-number { font-family: 'Syne', sans-serif; font-size: 1.6rem; font-weight: 800; }
.hotline-name { font-size: 0.85rem; font-weight: 600; margin-top: 0.15rem; color: var(--text); }
.hotline-desc { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; line-height: 1.4; }

/* Leaflet */
.leaflet-container { background: #1a1a2e; }
.leaflet-popup-content-wrapper { border-radius: 10px !important; box-shadow: 0 8px 30px rgba(0,0,0,0.25) !important; }

/* ===== RESPONSIVE CORREGIDO ===== */
@media (max-width: 768px) {
  header { padding: 1rem 1rem 0; }
  .header-inner { flex-direction: column; align-items: stretch; }
  .logo-area p { max-width: 100%; }
  .sos-badge { width: 100%; justify-content: center; }

  .emergency-bar {
    font-size: 0.68rem;
    line-height: 1.5;
    letter-spacing: 0.02em;
    padding: 0.6rem 0.5rem;
  }

  .nav-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  .nav-tab {
    flex-shrink: 0;
    font-size: 0.7rem;
    padding: 0.6rem 0.8rem;
  }

  .main-layout {
    flex-direction: column;
    height: auto;
    max-width: 100%;
  }

  /* MAPA PRIMERO, LISTA DESPUÉS */
  #map-container {
    order: 1;
    width: 100%;
    height: 420px;
    flex: none;
  }
  .sidebar {
    order: 2;
    width: 100%;
    height: auto;
    max-height: none;
    border-right: none;
    border-top: 1px solid var(--border);
    overflow: visible;
  }
  .places-list {
    flex: none;
    max-height: 380px;
    overflow-y: auto;
  }

  .map-legend { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-panel { max-height: 60%; }
  .place-address, .place-tags, .place-phone { margin-left: 0; }
}

@media (max-width: 380px) {
  #map-container { height: 340px; }
  .logo-area h1 { font-size: 1.35rem; }
}
