/* ========================================
   PDF VIEWER
======================================== */

.custom-pdf-viewer {
    width: 100%;
    max-width: 1200px;

    margin: 30px auto;

    background: #f5f5f5;

    border: 1px solid #e2e2e2;
    border-radius: 14px;

    overflow: hidden;

    box-shadow:
        0 8px 30px rgba(0, 0, 0, 0.08);
}


/* ========================================
   TOOLBAR
======================================== */

.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;

    gap: 15px;

    padding: 12px 18px;

    background: #ffffff;

    border-bottom: 1px solid #e5e5e5;

    position: relative;
    z-index: 20;
}


/* ========================================
   TITLE
======================================== */

.pdf-title {
    font-size: 15px;
    font-weight: 600;

    color: #222222;

    white-space: nowrap;

    overflow: hidden;
    text-overflow: ellipsis;
}


/* ========================================
   CONTROLS
======================================== */

.pdf-controls {
    display: flex;

    align-items: center;

    gap: 8px;

    flex-shrink: 0;
}


/* ========================================
   BUTTONS
======================================== */

.pdf-btn {
    height: 38px;
    min-width: 38px;

    padding: 0 10px;

    display: inline-flex;

    align-items: center;
    justify-content: center;

    border: 1px solid #dddddd;

    border-radius: 7px;

    background: #ffffff;

    color: #333333;

    font-family: inherit;

    font-size: 14px;
    font-weight: 500;

    line-height: 1;

    cursor: pointer;

    transition:
        background 0.2s ease,
        border-color 0.2s ease,
        transform 0.2s ease;
}


.pdf-btn:hover {
    background: #f3f3f3;

    border-color: #cccccc;
}


.pdf-btn:active {
    transform: scale(0.96);
}


/* ========================================
   ZOOM DISPLAY
======================================== */

.pdf-zoom-value {
    min-width: 50px;

    text-align: center;

    font-size: 13px;
    font-weight: 500;

    color: #555555;
}


/* ========================================
   DOCUMENT VIEWER
======================================== */

.pdf-document-wrapper {
    position: relative;

    width: 100%;

    /*
     * Desktop viewer height.
     */
    height: min(82vh, 900px);

    min-height: 550px;

    /*
     * CRITICAL:
     *
     * Pages go horizontally.
     */
    display: flex;

    flex-direction: row;

    align-items: stretch;

    justify-content: flex-start;

    /*
     * No padding here.
     *
     * Each individual slide receives
     * its own padding instead.
     */
    padding: 0;

    margin: 0;

    gap: 0;

    /*
     * Horizontal only.
     */
    overflow-x: auto;

    overflow-y: hidden;

    /*
     * Force page-by-page snapping.
     */
    scroll-snap-type: x mandatory;

    scroll-behavior: smooth;

    /*
     * Better touch/swipe behaviour.
     */
    -webkit-overflow-scrolling: touch;

    touch-action: pan-x;

    /*
     * Prevent browser overscroll from
     * moving the whole page horizontally.
     */
    overscroll-behavior-x: contain;

    overscroll-behavior-y: none;

    /*
     * Prevent Chrome scroll anchoring.
     */
    overflow-anchor: none;

    /*
     * Viewer background.
     */
    background: #eeeeee;

    box-sizing: border-box;

    /*
     * Don't allow old text-align rules
     * to influence canvases.
     */
    text-align: initial;

    /*
     * Firefox scrollbar.
     */
    scrollbar-width: thin;
}


/* ========================================
   EACH HORIZONTAL PDF SLIDE
======================================== */

/*
 * Your new JavaScript creates this wrapper
 * around every rendered canvas.
 *
 * Each slide occupies exactly one full
 * viewer width.
 */

.pdf-page-slide {
    position: relative;

    /*
     * IMPORTANT:
     *
     * Every PDF page consumes exactly
     * 100% of the viewer width.
     */
    flex: 0 0 100%;

    width: 100%;

    min-width: 100%;

    max-width: 100%;

    height: 100%;

    /*
     * Center the PDF page horizontally
     * and vertically.
     */
    display: flex;

    align-items: center;

    justify-content: center;

    padding: 24px;

    box-sizing: border-box;

    /*
     * Hard page snap.
     */
    scroll-snap-align: start;

    scroll-snap-stop: always;

    /*
     * Prevent canvases from overflowing
     * into neighboring slides.
     */
    overflow: hidden;

    overflow-anchor: none;
}


