/**
 * Nectar Lightbox Gallery - Styles
 * Version: 1.1.0
 */

/* ===============================================
   Grid Layout
   =============================================== */

.nlg-gallery {
  display: grid;
  grid-template-columns: repeat(var(--nlg-cols, 3), 1fr);
  gap: var(--nlg-gap, 16px);
  align-items: start;
  justify-items: stretch;
}

.nlg-item {
  display: block;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  aspect-ratio: var(--nlg-ratio, 1/1);
  height: var(--nlg-max-height, auto);
  width: 100%;
  border-radius: 4px;
  text-decoration: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* When height is set, override aspect-ratio to allow equal heights */
.nlg-gallery.nlg-has-max-height .nlg-item {
  aspect-ratio: auto !important;
  width: 100%;
  height: var(--nlg-max-height) !important;
  min-height: var(--nlg-max-height) !important;
  max-height: var(--nlg-max-height) !important;
}

.nlg-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}

.nlg-item:hover img {
  transform: scale(1.04);
}

/* ===============================================
   Captions (Grid View)
   =============================================== */

.nlg-caption {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  font-size: 14px;
  color: #fff;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  line-height: 1.4;
  pointer-events: none;
}

/* Visually hidden / screen reader only */
.nlg-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===============================================
   Lightbox Overlay
   =============================================== */

#nlg-lightbox {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.88);
  opacity: 0;
  transition: opacity 0.28s ease;
  will-change: opacity;
  touch-action: pan-x;
  -webkit-user-select: none;
  user-select: none;
}

#nlg-lightbox.nlg-visible {
  opacity: 1;
}

#nlg-lightbox .nlg-lb-inner {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 92vw;
  max-height: 90vh;
  pointer-events: none;
}

#nlg-lightbox img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  display: block;
  border-radius: 3px;
  opacity: 0;
  transform: scale(0.97);
  transition: opacity 0.22s ease, transform 0.22s ease;
  will-change: opacity, transform;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
}

#nlg-lightbox img.nlg-lb-loaded {
  opacity: 1;
  transform: scale(1);
}

/* Close animation state */
#nlg-lightbox.nlg-closing img {
  opacity: 0;
  transform: scale(0.94);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

#nlg-lightbox.nlg-closing {
  opacity: 0;
  transition: opacity 0.22s ease;
}

/* ===============================================
   Navigation Arrows
   =============================================== */

.nlg-prev,
.nlg-next {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  font-size: 28px;
  width: 48px;
  height: 72px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  z-index: 100000;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.nlg-prev {
  left: 16px;
}

.nlg-next {
  right: 16px;
}

.nlg-prev:hover,
.nlg-next:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* Close Button */
.nlg-close {
  position: fixed;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
  z-index: 100000;
  transition: opacity 0.15s;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

.nlg-close:hover {
  opacity: 1;
}

/* ===============================================
   Caption in Lightbox
   =============================================== */

.nlg-lb-caption {
  color: rgba(255, 255, 255, 0.82);
  font-size: 14px;
  text-align: center;
  margin-top: 12px;
  max-width: 600px;
  line-height: 1.5;
  padding: 0 16px;
  pointer-events: none;
}

.nlg-lb-caption.nlg-caption-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent);
  padding: 20px 16px 16px;
  margin-top: 0;
  max-width: 100%;
}

/* ===============================================
   Responsive Design
   =============================================== */

@media (max-width: 768px) {
  .nlg-gallery {
    grid-template-columns: repeat(min(var(--nlg-cols, 3), 2), 1fr);
  }

  /* Ensure equal heights are maintained on mobile */
  .nlg-gallery.nlg-has-max-height .nlg-item {
    height: var(--nlg-max-height) !important;
    aspect-ratio: auto !important;
    min-height: var(--nlg-max-height) !important;
    max-height: var(--nlg-max-height) !important;
  }

  .nlg-prev,
  .nlg-next {
    width: 40px;
    height: 60px;
    font-size: 24px;
  }

  .nlg-prev {
    left: 8px;
  }

  .nlg-next {
    right: 8px;
  }

  .nlg-close {
    top: 12px;
    right: 12px;
    font-size: 28px;
  }
}

@media (max-width: 480px) {
  .nlg-gallery {
    grid-template-columns: repeat(min(var(--nlg-cols, 3), 1), 1fr);
  }

  /* Ensure equal heights are maintained on mobile */
  .nlg-gallery.nlg-has-max-height .nlg-item {
    height: var(--nlg-max-height) !important;
    aspect-ratio: auto !important;
    min-height: var(--nlg-max-height) !important;
    max-height: var(--nlg-max-height) !important;
  }

  #nlg-lightbox img {
    max-width: 96vw;
    max-height: 85vh;
  }

  .nlg-lb-caption {
    font-size: 13px;
  }
}

/* ===============================================
   Accessibility
   =============================================== */

/* Focus styles for keyboard navigation */
.nlg-item:focus {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

.nlg-prev:focus,
.nlg-next:focus,
.nlg-close:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .nlg-item img,
  #nlg-lightbox,
  #nlg-lightbox img,
  .nlg-prev,
  .nlg-next,
  .nlg-close {
    transition: none;
  }

  .nlg-item:hover img {
    transform: none;
  }
}
