/*
 * Galerie administrable — Chalet Gruissan
 *
 * Compatible avec le bloc Galerie natif Gutenberg :
 * .wp-block-gallery.has-nested-images
 *
 * Ce fichier gère :
 * - la mosaïque desktop ;
 * - l’affichage tablette et mobile ;
 * - les légendes ;
 * - la lightbox ;
 * - les flèches, miniatures et compteur.
 */

/* =========================================================
   SECTION ET INTRODUCTION
   ========================================================= */

.cg-gallery-section {
  overflow: hidden;
  padding: clamp(54px, 5vw, 76px) 0;
}

.cg-gallery-heading {
  width: min(100%, 820px);
  margin: 0 auto clamp(30px, 4vw, 48px);
  text-align: center;
}

.cg-gallery-heading .eyebrow {
  justify-content: center;
}

.cg-gallery-heading .lead {
  margin-right: auto;
  margin-left: auto;
}

/* =========================================================
   CONTENEUR GUTENBERG
   ========================================================= */

.cg-gallery-editor {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}

/*
 * Les textes Gutenberg éventuellement placés avant ou après
 * la galerie restent dans une largeur de lecture confortable.
 */
.cg-gallery-editor > :not(.wp-block-gallery) {
  width: min(100%, 820px);
  margin-right: auto;
  margin-left: auto;
}

/* =========================================================
   RÉINITIALISATION DU BLOC GALERIE WORDPRESS
   ========================================================= */

.cg-gallery-editor .wp-block-gallery,
.cg-gallery-editor .wp-block-gallery.has-nested-images,
.cg-gallery-editor figure.wp-block-gallery {
  display: grid !important;
  grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
  grid-auto-flow: dense;
  grid-auto-rows: auto;

  gap: 16px !important;

  width: 100% !important;
  max-width: none !important;

  margin: 0 !important;
  padding: 0 !important;

  list-style: none !important;
}

/*
 * Gutenberg impose normalement :
 * width: calc(33.33% - ...)
 * flex-grow: 1
 *
 * Ces règles doivent être totalement neutralisées.
 */
