/*
  Archivo de Estilos Optimizado para el Visor de Impresos
  ---------------------------------------------------------
  - CORREGIDO: Se restaura el centrado del .main-container.
*/

/* 1. ESTILOS GLOBALES Y LAYOUT PRINCIPAL */
body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 50%, #dee2e6 100%);
    min-height: 100vh;
    color: #333;
}

.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    padding: 15px 0;
    box-shadow: 0 4px 30px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid rgba(0,0,0,0.1);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
}

.logo {
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.main-container {
    max-width: 1200px;
    margin: 0 auto; /* <-- ESTA LÍNEA ES LA QUE CENTRA TODO */
    padding: 20px;
}

/* 2. COMPONENTES DE UI (LOADING, ERROR) */
.loading, .error {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    border-radius: 15px;
    margin: 20px 0;
    backdrop-filter: blur(10px);
}

.loading {
    height: 400px;
    background: rgba(255, 255, 255, 0.9);
    font-size: 18px;
    color: #6c757d;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
}

.error {
    background: rgba(220, 53, 69, 0.1);
    color: #dc3545;
    text-align: center;
    border: 1px solid rgba(220, 53, 69, 0.2);
}

/* 3. BARRA DE CONTROL PRINCIPAL (ROJA) */
.control-bar {
    position: relative;
    height: 60px;
    background: linear-gradient(135deg, #e41e2b 0%, #c41e3a 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    box-shadow: 0 8px 25px rgba(228, 30, 43, 0.3);
    border-radius: 15px;
    margin: 20px auto 0 auto;
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
}

.control-bar .ctrl-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: #fff;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 18px;
    backdrop-filter: blur(5px);
}

.control-bar .ctrl-btn:hover { 
    background: rgba(255,255,255,0.2); 
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.control-bar .ctrl-btn:active {
    transform: translateY(0);
}

.control-bar .ctrl-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.control-bar .page-indicator {
    min-width: 120px;
    text-align: center;
    font-weight: 600;
    font-size: 16px;
    background: rgba(255,255,255,0.15);
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(5px);
}

.control-bar .sep { 
    width: 1px;
    height: 32px; 
    background: rgba(255,255,255,0.3); 
    margin: 0 6px; 
    border-radius: 1px;
}

/* 4. LISTA DE PDFS RECIENTES */
.latest-section {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(15px);
    padding: 20px;
    border-radius: 15px;
    margin-top: 30px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.1);
    border: 1px solid rgba(0,0,0,0.05);
}

.latest-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.latest-pdf-item {
    display: block;
    text-decoration: none;
    color: inherit;
    background: rgba(255,255,255,0.9);
    border-radius: 15px;
    overflow: hidden;
    transition: all 0.3s ease;
    border: 1px solid rgba(0,0,0,0.1);
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.latest-pdf-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    background: rgba(255,255,255,1);
}

.latest-pdf-item .thumbnail-container {
    position: relative;
    width: 100%;
    height: 200px;
    overflow: hidden;
}

.latest-pdf-item .thumbnail-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.latest-pdf-item:hover .thumbnail-container img {
    transform: scale(1.05);
}

.latest-pdf-item .content {
    padding: 15px;
}

.latest-pdf-item .content .title {
    font-size: 16px;
    font-weight: 600;
    color: #2c3e50;
    margin: 0 0 8px 0;
}

.latest-pdf-item .content .date {
    font-size: 14px;
    color: rgba(0,0,0,0.6);
}

.latest-pdf-item .content .category {
    margin-top: 8px;
}

.latest-pdf-item .content .badge {
    background: linear-gradient(135deg, #e41e2b 0%, #c41e3a 100%);
    color: white;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

/* 5. NÚCLEO DEL VISOR (WOWBOOK) */
.wowbook-book-container {
    position: relative;
    height: 600px; /* Altura por defecto para escritorio */
    margin: 20px auto 0 auto;
    perspective: 2500px;
    transform-style: preserve-3d;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(15px);
    border-radius: 20px;
    padding: 20px;
    border: 1px solid rgba(0,0,0,0.05);
    box-shadow: 0 12px 40px rgba(0,0,0,0.1);
    display: none; /* Oculto hasta que se carga un PDF */
}

.wowbook-book-container.show {
    display: block;
}

.wowbook {
    position: relative;
    height: 100%;
    width: 100%;
    transform-style: preserve-3d;
    margin: 0 auto;
}

.wowbook-origin {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.wowbook-zoomwindow,
.wowbook-clipper,
.wowbook-inner-clipper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.wowbook-zoomcontent {
    position: absolute;
    width: 100%;
    height: 100%;
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-tap-highlight-color: transparent;
}

/* 6. PÁGINAS DEL LIBRO */
.wowbook-page {
    position: absolute;
    width: 50%;
    height: 100%;
    transform-style: preserve-3d;
    backface-visibility: hidden;
    will-change: transform;
    background: #fff;
}

.wowbook-page.wowbook-left {
    left: 0;
    transform-origin: 100% 50%;
}

.wowbook-page.wowbook-right {
    left: 50%;
    transform-origin: 0% 50%;
}

.wowbook-page.single-page {
    left: 25% !important; /* Centrado en desktop */
    width: 50% !important;
}

.wowbook-page-content {
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    position: relative;
    background: #fff;
    border-radius: 3px;
    box-shadow: 0 3px 6px rgba(0,0,0,0.15), 0 6px 12px rgba(0,0,0,0.1);
    border: 1px solid #e0e0e0;
    overflow: auto; /* Permite PAN con zoom */
    display: flex;
    align-items: center;
    justify-content: center;
}

.wowbook-page-content canvas {
    display: block;
    margin: 0;
}

/* Estilos para Panorámica (Zoom) */
.wowbook-book-container.zoomed .wowbook-page-content {
    cursor: grab;
    justify-content: flex-start;
    align-items: flex-start;
}
.wowbook-book-container.grabbing .wowbook-page-content {
    cursor: grabbing;
}

/* 7. EFECTOS Y SOMBRAS */
.wowbook-gutter-shadow {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to right, 
        rgba(0,0,0,0.22) 0%, 
        transparent 10%, 
        transparent 90%, 
        rgba(0,0,0,0.22) 100%);
    pointer-events: none;
    z-index: 2;
}

.wowbook-book-shadow {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    height: 20px;
    background: radial-gradient(ellipse, rgba(0,0,0,0.4) 0%, transparent 70%);
    border-radius: 50%;
    z-index: -1;
    filter: blur(2px);
}

/* 8. ANIMACIONES DE PASO DE PÁGINA */
.wowbook-page.flipping {
    z-index: 20;
    pointer-events: none;
}

.wowbook-page.flip-left {
    animation: wowbookFlipLeft 1.2s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

.wowbook-page.flip-right {
    animation: wowbookFlipRight 1.2s cubic-bezier(0.4, 0.0, 0.2, 1) forwards;
}

@keyframes wowbookFlipLeft {
    0%   { transform: rotateY(0deg) translateZ(0px); filter: brightness(1); }
    45%  { transform: rotateY(-90deg) translateZ(45px); filter: brightness(0.85); }
    100% { transform: rotateY(-180deg) translateZ(0px); filter: brightness(1); }
}

@keyframes wowbookFlipRight {
    0%   { transform: rotateY(0deg) translateZ(0px); filter: brightness(1); }
    45%  { transform: rotateY(90deg) translateZ(45px); filter: brightness(0.85); }
    100% { transform: rotateY(180deg) translateZ(0px); filter: brightness(1); }
}

/* 9. ESTILOS PARA PANTALLA COMPLETA */
body.impreso-fullscreen .control-bar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 18px;
    z-index: 10000;
    width: min(92vw, 1100px);
}

body.impreso-fullscreen .wowbook-book-container {
    height: 100vh !important;
    width: 100vw !important;
    margin: 0 !important;
    padding: 5px !important;
    border-radius: 0 !important;
    border: none !important;
    box-shadow: none !important;
}

/* 10. ZONAS DE NAVEGACIÓN VISUALES */
.nav-zone {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 45px;
    height: 70px;
    background: rgba(0, 0, 0, 0.25);
    color: rgba(255, 255, 255, 0.8);
    display: none; /* Oculto por defecto */
    place-items: center;
    font-size: 24px;
    cursor: pointer;
    z-index: 100;
    border-radius: 8px;
    opacity: 0.7;
    transition: opacity 0.3s ease, background 0.3s ease;
}

.nav-zone-left {
    left: 10px;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.nav-zone-right {
    right: 10px;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.nav-zone:hover {
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
}


/* 11. ESTILOS RESPONSIVE (MEDIA QUERIES) */
@media (max-width: 768px) {
    .header-content {
        padding: 0 12px;
    }
    .logo {
        font-size: 20px;
    }
    .main-container {
        /* Para móvil, el padding se gestiona dentro de los elementos */
        padding: 0;
        /* La regla `margin: 0 auto` de arriba sigue funcionando aquí, centrando el contenido si el ancho es menor a 1200px */
    }
    
    .wowbook-book-container {
        border-radius: 0;
        margin: 0;
        padding: 0;
        /* La altura es gestionada por JS para adaptarse al viewport */
    }
    
    .wowbook-page.single-page {
        left: 0 !important;
        width: 100% !important;
    }

    /* Mostrar las zonas de navegación visuales en móvil */
    .wowbook-book-container.show .nav-zone {
        display: grid;
    }
    
    .control-bar { 
        height: 56px; 
        gap: 8px; 
        width: 100%;
        border-radius: 0;
        margin-top: 0;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 1001;
    }

    .control-bar .ctrl-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .control-bar .page-indicator {
        min-width: 90px;
        padding: 6px 10px;
        font-size: 14px;
    }
}