/* Theory Sidebar - Explorador lateral del marco teórico */
:root {
    --sidebar-width: 320px;
    --sidebar-width-collapsed: 60px;
    --sidebar-bg: #ffffff;
    --sidebar-border: rgba(26, 35, 126, 0.1);
    --sidebar-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    --sidebar-text: #1a237e;
    --sidebar-text-secondary: #666;
    --sidebar-hover: rgba(26, 35, 126, 0.05);
    --sidebar-active: #1a237e;
    --sidebar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Sidebar Container */
.theory-sidebar {
    position: fixed;
    left: 0;
    top: 72px; /* Alineado perfectamente con la navegación fija */
    height: calc(100vh - 72px);
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    box-shadow: var(--sidebar-shadow);
    transform: translateX(0);
    transition: var(--sidebar-transition);
    z-index: 950; /* Por debajo del nav fijo pero por encima del contenido */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.theory-sidebar.collapsed {
    transform: translateX(calc(-1 * (var(--sidebar-width) - var(--sidebar-width-collapsed))));
}

.theory-sidebar.hidden {
    transform: translateX(-100%);
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--sidebar-border);
    background: linear-gradient(135deg, rgba(26, 35, 126, 0.02), rgba(13, 71, 161, 0.05));
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-icon {
    font-size: 1.5em;
    background: linear-gradient(135deg, #1a237e, #0d47a1);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sidebar-title {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--sidebar-active);
    margin: 0;
}

.sidebar-toggle {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 6px;
    transition: var(--sidebar-transition);
    color: var(--sidebar-text-secondary);
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-active);
}

.toggle-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.theory-sidebar.collapsed .toggle-icon {
    transform: rotate(180deg);
}

/* Theory Tree Navigation */
.theory-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
}

.tree-container {
    padding: 1rem 0;
}

/* Tree Sections */
.tree-section {
    margin: 0;
    border-bottom: 1px solid rgba(26, 35, 126, 0.05);
}

.tree-section:last-child {
    border-bottom: none;
}

.section-header {
    display: flex;
    align-items: center;
    padding: 0;
    background: transparent;
    transition: var(--sidebar-transition);
}

.section-header:hover {
    background: var(--sidebar-hover);
}

.section-toggle {
    background: none;
    border: none;
    padding: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    color: var(--sidebar-text-secondary);
    transition: var(--sidebar-transition);
}

.toggle-arrow {
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.tree-section.active .toggle-arrow,
.section-toggle[aria-expanded="true"] .toggle-arrow {
    transform: rotate(90deg);
}

/* CSS SUPER ESPECÍFICO para forzar colores oscuros */
.theory-sidebar .tree-section .section-link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem 0.75rem 0;
    text-decoration: none;
    color: #000 !important; /* NEGRO PURO con !important para forzar */
    font-weight: 600 !important; /* Peso mayor con !important */
    transition: var(--sidebar-transition);
    min-height: 48px;
}

.theory-sidebar .tree-section .section-link:hover {
    color: var(--sidebar-active) !important;
    background: rgba(26, 35, 126, 0.03);
    border-radius: 6px;
}

.theory-sidebar .tree-section.active .section-link {
    color: var(--sidebar-active) !important;
    font-weight: 700 !important;
    background: rgba(26, 35, 126, 0.08);
    border-radius: 6px;
}

/* ICONOS ELIMINADOS - Solo viñetas simples */
.theory-sidebar .tree-section .section-icon {
    display: none; /* ELIMINAR iconos emoji */
}

.theory-sidebar .tree-section .section-number {
    font-weight: 700;
    font-size: 0; /* OCULTAR el texto original completamente */
    width: 20px;
    flex-shrink: 0;
    color: transparent !important; /* HACER INVISIBLE el texto original */
}

.theory-sidebar .tree-section .section-number::before {
    content: "•"; /* VIÑETA SIMPLE en lugar de números */
    color: #1a237e;
    font-weight: bold;
    font-size: 1.2rem; /* Usar rem en lugar de em para evitar herencia */
    display: inline-block;
}

/* ANULAR pseudo-elementos para section-number fuera del sidebar */
.theoretical-portal .section-number::before,
.theory-section .section-number::before {
    content: none !important;
    display: none !important;
}

/* DEBUG: Asegurar que NO haya elementos superpuestos en el header del sidebar */
.sidebar-header * {
    position: static !important;
    z-index: auto !important;
}

/* FORZAR que el título del sidebar NO sea clickeable */
.sidebar-title {
    pointer-events: none !important;
    position: relative !important;
    z-index: 999 !important;
}

/* DEBUG: Asegurar separación clara entre header y tree */
.theory-tree {
    margin-top: 0;
    padding-top: 0;
}

.section-title {
    font-size: 0.95em;
    line-height: 1.3;
    flex: 1;
    color: #000 !important; /* NEGRO PURO con !important */
    font-weight: 600 !important; /* Peso mayor con !important */
}

/* Subsections */
.subsection-list {
    display: none;
    background: rgba(26, 35, 126, 0.02);
    border-top: 1px solid rgba(26, 35, 126, 0.05);
    animation: slideDown 0.3s ease-out;
}

.tree-section.active .subsection-list {
    display: block;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

.subsection-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem 0.5rem 3rem;
    text-decoration: none;
    color: #555; /* Color más oscuro para mejor visibilidad de subsecciones */
    font-size: 0.9em;
    line-height: 1.4;
    transition: var(--sidebar-transition);
    border-left: 3px solid transparent;
}

.subsection-link:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-active);
    border-left-color: rgba(26, 35, 126, 0.2);
}

