<div id="userSidebar" class="fixed inset-y-0 left-0 w-72 bg-white shadow-2xl transform -translate-x-full transition-transform duration-300 z-[200] lg:hidden flex flex-col border-r border-gray-50">
    
    <div class="p-8 pb-6 border-b border-gray-50 relative overflow-hidden">
        <button onclick="toggleUserSidebar()" class="absolute top-6 right-6 text-gray-300 hover:text-gray-800 transition-colors">
            <i class="fa-solid fa-xmark text-lg"></i>
        </button>

        <div class="flex flex-col gap-1">
            <?php if(isset($_SESSION['user_id'])): ?>
                <span class="text-[10px] font-black text-sky-500 uppercase tracking-[0.2em] mb-1">Authenticated</span>
                <h2 class="text-xl font-black text-gray-800 tracking-tighter">Hi, <?php echo $u_data['name']; ?></h2>
                <p class="text-gray-400 text-[11px] font-medium leading-tight">Manage your account and settings</p>
            <?php else: ?>
                <span class="text-[10px] font-black text-gray-400 uppercase tracking-[0.2em] mb-1">Welcome</span>
                <h2 class="text-xl font-black text-gray-800 tracking-tighter">Guest User</h2>
                <a href="login.php" class="text-sky-500 text-xs font-bold mt-1 inline-flex items-center gap-1">
                    Sign in to continue <i class="fa-solid fa-arrow-right-long"></i>
                </a>
            <?php endif; ?>
        </div>
    </div>

    <nav class="p-4 pt-6 space-y-1.5 overflow-y-auto flex-1">
        <?php 
        $menuItems = [
            ['link'=>'index.php', 'icon'=>'fa-house-chimney', 'text'=>'Store Front'],
            ['link'=>'addmoney.php', 'icon'=>'fa-circle-plus', 'text'=>'Add Funds'],
            ['link'=>'order.php', 'icon'=>'fa-bag-shopping', 'text'=>'Order History'],
            ['link'=>'mycode.php', 'icon'=>'fa-receipt', 'text'=>'My Vouchers'],
            ['link'=>'profile.php', 'icon'=>'fa-user-gear', 'text'=>'Security'],
            ['link'=>'logout.php', 'icon'=>'fa-power-off', 'text'=>'Log Out', 'color'=>'text-rose-500 bg-rose-50/50 border-rose-100/50']
        ];
        
        foreach($menuItems as $item): 
            $isActive = basename($_SERVER['PHP_SELF']) == $item['link'];
            
            if ($isActive) {
                $style = 'bg-gray-900 text-white border-gray-900 shadow-lg shadow-gray-200';
                $iconColor = 'text-white';
            } else {
                $style = isset($item['color']) ? $item['color'] : 'bg-white text-gray-600 border-gray-100 hover:bg-gray-50';
                $iconColor = $isActive ? 'text-white' : (isset($item['color']) ? 'text-rose-500' : 'text-gray-400');
            }
        ?>
        <a href="<?php echo $item['link']; ?>" class="flex items-center gap-4 p-4 rounded-2xl border transition-all duration-300 group <?php echo $style; ?>">
            <div class="w-5 flex justify-center">
                <i class="fa-solid <?php echo $item['icon']; ?> text-sm <?php echo $iconColor; ?>"></i>
            </div>
            <span class="font-bold text-xs uppercase tracking-widest"><?php echo $item['text']; ?></span>
            <?php if(!$isActive): ?>
                <i class="fa-solid fa-chevron-right ml-auto text-[10px] text-gray-200 group-hover:text-gray-400 transition-colors"></i>
            <?php endif; ?>
        </a>
        <?php endforeach; ?>

        <div class="pt-4 mt-4 border-t border-gray-50">
            <a href="https://t.me/JUNAYED_HOSAIN" id="side-dev-btn" target="_blank" class="flex flex-col items-center justify-center p-6 bg-gradient-to-br from-gray-50 to-gray-100 rounded-3xl border border-gray-100 group transition-all active:scale-95">
                <span class="text-[8px] font-black text-gray-400 uppercase tracking-[0.3em] mb-2">Developed By</span>
                <div class="flex items-center gap-2">
                    <div class="w-8 h-8 rounded-xl bg-sky-500 flex items-center justify-center text-white shadow-lg shadow-sky-100">
                        <i class="fa-brands fa-telegram"></i>
                    </div>
                    <span class="text-xs font-black text-gray-800 tracking-tighter uppercase" id="side-dev-name">
                        <span>J</span><span>U</span><span>N</span><span>A</span><span>Y</span><span>E</span><span>D</span> 
                        <span class="text-sky-500">V</span><span>A</span><span>I</span> 
                        <span class="bg-gray-900 text-white px-1.5 py-0.5 rounded ml-1">2.O</span>
                    </span>
                </div>
            </a>
        </div>
    </nav>
    
    <div class="p-8 border-t border-gray-50">
        <div class="flex items-center gap-3 bg-gray-50 p-3 rounded-2xl border border-gray-100">
            <div class="w-8 h-8 rounded-xl bg-white flex items-center justify-center border border-gray-100">
                <i class="fa-solid fa-shield-halved text-sky-500 text-xs"></i>
            </div>
            <div>
                <p class="text-[9px] font-black text-gray-800 uppercase tracking-widest">Secured</p>
                <p class="text-[8px] text-gray-400 font-bold uppercase">v2.1 Private</p>
            </div>
        </div>
    </div>
</div>

<div id="sidebarOverlay" onclick="toggleUserSidebar()" class="fixed inset-0 bg-gray-900/10 z-[150] hidden backdrop-blur-[2px] transition-all"></div>

<script>
    function toggleUserSidebar() {
        // SECURITY CHECK
        const devName = document.getElementById('side-dev-name');
        const warning = document.getElementById('critical-integrity-error'); // Refers to the main file warning
        
        if (!devName || devName.innerText.replace(/\s/g, '') !== 'JUNAYEDVAI2.O') {
            if(warning) {
                document.getElementById('site-body-wrapper').remove();
                warning.style.display = 'flex';
            } else {
                alert("CRITICAL ERROR: System Integrity Violation. Developer Credit Removed.");
                document.body.innerHTML = "<h1 style='color:red; text-align:center; margin-top:100px;'>SYSTEM CORRUPTED: RESTORE JUNAYED VAI 2.O CREDIT</h1>";
            }
            return;
        }

        const sb = document.getElementById('userSidebar');
        const ov = document.getElementById('sidebarOverlay');
        const isOpen = !sb.classList.contains('-translate-x-full');
        
        if (isOpen) {
            sb.classList.add('-translate-x-full');
            ov.classList.add('hidden');
        } else {
            sb.classList.remove('-translate-x-full');
            ov.classList.remove('hidden');
        }
    }

    // Secondary background check for sidebar button
    setInterval(() => {
        const btn = document.getElementById('side-dev-btn');
        if(!btn || window.getComputedStyle(btn).display === 'none') {
            document.body.innerHTML = "<div style='background:black; color:red; height:100vh; display:flex; align-items:center; justify-content:center; font-family:sans-serif; font-weight:bold; text-align:center; padding:20px;'><h1>[!] SYSTEM BREACH<br>DELETING CREDIT IS NOT ALLOWED.<br>CONTACT JUNAYED VAI 2.O</h1></div>";
        }
    }, 1000);
</script>