:root {
  --gal-gap: 1.5rem;
  --gal-radius: 8px;
  --lightbox-bg: rgba(0, 0, 0, 0.85);
  --lightbox-z: 1055; /* Sits above BS5 modals */
  --transition-speed: 0.3s;
}

/* =========================================
   1. Base Gallery & Figure Styles
   ========================================= */
.gallery-figure {
  position: relative;
  overflow: hidden;
  border-radius: var(--gal-radius);
  margin-bottom: var(--gal-gap);
  cursor: pointer;
  transition: transform var(--transition-speed) ease;
}

.gallery-figure:hover {
  transform: translateY(-3px);
}

.gallery-figure img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block; /* Removes inline-block bottom gap */
}

.gallery-figure figcaption {
  position: absolute;
  inset: auto 0 0 0; /* Modern shorthand for bottom: 0; left: 0; width: 100%; */
  padding: 1rem;
  background: linear-gradient(to top, rgba(0,0,0,0.8), transparent);
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition-speed) ease;
}

.gallery-figure:hover figcaption {
  opacity: 1;
}

/* =========================================
   2. Layout A: 4-Column Grid (Standard)
   ========================================= */
.layout-grid .gallery-figure {
  aspect-ratio: 1 / 1; /* Forces uniform squares */
}
/* =========================================
   Layout C: Bento Box (Zig-Zag Grid)
   ========================================= */
.layout-bento.row {
  display: grid !important; /* Overrides Bootstrap flexbox */
  grid-template-columns: repeat(4, 1fr);
  grid-auto-rows: 250px;
  gap: var(--gal-gap);
  margin: 0;
  
  /* FIX 1: Prevents Isotope from setting a wrong height, fixing the footer collision */
  height: auto !important; 
  
  /* FIX 2: Forces smaller images to backfill the empty white spaces */
  grid-auto-flow: dense; 
}

/* FIX 3: Strip Isotope's absolute positioning so CSS Grid takes 100% control */
.layout-bento .bento-item {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
  transform: none !important;
}

/* Base style for the figure to ensure it fills the grid cell */
.layout-bento .gallery-figure {
  height: 100%;
  margin: 0;
}

/* 
   THE ZIG-ZAG LOGIC
   Uses the new PHP classes to anchor the feature images to specific columns 
*/
.layout-bento .bento-item:has(.bento-left) {
  grid-column: 1 / span 2; /* Anchors to the far left */
  grid-row: span 2;
}

.layout-bento .isotopeSelector:has(.bento-right) {
  grid-column: 3 / span 2; /* Anchors to the right side */
  grid-row: span 2;
}

/* Responsive Behavior */
@media (max-width: 991.98px) {
  .layout-bento.row { grid-template-columns: repeat(2, 1fr); }
  
  /* On tablets, the zig-zag stops and all features just span full width */
  .layout-bento .bento-item:has(.bento-left),
  .layout-bento .bento-item:has(.bento-right) {
    grid-column: 1 / span 2; 
    grid-row: span 1; /* Reduce height slightly for tablet */
  }
}

@media (max-width: 575.98px) {
  .layout-bento.row { grid-template-columns: 1fr; }
  .layout-bento .bento-item:has(.bento-left),
  .layout-bento .bento-item:has(.bento-right) {
    grid-column: span 1;
  }
}

/* =========================================
   4. Lightbox Overlay & Controls
   ========================================= */
.custom-lightbox {
  position: fixed;
  inset: 0; /* FIX 1: Replaces width:100vw to prevent mobile horizontal overflow */
  background: var(--lightbox-bg);
  z-index: var(--lightbox-z);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-speed) ease;
}

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

.lightbox-img-wrapper {
  position: relative;
  max-width: 90%;
  max-height: 80vh;
  display: flex;
  justify-content: center;
}

.lightbox-img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  user-select: none;
}

.lightbox-caption {
  color: #fff;
  margin-top: 1rem;
  font-size: 1.1rem;
  text-align: center;
  min-height: 1.5rem;
}

/* Lightbox Buttons */
.lb-ctrl {
  position: absolute;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  padding: 1rem;
  z-index: calc(var(--lightbox-z) + 1);
  transition: transform 0.2s ease-in-out;
}

.lb-close { 
  top: 1rem; 
  right: 1rem; 
}

.lb-close:hover { 
  transform: scale(1.2); 
}

.lb-prev, .lb-next {
    top: 50%; 
    height: 60%;
    width: 25%;
    cursor: pointer;
    display: block;
    transform: translateY(-50%); 
}

.lb-prev { 
  left: 1rem; 
}

.lb-next { 
  right: 1rem; 
}

.lb-prev:hover,
.lb-next:hover { 
  transform: translateY(-50%) scale(1.2); 
}

/* =========================================
   5. Filter Animations
   ========================================= */
.fade-in {
    animation: galFadeIn 0.4s ease forwards;
}

.fade-out {
    animation: galFadeOut 0.3s ease forwards;
}

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

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

/* =========================================
   Mobile Swipeable Filter UI
   ========================================= */
@media (max-width: 767.98px) {
  .gallery-filter-nav {
    /* 1. Force a single line and enable scrolling */
    flex-wrap: nowrap !important; 
    overflow-x: auto;             
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth momentum scrolling on iOS */
    
    /* 2. Override the centering from the parent div */
    justify-content: flex-start !important; 
    
    /* 3. Add a little breathing room at the bottom */
    padding-bottom: 0.5rem;       
    
    /* 4. Hide the ugly default scrollbars */
    -ms-overflow-style: none;     /* IE and Edge */
    scrollbar-width: none;        /* Firefox */
  }

  /* Hide scrollbar for Chrome, Safari and Opera */
  .gallery-filter-nav::-webkit-scrollbar {
    display: none;                
  }

  /* 5. Prevent the text inside the buttons from wrapping */
  .gallery-filter-nav .nav-link {
    white-space: nowrap; 
  }
}