.cwp-gallery {
    max-width: 1500px;
    margin: auto;
    padding: 40px 20px;
    /* Conteneur de requête : donne à la grille une unité (cqw) pour déduire la
       largeur d'une colonne, et donc fixer une hauteur de rangée constante.
       Sans danger ici : la lightbox (.image-modal, en position fixed) vit dans
       footer.php, hors de ce conteneur. */
    container-type: inline-size;
}

/* Navigation header */
.section--navigation .container--filters {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.cwp-gallery__header {
    width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.cwp-gallery__header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.cwp-gallery__advanced-btn {
    color: var(--color-text);
    text-decoration: underline;
    border: none;
    background: none;
    font-size: 14px;
    cursor: pointer;
}

.cwp-gallery__advanced {
    width: 100%;
    padding: 0 16px;
    margin: 0 auto;
}

.cwp-gallery__filters {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.cwp-gallery__filter {
    width: 100%;
}

.cwp-gallery__filter-title {
    font-weight: 600;
    margin-bottom: 10px;
}

.cwp-gallery__tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* Tags */
.cwp-tag {
    padding: 7px 10px;
    border-radius: 999px;
    border: 1px solid #ddd;
    background: #fff;
    font-size: 13px;
    cursor: pointer;
    transition: all .2s ease;
}

.cwp-tag:hover {
    border-color: #000;
}

.cwp-tag.is-active {
    border-color: #000;
    background: #000;
    color: #fff;
}

/* Actions */
.cwp-gallery__actions {
    width: 100%;
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

.cwp-gallery__reset {
    border: none;
    background: transparent;
    text-decoration: underline;
    cursor: pointer;
    opacity: .8;
}

/* Search */
.cwp-gallery__search {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #ddd;
    min-width: 400px;
}

/* Grid
 *
 * Les rangées sont FIXÉES, pas laissées en `auto`. En auto, la hauteur d'une
 * rangée dépend de ce qu'elle contient : une rangée qui ne reçoit que la moitié
 * d'une tuile à cheval (portrait ou grande tuile), sans aucune tuile d'une
 * seule ligne pour la caler, se retrouvait 5 à 10 px plus courte que ses
 * voisines. D'où un rythme vertical irrégulier alors que la gouttière, elle,
 * valait bien 10 px partout.
 *
 * On déduit donc la largeur d'une colonne du conteneur (--col), et une rangée
 * vaut la hauteur d'une tuile paysage 3:2, soit --col × 2/3. Toutes les rangées
 * deviennent identiques.
 *
 * Repli : si les unités de conteneur ne sont pas comprises, grid-auto-rows est
 * ignoré, les rangées repassent en auto et l'aspect-ratio des tuiles reprend la
 * main — l'ancien comportement. */
.cwp-gallery__grid {
    --gap: 10px;
    --col: calc((100cqw - 2 * var(--gap)) / 3);

    display: grid;
    gap: var(--gap);
    grid-auto-flow: dense;
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: calc(var(--col) * 2 / 3);
}

/* Item
 *
 * L'aspect-ratio sert au DIMENSIONNEMENT DES RANGÉES : c'est lui qui donne à la
 * grille la hauteur intrinsèque d'une tuile (w × 2/3 pour une colonne).
 *
 * `width` et `height` à 100% servent à REMPLIR l'emplacement une fois les
 * rangées calculées. Il faut IMPÉRATIVEMENT les deux : un aspect-ratio prime
 * sur l'étirement par défaut de la grille, donc dès qu'une seule dimension est
 * définie, le navigateur déduit l'autre du ratio au lieu de suivre la grille.
 *
 * Sans `height`, une tuile sur 2 rangées était trop courte d'une gouttière :
 * emplacement `2 × 0,667w + 10px`, ratio `1,333w`. Son bas se désalignait.
 *
 * Sans `width`, une grande tuile (2 colonnes) devenait trop LARGE : hauteur
 * définie à 650 px, donc largeur déduite à `650 × 36/24 = 975px` pour un
 * emplacement de 970 px. Les 5 px de débordement rognaient la gouttière la
 * séparant de la colonne voisine, qui paraissait deux fois plus fine.
 *
 * Pour une tuile d'une seule rangée, ratio et emplacement coïncident : aucun
 * effet. L'aspect-ratio ne sert donc plus qu'au repli sans unités de conteneur. */
.cwp-gallery__item {
    position: relative;
    overflow: hidden;
    aspect-ratio: 36 / 24;
    width: 100%;
    height: 100%;
    cursor: zoom-in;
}
.cwp-gallery__item .cwp-gallery__media{
      width: 100%;
    height: 100%;
}
/* Image */
.cwp-gallery__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}


/* Overlay Hover ✨ */
.cwp-gallery__overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    /* Sans gap, un titre long vient coller le bouton : space-between ne réserve
       aucun écart dès que les deux éléments remplissent la ligne. */
    gap: 10px;
    padding: 12px;

    background: linear-gradient(
        to top,
        rgba(0,0,0,0.55) 0%,
        rgba(0,0,0,0.15) 35%,
        rgba(0,0,0,0) 60%
    );

    opacity: 0;
    transition: opacity .25s ease;
}

.cwp-gallery__item:hover .cwp-gallery__overlay {
    opacity: 1;
}

/* Title
 * min-width: 0 est la clé : par défaut un élément flex ne peut pas rétrécir en
 * dessous de sa taille min-content. Un titre long refusait donc de se replier,
 * poussait le bouton et le forçait à passer sur deux lignes. Avec min-width: 0
 * c'est le titre qui cède, comme il doit.
 *
 * Le titre est en plus limité à 3 lignes : une légende très longue remplirait
 * sinon toute la tuile et masquerait l'image sous le dégradé. */
.cwp-gallery__title {
    min-width: 0;
    color: #fff;
    font-size: 14px;
    line-height: 1.4;
    text-shadow: 0 2px 12px rgba(0,0,0,.6);
    padding: 4px 8px;
    transform: translateY(6px);
    transition: transform .25s ease;

    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    overflow: hidden;
}

.cwp-gallery__item:hover .cwp-gallery__title {
    transform: translateY(0);
}

/* Link Button
 * Le bouton est prioritaire : il ne rétrécit jamais (flex: 0 0 auto) et son
 * libellé ne se coupe jamais (white-space: nowrap). C'est le titre qui s'adapte
 * à la place restante. */
.cwp-gallery__link {
    align-self: flex-end;
    flex: 0 0 auto;
    white-space: nowrap;

    font-size: 13px;
    padding: 6px 12px;
    border-radius: 999px;

    background: rgba(255,255,255,0.9);
    color: #000;
    text-decoration: none;
    font-weight: 500;

    opacity: 0;
    transform: translateY(4px);

    transition: all .25s ease;
}

.cwp-gallery__item:hover .cwp-gallery__link {
    opacity: 1;
    transform: translateY(0);
}

.cwp-gallery__link:hover {
    background: var(--color-bold);
    color:var(--color-white);
    text-decoration: none;
}

/* Tile sizes */
.cwp-tile--sm { grid-column: span 1; grid-row: span 1; }
.cwp-tile--lg { grid-column: span 2; grid-row: span 2; }

/* Tuile portrait : 1 colonne sur 2 rangées, soit exactement la hauteur d'une
 * grande tuile — la mosaïque reste alignée.
 *
 * L'aspect-ratio ne sert qu'à dimensionner les rangées quand une bande ne
 * contient que des portraits : sans tuile paysage pour fixer la hauteur, c'est
 * lui qui prend le relais. Le remplissage effectif de l'emplacement vient du
 * `height: 100%` posé sur .cwp-gallery__item (voir le commentaire là-bas). */
.cwp-tile--portrait {
    grid-column: span 1;
    grid-row: span 2;
    aspect-ratio: 3 / 4;
}

/* Les trous laissés à côté d'un portrait sont rebouchés par les paysages
 * suivants : grid-auto-flow: dense est déjà actif sur la grille. */

/* Sentinel */
.cwp-gallery__sentinel {
    height: 1px;
}

/* Load more */
.cwp-gallery__more {
    margin: 40px auto 0;
    display: block;
    padding: 12px 22px;
    border-radius: 999px;
    border: none;
    background: black;
    color: white;
    cursor: pointer;
    display: none;
}

/* Skeleton */
.cwp-skeleton {
    position: relative;
    overflow: hidden;
    background: #e9e9e9;
}

.cwp-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
        90deg,
        rgba(255,255,255,0) 0%,
        rgba(255,255,255,.55) 50%,
        rgba(255,255,255,0) 100%
    );
    animation: cwpShimmer 1.1s infinite;
}

