/* =========================================
   GALLERY — Carousel + Lightbox
   ========================================= */

/* ── Grille principale ── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  width: 100%;
}

/* ── En-tête événement ── */
.gallery-event-header {
  grid-column: 1 / -1;
  padding: 2.5rem var(--space-md) 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.gallery-event-header:first-child {
  border-top: none;
  padding-top: 1rem;
}

.gallery-event-label {
  font-size: var(--text-label);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--color-brand);
  font-weight: 600;
}

/* ── Carousel wrapper (span pleine largeur) ── */
.gallery-carousel-wrapper {
  grid-column: 1 / -1;
}

/* Track : même grille 4 colonnes que la galerie principale */
.gallery-carousel-track {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

/* ── Items ── */
.gallery-item {
  overflow: hidden;
  aspect-ratio: 4 / 3;
  cursor: pointer;
  position: relative;
  background: rgba(255, 255, 255, 0.03);
  /* Scroll-reveal / swap de page : démarre invisible */
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity   0.45s ease                            calc(var(--col, 0) * 55ms),
    transform 0.5s  cubic-bezier(0.16, 1, 0.3, 1)  calc(var(--col, 0) * 55ms);
}

.gallery-item.is-visible {
  opacity: 1;
  transform: none;
}

.gallery-item.is-panorama {
  grid-column: span 2;
  aspect-ratio: 8 / 3;
}

/* ── Placeholder + spinner (item visible mais image pas encore chargée) ── */
.gallery-item.is-visible:not(.img-ready) {
  /* Fond statique — pas d'animation background pour éviter le flickering GPU */
  background: rgba(168, 230, 255, 0.05);
}

.gallery-item.is-visible:not(.img-ready)::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 1.5px solid rgba(255, 255, 255, 0.12);
  border-top-color: rgba(168, 230, 255, 0.7);
  border-radius: 50%;
  animation: gallery-spin 0.75s linear infinite;
  z-index: 1;
  pointer-events: none;
}

.gallery-item.img-ready {
  background: transparent;
}

@keyframes gallery-spin {
  to { transform: rotate(360deg); }
}

/* ── Image ── */
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transform: scale(1);
  transition: opacity 0.4s ease, transform 0.65s cubic-bezier(0.16, 1, 0.3, 1);
}

.gallery-item img.loaded {
  opacity: 1;
}

.gallery-item:hover img {
  transform: scale(1.04);
}

/* ── Navigation carousel ── */
.gallery-carousel-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.8rem;
  padding: 1.4rem 0 0.5rem;
}

.carousel-btn {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: transparent;
  color: rgba(255, 255, 255, 0.4);
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.22s ease, color 0.22s ease, background 0.22s ease;
}

.carousel-btn:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.45);
  color: var(--color-white);
  background: rgba(255, 255, 255, 0.05);
}

.carousel-btn:disabled {
  opacity: 0.2;
  cursor: default;
  pointer-events: none;
}

.carousel-counter {
  font-size: 0.65rem;
  letter-spacing: 0.24em;
  color: rgba(255, 255, 255, 0.28);
  text-transform: uppercase;
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ── Lightbox ── */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: var(--z-lightbox);
  background: rgba(0, 5, 15, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
}

#lightbox.active {
  opacity: 1;
  visibility: visible;
}

#lightbox-img {
  max-width: 90vw;
  max-height: 88vh;
  object-fit: contain;
  display: block;
  border-radius: 2px;
  user-select: none;
  transition: opacity 0.22s ease;
}

#lightbox-close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  color: rgba(255, 255, 255, 0.55);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  transition: background 0.2s ease, color 0.2s ease;
}

#lightbox-close:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--color-white);
}

#lightbox-prev,
#lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.45);
  font-size: 3.5rem;
  font-weight: 200;
  line-height: 1;
  padding: var(--space-sm) var(--space-md);
  transition: color 0.2s ease;
  user-select: none;
}

#lightbox-prev { left: 0; }
#lightbox-next { right: 0; }

#lightbox-prev:hover,
#lightbox-next:hover {
  color: var(--color-white);
}

#lightbox-counter {
  position: absolute;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.28);
  text-transform: uppercase;
  pointer-events: none;
  user-select: none;
}

/* ── Mobile ── */
@media (max-width: 767px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
  }

  .gallery-carousel-track {
    grid-template-columns: repeat(2, 1fr);
    gap: 2px;
  }

  .gallery-item.is-panorama {
    grid-column: span 2;
    aspect-ratio: 16 / 6;
  }

  .gallery-carousel-nav {
    gap: 1.2rem;
    padding: 1rem 0 0.5rem;
  }

  #lightbox-prev,
  #lightbox-next {
    font-size: 2.5rem;
    padding: var(--space-xs) 0.8rem;
  }
}
