/* ==========================================================================
   SHARED MAP - Estilos del mapa compartidos entre public home y admin home
   Cargado tanto por home.html como por home-admin.html a través de map.css
   ========================================================================== */

/* Contenedor del mapa */
.map-container {
    height: calc(100vh - 20rem);
    min-height: 400px;
    width: 100%;
    z-index: 1;
}

/* Popups de Leaflet */
.leaflet-popup-content-wrapper {
    border-radius: 0.5rem;
    padding: 0;
}

.leaflet-popup-content {
    margin: 0;
    width: 220px;
}

.station-popup {
    padding: 1rem;
}

.station-popup h3 {
    color: var(--chaco-azul);
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.station-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.status-indicator {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
}

.station-last-update {
    font-size: 0.875rem;
    color: #64748b;
    margin-bottom: 0.5rem;
}

.station-link {
    display: block;
    background-color: var(--chaco-azul) !important;
    border: 1px solid var(--chaco-azul) !important;
    color: #fff !important;
    text-align: center;
    padding: 8px;
    border-radius: 5px;
    text-decoration: none !important;
    font-weight: 600;
    transition: all 0.3s ease;
    font-size: 0.875rem;
}

.station-link:hover {
    background-color: var(--chaco-fondo-secundario) !important;
    border-color: var(--chaco-azul) !important;
    color: var(--chaco-azul) !important;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

.leaflet-popup-content .station-link,
.leaflet-popup-content .station-link:visited,
.leaflet-popup-content .station-link:active,
.content-page .leaflet-popup-content .station-link,
 .content-page .leaflet-popup-content .station-link:visited,
.content-page .leaflet-popup-content .station-link:active {
    background-color: var(--chaco-azul) !important;
    border-color: var(--chaco-azul) !important;
    color: #fff !important;
}

.leaflet-popup-content .station-link:hover,
.leaflet-popup-content .station-link:focus,
.leaflet-popup-content .station-link:focus-visible,
.content-page .leaflet-popup-content .station-link:hover,
 .content-page .leaflet-popup-content .station-link:focus,
.content-page .leaflet-popup-content .station-link:focus-visible {
    background-color: var(--chaco-fondo-secundario) !important;
    border-color: var(--chaco-azul) !important;
    color: var(--chaco-azul) !important;
}

/* Controles de zoom */
.leaflet-control-zoom {
    border: none;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2);
}

.leaflet-control-zoom a {
    border-radius: 0.25rem;
    color: var(--chaco-azul);
}

.leaflet-control-zoom a:hover {
    background-color: var(--chaco-fondo-secundario);
    color: var(--chaco-azul-oscuro);
}

/* Marcadores punto */
.point-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px white, 0 0 5px rgba(0, 0, 0, 0.5);
}

/* Leyenda del mapa */
.map-legend {
    background-color: white;
    padding: 0.75rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    margin: 1rem;
}

.legend-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--chaco-azul-oscuro);
    margin-bottom: 0.5rem;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-color {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 50%;
}

.legend-label {
    font-size: 0.75rem;
}

/* Leyenda del raster */
.raster-legend {
    min-width: 200px;
    max-width: 250px;
}

.raster-legend .legend-title {
    font-size: 0.9rem;
    margin-bottom: 5px;
    color: var(--chaco-azul-oscuro);
}

/* Métricas de estación (popup extendido) */
.station-metrics {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--chaco-borde);
}

.metric-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.metric-icon {
    font-size: 20px;
    color: var(--chaco-azul);
    margin-bottom: 5px;
}

.metric-value {
    font-weight: 600;
    font-size: 14px;
    color: var(--chaco-texto);
}

.metric-label {
    font-size: 12px;
    color: var(--chaco-texto-secondary);
}

.metric-legend {
    width: 100%;
    text-align: center;
    font-size: 0.8em;
    color: var(--chaco-texto-secondary);
    margin-top: 10px;
    padding-top: 5px;
    border-top: 1px solid var(--chaco-borde);
}

.dashboard-icon {
    margin-right: 5px;
}

/* Admin map height override: Upvex layout has header/sidebar, less space */
.content-page .map-container {
    height: calc(100vh - 220px);
    min-height: 400px;
}

/* Responsive */
@media (max-width: 768px) {
    .map-container {
        height: 50vh;
    }
}

/* ==========================================================================
   LAYERS DRAWER - Panel lateral de gestión de capas
   ========================================================================== */

/* 1. Floating toggle button (.layers-btn) */
.layers-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    left: auto;
    z-index: 1000;
    background: white;
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 0.625rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--chaco-texto);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.layers-btn:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}
.layers-btn i {
    color: var(--azul-ui);
}
.layers-btn .badge {
    background: var(--chaco-verde);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}
.layers-btn .badge:empty,
.layers-btn .badge[style*="display: none"] {
    display: none;
}

