/* =========================================
   1. VARIABLES Y RESET
   ========================================= */
:root {
    --primary: #3b82f6;
    --bg-sidebar: #ffffff;
    --bg-main: #f1f5f9;
    --text-main: #334155;
    --border-color: #e2e8f0;
}

body { 
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

/* =========================================
   2. LAYOUT PRINCIPAL (App Container)
   ========================================= */
.app-container { 
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Área de Contenido (Derecha) */
#content-area {
    flex: 1;
    position: relative;
    background: var(--bg-main);
    overflow-y: auto;
    overflow-x: hidden;
}

/* Sistema de Vistas (Pestañas) */
.view-section {
    display: none;
    width: 100%;
    padding: 20px; 
    box-sizing: border-box;
    animation: fadeIn 0.3s ease-in;
}

.view-section.active {
    display: block;
}

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

/* Separadores */
.section-divider {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 40px 0;
}

/* =========================================
   3. SIDEBAR
   ========================================= */
#sidebar-nav {
    width: 250px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 2000;
    flex-shrink: 0;
}

.nav-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.nav-header h3 {
    margin: 0;
    color: var(--primary);
    font-size: 1.2rem;
}

.nav-items {
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-link {
    text-decoration: none;
    color: #64748b;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent; 
    border-radius: 0;
}

/* Estado Hover y Activo */
.nav-link:hover, .nav-link.active {
    background: #f8fafc;
    color: var(--primary);
    border-left-color: var(--primary);
}

/* --- APÉNDICE --- */
.nav-group {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.parent-toggle {
    cursor: pointer;
    user-select: none;
}

/* Flecha */
.arrow-icon {
    margin-left: auto; 
    font-size: 0.8rem;
    transition: transform 0.3s ease;
    color: #94a3b8;
}

/* Rotación de flecha */
.nav-group.open .arrow-icon {
    transform: rotate(180deg);
    color: var(--primary);
}

.nav-submenu {
    display: none;
    flex-direction: column;
    background-color: #ffffff;
}

.nav-group.open .nav-submenu {
    display: flex;
    animation: slideDown 0.2s ease-out;
}

/* Links Hijos (Indentados) */
.sub-link {
    padding-left: 45px;
    font-size: 0.95rem;
}

/* Animación */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* =========================================
   4. PESTAÑA: INTRODUCCIÓN
   ========================================= */
.intro-hero {
    text-align: center;
    padding: 40px 20px;
    background: linear-gradient(135deg, #fff 0%, #f1f5f9 100%);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 30px;
    border-radius: 8px;
}

.intro-hero h1 {
    color: var(--primary);
    margin-bottom: 10px;
    font-size: 2rem;
}

.intro-subtitle {
    font-size: 1.1rem;
    color: #64748b;
    max-width: 700px;
    margin: 0 auto;
}

.motivation-box {
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    border-left: 5px solid #f59e0b;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    font-size: 1.05rem;
    line-height: 1.6;
}

/* Noticias */
.news-section {
    display: flex;
    flex-direction: column;
    gap: 40px;
}

.news-card {
    display: flex;
    align-items: center;
    gap: 40px;
    background: white;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s;
}

.news-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

.news-card.reverse {
    flex-direction: row-reverse;
}

.news-content { flex: 1; }
.news-visual { flex: 1; display: flex; justify-content: center; }

.news-visual .placeholder-image {
    width: 100%;
    max-width: 300px;
    height: 200px;
    background: #f8fafc;
    border: 2px dashed #cbd5e1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    color: #94a3b8;
}

.news-video {
    width: 100%;           
    max-width: 450px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); 
    aspect-ratio: 16 / 9;
    background: #000;
    border: none;
}


.read-more-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 15px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: color 0.2s;
}

.read-more-link svg {
    transition: transform 0.2s;
}

.read-more-link:hover {
    color: #2563eb;
    text-decoration: underline;
}

.read-more-link:hover svg {
    transform: translateX(4px);
}

/* Widget de incertidumbre */
.uncertainty-widget {
    background: #fff;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    max-width: 1000px;
    margin: 20px auto;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.u-images-container {
    position: relative;
    width: 100%;
    height: 700px; 
    background: #f8fafc;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 20px;
    border: 1px solid #e2e8f0;
}

.u-state-img {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    max-width: 100%;
    max-height: 100%;
    height: auto;
    /* transición */
    opacity: 0; 
    transition: opacity 0.4s ease-in-out;
}

.u-state-img.active {
    opacity: 1;
    z-index: 2;
}

/* Controles */
.u-controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Botones específicos del widget */
.u-btn {
    font-size: 0.9rem;
    padding: 8px 15px;
}

/* Botón activo */
.u-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* =========================================
   5. PESTAÑA: ALGORITMO
   ========================================= */

/* Tarjetas de teoría */
.algo-theory-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.theory-card {
    background: #ffffff;
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.theory-card h3 { margin-top: 0; font-size: 1.1rem; color: var(--text-main); }
.theory-card ul { padding-left: 20px; margin-bottom: 0; }

/* Ejemplo Conceptual */
.example-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-top: 20px;
}

.example-box {
    background: white;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    text-align: center;
}

/* Controles */
.control-btn {
    padding: 8px 16px;
    cursor: pointer;
    border: 1px solid #cbd5e1;
    background: white;
    border-radius: 4px;
    transition: 0.2s;
}
.control-btn:hover { background: #f1f5f9; }

.simple-centered-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 10px;
    width: 100%;
    box-sizing: border-box;
}

.controls-top-row {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* Descripción (Caja Dedicada) */
.controls-bottom-row {
    width: 90%; 
    max-width: 900px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 15px 25px;
    /* Tipografía */
    font-size: 1.05rem;
    font-weight: 500;
    color: #334155;
    line-height: 1.5;
}

.step-display {
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-main);
    min-width: 80px;
    text-align: center;
}

.fixed-btn {
    width: 120px;
    text-align: center;
    font-weight: 600;
    border: 2px solid var(--text-main);
    color: var(--text-main);
}
.fixed-btn:hover { background: var(--text-main); color: white; }

/* Sección Interactiva */
.algo-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    background: #f1f5f9;
    padding: 10px;
    border-radius: 8px;
    justify-content: center;
}
.step-label { font-weight: bold; min-width: 150px; text-align: center; }

.interactive-grid {
    display: flex;
    gap: 20px;
    flex-wrap: wrap; 
}
.code-column, .vis-column { flex: 1; min-width: 300px; }

#grafo-container {
    width: 100%; 
    height: 500px; 
    border: 1px solid #cbd5e1; 
    border-radius: 8px;
    background: #fff;
}

