/* ============================================
   CBBC BOOKS LIBRARY AND ONLINE READER
   Uses the existing style.css palette.
============================================ */

.books-hero {
    padding: 58px 0 88px;
    background: linear-gradient(
        135deg,
        #f0faff 0%,
        #ffffff 52%,
        #eefaf3 100%
    );
    border-bottom: 1px solid var(--border);
}

.books-hero-inner {
    max-width: var(--container);
}

.books-back-link,
.viewer-back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--blue-dark);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 30px;
}

.books-hero h1 {
    margin: 12px 0 16px;
    max-width: 800px;
    font: 700 clamp(38px, 5vw, 60px)/1.12
        "Playfair Display", serif;
    color: var(--navy);
    letter-spacing: -1px;
}

.books-hero h1 span {
    color: var(--blue-dark);
}

.books-hero p {
    max-width: 690px;
    color: var(--text-light);
    font-size: 16px;
    line-height: 1.8;
}

/* Library statistics */

.books-stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 30px;
}

.books-stat {
    min-width: 120px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: rgba(255, 255, 255, .88);
    border: 1px solid var(--border);
    border-radius: 13px;
    padding: 13px 18px;
}

.books-stat strong {
    font-size: 23px;
    color: var(--navy);
    line-height: 1.2;
}

.books-stat span {
    color: var(--text-light);
    font-size: 12px;
}

/* Main library section */

.books-library {
    padding: 62px 0 90px;
}

.books-library-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.books-library-heading h2 {
    color: var(--navy);
    font: 700 clamp(28px, 3vw, 38px)/1.2
        "Playfair Display", serif;
    margin-top: 7px;
}

.books-library-heading p {
    color: var(--text-light);
    font-size: 14px;
    margin-top: 9px;
}

/* Search and file-type filter */

.books-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 10px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 28px;
}

.books-search {
    flex: 1 1 260px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 12px;
}

.books-search > span {
    font-size: 26px;
    color: var(--blue-dark);
    line-height: 1;
}

.books-search input {
    width: 100%;
    height: 44px;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font: inherit;
    font-size: 14px;
}

.books-filter-label select {
    height: 44px;
    max-width: 100%;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #fff;
    color: var(--text);
    padding: 0 32px 0 12px;
    font: inherit;
    font-size: 13px;
}

.books-search-button {
    height: 44px;
    padding: 0 22px;
    border: 0;
    border-radius: 9px;
    background: var(--blue-dark);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.books-search-button:hover {
    background: #206d98;
}

.books-clear {
    padding: 8px;
    color: var(--blue-dark);
    font-size: 13px;
    font-weight: 600;
}

/* Book cards */

.books-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}

.book-card {
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-sm);
    transition: transform .22s ease, box-shadow .22s ease;
}

.book-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow);
}

