/* style.css */

/* --- DEFINICIÓN DE VARIABLES DE COLOR (THEMING) --- */
:root {
    /* MODO CLARO (Por defecto) */
    --bg-body: #e5e7eb;
    --bg-paper: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --text-paragraph: #212121;
    --border-color: #d1d5db;
    --link-color: #2563eb;
    --h2-border: #374151;
    --h4-color: black;
    --h5-color: #303741;
    --shadow-paper: 0 25px 50px -12px rgba(0, 0, 0, 0.25); /* Sombra negra */
    
    /* Tablas y Etiquetas */
    --th-bg: #fee2e2;       
    --th-text: #991b1b;     
    --td-text: #1f2937;     
    --badge-alta-bg: #ffedd5;
    --badge-alta-text: #9a3412;
    --badge-media-bg: #dbeafe;
    --badge-media-text: #1e40af;
    --badge-baja-bg: #dcfce7;
    --badge-baja-text: #166534;
}

/* MODO OSCURO */
[data-theme="dark"] {
    --bg-body: #111827;     
    --bg-paper: #1f2937;    
    --text-main: #f3f4f6;   
    --text-muted: #9ca3af;  
    --text-paragraph: #e5e7eb;
    --border-color: #374151;
    --link-color: #60a5fa;  
    --h2-border: #9ca3af;
    --h4-color: #ffffff;
    --h5-color: #d1d5db;
    --shadow-paper: 0 0 25px rgba(255, 255, 255, 0.05); /* Sombra blanca resplandeciente */

    /* Tablas y Etiquetas (Adaptadas a oscuro) */
    --th-bg: #450a0a;       
    --th-text: #fca5a5;     
    --td-text: #ffffff;     /* Blanco puro para máximo contraste */
    --badge-alta-bg: #7c2d12;
    --badge-alta-text: #ffedd5;
    --badge-media-bg: #1e3a8a;
    --badge-media-text: #dbeafe;
    --badge-baja-bg: #14532d;
    --badge-baja-text: #dcfce7;
}

/* --- REGLAS DE FORZADO PARA MODO OSCURO (Soluciona el problema de Tailwind) --- */
/* Esto obliga a las negritas (S, M, A, R, T) y al texto de tabla a ser blancos */
[data-theme="dark"] .prose strong,
[data-theme="dark"] .tabla-smart strong {
    color: #ffffff !important;
}

[data-theme="dark"] .prose td,
[data-theme="dark"] .tabla-smart td {
    color: #e5e7eb !important;
}

[data-theme="dark"] .prose li {
    color: #e5e7eb !important;
}