/* Eficiencia */
.efficiency-box {
    background: #f1f5f9;
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    font-size: 1.5rem;
    margin: 20px auto;
    max-width: 250px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

/* Overrides para Pseudocode.js */
.ps-line.linea-activa { background-color: #ffd447 !important; }
.ps-line.linea-activa > td,
.ps-line.linea-activa > .ps-code, 
.ps-line.linea-activa > .ps-linenum { background-color: transparent !important; }

/* Monitor de variables */
.variables-panel {
    margin-top: 20px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.variables-panel h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 0.95rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 8px;
}

.vars-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.var-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.var-name {
    font-size: 0.85rem;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 5px;
    font-family: 'Courier New', Courier, monospace; /* Estilo código */
}

.var-value {
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 600;
    text-align: center;
    word-break: break-word; /* Evita que se rompa el diseño */
}

/* =========================================
   6. PESTAÑA: MAPA (Leaflet)
   ========================================= */
#mapa-view {
    height: 100%;
    padding: 0;
    overflow: hidden;
}

#map-container {
    width: 100%;
    height: 100%;
    z-index: 1;
    background: #cbd5e1;
}

/* Panel Flotante sobre el Mapa */
.controls-overlay {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    background: rgba(255,255,255,0.95);
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    z-index: 1000;
}

.control-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 10px;
    font-weight: bold;
}

.slider-container { margin-bottom: 10px; display: flex; }
#sim-slider { width: 100%; cursor: pointer; }

.buttons-row {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.step-info-box { 
    background: #f8fafc; 
    border-left: 3px solid var(--primary); 
    padding: 8px; 
    font-size: 0.85rem; 
    color: #475569; 
    max-height: 120px; 
    overflow-y: auto; 
}

/* =========================================
   7. PESTAÑA: ESTADÍSTICAS
   ========================================= */

.results-container {
    display: flex;
    flex-direction: column;
    gap: 40px;
    max-width: 900px;
    margin: 0 auto;
}

/* Tarjeta de Resultado */
.result-card {
    background: white;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    overflow: hidden;
}

.result-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
}

.result-header h3 {
    margin: 0;
    color: var(--text-main);
}

.badge-experiment {
    background: #e2e8f0;
    color: #475569;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
}

/* Área de la Imagen */
.chart-wrapper {
    padding: 20px;
    text-align: center;
    background: #fff;
    position: relative;
    cursor: zoom-in;
    border-bottom: 1px solid var(--border-color);
}

.zoomable-image {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    transition: transform 0.2s;
}

.zoomable-image:hover {
    opacity: 0.95;
}

.zoom-hint {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.chart-wrapper:hover .zoom-hint {
    opacity: 1;
}

/* Caja de Análisis */
.analysis-box {
    padding: 25px;
    background: #ffffff;
}

.analysis-box h4 {
    margin-top: 0;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-list {
    margin-top: 15px;
    padding-left: 20px;
    color: #334155;
}

.stat-list li {
    margin-bottom: 10px;
    line-height: 1.5;
}

/* =========================================
   8. PESTAÑA: REFERENCIAS
   ========================================= */
.references-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 800px;
}

.reference-card {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: box-shadow 0.2s, transform 0.2s;
}

.reference-card:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border-color: #cbd5e1;
}

.reference-card h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--text-main);
    font-size: 1.1rem;
    font-weight: 700;
}

.ref-grid {
    display: grid;
    grid-template-columns: 100px 1fr;
    row-gap: 12px;
    column-gap: 20px;
    align-items: baseline;
    font-size: 0.95rem;
}

.ref-label { color: #64748b; font-weight: 600; }
.ref-value { color: #334155; }

.ref-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
}
.ref-link:hover { text-decoration: underline; color: #2563eb; }

/* =========================================
   9. Otros
   ========================================= */
/* Estilo para enlaces internos dentro de párrafos */
.internal-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed var(--primary);
    cursor: pointer;
    transition: all 0.2s;
}

.internal-link:hover {
    background-color: #eff6ff;
    border-bottom-style: solid;
}