<?php
// includes/footer.php
?>
            </div> <!-- پایان کانتینر .max-w-7xl -->
            
            <footer class="mt-16 py-6 text-center text-gray-400 text-sm font-medium border-t border-gray-100">
                سیستم مدیریت و اکانتینگ VPNet
            </footer>
            
        </main> <!-- پایان کانتینر .main -->
    </div> <!-- پایان رپر اصلی (flex-1) -->

    <script>
        // --------------------------------------------------------
        // کنترل سایدبار موبایل
        // --------------------------------------------------------
        function toggleSidebar() {
            const sidebar = document.getElementById('sidebar');
            const backdrop = document.getElementById('sidebarBackdrop');
            const mobileMenu = document.getElementById('mobileMenu');
            
            if (!mobileMenu.classList.contains('hidden')) {
                mobileMenu.classList.add('hidden');
            } else {
                sidebar.classList.toggle('translate-x-full');
                if (sidebar.classList.contains('translate-x-full')) {
                    backdrop.classList.add('hidden');
                } else {
                    backdrop.classList.remove('hidden');
                }
            }
        }

        document.addEventListener("DOMContentLoaded", function() {
            const currentUrl = window.location.href;
            const navItems = document.querySelectorAll('.nav-item');
            navItems.forEach(item => {
                if(currentUrl.includes(item.getAttribute('href'))) {
                    item.classList.add('active');
                }
            });
        });

        // --------------------------------------------------------
        // کدهای مربوط به تغییر تم (دارک / لایت مود)
        // --------------------------------------------------------
        var themeToggleDarkIcon = document.getElementById('theme-toggle-dark-icon');
        var themeToggleLightIcon = document.getElementById('theme-toggle-light-icon');

        if (localStorage.getItem('color-theme') === 'dark' || (!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
            themeToggleLightIcon.classList.remove('hidden');
        } else {
            themeToggleDarkIcon.classList.remove('hidden');
        }

        var themeToggleBtn = document.getElementById('theme-toggle');
        if (themeToggleBtn) {
            themeToggleBtn.addEventListener('click', function() {
                themeToggleDarkIcon.classList.toggle('hidden');
                themeToggleLightIcon.classList.toggle('hidden');

                if (localStorage.getItem('color-theme')) {
                    if (localStorage.getItem('color-theme') === 'light') {
                        document.documentElement.classList.add('dark');
                        localStorage.setItem('color-theme', 'dark');
                    } else {
                        document.documentElement.classList.remove('dark');
                        localStorage.setItem('color-theme', 'light');
                    }
                } else {
                    if (document.documentElement.classList.contains('dark')) {
                        document.documentElement.classList.remove('dark');
                        localStorage.setItem('color-theme', 'light');
                    } else {
                        document.documentElement.classList.add('dark');
                        localStorage.setItem('color-theme', 'dark');
                    }
                }
            });
        }

        // --------------------------------------------------------
        // انجین سراسری شمارش معکوس (Countdown)
        // --------------------------------------------------------
        const countdownElement = document.getElementById('countdown-timer');
        if (countdownElement) {
            const targetDate = new Date(countdownElement.getAttribute('data-target')).getTime();
            
            const timerInterval = setInterval(function() {
                const now = new Date().getTime();
                const distance = targetDate - now;

                if (distance < 0) {
                    clearInterval(timerInterval);
                    document.getElementById('global-countdown-banner').style.display = 'none';
                    return;
                }

                const days = Math.floor(distance / (1000 * 60 * 60 * 24));
                const hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                const seconds = Math.floor((distance % (1000 * 60)) / 1000);

                countdownElement.innerHTML = 
                    (days < 10 ? "0" + days : days) + " : " + 
                    (hours < 10 ? "0" + hours : hours) + " : " + 
                    (minutes < 10 ? "0" + minutes : minutes) + " : " + 
                    (seconds < 10 ? "0" + seconds : seconds);
            }, 1000);
        }

        // --------------------------------------------------------
        // کدهای نوتیفیکیشن لایو (Live Notification Ajax)
        // --------------------------------------------------------
        <?php if(isset($_SESSION['user_id'])): ?>
        
        const notiBtn = document.getElementById('notiBtn');
        const notiDropdown = document.getElementById('notiDropdown');
        const notiBadge = document.getElementById('notiBadge');
        const notiList = document.getElementById('notiList');
        const notiCountText = document.getElementById('notiCountText');

        if(notiBtn) {
            notiBtn.addEventListener('click', function(e) {
                e.stopPropagation();
                const isHidden = notiDropdown.classList.contains('hidden');
                notiDropdown.classList.toggle('hidden');
                
                if (isHidden) {
                    fetch('/vpnet-panel/modules/notifications_api.php?action=mark_read')
                        .then(() => {
                            setTimeout(fetchNotifications, 2000);
                        });
                }
            });
            
            document.addEventListener('click', function(e) {
                if (!notiDropdown.contains(e.target) && !notiBtn.contains(e.target)) {
                    notiDropdown.classList.add('hidden');
                }
            });
        }

        function fetchNotifications() {
            fetch('/vpnet-panel/modules/notifications_api.php')
                .then(response => response.json())
                .then(data => {
                    if(data.count > 0) {
                        notiBadge.classList.remove('hidden');
                        notiCountText.innerText = data.count;
                        
                        let itemsHtml = '';
                        data.alerts.forEach(item => {
                            itemsHtml += `
                                <a href="${item.link}" class="flex items-start gap-4 p-3 rounded-2xl hover:bg-blue-50/50 transition border border-transparent hover:border-blue-100 dark:hover:bg-slate-700 dark:hover:border-slate-600">
                                    <div class="flex-shrink-0 w-12 h-12 flex items-center justify-center rounded-xl shadow-sm ${item.bg} ${item.color} text-xl">
                                        ${item.icon}
                                    </div>
                                    <div class="flex-1 pt-1">
                                        <h4 class="text-xs font-black text-gray-800 mb-1">${item.title}</h4>
                                        <p class="text-[11px] text-gray-500 leading-relaxed font-medium">${item.text}</p>
                                        ${item.button ? item.button : ''}
                                    </div>
                                </a>
                            `;
                        });
                        notiList.innerHTML = itemsHtml;
                    } else {
                        notiBadge.classList.add('hidden');
                        notiCountText.innerText = '0';
                        notiList.innerHTML = `<div class="p-8 flex flex-col items-center justify-center text-center"><span class="text-4xl mb-3 opacity-50">🎉</span><span class="text-xs text-gray-400 font-bold">هیچ اعلان جدیدی ندارید</span></div>`;
                    }
                })
                .catch(error => console.error('Notification Error:', error));
        }

        fetchNotifications();
        setInterval(fetchNotifications, 30000); 

        <?php endif; ?>
    </script>
</body>
</html>