[data-theme="dark"] .img-diagrama {
    background-color: rgba(255, 255, 255, 0.95);
    padding: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

html {
    scroll-behavior: smooth;
    font-size: clamp(14px, 1.5vw + 10px, 16px);
}

body {
    background-color: var(--bg-body);
    margin: 0;
    padding: 40px 0;
    font-family: 'Segoe UI', Roboto, Arial, sans-serif;
    color: var(--text-main);
    transition: background-color 0.3s, color 0.3s; 
    
    /* ESTA ES LA MAGIA: Impide que la pantalla se desplace hacia los lados */
    max-width: 100%;
    overflow-x: hidden; 
}

.prose p, .prose ul, .prose ol, .txt-licencia, .tabla-smart td {
    text-align: left !important;
}

/* --- NUEVO INTERRUPTOR DESLIZANTE (TOGGLE) --- */
.toggle-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

.toggle-input {
    display: none;
}

.toggle-label {
    display: flex;
    align-items: center;
    width: 60px;
    height: 30px;
    background-color: #1f2937; /* Color oscuro del carril */
    border-radius: 50px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.3s;
    border: 2px solid var(--border-color);
}

.toggle-knob {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 24px;
    height: 24px;
    background-color: #ffffff;
    border-radius: 50%;
    position: absolute;
    /* --- AQUÍ ESTÁ LA MAGIA DEL CENTRADO EXACTO --- */
    top: 50%;
    margin-top: -12px; /* Sube exactamente la mitad de su altura para clavarlo al centro */
    left: 1px;         /* Ajustado a 1px para que el margen derecho al encenderlo sea simétrico */
    /* ----------------------------------------------- */
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.icon-moon, .icon-sun {
    position: absolute;
    font-size: 14px;
    line-height: 1;
}

/* Animaciones de los iconos */
.icon-moon { opacity: 1; transform: rotate(0deg); transition: all 0.3s; }
.icon-sun { opacity: 0; transform: rotate(-90deg); transition: all 0.3s; }

/* ESTADOS ACTIVADOS (Modo Oscuro) */
.toggle-input:checked + .toggle-label .toggle-knob {
    transform: translateX(30px);
}

.toggle-input:checked + .toggle-label .icon-moon { opacity: 0; transform: rotate(90deg); }
.toggle-input:checked + .toggle-label .icon-sun { opacity: 1; transform: rotate(0deg); color: #f59e0b; }


/* --- Ajuste de Scroll --- */
.ancla-top {
    scroll-margin-top: 2.5rem;
}

/* --- Contenedor Principal (A4) --- */
.contenedor-pag {
    background-color: var(--bg-paper);
    width: 100%;
    max-width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
    padding: 25mm;
    box-sizing: border-box;
    position: relative;
    box-shadow: var(--shadow-paper); /* Sombra variable según tema */
    transition: background-color 0.3s, box-shadow 0.3s;
}

/* --- Cabecera y Logos --- */
.figura-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-ianuarius {
    width: 400px;
    max-width: 100%;
    margin: 0 auto;
    display: block;
    transition: background-color 0.3s;
}

.img-diagrama {
    width: 800px;
    max-width: 100%;
    margin: 1rem auto;
    display: block;
    border-radius: 6px;
    transition: background-color 0.3s;
}

.pie-foto {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-style: italic;
    margin-top: 0.5rem;
}

.info-cabecera {
    text-align: right;
    margin-bottom: 3rem;
}

.info-cabecera p { margin: 0.25rem 0; }
.txt-mayus { text-transform: uppercase; letter-spacing: 0.05em; font-size: 13px; font-weight: 500; }
.txt-titulo { font-size: 1.25rem; font-weight: bold; color: var(--text-main); }
.txt-insti { font-size: 13px; }

/* LOGO VENANCIO: Margen 150px y fondo blanco en oscuro */
.cont-logo-venancio {
    display: inline-block;
    margin: 1rem 150px;
    background-color: rgba(255, 255, 255, 0.9);
    padding: 5px;
    border-radius: 4px;
}

.logo-venancio { width: 50px; transition: background-color 0.3s; }
.txt-negrita { font-size: 13px; font-weight: bold; color: var(--text-main); margin-top: 1rem; }

/* --- Licencia --- */
.sec-licencia {
    margin-bottom: 3rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.tit-licencia { font-weight: bold; font-size: 0.875rem; color: var(--text-paragraph); text-transform: uppercase; margin-bottom: 0.5rem; }
.txt-licencia { font-size: 0.75rem; color: var(--text-muted); line-height: 1.6; text-align: justify; }
.enlace-azul { color: var(--link-color); text-decoration: none; }
.enlace-azul:hover { text-decoration: underline; }

/* --- Estilos del Texto y Títulos --- */
.prose h2 {
    border-bottom: 2px solid var(--h2-border);
    padding-bottom: 0.5rem;
    margin-top: 3rem;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-main);
}

.prose h4 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--h4-color);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.prose h5 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--h5-color);
    margin-top: 1.5em;
    margin-bottom: 0 !important;
}

.prose h5 + p,
.prose h5 + ul,
.prose h5 + table,
.prose h5 + div {
    margin-top: 0.2rem !important; /* Obliga a Tailwind a pegar el contenido al título */
}

.prose p {
    text-align: justify;
    margin-bottom: 0.2rem;
    color: var(--text-paragraph);
}

/* --- Listas --- */
.prose ul {
    list-style: none !important;
    padding-left: 0 !important;
    margin-bottom: 1rem;
}

.prose ul > li::marker {
    content: none !important;
}

.prose ol {
    list-style-type: decimal;
    padding-left: 1.5rem;
    margin-bottom: 1rem;
}

.prose ol > li::marker {
    color: var(--text-main) !important;
    font-weight: 800;
}

.prose a { color: var(--link-color); text-decoration: none; }
.prose a:hover { text-decoration: underline; }

.prose a, .txt-licencia a {
    overflow-wrap: break-word;
    word-break: break-word;
}

.nota-gris {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 0;
}

@media print {
    body { background: white; padding: 0; }
    .contenedor-pag {
        box-shadow: none;
        margin: 0;
        width: 100%;
        max-width: none;
        padding: 0;
    }
    .toggle-container { display: none; } 
}

/* --- CLASE PARA CONTENIDO NO INCLUIDO --- */
.zona-apagada {
    opacity: 0.4;
    filter: grayscale(100%);
}

