/* ==========================================================================
   1. ESTILOS GLOBALES Y RESET DE LAYOUT
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #1a1a1a;
    touch-action: none;
}

/* ==========================================================================
   2. ÁREA DE TRABAJO (ESCRITORIO Y ENTORNO DEL LIBRO)
   ========================================================================== */
#escritorio-LIB {
    width: 100%;
    height: 100vh;
    height: -webkit-fill-available;
    background: url("https://images.unsplash.com/photo-1546484475-7f7bd55792da?auto=format&fit=crop&w=1920&q=80") center/cover no-repeat;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    touch-action: none;
}

#zoom-wrapper-LIB {
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    transform-origin: center center;
    max-width: 100%;
    max-height: calc(100vh - 90px);
    z-index: 10;
}

.container-book-LIB {
    box-shadow: 0 15px 35px rgba(0,0,0,0.6);
    opacity: 0;
    transition: opacity 0.5s ease, transform 0.4s ease-out;
    touch-action: none;
}

.page-LIB {
    background-color: #ffffff;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================================================
   3. ELIMINAR HOJAS FANTASMA EN PORTADA Y CONTRAPORTADA
   ========================================================================== */
.stf-block.--empty,
.page-LIB.--hard.--left,
.page-LIB.--hard.--right {
    box-shadow: none !important;
    background: transparent !important;
}

.container-book-LIB[data-page="1"] .stf-block.--left,
.container-book-LIB[data-page="1"] .stf-wrapper > .--left,
.container-book-LIB[data-page="1"] .stf-wrapper > div:first-child {
    display: none !important;
    width: 0 !important;
    max-width: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.container-book-LIB[data-page-last="true"] .stf-block.--right,
.container-book-LIB[data-page-last="true"] .stf-wrapper > .--right,
.container-book-LIB[data-page-last="true"] .stf-wrapper > div:last-child {
    display: none !important;
    width: 0 !important;
    max-width: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.annotationLayer {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    pointer-events: none !important;
    z-index: 99 !important;
}

.annotationLayer a, 
.annotationLayer .linkAnnotation > a,
.annotationLayer section[data-annotation-id] {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* ==========================================================================
   4. PANTALLA DE CARGA (LOADER)
   ========================================================================== */
.icono-giratorio-LIB {
    animation: girarIcono 1.2s linear infinite;
    display: inline-block;
}

@keyframes girarIcono {
    to { transform: rotate(360deg); }
}

#loading-container-LIB {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    z-index: 1000;
}

.loader-spinner-LIB {
    width: 70px;
    height: 70px;
    background-color: #ffffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

.loader-spinner-LIB i {
    font-size: 38px;
    color: #7f7f7f;
}

.loading-badge-LIB {
    background: rgba(100, 100, 100, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    color: #ffffff;
    font-size: 14px;
    font-style: italic;
    padding: 8px 24px;
    border-radius: 12px;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 80vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ==========================================================================
   5. BOTONES LATERALES
   ========================================================================== */
.nav-side-btn-LIB {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    z-index: 150;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.3);
    width: 44px;
    height: 54px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    backdrop-filter: blur(4px);
}

.nav-side-btn-LIB:active {
    transform: translateY(-50%) scale(0.92);
    background: rgba(0, 0, 0, 0.85);
}

#side-prev-LIB { left: 8px; }
#side-next-LIB { right: 8px; }

/* ==========================================================================
   6. TOOLBAR Y MENÚS
   ========================================================================== */
#toolbar-container-LIB {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    width: 94vw;
    max-width: 550px;
    display: flex;
    justify-content: center;
}

#toolbar-LIB {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #e9ecef;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    border: 1px solid #ced4da;
    width: 100%;
    padding: 4px 6px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}

#toolbar-LIB::-webkit-scrollbar { display: none; }

.tb-btn-LIB {
    background: transparent;
    border: none;
    padding: 8px 10px;
    color: #495057;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
}

.tb-btn-LIB.active-LIB {
    background: #0088cc;
    color: #ffffff;
}

.tb-divider-LIB {
    width: 1px;
    height: 20px;
    background: #ced4da;
    margin: 0 2px;
    flex-shrink: 0;
}

#input-current-page-LIB {
    min-width: 52px;
    max-width: 75px;
    height: 24px;
    padding: 0 4px;
    background: #e9e9e9;
    border: 1.5px solid #1a1a1a;
    border-radius: 5px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: #333333;
    outline: none;
}

.btn-more-LIB { color: #0088cc; }

#more-menu-LIB {
    display: none;
    position: absolute;
    bottom: 55px;
    right: 0;
    width: 230px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    border: 1px solid #dee2e6;
    flex-direction: column;
    z-index: 10000;
}

#more-menu-LIB.active-LIB { display: flex; }

.menu-item-LIB {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: #495057;
    font-size: 14px;
    background: transparent;
    border: none;
    border-bottom: 1px solid #e9ecef;
    cursor: pointer;
    text-decoration: none;
}

.menu-item-LIB:last-child { border-bottom: none; }
.menu-item-LIB:hover { background-color: #f8f9fa; }

/* ==========================================================================
   7. SIDEBAR (ÍNDICE / MINIATURAS)
   ========================================================================== */
#sidebar-left-LIB {
    position: fixed;
    top: 0;
    left: -280px;
    width: 260px;
    max-width: 75vw;
    height: 100vh;
    background: #ffffff;
    box-shadow: 5px 0 25px rgba(0,0,0,0.4);
    z-index: 10001;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

#sidebar-left-LIB.open-LIB { left: 0; }

.sidebar-header-LIB {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
    padding: 10px 12px;
}

.sidebar-tabs-LIB { display: flex; gap: 6px; }

.tab-btn-LIB {
    background: transparent;
    border: none;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #6c757d;
    cursor: pointer;
    border-radius: 6px;
}

.tab-btn-LIB.active-LIB {
    background: #e9ecef;
    color: #0088cc;
}

.close-sidebar-btn-LIB {
    background: transparent;
    border: none;
    font-size: 22px;
    color: #888;
    cursor: pointer;
}

.search-toc-wrapper-LIB {
    padding: 8px 10px;
    border-bottom: 1px solid #e9ecef;
    background: #fafafa;
}

.search-toc-wrapper-LIB input {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    outline: none;
}

.sidebar-body-LIB {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.tab-content-LIB { display: none; }
.tab-content-LIB.active-LIB { display: block; }

.toc-list-LIB, .toc-sublist-LIB { list-style: none; padding-left: 0; }
.toc-sublist-LIB { display: none; }
.toc-group-LIB.expanded-LIB > .toc-sublist-LIB { display: block; }

.toc-item-LIB {
    padding: 8px 10px;
    border-bottom: 1px solid #f1f3f5;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #333333;
    font-size: 12px;
}

.toc-item-LIB:hover { background-color: #f1f3f5; color: #0088cc; }

.toc-item-LIB.active-LIB {
    background-color: #e7f5ff;
    color: #0088cc;
    font-weight: 700;
    border-left: 4px solid #0088cc;
}

.toc-item-LIB b {
    font-size: 10.5px;
    color: #0088cc;
    background: #e7f5ff;
    padding: 2px 6px;
    border-radius: 4px;
}

.toc-item-LIB.active-LIB b { background: #0088cc; color: #ffffff; }

.grid-container-sidebar-LIB {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.thumb-item-LIB {
    width: 100%;
    max-width: 140px;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
    text-align: center;
    background: #ffffff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
}

.thumb-item-LIB span {
    order: -1;
    padding: 5px 0;
    font-size: 11px;
    font-weight: 700;
    color: #0077b6;
    background: #edf2f7;
    border-bottom: 1px solid #e2e8f0;
}

.thumb-item-LIB.active-LIB {
    border-color: #0088cc;
    transform: scale(1.03);
    box-shadow: 0 4px 14px rgba(0, 136, 204, 0.35);
}

/* ==========================================================================
   8. MODAL COMPARTIR
   ========================================================================== */
#share-modal-overlay-LIB {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.65);
    z-index: 20000;
    justify-content: center;
    align-items: center;
}

#share-modal-overlay-LIB.active-LIB { display: flex; }

.share-card-LIB {
    background: #22252a;
    width: 340px;
    max-width: 90vw;
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.close-share-btn-LIB {
    position: absolute;
    top: 10px;
    right: 14px;
    background: transparent;
    border: none;
    font-size: 24px;
    color: #94a3b8;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
}

.close-share-btn-LIB:hover { color: #ffffff; }

.share-card-title-LIB { font-size: 18px; color: #e2e8f0; margin-bottom: 16px; }

.share-input-box-LIB {
    width: 100%;
    height: 75px;
    border: 1px solid #3a3f47;
    border-radius: 10px;
    padding: 10px;
    font-family: monospace;
    font-size: 12.5px;
    color: #cbd5e1;
    background-color: #16181c;
    resize: none;
    outline: none;
    margin-bottom: 22px;
}

.share-social-icons-LIB { display: flex; gap: 22px; }

.share-icon-btn-LIB {
    color: #94a3b8;
    font-size: 20px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.06);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}