/* --- VARIABLES Y ESTILOS GLOBALES --- */
:root {
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

/* --- NAVEGACIÓN LATERAL (DESKTOP) --- */
.sidebar {
    width: 280px;
    background-color: var(--card-bg);
    border-right: 1px solid var(--border);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.brand h2 {
    color: var(--primary);
    font-size: 1.4rem;
    font-weight: 700;
}

.brand p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.menu ul {
    list-style: none;
}

.menu li {
    margin-bottom: 0.5rem;
}

.nav-btn {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.nav-btn:hover, .nav-btn.active {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--primary);
    font-weight: 600;
}

/* --- CONTENIDO PRINCIPAL --- */
.content {
    flex: 1;
    padding: 2.5rem;
    max-width: 1100px;
}

.module-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
}

.badge {
    background: rgba(59, 130, 246, 0.2);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    text-transform: uppercase;
}

.badge-quiz {
    background: rgba(16, 185, 129, 0.2);
    color: #10b981;
}

h1 {
    font-size: 1.6rem;
    margin: 0.5rem 0 1.5rem 0;
}

/* --- ESPACIADO Y TIPOGRAFÍA DE TEORÍA (.theory-block Y .theme-content) --- */

/* Reglas generales para párrafos y listas */
.theory-block p,
.theme-content p {
    margin-top: 0.75rem;
    margin-bottom: 1.25rem;
    line-height: 1.6;
    color: var(--text-main);
}

.theory-block ul, 
.theme-content ul,
.theory-block ol,
.theme-content ol {
    margin-top: 0.75rem;
    margin-bottom: 1.25rem;
    padding-left: 1.5rem;
}

.theory-block li,
.theme-content li {
    margin-bottom: 0.5rem;
    line-height: 1.5;
}

/* Títulos H2 y H3 */
.theory-block h2,
.theme-content h2 {
    font-size: 1.35rem;
    margin-top: 2.5rem;
    margin-bottom: 0.75rem;
    line-height: 1.3;
    color: var(--text-main);
}

.theory-block h3,
.theme-content h3 {
    font-size: 1.15rem;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    line-height: 1.3;
    color: var(--text-main);
}

/* Ajuste fino cuando un H3 va justo después de un H2 o de un párrafo previo */
.theory-block h2 + p,
.theme-content h2 + p {
    margin-top: 0.5rem; /* Ajusta el espacio del primer párrafo tras el título principal */
}

.theory-block p + h3,
.theme-content p + h3 {
    margin-top: 1.5rem; /* Espacio equilibrado antes de un subtítulo H3 */
}

/* Quitar margen superior extra al primer elemento */
.theory-block > *:first-child,
.theme-content > *:first-child {
    margin-top: 0 !important;
}

/* --- TABLAS --- */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
}

table td:last-child {
    white-space: nowrap;
    width: 1%;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
    text-align: center;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.hidden {
    display: none;
}

/* --- ADAPTACIÓN PARA MÓVILES --- */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 1rem;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .brand p {
        margin-bottom: 1rem;
    }

    .menu ul {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .menu li {
        margin-bottom: 0;
        flex-shrink: 0;
    }

    .nav-btn {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .content {
        padding: 1rem;
    }

    .module-card {
        padding: 1.2rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    table th:first-child,
    table td:first-child {
        display: none;
    }

    th, td {
        padding: 0.6rem 0.4rem;
        font-size: 0.85rem;
    }

    .btn-primary {
        padding: 0.4rem 0.6rem !important;
        font-size: 0.75rem !important;
    }
}