.subsection-link.active {
    background: rgba(26, 35, 126, 0.08);
    color: var(--sidebar-active);
    border-left-color: var(--sidebar-active);
    font-weight: 500;
}

.subsection-dot {
    color: rgba(26, 35, 126, 0.3);
    font-size: 1.2em;
    width: 12px;
    text-align: center;
    flex-shrink: 0;
}

.subsection-title {
    flex: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--sidebar-border);
    background: rgba(26, 35, 126, 0.02);
}

.progress-indicator {
    width: 100%;
    height: 4px;
    background: rgba(26, 35, 126, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #1a237e, #0d47a1);
    width: 0%;
    transition: width 0.3s ease;
    border-radius: 2px;
}

.progress-text {
    font-size: 0.75em;
    color: var(--sidebar-text-secondary);
    text-align: center;
}

/* Botón de descarga PDF */
.pdf-download-btn {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, #1a237e, #0d47a1);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(26, 35, 126, 0.2);
}

.pdf-download-btn:hover {
    background: linear-gradient(135deg, #0d47a1, #1a237e);
    box-shadow: 0 4px 8px rgba(26, 35, 126, 0.3);
    transform: translateY(-1px);
}

.pdf-download-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(26, 35, 126, 0.2);
}

.pdf-download-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.pdf-icon {
    font-size: 1.1em;
    line-height: 1;
}

.pdf-text {
    font-size: 0.85em;
    letter-spacing: 0.02em;
}

/* Animación de carga en el botón */
.pdf-download-btn.loading .pdf-icon {
    animation: pulse 1.5s infinite;
}

.pdf-download-btn.loading .pdf-text::after {
    content: '...';
    animation: dots 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
    100% { content: ''; }
}


/* Content Adjustment */
.theory-page-content {
    margin-left: var(--sidebar-width);
    transition: var(--sidebar-transition);
    min-height: calc(100vh - 72px); /* Resta la altura de la navegación fija */
    position: relative;
    z-index: 1; /* Mantener el contenido por debajo del sidebar y navegación */
}

/* Ajuste para el contenido principal de las páginas de teoría */
.theory-page-content .section:first-child,
.theory-page-content .hobbes-section:first-child,
.theory-page-content .hero,
.theory-page-content .hobbes-hero {
    padding-top: 1.5rem; /* Espaciado superior limpio sin el header principal */
    margin-top: 0; /* Sin margin adicional */
}

/* Ajuste específico para el portal teórico - REMOVIDO para permitir centrado vertical */
/* NOTA: El centrado se maneja ahora en foundations.css con flexbox */

/* .theory-page-content .portal-grid { REMOVIDO - interfería con centrado vertical } */
/* .theory-page-content .portal-intro { REMOVIDO - innecesario con flexbox } */

.theory-sidebar.collapsed + .theory-page-content {
    margin-left: var(--sidebar-width-collapsed);
}

.theory-sidebar.hidden + .theory-page-content {
    margin-left: 0;
}

/* Mobile Overlay */
.sidebar-overlay {
    position: fixed;
    top: 72px; /* Ajustado para comenzar después del navbar */
    left: 0;
    width: 100vw;
    height: calc(100vh - 72px);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 940; /* Por debajo del sidebar pero por encima del contenido */
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .theory-sidebar {
        transform: translateX(-100%);
    }
    
    .theory-sidebar.active {
        transform: translateX(0);
    }
    
    .theory-page-content {
        margin-left: 0;
        min-height: calc(100vh - 65px); /* Ajuste para altura reducida de navegación en móvil */
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }
    
    .theory-sidebar {
        top: 65px; /* Altura reducida en móvil */
        height: calc(100vh - 65px);
    }
    
    .sidebar-overlay {
        top: 65px;
        height: calc(100vh - 65px);
    }
    
    .sidebar-header {
        padding: 1rem 0.75rem;
    }
    
    .sidebar-title {
        font-size: 1em;
    }
    
    .section-link {
        padding: 0.75rem 0.75rem 0.75rem 0;
    }
    
    .subsection-link {
        padding: 0.5rem 0.75rem 0.5rem 2.5rem;
    }
    
    /* Ajuste de contenido en móvil */
    .theory-page-content .section:first-child,
    .theory-page-content .hobbes-section:first-child,
    .theory-page-content .hero,
    .theory-page-content .hobbes-hero {
        padding-top: 1rem; /* Menos espacio en móvil sin header principal */
    }
    
    /* Ajuste del portal en móvil - REMOVIDO para permitir centrado vertical */
    /* NOTA: El centrado responsive se maneja en foundations.css */
    
    /* .theory-page-content .portal-grid { REMOVIDO - interfería con flexbox } */
    /* .theory-page-content .portal-intro { REMOVIDO - innecesario } */
}

/* Scrollbar Styling */
.theory-tree::-webkit-scrollbar {
    width: 6px;
}

.theory-tree::-webkit-scrollbar-track {
    background: transparent;
}

.theory-tree::-webkit-scrollbar-thumb {
    background: rgba(26, 35, 126, 0.2);
    border-radius: 3px;
}

.theory-tree::-webkit-scrollbar-thumb:hover {
    background: rgba(26, 35, 126, 0.4);
}

/* Focus States for Accessibility */
.section-toggle:focus,
.section-link:focus,
.subsection-link:focus,
.sidebar-toggle:focus {
    outline: 2px solid var(--sidebar-active);
    outline-offset: -2px;
    border-radius: 4px;
}

.section-toggle:focus:not(:focus-visible),
.section-link:focus:not(:focus-visible),
.subsection-link:focus:not(:focus-visible),
.sidebar-toggle:focus:not(:focus-visible) {
    outline: none;
}

/* CORRECCIÓN: Títulos de las secciones teóricas en portal.php con contraste mejorado */
.theoretical-portal .theory-section .section-title,
.theoretical-portal .theory-section h2.section-title {
    color: #ffffff !important;
    background: none !important;
    -webkit-background-clip: initial !important;
    background-clip: initial !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5) !important;
    font-weight: 600 !important;
}