/* ========================================
   PDF CANVAS
======================================== */

.pdf-page {
    /*
     * DO NOT use:
     *
     * display:block;
     * margin-bottom:22px;
     *
     * Those were for vertical rendering.
     */

    display: block;

    flex: 0 0 auto;

    margin: 0;

    padding: 0;

    /*
     * JS calculates the exact width/height
     * needed to fit within the viewport.
     */
    max-width: none;

    max-height: none;

    background: #ffffff;

    box-sizing: border-box;

    overflow-anchor: none;

    box-shadow:
        0 2px 6px rgba(0, 0, 0, 0.08),
        0 8px 20px rgba(0, 0, 0, 0.10);
}


/*
 * IMPORTANT:
 *
 * Remove the old:
 *
 * .pdf-page:last-child {
 *     margin-bottom: 0;
 * }
 *
 * It is no longer required.
 */


/* ========================================
   LOADING
======================================== */

.pdf-loading {
    /*
     * Loading message takes the complete
     * viewer width.
     */
    flex: 0 0 100%;

    width: 100%;

    min-width: 100%;

    height: 100%;

    min-height: 300px;

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 40px 20px;

    box-sizing: border-box;

    text-align: center;

    color: #666666;

    font-size: 15px;
}


/* ========================================
   ERROR
======================================== */

.pdf-error {
    flex: 0 0 100%;

    width: 100%;

    min-width: 100%;

    height: 100%;

    min-height: 300px;

    display: flex;

    align-items: center;

    justify-content: center;

    padding: 40px 20px;

    box-sizing: border-box;

    text-align: center;

    color: #666666;

    font-size: 15px;
}


/* ========================================
   TABLET
======================================== */

@media (max-width: 991.98px) {

    .custom-pdf-viewer {
        max-width: 100%;
    }


    .pdf-document-wrapper {
        height: 75vh;

        min-height: 470px;
    }


    .pdf-page-slide {
        padding: 18px;
    }

}


/* ========================================
   MOBILE
======================================== */

@media (max-width: 768px) {

    .custom-pdf-viewer {
        width: 100%;

        margin: 15px auto;

        border-radius: 8px;
    }


    .pdf-toolbar {
        padding: 10px 12px;

        gap: 8px;
    }


    .pdf-title {
        font-size: 13px;
    }


    .pdf-controls {
        gap: 5px;
    }


    .pdf-document-wrapper {
        /*
         * Enough height for portrait PDF
         * while remaining responsive.
         */
        height: 72vh;

        min-height: 420px;

        /*
         * Hide visible horizontal scrollbar
         * on mobile while swipe still works.
         */
        scrollbar-width: none;
    }


    .pdf-document-wrapper::-webkit-scrollbar {
        display: none;
    }


    .pdf-page-slide {
        padding: 12px;
    }


    .pdf-btn {
        width: 34px;

        min-width: 34px;

        height: 34px;

        padding: 0 7px;

        font-size: 13px;
    }


    .pdf-zoom-value {
        min-width: 43px;

        font-size: 12px;
    }

}


/* ========================================
   SMALL MOBILE
======================================== */

@media (max-width: 480px) {

    .custom-pdf-viewer {
        margin: 10px auto;

        border-radius: 6px;
    }


    .pdf-title {
        display: none;
    }


    .pdf-toolbar {
        justify-content: center;

        padding: 9px 10px;
    }


    .pdf-controls {
        justify-content: center;

        width: 100%;
    }


    .pdf-document-wrapper {
        height: 68vh;

        min-height: 380px;
    }


    .pdf-page-slide {
        padding: 8px;
    }

}


/* ========================================
   VERY SMALL WIDTHS
======================================== */

@media (max-width: 360px) {

    .pdf-document-wrapper {
        min-height: 350px;
    }


    .pdf-page-slide {
        padding: 6px;
    }


    .pdf-btn {
        width: 32px;

        min-width: 32px;

        height: 32px;
    }

}


/* ========================================
   SHORT LANDSCAPE SCREENS
======================================== */

@media (max-height: 650px) {

    .pdf-document-wrapper {
        height: 72vh;

        min-height: 320px;
    }


    .pdf-page-slide {
        padding-top: 8px;

        padding-bottom: 8px;
    }

}