/**
 * Composant : galerie « grande image + miniatures ».
 *
 * Markup : template-parts/components/thumb-gallery.php
 * JS     : assets/js/thumb-gallery.js
 * La lightbox réutilise .school-lightbox* (components/school-gallery.css),
 * à charger aussi sur la page.
 *
 * Couleur d'accent : --kc-school-color si le parent la définit (KidsClub).
 */

.thumb-gallery {
  --tg-accent: var(--kc-school-color, #009c8e);
}

/* Grande image */
.thumb-gallery__stage {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 24px;
  overflow: hidden;
  background: #0a0f19;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.10);
}

.thumb-gallery__zoom {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: none;
  cursor: zoom-in;
  -webkit-appearance: none;
  appearance: none;
}

.thumb-gallery__zoom img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Photo portrait dans un cadre 4:3 : on comble avec une copie floutée plutôt
   que des bandes noires (même principe que « Vie de l'établissement »). */
.thumb-gallery__backdrop {
  object-fit: cover;
  filter: blur(26px) brightness(0.62) saturate(1.1);
  transform: scale(1.2);
  pointer-events: none;
}

.thumb-gallery__image {
  object-fit: contain;
  transition: opacity 0.25s ease;
}

.thumb-gallery__image.is-loading {
  opacity: 0.35;
}

.thumb-gallery__zoom-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.92);
  color: #1f2a44;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.thumb-gallery__zoom:hover .thumb-gallery__zoom-icon,
.thumb-gallery__zoom:focus-visible .thumb-gallery__zoom-icon {
  opacity: 1;
}

.thumb-gallery__zoom:focus-visible {
  outline: 3px solid var(--tg-accent);
  outline-offset: -3px;
}

/* Flèches sur la grande image */
.thumb-gallery__nav {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 42px;
  height: 42px;
  min-width: 42px;
  padding: 0;
  aspect-ratio: 1 / 1;
  border: 1.5px solid rgba(31, 42, 68, 0.14);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
  color: #1f2a44;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transform: translateY(-50%);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  transition: border-color 0.2s ease, color 0.2s ease;
}

.thumb-gallery__nav svg {
  display: block;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.thumb-gallery__nav:hover {
  border-color: var(--tg-accent);
  color: var(--tg-accent);
}

.thumb-gallery__nav:focus-visible {
  outline: 2px solid var(--tg-accent);
  outline-offset: 3px;
}

.thumb-gallery__nav--prev { left: 14px; }
.thumb-gallery__nav--next { right: 14px; }

.thumb-gallery__counter {
  position: absolute;
  bottom: 12px;
  left: 50%;
  z-index: 2;
  margin: 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(10, 15, 25, 0.6);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%);
  pointer-events: none;
}

/* Miniatures */
.thumb-gallery__thumbs {
  display: flex;
  gap: 10px;
  margin: 12px 0 0;
  padding: 4px 2px;
  list-style: none;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  scrollbar-width: thin;
}

.thumb-gallery__thumbs li {
  flex: 0 0 auto;
  margin: 0;
  scroll-snap-align: start;
}

.thumb-gallery__thumb {
  display: block;
  width: 84px;
  height: 64px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  background: #e5e7eb;
  cursor: pointer;
  opacity: 0.6;
  -webkit-appearance: none;
  appearance: none;
  transition: opacity 0.2s ease, border-color 0.2s ease;
}

.thumb-gallery__thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-gallery__thumb:hover {
  opacity: 0.9;
}

.thumb-gallery__thumb.is-active {
  border-color: var(--tg-accent);
  opacity: 1;
}

.thumb-gallery__thumb:focus-visible {
  outline: 2px solid var(--tg-accent);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  .thumb-gallery__stage { border-radius: 16px; }
  .thumb-gallery__nav { width: 36px; height: 36px; min-width: 36px; }
  .thumb-gallery__nav--prev { left: 8px; }
  .thumb-gallery__nav--next { right: 8px; }
  .thumb-gallery__thumb { width: 64px; height: 48px; }
  /* Pas de survol au doigt : l'icône plein écran reste visible */
  .thumb-gallery__zoom-icon { opacity: 1; width: 32px; height: 32px; top: 10px; right: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .thumb-gallery__image,
  .thumb-gallery__thumb,
  .thumb-gallery__zoom-icon {
    transition: none;
  }
}
