:root{
  --ink: #1B2430;
  --ink-soft: #52606B;
  --teal: #1B6E86;
  --teal-deep: #124B5C;
  --coral: #E1633A;
  --violet: #7C3AED;
  --line: #DDE4E6;
  --sidebar-w: 300px;
}

*{ box-sizing: border-box; }

html, body{ height: 100%; margin: 0; }

body{
  font-family: 'Work Sans', sans-serif;
  color: var(--ink);
  overflow: hidden; /* el scroll vive dentro del sidebar, no de la página */
}

:focus-visible{
  outline: 3px solid var(--coral);
  outline-offset: 2px;
}

/* ---------- LAYOUT GENERAL ---------- */
.app-shell{
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
}

/* ---------- SIDEBAR ---------- */
.sidebar{
  flex: none;
  width: var(--sidebar-w);
  background: #FFFFFF;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.22s ease, box-shadow 0.22s ease;
  z-index: 1100;
}

.sidebar-inner{
  width: var(--sidebar-w);
  padding: 20px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar.collapsed{
  width: 0;
}

.sidebar-brand{
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.sidebar-brand img{ height: 36px; width: 36px; object-fit: contain; flex-shrink: 0; }
.sidebar-brand-text{
  font-family: 'Fraunces', serif;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.15;
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.sidebar-brand-text small{
  font-family: 'Work Sans', sans-serif;
  font-weight: 400;
  font-size: 0.68rem;
  color: var(--ink-soft);
}
.sidebar-brand-text small a{ color: var(--teal-deep); font-weight: 600; text-decoration: none; }
.sidebar-brand-text small a:hover{ text-decoration: underline; }

.sidebar-tagline{
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin: 0;
  line-height: 1.4;
}

.sidebar-cta{
  display: inline-block;
  background: var(--teal);
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
  padding: 9px 14px;
  border-radius: 7px;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s ease;
}
.sidebar-cta:hover{ background: var(--teal-deep); }

.sidebar-section{
  border-top: 1px solid var(--line);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-section-head{
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-label{
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
}

.sidebar-hint{
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin: -4px 0 2px;
}

.legend-item{
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.85rem;
  color: var(--ink);
}

.legend-toggle{
  cursor: pointer;
  justify-content: flex-start;
}
.legend-toggle input{
  margin-left: auto;
  width: 16px;
  height: 16px;
  accent-color: var(--violet, #7C3AED);
  cursor: pointer;
}

.legend-dot{
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}
.legend-pie{ background: #20c997; border: 1.5px solid #198754; }
.legend-especial{ background: #b794f4; border: 1.5px solid #6d28d9; }
/* Rosado más saturado y oscuro que el violeta, para que no se confundan (también con daltonismo) */
.legend-lenguaje{ background: #ec4899; border: 1.5px solid #9d174d; }
#toggle-lenguaje{ accent-color: #ec4899; }

#filtro-comuna, #direccion{
  font-family: 'Work Sans', sans-serif;
  font-size: 0.88rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}
#filtro-comuna:focus, #direccion:focus{
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(27,110,134,0.15);
}

.btn-limpiar{
  font-size: 0.76rem;
  color: var(--coral);
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 0;
}
.btn-limpiar:hover{ text-decoration: underline; }

.checkbox-list{
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ms-option{
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 4px;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
  border-radius: 6px;
}
.ms-option:hover{ background: #F1F4F5; }
.ms-option input{
  width: 16px;
  height: 16px;
  accent-color: var(--teal);
  flex-shrink: 0;
  cursor: pointer;
}

.sidebar-footer{
  border-top: 1px solid var(--line);
  padding-top: 14px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.sidebar-section.deshabilitado{
  opacity: 0.4;
  pointer-events: none;
}

/* ---------- BOTÓN PARA MOSTRAR/OCULTAR EL SIDEBAR ---------- */
.sidebar-toggle{
  position: absolute;
  top: 14px;
  left: calc(var(--sidebar-w) + 14px);
  z-index: 1200;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  color: var(--ink-soft);
  cursor: pointer;
  transition: left 0.22s ease;
}
.sidebar-toggle:hover{ color: var(--teal-deep); border-color: var(--teal); }
.sidebar.collapsed ~ .sidebar-toggle{ left: 14px; }

/* ---------- MAPA ---------- */
.map-area{
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  height: 100%;
}
#map{
  width: 100%;
  height: 100%;
}

.backdrop{
  display: none;
}

/* ---------- MOBILE: EL SIDEBAR SE CONVIERTE EN UN CAJÓN SUPERPUESTO ---------- */
@media (max-width: 780px){
  .sidebar{
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: min(300px, 84vw);
    box-shadow: 2px 0 16px rgba(0,0,0,0.18);
    transform: translateX(0%);
    transition: transform 0.22s ease;
  }
  .sidebar.collapsed{
    width: min(300px, 84vw); /* mantenemos el ancho, solo la deslizamos fuera de vista */
    transform: translateX(-100%);
  }
  .sidebar-inner{ width: min(300px, 84vw); }

  .sidebar-toggle{
    left: 14px !important; /* siempre pegado a la izquierda del mapa en mobile */
  }

  .backdrop{
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .app-shell.sidebar-open .backdrop{
    opacity: 1;
    pointer-events: auto;
  }
}

#lista-especialidades .ms-option input{ accent-color: var(--violet); }

/* ---------- BUSCAR CERCA DE UNA DIRECCIÓN ---------- */
.buscador-direccion{
  display: flex;
  gap: 6px;
}
.buscador-direccion input{ flex: 1; min-width: 0; }
#btn-buscar-direccion{
  font-family: 'Work Sans', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: var(--teal);
  border: none;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
}
#btn-buscar-direccion:hover{ background: var(--teal-deep); }
#btn-buscar-direccion:disabled{ opacity: 0.6; cursor: wait; }
.btn-ubicacion{
  margin-top: 8px;
  font-family: 'Work Sans', sans-serif;
  font-size: 0.82rem;
  color: var(--teal);
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.btn-ubicacion:hover{ background: #F1F4F5; }
#estado-cercanos:empty{ display: none; }
.lista-cercanos{
  list-style: none;
  margin: 8px 0 4px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lista-cercanos li button{
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  cursor: pointer;
  font-family: 'Work Sans', sans-serif;
  color: var(--ink);
}
.lista-cercanos li button:hover{ background: #F1F4F5; }
.lista-cercanos .legend-dot{ margin-top: 4px; flex-shrink: 0; }
.cercano-texto{ flex: 1; min-width: 0; font-size: 0.8rem; line-height: 1.3; }
.cercano-texto small{ display: block; color: var(--ink-soft); font-size: 0.74rem; }
.cercano-distancia{ font-size: 0.76rem; font-weight: 600; color: var(--teal); white-space: nowrap; }