<?php if (empty($_SESSION['user_id'])) return; ?>
</main>
</div>
<script>
(function(){
    var sb = document.querySelector('.sidebar-nav');
    if (!sb) return;
    var key = 'sidebar_scroll';
    var saved = localStorage.getItem(key);
    if (saved) { sb.scrollTop = parseInt(saved, 10); }
    window.addEventListener('beforeunload', function(){
        localStorage.setItem(key, sb.scrollTop);
    });
    var scrollTimer;
    sb.addEventListener('scroll', function(){
        clearTimeout(scrollTimer);
        scrollTimer = setTimeout(function(){
            localStorage.setItem(key, sb.scrollTop);
        }, 100);
    });
})();
document.addEventListener('click', function(e) {
    var sb = document.querySelector('.sidebar');
    var btn = document.querySelector('.sidebar-toggle');
    if (sb && sb.classList.contains('open') && !sb.contains(e.target) && btn && !btn.contains(e.target)) {
        sb.classList.remove('open');
    }
});
</script>
</body>
</html>
