/* =========================================================
   IMAGE GALLERY COMPONENT
   ========================================================= */

.image-gallery {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.image-gallery__link {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}

.image-gallery > img,
.image-gallery__link img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  cursor: zoom-in;
  transition: transform 0.25s ease;
}

.image-gallery__link:hover img,
.image-gallery__link:focus-visible img {
  transform: scale(1.03);
}

/* Tablet */
@media (max-width: 900px) {
  .image-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Mobile */
@media (max-width: 600px) {
  .image-gallery {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

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

.gallery-lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  border: 0;
  box-sizing: border-box;
  color: #fff;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(0, 0, 0, 0.9);
}

.gallery-lightbox[open] {
  display: flex;
}

.gallery-lightbox__content {
  max-width: min(92vw, 1400px);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.gallery-lightbox__image {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  width: auto;
  height: auto;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  touch-action: pan-y;
}

.gallery-lightbox__caption {
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: center;
  min-height: 1.4em;
  max-width: 90%;
}

/* Navigation */
.gallery-lightbox__nav,
.gallery-lightbox__close {
  position: absolute;
  border: 0;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  cursor: pointer;
  transition:
    background 0.2s ease,
    transform 0.2s ease;
}

.gallery-lightbox__nav:hover,
.gallery-lightbox__close:hover,
.gallery-lightbox__nav:focus-visible,
.gallery-lightbox__close:focus-visible {
  background: rgba(255, 255, 255, 0.24);
}

.gallery-lightbox__close {
  top: 1rem;
  right: 1rem;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  font-size: 2rem;
  line-height: 1;
}

.gallery-lightbox__nav {
  top: 50%;
  transform: translateY(-50%);
  width: 3.25rem;
  height: 3.25rem;
  border-radius: 50%;
  font-size: 2rem;
  line-height: 1;
}

.gallery-lightbox__nav--prev {
  left: 1rem;
}

.gallery-lightbox__nav--next {
  right: 1rem;
}

/* Thumbnail strip */
.gallery-lightbox__thumbs {
  display: flex;
  gap: 0.75rem;
  max-width: 100%;
  overflow-x: auto;
  padding: 0.25rem 0 0.5rem;
  scrollbar-width: thin;
}

.gallery-lightbox__thumbs::-webkit-scrollbar {
  height: 8px;
}

.gallery-lightbox__thumbs::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.35);
  border-radius: 999px;
}

.gallery-lightbox__thumb {
  flex: 0 0 auto;
  width: 88px;
  height: 58px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  background: transparent;
  cursor: pointer;
  opacity: 0.72;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease,
    border-color 0.2s ease;
}

.gallery-lightbox__thumb:hover,
.gallery-lightbox__thumb:focus-visible {
  opacity: 1;
  transform: translateY(-1px);
}

.gallery-lightbox__thumb.is-active {
  opacity: 1;
  border-color: #fff;
}

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

/* Mobile improvements */
@media (max-width: 767px) {
  .gallery-lightbox {
    padding: 0.75rem;
  }

  .gallery-lightbox__content {
    width: 100%;
    gap: 0.75rem;
  }

  .gallery-lightbox__image {
    max-height: 62vh;
  }

  .gallery-lightbox__thumb {
    width: 72px;
    height: 48px;
  }

  .gallery-lightbox__nav {
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.6rem;
  }

  .gallery-lightbox__nav--prev {
    left: 0.5rem;
  }

  .gallery-lightbox__nav--next {
    right: 0.5rem;
  }

  .gallery-lightbox__close {
    top: 0.5rem;
    right: 0.5rem;
    width: 2.75rem;
    height: 2.75rem;
    font-size: 1.8rem;
  }
}

/* Gallery Lightbox 2.0 */
.gallery-lightbox::backdrop {
  background: transparent;
}
.gallery-lightbox__content {
  min-width: 0;
  width: min(80vw, 1400px);
}
.gallery-lightbox__image {
  max-height: 65vh;
  max-height: 65dvh;
  object-fit: contain;
}
.gallery-lightbox__nav,
.gallery-lightbox__close {
  z-index: 1;
}
.gallery-lightbox button[hidden] {
  display: none;
}
.gallery-lightbox button:focus-visible,
.image-gallery__link:focus-visible {
  outline: 3px solid #77a1c1;
  outline-offset: 3px;
}
.image-gallery > p,
.image-gallery > figure {
  margin: 0;
  min-width: 0;
}
@media (max-width: 767px) {
  .gallery-lightbox__content {
    width: 100%;
  }
  .gallery-lightbox__image {
    max-height: 58vh;
    max-height: 58dvh;
  }
}
@media (prefers-reduced-motion: reduce) {
  .image-gallery__link img,
  .gallery-lightbox button {
    transition: none;
  }
}

@media (max-width: 600px) {
  .image-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }
}