.cg-gallery-editor
  .wp-block-gallery.has-nested-images
  figure.wp-block-image:not(#individual-image),
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image,
.cg-gallery-editor
  .blocks-gallery-grid
  .blocks-gallery-item {
  position: relative !important;

  display: block !important;
  overflow: hidden !important;

  flex: none !important;
  flex-basis: auto !important;
  flex-grow: 0 !important;
  flex-shrink: 0 !important;

  grid-column: span 4;
  grid-row: span 1;

  width: auto !important;
  min-width: 0 !important;
  max-width: none !important;

  height: auto !important;
  min-height: 0 !important;

  margin: 0 !important;
  padding: 0 !important;

  aspect-ratio: 4 / 3;

  background: var(--sand, #f3e8d8);
  border: 0 !important;
  border-radius: 18px;

  box-shadow: 0 12px 34px rgba(20, 50, 63, 0.1);

  cursor: zoom-in;

  isolation: isolate;
}

/* =========================================================
   COMPOSITION DE LA MOSAÏQUE
   ========================================================= */

/* Grandes images panoramiques */
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image:nth-child(10n + 1),
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image:nth-child(10n + 7) {
  grid-column: span 8;
  aspect-ratio: 16 / 9;
}

/* Images verticales contrôlées */
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image:nth-child(10n + 4) {
  grid-column: span 4;
  grid-row: span 2;

  aspect-ratio: auto;
  min-height: 540px !important;
}

/*
 * Évite une dernière ligne avec une seule petite image
 * lorsque le nombre de photos ne remplit pas la grille.
 */
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image:last-child:nth-child(3n + 1) {
  grid-column: span 8;
}

/* =========================================================
   LIENS ET IMAGES
   ========================================================= */

.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image
  > a,
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image
  > div {
  display: block !important;

  width: 100% !important;
  height: 100% !important;

  margin: 0 !important;
  padding: 0 !important;
}

.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image
  img,
.cg-gallery-editor
  .blocks-gallery-grid
  .blocks-gallery-item
  img {
  position: absolute !important;
  inset: 0 !important;

  display: block !important;

  width: 100% !important;
  min-width: 100% !important;
  max-width: none !important;

  height: 100% !important;
  min-height: 100% !important;
  max-height: none !important;

  margin: 0 !important;
  padding: 0 !important;

  aspect-ratio: auto !important;

  object-fit: cover !important;
  object-position: center center;

  border: 0 !important;
  border-radius: 0 !important;

  box-shadow: none !important;

  transform: scale(1);

  transition:
    transform 0.5s ease,
    filter 0.3s ease;
}

/* Zoom discret */
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image:hover
  img,
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image:focus-visible
  img {
  filter: saturate(1.05) contrast(1.02);
  transform: scale(1.045);
}

/* Aucun bandeau ou badge au survol : seul le zoom discret est conservé. */

/* =========================================================
   LÉGENDES
   ========================================================= */

.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image
  figcaption,
.cg-gallery-editor
  .blocks-gallery-grid
  .blocks-gallery-item
  figcaption {
  position: absolute !important;
  right: 0 !important;
  bottom: 0 !important;
  left: 0 !important;
  z-index: 3 !important;

  display: block !important;

  width: 100% !important;
  max-height: none !important;

  margin: 0 !important;
  padding: 55px 18px 17px !important;

  color: #ffffff !important;
  background:
    linear-gradient(
      to bottom,
      transparent,
      rgba(5, 27, 37, 0.82)
    ) !important;

  font-family: var(--font-body, Roboto, Arial, sans-serif);
  font-size: 0.82rem !important;
  font-weight: 600;
  line-height: 1.4;
  text-align: left !important;

  pointer-events: none;
}

/*
 * Gutenberg peut injecter un fond supplémentaire derrière
 * la légende. On le neutralise.
 */
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image
  figcaption::before,
.cg-gallery-editor
  .wp-block-gallery
  figure.wp-block-image
  figcaption::after {
  display: none !important;
  content: none !important;
}

/* =========================================================
   ÉTAT VIDE
   ========================================================= */

.cg-gallery-empty {
  width: min(100%, 760px);

  margin: 0 auto;
  padding: 28px;

  color: var(--navy, #163a4b);
  background: var(--sand-2, #fbf7f0);
  border: 1px dashed rgba(22, 58, 75, 0.28);
  border-radius: 16px;

  text-align: center;
}

/* =========================================================
   LIGHTBOX
   ========================================================= */

body.cg-lightbox-open {
  overflow: hidden;
}

.cg-lightbox,
.cg-lightbox *,
.cg-lightbox *::before,
.cg-lightbox *::after {
  box-sizing: border-box;
}

.cg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;

  display: none;

  grid-template-columns: 70px minmax(0, 1fr) 70px;
  grid-template-rows: 54px minmax(0, 1fr) 68px;

  align-items: center;
  gap: 12px;

  width: 100vw;
  height: 100dvh;

  padding: 12px 22px 14px;

  color: #ffffff;
  background: rgba(5, 22, 30, 0.97);

  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
}

.cg-lightbox.is-open {
  display: grid;
}

/* Barre supérieure */
.cg-lightbox__topbar {
  grid-column: 1 / -1;
  grid-row: 1;

  display: flex;
  align-items: center;
  justify-content: space-between;

  width: 100%;
  min-height: 48px;
}

.cg-lightbox__counter {
  color: rgba(255, 255, 255, 0.8);

  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

/* Boutons */
.cg-lightbox__close,
.cg-lightbox__nav {
  display: grid;
  place-items: center;

  margin: 0;
  padding: 0;

  color: #ffffff;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;

  box-shadow: none;

  cursor: pointer;

  transition:
    background-color 0.2s ease,
    transform 0.2s ease;
}

.cg-lightbox__close:hover,
.cg-lightbox__nav:hover {
  background: rgba(255, 255, 255, 0.19);
  transform: scale(1.05);
}

.cg-lightbox__close {
  width: 46px;
  height: 46px;

  font-size: 1.8rem;
  line-height: 1;
}

.cg-lightbox__nav {
  width: 56px;
  height: 56px;

  justify-self: center;

  font-size: 2.3rem;
  line-height: 1;
}

.cg-lightbox__nav--prev {
  grid-column: 1;
  grid-row: 2;
}

.cg-lightbox__nav--next {
  grid-column: 3;
  grid-row: 2;
}

/* Photo */
.cg-lightbox__figure {
  grid-column: 2;
  grid-row: 2;

  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;

  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;

  margin: 0;
  padding: 0;
}

.cg-lightbox__figure img {
  display: block;

  width: auto;
  max-width: 100%;

  height: auto;
  max-height: calc(100dvh - 190px);

  margin: auto;

  object-fit: contain;

  border-radius: 10px;

  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.38);
}

.cg-lightbox__figure figcaption {
  min-height: 34px;

  margin: 0;
  padding: 10px 18px 0;

  color: rgba(255, 255, 255, 0.82);

  font-size: 0.86rem;
  line-height: 1.4;
  text-align: center;
}

/* Miniatures */
.cg-lightbox__thumbs {
  grid-column: 1 / -1;
  grid-row: 3;

  display: flex;
  align-items: center;
  gap: 8px;

  overflow-x: auto;
  overflow-y: hidden;

  width: 100%;
  height: 62px;

  margin: 0;
  padding: 4px 0;

  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  scrollbar-width: thin;
}

.cg-lightbox__thumb {
  position: relative;

  flex: 0 0 auto;
  overflow: hidden;

  width: 76px;
  height: 54px;

  margin: 0;
  padding: 0;

  background: transparent;
  border: 2px solid transparent;
  border-radius: 7px;

  opacity: 0.48;

  cursor: pointer;

  transition:
    opacity 0.2s ease,
    border-color 0.2s ease,
    transform 0.2s ease;
}

.cg-lightbox__thumb:hover {
  opacity: 0.8;
}

.cg-lightbox__thumb.is-active {
  border-color: #df7657;
  opacity: 1;
  transform: translateY(-2px);
}

.cg-lightbox__thumb img {
  display: block;

  width: 100%;
  height: 100%;

  object-fit: cover;
}

/* =========================================================
   TABLETTE
   ========================================================= */

@media (max-width: 980px) {
  .cg-gallery-editor .wp-block-gallery,
  .cg-gallery-editor .wp-block-gallery.has-nested-images {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image,
  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image:nth-child(n) {
    grid-column: span 1;
    grid-row: auto;

    min-height: 0 !important;

    aspect-ratio: 4 / 3;
  }

  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image:nth-child(5n + 1) {
    grid-column: 1 / -1;

    aspect-ratio: 16 / 9;
  }

  .cg-lightbox {
    grid-template-columns: 58px minmax(0, 1fr) 58px;
    padding-right: 14px;
    padding-left: 14px;
  }

  .cg-lightbox__nav {
    width: 48px;
    height: 48px;
  }
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 680px) {
  .cg-gallery-section {
    padding: 42px 0;
  }

  .cg-gallery-heading {
    margin-bottom: 26px;
  }

  .cg-gallery-editor .wp-block-gallery,
  .cg-gallery-editor .wp-block-gallery.has-nested-images {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image,
  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image:nth-child(n) {
    grid-column: auto;
    grid-row: auto;

    width: 100% !important;
    min-height: 0 !important;

    aspect-ratio: 4 / 3;

    border-radius: 14px;
  }

  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image:nth-child(4n + 1) {
    aspect-ratio: 16 / 10;
  }

  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image::before {
    display: none;
  }

  .cg-lightbox {
    grid-template-columns: 1fr;
    grid-template-rows: 50px minmax(0, 1fr) 58px;

    gap: 6px;

    padding: 8px 10px 10px;
  }

  .cg-lightbox__topbar {
    grid-column: 1;
    grid-row: 1;
  }

  .cg-lightbox__figure {
    grid-column: 1;
    grid-row: 2;
  }

  .cg-lightbox__figure img {
    max-height: calc(100dvh - 155px);
    border-radius: 7px;
  }

  .cg-lightbox__nav {
    position: fixed;
    top: 50%;
    z-index: 3;

    width: 44px;
    height: 44px;

    background: rgba(5, 22, 30, 0.72);

    font-size: 1.9rem;

    transform: translateY(-50%);
  }

  .cg-lightbox__nav:hover {
    transform: translateY(-50%) scale(1.05);
  }

  .cg-lightbox__nav--prev {
    left: 8px;
  }

  .cg-lightbox__nav--next {
    right: 8px;
  }

  .cg-lightbox__thumbs {
    grid-column: 1;
    grid-row: 3;

    height: 56px;
  }

  .cg-lightbox__thumb {
    width: 66px;
    height: 48px;
  }

  .cg-lightbox__figure figcaption {
    padding-top: 8px;
    font-size: 0.78rem;
  }
}

/* =========================================================
   ACCESSIBILITÉ
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image
    img,
  .cg-gallery-editor
    .wp-block-gallery
    figure.wp-block-image::before,
  .cg-lightbox__close,
  .cg-lightbox__nav,
  .cg-lightbox__thumb {
    transition: none;
  }
}

.cg-gallery-editor .wp-block-gallery figure.wp-block-image::before {
  display: none !important;
  content: none !important;
}

.cg-gallery-editor figcaption.cg-gallery-caption--generic {
  display: none !important;
}

/* =========================================================
   PLUGIN — grille, filtres, visite
   ========================================================= */

.cgg-gallery {
  width: 100%;
}

.cgg-gallery__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px 20px;
  margin: 0 0 28px;
}

.cgg-gallery__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 1 1 auto;
}

.cgg-filter {
  min-height: 42px;
  padding: 0 16px;
  color: #163a4b;
  background: #fff;
  border: 1px solid rgba(22, 58, 75, 0.14);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.cgg-filter:hover {
  border-color: rgba(221, 118, 85, 0.55);
  color: #c96042;
}

.cgg-filter.is-active {
  color: #fff;
  background: #dd7655;
  border-color: #dd7655;
}

.cgg-tour-btn {
  flex: 0 0 auto;
  margin-left: auto;
}

.cgg-gallery__grid {
  display: grid !important;
  grid-template-columns: repeat(12, minmax(0, 1fr)) !important;
  grid-auto-flow: dense;
  gap: 16px !important;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cgg-gallery__item {
  position: relative !important;
  display: block !important;
  overflow: hidden !important;
  grid-column: span 4;
  aspect-ratio: 4 / 3;
  margin: 0 !important;
  background: #f3e8d8;
  border-radius: 18px;
  box-shadow: 0 12px 34px rgba(20, 50, 63, 0.1);
  cursor: zoom-in;
  isolation: isolate;
}

.cgg-gallery__item--wide {
  grid-column: span 8;
  aspect-ratio: 16 / 10;
}

.cgg-gallery__item--tall {
  grid-column: span 4;
  aspect-ratio: 3 / 4;
  min-height: 0;
}

.cgg-gallery__item.is-hidden {
  display: none !important;
}

.cgg-gallery__item img {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  object-position: center center;
  transition: transform 0.5s ease, filter 0.3s ease;
}

.cgg-gallery__item:hover img,
.cgg-gallery__item:focus-visible img {
  filter: saturate(1.05) contrast(1.02);
  transform: scale(1.045);
}

/* Pas de titres / légendes visibles sur la grille */
.cgg-gallery__item figcaption {
  display: none !important;
}

.cg-lightbox__mode {
  margin-right: 12px;
  color: #dd7655;
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.cgg-gallery__empty-filter {
  margin: 24px 0 0;
  text-align: center;
  color: #62747c;
}

@media (max-width: 900px) {
  .cgg-gallery__grid {
    grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
  }

  .cgg-gallery__item,
  .cgg-gallery__item--wide,
  .cgg-gallery__item--tall {
    grid-column: span 3;
    grid-row: span 1;
    min-height: 0;
    aspect-ratio: 4 / 3;
  }

  .cgg-tour-btn {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 640px) {
  .cgg-gallery__item,
  .cgg-gallery__item--wide,
  .cgg-gallery__item--tall {
    grid-column: span 6;
    aspect-ratio: 4 / 3;
  }
}
