/* =============== GALLERY CONTROLS =============== */
.gallery-controls {
  display: flex;
  justify-content: center;
  margin-bottom: 10px;
}
.gallery-controls > * {
  margin: 0 1rem;
}

/* =============== GALLERY SWIPER CONTAINER =============== */
.gallery-slider-container {
  max-width: 600px;
  margin: 40px auto;
}

/* Style for the gallery container to prevent FOUC (Flash of Unstyled Content) */
.gallery-swiper {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  min-height: 200px; /* Prevent collapse before images load */
 
}

/* Style for slides before they're fully initialized */
.swiper-slide {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100px; /* Prevent collapse */
}

/* =============== GALLERY MATERIAL WRAPPER (NO SHADOW) =============== */
.gallery-material-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 16px;
  background-color: transparent; /* Changed from white to transparent to avoid white flash */
  overflow: hidden;
}

.gallery-material-content {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #f0f0f0; /* Light gray background that will be visible before skeleton loads */
}

/* OPTIONAL SCALE EFFECT */
[data-swiper-material-scale="1.25"] {
  transition: transform 0.6s ease;
  transform-origin: center center;
}
.swiper-slide-active [data-swiper-material-scale="1.25"] {
  transform: scale(1.06) translateY(-5px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
  transition: transform 0.5s ease, box-shadow 0.5s ease;
}

/* =============== GALLERY IMAGES =============== */
.gallery-material-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  opacity: 0; /* Start with 0 opacity */
  transition: opacity 0.5s ease; /* Smooth transition when loaded */
}

/* Skeleton placeholder */
.skeleton-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    #f0f0f0 0%, 
    #ffffff 50%, 
    #f0f0f0 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.2s infinite ease-in-out;
  border-radius: 16px;
  z-index: 1;
}

.skeleton-placeholder.loaded {
  opacity: 0;
  transition: opacity 0.5s ease;
}

@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Lazy loading spinner - keep as fallback */
.swiper-lazy-preloader {
  width: 42px;
  height: 42px;
  position: absolute;
  left: 50%;
  top: 50%;
  margin-left: -21px;
  margin-top: -21px;
  z-index: 0; /* Lower z-index so skeleton shows above */
  transform-origin: 50%;
  animation: swiper-preloader-spin 1s infinite linear;
  box-sizing: border-box;
  border: 4px solid var(--swiper-preloader-color, var(--swiper-theme-color));
  border-radius: 50%;
  border-top-color: transparent;
  display: none; /* Hide spinner in favor of skeleton */
}

@keyframes swiper-preloader-spin {
  100% {
    transform: rotate(360deg);
  }
}

/* =============== GALLERY VIDEO THUMBNAIL + ICON =============== */
.gallery-video-thumbnail {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  cursor: pointer;
}
.gallery-youtube-icon-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 64px;
  height: 64px;
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}
.gallery-youtube-icon-overlay img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* =============== GALLERY SWIPER PAGINATION =============== */
.gallery-swiper-pagination {
  margin-top: 20px;
  text-align: center;
}
.swiper-pagination-bullet {
  background: #000;
  opacity: 0.4;
}
.swiper-pagination-bullet-active {
  opacity: 1;
  background: #2f2f2f !important;
}
.swiper-pagination {
  position: unset !important;
  margin-top: 18px;
}

/* =============== GALLERY LIGHTBOX MODAL =============== */
.gallery-lightbox-modal {
  position: fixed;
  z-index: 9999;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.9);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}
.gallery-lightbox-modal.visible {
  opacity: 1;
  visibility: visible;
}

/* GALLERY CLOSE BUTTON — plain X icon, no background/border */
.gallery-modal-close {
  background: none;
  padding: 0;
  line-height: 1;
  color: #fff;
  cursor: pointer;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  position: absolute;
  top: 10px;
  right: 15px;
  transition: transform 0.2s ease, opacity 0.2s ease;
  opacity: 0.85;
  z-index: 10001;
}

.gallery-modal-close svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  display: block;
}

.gallery-modal-close:hover {
  opacity: 1;
  transform: scale(1.1);
}

.gallery-modal-close:active {
  transform: scale(0.95);
}

/* Adjust for high contrast mode */
@media (forced-colors: active) {
  .gallery-modal-close,
  .lightbox-nav-btn,
  .gallery-tool-btn {
    border: 2px solid currentColor;
  }
}

/* =============== IMAGE TOOLBAR (rotate / flip / reset) =============== */
.gallery-modal-toolbar {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 10001;
}

.gallery-tool-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.gallery-tool-btn:hover {
  background-color: rgba(0, 0, 0, 0.55);
  transform: scale(1.08);
}

.gallery-tool-btn:active {
  transform: scale(0.95);
}

.gallery-tool-btn svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
  display: block;
}

/* Reuse the horizontal-flip glyph for the vertical-flip button */
.gallery-tool-btn.flip-vertical svg {
  transform: rotate(90deg);
}

/* GALLERY MODAL CONTENT
   Laid out as a vertical stack: [stage (image/video)] on top, then the
   [footer (thumbnails + progress + counter)] below. Using flex flow instead
   of absolute offsets keeps the pieces from overlapping each other. */
.gallery-modal-content {
  position: relative;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 64px 16px 20px; /* top room for the close button */
  box-sizing: border-box;
  gap: 14px;
}

