/**
 * mod_policarpagallery — grille responsive + lightbox plein écran
 *
 * Lightbox transposée du projet Mon Héritage (exhibition.php), préfixes mh- -> pol-.
 * Variables --pol-* avec fallback : le template tpl_policarpa peut les redéfinir
 * sans toucher à ce fichier. Aucune police imposée (héritage du template).
 *
 * (C) 2026 LEDEV — GNU GPL v2 ou ultérieure
 */

/* === Grille === */

/* Respiration autour de la galerie : insérée dans un article via
   loadposition, elle collait sinon au contenu qui suit (retour Yann,
   31 Juillet 2026 — bouton « Retour » collé à la dernière rangée) */
.pol-gallery {
    margin-block: 1.5rem 2.5rem;
}

/* --pol-gallery-cols et --pol-gallery-ratio sont posées inline par le module
   (valeurs issues d'une allowlist PHP : 2/3/4 colonnes, ratios prédéfinis) */
.pol-gallery__grid {
    display: grid;
    grid-template-columns: repeat(var(--pol-gallery-cols, 3), 1fr);
    gap: var(--pol-space-sm, 16px);
}

/* Carte en colonne : height 100% remplit la cellule de grille (stretch),
   la zone de légende s'étire jusqu'au bas (flex) → toutes les cartes d'une
   rangée sont alignées même quand les légendes font 1 à 4 lignes (retour
   Yann, 31 Juillet 2026). Fine bordure : même vocabulaire « encadré » que
   les couvertures de livres. */
