/**
 * Améliorations pour la lecture sur mobile
 * AnarcosyndicalismeBOOK - Mobile Reading Experience
 */

/* Variables pour la lecture mobile */
:root {
    --mobile-padding: 15px;
    --mobile-font-size: 16px;
    --mobile-line-height: 1.6;
    --mobile-max-width: 100%;
    --reading-bg: #fafafa;
    --reading-text: #2c3e50;
    --reading-accent: #dc3545;
    --mobile-shadow: 0 2px 8px rgba(0,0,0,0.1);
    --mobile-border-radius: 12px;
    --touch-target-size: 44px;
}



/* Barre d'outils de lecture flottante */
.mobile-reading-toolbar {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: white;
    border-radius: 25px;
    box-shadow: var(--mobile-shadow);
    padding: 8px;
    display: flex;
    gap: 8px;
    z-index: 1000;
    transition: all 0.3s ease;
}

.mobile-reading-toolbar.hidden {
    transform: translateY(100px);
    opacity: 0;
}

.mobile-reading-toolbar .btn {
    width: var(--touch-target-size);
    height: var(--touch-target-size);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: #f8f9fa;
    color: #666;
    transition: all 0.2s ease;
}

.mobile-reading-toolbar .btn:hover,
.mobile-reading-toolbar .btn.active {
    background: var(--reading-accent);
    color: white;
    transform: scale(1.1);
}

/* Améliorations générales pour mobile */
@media (max-width: 768px) {
    
    /* Container principal plus adapté */
    .container-fluid {
        padding-left: var(--mobile-padding);
        padding-right: var(--mobile-padding);
    }
    
    /* Article de lecture optimisé */
    article {
        padding: var(--mobile-padding) !important;
        margin-bottom: 20px;
        border-radius: var(--mobile-border-radius) !important;
        box-shadow: var(--mobile-shadow);
    }
    
    /* Titre principal plus lisible */
    .display-6 {
        font-size: 1.5rem !important;
        line-height: 1.3 !important;
        margin-bottom: 1rem !important;
    }
    
    /* Sous-titre adapté */
    .lead {
        font-size: 1rem !important;
        line-height: 1.4 !important;
    }
    
    /* En-tête auteur plus compact */
    header .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 10px;
    }
    
    header .d-flex > div {
        width: 100%;
    }
    
    /* Photo auteur plus petite sur mobile */
    header img,
    header .rounded-circle {
        width: 40px !important;
        height: 40px !important;
        margin-right: 10px !important;
    }
    
    /* Badges catégories plus lisibles */
    .badge {
        font-size: 0.75rem !important;
        padding: 0.4em 0.6em !important;
        margin-bottom: 5px;
        display: inline-block;
    }
    
    /* Boutons d'action optimisés */
    .d-flex.flex-wrap.gap-2 {
        flex-direction: row !important;
        gap: 8px !important;
        flex-wrap: wrap !important;
    }
    
    .btn-sm {
        padding: 10px 16px !important;
        font-size: 0.875rem !important;
        min-height: var(--touch-target-size);
        text-align: center;
        border-radius: 8px !important;
        flex: 1 1 auto;
        min-width: 120px;
    }
    
    /* Formulaire favori en ligne */
    form.d-inline {
        flex: 1 1 auto;
    }
    
    form.d-inline .btn {
        width: 100%;
    }
    
    /* Partage social adapté */
    .share-container {
        width: 100%;
    }
    
    .share-icons {
        justify-content: center !important;
        margin-top: 10px;
    }
    
    .share-icon {
        margin: 0 8px !important;
    }
}

/* Améliorations pour très petits écrans */
@media (max-width: 480px) {
    
    /* Padding encore plus réduit */
    :root {
        --mobile-padding: 10px;
    }
    
    /* Titre encore plus compact */
    .display-6 {
        font-size: 1.3rem !important;
    }
    
    /* Boutons plus grands pour le touch */
    .btn-sm {
        padding: 12px 16px !important;
        font-size: 0.9rem !important;
    }
    
    /* Navigation breadcrumb cachée sur très petit écran */
    .breadcrumb {
        display: none;
    }
}

