/* === ESTRUCTURA GENERAL (LAYOUT) ESTRICTA === */
html, body {
    height: 100%; /* Usa exactamente el alto de la ventana, ni un pixel más */
    margin: 0;
    padding: 0;
    overflow: hidden !important; /* Corta de cuajo cualquier scroll en la ventana principal */
    background-color: #f8f9fa;
}

body {
    display: flex;
    flex-direction: column;
}

/* Banner Pruebas */
.banner-pruebas {
    flex: 0 0 auto; /* Toma su espacio y no cede ni crece */
    background-color: #ffc107 !important;
    color: #212529 !important;
    text-align: center;
    padding: 0.5rem 0;
    font-weight: bold;
    font-size: 0.9rem;
    border-bottom: 1px solid #d39e00;
    width: 100%;
    position: relative;
    z-index: 1100;
}

#wrapper {
    flex: 1 1 auto; /* Toma todo el espacio que SOBRA debajo del banner */
    display: flex;
    width: 100%;
    overflow: hidden; /* Nada sale de acá */
}

/* === SIDEBAR (Barra Lateral) === */
#sidebar-wrapper {
    width: 280px;
    flex: 0 0 280px; /* Fija el ancho exacto sin importar qué pase */
    display: flex;
    flex-direction: column;
    background-color: #0097a7 !important;
    color: #fff;
    z-index: 1050;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    transition: margin 0.3s ease-out;
    /* Redondeamos solo las esquinas derechas */
    border-top-right-radius: 16px;
    border-bottom-right-radius: 16px;
    
    /* Opcional: Una sombra muy suave para que el borde redondeado resalte y se separe del mapa */
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.08);
    
    /* Evita que los elementos internos (como los enlaces) se salgan del borde redondeado */
    overflow: hidden;
}

/* El logo (encabezado) queda fijo arriba */
.sidebar-heading {
    flex-shrink: 0;
}

/* La lista de links es la ÚNICA que tiene scroll en el menú */
#sidebar-wrapper .flex-grow-1 {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}

/* Scrollbar estética para Chrome/Safari */
#sidebar-wrapper .flex-grow-1::-webkit-scrollbar { width: 4px; }
#sidebar-wrapper .flex-grow-1::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 10px; }

/* El footer (Cerrar Sesión) queda SIEMPRE abajo */
#sidebar-wrapper .border-top {
    flex-shrink: 0;
    margin-top: auto; 
    background-color: #00838F; 
}

/* Items del menú */
.list-group-item {
    border: none;
    padding: 0.8rem 1.5rem;
    background-color: transparent; 
    color: #fff !important; 
    text-decoration: none;
}

.list-group-item:hover {
    background-color: rgba(0, 0, 0, 0.1) !important;
    padding-left: 1.8rem;
    transition: all 0.2s;
    /* Deja un pequeño espacio a los costados para que no choquen con el borde */
    margin: 4px 8px; 
    
    /* Redondea los botones internos */
    border-radius: 8px; 
    
    /* Quita los bordes duros por defecto */
    border: none;
}

/* === RESPONSIVE (CELULARES Y PC) === */
@media (max-width: 767px) {
    #sidebar-wrapper {
        position: fixed;
        margin-left: -280px; /* Escondido por defecto en celular */
        height: 100%;
    }
    #wrapper.toggled #sidebar-wrapper {
        margin-left: 0; /* Aparece al tocar Menú */
    }
}

@media (min-width: 768px) {
    #sidebar-wrapper {
        margin-left: 0; /* Visible por defecto en PC */
    }
    #wrapper.toggled #sidebar-wrapper {
        margin-left: -280px; /* Se esconde al tocar Menú en PC */
    }
}

/* === CONTENIDO PRINCIPAL === */
#page-content-wrapper {
    flex: 1 1 auto;
    display: flex; /* CLAVE: Convertimos el espacio derecho en un contenedor flexible */
    flex-direction: column;
    overflow-y: auto; 
    overflow-x: hidden;
    position: relative;
    width: 100%;
}

/* Overlay para móviles */
#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
}
@media (max-width: 767px) {
    #wrapper.toggled #sidebar-overlay { display: block; }
}

/* === ESTILOS DE WIDGETS Y GRÁFICOS === */
.widget-icon-bg { width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.widget-icon-bg i { font-size: 1.5rem; }
.widget-value { line-height: 1; }
.widget-timestamp { font-size: 0.75rem; }
.widget-gauge-thermo .progress, .widget-gauge-level .progress { width: 20px; flex-direction: column-reverse; }
.widget-gauge-thermo .progress-bar, .widget-gauge-level .progress-bar { width: 100%; transition: height 0.5s ease-out; }
.green-dot-icon { background-color: #198754; border: 2px solid #ffffff; box-shadow: 0 0 5px rgba(0,0,0,0.5); border-radius: 50%; width: 12px; height: 12px; margin-left: -8px; margin-top: -8px; }
.chart-wrapper { width: 100%; min-height: 550px; margin-bottom: 2rem; border: 1px solid #dee2e6; border-radius: 0.375rem; padding: 1rem; }

/* === MAPA Y TABLAS === */
.full-screen-map-container { 
    flex: 1; /* CLAVE: Le dice al mapa que se expanda para llenar todo el hueco disponible */
    min-height: 500px; 
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
}

.full-h { 
    height: 100%; 
    width: 100%; 
    flex: 1;
}

.table-responsive { border: 0; -webkit-overflow-scrolling: touch; }

/* Colores de Estado */
.bg-success { background-color: #4caf50 !important; color: white !important; }
.bg-danger { background-color: #f44336 !important; color: white !important; }
.bg-warning { background-color: #ffc107 !important; color: #212529 !important; }
.matriz-gris { background-color: #9e9e9e !important; color: white !important; }
.bg-critical { background-color: #b71c1c !important; color: white !important; }

.tarjeta-estado { transition: transform 0.2s; border-radius: 12px; }
.tarjeta-estado:hover { transform: translateY(-5px); }

/* =========================================
   ESTILOS ESPECÍFICOS DEL MAPA (LEAFLET)
   ========================================= */

/* Estilo para los popups de Leaflet */
.popup-custom .leaflet-popup-content-wrapper { 
    border-radius: 8px; 
    padding: 0; 
    overflow: hidden; 
}
.popup-custom .leaflet-popup-content { 
    margin: 12px; 
    width: 260px !important; 
}

/* Cartelito de ID de las estaciones */
.id-tooltip {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid #666;
    border-radius: 5px;
    padding: 2px 6px;
    font-size: 13px;
    font-weight: 800;
    color: #000;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.3);
    white-space: nowrap;
}

/* Ocultar etiquetas al alejar el zoom */
.zoom-hide-labels .leaflet-tooltip {
    display: none !important;
}

/* Etiquetas transparentes para nombres de EMAs */
.leaflet-tooltip.ema-label { 
    background-color: transparent; 
    border: none; 
    box-shadow: none; 
    font-weight: bold; 
    font-size: 12px; 
    color: #000; 
    text-shadow: -1px -1px 0 #fff, 1px -1px 0 #fff, -1px 1px 0 #fff, 1px 1px 0 #fff; 
}

/* Icono de capas del mapa personalizado */
.leaflet-control-layers-toggle { 
    background-image: none !important; 
    width: 36px !important; 
    height: 36px !important; 
}
.leaflet-control-layers-toggle::before { 
    font-family: "bootstrap-icons" !important; 
    content: "\F542"; 
    font-size: 20px; 
    color: #555; 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%); 
}
.leaflet-control-layers-toggle:hover::before { color: #000; }