/* ==========================================
   1. VARIABLES Y ESTILOS GLOBALES
   ========================================== */
:root {
    --blue-primary: #337ab7;
    --blue-dark: #286090;
    --bg-gray: #f4f4f4;
    --bg-light: #ffffff;
    --card-bg: #eeeeee;
    --text-main: #333333;
    --text-light: #666666;
    --border-color: #bcd1e6;
    --success: #27ae60;
    --warning: #856404;
    --warning-bg: #fff3cd;
    --success-bg: #d4edda;
}

body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-gray);
    overflow: hidden; 
}

/* ==========================================
   2. SECCIÓN DE LOGIN
   ========================================== */
.split-container { 
    display: flex; 
    height: 100vh; 
    width: 100%; 
}

.login-left {
    flex: 1;
    background: linear-gradient(135deg, #4a90e2 0%, #9013fe 100%);
    background-image: url('https://images.unsplash.com/photo-1557683316-973673baf926?auto=format&fit=crop&q=80&w=1000');
    background-size: cover; 
    background-position: center;
    display: flex; 
    justify-content: center; 
    align-items: center;   
}

.login-right { 
    flex: 1; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    background-color: var(--bg-light); 
    padding: 20px;
    overflow-y: auto;
}

.login-content { 
    width: 100%; 
    max-width: 400px; 
}

.main-logo { 
    max-width: 400px; 
    filter: drop-shadow(0px 4px 10px rgba(0,0,0,0.3)); 
}

.welcome-text h1 {
    margin: 5px 0 30px 0; 
    font-size: 2.5rem; 
    font-weight: 300;
}

.welcome-text h1 span { 
    font-weight: 700; 
}

.input-group { 
    position: relative; 
    margin-bottom: 25px; 
}

.input-group label { 
    position: absolute; 
    top: -10px; 
    left: 15px; 
    background: white; 
    padding: 0 5px; 
    font-size: 12px; 
    color: var(--blue-primary); 
    z-index: 1;
}

.input-group input { 
    width: 100%; 
    padding: 15px; 
    border: 1.5px solid var(--border-color); 
    border-radius: 8px; 
    box-sizing: border-box; 
    font-size: 14px; 
    outline: none;
}

.input-group .icon {
    position: absolute;
    right: 15px;
    top: 15px;
    color: #ccc;
}

#btnLogin {
    width: 100%;
    padding: 15px;
    background-color: var(--blue-primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s;
    display: flex; 
    justify-content: center;
    align-items: center;
    position: relative;
}

/* ==========================================
   3. DASHBOARD (ESTRUCTURA PRINCIPAL)
   ========================================== */
.dashboard-container { 
    display: flex; 
    height: 100vh; 
    width: 100%; 
    overflow: hidden; 
}

.sidebar {
    width: 250px; 
    min-width: 250px;
    flex-shrink: 0;
    background-color: var(--blue-primary); 
    color: white; 
    display: flex; 
    flex-direction: column; 
    padding: 30px 20px; 
    box-sizing: border-box; 
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 400;
    line-height: 1.3;
    margin-bottom: 40px;
}

.sidebar-nav {
    flex-grow: 1; 
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.menu-item {
    width: 100%;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    padding: 12px 20px; 
    text-align: left;
    border-radius: 8px; 
    font-size: 1rem; 
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 65px; 
    display: flex;
    align-items: center;
}

.menu-item.active, .menu-item:hover {
    background: rgba(255, 255, 255, 0.25);
    font-weight: 600;
}

.logout-btn {
    background: none;
    border: none;
    color: white; 
    font-size: 1.1rem; 
    cursor: pointer; 
    display: flex; 
    align-items: center;
    gap: 12px;
    font-weight: 500; 
}

.main-content { 
    flex-grow: 1; 
    background-color: var(--bg-light); 
    padding: 30px 40px; 
    overflow-y: auto; 
    display: flex; 
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
}

/* ==========================================
   4. COMPONENTES Y GRIDS
   ========================================== */
.survey-subtitle { 
    font-size: 1.1rem; 
    color: var(--text-light); 
    margin-bottom: 30px; }

.question-item { 
    margin-bottom: 12px; 
    animation: fadeIn 0.5s ease; }
    
.question-item label { 
    font-weight: 600; 
    display: block; 
    margin-bottom: 12px; }

.rating-group { 
    display: flex; 
    gap: 10px; }
    
.rating-option { 
    flex: 1; 
    text-align: center; 
    padding: 8px; 
    border: 1px solid #ddd; 
    border-radius: 8px; 
    cursor: pointer; 
    background: #fff; 
    transition: all 0.2s; }
    
.rating-option.selected { 
    background: var(--blue-primary); 
    color: white; 
    font-weight: 700; 
    border-color: var(--blue-primary); }

.options-grid { 
    display: grid; 
    grid-template-columns: repeat(3, 1fr); 
    gap: 15px; }

.text-libre { 
    width: 100%; 
    padding: 10px; 
    border: 1px solid #ddd; 
    border-radius: 8px; 
    box-sizing: border-box; 
    resize: vertical; 
    font-family: inherit; }

.form-footer { 
    display: flex; 
    justify-content: flex-end; 
    margin-top: 40px; 
    padding-bottom: 40px; }

#btnEnviar, #btnEnviarEval, #btnEnviarSupEval {
    background-color: var(--blue-primary); 
    color: white; 
    border: none; 
    padding: 14px 40px; 
    font-size: 16px; 
    font-weight: 600; 
    border-radius: 8px; 
    cursor: pointer; 
    min-width: 240px; 
    height: 52px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    position: relative;
}

.correctores-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); 
    gap: 20px;
    margin-bottom: 20px;
}
.corr-card {
    background: white; 
    border: 1px solid #ddd; 
    border-radius: 12px; 
    padding: 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    cursor: pointer; 
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.corr-info h3 { 
    margin: 0; 
    font-size: 1.1rem; 
    line-height: 1.2; 
}

.corr-info p { 
    margin: 2px 0 0 0 !important; 
    color: var(--text-light); 
    font-size: 0.9rem; 
}

.welcome-gif { max-width: 90px; height: auto; margin-top: 0 !important; }

/* Bloqueo profesional durante carga asíncrona */
.form-block-overlay {
    pointer-events: none; /* Evita clics */
    opacity: 0.5;        /* Efecto visual de 'desactivado' */
    filter: grayscale(0.5);
    transition: opacity 0.4s ease;
}

/* Animación de entrada para los campos cuando se desbloquean */
#surveyForm:not(.form-block-overlay) {
    opacity: 1;
    filter: none;
}

