: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.bento-big-left {
  grid-column: 1 / span 2; /* Anchors to the far left */
  grid-row: span 2;
}

.layout-bento .bento-item.bento-big-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.bento-big-left,
  .layout-bento .bento-item.bento-big-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.bento-big-left,
  .layout-bento .bento-item.bento-big-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); }
}

/* =========================================
   6. Responsive Filter Navigation
   ========================================= */

.gallery-filter-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}

.gallery-filter-nav .nav-item {
  margin: 0;
}

.gallery-filter-nav .btn {
  white-space: nowrap;
}

/* Pill filter: one row by default; a +/- button at the end of the row expands/collapses the rest.
   Pills share a uniform minimum width; only long labels grow wider. */
.gallery-filter-nav {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
}

.gallery-filter-nav .btn {
  white-space: nowrap;
}

.gallery-filter-nav .btn {
  min-width: 130px;
  text-align: center;
  font-size: 0.9rem;
}

/* Filter chips: soft filled style (no outline). Active chip is filled with the theme colour. */
.gallery-filter-nav .btn {
  background: #f1f3f5;
  color: #343a40;
  border: 1px solid #adb5bd !important;
  padding: 0.6rem 1.4rem !important;
  font-weight: 600;
  letter-spacing: 0.2px;
  box-shadow: none;
  transition: background-color 0.2s, color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.gallery-filter-nav .btn:hover {
  background: var(--theme-primary-btn-color);
  border-color: var(--theme-primary-btn-color) !important;
  color: #fff;
  transform: translateY(-1px);
}

.gallery-filter-nav .btn.active,
.gallery-filter-nav .btn.active:hover {
  background: var(--theme-primary-btn-color);
  border-color: var(--theme-primary-btn-color) !important;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  transform: none;
}

/* +/- toggle: same chip shape and colours as the category chips */
.filter-toggle-btn {
  min-width: 56px;
  padding: 0.6rem 1.2rem;
  border: 1px solid #adb5bd;
  border-radius: 3rem;
  background: #f1f3f5;
  color: #111;
  font-size: 0.9rem;
  line-height: 1.5;
  transition: background-color 0.2s, color 0.2s, transform 0.15s;
}

.filter-toggle-btn:hover,
.filter-toggle-btn:focus-visible {
  border-color: var(--theme-primary-btn-color);
  background: var(--theme-primary-btn-color);
  color: #fff;
  outline: none;
  transform: translateY(-1px);
}

/* Small Mobile: Adjust font size */
@media (max-width: 575.98px) {
  .gallery-filter-nav .btn {
    font-size: 0.85rem;
  }
}

    /* Gallery item animations */
    .bento-item {
        transition: opacity 0.35s ease, transform 0.35s ease;
    }

    /* Initial page load animation - staggered entrance */
    .bento-item.gal-initial {
        animation: galleryItemLoad 0.5s ease-out forwards;
        animation-delay: calc(var(--item-index, 0) * 50ms);
        opacity: 0;
        transform: scale(0.9);
    }

    @keyframes galleryItemLoad {
        to {
            opacity: 1;
            transform: scale(1);
        }
    }

    /* Section Re-render animation */
    #main-gallery-wrapper {
        transition: opacity 0.3s ease, transform 0.3s ease;
    }
    
    #main-gallery-wrapper.re-rendering {
        opacity: 0;
        transform: translateY(10px);
    }

    /* Filter animation - when showing items */
    .bento-item.gal-showing {
        opacity: 1;
        transform: scale(1);
    }

    /* Filter button subtle click feedback */
    .gallery-filter-nav .btn.filter-btn-active {
        animation: filterBtnBlink 0.3s ease;
    }

    @keyframes filterBtnBlink {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.7; }
    }