/**
 * Front-end navigation: toggles the mobile menu and closes it on outside click.
 */
(function () {
	'use strict';

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

		if (!toggle || !menu) {
			return;
		}

		function openMenu() {
			menu.classList.add('active');
		}

		function closeMenu() {
			menu.classList.remove('active');
		}

		toggle.addEventListener('click', function (e) {
			e.stopPropagation();
			menu.classList.contains('active') ? closeMenu() : openMenu();
		});

		document.addEventListener('click', function (event) {
			if (!menu.contains(event.target) && !toggle.contains(event.target)) {
				closeMenu();
			}
		});

		menu.querySelectorAll('a').forEach(function (link) {
			link.addEventListener('click', closeMenu);
		});
	});
})();
