<script>
(function () {
    var body = document.body;
    var toggle = document.getElementById('adminSidebarToggle');
    var closeBtn = document.getElementById('adminSidebarClose');
    var backdrop = document.getElementById('adminSidebarBackdrop');
    if (toggle) {
        toggle.addEventListener('click', function () {
            body.classList.toggle('sidebar-open');
        });
    }
    if (closeBtn) {
        closeBtn.addEventListener('click', function () {
            body.classList.remove('sidebar-open');
        });
    }
    if (backdrop) {
        backdrop.addEventListener('click', function () {
            body.classList.remove('sidebar-open');
        });
    }
    document.querySelectorAll('.sidebar .collapse').forEach(function (el) {
        el.addEventListener('show.bs.collapse', function () {
            var li = el.closest('.has-submenu');
            if (li) li.classList.add('open');
        });
        el.addEventListener('hide.bs.collapse', function () {
            var li = el.closest('.has-submenu');
            if (li) li.classList.remove('open');
        });
    });
})();
</script>
