document.addEventListener("DOMContentLoaded", () => {
    const sidebar = document.getElementById("sidebar");
    const toggle = document.getElementById("toggleSidebar");

    // Recolher / expandir sidebar
    toggle.addEventListener("click", () => {
        sidebar.classList.toggle("collapsed");

        // Fecha submenus ao recolher
        if (sidebar.classList.contains("collapsed")) {
            document.querySelectorAll(".collapse.show").forEach(el => {
                new bootstrap.Collapse(el, { toggle: true });
            });
        }
    });
});
