/* =============================================
   Escuelas Map Plugin - Styles v5
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&family=Open+Sans:wght@400;600&display=swap');

/* =============================================
   DESKTOP — flex row, sidebar | map
   ============================================= */

.escuelas-map-container {
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 600px;
    font-family: 'Open Sans', sans-serif;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0,0,0,0.12);
    position: relative; /* anchor for overlay */
    background: #f5f7fa;
}

/* ---- Sidebar ---- */
.em-sidebar {
    width: 320px;
    min-width: 280px;
    flex-shrink: 0;
    background: #fff;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e8edf2;
    height: 100%;
    overflow: hidden;
    /* z-index normal en desktop */
    position: relative;
    z-index: 2;
}

.em-sidebar-header {
    padding: 18px 16px 12px;
    border-bottom: 1px solid #e8edf2;
    flex-shrink: 0;
}

.em-sidebar-title {
    font-family: 'Nunito', sans-serif;
    font-size: 22px;
    font-weight: 800;
    color: #2e87c8;
    margin: 0 0 12px;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

/* ---- Search ---- */
.em-search-wrap { position: relative; }

.em-search-input {
    width: 100%;
    padding: 9px 36px 9px 12px;
    border: 1.5px solid #dde4ec;
    border-radius: 8px;
    font-size: 13px;
    color: #3a4a5c;
    background: #f5f8fb;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    font-family: inherit;
}
.em-search-input:focus {
    border-color: #2e87c8;
    box-shadow: 0 0 0 3px rgba(46,135,200,0.12);
    background: #fff;
}
.em-search-icon {
    position: absolute;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    width: 16px; height: 16px;
    color: #99a8b8;
    pointer-events: none;
}

/* ---- List ---- */
.em-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
    scrollbar-width: thin;
    scrollbar-color: #c8d5e0 transparent;
    -webkit-overflow-scrolling: touch;
}
.em-list::-webkit-scrollbar { width: 5px; }
.em-list::-webkit-scrollbar-thumb { background: #c8d5e0; border-radius: 4px; }

.em-item {
    display: flex;
    align-items: flex-start;
    padding: 12px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    gap: 10px;
}
.em-item:hover { background: #f0f6fb; }
.em-item.active {
    border-left-color: #2e87c8;
    background-color: rgba(46,135,200,0.08);
}
.em-item.hidden { display: none !important; }

.em-item-pin {
    flex-shrink: 0;
    width: 22px; height: 22px;
    color: #2e87c8;
    margin-top: 2px;
    transition: transform 0.2s;
}
.em-item:hover .em-item-pin,
.em-item.active .em-item-pin { transform: scale(1.2); }
.em-item-pin svg { width: 100%; height: 100%; }

.em-item-content { flex: 1; min-width: 0; }
.em-item-name {
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 13px;
    color: #1e2d3d;
    line-height: 1.3;
    margin-bottom: 2px;
}
.em-item-city {
    font-size: 11px;
    font-weight: 700;
    color: #2e87c8;
    margin-bottom: 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.em-item-address {
    font-size: 11px;
    color: #7a8fa3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

/* ---- Touch blocker ---- */
.em-touch-blocker {
    display: none; /* shown only on mobile via media query */
    position: absolute;
    inset: 0;
    z-index: 400;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.em-touch-hint {
    background: rgba(0,0,0,0.72);
    color: #fff;
    padding: 12px 18px;
    border-radius: 10px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 220px;
    text-align: center;
    opacity: 0;
    transition: opacity 0.25s;
    line-height: 1.3;
}
.em-touch-hint.show { opacity: 1; }
.em-touch-hint svg { width: 24px; height: 24px; flex-shrink: 0; }

/* ---- Popup ---- */
.em-popup-inner {
    padding: 14px 16px;
    min-width: 200px;
    max-width: 260px;
}
.em-popup-nombre {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 14px;
    color: #1e2d3d;
    margin-bottom: 3px;
    line-height: 1.3;
}
.em-popup-ciudad {
    font-size: 11px;
    font-weight: 700;
    color: #2e87c8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 9px;
}
.em-popup-row {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    margin-bottom: 5px;
    font-size: 11.5px;
    color: #4a5e72;
    line-height: 1.4;
    font-family: 'Open Sans', sans-serif;
}
.em-popup-row svg { flex-shrink: 0; width: 13px; height: 13px; color: #2e87c8; margin-top: 1px; }

/* ---- Markers ---- */
.em-marker-icon { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; }
.em-marker-icon svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 5px rgba(0,0,0,0.28)); transition: transform 0.18s; }
.em-marker-icon.active svg { transform: scale(1.35); }

/* ---- Mobile toggle (hidden on desktop) ---- */
.em-mobile-toggle {
    display: none;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: #2e87c8;
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 10px 22px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    align-items: center;
    gap: 7px;
    box-shadow: 0 4px 16px rgba(46,135,200,0.45);
    z-index: 600;
    transition: background 0.2s;
    white-space: nowrap;
    line-height: 1;
}
.em-mobile-toggle:hover,
.em-mobile-toggle.is-open { background: #1a6fa8; }
.em-btn-bottom { bottom: 16px; top: auto; }
.em-btn-top    { top: 14px;   bottom: auto; }

/* ---- Overlay (hidden by default) ---- */
.em-sidebar-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 299; /* below sidebar (300), above map */
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
}
.em-sidebar-overlay.is-visible {
    display: block;
}

/* =============================================
   MOBILE — sidebar se convierte en drawer
   El container pasa a ser un bloque con altura
   fija para el mapa + el panel debajo.
   ============================================= */
@media (max-width: 768px) {

    /* Container: bloque, no flex-row */
    .escuelas-map-container {
        flex-direction: column;
        height: auto !important;
        border-radius: 8px;
        overflow: visible;   /* sidebar drawer puede salir del borde */
        position: relative;  /* anchor para absolute children */
    }

    /* Mapa: z-index:1 crea un stacking context aislado para Leaflet.
       Sus capas internas (z-index 400, 600…) quedan confinadas
       y no compiten con el sidebar del container padre. */
    .em-map-area {
        width: 100%;
        height: 420px;
        flex: none;
        position: relative;
        z-index: 1;
        overflow: hidden;
        border-radius: 8px 8px 0 0;
    }

    /* El mapa llena su contenedor */
    .em-map {
        position: absolute;
        inset: 0;
    }

    /* Sidebar: position absolute relativo al container (position:relative).
       z-index:10 — sobre em-map-area (z-index:1), mismo contexto. */
    .em-sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 82% !important;
        min-width: unset !important;
        max-width: 290px;
        height: 420px;
        transform: translateX(-110%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 10;
        box-shadow: 4px 0 24px rgba(0,0,0,0.25);
        border-right: none;
        border-radius: 0;
    }
    .em-sidebar.is-open {
        transform: translateX(0);
    }

    /* Overlay: entre mapa (z:1) y sidebar (z:10) */
    .em-sidebar-overlay {
        position: absolute;
        top: 0; left: 0;
        width: 100%;
        height: 420px;
        z-index: 5;
    }

    /* Mostrar botón toggle */
    .em-mobile-toggle {
        display: flex;
    }

    /* Mostrar touch blocker */
    .em-touch-blocker {
        display: flex;
    }
}

@media (max-width: 480px) {
    .em-map-area  { height: 360px; }
    .em-sidebar   { height: 360px; }
    .em-sidebar-overlay { height: 360px; }
    .em-popup-inner { min-width: 160px; max-width: 210px; }
    .em-popup-nombre { font-size: 13px; }
}

/* =============================================
   Leaflet overrides
   ============================================= */
.leaflet-popup-content-wrapper {
    border-radius: 10px !important;
    padding: 0 !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.16) !important;
    overflow: hidden;
}
.leaflet-popup-content { margin: 0 !important; width: auto !important; }
.leaflet-popup-tip { background: #fff !important; }
.leaflet-popup-close-button {
    top: 6px !important; right: 8px !important;
    color: #99a8b8 !important;
    font-size: 20px !important;
}
.leaflet-touch .leaflet-control-zoom { border: none !important; }
.leaflet-control-zoom a { border-radius: 6px !important; }