/* Améliorations pour le contenu de lecture */
@media (max-width: 768px) {
    
    /* Contenu principal plus lisible */
    .col-lg-9 {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Sidebar cachée sur mobile, ou en bas */
    .col-lg-3 {
        margin-top: 20px;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Cards de la sidebar plus compactes */
    .col-lg-3 .card {
        margin-bottom: 15px;
        padding: 15px;
    }
    
    .col-lg-3 .card-body {
        padding: 15px !important;
    }
    
    /* Recommandations plus compactes */
    .col-lg-3 .list-group-item {
        padding: 10px 15px !important;
        font-size: 0.9rem;
    }
    
    /* Images dans les recommandations plus petites */
    .col-lg-3 img {
        max-width: 40px !important;
        max-height: 40px !important;
    }
}

/* Mode lecture simplifié (sans bouton) */
@media (max-width: 768px) {
    
    /* Amélioration automatique de la lecture */
    body {
        background: var(--reading-bg);
    }
    
    article {
        background: white !important;
        font-size: var(--mobile-font-size) !important;
        line-height: var(--mobile-line-height) !important;
        color: var(--reading-text) !important;
    }
    
    /* Sidebar automatiquement en bas sur mobile */
    .col-lg-3 {
        order: 2;
    }
    
    .col-lg-9 {
        order: 1;
        width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
    }
}

/* Améliorations pour les liens et interactions */
@media (max-width: 768px) {
    
    /* Liens plus faciles à toucher */
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        padding: 2px 4px;
    }
    
    /* Boutons avec meilleure zone de touch */
    .btn {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Amélioration des formulaires */
    input, select, textarea {
        font-size: 16px !important; /* Évite le zoom sur iOS */
        padding: 12px !important;
    }
}

/* Animation pour le mode lecture */
@keyframes fadeInReading {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reading-mode article {
    animation: fadeInReading 0.3s ease-out;
}

/* Amélioration de la typographie mobile */
@media (max-width: 768px) {
    
    /* Texte principal plus lisible */
    p {
        font-size: 1rem !important;
        line-height: 1.6 !important;
        margin-bottom: 1rem !important;
    }
    
    /* Listes plus espacées */
    ul, ol {
        padding-left: 20px;
        margin-bottom: 1rem;
    }
    
    li {
        margin-bottom: 0.5rem;
        line-height: 1.5;
    }
    
    /* Citations plus visibles */
    blockquote {
        font-size: 1.1rem !important;
        line-height: 1.5 !important;
        padding: 15px !important;
        margin: 20px 0 !important;
        border-left: 4px solid var(--bs-primary);
        background: #f8f9fa;
    }
}

/* Scroll smooth pour une meilleure navigation */
html {
    scroll-behavior: smooth;
}

/* Amélioration des images dans le contenu */
@media (max-width: 768px) {
    
    img {
        max-width: 100% !important;
        height: auto !important;
        border-radius: 8px;
        margin: 10px 0;
    }
    
    /* Images avec légende */
    figure {
        margin: 20px 0;
        text-align: center;
    }
    
    figcaption {
        font-size: 0.9rem;
        color: #666;
        margin-top: 8px;
        font-style: italic;
    }
}

/* Indicateur de progression de lecture */
.reading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 0%;
    height: 3px;
    background: linear-gradient(90deg, var(--reading-accent), #ff6b6b);
    z-index: 9999;
    transition: width 0.1s ease;
}

/* Menu de paramètres de lecture */
.reading-settings-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    padding: 20px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1001;
    max-height: 70vh;
    overflow-y: auto;
}

.reading-settings-panel.active {
    transform: translateY(0);
}

.reading-settings-panel .setting-group {
    margin-bottom: 20px;
}

.reading-settings-panel .setting-label {
    font-weight: 600;
    margin-bottom: 10px;
    display: block;
    color: #333;
}

.reading-settings-panel .setting-options {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.reading-settings-panel .setting-btn {
    flex: 1;
    min-width: 60px;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.reading-settings-panel .setting-btn.active {
    border-color: var(--reading-accent);
    background: rgba(220, 53, 69, 0.1);
    color: var(--reading-accent);
    font-weight: 600;
}

.reading-settings-panel .close-settings {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #999;
    cursor: pointer;
}

/* Overlay pour le panneau de paramètres */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.settings-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Thèmes de lecture */
.theme-light {
    --reading-bg: #ffffff;
    --reading-text: #2c3e50;
}

.theme-sepia {
    --reading-bg: #f4ecd8;
    --reading-text: #5c4a3a;
}

.theme-dark {
    --reading-bg: #1a1a1a;
    --reading-text: #e0e0e0;
}



/* Tailles de police ajustables */
.font-size-small { font-size: 14px !important; }
.font-size-medium { font-size: 16px !important; }
.font-size-large { font-size: 18px !important; }
.font-size-xlarge { font-size: 20px !important; }

/* Espacement de ligne ajustable */
.line-height-compact { line-height: 1.4 !important; }
.line-height-normal { line-height: 1.6 !important; }
.line-height-relaxed { line-height: 1.8 !important; }
.line-height-loose { line-height: 2.0 !important; }
/* Améliorations supplémentaires pour l'expérience mobile */

/* Animation d'entrée pour les éléments */
@keyframes slideInUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.mobile-reading-toolbar {
    animation: slideInUp 0.5s ease-out 0.5s both;
}

/* Amélioration des contrôles PDF/EPUB sur mobile */
@media (max-width: 768px) {
    #pdfContainer,
    #epubContainer {
        border-radius: var(--mobile-border-radius) !important;
        overflow: hidden;
    }
    
    #pdfControls,
    #epubControls {
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(10px);
        border-top: 1px solid rgba(0,0,0,0.1) !important;
        padding: 12px !important;
    }
    
    .pdf-nav-btn,
    .epub-nav-btn {
        min-height: var(--touch-target-size) !important;
        border-radius: 8px !important;
        font-weight: 500;
    }
}

/* Amélioration du partage social sur mobile */
@media (max-width: 768px) {
    .share-container .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .share-icons {
        position: fixed !important;
        bottom: 100px !important;
        left: 50% !important;
        transform: translateX(-50%) !important;
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(10px);
        border: 1px solid rgba(0,0,0,0.1);
        padding: 15px 20px !important;
        border-radius: 20px !important;
        box-shadow: 0 8px 32px rgba(0,0,0,0.2) !important;
    }
    
    .share-icons::before {
        display: none !important;
    }
    
    .share-icon {
        width: 50px !important;
        height: 50px !important;
        margin: 0 5px !important;
        font-size: 1.2rem !important;
    }
}

/* Mode sombre amélioré */
.theme-dark {
    --reading-bg: #1a1a1a;
    --reading-text: #e0e0e0;
    --mobile-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.theme-dark .mobile-reading-toolbar {
    background: #2d2d2d;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.theme-dark .mobile-reading-toolbar .btn {
    background: #3d3d3d;
    color: #ccc;
}

.theme-dark .mobile-reading-toolbar .btn:hover,
.theme-dark .mobile-reading-toolbar .btn.active {
    background: var(--reading-accent);
    color: white;
}

.theme-dark .reading-settings-panel {
    background: #2d2d2d;
    color: #e0e0e0;
}

.theme-dark .setting-btn {
    background: #3d3d3d;
    border-color: #555;
    color: #ccc;
}

.theme-dark .setting-btn.active {
    background: rgba(220, 53, 69, 0.2);
    border-color: var(--reading-accent);
    color: var(--reading-accent);
}

/* Mode sépia amélioré */
.theme-sepia {
    --reading-bg: #f4ecd8;
    --reading-text: #5c4a3a;
}

.theme-sepia .mobile-reading-toolbar {
    background: #f0e6d2;
}

.theme-sepia .mobile-reading-toolbar .btn {
    background: #e8dcc0;
    color: #8b7355;
}

/* Amélioration de l'accessibilité */
@media (prefers-reduced-motion: reduce) {
    .mobile-reading-toolbar,
    .reading-settings-panel,
    .share-icons,
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Support pour les écrans haute densité */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .mobile-reading-toolbar {
        box-shadow: 0 1px 4px rgba(0,0,0,0.15);
    }
    
    .reading-settings-panel {
        box-shadow: 0 -2px 10px rgba(0,0,0,0.2);
    }
}

/* Amélioration pour les très grands écrans mobiles */
@media (max-width: 768px) and (min-height: 900px) {
    .mobile-reading-toolbar {
        bottom: 40px;
    }
    
    .reading-settings-panel {
        max-height: 60vh;
    }
}

/* Amélioration pour les écrans en mode paysage */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-reading-toolbar {
        bottom: 15px;
        right: 15px;
        flex-direction: row;
    }
    
    .reading-settings-panel {
        max-height: 80vh;
        border-radius: 15px 15px 0 0;
    }
    

}

/* Indicateur de chargement pour les images */
img[loading="lazy"] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

img[loading="lazy"]:not([src]) {
    min-height: 200px;
}

/* Amélioration des tooltips sur mobile */
@media (max-width: 768px) {
    [title]:hover::after {
        content: attr(title);
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(0,0,0,0.8);
        color: white;
        padding: 8px 12px;
        border-radius: 6px;
        font-size: 0.8rem;
        white-space: nowrap;
        z-index: 1000;
        pointer-events: none;
    }
}
/* Mode Focus - masque les distractions */
.focus-mode .navbar,
.focus-mode .breadcrumb,
.focus-mode .col-lg-3,
.focus-mode footer,
.focus-mode .share-container,
.focus-mode .btn:not(.mobile-reading-toolbar .btn),
.focus-mode .badge,
.focus-mode .alert {
    opacity: 0.3 !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease !important;
}

.focus-mode article {
    max-width: 700px !important;
    margin: 0 auto !important;
    padding: 40px 20px !important;
    font-size: 18px !important;
    line-height: 1.8 !important;
}

.focus-mode .focus-mode-toggle {
    background: var(--reading-accent) !important;
    color: white !important;
}

/* Amélioration des images zoomées */
img.zoomed {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) scale(2) !important;
    z-index: 9999 !important;
    max-width: 90vw !important;
    max-height: 90vh !important;
    object-fit: contain !important;
    background: rgba(0,0,0,0.9) !important;
    padding: 20px !important;
    border-radius: 10px !important;
    box-shadow: 0 10px 50px rgba(0,0,0,0.5) !important;
}

/* Overlay pour les images zoomées */
img.zoomed::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.8);
    z-index: -1;
}