/* --- TABLAS SMART (Adaptables) --- */
.tabla-smart {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

.tabla-smart th {
    background-color: var(--th-bg);
    color: var(--th-text);
    font-weight: bold;
    text-align: left;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
}

.tabla-smart td {
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    vertical-align: top;
    color: var(--td-text); 
}

/* Etiquetas de prioridad */
.etiqueta {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: bold;
    text-align: center;
}

.prio-alta { background-color: var(--badge-alta-bg); color: var(--badge-alta-text); }
.prio-media { background-color: var(--badge-media-bg); color: var(--badge-media-text); }
.prio-baja { background-color: var(--badge-baja-bg); color: var(--badge-baja-text); }


/* SANGRÍAS JERÁRQUICAS (Indentación de niveles) */
/* Por defecto (Móviles): Sangrías más pequeñas para no comerse el espacio de lectura */
.nivel-h3 { margin-left: 0.5rem; }
.nivel-h4 { margin-left: 1rem; }
.nivel-h5 { margin-left: 1.5rem; }
/* En pantallas medianas y grandes (Tablets y PC): Sangrías completas */
@media (min-width: 768px) {
    .nivel-h3 { margin-left: 1.5rem; } /* Aprox 24px */
    .nivel-h4 { margin-left: 3rem; }   /* Aprox 48px */
    .nivel-h5 { margin-left: 4.5rem; } /* Aprox 72px */
}

.prose h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.25rem;
}
/* --- SANGRÍAS JERÁRQUICAS --- */
.sangria-1 { margin-left: 1.5rem; }
.sangria-2 { margin-left: 3rem; }
.sangria-3 { margin-left: 4.5rem; }

/* En móviles reducimos la sangría para que el texto no se aplaste */
@media (max-width: 768px) {
    .sangria-1 { margin-left: 0.5rem; }
    .sangria-2 { margin-left: 1rem; }
    .sangria-3 { margin-left: 1.5rem; }
    
}

/* --- AJUSTES RESPONSIVOS (Tablets y Móviles) --- */

/* 1. Pantallas medianas (Tablets y ventanas reducidas) */
@media (max-width: 1024px) {
    .toggle-container {
        position: absolute;
        top: 15px;
        right: 20px;
    }
    body {
        padding-top: 60px; 
    }
    .contenedor-pag {
        width: calc(100% - 60px); /* Forzamos 30px de margen gris a cada lado */
        padding: 30px; 
    }
}

/* 2. Pantallas muy pequeñas (Móviles) */
/* 2. Pantallas muy pequeñas (Móviles) */
@media (max-width: 640px) {
    /* Botón todavía más pequeñito para que no desentone */
    .toggle-container {
        transform: scale(0.73); 
        transform-origin: top right;
        top: 10px;    /* Lo subimos un pelín más al ser más chico */
        right: 10px;  /* Lo pegamos un poco más al borde */
    }

    .contenedor-pag {
        width: 100vw; 
        max-width: 100%;
        padding: 15px; 
        box-shadow: none; 
        border-radius: 0;
        box-sizing: border-box !important;
        overflow: hidden; 
    }

    /* Tablas domadas con scroll horizontal */
    .tabla-smart {
        display: block !important;
        overflow-x: auto !important; 
        white-space: normal;
        -webkit-overflow-scrolling: touch; 
        width: 100%; 
    }

    .tabla-smart th, .tabla-smart td {
        min-width: 130px; 
    }
}

/* Contenedor modal */
.zoom-modal {
    display: none;
    position: fixed;
    z-index: 9999;
    padding-top: 50px;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.9);
    cursor: zoom-out;
    transition: opacity 0.3s ease;
    opacity: 0;
}

/* Img del modal */
.zoom-modal-content {
    margin: auto;
    display: block;
    max-width: 90%;
    max-height: 85%;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: scale(0.7);
    transition: transform 0.3s ease;
}

/* Mostrar modal */
.zoom-modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

/* Animacion img final */
.zoom-modal.show .zoom-modal-content {
    transform: scale(1);
}

/* Img ampliable */
.img-zoomable {
    cursor: zoom-in;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Efecto hover img */
.img-zoomable:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

/* Modo oscuro modal */
body[data-theme="dark"] .zoom-modal {
    background-color: rgba(15, 23, 42, 0.96);
}

/* Fix contraste etiquetas code en modo oscuro */
[data-theme="dark"] .prose code {
    background-color: #374151;
    color: #fca5a5;
    padding: 0.15rem 0.3rem;
    border-radius: 4px;
    font-family: monospace;
}

/* Control del scroll al hacer clic en enlaces del índice */
.ancla-top {
    scroll-margin-top: 3rem; /* Títulos: se quedan arriba con un pequeño margen */
    display: block;
}

.ancla-centro {
    scroll-margin-top: 35vh; /* Tablas/Imágenes: se quedan en el centro de la pantalla */
    display: block;
}