/* --- assets/css/stats.css --- */

/* =================================================================== */
/* ESTRUCTURA PRINCIPAL DE STATS                                       */
/* =================================================================== */

/* Contenedor central donde irán las tablas y gráficos */
#stats-main {
    width: 100%;
    max-width: 1200px;
    margin: 2rem auto;
    min-height: 40vh;
    /* Para que el footer no suba demasiado si está vacío */
}

/* =================================================================== */
/* AJUSTES ESPECÍFICOS DE UI                                           */
/* =================================================================== */

/* Retoques para el botón "Volver al Clima" (ID reutilizado btnStats) */
#btnStats {
    text-decoration: none;
    border: none;
    margin-right: 5px;
    /* El estado visible/invisible lo maneja iotAuthLogin.js, 
       pero definimos el estado inicial aquí */
    display: none;
}

/* =================================================================== */
/* IMÁGENES DE FONDO (Backgrounds)                                     */
/* =================================================================== */

/* 
   NOTA: Las rutas son relativas al archivo .CSS.
   Como estamos en /assets/css/, tenemos que subir dos niveles (../../)
   para llegar a la carpeta /images/
*/

#bg div:nth-child(1) {
    background-image: url('../../images/bg01.jpg');
}

#bg div:nth-child(2) {
    background-image: url('../../images/bg02.jpg');
}

#bg div:nth-child(3) {
    background-image: url('../../images/bg03.jpg');
}

/* =================================================================== */
/* PROTECCIÓN DE CONTENIDO (Access Control)                            */
/* =================================================================== */

/* 1. Ocultamos el contenido principal por defecto */
/* AÑADIDO: !important para vencer los estilos fuertes del #footer en main_even.css */
.protected-content {
    display: none !important;
    opacity: 0;
}

/* 2. Clase que añade JS cuando detecta login correcto */
body.is-authenticated .protected-content {
    display: block !important;
    /* Forzamos mostrar */
    animation: fadeInContent 1s forwards;
}

/* 3. EXCEPCIÓN IMPORTANTE: El footer necesita ser 'flex', no 'block' */
/* Si no ponemos esto, al desbloquearse el footer perderá su centrado */
body.is-authenticated footer.protected-content {
    display: flex !important;
}

@keyframes fadeInContent {
    to {
        opacity: 1;
    }
}

/* 3. Mensaje de "Acceso Restringido" */
#access-warning {
    /* CAMBIO IMPORTANTE: De absolute a fixed */
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);

    text-align: center;
    width: 90%;
    max-width: 600px;

    background: rgba(0, 0, 0, 0.85);
    /* Un poco más oscuro */
    backdrop-filter: blur(5px);
    /* Efecto borroso detrás */
    border: 1px solid #ff3e4d;
    padding: 3rem 2rem;
    /* Un poco más de aire */
    border-radius: 12px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    /* Sombra fuerte para tapar lo de atrás */

    /* Aseguramos que esté por encima de TODO, incluso del login */
    z-index: 9999;
}

/* Si estamos autenticados, ocultamos el aviso */
body.is-authenticated #access-warning {
    display: none !important;
}

#access-warning h2 {
    color: #ff3e4d;
    font-size: 1.8em;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

#access-warning p {
    font-size: 1.1em;
    color: #e0e0e0;
    line-height: 1.6;
}

#access-warning i {
    font-size: 4em;
    color: #ff3e4d;
    margin-bottom: 1.5rem;
    display: block;
    animation: pulseLock 2s infinite;
}

@keyframes pulseLock {
    0% {
        opacity: 0.8;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
        text-shadow: 0 0 20px #ff3e4d;
    }

    100% {
        opacity: 0.8;
        transform: scale(1);
    }
}

/* --- AÑADIR A assets/css/stats.css --- */

/* Utility: Panel de Cristal Genérico */
.glass-panel {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(5px);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* 1. BARRA DE CONTROLES */
.stats-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    align-items: center;
    justify-content: center;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* FIX: Forzamos que la etiqueta y el icono estén en línea */
.control-group label {
    display: flex;
    /* Flexbox para alinear icono y texto */
    align-items: center;
    /* Centrado vertical */
    gap: 6px;
    /* Espacio entre el icono y la palabra */
    margin: 0;
    color: #f5c842;
    font-size: 0.9em;
    white-space: nowrap;
    /* Evita que se rompa la línea */
}

/* Inputs de fecha oscuros */
.glass-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #fff;
    padding: 8px 12px;
    font-family: 'Roboto', sans-serif;
    color-scheme: dark;
    /* Fuerza calendario oscuro en navegadores modernos */
}

.action-btn {
    background-color: #1cb495;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.2s;
}

.action-btn:hover {
    background-color: #17a187;
}

/* 2. KPI GRID */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.2rem;
    transition: transform 0.2s;
}

.kpi-card:hover {
    transform: translateY(-5px);
    border-color: #1cb495;
}

