/* ============================================================
   CMSMS GALLERY + POPUP LIGHTBOX (FINAL STABLE BUILD)
   - Popup always above blurred background
   - No filter() on gallery (no stacking traps)
   - Prev / Next anchored to popup image (±25px)
   - Close button top-right
   - Responsive + mobile safe
   ============================================================ */


/* ===============================
   BASE RESET
   =============================== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background-color: #e6ede8;
}


/* ===============================
   GALLERY GRID
   =============================== */
.gallery {
  position: relative;
  z-index: 1;

  padding: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

/* Disable clicks when popup open (NO blur here) */
.gallery.pop {
  pointer-events: none;
}

/* Gallery tiles */
.gallery figure {
  margin: 0;
  padding: 0;

  overflow: hidden;
  border-radius: 10px;
  cursor: pointer;

  flex: 1 1 calc(33.333% - 20px);
  max-width: calc(33.333% - 20px);
}

/* Gallery images */
.gallery figure img {
  display: block;
  width: 100%;
  height: 400px;

  object-fit: cover;
  border-radius: 10px;

  transition: transform 0.25s ease;
}

.gallery figure:hover img {
  transform: scale(1.04);
}

/* Hide captions in grid */
.gallery figure figcaption {
  display: none;
}


/* ===============================
   POPUP OVERLAY
   =============================== */
.popup {
  position: fixed;
  inset: 0;

  z-index: 2147483640;

  opacity: 0;
  pointer-events: none;

  background: rgba(255,255,255,0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);

  transition: opacity 0.25s ease;
  isolation: isolate;
}

.popup.pop {
  opacity: 1;
  pointer-events: auto;
}


/* ===============================
   POPUP CONTENT (IMAGE)
   =============================== */
.popup figure {
  position: absolute;
  top: 50%;
  left: 50%;

  transform: translate(-50%, -50%);
  transform-origin: center;

  margin: 0;
  z-index: 2147483000;

  animation: poppy 450ms ease-out both;
}

/* Popup image */
.popup figure img {
  display: block;

  width: min(90vw, 900px);
  max-height: 80vh;
  height: auto;

  object-fit: contain;
  border-radius: 14px;

  box-shadow:
    0 6px 20px rgba(0,0,0,0.35),
    0 0 0 1px rgba(255,255,255,0.25);
}

/* Caption */
.popup figure figcaption {
  position: absolute;
  left: 0;
  bottom: 0;

  width: 100%;
  padding: 90px 20px 18px;

  color: #fff;
  font-size: 26px;
  line-height: 1.25;

  background: linear-gradient(
    to top,
    rgba(0,0,0,0.78),
    rgba(0,0,0,0)
  );

  border-radius: 0 0 14px 14px;
}

.popup figure figcaption small {
  display: block;
  margin-top: 10px;

  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.85;
}

.popup figure figcaption small a {
  color: #d2ff00;
  font-weight: 700;
  text-decoration: none;
}

.popup figure figcaption small a:hover {
  color: #009cff;
}


/* ===============================
   CLOSE BUTTON
   =============================== */
.popup .close {
  position: absolute;
  top: 15px;
  right: 15px;

  z-index: 2147483646;

  width: 42px;
  height: 42px;

  border-radius: 50%;
  border: 0;

  background: rgba(0,0,0,0.35);
  color: #fff;

  font-size: 18px;
  font-weight: 800;

  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.popup .close:hover {
  background: rgba(0,0,0,0.6);
  transform: scale(1.08);
}


/* ===============================
   PREV / NEXT BUTTONS
   =============================== */
.popup .popup-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);

  z-index: 2147483647;

  width: 46px;
  height: 46px;

  border-radius: 50%;
  border: 0;

  background: rgba(0,0,0,0.65);
  color: #fff;

  font-size: 14px;
  font-weight: 700;

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

/* Anchor buttons to IMAGE, not viewport */
.popup figure {
  position: relative;
}

/* 25px from image edge */
.popup .popup-nav.prev {
  left: -25px;
}

.popup .popup-nav.next {
  right: -25px;
}

.popup .popup-nav:hover {
  background: rgba(0,0,0,0.85);
  transform: translateY(-50%) scale(1.1);
}


/* ===============================
   ANIMATION
   =============================== */
@keyframes poppy {
  from {
    transform: translate(-50%, -50%) scale(0.85);
    opacity: 0;
  }
  to {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}


/* ===============================
   RESPONSIVE
   =============================== */
@media (max-width: 1024px) {
  .gallery figure {
    flex: 1 1 calc(50% - 20px);
    max-width: calc(50% - 20px);
  }

  .gallery figure img {
    height: 320px;
  }
}

@media (max-width: 640px) {
  .gallery {
    gap: 12px;
  }

  .gallery figure {
    flex: 1 1 100%;
    max-width: 100%;
  }

  .gallery figure img {
    height: 220px;
  }

  .popup figure img {
    width: 94vw;
    max-height: 72vh;
  }

  /* Pull nav buttons inside on mobile */
  .popup .popup-nav.prev {
    left: 10px;
  }

  .popup .popup-nav.next {
    right: 10px;
  }

  .popup figure figcaption {
    font-size: 20px;
    padding: 70px 14px 14px;
  }
}

/* ============================================================
   FORCE Prev/Next visible and positioned on popup image
   (Overrides Gallery module CSS)
   ============================================================ */

/* Make sure the popup figure can show buttons outside its bounds */
.popup,
.popup figure {
  overflow: visible !important;
}

/* Force nav buttons to exist visually (module may hide them) */
.popup .popup-nav {
  display: flex !important;
  visibility: visible !important;
  opacity: 1 !important;

  position: absolute !important;
  top: 50% !important;
  transform: translateY(-50%) !important;

  z-index: 2147483647 !important;
  pointer-events: auto !important;

  width: 46px !important;
  height: 46px !important;

  align-items: center !important;
  justify-content: center !important;

  border: 0 !important;
  border-radius: 50% !important;

  background: rgba(0,0,0,0.65) !important;
  color: #fff !important;

  font-size: 14px !important;
  font-weight: 800 !important;
  line-height: 1 !important;

  cursor: pointer !important;
}

/* Anchor them to the popup IMAGE container */
.popup figure { position: absolute !important; } /* your figure is centered via absolute */
.popup figure .popup-nav.prev { left: -25px !important; }
.popup figure .popup-nav.next { right: -25px !important; }

/* If your figure has no explicit width/height, ensure it wraps the image */
.popup figure img { display: block !important; }

/* Mobile: pull inside so they don’t go off-screen */
@media (max-width: 640px){
  .popup figure .popup-nav.prev { left: 10px !important; }
  .popup figure .popup-nav.next { right: 10px !important; }
}