@keyframes cwpShimmer {
    to { transform: translateX(100%); }
}


.cwp-gallery__empty{
  max-width: 680px;
  margin: 28px auto 0;
  padding: 18px 18px;
  border: 1px solid #e7e7e7;
  border-radius: 14px;
  background: #fff;
  text-align: center;
}
.cwp-gallery__empty-title{
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 6px;
}
.cwp-gallery__empty-text{
  font-size: 14px;
  opacity: .75;
  margin-bottom: 14px;
}
.cwp-gallery__empty-reset{
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  background: #000;
  color: #fff;
  cursor: pointer;
}

/* Responsive
 * À chaque palier, --col doit être recalculé en même temps que le nombre de
 * colonnes : c'est lui qui pilote la hauteur des rangées. */
@media (max-width: 900px) {
    .cwp-gallery__grid {
        --col: calc((100cqw - var(--gap)) / 2);
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .cwp-gallery__header {
        flex-direction: column;
        gap: 16px;
    }

    .cwp-gallery__header-left {
        width: 100%;
    }

    .cwp-gallery__search {
        width: 100%;
        min-width: auto;
    }

    .cwp-gallery__header-right {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        padding: 0 8px;
    }
}

@media (max-width: 520px) {
    .cwp-gallery__grid {
        --col: 100cqw;
        grid-template-columns: 1fr;
    }

    .cwp-tile--lg {
        grid-column: span 1;
        grid-row: span 1;
    }
}

/* Mobile / touch → pas de hover */
@media (hover: none) {
    .cwp-gallery__overlay {
        opacity: 1;
    }

    .cwp-gallery__link {
        opacity: 1;
        transform: none;
    }

    .cwp-gallery__item img {
        transform: none !important;
    }
}