.biblioteca-page {
    --bib-blue: #0943B5;
    --bib-blue-dark: #062f80;
    --bib-blue-soft: #e8efff;
    --bib-yellow: #FFC20E;
    --bib-text: #1f2937;
    --bib-muted: #6b7280;
    --bib-border: #e5e7eb;
    --bib-bg: #f8fafc;
    /* Geometría de la estantería: portada 150x212, repisa debajo de cada fila */
    --bib-portada-w: 150px;
    --bib-portada-h: 212px;
    --bib-pad-top: 14px;
    --bib-fila: 344px;
    --bib-gap-fila: 26px;
}

/* ---------- Encabezado ---------- */
.biblioteca-page .bib-hero {
    position: relative;
    overflow: hidden;
    border-radius: 20px;
    padding: 2.25rem 2rem 2rem;
    margin-bottom: 2rem;
    color: #fff;
    background:
        radial-gradient(circle at 92% 12%, rgba(255, 194, 14, 0.28) 0, rgba(255, 194, 14, 0) 38%),
        linear-gradient(135deg, var(--bib-blue) 0%, var(--bib-blue-dark) 100%);
    box-shadow: 0 14px 34px rgba(9, 67, 181, 0.22);
}

.biblioteca-page .bib-hero::after {
    content: "";
    position: absolute;
    right: -30px;
    bottom: -40px;
    width: 260px;
    height: 200px;
    opacity: 0.12;
    background:
        linear-gradient(#fff, #fff) 0 100% / 34px 150px no-repeat,
        linear-gradient(#fff, #fff) 44px 100% / 28px 120px no-repeat,
        linear-gradient(#fff, #fff) 82px 100% / 38px 170px no-repeat,
        linear-gradient(#fff, #fff) 130px 100% / 26px 135px no-repeat,
        linear-gradient(#fff, #fff) 166px 100% / 34px 160px no-repeat;
    transform: rotate(-6deg);
    pointer-events: none;
}

.biblioteca-page .bib-hero__eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--bib-yellow);
    margin-bottom: 0.5rem;
}

.biblioteca-page .bib-hero h1 {
    font-weight: 800;
    font-size: clamp(1.8rem, 3vw, 2.4rem);
    letter-spacing: -0.02em;
    margin: 0 0 0.35rem;
}

.biblioteca-page .bib-hero p {
    margin: 0;
    max-width: 640px;
    color: rgba(255, 255, 255, 0.86);
}

.biblioteca-page .bib-hero .rich-text-content,
.biblioteca-page .bib-hero .rich-text-content * {
    color: rgba(255, 255, 255, 0.86);
    max-width: 640px;
}

.biblioteca-page .bib-buscador {
    position: relative;
    max-width: 560px;
    margin-top: 1.4rem;
}

.biblioteca-page .bib-buscador svg {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--bib-muted);
    pointer-events: none;
}

.biblioteca-page .bib-buscador input {
    width: 100%;
    border: 0;
    border-radius: 999px;
    padding: 0.85rem 1.2rem 0.85rem 2.8rem;
    font-size: 0.98rem;
    color: var(--bib-text);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.15);
}

.biblioteca-page .bib-buscador input:focus {
    outline: 3px solid var(--bib-yellow);
    outline-offset: 2px;
}

.biblioteca-page .bib-hero__stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    font-size: 0.82rem;
}

.biblioteca-page .bib-hero__stats span {
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    padding: 0.25rem 0.75rem;
}

/* ---------- Secciones y filtros ---------- */
.biblioteca-page .bib-seccion {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--bib-blue);
    font-weight: 700;
    font-size: 1.15rem;
    margin: 0 0 1rem;
}

.biblioteca-page .bib-seccion::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, #c7d7f5, transparent);
}

