/* --- BASE VIEWER --- */
.pdf-viewer-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    margin: 2rem auto;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
}

.pdf-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.75rem 1.5rem;
    background: #0f172a;
    color: #f8fafc;
    gap: 1rem;
}

.pdf-pagination, .pdf-zoom {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

/* --- CURSEUR ET BOUTONS --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    background: #475569;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
}

.btn:hover { background: #2563eb; }

#fit-width {
    font-weight: bold;
    font-size: 1.1rem;
    padding: 0.2rem 0.6rem;
}

#fullscreen-btn {
    font-size: 1.2rem;
    padding: 0.2rem 0.6rem;
}

/* --- CANEVAS ET LOADER --- */
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 75vh;
    min-height: 400px;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #cbd5e1;
    padding: 20px;
    box-sizing: border-box;
    touch-action: pan-x pan-y; 
}

.pdf-canvas {
    display: block;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    background: #fff;
    transition: transform 0.05s linear; 
}

.pdf-loader {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(203, 213, 225, 0.7);
    display: flex; justify-content: center; align-items: center; z-index: 10;
}

.spinner {
    width: 40px; height: 40px; border: 4px solid #94a3b8;
    border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- MODE PLEIN ÉCRAN --- */
.pdf-viewer-container.is-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    margin: 0;
    border-radius: 0;
    border: none;
    z-index: 999999;
}

.pdf-viewer-container.is-fullscreen .canvas-wrapper {
    height: calc(100vh - 64px);
    padding: 10px;
}

/* --- MEDIA QUERIES --- */
@media (max-width: 600px) {
    .pdf-toolbar { flex-direction: column; }
    .pdf-zoom input[type="range"] { width: 80px; }
    
    /* Si on n'est pas en plein écran, on adapte la hauteur */
    .pdf-viewer-container:not(.is-fullscreen) .canvas-wrapper { 
        height: 60vh; 
        padding: 10px; 
    }
}


/* --- BOUTONS OVERLAY DE NAVIGATION (SWIPE FALLBACK) --- */
.nav-overlay {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 15%; /* Prend 15% de l'écran de chaque côté */
    min-width: 50px;
    background: transparent;
    color: rgba(0, 0, 0, 0.15); /* Flèche très discrète */
    border: none;
    font-size: 4rem;
    cursor: pointer;
    z-index: 20;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Désactive la sélection de texte au double tap */
    user-select: none; 
    -webkit-tap-highlight-color: transparent;
}

.nav-overlay:hover, 
.nav-overlay:active {
    color: rgba(0, 0, 0, 0.7);
    background: rgba(0, 0, 0, 0.05);
}

.nav-overlay.left { 
    left: 0; 
}

.nav-overlay.right { 
    right: 0; 
}

@media (max-width: 600px) {
    .nav-overlay { width: 20%; font-size: 3rem; }
}

/* --- BASE VIEWER --- */
.pdf-viewer-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    margin: 2rem auto;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    font-family: system-ui, -apple-system, sans-serif;
}

.pdf-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    padding: 0.75rem 1.5rem;
    background: #0f172a;
    color: #f8fafc;
    gap: 1rem;
}

.pdf-pagination, .pdf-zoom {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

/* --- CURSEUR ET BOUTONS --- */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    background: #475569;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: #3b82f6;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }

.btn {
    background: #3b82f6;
    color: white;
    border: none;
    padding: 0.4rem 0.8rem;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
}
.btn:hover { background: #2563eb; }
#fit-width { font-weight: bold; font-size: 1.1rem; padding: 0.2rem 0.6rem; }
#fullscreen-btn { font-size: 1.2rem; padding: 0.2rem 0.6rem; }

/* --- CANEVAS ET CHARGEMENT --- */
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 75vh;
    min-height: 400px;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #cbd5e1;
    padding: 20px;
    box-sizing: border-box;
    touch-action: pan-x pan-y; 
}

.pdf-canvas {
    display: block;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    background: #fff;
    transition: transform 0.05s linear; 
}

/* --- LE NOUVEAU SMART LOADER --- */
.pdf-loader {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(203, 213, 225, 0.9);
    display: flex; justify-content: center; align-items: center; z-index: 10;
}

.loader-content {
    display: flex; flex-direction: column; align-items: center; gap: 15px;
    background: #fff; padding: 25px 40px; border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.spinner {
    width: 40px; height: 40px; border: 4px solid #e2e8f0;
    border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s linear infinite;
}

.progress-container {
    width: 200px; height: 8px; background: #e2e8f0;
    border-radius: 4px; overflow: hidden;
}

.progress-bar {
    height: 100%; width: 0%; background: #3b82f6;
    transition: width 0.1s linear;
}

.progress-bar.indeterminate {
    width: 100%; background: linear-gradient(90deg, #3b82f6 0%, #93c5fd 50%, #3b82f6 100%);
    background-size: 200% 100%; animation: pulse-bg 1.5s linear infinite;
}

.progress-text { font-size: 0.9rem; font-weight: 600; color: #475569; font-family: monospace; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-bg { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* --- BOUTONS OVERLAY ET FULLSCREEN (INCHANGÉS) --- */
.nav-overlay {
    position: absolute; top: 0; bottom: 0; width: 15%; min-width: 50px;
    background: transparent; color: rgba(0, 0, 0, 0.15); border: none;
    font-size: 4rem; cursor: pointer; z-index: 20; transition: all 0.2s ease;
    display: flex; align-items: center; justify-content: center;
    user-select: none; -webkit-tap-highlight-color: transparent;
}
.nav-overlay:hover, .nav-overlay:active { color: rgba(0, 0, 0, 0.7); background: rgba(0, 0, 0, 0.05); }
.nav-overlay.left { left: 0; }
.nav-overlay.right { right: 0; }

.pdf-viewer-container.is-fullscreen {
    position: fixed; top: 0; left: 0; width: 100vw; max-width: 100vw;
    height: 100vh; margin: 0; border-radius: 0; border: none; z-index: 999999;
}
.pdf-viewer-container.is-fullscreen .canvas-wrapper { height: calc(100vh - 64px); padding: 10px; }

@media (max-width: 600px) {
    .pdf-toolbar { flex-direction: column; }
    .pdf-zoom input[type="range"] { width: 80px; }
    .nav-overlay { width: 20%; font-size: 3rem; }
    .pdf-viewer-container:not(.is-fullscreen) .canvas-wrapper { height: 60vh; padding: 10px; }
}