.pol-gallery__item {
    display: flex;
    flex-direction: column;
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    border: 1px solid var(--pol-border-carte, rgba(30, 30, 30, 0.08));
    background: none;
    border-radius: var(--pol-radius-sm, 8px);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Seuls les items-boutons (lightbox active) sont cliquables */
button.pol-gallery__item {
    cursor: pointer;
    text-align: inherit;
    font: inherit;
}

/* Effet de survol réservé aux items cliquables : une figure statique
   (lightbox désactivée) qui zoome suggérerait à tort une interaction */
button.pol-gallery__item:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.pol-gallery__item:focus-visible {
    outline: 3px solid var(--pol-accent, #F13B3A);
    outline-offset: 2px;
}

.pol-gallery__item img {
    display: block;
    flex: none; /* l'image garde son ratio, seule la légende s'étire */
    width: 100%;
    /* Ratio « auto » : la variable vaut alors littéralement auto,
       chaque vignette garde sa hauteur naturelle */
    aspect-ratio: var(--pol-gallery-ratio, 4 / 5);
    object-fit: cover;
}

.pol-gallery__caption {
    display: block;
    flex: 1 1 auto; /* la zone crème descend jusqu'au bas de la carte */
    padding: var(--pol-space-xs, 8px) var(--pol-space-sm, 12px);
    font-size: 13px;
    text-align: center;
    color: var(--pol-text-secondary, #54595F);
    background: var(--pol-surface, #FAF9F5);
}

/* Paragraphes de légende (.pol-cap-par, générés par le module) : blocs
   espacés — distincts du simple retour à la ligne <br> qui, lui,
   n'ajoute aucun espace. Vaut pour la grille ET la lightbox. */
.pol-gallery__caption .pol-cap-par,
.pol-lb-caption .pol-cap-par {
    display: block;
}

.pol-gallery__caption .pol-cap-par + .pol-cap-par,
.pol-lb-caption .pol-cap-par + .pol-cap-par {
    margin-top: 0.6em;
}

/* Responsive : N -> 2 -> 1 colonnes (breakpoints de la charte policarpa) */
@media (max-width: 1024px) {
    .pol-gallery__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 767px) {
    .pol-gallery__grid {
        grid-template-columns: 1fr;
    }
}

/* === Lightbox (overlay plein écran + bande de vignettes en bas) === */

.pol-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    z-index: 9999;
    display: grid;
    grid-template-rows: 1fr auto;
    align-items: center;
    justify-items: center;
}

.pol-lightbox[hidden] {
    display: none;
}

.pol-lb-content {
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--pol-space-sm, 12px);
    /* Gouttières latérales réservées aux chevrons (bouton 72px posé à 16px
       du bord → 88px occupés par côté) : l'image ne doit JAMAIS passer sous
       les flèches, quelle que soit la largeur d'écran (retour Yann,
       07 Août 2026, constaté sur iPhone) */
    max-width: min(90vw, 100vw - 192px);
    max-height: 100%;
    padding: 60px 20px 20px;
    overflow: hidden;
}

.pol-lb-image {
    max-width: 100%;
    /* Laisse la place à la bande de vignettes en bas + aux contrôles en haut */
    max-height: calc(100vh - 250px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s ease;
}

.pol-lb-caption {
    color: #fff;
    text-align: center;
    font-size: 14px;
    max-width: 600px;
    line-height: 1.5;
    min-height: 1.5em;
}

/* Boutons fermer + navigation */
.pol-lb-close,
.pol-lb-nav {
    position: absolute;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 12px;
    border-radius: 50%;
    transition: background 0.15s;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pol-lb-close:hover,
.pol-lb-nav:hover {
    background: rgba(255, 255, 255, 0.1);
}

.pol-lb-close:focus-visible,
.pol-lb-nav:focus-visible,
.pol-lb-thumb:focus-visible {
    outline: 3px solid var(--pol-accent, #F13B3A);
    outline-offset: 2px;
}

.pol-lb-close {
    top: 16px;
    right: 16px;
}

.pol-lb-nav {
    top: 50%;
    transform: translateY(-50%);
}

.pol-lb-nav-prev {
    left: 16px;
}

.pol-lb-nav-next {
    right: 16px;
}

@media (max-width: 767px) {
    .pol-lb-nav-prev {
        left: 4px;
    }

    .pol-lb-nav-next {
        right: 4px;
    }

    /* Chevron réduit sur mobile : icône 32px + padding 8px = bouton 48px
       (minimum tactile respecté) pour céder le moins de largeur possible
       à la photo ; posé à 4px du bord → 52px occupés par côté */
    .pol-lb-nav {
        padding: 8px;
    }

    .pol-lb-nav svg {
        width: 32px;
        height: 32px;
    }

    /* Gouttières mobiles : 56px par côté (52px de chevron + marge) ;
       le padding interne descend à 8px pour rendre à la photo une partie
       de la largeur cédée aux flèches (le swipe reste disponible) */
    .pol-lb-content {
        max-width: calc(100vw - 112px);
        padding-inline: 8px;
    }
}

.pol-lb-counter {
    position: absolute;
    top: 24px;
    left: 24px;
    color: #fff;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
    background: rgba(0, 0, 0, 0.4);
    padding: 6px 12px;
    border-radius: 16px;
}

/* Bande de vignettes en bas */
.pol-lb-thumbs {
    grid-row: 2;
    width: 100%;
    background: rgba(0, 0, 0, 0.5);
    padding: 12px 16px;
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
    /* Centré quand les vignettes tiennent dans la largeur,
       bascule en flex-start si débordement pour ne pas masquer les premières
       (sans « safe », le centrage tronquerait le début en cas de scroll) */
    justify-content: center;
    justify-content: safe center;
}

.pol-lb-thumbs::-webkit-scrollbar {
    height: 6px;
}

.pol-lb-thumbs::-webkit-scrollbar-track {
    background: transparent;
}

.pol-lb-thumbs::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

.pol-lb-thumb {
    flex-shrink: 0;
    background: none;
    border: 2px solid transparent;
    padding: 0;
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    width: 70px;
    height: 70px;
    transition: border-color 0.15s, opacity 0.15s, transform 0.15s;
    opacity: 0.6;
}

.pol-lb-thumb:hover {
    opacity: 1;
    transform: scale(1.05);
}

.pol-lb-thumb.is-active {
    opacity: 1;
    border-color: var(--pol-accent, #F13B3A);
}

.pol-lb-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

@media (max-width: 767px) {
    .pol-lb-thumb {
        width: 56px;
        height: 56px;
    }

    .pol-lb-thumbs {
        padding: 8px 10px;
    }
}

/* Bloque le défilement de la page tant que la lightbox est ouverte */
body.pol-lb-open {
    overflow: hidden;
}