.biblioteca-page .bib-filtros {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.biblioteca-page .bib-chip {
    border: 1px solid #c7d7f5;
    background: #fff;
    color: var(--bib-blue);
    border-radius: 999px;
    padding: 0.35rem 0.95rem;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.biblioteca-page .bib-chip:hover {
    background: var(--bib-blue-soft);
}

.biblioteca-page .bib-chip.is-activo {
    background: var(--bib-blue);
    border-color: var(--bib-blue);
    color: #fff;
    box-shadow: 0 4px 12px rgba(9, 67, 181, 0.25);
}

.biblioteca-page .bib-chip:focus-visible {
    outline: 2px solid var(--bib-yellow);
    outline-offset: 2px;
}

/* ---------- Colecciones (carpetas) ---------- */
.biblioteca-page .bib-coleccion {
    display: flex;
    align-items: center;
    gap: 1rem;
    height: 100%;
    padding: 1rem 1.1rem;
    border-radius: 14px;
    border: 1px solid var(--bib-border);
    background: #fff;
    color: inherit;
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.biblioteca-page .bib-coleccion:hover {
    transform: translateY(-3px);
    border-color: #c7d7f5;
    box-shadow: 0 10px 24px rgba(9, 67, 181, 0.12);
    color: inherit;
}

.biblioteca-page .bib-coleccion__libros {
    position: relative;
    flex-shrink: 0;
    width: 62px;
    height: 58px;
}

.biblioteca-page .bib-coleccion__libros span {
    position: absolute;
    bottom: 0;
    width: 16px;
    border-radius: 3px 3px 1px 1px;
    box-shadow: inset -3px 0 0 rgba(0, 0, 0, 0.12);
}

.biblioteca-page .bib-coleccion__libros span:nth-child(1) { left: 2px; height: 46px; background: var(--bib-blue); }
.biblioteca-page .bib-coleccion__libros span:nth-child(2) { left: 20px; height: 54px; background: #3b82f6; }
.biblioteca-page .bib-coleccion__libros span:nth-child(3) { left: 38px; height: 42px; background: var(--bib-yellow); transform: rotate(10deg); transform-origin: bottom left; }

.biblioteca-page .bib-coleccion__body {
    min-width: 0;
}

.biblioteca-page .bib-coleccion__titulo {
    margin: 0 0 0.2rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--bib-text);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.biblioteca-page .bib-coleccion:hover .bib-coleccion__titulo {
    color: var(--bib-blue);
}

.biblioteca-page .bib-coleccion__meta {
    font-size: 0.8rem;
    color: var(--bib-muted);
}

/* ---------- Estantería ---------- */
.biblioteca-page .bib-estante {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
    grid-auto-rows: var(--bib-fila);
    row-gap: var(--bib-gap-fila);
    column-gap: 14px;
    padding: 0 0.75rem;
    border-radius: 16px;
    background-color: #f6f8fc;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent calc(var(--bib-pad-top) + var(--bib-portada-h)),
        #ead7b5 calc(var(--bib-pad-top) + var(--bib-portada-h)),
        #e2c79c calc(var(--bib-pad-top) + var(--bib-portada-h) + 10px),
        #bf9a66 calc(var(--bib-pad-top) + var(--bib-portada-h) + 10px),
        #b48c58 calc(var(--bib-pad-top) + var(--bib-portada-h) + 16px),
        rgba(15, 23, 42, 0.10) calc(var(--bib-pad-top) + var(--bib-portada-h) + 16px),
        transparent calc(var(--bib-pad-top) + var(--bib-portada-h) + 26px),
        transparent calc(var(--bib-fila) + var(--bib-gap-fila))
    );
}

.biblioteca-page .bib-libro {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: var(--bib-pad-top);
    min-width: 0;
}

.biblioteca-page .bib-libro[hidden] {
    display: none;
}

.biblioteca-page .bib-libro__portada {
    position: relative;
    width: var(--bib-portada-w);
    height: var(--bib-portada-h);
    flex-shrink: 0;
    border-radius: 3px 8px 8px 3px;
    background: #fff;
    box-shadow:
        0 1px 1px rgba(0, 0, 0, 0.08),
        6px 8px 16px rgba(15, 23, 42, 0.22);
    transform-origin: bottom center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.biblioteca-page .bib-libro__portada::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 12px;
    z-index: 3;
    border-radius: 3px 0 0 3px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.28), rgba(255, 255, 255, 0.18) 55%, rgba(0, 0, 0, 0.08));
    pointer-events: none;
}

.biblioteca-page .bib-libro:hover .bib-libro__portada,
.biblioteca-page .bib-libro:focus-within .bib-libro__portada {
    transform: translateY(-10px) rotate(-1.5deg);
    box-shadow:
        0 1px 1px rgba(0, 0, 0, 0.08),
        10px 18px 28px rgba(15, 23, 42, 0.28);
}

.biblioteca-page .bib-libro__enlace {
    position: absolute;
    inset: 0;
    display: block;
    overflow: hidden;
    border-radius: inherit;
}

.biblioteca-page .bib-libro__enlace:focus-visible {
    outline: 3px solid var(--bib-yellow);
    outline-offset: 3px;
}

.biblioteca-page .bib-libro__img,
.biblioteca-page .bib-libro__pdf img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    z-index: 2;
    background: #fff;
    animation: bib-aparecer 0.35s ease;
}

@keyframes bib-aparecer {
    from { opacity: 0; }
    to { opacity: 1; }
}

.biblioteca-page .bib-libro__generica {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem 0.85rem 0.8rem 1.35rem;
    color: #fff;
    background:
        linear-gradient(160deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0) 45%),
        linear-gradient(180deg, var(--bib-blue) 0%, var(--bib-blue-dark) 100%);
}

.biblioteca-page .bib-libro__generica::after {
    content: "";
    position: absolute;
    left: 1.35rem;
    right: 0.85rem;
    top: 2.6rem;
    height: 3px;
    background: var(--bib-yellow);
    border-radius: 2px;
}

