// ========================================
// AOS Init (OUTSIDE DOMContentLoaded)
// ========================================
AOS.init({
  duration: 800,
  easing: 'slide',
  once: true
});

window.addEventListener('load', function() {
  AOS.refresh();
});

// ========================================
// Main Initialization
// ========================================
document.addEventListener('DOMContentLoaded', function() {
  'use strict';

  initMobileMenu();
  initLightbox();
});

// ========================================
// Mobile Menu (replaces jQuery siteMenuClone)
// ========================================
function initMobileMenu() {
  // Clone navigation to mobile menu
  var navs = document.querySelectorAll('.js-clone-nav');
  var mobileBody = document.querySelector('.site-mobile-menu-body');

  if (!mobileBody) return;

  navs.forEach(function(nav) {
    var clone = nav.cloneNode(true);
    clone.className = 'site-nav-wrap';
    mobileBody.appendChild(clone);
  });

  // Toggle menu
  var toggles = document.querySelectorAll('.js-menu-toggle');
  var body = document.body;

  toggles.forEach(function(toggle) {
    toggle.addEventListener('click', function(e) {
      e.preventDefault();
      body.classList.toggle('offcanvas-menu');
    });
  });

  // Close on outside click
  document.addEventListener('click', function(e) {
    var menu = document.querySelector('.site-mobile-menu');
    if (body.classList.contains('offcanvas-menu') &&
        !menu.contains(e.target) &&
        !e.target.closest('.js-menu-toggle')) {
      body.classList.remove('offcanvas-menu');
    }
  });

  // Close menu on window resize > 768px
  window.addEventListener('resize', function() {
    if (window.innerWidth > 768 && body.classList.contains('offcanvas-menu')) {
      body.classList.remove('offcanvas-menu');
    }
  });
}

// ========================================
// Lightbox (GLightbox)
// ========================================
function initLightbox() {
  if (typeof GLightbox === 'undefined') return;
  GLightbox({
    selector: '.glightbox',
    touchNavigation: true,
    loop: true
  });
}
