document.addEventListener('DOMContentLoaded', function () {
  var toggle = document.querySelector('.nav-toggle');
  var menu = document.querySelector('.nav-menu');

  if (toggle && menu) {
    toggle.addEventListener('click', function () {
      var isOpen = menu.classList.toggle('nav-menu--open');
      toggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
    });
  }

  // Submenu tap-to-open untuk mobile (selain hover)
  document.querySelectorAll('.nav-menu > li').forEach(function (item) {
    var link = item.querySelector('a');
    var submenu = item.querySelector('.submenu');
    if (!submenu || !link) return;

    link.addEventListener('click', function (e) {
      if (window.innerWidth <= 900) {
        e.preventDefault();
        item.classList.toggle('submenu-open');
      }
    });
  });
});
