/**
 * ANIMATIONS CSS
 * Transitions, animations et effets visuels
 */

/* ===============================================
   CHARGEMENT IMAGES — SKELETON SHIMMER + FONDU
   =============================================== */

/**
 * Balayage lumineux (shimmer) pour pseudo-éléments overlay (::after).
 * Fait glisser l'overlay transparent sur le fond gris — le conteneur
 * doit avoir overflow:hidden. Ne pas appliquer directement sur un
 * élément conteneur (utiliser skeleton-bg-shimmer à la place).
 */
@keyframes skeleton-shimmer {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/**
 * Shimmer pour conteneurs ayant un dégradé de fond (background-position).
 * Utiliser sur .actualite-thumbnail, .featured-image-wrap, etc.
 * Anime la position du gradient sans déplacer l'élément.
 */
@keyframes skeleton-bg-shimmer {
    0%   { background-position: -1200px 0; }
    100% { background-position: 1200px 0; }
}

/**
 * Classe ajoutée par JS sur les conteneurs d'images en cours de chargement.
 * Compatible avec ::before existant (utilise ::after).
 */
.img-skeleton {
    position: relative;
    overflow: hidden;
}

.img-skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.52) 50%,
        transparent 100%
    );
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    pointer-events: none;
    z-index: 3;
}

/*
 * Miniatures + carrousel : pas de calque ::after (image-loader ajoute .img-skeleton).
 * L’overlay blanc animé passait au-dessus du dégradé marque et donnait un fond « gris ».
 */
.actualite-thumbnail.img-skeleton::after,
.featured-image-wrap.img-skeleton::after {
    content: none;
    display: none;
}

/* Fondu d'apparition pour les balises <img> (classe ajoutée par JS) */
img.img-fade {
    opacity: 0;
    transition: opacity 0.22s ease;
}

img.img-fade.img-loaded {
    opacity: 1;
}

/* -----------------------------------------------
   Hero : le mécanisme page-loading (base.html)
   masque déjà toute la page jusqu'au chargement
   de l'image de fond. Pas d'animation CSS
   supplémentaire nécessaire ici.
   ----------------------------------------------- */

/* ===============================================
   AIDE WIDGET - Animation d'apparition du panneau
   =============================================== */

.aide-widget-panel:not([hidden]) {
    animation: aidePanelAppear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: bottom left;
}

@keyframes aidePanelAppear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Légère pulsation sur le bouton + l'icône quand le panneau est fermé */
.aide-widget-trigger[aria-expanded="false"] {
    animation: aideTriggerBeat 2.6s ease-in-out infinite;
}

.aide-widget-trigger[aria-expanded="false"] .aide-widget-icon {
    animation: aideIconPulse 2.5s ease-in-out infinite;
}

@keyframes aideTriggerBeat {
    0%,
    100% {
        transform: translateY(0) scale(1);
        box-shadow:
            0 4px 15px rgba(255, 140, 0, 0.35),
            0 0 0 0 rgba(255, 140, 0, 0.0);
    }
    45% {
        transform: translateY(-1px) scale(1.015);
        box-shadow:
            0 7px 20px rgba(255, 140, 0, 0.45),
            0 0 0 8px rgba(255, 140, 0, 0.0);
    }
    55% {
        transform: translateY(-1px) scale(1.01);
        box-shadow:
            0 8px 22px rgba(255, 140, 0, 0.5),
            0 0 0 12px rgba(255, 140, 0, 0.0);
    }
}

@keyframes aideIconPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255, 140, 0, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(255, 140, 0, 0); }
}

@media (prefers-reduced-motion: reduce) {
    .aide-widget-trigger[aria-expanded="false"],
    .aide-widget-trigger[aria-expanded="false"] .aide-widget-icon {
        animation: none;
    }
}

/* ===============================================
   MODAL ANIMATIONS
   =============================================== */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal);
    animation: fadeInOverlay 0.3s;
    overflow: hidden; /* seul le modal-body défile, pas le fond */
}

.modal-overlay.active {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: max(1.5rem, env(safe-area-inset-top, 0)) max(1.5rem, env(safe-area-inset-right, 0)) max(1.5rem, env(safe-area-inset-bottom, 0)) max(1.5rem, env(safe-area-inset-left, 0));
    pointer-events: auto;
}

@keyframes fadeInOverlay {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: var(--couleur-blanc);
    border-radius: var(--rayon-arrondi);
    max-width: min(var(--largeur-modal), calc(100vw - 3rem));
    width: 100%;
    min-width: 0; /* flex : évite rognage à droite (WebKit tablette) */
    min-height: 0; /* enchaînement flex → zone texte scrollable */
    max-height: calc(100vh - 3rem);
    max-height: calc(100dvh - 3rem);
    overflow: hidden;
    position: relative;
    animation: slideIn 0.3s;
    box-shadow: var(--ombre-tres-forte);
    display: flex;
    flex-direction: column;
}

