/* =========================================================
   PDF MODAL — Scherzo Editions style
   ========================================================= */

:root {
    --pdfm-red: #9B090D;
    --pdfm-red-hover: #8a0019;
    --pdfm-cream: #F7F3EB;
    --pdfm-text: #202020;
    --pdfm-border: rgba(0, 0, 0, 0.08);
    --pdfm-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
}

/* Overlay */
.pdf-modal {
    position: fixed;
    inset: 0;
    background: rgba(20, 20, 20, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 99999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 32px;
    opacity: 0;
    transition: opacity 0.25s ease;
}
.pdf-modal.is-open {
    display: flex;
    opacity: 1;
}

/* Dialog */
.pdf-modal__dialog {
    background: #ffffff;
    width: 100%;
    max-width: 1120px;
    height: 100%;
    max-height: 92vh;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--pdfm-shadow);
    transform: translateY(10px);
    transition: transform 0.3s ease;
}
.pdf-modal.is-open .pdf-modal__dialog {
    transform: translateY(0);
}

/* Toolbar */
.pdf-modal__toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    background: var(--pdfm-cream);
    color: var(--pdfm-text);
    border-bottom: 1px solid var(--pdfm-border);
    flex-shrink: 0;
}

.pdf-modal__title {
    font-family: inherit;
    font-weight: 500;
    font-size: 15px;
    letter-spacing: 0.01em;
    color: var(--pdfm-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.pdf-modal__controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pdf-modal__group {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
    border-right: 1px solid var(--pdfm-border);
}
.pdf-modal__group:last-child {
    border-right: none;
    padding-right: 0;
}

/* Buttons */
.pdf-modal__btn {
    background: transparent !important;
    color: var(--pdfm-text) !important;
    border: none !important;
    padding: 8px 12px !important;
    font-size: 14px !important;
    font-weight: 500;
    line-height: 1;
    transition: background 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    min-width: 36px;
    height: 36px;
    box-sizing: border-box;
}
.pdf-modal__btn:hover:not(:disabled):not([aria-disabled="true"]) {
    background: rgba(0, 0, 0, 0.06) !important;
}
.pdf-modal__btn:disabled,
.pdf-modal__btn[aria-disabled="true"] {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* All SVG icons — force size & display */
.pdf-modal .pdf-modal__btn svg,
.pdf-modal__btn svg {
    width: 16px !important;
    height: 16px !important;
    min-width: 16px !important;
    min-height: 16px !important;
    max-width: 16px !important;
    max-height: 16px !important;
    display: block !important;
    flex-shrink: 0 !important;
    fill: none !important;
    overflow: visible !important;
}

/* Primary (close) button — red */
.pdf-modal__close {
    background: var(--pdfm-red) !important;
    color: #ffffff !important;
    margin-left: 8px;
    width: 36px;
    position: relative;
}
.pdf-modal__btn.pdf-modal__close:hover:not(:disabled) {
    background: var(--pdfm-red-hover) !important;
}

/* CSS-drawn X — bullet-proof across themes */
.pdf-modal__close::before,
.pdf-modal__close::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 2px;
    background: #ffffff;
    border-radius: 1px;
    pointer-events: none;
}
.pdf-modal__close::before { transform: translate(-50%, -50%) rotate(45deg); }
.pdf-modal__close::after  { transform: translate(-50%, -50%) rotate(-45deg); }
.pdf-modal__close svg { display: none !important; }

/* Page indicator */
.pdf-modal__pageinfo {
    font-variant-numeric: tabular-nums;
    min-width: 64px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    color: var(--pdfm-text);
    padding: 0 4px;
}

/* Viewer area — must allow horizontal scroll when canvas is zoomed beyond width */
.pdf-modal__viewer {
    flex: 1;
    overflow: auto;
    background: #e8e6e1;
    padding: 32px;
    position: relative;
    /* Use block layout so a wider canvas overflows and scrolls horizontally */
    display: block;
    text-align: center;
}

/* Wrapper centers the canvas. When the canvas is wider than the viewer,
   inline-block + min-width:100% keeps the centering AND lets it overflow. */
.pdf-modal__canvas-wrap {
    display: inline-block;
    min-width: 100%;
    box-sizing: border-box;
    text-align: center;
}

.pdf-modal__canvas {
    background: #fff;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    display: inline-block;
    /* IMPORTANT: no max-width / no width:auto — width is set in JS via style.width */
    vertical-align: top;
}

/* Loading */
.pdf-modal__loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--pdfm-text);
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.02em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}
.pdf-modal__spinner {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--pdfm-red);
    border-radius: 50%;
    animation: pdfm-spin 0.8s linear infinite;
}
@keyframes pdfm-spin { to { transform: rotate(360deg); } }

body.pdf-modal-open { overflow: hidden; }

/* ---------- Tablet ---------- */
@media (max-width: 900px) {
    .pdf-modal { padding: 0; }
    .pdf-modal__dialog {
        max-height: 100vh;
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }
}

/* ---------- Mobile ---------- */
@media (max-width: 600px) {
    .pdf-modal__toolbar {
        padding: 10px 12px;
        gap: 8px;
        flex-wrap: nowrap;
    }
    .pdf-modal__title { display: none; }
    .pdf-modal__controls {
        flex: 1;
        justify-content: space-between;
        width: 100%;
    }
    .pdf-modal__btn {
        padding: 6px 8px;
        min-width: 34px;
        height: 34px;
        font-size: 13px;
    }
    .pdf-modal__group { padding: 0 4px; gap: 0; }
    .pdf-modal__group:first-child { padding-left: 0; }
    .pdf-modal__group:last-child { padding-right: 0; }
    .pdf-modal__close { margin-left: 4px; }
    .pdf-modal__viewer { padding: 8px; }
    .pdf-modal__pageinfo {
        min-width: 42px;
        font-size: 11px;
        padding: 0 2px;
    }
}

@media (max-width: 360px) {
    .pdf-modal__pageinfo { display: none; }
}