/* Indicateur de temps de lecture */
.reading-time-indicator {
    text-align: center;
}

.reading-time-indicator small {
    display: block;
    opacity: 0.8;
    font-size: 0.8rem;
    margin-top: 2px;
}

/* Amélioration de la barre de progression */
.reading-progress {
    background: linear-gradient(90deg, var(--reading-accent) 0%, #ff6b6b 50%, #4ecdc4 100%);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Animation de pulsation pour les boutons actifs */
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.mobile-reading-toolbar .btn.active {
    animation: pulse 2s infinite;
}

/* Amélioration des contrôles en mode plein écran */
.fullscreen .mobile-reading-toolbar,
.fullscreen-epub .mobile-reading-toolbar {
    display: none !important;
}

/* Styles pour les notifications toast améliorées */
.mobile-toast {
    backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
}

/* Amélioration de l'accessibilité - focus visible */
.mobile-reading-toolbar .btn:focus,
.setting-btn:focus,
.share-icon:focus {
    outline: 2px solid var(--reading-accent) !important;
    outline-offset: 2px !important;
}

/* Support pour les préférences système */
@media (prefers-color-scheme: dark) {
    :root {
        --reading-bg: #1a1a1a;
        --reading-text: #e0e0e0;
    }
}

@media (prefers-color-scheme: light) {
    :root {
        --reading-bg: #ffffff;
        --reading-text: #2c3e50;
    }
}

/* Amélioration pour les écrans tactiles */
@media (hover: none) and (pointer: coarse) {
    .mobile-reading-toolbar .btn {
        min-width: 50px !important;
        min-height: 50px !important;
    }
    
    .setting-btn {
        min-height: 50px !important;
        font-size: 1rem !important;
    }
    
    .share-icon {
        min-width: 50px !important;
        min-height: 50px !important;
    }
}

/* Amélioration pour les écrans pliables */
@media (max-width: 768px) and (min-aspect-ratio: 1/1) {

}

/* Styles pour les appareils avec encoche */
@supports (padding-top: env(safe-area-inset-top)) {
    .reading-progress {
        top: env(safe-area-inset-top) !important;
    }
    
    .mobile-reading-toolbar {
        bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    }
    
    .reading-settings-panel {
        padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    }
}

/* Animation de chargement pour le contenu */
@keyframes contentFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}












/* Corrections spécifiques pour les contrôles PDF/EPUB qui sortent de l'écran */
@media (max-width: 768px) {
    /* Forcer les contrôles à rester dans l'écran */
    #pdfControls,
    #epubControls {
        max-width: 100vw !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }
    
    /* Améliorer la distribution des boutons */
    #pdfControls > *,
    #epubControls > * {
        flex-shrink: 1 !important;
        min-width: 0 !important;
    }
    
    /* Boutons de navigation plus compacts */
    .pdf-nav-btn,
    .epub-nav-btn {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }
    
    /* Indicateurs de page plus flexibles */
    #pdfPageIndicator,
    #epubProgress {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
        text-align: center !important;
    }
}

