/* ==========================================================================
   Champ at_gallery — habillage des 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 `is-pending` (invisible, légèrement
   bas), placé puis dévoilé un à un par le script (cadence réglable) : la
   transition joue au retrait de la classe. `translate` (propriété
   individuelle) et non `transform` : masonry-layout place ses items par
   `transform`, une animation de transform l'écraserait (items empilés en 0,0).
   Coupé si l'utilisateur préfère moins d'animation. */
.at-gallery__item.is-revealed {
    transition: opacity .4s ease, translate .4s ease;
}

.at-gallery__item.is-pending {
    opacity: 0;
    translate: 0 14px;
    transition: none;
}

@media (prefers-reduced-motion: reduce) {
    .at-gallery__item.is-revealed { transition: none; }
    .at-gallery__item.is-pending { translate: 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 — un carrousel du moteur unique (Placement) par groupe ; une image par slide, largeur auto.
   -------------------------------------------------------------------------- */
.at-gallery--slider .at-gallery__carousel {
    position: relative; /* les commandes s'y ancrent */
    overflow: hidden;
}

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

.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é : le carrousel 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] .at-gallery__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 .atp-nav__arrow {
    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%;
}

/* --------------------------------------------------------------------------
   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. */

/* Slider — effets « une image à la fois » (fondu, cartes, cube, retournement, créatif) : une image par vue (forcée par
   le gabarit), centrée et bornée ; les cartes débordent de leur boîte (pile visible). */
.at-gallery--fx-fade .at-gallery__carousel,
.at-gallery--fx-cards .at-gallery__carousel,
.at-gallery--fx-cube .at-gallery__carousel,
.at-gallery--fx-flip .at-gallery__carousel,
.at-gallery--fx-creative .at-gallery__carousel {
    max-width: var(--at-gallery-fx-width, 40rem);
    margin-inline: auto;
}

.at-gallery--fx-cards .at-gallery__carousel {
    max-width: var(--at-gallery-fx-width, min(28rem, 78%));
    overflow: visible;
}

:is(.at-gallery--fx-fade, .at-gallery--fx-cards, .at-gallery--fx-cube, .at-gallery--fx-flip, .at-gallery--fx-creative) .at-gallery__slide {
    max-width: none;
}

:is(.at-gallery--fx-fade, .at-gallery--fx-cards, .at-gallery--fx-cube, .at-gallery--fx-flip, .at-gallery--fx-creative) .at-gallery__item {
    width: 100%;
    height: auto;
    aspect-ratio: var(--at-gallery-ratio, 3 / 2);
}

/* --------------------------------------------------------------------------
   Volets — bandes côte à côte, la bande ouverte (is-open, at-gallery.js) prend la place ; empilées sur petit écran.
   -------------------------------------------------------------------------- */
.at-gallery--strips .at-gallery__group {
    container-type: inline-size;
}

.at-gallery--strips .at-gallery__items {
    display: flex;
    gap: var(--at-gallery-gap, 1rem);
    height: var(--at-gallery-height, 27rem);
}

.at-gallery--strips .at-gallery__item {
    flex: 1 1 0;
    min-width: 0;
    cursor: pointer;
    transition: flex-grow .55s cubic-bezier(.2, .8, .2, 1);
}

.at-gallery--strips .at-gallery__item.is-open {
    flex-grow: 5;
}

.at-gallery--strips.has-lightbox .at-gallery__item.is-open {
    cursor: zoom-in;
}

.at-gallery--strips .at-gallery__caption {
    opacity: 0;
    transition: opacity .3s .2s;
}

.at-gallery--strips .at-gallery__item.is-open .at-gallery__caption {
    opacity: 1;
}

@container (max-width: 640px) {
    .at-gallery--strips .at-gallery__items {
        flex-direction: column;
        height: var(--at-gallery-height, 34rem);
    }
}

/* --------------------------------------------------------------------------
   Éparpillé — tirages inclinés (--rot, --dx, --dy : stables, posés par le gabarit), redressés au survol.
   -------------------------------------------------------------------------- */
.at-gallery--scatter .at-gallery__items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(13rem, 100%), 1fr));
    gap: calc(var(--at-gallery-gap, 1rem) * 2.75) calc(var(--at-gallery-gap, 1rem) * 1.75);
    padding: 1.5rem .5rem;
}

