/* ==========================================================================
   Champ at_gallery — habillage des six dispositions + lightbox.
   Rendu par Gallery_Options::render() (classes/gallery-options.class.php).

   Tout le rythme est en variables `--at-gallery-*` : un plugin hôte n'en
   fournit que des valeurs (pont CSS), jamais de règle. Les valeurs posées par
   le rendu lui-même : --at-gallery-columns, --at-gallery-gap,
   --at-gallery-row-height, --at-gallery-ratio (facultatif), et --ratio sur
   chaque figure (largeur / hauteur de l'image).
   ========================================================================== */

.at-gallery {
    --at-gallery-radius: var(--at-radius, 0.5rem);
    --at-gallery-caption-bg: rgba(0, 0, 0, .55);
    --at-gallery-caption-color: #fff;
    --at-gallery-featured-span: 2;
    position: relative;
}

.at-gallery__group + .at-gallery__group {
    margin-top: calc(var(--at-gallery-gap, 1rem) * 2);
}

.at-gallery__title {
    margin: 0 0 var(--at-gallery-gap, 1rem);
}

.at-gallery__item {
    position: relative;
    margin: 0;
    overflow: hidden;
    border-radius: var(--at-gallery-radius);
    /* Fond de case : visible avant le chargement et autour d'une image entière
       (contain). Un hôte peut le rendre transparent (logos sur fond blanc). */
    background: var(--at-gallery-item-bg, color-mix(in oklab, currentColor 6%, transparent));
}

