/* ==========================================================================
   GRAD PDF Viewer — liseuse PDF classique (PDF.js, texte natif sélectionnable)
   ========================================================================== */

#grad-pdf-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
#grad-pdf-modal.is-open {
    opacity: 1;
    visibility: visible;
}
#grad-pdf-modal.is-closing {
    opacity: 0;
    visibility: hidden;
}

#grad-pdf-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.90);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: pointer;
}

#grad-pdf-container {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: row;
    pointer-events: none;
}

#grad-pdf-thumbs,
#grad-pdf-topbar,
#grad-pdf-viewer,
#grad-pdf-navbtns {
    pointer-events: all;
}

/* ── Sidebar de vignettes (façon Adobe Acrobat) ── */
#grad-pdf-thumbs {
    width: 148px;
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding: 24px 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    background: rgba(255, 255, 255, 0.03);
    border-right: 1px solid rgba(255, 255, 255, 0.08);

    /* Scrollbar sombre minimaliste (Firefox) */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
}

/* Scrollbar sombre minimaliste (Chrome / Safari / Edge) */
#grad-pdf-thumbs::-webkit-scrollbar {
    width: 6px;
}
#grad-pdf-thumbs::-webkit-scrollbar-track {
    background: transparent;
}
#grad-pdf-thumbs::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.18);
    border-radius: 3px;
}
#grad-pdf-thumbs::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.32);
}

.grad-pdf-thumb {
    position: relative;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    opacity: 0.4;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s ease, box-shadow 0.2s ease;
}
.grad-pdf-thumb:hover {
    opacity: 0.7;
}
.grad-pdf-thumb.is-active {
    opacity: 1;
    box-shadow: 0 0 0 2px #fff, 0 4px 16px rgba(0, 0, 0, 0.5);
}
.grad-pdf-thumb canvas {
    display: block;
    width: 100%;
    height: 100%;
}
.grad-pdf-thumb-num {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(0, 0, 0, 0.65);
    color: rgba(255, 255, 255, 0.85);
    font-family: 'IvyStyleSans', sans-serif;
    font-size: 10px;
    font-weight: 300;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 3px;
    z-index: 1;
}

/* ── Colonne principale ── */
#grad-pdf-main {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ── */
#grad-pdf-topbar {
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 0 20px;
    box-sizing: border-box;
    flex-shrink: 0;
}

#grad-pdf-page-info {
    color: rgba(255, 255, 255, 0.55);
    font-family: 'IvyStyleSans', sans-serif;
    font-size: 12px;
    font-weight: 300;
    letter-spacing: 0.06em;
    margin-right: auto;
    user-select: none;
}

#grad-pdf-zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}
#grad-pdf-zoom-reset {
    margin-right: 6px;
}

#grad-pdf-zoom-reset,
#grad-pdf-zoom-out,
#grad-pdf-zoom-in,
#grad-pdf-prev,
#grad-pdf-next {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.75);
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .2s, background .2s, color .2s;
    padding: 0;
    flex-shrink: 0;
}
#grad-pdf-zoom-reset:hover,
#grad-pdf-zoom-out:hover,
#grad-pdf-zoom-in:hover,
#grad-pdf-prev:hover,
#grad-pdf-next:hover {
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

#grad-pdf-zoom-level {
    color: rgba(255, 255, 255, 0.55);
    font-family: 'IvyStyleSans', sans-serif;
    font-size: 12px;
    font-weight: 300;
    letter-spacing: 0.06em;
    min-width: 40px;
    text-align: center;
    user-select: none;
}

#grad-pdf-download {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-family: 'IvyStyleSans', sans-serif;
    font-size: 12px;
    font-weight: 300;
    letter-spacing: 0.06em;
    padding: 8px 14px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    transition: color .2s, border-color .2s, background .2s;
}
#grad-pdf-download:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.06);
}

#grad-pdf-close {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color .2s, border-color .2s, background .2s;
    padding: 0;
}
#grad-pdf-close:hover {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Loader ── */
#grad-pdf-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: rgba(255, 255, 255, 0.65);
    font-family: 'IvyStyleSans', sans-serif;
    font-size: 13px;
    font-weight: 300;
    flex: 1;
    pointer-events: none;
}
.grad-pdf-spinner {
    width: 28px;
    height: 28px;
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-top-color: rgba(255, 255, 255, 0.75);
    border-radius: 50%;
    animation: grad-pdf-spin 0.7s linear infinite;
}
@keyframes grad-pdf-spin {
    to { transform: rotate(360deg); }
}
.grad-pdf-error {
    color: #ff6b6b;
    text-align: center;
    font-size: 13px;
    padding: 0 24px;
}

/* ── Viewer (scroll vertical continu) ── */
#grad-pdf-viewer {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto; /* nécessaire quand une page zoomée dépasse la largeur */
    display: none; /* affiché en JS une fois le chargement terminé */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    cursor: grab;
}
#grad-pdf-viewer.is-grabbing {
    cursor: grabbing;
}

#grad-pdf-pages {
    padding: 24px 16px 40px;
    box-sizing: border-box;
    min-height: 100%;
}

.grad-pdf-page {
    position: relative;
    background: #fff;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
    margin: 0 auto 24px;
    cursor: zoom-in;
}
#grad-pdf-pages.is-zoomed .grad-pdf-page {
    cursor: zoom-out;
}

.grad-pdf-page canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
}

/* ── Couche de texte native PDF.js (sélectionnable, invisible) ── */
.textLayer {
    position: absolute;
    top: 0;
    left: 0;
    text-align: initial;
    overflow: hidden;
    line-height: 1;
    -webkit-text-size-adjust: none;
    text-size-adjust: none;
    forced-color-adjust: none;
    transform-origin: 0 0;
    z-index: 2;
}
.textLayer span,
.textLayer br {
    color: transparent;
    position: absolute;
    white-space: pre;
    cursor: text;
    transform-origin: 0% 0%;
}
.textLayer ::selection {
    background: rgba(60, 140, 255, 0.35);
}

/* ── Boutons de navigation flottants (sur la colonne principale uniquement) ── */
#grad-pdf-navbtns {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 16px;
    transform: translateY(-50%);
    pointer-events: none;
}
#grad-pdf-navbtns button {
    pointer-events: all;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .2s, background .2s, color .2s;
    padding: 0;
}
#grad-pdf-navbtns button:hover {
    border-color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
}

/* ── Responsive ── */
@media (max-width: 768px) {
    #grad-pdf-thumbs { display: none; } /* place limitée : masqué sur mobile */
    #grad-pdf-topbar { padding: 0 12px; gap: 8px; }
    #grad-pdf-page-info { display: none; }
    #grad-pdf-zoom-out, #grad-pdf-zoom-in { width: 30px; height: 30px; }
    #grad-pdf-navbtns { padding: 0 8px; }
    #grad-pdf-navbtns button { width: 38px; height: 38px; }
    #grad-pdf-pages { padding: 16px 8px 32px; }
    .grad-pdf-page { margin-bottom: 16px; }
}