/* Corrections pour très petits écrans */
@media (max-width: 480px) {
    /* Réduire encore plus l'espacement */
    #pdfControls,
    #epubControls {
        gap: 2px !important;
        padding: 4px 2px !important;
    }
    
    /* Boutons encore plus compacts */
    .pdf-nav-btn,
    .epub-nav-btn,
    #closeFullscreen,
    #closeEpubFullscreen {
        font-size: 0.7rem !important;
        padding: 0.15rem 0.2rem !important;
        max-width: 55px !important;
    }
    
    /* Masquer le texte, garder seulement les icônes */
    .pdf-nav-btn span,
    .epub-nav-btn span {
        display: none !important;
    }
    
    /* Indicateurs plus petits */
    #pdfPageIndicator,
    #epubProgress {
        font-size: 0.7rem !important;
        padding: 0.15rem 0.1rem !important;
        max-width: 90px !important;
    }
}

/* Pour les écrans vraiment minuscules */
@media (max-width: 360px) {
    #pdfControls,
    #epubControls {
        gap: 1px !important;
        padding: 3px 1px !important;
        justify-content: space-evenly !important;
    }
    
    .pdf-nav-btn,
    .epub-nav-btn,
    #closeFullscreen,
    #closeEpubFullscreen {
        font-size: 0.65rem !important;
        padding: 0.1rem 0.15rem !important;
        max-width: 45px !important;
        min-width: 30px !important;
    }
    
    #pdfPageIndicator,
    #epubProgress {
        font-size: 0.65rem !important;
        padding: 0.1rem 0.05rem !important;
        max-width: 70px !important;
        min-width: 35px !important;
    }
}