.kpi-icon {
    font-size: 2em;
    color: #1cb495;
    background: rgba(28, 180, 149, 0.1);
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.kpi-data h3 {
    font-size: 1.8em;
    margin: 0;
    color: #fff;
    line-height: 1;
}

.kpi-data p {
    margin: 5px 0 0 0;
    font-size: 0.8em;
    color: rgba(255, 255, 255, 0.6);
    text-transform: uppercase;
}

/* 3. CHART WRAPPER */
.chart-wrapper h3 {
    color: #f5c842;
    font-size: 1.1em;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

/* 4. TABLA */
.table-wrapper h3 {
    color: #f5c842;
    font-size: 1.1em;
    margin-bottom: 1rem;
}

.table-scroll {
    overflow-x: auto;
    max-height: 400px;
    /* Scroll vertical si es muy larga */
}

table#logsTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
}

table#logsTable th {
    text-align: left;
    padding: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: #1cb495;
    position: sticky;
    top: 0;
}

table#logsTable td {
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.8);
}

table#logsTable tr:hover td {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
}

/* --- assets/css/stats.css --- */

/* ... (MANTÉN TODO LO ANTERIOR) ... */


/* =================================================================== */
/* FIXES DE USABILIDAD Y SCROLL                                        */
/* =================================================================== */

/* 1. Arreglo del Scroll "bloqueado" en los laterales */
/* Sobreescribimos el main_even.css para permitir que la página crezca */
html,
body {
    height: auto !important;
    min-height: 100% !important;
    overflow-y: auto !important;
    /* Devuelve el control a la barra nativa */
}

/* 2. Botón Filtrar: Centrado perfecto */
#btnFilterStats {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    /* Espacio entre icono y texto */
    height: 40px;
    /* Altura fija para alinearse con los inputs */
    line-height: 1;
    margin-top: 2px;
    /* Pequeño ajuste visual */
}

/* 3. Inputs Select (Estilo Glass igual que los date) */
select.glass-input {
    appearance: none;
    /* Quitar estilo nativo feo */
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' viewBox='0 0 40 40'%3E%3Cpath d='M9.4,12.3l10.4,10.4l10.4-10.4c0.2-0.2,0.5-0.4,0.9-0.4c0.3,0,0.6,0.1,0.9,0.4l3.3,3.3c0.2,0.2,0.4,0.5,0.4,0.9 c0,0.4-0.1,0.6-0.4,0.9L20.7,31.9c-0.2,0.2-0.5,0.4-0.9,0.4c-0.3,0-0.6-0.1-0.9-0.4L4.3,17.3c-0.2-0.2-0.4-0.5-0.4-0.9 c0-0.4,0.1-0.6,0.4-0.9l3.3-3.3c0.2-0.2,0.5-0.4,0.9-0.4S9.1,12.1,9.4,12.3z' fill='rgba(255, 255, 255, 0.5)' /%3E%3C/svg%3E");
    background-size: 1rem;
    background-repeat: no-repeat;
    background-position: calc(100% - 10px) center;
    padding-right: 2rem;
    cursor: pointer;
}

select.glass-input option {
    background: #1b1b1b;
    color: #fff;
}

/* --- assets/css/stats.css --- */

/* ... (Mantén lo anterior) ... */

/* =================================================================== */
/* 3. CHART WRAPPER & TOP 5 SIDEBAR                                    */
/* =================================================================== */

/* Cabecera del Gráfico (Flex para alinear Título y Selector) */
.chart-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.8rem;
    flex-wrap: wrap;
    gap: 10px;
}

/* Alineación Icono + Texto Evolución */
.chart-header-row h3 {
    margin: 0;
    border: none;
    display: flex;
    /* Flexbox para el icono y texto */
    align-items: center;
    gap: 10px;
    /* Espacio entre icono y texto */
    color: #f5c842;
    font-size: 1.2em;
}

/* Selector Compacto (Menos ancho) */
.compact-select {
    font-size: 0.85em;
    padding: 6px 12px;
    height: auto;
    width: auto;
    /* Que ocupe solo lo necesario */
    max-width: 250px;
    /* Tope máximo para que no se desmadre */
    min-width: 150px;
}

/* Rejilla Principal: Gráfico (Flexible) | Lista (Fijo 250px aprox) */
.chart-body-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    /* Gráfico | Barra lateral */
    gap: 2rem;
    align-items: start;
}

.chart-canvas-container {
    position: relative;
    height: 350px;
    width: 100%;
}

/* Barra Lateral Top 5 */
.chart-sidebar {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    height: 100%;
    max-height: 350px;
    overflow-y: auto;
    /* Scroll si la lista es larga */
}

.chart-sidebar h4 {
    margin: 0 0 1rem 0;
    color: #1cb495;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 0.5rem;
}

/* Lista Top 5 */
ul.top-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

ul.top-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.85em;
    color: rgba(255, 255, 255, 0.8);
}

ul.top-list li:last-child {
    border-bottom: none;
}

ul.top-list li span.count {
    background: rgba(28, 180, 149, 0.2);
    color: #1cb495;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: bold;
    font-size: 0.9em;
}

ul.top-list li span.label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 180px;
    /* Cortar textos muy largos como UserAgents */
}

/* Responsive: En móvil, columna única */
@media (max-width: 800px) {
    .chart-body-grid {
        grid-template-columns: 1fr;
        /* Una columna */
    }

    .chart-sidebar {
        max-height: none;
    }
}