/*
 * PREMIUM GALLERY LIGHTBOX
 * Click to enlarge, swipe to navigate, mobile-optimized
 */

/* ===== LIGHTBOX OVERLAY - MOBILE FIRST ===== */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile */
  background: rgba(0, 0, 0, 0.96);
  z-index: 999999; /* CRITICAL: Above everything */
  display: none;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; /* Prevent pull-to-refresh breaking layout */
}

.lightbox-overlay.active {
  display: flex;
}

/* ===== LIGHTBOX CONTAINER - MOBILE FIRST ===== */
.lightbox-container {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

/* ===== LIGHTBOX IMAGE - MOBILE OPTIMIZED ===== */
.lightbox-image {
  max-width: 100vw;
  max-height: 100vh;
  max-height: 100dvh; /* Dynamic viewport */
  width: auto;
  height: auto;
  object-fit: contain;
  animation: zoomIn 0.3s ease;
  touch-action: pan-x pan-y pinch-zoom; /* Allow touch gestures */
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
  transform: translateZ(0); /* GPU acceleration */
  -webkit-transform: translateZ(0);
}

@keyframes zoomIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ===== CLOSE BUTTON - MOBILE FIRST ===== */
.lightbox-close {
  position: fixed;
  top: env(safe-area-inset-top, 10px); /* iOS notch support */
  right: env(safe-area-inset-right, 10px);
  width: 48px;
  height: 48px;
  min-width: 48px; /* WCAG touch target */
  min-height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: white;
  font-size: 1.8rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 1000001;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.lightbox-close:active {
  background: rgba(255, 0, 0, 0.4);
  transform: scale(0.9);
}

@media (hover: hover) {
  .lightbox-close:hover {
    background: rgba(255, 0, 0, 0.3);
    border-color: rgba(255, 0, 0, 0.5);
    transform: rotate(90deg) scale(1.1);
  }
}

/* ===== NAVIGATION ARROWS - MOBILE FIRST ===== */
.lightbox-prev,
.lightbox-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.25);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  z-index: 1000001;
  pointer-events: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.8;
}

.lightbox-prev {
  left: env(safe-area-inset-left, 10px);
}

.lightbox-next {
  right: env(safe-area-inset-right, 10px);
}

.lightbox-prev:active,
.lightbox-next:active {
  transform: translateY(-50%) scale(0.88);
  background: rgba(255, 255, 255, 0.25);
}

@media (hover: hover) {
  .lightbox-prev:hover,
  .lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-50%) scale(1.1);
    opacity: 1;
  }
}

/* Hide arrows when at start/end */
.lightbox-prev.disabled,
.lightbox-next.disabled {
  opacity: 0.3;
  pointer-events: none;
}

/* ===== IMAGE COUNTER ===== */
.lightbox-counter {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 50px;
  font-size: 1rem;
  font-weight: 600;
  z-index: 10001;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ===== IMAGE CAPTION ===== */
.lightbox-caption {
  position: fixed;
  bottom: 5rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: white;
  padding: 1rem 2rem;
  border-radius: 12px;
  font-size: 1rem;
  max-width: 600px;
  text-align: center;
  z-index: 10001;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: none;
}

.lightbox-caption.show {
  display: block;
}

/* ===== LOADING INDICATOR ===== */
.lightbox-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 60px;
  height: 60px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  z-index: 10000;
  display: none;
}

.lightbox-loading.show {
  display: block;
}

@keyframes spin {
  to {
    transform: translate(-50%, -50%) rotate(360deg);
  }
}

/* ===== MOBILE OPTIMIZATIONS - CRITICAL ===== */
@media (max-width: 768px) {
  .lightbox-overlay {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport - prevents address bar issues */
  }
  
  .lightbox-container {
    padding: 0;
  }

  .lightbox-image {
    max-width: 100vw;
    max-height: 100vh;
    max-height: 100dvh;
    width: 100%;
    height: auto;
    padding: 0;
  }

  .lightbox-close {
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.6rem;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.4);
  }

  .lightbox-prev,
  .lightbox-next {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.4rem;
    background: rgba(0, 0, 0, 0.6);
  }

  .lightbox-prev {
    left: 8px;
  }

  .lightbox-next {
    right: 8px;
  }

  .lightbox-counter {
    bottom: env(safe-area-inset-bottom, 12px);
    padding: 8px 16px;
    font-size: 0.9rem;
    background: rgba(0, 0, 0, 0.8);
  }

  .lightbox-caption {
    bottom: calc(env(safe-area-inset-bottom, 12px) + 50px);
    padding: 10px 16px;
    font-size: 0.85rem;
    max-width: calc(100vw - 24px);
  }

  /* Hide keyboard hint on mobile */
  .keyboard-hint {
    display: none !important;
  }
}

/* ===== SWIPE INDICATOR (MOBILE) ===== */
.swipe-hint {
  position: fixed;
  bottom: 6rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.85rem;
  animation: fadeOut 3s forwards;
  z-index: 10001;
  pointer-events: none;
}

@keyframes fadeOut {
  0% {
    opacity: 1;
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (min-width: 769px) {
  .swipe-hint {
    display: none;
  }
}

/* ===== CLICKABLE GALLERY IMAGES ===== */
.gallery-grid img {
  cursor: pointer;
  transition: all 0.3s ease;
}

.gallery-grid img:hover {
  transform: scale(1.05);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.gallery-grid img:active {
  transform: scale(0.98);
}

/* ===== PREVENT BODY SCROLL - MOBILE CRITICAL ===== */
body.lightbox-open {
  overflow: hidden !important;
  position: fixed !important; /* Prevents iOS Safari scroll issues */
  width: 100% !important;
  height: 100% !important;
  touch-action: none !important; /* Prevent pull-to-refresh */
  overscroll-behavior: contain !important;
}

/* ===== SMOOTH TRANSITIONS ===== */
.lightbox-image {
  transition: opacity 0.3s ease;
}

.lightbox-image.changing {
  opacity: 0.5;
}

/* ===== KEYBOARD HINT ===== */
.keyboard-hint {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.85rem;
  z-index: 10001;
  animation: fadeOut 4s forwards;
  pointer-events: none;
  display: none;
}

@media (min-width: 769px) {
  .keyboard-hint {
    display: block;
  }
}

/* ===== ACCESSIBILITY ===== */
.lightbox-overlay:focus {
  outline: none;
}

.lightbox-close:focus,
.lightbox-prev:focus,
.lightbox-next:focus {
  outline: 2px solid white;
  outline-offset: 2px;
}

/* ===== TOUCH FEEDBACK ===== */
@media (max-width: 768px) {
  .lightbox-prev:active,
  .lightbox-next:active {
    background: rgba(255, 255, 255, 0.3);
  }
}

/* ===== ZOOM SUPPORT (DOUBLE TAP/PINCH) ===== */
.lightbox-image.zoomed {
  max-width: none;
  max-height: none;
  width: 150%;
  cursor: move;
}

/* ===== PERFORMANCE ===== */
.lightbox-overlay,
.lightbox-image {
  will-change: transform, opacity;
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
