/* ========================================
   AN NHIÊN HOMESTAY — Gallery Section
   PC: 1 large + 4 small (5 ảnh)
   Mobile: 1 large + 2 small (3 ảnh) + Xem tất cả
   ======================================== */

.gallery {
  padding-block: var(--space-3xl);
  background: var(--color-cream);
}

/* ── Gallery Grid: PC layout ── */
.gallery__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: auto auto;
  gap: var(--space-sm);
}

.gallery__item {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
}

/* First image spans 2 cols + 2 rows (large hero) */
.gallery__item:nth-child(1) {
  grid-column: span 2;
  grid-row: span 2;
}

.gallery__image {
  width: 100%;
  height: 100%;
  min-height: 250px;
  object-fit: cover;
  transition: transform var(--duration-slower) var(--ease-smooth);
}

.gallery__item:nth-child(1) .gallery__image {
  min-height: 520px;
}

/* ── Hidden extra images ── */
.gallery__item--hidden {
  display: none;
}

/* ── Hover Overlay ── */
.gallery__overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(28, 23, 18, 0.6) 100%);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-smooth);
  display: flex;
  align-items: flex-end;
  padding: var(--space-md);
}

.gallery__overlay-text {
  color: var(--color-white);
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-wide);
  transform: translateY(10px);
  transition: transform var(--duration-normal) var(--ease-smooth);
}

.gallery__overlay-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--color-white);
  font-size: 1.2rem;
  opacity: 0;
  transition: all var(--duration-normal) var(--ease-smooth);
}

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

.gallery__item:hover .gallery__overlay {
  opacity: 1;
}

.gallery__item:hover .gallery__overlay-text {
  transform: translateY(0);
}

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

/* ── View All Button ── */
.gallery__view-all {
  display: flex;
  justify-content: center;
  margin-top: var(--space-lg);
}

.gallery__view-all-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 36px;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  color: var(--color-brown-dark);
  background: var(--color-white);
  border: 1px solid var(--color-cream-dark);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-smooth);
}

.gallery__view-all-btn:hover {
  background: var(--color-green);
  color: var(--color-white);
  border-color: var(--color-green);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.gallery__view-all-btn svg {
  transition: transform var(--duration-normal) var(--ease-smooth);
}

.gallery__view-all-btn:hover svg {
  transform: translateX(4px);
}

/* When gallery is expanded */
.gallery__grid.expanded .gallery__item--hidden {
  display: block;
  animation: galleryFadeIn 0.5s var(--ease-out) both;
}

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

/* ── Full Gallery Modal ── */
.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--color-cream-light);
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-smooth),
              visibility var(--duration-normal) var(--ease-smooth);
}

.gallery-modal.active {
  opacity: 1;
  visibility: visible;
}

.gallery-modal__header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--color-glass-border);
}

.gallery-modal__title {
  font-family: var(--font-heading);
  font-size: var(--fs-h3);
  color: var(--color-brown-dark);
}

.gallery-modal__close {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-cream);
  border-radius: var(--radius-full);
  font-size: 1.2rem;
  color: var(--color-brown-dark);
  transition: all var(--duration-fast) var(--ease-smooth);
}

.gallery-modal__close:hover {
  background: var(--color-brown-dark);
  color: var(--color-white);
}

.gallery-modal__grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  padding: var(--space-xl) var(--space-lg);
  max-width: 900px;
  margin: 0 auto;
}

.gallery-modal__item {
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0;
  transform: translateY(40px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}

.gallery-modal__item.modal-revealed {
  opacity: 1;
  transform: translateY(0);
}

.gallery-modal__item img {
  width: 100%;
  display: block;
}

.gallery-modal__caption {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-white);
  font-size: var(--fs-small);
  color: var(--color-brown-medium);
}

/* ── Lightbox ── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-modal) + 1);
  background: rgba(10, 8, 6, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--duration-normal) var(--ease-smooth),
              visibility var(--duration-normal) var(--ease-smooth);
}

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

.lightbox__content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  transform: scale(0.9);
  transition: transform var(--duration-normal) var(--ease-out);
}

.lightbox.active .lightbox__content {
  transform: scale(1);
}

.lightbox__image {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-md);
}

.lightbox__close {
  position: absolute;
  top: -50px;
  right: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-white);
  font-size: 1.5rem;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: all var(--duration-fast) var(--ease-smooth);
}

.lightbox__close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-white);
  font-size: 1.5rem;
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: all var(--duration-fast) var(--ease-smooth);
}

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

.lightbox__prev { left: -70px; }
.lightbox__next { right: -70px; }

.lightbox__counter {
  position: absolute;
  bottom: -40px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.5);
  font-size: var(--fs-small);
  letter-spacing: var(--ls-wide);
}

/* ── Tablet ── */
@media (max-width: 1024px) {
  .gallery__grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ── Mobile: 1 large + 2 small = 3 images total ── */
@media (max-width: 768px) {
  .gallery {
    padding-block: var(--space-2xl);
  }

  .gallery__grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto auto;
    gap: 8px;
  }

  /* First item: full width, 1 row */
  .gallery__item:nth-child(1) {
    grid-column: span 2;
    grid-row: span 1;
  }

  .gallery__item:nth-child(1) .gallery__image {
    min-height: 220px;
  }

  .gallery__image {
    min-height: 160px;
  }

  /* Hide items 4, 5 on mobile (show only 1+2+3) */
  .gallery__item:nth-child(n+4):not(.gallery__item--hidden) {
    display: none;
  }

  /* Show them back when expanded */
  .gallery__grid.expanded .gallery__item:nth-child(n+4):not(.gallery__item--hidden) {
    display: block;
    animation: galleryFadeIn 0.5s var(--ease-out) both;
  }

  .lightbox__prev { left: 10px; }
  .lightbox__next { right: 10px; }
  .lightbox__close { top: -40px; }

  .gallery-modal__grid {
    padding: var(--space-md);
    gap: var(--space-md);
  }
}