/* Amélioration de la lisibilité des contrôles */
@media (max-width: 768px) {
    /* Contraste amélioré pour les boutons */
    .pdf-nav-btn:not(#closeFullscreen),
    .epub-nav-btn:not(#closeEpubFullscreen) {
        background-color: #495057 !important;
        border-color: #495057 !important;
        color: white !important;
    }
    
    .pdf-nav-btn:hover:not(#closeFullscreen),
    .epub-nav-btn:hover:not(#closeEpubFullscreen) {
        background-color: #343a40 !important;
        border-color: #343a40 !important;
    }
    
    /* Bouton fermer plus visible */
    #closeFullscreen,
    #closeEpubFullscreen {
        background-color: #dc3545 !important;
        border-color: #dc3545 !important;
        color: white !important;
        font-weight: bold !important;
    }
    
    /* Indicateurs plus lisibles */
    #pdfPageIndicator,
    #epubProgress {
        background: rgba(0,0,0,0.05) !important;
        border-radius: 4px !important;
        font-weight: 600 !important;
        color: #495057 !important;
    }
}

/* Animation pour indiquer que les contrôles sont interactifs */
@media (max-width: 768px) {
    .pdf-nav-btn,
    .epub-nav-btn,
    #closeFullscreen,
    #closeEpubFullscreen {
        transition: all 0.2s ease !important;
    }
    
    .pdf-nav-btn:active,
    .epub-nav-btn:active,
    #closeFullscreen:active,
    #closeEpubFullscreen:active {
        transform: scale(0.95) !important;
    }
}

/* Support pour les appareils avec encoche */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 768px) {
        #pdfControls,
        #epubControls {
            padding-bottom: calc(4px + env(safe-area-inset-bottom)) !important;
        }
    }
}