/* Supprimé : plus de bouton "Lire la suite", le modal-body défile toujours */

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-50px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-close {
    position: absolute;
    top: max(var(--espacement-md), env(safe-area-inset-top, 0));
    right: max(var(--espacement-md), env(safe-area-inset-right, 0));
    background: #ffffff;
    border: 2px solid var(--couleur-primaire);
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
    border-radius: var(--rayon-rond);
    font-size: var(--taille-titre-3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-rapide);
    color: var(--couleur-primaire);
    z-index: 10;
    touch-action: manipulation;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    font-weight: bold;
}

.modal-close:hover {
    background: var(--couleur-primaire);
    color: var(--texte-inverse);
    transform: rotate(90deg);
}

.modal-header-image {
    width: 100%;
    height: auto;
    /* min-height garantit une zone visible pendant le chargement asynchrone */
    min-height: 180px;
    /* Affiche / poster : plus grand pour lisibilité (desktop) */
    max-height: min(68vh, 580px);
    object-fit: contain;
    object-position: center center;
    background: #1a1a1a;
    border-radius: var(--rayon-arrondi) var(--rayon-arrondi) 0 0;
    display: block;
    flex: 0 1 auto; /* ne pas manger toute la hauteur : laisser du scroll au texte */
    min-height: 0;
}

.modal-header-image--default {
    background: #f4f4f4;
    max-height: 140px;
    padding: 1.25rem 2.5rem;
    object-fit: contain;
}

/* Shimmer pendant le préchargement de l'image */
.modal-header-image--loading {
    background: linear-gradient(90deg, #1a1a1a 25%, #2e2e2e 50%, #1a1a1a 75%);
    background-size: 200% 100%;
    animation: modalImageShimmer 1.4s ease-in-out infinite;
}

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

/* Paysage / petites hauteurs : moins d’image, plus de place pour le texte défilable */
@media (max-height: 750px) {
    .modal-overlay.active {
        /* Tablette paysage (largeur > 768) : même logique que le breakpoint mobile. */
        align-items: flex-start;
        padding-top: max(0.75rem, env(safe-area-inset-top, 0));
    }
    .modal-header-image {
        max-height: min(40vh, 360px) !important;
    }
}
@media (orientation: landscape) and (max-height: 500px) {
    .modal-header-image {
        max-height: min(32vh, 240px) !important;
    }
}

.modal-body {
    padding: var(--espacement-md);
    padding-left: max(var(--espacement-md), env(safe-area-inset-left, 0));
    padding-right: max(var(--espacement-md), env(safe-area-inset-right, 0));
    padding-bottom: calc(var(--espacement-md) + 1.5rem + env(safe-area-inset-bottom, 0));
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overflow-y: auto;
    overflow-x: hidden; /* texte / images ne débordent pas à droite */
    flex: 1;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,119,0,0.4) transparent;

    /* Ombre de scroll : apparaît en bas quand du contenu reste à lire */
    background:
        linear-gradient(white 30%, transparent) top    / 100% 48px no-repeat local,
        linear-gradient(transparent, white 70%) bottom / 100% 48px no-repeat local,
        radial-gradient(farthest-side at 50% 0,   rgba(0,0,0,.10), transparent) top    / 100% 12px no-repeat scroll,
        radial-gradient(farthest-side at 50% 100%, rgba(0,0,0,.10), transparent) bottom / 100% 12px no-repeat scroll;
    background-color: white;
}

/* Scrollbar Webkit (Chrome/Safari) */
.modal-body::-webkit-scrollbar {
    width: 5px;
}
.modal-body::-webkit-scrollbar-track {
    background: transparent;
}
.modal-body::-webkit-scrollbar-thumb {
    background: rgba(255,119,0,0.35);
    border-radius: 10px;
}
.modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255,119,0,0.65);
}

.modal-meta {
    display: flex;
    align-items: center;
    gap: var(--espacement-sm);
    margin-bottom: var(--espacement-sm);
    flex-wrap: wrap;
}

.modal-title {
    font-size: 28px;
    font-weight: var(--poids-bold);
    color: var(--couleur-secondaire);
    margin-bottom: var(--espacement-sm);
    line-height: 1.4;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-wrap: break-word;
    padding-right: 3.25rem; /* laisse l'espace du bouton fermer */
}

.modal-date {
    font-size: var(--taille-normal);
    color: var(--texte-secondaire);
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-date::before {
    content: '\1F4C5';
    font-size: var(--taille-moyen);
}

.modal-text {
    font-size: var(--taille-moyen);
    line-height: 1.8;
    color: #444;
    margin-bottom: var(--espacement-sm);
    max-width: 100%;
    overflow-wrap: anywhere;
    word-wrap: break-word;
}

.modal-text p {
    margin-bottom: var(--espacement-sm);
}

/* .modal-read-more supprimé — le body défile directement */

.modal-read-more:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 140, 0, 0.4);
}
