/* ==========================================================================
   1. VARIABLES & RESET & CONFIGURACIÓN BASE
   ========================================================================== */
:root {
    --primary: #007bff;
    --primary-dark: #0056b3;
    --secondary: #6c757d;
    --bg-light: #f8f9fa;
    --text-dark: #343a40;
    --white: #ffffff;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background-color: #f4f7f6;
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    min-height: 100vh;

    /* --- ARREGLO MÓVIL IMPORTANTE --- */
    /* Padding 0 por defecto para que el móvil ocupe el 100% del ancho.
       El margen de 170px se añade SOLO en pantallas gigantes (ver final del archivo) */
    padding: 0; 
    
    /* Espacio inferior reservado para el anuncio flotante */
    padding-bottom: 100px; 
}

/* Contenedor Principal Genérico */
main {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
    box-sizing: border-box;
}


/* ==========================================================================
   2. HEADER & NAVEGACIÓN
   ========================================================================== */
header {
    background: var(--white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid #eee;
}

.navbar {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.8rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* Permite que el menú se adapte en móviles pequeños */
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Enlaces del menú (estilo botón suave) */
.nav-link {
    text-decoration: none;
    color: #555;
    font-weight: 600;
    padding: 10px 16px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease-in-out;
}

.nav-link:hover {
    background-color: #e7f1ff;
    color: var(--primary);
    border-color: #cce5ff;
    transform: translateY(-2px);
}

/* Botones de Login/Registro */
#auth-buttons {
    display: flex; 
    gap: 10px;
}

.btn-login, .btn-signup {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.btn-login {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
}
.btn-login:hover { background: #f0f7ff; }

.btn-signup {
    background: var(--primary);
    color: var(--white);
    border: 1px solid var(--primary);
}
.btn-signup:hover { background: var(--primary-dark); }


/* ==========================================================================
   3. MENÚ DE USUARIO (DROPDOWN)
   ========================================================================== */
.user-menu {
    position: relative;
    display: none; /* Se activa vía JS */
}

.user-avatar {
    width: 40px; height: 40px;
    background: #007bff; color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; cursor: pointer;
    user-select: none;
    transition: transform 0.2s;
}
.user-avatar:hover { transform: scale(1.1); }

/* Caja del desplegable */
.dropdown-menu {
    display: none;
    position: absolute;
    top: 55px; 
    right: 0;
    background: white;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    width: 220px;
    flex-direction: column;
    overflow: hidden;
    z-index: 2000;
    border: 1px solid #eee;
}
.dropdown-menu.show { display: flex; animation: fadeIn 0.2s; }

/* Items dentro del menú */
.dropdown-header {
    padding: 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
}
.dropdown-name { display: block; font-weight: 800; color: #333; }
.dropdown-role { display: block; font-size: 0.75rem; color: #666; text-transform: uppercase; margin-top: 2px;}

.dropdown-item {
    padding: 12px 15px;
    text-decoration: none;
    color: #444;
    font-size: 0.95rem;
    border-bottom: 1px solid #f9f9f9;
    transition: background 0.2s;
    background: none; border: none; 
    text-align: left; width: 100%; cursor: pointer;
    display: flex; align-items: center; gap: 8px;
}
.dropdown-item:hover { background: #f0f7ff; color: #007bff; }
.dropdown-item.danger { color: #dc3545; font-weight: 600; }
.dropdown-item.danger:hover { background: #fff5f5; }

/* Elementos auxiliares del dropdown */
.dropdown-content {
    display: none; position: absolute; right: 0; top: 50px;
    background-color: white; min-width: 220px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.15); border-radius: 8px; z-index: 1000;
    border: 1px solid #eee; flex-direction: column; overflow: hidden;
}
.dropdown-content.show-dropdown { display: flex !important; }

.dropdown-content a {
    padding: 12px 16px; text-decoration: none; color: #333;
    display: block; border-bottom: 1px solid #f9f9f9;
}
.dropdown-content a:hover { background-color: #f1f3f5; color: #007bff; }
.role-restricted { align-items: center; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }


/* ==========================================================================
   4. HOME & TARJETAS GENERALES
   ========================================================================== */
.hero-section {
    text-align: center;
    margin-bottom: 3rem;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.card {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: var(--shadow);
    text-align: center;
    transition: transform 0.2s;
    border: 1px solid #eee;
}
.card:hover { transform: translateY(-5px); border-color: var(--primary); }
.card h3 { margin-top: 1rem; color: var(--primary); }
.card p { color: #666; margin-bottom: 2rem; }

.card-btn {
    display: inline-block; padding: 10px 20px;
    background: var(--primary); color: white;
    border-radius: 6px; text-decoration: none;
}


/* ==========================================================================
   5. LISTADO DE EXÁMENES (examenes.html)
   ========================================================================== */
.filters-bar {
    background: white;
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    margin-bottom: 2rem;
    display: flex; align-items: center; gap: 15px;
    border: 1px solid #eee;
}

.exams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
}

.exam-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #f0f0f0;
    display: flex; flex-direction: column; position: relative; height: 100%;
}
.exam-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 20px rgba(0,0,0,0.1);
    border-color: var(--primary);
}

/* Cabecera Examen */
.exam-header { background: #f8faff; padding: 1.5rem; border-bottom: 1px solid #edf2f7; position: relative; }
.exam-season-badge {
    position: absolute; top: 15px; right: 15px;
    background: #e7f1ff; color: var(--primary);
    padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.5px;
}
.exam-title {
    font-size: 1.3rem; font-weight: 800; margin: 0 0 0.5rem 0; color: #2d3748;
    padding-right: 70px; line-height: 1.3;
}
.exam-category { color: #718096; font-size: 0.85rem; font-weight: 600; text-transform: uppercase; display: flex; align-items: center; gap: 5px; }

/* Cuerpo Examen */
.exam-body { padding: 1.5rem; flex-grow: 1; color: #4a5568; font-size: 0.95rem; }
.exam-meta { margin-bottom: 10px; line-height: 1.5; }
.exam-meta strong { color: #2d3748; font-weight: 700; margin-right: 4px; }

/* Footer Examen */
.exam-footer {
    padding: 1.2rem 1.5rem; background: white; border-top: 1px solid #f7fafc;
    display: flex; flex-direction: column; gap: 12px;
}

/* Botones de acción (Modo Examen/Práctica) */
.btn-mode {
    display: flex; justify-content: center; align-items: center; gap: 10px;
    width: 100%; padding: 12px; border-radius: 10px;
    text-decoration: none; font-weight: 700; font-size: 0.9rem;
    transition: all 0.2s ease; border: none; cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.btn-oficial { background: linear-gradient(135deg, #007bff 0%, #0056b3 100%); color: white; }
.btn-oficial:hover { box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3); transform: translateY(-2px); }

.btn-practica { background: #f1f3f5; color: #495057; border: 1px solid #e9ecef; }
.btn-practica:hover { background: #e9ecef; color: #212529; transform: translateY(-2px); border-color: #dee2e6; }

.btn-start {
    display: block; width: 100%; text-align: center;
    background: var(--primary); color: white; padding: 10px;
    border-radius: 6px; text-decoration: none; font-weight: bold; transition: background 0.2s;
}
.btn-start:hover { background: var(--primary-dark); }


/* ==========================================================================
   6. SIMULADOR DE TEST (Realizando el examen)
   ========================================================================== */
.simulator-container {
    max-width: 800px; margin: 0 auto; background: white;
    border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    overflow: hidden; position: relative; min-height: 500px;
    display: flex; flex-direction: column;
}

/* Barra de Tiempo */
.timer-bar-container { height: 8px; background: #e9ecef; width: 100%; }
.timer-bar-fill { height: 100%; background: #dc3545; width: 0%; transition: width 1s linear; }

/* Cabecera Test */
.sim-header {
    padding: 1.5rem; border-bottom: 1px solid #eee;
    display: flex; justify-content: space-between; align-items: center; background: #fdfdfd;
}
.question-counter { font-weight: bold; color: #555; }
.timer-display { font-weight: bold; color: #dc3545; display: flex; align-items: center; gap: 5px; }

/* Cuerpo Pregunta */
.sim-body { padding: 2rem; flex: 1; }
.question-title { font-size: 1.4rem; margin-bottom: 2rem; color: #333; line-height: 1.5; }

/* Grid de Respuestas */
.answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 columnas en PC */
    gap: 15px;
}

.answer-card {
    background: #f8f9fa; border: 2px solid #e9ecef; padding: 1.5rem;
    border-radius: 10px; cursor: pointer; transition: all 0.2s;
    font-size: 1rem; display: flex; align-items: center;
}
.answer-card:hover { border-color: #007bff; background: #f0f7ff; }
.answer-card.selected { border-color: #007bff; background: #007bff; color: white; }

/* Footer Navegación Test */
.sim-footer {
    padding: 1.5rem; border-top: 1px solid #eee;
    display: flex; background: #fff; align-items: center;
}
.btn-nav {
    padding: 10px 25px; border-radius: 8px; border: none; font-weight: bold;
    cursor: pointer; font-size: 1rem; transition: background 0.2s;
}
.btn-prev { background: #e2e6ea; color: #333; margin-right: auto; }
.btn-next { background: #007bff; color: white; margin-left: auto; }
.btn-next:hover { background: #0056b3; }
.btn-prev:hover { background: #dbe2e8; }


/* ==========================================================================
   7. RESULTADOS Y FEEDBACK
   ========================================================================== */
.score-card {
    text-align: center; padding: 3rem; background: white;
    border-radius: 16px; box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    margin-bottom: 2rem; border: 1px solid #f0f0f0;
}
.score-big { font-size: 4rem; font-weight: 800; color: #333; margin: 0; }
.score-percent { font-size: 1.5rem; color: #666; font-weight: 500; }
.score-message { margin-top: 1rem; font-size: 1.2rem; color: #007bff; }

.history-box {
    background: #f8f9fa; border-left: 4px solid #007bff;
    padding: 1rem; margin-bottom: 2rem; border-radius: 4px;
}
.btn-history {
    display: inline-block; margin-top: 12px; padding: 10px 20px;
    background-color: #007bff; color: white !important; text-decoration: none;
    border-radius: 8px; font-weight: 700; font-size: 0.95rem;
    box-shadow: 0 2px 5px rgba(0, 123, 255, 0.3); transition: all 0.2s ease;
}
.btn-history:hover {
    background-color: #0056b3; transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.4);
}

/* Grid de cuadraditos (Resumen) */
.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 10px; margin-top: 2rem;
}
.result-box {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    border-radius: 8px; font-weight: bold; color: white;
    cursor: pointer; transition: transform 0.2s; font-size: 1.2rem;
}
.result-box:hover { transform: scale(1.1); }

/* Estados (Colores semáforo) */
.status-correct { background-color: #28a745; border: 2px solid #1e7e34; }
.status-incorrect { background-color: #dc3545; border: 2px solid #bd2130; }
.status-unanswered { background-color: #6c757d; border: 2px solid #545b62; }

/* Navegación Circular (Feedback en detalle) */
.nav-circles-container {
    display: flex; justify-content: center; flex-wrap: wrap;
    gap: 10px; margin: 1.5rem 0; padding: 0 10px;
}
.nav-circle {
    width: 35px; height: 35px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: bold; color: white; cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 0.9rem; border: 2px solid transparent;
}
.nc-correct { background-color: #28a745; border-color: #1e7e34; }
.nc-incorrect { background-color: #dc3545; border-color: #bd2130; }
.nc-unanswered { background-color: #6c757d; border-color: #545b62; }
.nav-circle.active {
    transform: scale(1.4); box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    z-index: 10; border: 2px solid white;
}
.review-nav-bar { /* Barra antigua scrollable */
    display: flex; gap: 8px; overflow-x: auto; padding: 10px 15px;
    margin-bottom: 20px; border-bottom: 1px solid #eee; -webkit-overflow-scrolling: touch;
}

/* Cajas de corrección */
.correction-feedback {
    margin-top: 1rem; padding: 1rem; border-radius: 8px;
    background: #f1f3f5; border: 1px solid #ddd;
}
.correct-text { color: #28a745; font-weight: bold; }
.incorrect-text { color: #dc3545; font-weight: bold; text-decoration: line-through; }

/* Botones Navegación Resultado */
.btn-nav-action, .btn-back-summary {
    padding: 12px 24px; border-radius: 10px; font-weight: 700; font-size: 1rem;
    cursor: pointer; transition: all 0.2s ease; border: none;
    display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.btn-nav-action {
    background: linear-gradient(135deg, #007bff 0%, #0056b3 100%); color: white;
}
.btn-nav-action:hover {
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3); transform: translateY(-2px);
}
.btn-back-summary {
    background: #f1f3f5; color: #495057; border: 1px solid #e9ecef;
}
.btn-back-summary:hover {
    background: #e9ecef; color: #212529; transform: translateY(-2px); border-color: #dee2e6;
}


/* ==========================================================================
   8. ADMIN & INPUTS ESPECIALES
   ========================================================================== */
.admin-container {
    width: 100%; max-width: 1200px; margin: 2rem auto;
    display: grid;
    grid-template-columns: 240px 1fr; /* Sidebar izquierda */
    gap: 30px; align-items: start;
}

.admin-stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px; margin-bottom: 30px;
}

.stat-card {
    background: white; padding: 20px; border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05); text-align: center; border: 1px solid #edf2f7;
}
.stat-number { font-size: 2.2rem; font-weight: 800; color: #007bff; display: block; }
.stat-label { color: #64748b; font-weight: 600; font-size: 0.9rem; text-transform: uppercase; }

/* Chip Inputs (Selector de respuestas correcta) */
.chip-input:disabled + .chip-label {
    background-color: #f2f2f2 !important; color: #a0a0a0 !important;
    border: 1px dashed #ccc !important; cursor: not-allowed !important;
    opacity: 0.6; pointer-events: none; box-shadow: none !important; transform: none !important;
}
.chip-input:disabled + .chip-label i, .chip-input:disabled + .chip-label span {
    filter: grayscale(100%);
}


/* ==========================================================================
   9. FOOTER
   ========================================================================== */
footer {
    background: #333; color: white; text-align: center;
    padding: 0.8rem 1rem; margin-top: auto;
    font-size: 0.85rem; border-top: 1px solid #444;
}

footer a {
    color: #64748b !important; text-decoration: none;
    font-weight: 500; transition: color 0.2s ease;
}
footer a:hover {
    color: #007bff !important; text-decoration: underline;
}
footer p { margin: 5px 0; }
.footer-link-btn {
    background: #f1f5f9; padding: 5px 12px; border-radius: 6px; font-size: 0.85rem;
}


/* ==========================================================================
   10. PUBLICIDAD (ADS)
   ========================================================================== */
.ad-container {
    background: white; position: relative; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); z-index: 900;
}
.ad-label {
    position: absolute; top: 0; right: 0;
    background: rgba(255, 255, 255, 0.9); color: #999;
    font-size: 9px; padding: 2px 4px; text-transform: uppercase;
    border-bottom-left-radius: 4px;
}
.ad-image { width: 100%; height: 100%; object-fit: cover; cursor: pointer; }

/* Banner Inferior (Sticky) */
.ad-bottom {
    position: fixed; bottom: 0; left: 0;
    width: 100%; height: 60px; /* Altura para móvil */
    background: white; border-top: 1px solid #ddd;
    display: flex; justify-content: center; align-items: center;
    z-index: 9999; margin: 0;
}

/* Banner Superior */
.ad-top-banner {
    width: 95%; max-width: 728px; height: 90px;
    margin: 1rem auto; display: flex;
}
@media (max-width: 768px) {
    .ad-top-banner { height: 100px; max-width: 350px; }
}


/* Laterales (Ocultos por defecto) */
.ad-sidebar {
    display: none; position: fixed; top: 80px; width: 160px;
    height: calc(100vh - 160px); z-index: 100; background: #eee;
}
.ad-side-left { left: 10px; }
.ad-side-right { right: 10px; }
.ad-left { left: 10px; } /* Alias */
.ad-right { right: 10px; } /* Alias */

/* =========================================
   PUBLICIDAD NATIVA
   ========================================= */

.card.ad-native {
    padding: 0; 
    overflow: hidden; 
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    
    /* CAMBIO IMPORTANTE: */
    /* Usamos height: 100% para que intente igualar a sus vecinos en el grid */
    /* Pero si está vacío (sin anuncio), el script de Adsense lo ocultará */
    height: 100%; 
    /*min-height: 300px; /* Mantén esto SOLO mientras diseñas. Luego bórralo para que colapse si no hay ad */
    
    background-color: #f8f9fa;
    border: 1px solid #eee; /* Borde sutil igual que las otras */
}

.card.ad-native .ad-label {
    position: absolute; top: 0; right: 0;
    background: rgba(255, 255, 255, 0.9);
    color: #999; font-size: 10px; padding: 2px 6px;
    border-bottom-left-radius: 6px; z-index: 2; font-weight: bold;
}

.card.ad-native .ad-image {
    width: 100%; 
    height: 100%;
    object-fit: cover; 
    display: block;
}

/* Control Móvil */
@media (max-width: 768px) {
    .options-grid {
        display: flex;
        flex-direction: column;
        gap: 20px;
    }
    /* Orden visual */
    .order-1 { order: 1; }
    .order-2 { order: 2; }
    .order-3 { order: 3; } 
}

/* =======================================================
   TRUCO DE MAGIA: OCULTAR TARJETA SI NO HAY ANUNCIO
   ======================================================= */

/* 1. Si Google marca el anuncio como "unfilled" (vacío), ocultamos la tarjeta entera */
.card.ad-native:has(ins[data-ad-status="unfilled"]) {
    display: none !important;
}

/* 2. Ajuste para que no se vea el cuadro blanco vacío mientras carga */
.card.ad-native {
    /* Quitamos la altura mínima forzada para que pueda colapsar */
    min-height: auto; 
    /* Quitamos el fondo para que si está vacío sea invisible */
    background: transparent !important; 
    border: none;
    box-shadow: none;
}

/* 3. PERO... cuando el anuncio cargue, queremos que recupere su forma bonita */
.card.ad-native:has(ins[data-ad-status="filled"]) {
    min-height: 300px; /* Recupera la altura */
    background: white !important; /* Recupera el fondo */
    border: 1px solid #eee;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

/* ==========================================================================
   11. MEDIA QUERIES (RESPONSIVE)
   ========================================================================== */

/* A. MÓVILES ( < 768px ) */
@media (max-width: 768px) {
    main, .container, .login-box, .card-section, .history-box {
        width: 100% !important; max-width: 100% !important;
        margin: 0 auto 1rem auto !important; padding: 1rem !important;
    }
    h1, h2 { font-size: 1.6rem !important; word-wrap: break-word; text-align: center; }
    
    .btn, button, .btn-nav-action, input[type="submit"], .btn-start, .btn-mode, .btn-prev, .btn-next {
        width: 100% !important; display: block; margin-bottom: 10px; height: auto !important; margin-left: 0; margin-right: 0;
    }
    input, select, textarea { width: 100% !important; font-size: 16px !important; }
    
    header .navbar { flex-direction: column; gap: 15px; text-align: center; }
    
    .answers-grid { grid-template-columns: 1fr; }
    .sim-footer { flex-direction: column; gap: 10px; }
    .admin-container { grid-template-columns: 1fr; }
    .nav-circle { width: 30px; height: 30px; font-size: 0.8rem; }
}


/* B. PORTÁTILES Y ESCRITORIO ( > 1280px )
   He cambiado esto de 1600px a 1280px para que los portátiles
   vean los anuncios laterales y NO el de arriba.
*/
@media (min-width: 1280px) {
    body {
        padding-left: 170px;
        padding-right: 170px;
    }

    /* Mostrar anuncios laterales */
    .ad-sidebar {
        display: flex;
        position: fixed; top: 110px; width: 160px; height: 600px;
    }

    /* Ocultar banner superior (para que no empuje la pregunta) */
    .ad-top-banner { display: none; }

    /* Banner inferior más elegante en PC */
    .ad-bottom {
        height: 90px; max-width: 728px;
        left: 50%; transform: translateX(-50%);
        border-radius: 8px 8px 0 0; box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
    }
}