.book-card-top {
    min-height: 145px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.file-pdf {
    color: #277eae;
    background: linear-gradient(135deg, #eaf7fd, #f6fcff);
}

.file-word {
    color: #287b50;
    background: linear-gradient(135deg, #eefaf3, #f8fdf9);
}

.book-file-icon {
    width: 58px;
    height: 66px;
}

.book-file-icon svg {
    width: 100%;
    height: 100%;
}

.book-type-pill {
    position: absolute;
    right: 14px;
    top: 14px;
    padding: 5px 9px;
    border-radius: 100px;
    background: rgba(255, 255, 255, .9);
    color: var(--navy);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .5px;
}

.book-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    padding: 20px;
}

.book-card-kicker {
    color: var(--blue-dark);
    font-size: 10px;
    letter-spacing: 1.1px;
    font-weight: 800;
}

.book-card h3 {
    color: var(--navy);
    font-size: 17px;
    line-height: 1.45;
    margin: 8px 0 7px;
    overflow-wrap: anywhere;
}

.book-folder {
    color: var(--text-light);
    font-size: 12px;
    margin-bottom: 6px;
    overflow-wrap: anywhere;
}

.book-meta {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    color: var(--text-light);
    font-size: 11px;
    margin: 8px 0 18px;
}

/* Read and download actions */

.book-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: auto;
}

.book-view-button,
.book-download-button,
.viewer-download {
    min-height: 42px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    border-radius: 9px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    transition: background .2s ease, border-color .2s ease;
}

.book-view-button {
    background: var(--blue-dark);
    color: #fff;
    border: 1px solid var(--blue-dark);
}

.book-view-button:hover {
    background: #206d98;
}

.book-download-button {
    background: #fff;
    color: var(--navy);
    border: 1px solid var(--border);
}

.book-download-button:hover {
    background: var(--green-light);
    border-color: var(--green);
}

/* Empty and error states */

.books-empty {
    padding: 65px 20px;
    text-align: center;
    border: 1px dashed #bfd8e4;
    border-radius: 16px;
    background: #fff;
}

.books-empty-icon {
    font-size: 35px;
    margin-bottom: 12px;
}

.books-empty h3 {
    color: var(--navy);
    font-size: 21px;
    margin-bottom: 8px;
}

.books-empty p {
    max-width: 500px;
    margin: auto;
    color: var(--text-light);
    font-size: 14px;
}

.books-notice {
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 24px;
    font-size: 14px;
}

.books-notice p {
    margin-top: 6px;
    overflow-wrap: anywhere;
}

.books-notice-error {
    background: #fff5f4;
    border: 1px solid #f0c7c3;
    color: #7b2824;
}

.books-library-note {
    margin-top: 28px;
    color: var(--text-light);
    font-size: 12px;
    line-height: 1.7;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ============================================
   ONLINE DOCUMENT VIEWER
============================================ */

.viewer-main {
    min-height: 65vh;
    padding: 32px 0 70px;
    background: #f2f6f8;
}

.viewer-titlebar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 22px;
    padding-bottom: 22px;
}

.viewer-titlebar h1 {
    color: var(--navy);
    font: 700 clamp(24px, 3vw, 34px)/1.25
        "Playfair Display", serif;
    margin: 7px 0 6px;
    overflow-wrap: anywhere;
}

.viewer-titlebar p {
    color: var(--text-light);
    font-size: 12px;
    letter-spacing: .5px;
}

.viewer-download {
    flex-shrink: 0;
    background: var(--blue-dark);
    color: #fff;
}

.viewer-download:hover {
    background: #206d98;
}

/* PDF viewer */

.pdf-viewer-shell {
    width: min(1180px, 94%);
    margin: 0 auto;
    background: #dfe6ea;
    border: 1px solid #cbd7dd;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.pdf-viewer-frame {
    display: block;
    width: 100%;
    height: min(82vh, 1000px);
    min-height: 560px;
    border: 0;
    background: #fff;
}

.viewer-fallback {
    padding: 13px 18px;
    color: var(--text);
    background: #fff;
    font-size: 13px;
}

.viewer-fallback a,
.word-viewer-fallback a {
    color: var(--blue-dark);
    font-weight: 700;
    text-decoration: underline;
}

/* Word document viewer */

.word-viewer-shell {
    padding: 0 0 10px;
}

.word-viewer-notice {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 16px;
}

.word-viewer-symbol {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 46px;
    height: 50px;
    border-radius: 9px;
    background: #e9f3ff;
    color: #245f9e;
    font-size: 24px;
    font-weight: 800;
}

.word-viewer-notice h2 {
    color: var(--navy);
    font-size: 17px;
    margin-bottom: 4px;
}

.word-viewer-notice p,
.word-viewer-fallback {
    color: var(--text-light);
    font-size: 12px;
    line-height: 1.7;
}

.word-viewer-frame-wrap {
    overflow: hidden;
    border: 1px solid #cbd7dd;
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow-sm);
}

.word-viewer-frame {
    display: block;
    width: 100%;
    height: 78vh;
    min-height: 560px;
    border: 0;
}

.word-viewer-fallback {
    margin-top: 13px;
}

/* Error page */

.viewer-error {
    padding: 80px 0;
}

.viewer-error h1 {
    color: var(--navy);
    font: 700 34px "Playfair Display", serif;
}

.viewer-error p {
    margin: 10px 0 20px;
    color: var(--text-light);
}

/* ============================================
   RESPONSIVE DESIGN
============================================ */

@media (max-width: 900px) {
    .books-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 650px) {
    .books-hero {
        padding: 38px 0 62px;
    }

    .books-hero h1 {
        font-size: 39px;
    }

    .books-hero p {
        font-size: 14px;
    }

    .books-stat {
        min-width: calc(33.333% - 9px);
        flex: 1;
        padding: 11px 12px;
    }

    .books-stat strong {
        font-size: 20px;
    }

    .books-library {
        padding: 46px 0 65px;
    }

    .books-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .book-card-top {
        min-height: 118px;
    }

    .books-toolbar {
        gap: 8px;
    }

    .books-search {
        flex-basis: 100%;
        border-bottom: 1px solid var(--border);
    }

    .books-filter-label {
        flex: 1;
    }

    .books-filter-label select {
        width: 100%;
    }

    .books-search-button {
        padding: 0 15px;
    }

    .books-clear {
        padding: 8px 4px;
    }

    .viewer-titlebar {
        align-items: flex-start;
        flex-direction: column;
    }

    .pdf-viewer-frame,
    .word-viewer-frame {
        min-height: 65vh;
        height: 70vh;
    }

    .word-viewer-notice {
        align-items: flex-start;
    }
}