/* Spinner de título discreto */
.fa-spin {
    animation: spin 1s linear infinite;
}

/* ==========================================
   ESTILOS PARA FORMULARIOS FINALIZADOS (READONLY)
   ========================================== */

/* 1. Apagar el color de la opción seleccionada */
.readonly .rating-option.selected {
    background: #9eb6c9 !important; /* Un azul grisáceo apagado */
    border-color: #9eb6c9 !important;
    color: white !important;
    box-shadow: none !important;
}

/* 2. Quitar el efecto hover de las opciones no seleccionadas */
.readonly .rating-option:hover {
    background: #fff !important;
    font-weight: normal !important;
    cursor: default;
}

/* 3. Sombrear las cajas de texto para que parezcan bloqueadas */
.readonly .text-libre {
    background-color: #f0f0f0; /* Fondo gris claro */
    color: #666; /* Texto más suave */
    border-color: #e0e0e0;
}

/* 4. Apagar el botón de enviar y cambiar el cursor */
.readonly .form-footer button {
    background-color: #cccccc !important; /* Gris bloqueado */
    color: #888888 !important; /* Texto gris oscuro */
    cursor: not-allowed !important; /* Cursor de "prohibido" */
    box-shadow: none !important;
}

/* ==========================================
   5. RESPONSIVE DESIGN (MÓVIL)
   ========================================== */
