/* ============================================
   📱 PDF-MOBILE.CSS
   Responsive pour la page lecteur PDF (pdf.html)
   Mobile-first, puis tablette
   ============================================ */

/* ===== MOBILE ≤ 768px ===== */
@media (max-width: 500px) and (pointer: coarse),
       (pointer: coarse) and (max-height: 600px) and (orientation: landscape) {

    /* --- Viewer : hauteur explicite (l'iframe en height:100% a besoin d'un parent à hauteur définie) --- */
    .pdf-viewer-wrap {
        height: 68vh;
        max-height: none;
        min-height: 300px;
    }

    /* --- Corps : référence de positionnement pour le TOC absolu --- */
    .pdf-viewer-body {
        position: relative;
    }

    /* --- TOC : superposition flottante au lieu de réduire la largeur du viewer --- */
    .pdf-toc-panel {
        position: absolute !important;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 10;
        width: min(280px, 80vw) !important;
        max-height: 100% !important;
        transform: translateX(-105%);
        transition: transform 0.3s ease, opacity 0.3s ease;
        opacity: 0;
        pointer-events: none;
    }
    .pdf-toc-panel:not(.hidden) {
        transform: translateX(0);
        opacity: 1;
        pointer-events: auto;
    }
    /* Empêcher que .hidden collapse à width:0 — on utilise transform pour animer */
    .pdf-toc-panel.hidden {
        width: min(280px, 80vw) !important;
        min-width: 0 !important;
        border-right: none;
        opacity: 0 !important;
    }

    /* --- Annuler les règles mobiles de pdf-style.css qui cassent le layout --- */
    /* pdf-style.css @media(max-width:768px) force flex-direction:column + padding:12px sur le wrap */
    .pdf-viewer-header {
        flex-direction: row !important;   /* annule flex-direction:column de pdf-style.css */
        align-items: center !important;   /* annule align-items:stretch */
        overflow-x: auto;
        flex-wrap: nowrap !important;
        padding: 8px 10px;
        gap: 8px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .pdf-viewer-header::-webkit-scrollbar { display: none; }

    .pdf-viewer-left,
    .pdf-viewer-right {
        flex-shrink: 0;
        width: auto !important;           /* annule width:100% de pdf-style.css */
        flex-wrap: nowrap !important;
        gap: 6px;
    }

    /* Le padding sur le wrap était inutile : l'iframe en height:100% perd cette surface */
    .pdf-viewer-wrap {
        padding: 0 !important;
    }

    /* Conserver : TOC ‹btn›, Recherche ‹btn›, Zoom −/°/+ ‹btn›, Plein écran ‹btn›
       Cacher sur mobile : sélecteur de mode (défilement continu par défaut),
       réinitialiser zoom, effacer surlignages, séparateurs */
    #modeSelect,
    #resetZoom,
    #clearHighlightsBtnSolo { display: none !important; }

    .pdf-viewer-input {
        min-width: 0;
        flex: 1;
    }

    .pdf-viewer-btn {
        padding: 6px 10px;
        font-size: 13px;
    }

    .pdf-viewer-btn.pdf-viewer-ghost {
        padding: 4px 8px;
        font-size: 14px;
    }

    /* Cacher le séparateur vertical sur mobile */
    .pdf-viewer-separator {
        display: none;
    }

    /* Groupe de contrôles zoom : compacter */
    .pdf-viewer-controls-group {
        padding: 2px;
        gap: 2px;
    }

    .pdf-viewer-zoom-label {
        min-width: 40px;
        font-size: 12px;
    }

    .pdf-viewer-status,
    .pdf-viewer-note {
        font-size: 12px;
    }

    /* Cacher le label textuel du bouton comparer sur mobile */
    .compare-btn-label {
        display: none;
    }

    /* --- Mode comparaison : empiler verticalement --- */
    .hero-left.compare-active {
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        gap: 8px;
        padding: 4px;
    }

    .hero-left.compare-active .pdf-viewer-container {
        width: 100% !important;
        flex: 0 0 auto;
    }

    .hero-left.compare-active .pdf-viewer-wrap {
        min-height: 40vh;
    }

    /* Shared toolbar compacte en mobile */
    .pdf-shared-toolbar-controls {
        flex-direction: column;
        gap: 6px;
        padding: 8px;
    }

    .pdf-shared-toolbar-zone {
        width: 100%;
        justify-content: center;
    }

    /* --- Modal comparaison --- */
    .pdf-compare-modal-content {
        width: 95vw !important;
        max-width: none;
        margin: auto 2.5vw;
        max-height: 80vh;
    }

    /* --- Recherche intégrée --- */
    .pdf-search-input {
        min-width: 100px !important;
        max-width: 160px;
        font-size: 13px;
    }

    /* --- Page input --- */
    .pdf-viewer-page-input {
        width: 44px;
        min-width: 44px;
        font-size: 13px;
    }

    /* Sélecteur de mode (défilement/paginé) */
    .pdf-viewer-select {
        font-size: 12px;
        padding: 6px 8px;
    }
}

/* ===== PETIT MOBILE ≤ 480px ===== */
@media (max-width: 480px) {

    .pdf-viewer-wrap {
        min-height: 45vh;
    }

    .pdf-viewer-header {
        padding: 6px 8px;
        gap: 4px;
    }

    .pdf-viewer-btn {
        padding: 5px 8px;
        font-size: 12px;
    }

    /* TOC encore plus étroit */
    .pdf-toc-panel {
        width: 240px;
    }

    .pdf-toc-item {
        font-size: 12px;
        padding: 6px 0;
    }

    .pdf-toc-item.level-2 {
        font-size: 11px;
    }

    .pdf-toc-item.level-3 {
        font-size: 10px;
    }

    /* Modal comparaison plein écran */
    .pdf-compare-modal-content {
        width: 100vw !important;
        margin: 0;
        border-radius: 12px 12px 0 0;
        max-height: 85vh;
    }

    .pdf-compare-book-item {
        padding: 10px;
        font-size: 13px;
    }
}

/* ===== TABLETTE 769px – 1024px ===== */
@media (min-width: 769px) and (max-width: 1024px) {

    .pdf-viewer-wrap {
        height: 700px;
        max-height: 700px;
    }

    .pdf-toc-panel {
        max-height: 700px;
    }

    /* Comparaison : garder côte à côte mais réduire la hauteur */
    .hero-left.compare-active .pdf-viewer-wrap {
        height: 500px;
        max-height: 500px;
    }
}

/* ===== ORIENTATION PAYSAGE MOBILE ===== */
@media (pointer: coarse) and (max-height: 600px) and (orientation: landscape) {

    .pdf-viewer-wrap {
        min-height: 60vh;
    }

    /* En paysage : comparaison côte à côte possible */
    .hero-left.compare-active {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
    }

    .hero-left.compare-active .pdf-viewer-wrap {
        min-height: 50vh;
    }
}

/* ===== PRÉFÉRENCE : réduire les animations ===== */
@media (prefers-reduced-motion: reduce) {

    .pdf-toc-children,
    .pdf-toc-panel,
    .pdf-viewer-btn {
        transition: none !important;
    }
}