.at-gallery--scatter .at-gallery__item {
    padding: .65rem .65rem 2.6rem;
    border-radius: 2px;
    background: var(--at-gallery-print-bg, #fff);
    box-shadow: 0 8px 22px rgb(0 0 0 / .16);
    transform: translate(var(--dx, 0), var(--dy, 0)) rotate(var(--rot, 0));
    transition: transform .35s cubic-bezier(.2, .8, .2, 1), box-shadow .35s;
}

.at-gallery--scatter .at-gallery__img {
    height: auto;
    aspect-ratio: var(--at-gallery-ratio, 1);
}

.at-gallery--scatter .at-gallery__caption {
    inset: auto .65rem .55rem;
    padding: 0;
    background: none;
    color: var(--at-gallery-print-color, #4a4659);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.at-gallery--scatter .at-gallery__item:is(:hover, :focus-visible) {
    transform: translateY(-.4rem) scale(1.05);
    box-shadow: 0 18px 36px rgb(0 0 0 / .22);
    z-index: 2;
}

/* --------------------------------------------------------------------------
   Contre-sens — colonnes (rangées au serveur, 2 sous 640 px par le script) translatées en sens opposés au défilement.
   -------------------------------------------------------------------------- */
.at-gallery--counter .at-gallery__items {
    display: grid;
    grid-template-columns: repeat(var(--at-counter-cols, 3), minmax(0, 1fr));
    gap: var(--at-gallery-gap, 1rem);
    height: var(--at-gallery-height, 38rem);
    overflow: hidden;
    border-radius: var(--at-gallery-radius);
}

.at-gallery__col {
    display: flex;
    flex-direction: column;
    gap: var(--at-gallery-gap, 1rem);
    will-change: transform;
}

.at-gallery__col:empty {
    display: none;
}

.at-gallery--counter .at-gallery__img {
    height: auto;
    aspect-ratio: var(--at-gallery-ratio, 4 / 5);
}

/* --------------------------------------------------------------------------
   Tunnel — chaque image à sa place (--x, --y en unités de la scène) et à son décalage dans la boucle (--d) ; « au
   défilement » : la scène se fige et le script pose le décalage (animation en pause).
   -------------------------------------------------------------------------- */
.at-gallery--tunnel .at-gallery__items {
    position: relative;
    height: var(--at-gallery-height, 34rem);
    container-type: size;
    perspective: 900px;
    overflow: hidden;
    border-radius: var(--at-gallery-radius);
    background: var(--at-gallery-tunnel-bg, radial-gradient(circle at 50% 50%, #2a2f3d, #0e1118));
}

.at-gallery--tunnel .at-gallery__item {
    --w: var(--at-gallery-tunnel-w, clamp(8rem, 24cqw, 15rem));
    position: absolute;
    left: 50%;
    top: 50%;
    width: var(--w);
    margin: calc(var(--w) * -.32) 0 0 calc(var(--w) / -2);
    box-shadow: 0 14px 40px rgb(0 0 0 / .45);
    animation: at-tunnel 14s linear infinite;
    animation-delay: var(--d, 0s);
}

.at-gallery--tunnel .at-gallery__img {
    height: auto;
    aspect-ratio: var(--at-gallery-ratio, 16 / 10);
}

@keyframes at-tunnel {
    0% { transform: translate3d(var(--x), var(--y), -2200px); opacity: 0; }
    12% { opacity: 1; }
    88% { opacity: 1; }
    100% { transform: translate3d(calc(var(--x) * 1.9), calc(var(--y) * 1.9), 520px); opacity: 0; }
}

.at-gallery--tunnel[data-go="loop"] .at-gallery__items:is(:hover, :focus-within) .at-gallery__item,
.at-gallery--tunnel.is-off .at-gallery__item {
    animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
    .at-gallery--strips .at-gallery__item,
    .at-gallery--strips .at-gallery__caption,
    .at-gallery--scatter .at-gallery__item { transition: none; }
    .at-gallery--counter .at-gallery__items { height: auto; }
    .at-gallery--tunnel .at-gallery__items {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr));
        gap: var(--at-gallery-gap, 1rem);
        height: auto;
        container-type: normal;
        perspective: none;
        background: none;
    }
    .at-gallery--tunnel .at-gallery__item { position: static; width: auto; margin: 0; animation: none; }
}

/* --------------------------------------------------------------------------
   Lightbox — un <dialog> par page, monté par at-lightbox.js.
   -------------------------------------------------------------------------- */
.at-lightbox {
    --at-lightbox-bg: rgba(10, 12, 16, .92);
    --at-lightbox-fg: #fff;
    /* Retraits de la scène : l'image se borne à l'écran moins ces valeurs. */
    --at-lightbox-pad-x: 4rem;
    --at-lightbox-pad-top: 3.5rem;
    --at-lightbox-pad-bottom: 4rem;
    /* Hauteur d'écran : vh en repli, dvh quand le navigateur le connaît (la
       barre d'adresse mobile ne rogne plus le bas de l'image). */
    --at-lightbox-vh: 100vh;
    border: 0;
    padding: 0;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: var(--at-lightbox-vh);
    max-width: none;
    max-height: var(--at-lightbox-vh);
    overflow: hidden;
    background: transparent;
    color: var(--at-lightbox-fg);
}

@supports (height: 100dvh) {
    .at-lightbox { --at-lightbox-vh: 100dvh; }
}

.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: var(--at-lightbox-pad-top) var(--at-lightbox-pad-x) var(--at-lightbox-pad-bottom);
    box-sizing: border-box;
    overflow: hidden;
}

.at-lightbox__img {
    /* Bornes en unités d'écran plutôt qu'en % : ne dépendent pas de la
       résolution de la hauteur du dialog, l'image tient TOUJOURS dans l'écran. */
    max-width: calc(100vw - 2 * var(--at-lightbox-pad-x));
    max-height: calc(var(--at-lightbox-vh) - var(--at-lightbox-pad-top) - var(--at-lightbox-pad-bottom));
    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;
    /* Zoom (pincement, double-tap) : transform inline posé par le script. */
    transform-origin: center;
    touch-action: none;
    user-select: none;
    -webkit-user-drag: none;
    cursor: zoom-in;
}

.at-lightbox__img.is-animating { transition: transform .25s ease; }
.at-lightbox.is-zoomed .at-lightbox__img { cursor: grab; }
.at-lightbox.is-zoomed .at-lightbox__img:active { cursor: grabbing; }

/* `scale` et non `transform` : l'animation d'entrée (fill both) écraserait
   sinon le transform de zoom posé en inline. */
@keyframes at-lightbox-in {
    from { opacity: 0; scale: .98; }
    to   { opacity: 1; scale: 1; }
}

.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;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .12);
    color: inherit;
    font: inherit;
    line-height: 0;
    cursor: pointer;
    transition: background .15s;
}

.at-lightbox__icon {
    display: block;
    width: 1.375rem;
    height: 1.375rem;
}

.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 { --at-lightbox-pad-x: .5rem; --at-lightbox-pad-top: 3.25rem; --at-lightbox-pad-bottom: 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; }
}