.biblioteca-page .bib-libro__generica-cat {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.biblioteca-page .bib-libro__generica-titulo {
    margin-top: 1.4rem;
    font-size: 0.8rem;
    font-weight: 700;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 7;
    line-clamp: 7;
    overflow: hidden;
}

.biblioteca-page .bib-libro__generica-marca {
    margin-top: auto;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    color: var(--bib-yellow);
}

.biblioteca-page .bib-libro__pdf.is-cargando::after {
    content: "";
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 2;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: bib-girar 0.8s linear infinite;
}

@keyframes bib-girar {
    to { transform: rotate(360deg); }
}

.biblioteca-page .bib-libro__cinta {
    position: absolute;
    top: 10px;
    right: -6px;
    z-index: 4;
    background: var(--bib-yellow);
    color: #3b2f00;
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 3px 3px 0 3px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.biblioteca-page .bib-libro__cinta::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: -6px;
    border-left: 6px solid #c99700;
    border-bottom: 6px solid transparent;
}

.biblioteca-page .bib-libro__tipo {
    position: absolute;
    right: 8px;
    bottom: 8px;
    z-index: 4;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    padding: 0.12rem 0.45rem;
    border-radius: 999px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.biblioteca-page .bib-libro__tipo--pdf { background: #fee2e2; color: #b91c1c; }
.biblioteca-page .bib-libro__tipo--enlace { background: #dbeafe; color: #1d4ed8; }
.biblioteca-page .bib-libro__tipo--archivo { background: #e5e7eb; color: #374151; }

.biblioteca-page .bib-libro__acciones {
    position: absolute;
    left: 12px;
    right: 0;
    bottom: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 2.2rem 0.6rem 0.6rem;
    border-radius: 0 0 8px 0;
    background: linear-gradient(to top, rgba(6, 47, 128, 0.94), rgba(6, 47, 128, 0.6) 70%, transparent);
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.biblioteca-page .bib-libro:hover .bib-libro__acciones,
.biblioteca-page .bib-libro:focus-within .bib-libro__acciones {
    opacity: 1;
    transform: translateY(0);
}

.biblioteca-page .bib-libro__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.32rem 0.5rem;
    border-radius: 999px;
    background: var(--bib-yellow);
    color: #2b2200;
    font-size: 0.76rem;
    font-weight: 700;
    text-decoration: none;
}

.biblioteca-page .bib-libro__btn:hover {
    background: #ffd54a;
    color: #2b2200;
}

.biblioteca-page .bib-libro__btn--claro {
    background: rgba(255, 255, 255, 0.95);
    color: var(--bib-blue);
}

.biblioteca-page .bib-libro__btn--claro:hover {
    background: #fff;
    color: var(--bib-blue-dark);
}

.biblioteca-page .bib-libro__info {
    width: 100%;
    max-width: 176px;
    margin-top: 30px;
    text-align: center;
}

.biblioteca-page .bib-libro__titulo {
    margin: 0 0 0.25rem;
    font-size: 0.84rem;
    font-weight: 700;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

.biblioteca-page .bib-libro__titulo a {
    color: var(--bib-text);
    text-decoration: none;
}

.biblioteca-page .bib-libro__titulo a:hover {
    color: var(--bib-blue);
}

.biblioteca-page .bib-libro__meta {
    margin: 0;
    display: flex;
    justify-content: center;
    gap: 0.3rem;
    font-size: 0.74rem;
    color: var(--bib-muted);
    white-space: nowrap;
    overflow: hidden;
}

.biblioteca-page .bib-libro__meta span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* En pantallas táctiles las acciones quedan siempre visibles */
@media (hover: none) {
    .biblioteca-page .bib-libro__acciones {
        opacity: 1;
        transform: none;
        flex-direction: row;
        padding: 1.6rem 0.4rem 0.45rem;
    }

    .biblioteca-page .bib-libro__btn {
        flex: 1;
        padding: 0.3rem 0.25rem;
        font-size: 0.7rem;
    }

    .biblioteca-page .bib-libro__tipo {
        display: none;
    }
}

@media (max-width: 420px) {
    .biblioteca-page {
        --bib-portada-w: 132px;
        --bib-portada-h: 187px;
        --bib-fila: 318px;
    }

    .biblioteca-page .bib-estante {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        column-gap: 8px;
        padding: 0 0.4rem;
    }

    .biblioteca-page .bib-hero {
        padding: 1.6rem 1.2rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .biblioteca-page .bib-libro__portada,
    .biblioteca-page .bib-libro__acciones,
    .biblioteca-page .bib-coleccion {
        transition: none;
    }

    .biblioteca-page .bib-libro:hover .bib-libro__portada,
    .biblioteca-page .bib-libro:focus-within .bib-libro__portada {
        transform: none;
    }
}

/* ---------- Estados ---------- */
.biblioteca-page .bib-empty {
    background: var(--bib-bg);
    border: 1px dashed #c7d7f5;
    border-radius: 14px;
    padding: 2.5rem 1rem;
    color: var(--bib-muted);
    text-align: center;
}

.biblioteca-page .bib-empty strong {
    color: var(--bib-blue);
}
