// Core sidebar toggle functionality
document.addEventListener('DOMContentLoaded', function () {
    const toggleBtn = document.getElementById('sidebarToggle');
    const sidebar = document.getElementById('sidebarDesktop');
    const mainArea = document.getElementById('mainArea');

    if (toggleBtn && sidebar && mainArea) {
        // Restore saved state
        const collapsed = localStorage.getItem('sidebarCollapsed') === 'true';
        if (collapsed) {
            sidebar.classList.add('collapsed');
            mainArea.classList.add('expanded');
            toggleBtn.querySelector('i').classList.replace('bi-layout-sidebar-inset', 'bi-layout-sidebar');
        }

        toggleBtn.addEventListener('click', function () {
            const isCollapsed = sidebar.classList.contains('collapsed');
            if (isCollapsed) {
                sidebar.classList.remove('collapsed');
                mainArea.classList.remove('expanded');
                toggleBtn.querySelector('i').classList.replace('bi-layout-sidebar', 'bi-layout-sidebar-inset');
                localStorage.setItem('sidebarCollapsed', 'false');
            } else {
                sidebar.classList.add('collapsed');
                mainArea.classList.add('expanded');
                toggleBtn.querySelector('i').classList.replace('bi-layout-sidebar-inset', 'bi-layout-sidebar');
                localStorage.setItem('sidebarCollapsed', 'true');
            }
        });
    }
});