



    /* Scrolling Gallery Styles */
.cms-gallery-wrapper {
    width: 100%;
    overflow: hidden;
    position: relative;
}
/* Page width: matches the old Elementor boxed layout */
body {
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
}

/* Fade edges for seamless feel */
.cms-gallery-wrapper::before,
.cms-gallery-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100px;
    z-index: 2;
    pointer-events: none;
}

.cms-gallery-wrapper::before {
    left: 0;
    padding: 20px 0;
    background: linear-gradient(to right, var(--mhm-card-bg, #FAF8F5), transparent);
}

.cms-gallery-wrapper::after {
    right: 0;
    background: linear-gradient(to left, var(--mhm-card-bg, #FAF8F5), transparent);
}

.cms-gallery-track {
    display: flex;
    gap: 24px;
    padding: 20px 0;
    animation: scroll 40s linear infinite;
    width: max-content;
}

/* Pause on hover */
.cms-gallery-track:hover {
    animation-play-state: paused;
}

.cms-gallery-item {
    flex-shrink: 0;
    width: 350px;
    height: 450px;
    border-radius: var(--mhm-radius-lg, 20px);
    overflow: hidden;
    box-shadow: 0 8px 15px rgba(0, 0, 0, 0.45);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cms-gallery-item:hover {
    transform: scale(1.02);
    box-shadow: 0 12px 50px rgba(0, 0, 0, 0.55);
}

.cms-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.cms-gallery-item:hover img {
    transform: scale(1.05);
}

@keyframes scroll {
    0% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(calc(-350px * 6 - 24px * 6));
    }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .cms-gallery-item {
        width: 280px;
        height: 360px;
    }

    @keyframes scroll {
        0% {
            transform: translateX(0);
        }
        100% {
            transform: translateX(calc(-280px * 6 - 24px * 6));
        }
    }

    .cms-gallery-wrapper::before,
    .cms-gallery-wrapper::after {
        width: 50px;
    }
}


    /* ============================================
       FILTER BUTTONS
       ============================================ */
.cms-filter-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: var(--mhm-space-xl, 48px);
}

.cms-filter-btn {
    padding: 10px 24px;
    border: 1px solid var(--mhm-border, #D6CFC5);
    border-radius: 50px;
    background: transparent;
    color: var(--mhm-primary, #C4856A);
    font-family: var(--mhm-body-font, 'DM Sans', system-ui, sans-serif);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.25s ease;
}

.cms-filter-btn:hover {
    border-color: var(--mhm-accent, #C4856A);
    background: rgba(196, 133, 106, 0.08);
}

.cms-filter-btn.active {
    background: var(--mhm-primary, #4A5859);
    border-color: var(--mhm-primary, #4A5859);
    color: white;
}

/* ============================================
   GALLERY GRID
   ============================================ */
.cms-gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 28px;
}

@media (max-width: 992px) {
    .cms-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
    }
}

@media (max-width: 576px) {
    .cms-gallery-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
}

/* ============================================
   GALLERY CARDS
   ============================================ */
.cms-gallery-card {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.cms-gallery-card.hidden {
    display: none;
}

/* Fade-in animation for filtered items */
.cms-gallery-card.fade-in {
    animation: fadeInUp 0.4s ease forwards;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cms-gallery-image {
    aspect-ratio: 1 / 1;
    border-radius: var(--mhm-radius-lg, 16px);
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    background: var(--mhm-border, #D6CFC5); /* Placeholder colour while loading */
}

.cms-gallery-image:hover {
    transform: translateY(-6px);
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.15);
}

.cms-gallery-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease, opacity 0.3s ease;
    opacity: 0;
}

/* Fade in when image loads */
.cms-gallery-image img.loaded {
    opacity: 1;
}

.cms-gallery-image:hover img {
    transform: scale(1.06);
}

/* Zoom icon overlay */
.cms-gallery-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(45, 55, 72, 0) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3Cline x1='11' y1='8' x2='11' y2='14'%3E%3C/line%3E%3Cline x1='8' y1='11' x2='14' y2='11'%3E%3C/line%3E%3C/svg%3E") center center no-repeat;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.cms-gallery-image:hover::after {
    background-color: rgba(45, 55, 72, 0.3);
    opacity: 1;
}

.cms-gallery-caption {
    margin-top: 14px;
    font-size: 0.9rem;
    color: var(--mhm-muted, #6B7280);
    padding-left: 0px;      /* you can set this to 0 if you want it perfectly centred */
    text-align: center;
}


/* ============================================
   LIGHTBOX
   ============================================ */
.cms-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 99999;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.cms-lightbox.active {
    display: flex;
    opacity: 1;
}

.cms-lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 90%;
    max-height: 90vh;
}

.cms-lightbox-close {
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 45px;
    color: white;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.2s ease;
    line-height: 1;
    padding: 10px;
    z-index: 10;
}

.cms-lightbox-close:hover {
    color: var(--mhm-accent, #C4856A);
    transform: scale(1.1);
}

.cms-lightbox-prev,
.cms-lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 32px;
    color: white;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    padding: 20px 16px;
    transition: all 0.2s ease;
    border-radius: 4px;
}

.cms-lightbox-prev {
    left: 20px;
}

.cms-lightbox-next {
    right: 20px;
}

.cms-lightbox-prev:hover,
.cms-lightbox-next:hover {
    background: rgba(255, 255, 255, 0.2);
    color: var(--mhm-accent, #C4856A);
}

#cms-lightbox-img {
    max-width: 100%;
    max-height: 80vh;
    border-radius: var(--mhm-radius, 12px);
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#cms-lightbox-img.loaded {
    opacity: 1;
    transform: scale(1);
}

#cms-lightbox-caption {
    color: rgba(255, 255, 255, 0.9);
    margin-top: 20px;
    font-size: 1rem;
    text-align: center;
    font-family: var(--mhm-body-font, 'DM Sans', system-ui, sans-serif);
}

/* Hide prev/next on mobile - use swipe instead */
@media (max-width: 768px) {
    .cms-lightbox-prev,
    .cms-lightbox-next {
        padding: 15px 12px;
        font-size: 24px;
    }

    .cms-lightbox-close {
        top: 10px;
        right: 15px;
        font-size: 36px;
    }
}
</style>

<script>
(function() {
'use strict';

// ============================================
// LAZY LOADING - Fade in images when loaded
// ============================================
document.querySelectorAll('.cms-gallery-image img').forEach(img => {
// If already cached/loaded
if (img.complete) {
img.classList.add('loaded');
} else {
      img.addEventListener('load', function() {
      this.classList.add('loaded');
  });
  }
});

// ============================================
// FILTER FUNCTIONALITY
// ============================================
const filterButtons = document.querySelectorAll('.cms-filter-btn');
    const galleryCards = document.querySelectorAll('.cms-gallery-card');

filterButtons.forEach(button => {
button.addEventListener('click', function() {
// Update active button
filterButtons.forEach(btn => btn.classList.remove('active'));
this.classList.add('active');

// Get filter value
const filter = this.getAttribute('data-filter');

// Filter gallery items with animation
galleryCards.forEach((card, index) => {
card.classList.remove('fade-in');

    if (filter === 'all' || card.getAttribute('data-category').includes(filter)) {
card.classList.remove('hidden');
// Stagger the fade-in animation
setTimeout(() => {
card.classList.add('fade-in');
}, index * 50);
} else {
      card.classList.add('hidden');
  }
});
});
});

// ============================================
// LIGHTBOX FUNCTIONALITY
// ============================================
const lightbox = document.getElementById('cms-lightbox');
    const lightboxImg = document.getElementById('cms-lightbox-img');
    const lightboxCaption = document.getElementById('cms-lightbox-caption');

// Get all visible gallery images
let currentIndex = 0;

    function getVisibleImages() {
return Array.from(document.querySelectorAll('.cms-gallery-card:not(.hidden) .cms-gallery-image'));
}

// Open lightbox
document.querySelectorAll('.cms-gallery-image').forEach(imageContainer => {
imageContainer.addEventListener('click', function() {
    const visibleImages = getVisibleImages();
    currentIndex = visibleImages.indexOf(this);

showImage(this);
lightbox.classList.add('active');
document.body.style.overflow = 'hidden';
});
});

    function showImage(imageContainer) {
    const fullSrc = imageContainer.getAttribute('data-full') || imageContainer.querySelector('img').src;
    const caption = imageContainer.getAttribute('data-caption') || '';

lightboxImg.classList.remove('loaded');
lightboxImg.src = fullSrc;
lightboxImg.onload = function() {
lightboxImg.classList.add('loaded');
};
lightboxCaption.textContent = caption;
}

// Close lightbox
function closeLightbox() {
lightbox.classList.remove('active');
document.body.style.overflow = '';
}

document.querySelector('.cms-lightbox-close').addEventListener('click', closeLightbox);

// Close on background click
lightbox.addEventListener('click', function(e) {
    if (e.target === lightbox) {
closeLightbox();
}
});

// Previous image
document.querySelector('.cms-lightbox-prev').addEventListener('click', function(e) {
e.stopPropagation();
    const visibleImages = getVisibleImages();
    currentIndex = (currentIndex - 1 + visibleImages.length) % visibleImages.length;
showImage(visibleImages[currentIndex]);
});

// Next image
document.querySelector('.cms-lightbox-next').addEventListener('click', function(e) {
e.stopPropagation();
    const visibleImages = getVisibleImages();
    currentIndex = (currentIndex + 1) % visibleImages.length;
showImage(visibleImages[currentIndex]);
});

// Keyboard navigation
document.addEventListener('keydown', function(e) {
    if (!lightbox.classList.contains('active')) return;

    if (e.key === 'Escape') {
closeLightbox();
} else if (e.key === 'ArrowLeft') {
document.querySelector('.cms-lightbox-prev').click();
} else if (e.key === 'ArrowRight') {
document.querySelector('.cms-lightbox-next').click();
}
});

// Touch swipe support for mobile
let touchStartX = 0;
    let touchEndX = 0;

lightbox.addEventListener('touchstart', function(e) {
    touchStartX = e.changedTouches[0].screenX;
}, { passive: true });

lightbox.addEventListener('touchend', function(e) {
    touchEndX = e.changedTouches[0].screenX;
handleSwipe();
}, { passive: true });

    function handleSwipe() {
    const swipeThreshold = 50;
    const diff = touchStartX - touchEndX;

    if (Math.abs(diff) > swipeThreshold) {
    if (diff > 0) {
// Swipe left - next image
document.querySelector('.cms-lightbox-next').click();
} else {
  // Swipe right - previous image
  document.querySelector('.cms-lightbox-prev').click();
  }
}
}
})();