/* 2. Overlay (.layers-overlay) */
.layers-overlay {
    position: fixed;
    inset: 0;
    z-index: 999;
    background: rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.layers-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

/* 3. Drawer panel (.layers-drawer) */
.layers-drawer {
    position: fixed;
    top: 65px;
    right: 0;
    bottom: 0;
    width: 340px;
    max-width: 100vw;
    background: white;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
}
.layers-drawer.is-open {
    transform: translateX(0);
}

/* 4. Drawer header (.layers-drawer-header) */
.layers-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--chaco-borde);
    flex-shrink: 0;
}
.layers-drawer-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--chaco-texto);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.layers-drawer-title i {
    color: var(--azul-ui);
}
.layers-drawer-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--chaco-fondo-secundario);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--chaco-texto-secondary);
    font-size: 0.9rem;
    transition: background 0.15s ease;
}
.layers-drawer-close:hover {
    background: var(--chaco-borde);
    color: var(--chaco-texto);
}
.layers-drawer-header .active-count {
    font-size: 0.8rem;
    color: var(--chaco-texto-secondary);
    font-weight: 400;
    margin-left: 0.25rem;
}

/* 5. Search (.layers-search) */
.layers-search {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--chaco-borde);
    flex-shrink: 0;
}
.layers-search-wrapper {
    position: relative;
}
.layers-search-wrapper i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chaco-texto-secondary);
    font-size: 0.875rem;
}
.layers-search-input {
    width: 100%;
    padding: 0.625rem 0.875rem 0.625rem 2.5rem;
    border: 1.5px solid var(--chaco-borde);
    border-radius: var(--radius);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--chaco-texto);
    background: var(--chaco-fondo-secundario);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.layers-search-input::placeholder {
    color: var(--chaco-texto-secondary);
}
.layers-search-input:focus {
    outline: none;
    border-color: var(--azul-ui);
    background: white;
    box-shadow: 0 0 0 3px rgba(80, 89, 188, 0.1);
}

/* 6. Drawer content with layer list (.layers-drawer-content) */
.layers-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}
.layer-group-header {
    padding: 0.5rem 1.25rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--chaco-texto-secondary);
    background: var(--chaco-fondo-secundario);
    position: sticky;
    top: 0;
    z-index: 1;
}
.layer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.25rem;
    cursor: pointer;
    transition: background 0.1s ease;
    gap: 0.75rem;
}
.layer-row:hover {
    background: var(--chaco-fondo-secundario);
}
.layer-row.active {
    background: rgba(141, 198, 63, 0.06);
}
.layer-row-info {
    flex: 1;
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}
.layer-row-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--chaco-texto);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
    position: relative;
    display: block;
}
.layer-row.active .layer-row-name {
    font-weight: 600;
}
.layer-row-period {
    font-size: 0.75rem;
    color: var(--chaco-texto-secondary);
    display: block;
}
/* Tooltip via native title attribute - browser handles the rest */

/* 7. Toggle switch (.layer-toggle) */
.layer-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}
.layer-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}
.layer-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #c8d0d8;
    border-radius: 999px;
    transition: background 0.2s ease;
}
.layer-toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.layer-toggle input:checked + .layer-toggle-slider {
    background: var(--chaco-verde);
}
.layer-toggle input:checked + .layer-toggle-slider::before {
    transform: translateX(20px);
}
.layer-toggle input:focus-visible + .layer-toggle-slider {
    box-shadow: 0 0 0 3px rgba(141, 198, 63, 0.3);
}

/* 8. Drawer footer (.layers-drawer-footer) */
.layers-drawer-footer {
    padding: 0.875rem 1.25rem;
    border-top: 1px solid var(--chaco-borde);
    flex-shrink: 0;
    display: flex;
    gap: 0.75rem;
    opacity: 1;
    transition: opacity 0.2s ease;
}
.layers-drawer-footer.is-hidden {
    opacity: 0;
    pointer-events: none;
}
.btn-clear-all {
    flex: 1;
    padding: 0.625rem;
    border: 1.5px solid var(--chaco-borde);
    border-radius: var(--radius);
    background: white;
    color: var(--chaco-texto-secondary);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s ease, color 0.15s ease;
}
.btn-clear-all:hover {
    border-color: var(--chaco-texto-secondary);
    color: var(--chaco-texto);
}

/* 9. No results state */
.layers-no-results {
    padding: 2rem 1.25rem;
    text-align: center;
    color: var(--chaco-texto-secondary);
    font-size: 0.875rem;
    display: none;
}
.layers-no-results.is-visible {
    display: block;
}
.layers-no-results i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--chaco-borde);
}

/* 10. Responsive */
@media (max-width: 576px) {
    .layers-drawer {
        width: 100vw;
    }
    .layers-btn {
        top: 0.75rem;
        right: 0.75rem;
        padding: 0.5rem 0.875rem;
        font-size: 0.8rem;
    }
}

/* 11. Ensure the drawer layer list item text doesn't overflow on smaller screens */
@media (max-width: 768px) {
    .layers-drawer {
        width: 300px;
    }
    .layer-row-name {
        max-width: 180px;
    }
}