.at-gallery__img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Image entière dans sa case (logos, visuels qu'on ne rogne pas) : la case
   garde sa géométrie, l'image y tient avec une marge intérieure optionnelle. */
.at-gallery--contain .at-gallery__img {
    object-fit: contain;
    padding: var(--at-gallery-fit-padding, 0);
    box-sizing: border-box;
}

.has-lightbox .at-gallery__item {
    cursor: zoom-in;
}

.has-lightbox .at-gallery__item:focus-visible {
    outline: 3px solid var(--at-focus, #005fcc);
    outline-offset: 2px;
}

.at-gallery__caption {
    position: absolute;
    inset: auto 0 0;
    padding: .5rem .75rem;
    font-size: .875rem;
    line-height: 1.3;
    color: var(--at-gallery-caption-color);
    background: var(--at-gallery-caption-bg);
}

/* Le sizer masonry et les lots inertes ne prennent pas de place. */
.at-gallery__sizer {
    position: absolute;
    visibility: hidden;
    pointer-events: none;
}

.at-gallery__sentinel {
    height: 1px;
}

/* Un item fraîchement révélé arrive en fondu ; coupé si l'utilisateur préfère
   moins d'animation. Opacité seule : masonry-layout place ses items par
   `transform`, une animation de transform l'écraserait (items empilés en 0,0). */
.at-gallery__item.is-revealed {
    animation: at-gallery-reveal .35s ease both;
}

@keyframes at-gallery-reveal {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .at-gallery__item.is-revealed { animation: none; }
}

/* Un déclencheur « charger plus » (data-atb-gallery-more) disparaît quand tout
   est chargé. */
[data-atb-gallery-more].is-done {
    display: none !important;
}

/* --------------------------------------------------------------------------
   Grille
   -------------------------------------------------------------------------- */
.at-gallery--grid .at-gallery__items {
    display: grid;
    grid-template-columns: repeat(var(--at-gallery-columns, 3), minmax(0, 1fr));
    gap: var(--at-gallery-gap, 1rem);
}

.at-gallery--grid .at-gallery__item {
    aspect-ratio: var(--at-gallery-ratio, var(--ratio, auto));
}

/* Colonnes tablette / mobile : posées par le rendu (réglage ou défaut du rendu). */
@media (max-width: 768px) {
    .at-gallery--grid .at-gallery__items {
        grid-template-columns: repeat(var(--at-gallery-columns-md, 2), minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .at-gallery--grid .at-gallery__items {
        grid-template-columns: repeat(var(--at-gallery-columns-sm, 1), minmax(0, 1fr));
    }
}

/* --------------------------------------------------------------------------
   Rangée — hauteur cible, largeur naturelle, retour à la ligne, rien ne
   s'étire (logos, certifications). Alignement : --at-gallery-row-align.
   -------------------------------------------------------------------------- */
.at-gallery--row .at-gallery__items {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: var(--at-gallery-row-align, flex-start);
    gap: var(--at-gallery-gap, 1rem);
}

.at-gallery--row .at-gallery__item {
    flex: none;
    height: var(--at-gallery-row-height, 240px);
    aspect-ratio: var(--at-gallery-ratio, var(--ratio, 1.5));
    width: auto;
    max-width: 100%;
}

/* --------------------------------------------------------------------------
   Justifié — rangées à hauteur cible, largeur proportionnelle au ratio.
   flex-grow = ratio (× 100 pour rester en entiers lisibles), base = hauteur
   cible × ratio : une rangée pleine étire ses images à la même hauteur, la
   dernière rangée est retenue par le pseudo-élément à croissance énorme.
   -------------------------------------------------------------------------- */
.at-gallery--justified .at-gallery__items {
    display: flex;
    flex-wrap: wrap;
    gap: var(--at-gallery-gap, 1rem);
}

.at-gallery--justified .at-gallery__item {
    flex: calc(var(--ratio, 1.5) * 100) 1 calc(var(--at-gallery-row-height, 240px) * var(--ratio, 1.5));
    max-width: 100%;
    aspect-ratio: var(--ratio, 1.5);
}

.at-gallery--justified .at-gallery__items::after {
    content: "";
    flex: 1000000 1 0;
    min-width: 0;
}

@media (max-width: 480px) {
    .at-gallery--justified .at-gallery__item {
        flex-basis: calc(var(--at-gallery-row-height, 240px) * var(--ratio, 1.5) * 0.6);
    }
    /* Une image par rangée le plus souvent : sans retenue, la dernière
       remplit sa rangée au lieu de finir minuscule. */
    .at-gallery--justified .at-gallery__items::after {
        display: none;
    }
}

/* --------------------------------------------------------------------------
   Masonry — largeur de colonne en CSS (sizer + items), placement par
   masonry-layout. Avant l'initialisation : grille CSS de repli, sans saut.
   -------------------------------------------------------------------------- */
.at-gallery--masonry .at-gallery__items {
    --at-gallery-col: calc((100% - var(--at-gallery-gap, 1rem) * (var(--at-gallery-columns, 3) - 1)) / var(--at-gallery-columns, 3));
    display: grid;
    grid-template-columns: repeat(var(--at-gallery-columns, 3), minmax(0, 1fr));
    gap: var(--at-gallery-gap, 1rem);
}

.at-gallery--masonry .at-gallery__items.is-masonry {
    display: block;
    position: relative;
}

.at-gallery--masonry .is-masonry .at-gallery__sizer,
.at-gallery--masonry .is-masonry .at-gallery__item {
    width: var(--at-gallery-col);
}

.at-gallery--masonry .is-masonry .at-gallery__item {
    margin-bottom: var(--at-gallery-gap, 1rem);
}

@media (max-width: 768px) {
    .at-gallery--masonry .at-gallery__items { --at-gallery-columns: var(--at-gallery-columns-md, 2); grid-template-columns: repeat(var(--at-gallery-columns-md, 2), minmax(0, 1fr)); }
}

@media (max-width: 480px) {
    .at-gallery--masonry .at-gallery__items { --at-gallery-columns: var(--at-gallery-columns-sm, 1); grid-template-columns: repeat(var(--at-gallery-columns-sm, 1), minmax(0, 1fr)); }
}

/* --------------------------------------------------------------------------
   Mosaïque — grille de cases : la case fait la largeur d'une colonne (hauteur
   au ratio demandé, carrée par défaut), calculée en unités de conteneur ; une
   image occupe --at-span-c × --at-span-r cases (posés par le template) et
   `dense` comble les trous. Sans ratio de cases fixe, les spans ne pourraient
   pas s'aligner.
   -------------------------------------------------------------------------- */
/* Les unités cq* se résolvent sur un conteneur ANCÊTRE : c'est le groupe
   (même largeur que sa grille) qui porte container-type, pas la grille. */
.at-gallery--mosaic .at-gallery__group {
    container-type: inline-size;
}

.at-gallery--mosaic .at-gallery__items {
    --at-gallery-cell: calc((100cqw - var(--at-gallery-gap, 1rem) * (var(--at-gallery-columns, 3) - 1)) / var(--at-gallery-columns, 3));
    display: grid;
    grid-template-columns: repeat(var(--at-gallery-columns, 3), minmax(0, 1fr));
    grid-auto-rows: calc(var(--at-gallery-cell) / (var(--at-gallery-ratio, 1)));
    grid-auto-flow: dense;
    gap: var(--at-gallery-gap, 1rem);
}

.at-gallery--mosaic .at-gallery__item {
    grid-column: span min(var(--at-span-c, 1), var(--at-gallery-columns, 3));
    grid-row: span var(--at-span-r, 1);
    min-height: 0;
    aspect-ratio: auto;
}

@media (max-width: 768px) {
    .at-gallery--mosaic .at-gallery__items {
        --at-gallery-columns: var(--at-gallery-columns-md, 2);
        grid-template-columns: repeat(var(--at-gallery-columns-md, 2), minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .at-gallery--mosaic .at-gallery__items {
        --at-gallery-columns: var(--at-gallery-columns-sm, 2);
        grid-template-columns: repeat(var(--at-gallery-columns-sm, 2), minmax(0, 1fr));
    }
}

/* --------------------------------------------------------------------------
   Slider — Swiper (at-slider.js) ; une image par slide, largeur auto.
   -------------------------------------------------------------------------- */
.at-gallery--slider .at-slider {
    position: relative; /* les contrôles, créés hors du .swiper, s'y ancrent */
}

.at-gallery--slider .at-slider__viewport {
    overflow: hidden;
}

.at-gallery--slider .swiper-slide {
    width: auto;
    max-width: 90%;
    height: auto;
}

.at-gallery--slider .at-slider__nav {
    --swiper-navigation-size: 1rem;
}

.at-gallery--slider .at-slider__pagination {
    --swiper-pagination-color: var(--at-gallery-nav-bg, rgba(0, 0, 0, .45));
}

.at-gallery--slider .at-gallery__item {
    height: var(--at-gallery-row-height, 240px);
    aspect-ratio: var(--at-gallery-ratio, var(--ratio, 1.5));
    width: auto;
}

/* « Images par vue » fixé : Swiper dimensionne les slides, l'image remplit
   la sienne (ratio de la galerie, sinon 3:2 commun à toutes pour une rangée
   régulière). */
.at-gallery--slider[data-per-view] .swiper-slide {
    max-width: none;
}

.at-gallery--slider[data-per-view] .at-gallery__item {
    width: 100%;
    height: auto;
    aspect-ratio: var(--at-gallery-ratio, 3 / 2);
}

.at-gallery--slider .swiper-button-prev,
.at-gallery--slider .swiper-button-next {
    color: var(--at-gallery-nav-color, #fff);
    background: var(--at-gallery-nav-bg, rgba(0, 0, 0, .45));
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
}

.at-gallery--slider .swiper-button-prev::after,
.at-gallery--slider .swiper-button-next::after {
    font-size: 1rem;
}

/* --------------------------------------------------------------------------
   Bandeau — initMarquee ; les figures en ligne, hauteur fixe.
   -------------------------------------------------------------------------- */
.at-gallery--marquee .at-marquee-wrapper .content {
    display: flex;
    gap: var(--at-gallery-gap, 1rem);
    padding-right: var(--at-gallery-gap, 1rem);
}

.at-gallery--marquee .at-gallery__item {
    flex: none;
    height: var(--at-gallery-row-height, 240px);
    aspect-ratio: var(--at-gallery-ratio, var(--ratio, 1.5));
    width: auto;
}

/* Sens inverse : posé par le template, honoré par initMarquee (qui ajoute
   `reverse` à l'animation) — la règle CSS seule serait écrasée par le
   raccourci `animation` inline. */

/* --------------------------------------------------------------------------
   Lightbox — un <dialog> par page, monté par at-lightbox.js.
   -------------------------------------------------------------------------- */
.at-lightbox {
    --at-lightbox-bg: rgba(10, 12, 16, .92);
    --at-lightbox-fg: #fff;
    border: 0;
    padding: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    max-height: none;
    background: transparent;
    color: var(--at-lightbox-fg);
}

.at-lightbox::backdrop {
    background: var(--at-lightbox-bg, rgba(10, 12, 16, .92));
}

.at-lightbox__stage {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    padding: 3.5rem 4rem 4rem;
    box-sizing: border-box;
}

.at-lightbox__img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: var(--at-gallery-radius, 0.5rem);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
    animation: at-lightbox-in .2s ease both;
}

@keyframes at-lightbox-in {
    from { opacity: 0; transform: scale(.98); }
    to   { opacity: 1; transform: none; }
}

.at-lightbox__caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1rem;
    text-align: center;
    padding: 0 4rem;
    font-size: .95rem;
    line-height: 1.35;
    opacity: .9;
}

.at-lightbox__counter {
    position: absolute;
    top: 1rem;
    left: 1.25rem;
    font-size: .875rem;
    opacity: .75;
    font-variant-numeric: tabular-nums;
}

.at-lightbox__btn {
    position: absolute;
    display: grid;
    place-items: center;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: inherit;
    font: inherit;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    transition: background .15s;
}

.at-lightbox__btn:hover,
.at-lightbox__btn:focus-visible {
    background: rgba(255, 255, 255, .28);
    outline: none;
}

.at-lightbox__btn[disabled] {
    opacity: .3;
    cursor: default;
}

.at-lightbox__close { top: .75rem; right: .75rem; }
.at-lightbox__prev  { left: .75rem; top: 50%; transform: translateY(-50%); }
.at-lightbox__next  { right: .75rem; top: 50%; transform: translateY(-50%); }

@media (max-width: 640px) {
    .at-lightbox__stage { padding: 3.25rem .5rem 3.5rem; }
    .at-lightbox__prev,
    .at-lightbox__next { top: auto; bottom: .5rem; transform: none; }
    .at-lightbox__caption { bottom: 3.75rem; padding: 0 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    .at-lightbox__img { animation: none; }
}
