/* Visor tipo libro (flipbook) para documentos PDF de la biblioteca */

.flipbook {
    --fb-blue: #0943B5;
    --fb-blue-dark: #062f80;
    --fb-yellow: #FFC20E;
    position: relative;
    display: flex;
    flex-direction: column;
    margin: 1.25rem 0 1.5rem;
    border-radius: 16px;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 50% 35%, #ffffff 0%, rgba(255, 255, 255, 0) 65%),
        linear-gradient(160deg, #eef1f6 0%, #e2e7ef 100%);
    border: 1px solid #dfe5ee;
    user-select: none;
}

/* ---------- Barra superior ---------- */
.flipbook__barra {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.7rem 1rem;
    background: linear-gradient(90deg, var(--fb-blue) 0%, var(--fb-blue-dark) 100%);
    color: #fff;
}

.flipbook__marca {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
}

.flipbook__marca img {
    height: 38px;
    width: auto;
    flex-shrink: 0;
    padding: 4px 8px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.flipbook__marca-texto {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.flipbook__marca-texto small {
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--fb-yellow);
}

.flipbook__marca-texto span {
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flipbook__herramientas {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
}

.flipbook__herramienta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.2s ease;
}

.flipbook__herramienta:hover {
    background: rgba(255, 255, 255, 0.24);
    transform: translateY(-1px);
}

.flipbook__herramienta:focus-visible,
.flipbook__flecha:focus-visible {
    outline: 3px solid var(--fb-yellow);
    outline-offset: 2px;
}

.flipbook__herramienta[aria-pressed="true"] {
    background: var(--fb-yellow);
    color: #2b2200;
    border-color: var(--fb-yellow);
}

/* ---------- Escenario y libro ---------- */
.flipbook__escenario {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: clamp(420px, calc(100vh - 230px), 920px);
    padding: 1.25rem 4rem;
}

.flipbook__contenedor {
    position: relative;
    margin: 0 auto;
    max-width: 100%;
}

.flipbook__libro {
    filter: drop-shadow(0 18px 30px rgba(15, 23, 42, 0.22));
    transition: transform 0.45s ease;
}

.flipbook__pagina {
    background: #fff;
    overflow: hidden;
}

.flipbook__pagina img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #fff;
    pointer-events: none;
    -webkit-user-drag: none;
}

.flipbook__pagina-espera {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    color: #94a3b8;
    font-size: 0.8rem;
    font-weight: 600;
    background:
        linear-gradient(90deg, #f8fafc 0%, #ffffff 50%, #f8fafc 100%);
}

.flipbook__giro {
    width: 26px;
    height: 26px;
    border: 3px solid #dbe4f3;
    border-top-color: var(--fb-blue);
    border-radius: 50%;
    animation: fb-girar 0.8s linear infinite;
}

@keyframes fb-girar {
    to { transform: rotate(360deg); }
}

.flipbook__flecha {
    position: absolute;
    top: 50%;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    margin-top: -23px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: var(--fb-blue);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.flipbook__flecha:hover {
    background: var(--fb-blue);
    color: #fff;
    transform: scale(1.06);
}

.flipbook__flecha:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
    background: #fff;
    color: var(--fb-blue);
}

.flipbook__flecha--prev { left: 0.9rem; }
.flipbook__flecha--next { right: 0.9rem; }

.flipbook__cargando {
    position: absolute;
    inset: 0;
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    color: var(--fb-blue);
    font-weight: 600;
    background: rgba(238, 241, 246, 0.92);
}

.flipbook__cargando[hidden] {
    display: none;
}

.flipbook__cargando .flipbook__giro {
    width: 42px;
    height: 42px;
    border-width: 4px;
}

.flipbook__error {
    max-width: 420px;
    text-align: center;
    color: #475569;
    font-weight: 500;
}

/* ---------- Pie: progreso ---------- */
.flipbook__pie {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.65rem 1.25rem 0.9rem;
}

.flipbook__contador {
    flex-shrink: 0;
    min-width: 92px;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: #fff;
    color: var(--fb-blue);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08);
}

.flipbook__progreso {
    flex: 1;
    min-width: 0;
    accent-color: var(--fb-blue);
    cursor: pointer;
}

.flipbook__paso {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid #d5deec;
    border-radius: 50%;
    background: #fff;
    color: var(--fb-blue);
    cursor: pointer;
}

.flipbook__paso:hover {
    background: var(--fb-blue);
    color: #fff;
}

.flipbook__paso:disabled {
    opacity: 0.4;
    cursor: default;
    background: #fff;
    color: var(--fb-blue);
}

/* ---------- Paneles: miniaturas y ampliación ---------- */
.flipbook__panel {
    position: absolute;
    inset: 0;
    z-index: 8;
    display: flex;
    flex-direction: column;
    background: rgba(6, 22, 60, 0.94);
    color: #fff;
}

.flipbook__panel[hidden] {
    display: none;
}

.flipbook__panel-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.flipbook__panel-cuerpo {
    flex: 1;
    overflow: auto;
    padding: 1.25rem;
}

.flipbook__miniaturas {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 1rem;
}

.flipbook__miniatura {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.flipbook__miniatura-img {
    position: relative;
    width: 100%;
    background: #fff;
    border-radius: 3px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    outline: 3px solid transparent;
    transition: outline-color 0.2s ease, transform 0.2s ease;
}

.flipbook__miniatura-img img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.flipbook__miniatura:hover .flipbook__miniatura-img,
.flipbook__miniatura:focus-visible .flipbook__miniatura-img {
    outline-color: var(--fb-yellow);
    transform: translateY(-3px);
}

.flipbook__miniatura.is-actual .flipbook__miniatura-img {
    outline-color: var(--fb-yellow);
}

.flipbook__zoom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.flipbook__zoom img {
    display: block;
    width: min(100%, 1100px);
    height: auto;
    background: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
}

/* ---------- Pantalla completa ---------- */
.flipbook:fullscreen {
    margin: 0;
    border-radius: 0;
    border: 0;
    width: 100vw;
    height: 100vh;
}

.flipbook:fullscreen .flipbook__escenario {
    flex: 1;
    height: auto;
}

/* ---------- Móvil ---------- */
@media (max-width: 575.98px) {
    .flipbook__escenario {
        padding: 1rem 0.75rem;
        height: clamp(320px, min(calc(100vh - 200px), calc((100vw - 3rem) * 1.45)), 760px);
    }

    .flipbook__flecha {
        display: none;
    }

    .flipbook__pie {
        gap: 0.5rem;
        padding: 0.6rem 0.75rem 0.8rem;
    }

    .flipbook__marca-texto span {
        display: none;
    }

    .flipbook__herramienta {
        width: 34px;
        height: 34px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .flipbook__herramienta,
    .flipbook__flecha,
    .flipbook__miniatura-img {
        transition: none;
    }
}