@media (max-width: 768px) {
    :root { --mobile-q-font: 18px; }

    /* LOGIN MÓVIL: Logo como Banner y Formulario Centrado */
    .split-container {
        flex-direction: column !important;
        height: 100vh !important;
    }

    .login-left {
        display: flex !important;
        height: 100px !important; /* Altura del mini banner */
        flex: none !important;
    }

    .main-logo {
        max-width: 220px !important;
    }

    .login-right {
        flex: 1 !important;
        display: flex !important;
        flex-direction: row !important; /* Mantiene la fila para centrar horizontalmente */
        justify-content: center !important; /* Centrado horizontal del form */
        align-items: flex-start !important; /* Alineado arriba verticalmente */
        padding: 40px 20px 80px 20px !important; /* 40px de top para la distancia que pides */
        background-color: var(--bg-light) !important;
    }

    /* BARRA AZUL INFERIOR FIJA */
    .sidebar {
        position: fixed !important; bottom: 0; left: 0; width: 100%; height: 90px;
        flex-direction: row !important; padding: 0 !important; z-index: 9999;
        background-color: var(--blue-primary) !important;
        box-shadow: 0 -4px 15px rgba(0,0,0,0.3);
    }
    .sidebar-header { display: none; }
    .sidebar-nav, .sidebar-footer, #roleMenuContainer { display: contents !important; }

    .menu-item, .logout-btn {
        flex: 1 !important; 
        height: 100% !important; 
        min-height: 0 !important;
        margin: 0 !important; 
        border-radius: 0 !important; 
        border: 0.5px solid rgba(255,255,255,0.1) !important;
        padding: 5px !important; 
        font-size: 14px !important; 
        display: flex !important;
        flex-direction: row !important; 

        justify-content: center !important;
        align-items: center !important; 
        text-align: center !important; 
        background: transparent !important;
        gap: 6px !important;
        line-height: 1.2 !important;
    }
    

    /* ÁREA DE CONTENIDO MÓVIL CON SCROLL */
    .main-content {
        padding: 20px 20px 200px 20px !important; 
        overflow-y: auto !important;
        height: 100vh !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .correctores-grid { grid-template-columns: 1fr !important; padding-bottom: 50px !important; }
    .corr-card { border: 2px solid #ccc !important; margin-bottom: 15px; }
    .question-item label { font-size: var(--mobile-q-font); }
    .welcome-gif { transform: rotate(-90deg) !important; max-width: 90px !important; }
    .form-footer { justify-content: center !important; margin-bottom: 60px; }
    #btnEnviar, #btnEnviarEval, #btnEnviarSupEval { width: 100%; min-width: 0; }
}



/* ==========================================
   6. UTILIDADES Y ANIMACIONES
   ========================================== */
.main-loader-container { display: flex; flex-direction: column; justify-content: center; align-items: center; flex-grow: 1; min-height: 300px; }
.spinner-blue { width: 50px; height: 50px; border: 5px solid rgba(51, 122, 183, 0.2); border-top: 5px solid var(--blue-primary); border-radius: 50%; animation: spin 1s linear infinite; }
.spinner { width: 24px; height: 24px; border: 3px solid rgba(255,255,255,0.3); border-top: 3px solid #fff; border-radius: 50%; animation: spin 1s linear infinite; position: absolute; display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast { position: fixed; top: 25px; right: 25px; background: var(--success); color: white; padding: 16px 28px; border-radius: 8px; transform: translateX(200%); transition: 0.5s; z-index: 3000; font-weight: 600; }
#toast.show { transform: translateX(0); }

.welcome-view { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; height: 100%; }
.badge { padding: 6px 14px; border-radius: 20px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.badge-pendiente { background: var(--warning-bg); color: var(--warning); border: 1px solid #ffeeba; }
.badge-finalizado { background: var(--success-bg); color: var(--success); border: 1px solid #c3e6cb; }

.readonly { pointer-events: none; opacity: 0.8; }
.btn-back { background: none; border: none; color: var(--blue-primary); cursor: pointer; font-size: 1rem; margin-bottom: 25px; display: flex; align-items: center; gap: 8px; font-weight: 600; }
#btnEnvText, #btnEvalText, #btnSupEvalText, #btnText { transition: opacity 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }



/* ==========================================
   7. ESTILOS ADMINISTRADOR
   ========================================== */
   
   /* Darle espaciado a los botones del menú Admin */
#roleMenuContainer {
    display: flex;
    flex-direction: column;
    gap: 12px; /* Esta es la separación mágica */
}

/* Asegurar que la tabla haga scroll horizontal sin empujar el menú */
.table-container {
    width: 100%;
    max-width: calc(100vw - 330px); /* 100% de la pantalla menos el menú (300px) y paddings */
    overflow-x: auto; /* Scroll horizontal solo para la tabla */
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.admin-table {
    width: 100%; 
    border-collapse: collapse;
    table-layout: auto; 
}

/* TEXTO TRUNCADO (Puntos suspensivos...) */
.truncate-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* TAMAÑOS DE COLUMNA ESPECÍFICOS */

/* Nombres y Apellidos (CRECEN para llenar el espacio vacío) */
.col-name { 
    width: auto; 
    min-width: 120px; 
}

/* RUN y Cargo */
.col-medium { 
    width: 85px; 
    min-width: 85px; 
}

/* Preguntas 1 a 4  */
.col-short { 
    width: 61px; 
    min-width: 61px; 
    max-width: 61px; 
    text-align: center; 
}

/* Preguntas 5 en adelante (Texto largo) */
.col-long { 
    min-width: 65px; 
    max-width: 200px; 
}

/* Centrar el texto en los TH de los números para que se vea ordenado */
th.col-short { text-align: center; }
td.col-short { text-align: center; font-weight: 600; color: var(--blue-primary); }


.admin-table th, .admin-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.admin-table th {
    background-color: var(--blue-primary);
    color: white;
    font-weight: 600;
}

.admin-table tr:hover {
    background-color: #f8f9fa;
}

.action-buttons button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--blue-primary);
    margin-right: 10px;
}

.action-buttons .btn-delete {
    color: #dc3545; /* Rojo para eliminar */
}

/* Contenedor de las acciones superiores (Buscador + Excel) */
.header-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Caja de búsqueda con ícono integrado */
.search-box {
    position: relative;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 0.9rem;
}

.search-box input {
    padding: 10px 15px 10px 35px; /* El 35px deja espacio para la lupa */
    border: 1px solid var(--border-color);
    border-radius: 6px;
    width: 280px;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s ease;
}

.search-box input:focus {
    border-color: var(--blue-primary);
    box-shadow: 0 0 5px rgba(51, 122, 183, 0.3);
}

.btn-download {
    background-color: var(--success);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Flexbox para alinear título a la izq y botón a la der */
.admin-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

/* Botón Excel de 160px */
.btn-download {
    background-color: #217346; /* Verde oficial de Excel */
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 160px; /* Ancho solicitado */
    transition: background 0.3s;
}

.btn-download:hover { background-color: #1a5c37; }

/* BADGES DE ESTADO */
.badge { 
    padding: 6px 12px; 
    border-radius: 20px; 
    font-size: 0.75rem; 
    font-weight: 700; 
    text-transform: uppercase; 
    display: inline-block;
    min-width: 80px; /* Para que se vean uniformes */
    text-align: center;
}

/* Pendiente / Supervisor (Amarillo) */
.badge-pendiente { 
    background: var(--warning-bg); 
    color: var(--warning); 
    border: 1px solid #ffeeba; 
}

/* Finalizado (Verde) */
.badge-finalizado { 
    background: var(--success-bg); 
    color: var(--success); 
    border: 1px solid #c3e6cb; 
}

/* En Proceso "X de N" (Azul - Opcional, para diferenciar) */
.badge-proceso { 
    background: #e7f1ff; 
    color: #0056b3; 
    border: 1px solid #b8daff; 
}


/* Contenedor de Ratios/Promedios */

/* Contenedor invisible que distribuye los ratios */
.stats-container {
    display: flex;
    flex-wrap: wrap; /* Permite bajar a la siguiente línea si no caben */
    gap: 15px; /* Separación solicitada */
    margin-bottom: 25px;
    width: 100%;
    /* Se eliminaron bordes, fondos y sombras del contenedor general */
}

/* Cada ratio ocupa el mismo ancho y crece para llenar el 100% */
.stat-badge {
    /* La base es un 15% para forzar máximo 6 por fila, pero flex: 1 lo auto-ajusta */
    flex: 1 1 calc(16% - 15px); 
    min-width: 120px; /* Evita que queden demasiado pequeños en pantallas chicas */
    
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    
    /* Centrado de texto */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    text-align: center;
}

/* Texto descriptivo ("Promedio Q001") */
.stat-badge span {
    font-size: 0.85rem;
    color: var(--text-light);
    text-transform: uppercase;
    font-weight: 600;
}

/* El número grande del promedio */
.stat-badge strong {
    color: var(--blue-primary);
    font-size: 1.6rem;
    line-height: 1;
}

/* ESTILOS PARA ORDENAMIENTO DE TABLAS */
.admin-table th {
    cursor: pointer; /* Cursor de manito */
    user-select: none; /* Evita que el texto se seleccione al hacer doble clic */
    transition: background-color 0.2s;
    position: relative;
}

.admin-table th:hover {
    background-color: var(--blue-dark); /* Feedback visual al pasar el mouse */
}

.admin-table th i {
    margin-left: 8px;
    opacity: 0.5; /* Ícono semi-transparente por defecto */
    transition: opacity 0.2s;
}

/* Cuando está ordenado, el ícono se vuelve 100% visible */
.admin-table th.asc i, 
.admin-table th.desc i {
    opacity: 1;
}

/* El <th> de acciones no debe parecer clickeable */
.admin-table th:last-child {
    cursor: default;
}
.admin-table th:last-child:hover {
    background-color: var(--blue-primary);
}

.admin-table th i {
    margin-left: 0.5px;
    opacity: 0.5; 
    transition: opacity 0.2s;
    
    /* --- NUEVO: Ajuste de Tamaño --- */
    font-size: 0.7rem; /* Esto lo hace un 30% más pequeño que el texto */
    vertical-align: middle; /* Alinea el ícono pequeñito perfectamente con el texto */
}