/* ==========================================================================
   GALLERY & LIGHTBOX
   Casale Isidoro
   ========================================================================== */

/* --------------------------------------------------------------------------
   Gallery Grid
   -------------------------------------------------------------------------- */

.gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-xs);
}

/* 2-column on tablet */
@media (min-width: 768px) {
  .gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-sm);
  }
}

/* 3-column on desktop */
@media (min-width: 1024px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-sm);
  }

  /* Masonry-like: span items across rows for visual variety */
  .gallery--masonry {
    grid-auto-rows: 250px;
  }

  .gallery--masonry .gallery__item:nth-child(4n+1) {
    grid-row: span 2;
  }

  .gallery--masonry .gallery__item:nth-child(6n+3) {
    grid-column: span 2;
  }
}

/* Uniform Gallery — all items same aspect ratio, clean grid */
.gallery--uniform .gallery__item::before {
  display: block;
  padding-top: 66.67%; /* 3:2 */
}

.gallery--uniform .gallery__item {
  border-radius: var(--radius-md);
}

/* --------------------------------------------------------------------------
   Gallery Item
   -------------------------------------------------------------------------- */

.gallery__item {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background-color: var(--bg-secondary);
}

.gallery__item::before {
  content: '';
  display: block;
  padding-top: 66.67%; /* 3:2 aspect ratio */
}

.gallery--masonry .gallery__item::before {
  display: none; /* masonry uses grid-auto-rows instead */
}

.gallery--masonry .gallery__item {
  min-height: 0;
}

.gallery__img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-slow);
}

/* Hover overlay */
.gallery__item::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0);
  transition: background var(--transition-base);
  z-index: 1;
  pointer-events: none;
}

.gallery__item:hover .gallery__img {
  transform: scale(1.05);
}

.gallery__item:hover::after {
  background: rgba(0, 0, 0, 0.15);
}

/* --- Gallery Caption (optional) --- */
.gallery__caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-sm) var(--space-md);
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.5));
  color: #FFFFFF;
  font-size: var(--fs-small);
  font-weight: var(--fw-light);
  z-index: 2;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity var(--transition-base),
    transform var(--transition-base);
}

.gallery__item:hover .gallery__caption {
  opacity: 1;
  transform: translateY(0);
}

/* --- Expand Icon --- */
.gallery__expand {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  z-index: 2;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(4px);
  color: #FFFFFF;
  opacity: 0;
  transition:
    opacity var(--transition-base),
    transform var(--transition-base);
}

.gallery__item:hover .gallery__expand {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.gallery__expand-icon {
  width: 20px;
  height: 20px;
}

/* --------------------------------------------------------------------------
   Gallery Filters / Tabs
   -------------------------------------------------------------------------- */

.gallery__filters {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-bottom: var(--space-lg);
}

/* Gallery filter buttons use .filter-pill from main.css */

/* --------------------------------------------------------------------------
   Lightbox
   -------------------------------------------------------------------------- */

.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--transition-base),
    visibility var(--transition-base);
}

.lightbox.is-open {
  opacity: 1;
  visibility: visible;
}

/* Backdrop */
.lightbox__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
}

/* Image Container */
.lightbox__content {
  position: relative;
  z-index: 1;
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox__img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xl);
  animation: lightboxFadeIn var(--transition-base);
}

@keyframes lightboxFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Caption */
.lightbox__caption {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--fs-small);
  font-weight: var(--fw-light);
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
}

/* Close Button */
.lightbox__close {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  z-index: 2;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: var(--radius-full);
  color: #FFFFFF;
  font-size: 1.5rem;
  cursor: pointer;
  transition:
    background-color var(--transition-base),
    transform var(--transition-fast);
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: rotate(90deg);
}

/* Navigation Arrows */
.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 2;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: none;
  border-radius: var(--radius-full);
  color: #FFFFFF;
  font-size: 1.2rem;
  cursor: pointer;
  transition:
    background-color var(--transition-base),
    transform var(--transition-fast);
}

.lightbox__nav:hover {
  background: rgba(255, 255, 255, 0.15);
}

.lightbox__nav--prev {
  left: var(--space-md);
}

.lightbox__nav--prev:hover {
  transform: translateY(-50%) translateX(-2px);
}

.lightbox__nav--next {
  right: var(--space-md);
}

.lightbox__nav--next:hover {
  transform: translateY(-50%) translateX(2px);
}

/* Counter */
.lightbox__counter {
  position: absolute;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: 0.8rem;
  font-weight: var(--fw-light);
  color: rgba(255, 255, 255, 0.5);
  letter-spacing: 0.1em;
}

/* --------------------------------------------------------------------------
   Swiper.js Overrides (if used)
   -------------------------------------------------------------------------- */

.gallery-swiper .swiper-pagination-bullet {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  opacity: 0.4;
  transition: opacity var(--transition-base), background var(--transition-base);
}

.gallery-swiper .swiper-pagination-bullet-active {
  background: var(--accent);
  opacity: 1;
}

.gallery-swiper .swiper-button-prev,
.gallery-swiper .swiper-button-next {
  color: var(--accent);
  width: 44px;
  height: 44px;
}

.gallery-swiper .swiper-button-prev::after,
.gallery-swiper .swiper-button-next::after {
  font-size: 1rem;
}

/* --------------------------------------------------------------------------
   Responsive Lightbox
   -------------------------------------------------------------------------- */

@media (max-width: 767px) {
  .lightbox__nav {
    width: 40px;
    height: 40px;
  }

  .lightbox__nav--prev {
    left: var(--space-xs);
  }

  .lightbox__nav--next {
    right: var(--space-xs);
  }

  .lightbox__close {
    top: var(--space-sm);
    right: var(--space-sm);
    width: 40px;
    height: 40px;
  }
}