/* Stage: holds the active image/video plus the overlaid side nav arrows.
   flex:1 + min-height:0 lets the media shrink to fit above the footer. */
.gallery-modal-stage {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* contain zoom-pan / rotation so it never covers the footer */
  touch-action: none; /* we handle pinch/pan/swipe ourselves */
}

/* GALLERY IMAGE CONTAINER */
.gallery-modal-image-container {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible; /* don't clip the image when it's rotated 90/270° */
  border-radius: 8px;
  transition: opacity 0.2s ease;
}

.gallery-modal-image-container.transitioning {
  opacity: 0;
}

.gallery-modal-img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 16px;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform-origin: center center;
  cursor: zoom-in;
  will-change: transform, opacity; /* promote to its own GPU layer */
  backface-visibility: hidden;
  user-select: none;
  -webkit-user-drag: none; /* belt-and-suspenders: no native image drag */
}

/* Modal skeleton placeholder */
.modal-skeleton-placeholder {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    #e0e0e0 0%, 
    #ffffff 50%, 
    #e0e0e0 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.2s infinite ease-in-out;
  border-radius: 16px;
  z-index: 1;
}

.modal-skeleton-placeholder.loaded {
  opacity: 0;
  transition: opacity 0.5s ease;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* =============== LIGHTBOX FOOTER (thumbnails + progress + counter) ===============
   A single normal-flow column under the image. This is what fixes the old
   overlap bugs: every control lives here in order instead of being absolutely
   positioned with conflicting `bottom` values. */
.gallery-lightbox-footer {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* Progress bar */
.gallery-progress-bar {
  position: relative;
  height: 4px;
  width: 60%;
  max-width: 300px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
  overflow: hidden;
}

.gallery-progress-indicator {
  height: 100%;
  background: #fff;
  transition: width 0.3s ease;
}

/* For screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* GALLERY VIDEO CONTAINER */
.gallery-modal-video-container {
  position: relative;
  width: 90vw;
  max-width: 1600px;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 16px;
  overflow: hidden;
}
.gallery-modal-video {
  width: 100%;
  height: 100%;
  border: none;
}

/* =============== LIGHTBOX NAVIGATION (side arrows) ===============
   The arrows overlay the stage (left/right, vertically centered). The
   container ignores pointer events so clicks pass through to the image,
   while the buttons themselves stay clickable. */
.lightbox-navigation {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  pointer-events: none;
  z-index: 10001;
}

.lightbox-nav-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  background-color: rgba(0, 0, 0, 0.35);
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.lightbox-nav-btn:hover {
  background-color: rgba(0, 0, 0, 0.5);
  transform: scale(1.1);
}

.lightbox-nav-btn:active {
  transform: scale(0.95);
}

.lightbox-nav-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  display: block;
}

/* Counter / indicator — lives in the footer, in normal flow */
.lightbox-indicator {
  color: #fff;
  background-color: rgba(0, 0, 0, 0.4);
  padding: 4px 12px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.4;
}

@media (min-width: 768px) {
  .lightbox-navigation {
    padding: 0 24px;
  }
  .lightbox-nav-btn {
    width: 50px;
    height: 50px;
  }
  .lightbox-nav-btn svg {
    width: 28px;
    height: 28px;
  }
}

/* =============== THUMBNAIL STRIP =============== */
/* width:max-content + margin auto centers the strip when there are only a few
   thumbnails, but caps at 100% and scrolls horizontally for large galleries.
   direction:ltr keeps scrollLeft math consistent on the RTL page. */
.gallery-thumbnail-strip {
  position: relative;
  display: flex;
  gap: 8px;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 4px;
  direction: ltr;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.4) transparent;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.gallery-thumbnail-strip::-webkit-scrollbar {
  height: 6px;
}
.gallery-thumbnail-strip::-webkit-scrollbar-track {
  background: transparent;
}
.gallery-thumbnail-strip::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.4);
  border-radius: 3px;
}

.gallery-thumbnail-item {
  flex: 0 0 auto;
  width: 50px;
  height: 34px;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  opacity: 0.55;
  border: 2px solid transparent;
  transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.gallery-thumbnail-item.active {
  opacity: 1;
  border-color: #fff;
  transform: translateY(-2px);
}

.gallery-thumbnail-item:hover {
  opacity: 0.9;
}

.gallery-thumbnail-img {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
}

@media (min-width: 768px) {
  .gallery-thumbnail-strip {
    gap: 10px;
  }
  .gallery-thumbnail-item {
    width: 64px;
    height: 44px;
  }
}

.gallery-title-desc {
  margin-bottom: 30px;
  text-align: center;
}
.gallery-title-desc h3 {
  margin: 0 0 5px;
  font-size: 1.5rem;
  margin-top: 20px;
  display: block;
  width: fit-content;
  /* fit-content resolves to max-content, so an unbreakable token (a pasted URL)
     would grow wider than the page and blow out the layout. Cap it and let long
     words wrap. */
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin-left: auto;
  margin-right: auto;
  padding-bottom: 8px;
  padding-left: 15px;
  padding-right: 15px;
  position: relative;
}
.gallery-title-desc h3::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 1.5px;
  background-color: #ddd;
}
.gallery-title-desc p {
  margin: 0;
  margin-bottom: -15px;
  font-size: 0.9rem;
  color: #333;
  overflow-wrap: anywhere;
  word-break: break-word;
}