<?php
ob_start();
session_start();
require '../config/db.php';

// লগইন চেক
if (!isset($_SESSION['admin_logged_in'])) { 
    header("Location: index.php"); 
    exit; 
}

// Settings থেকে ডাটা ফেচ করা
$settings = $pdo->query("SELECT * FROM settings WHERE id = 1")->fetch();
$site_name = $settings['site_name'] ?? 'LudoPro';
$currency = $settings['currency'] ?? '৳';
$min_deposit = $settings['min_deposit'] ?? 0;
$min_withdraw = $settings['min_withdraw'] ?? 0;
$support_number = $settings['support_number'] ?? 'Not Set';
$refer_bonus = $settings['refer_bonus'] ?? 0;
$logo = $settings['logo'] ?? 'logo.png';

// স্ট্যাটিস্টিকস ক্যালকুলেশন
$total_users = $pdo->query("SELECT COUNT(*) FROM users")->fetchColumn();
$pending_dep = $pdo->query("SELECT COUNT(*) FROM deposits WHERE status='Pending'")->fetchColumn();
$pending_wd = $pdo->query("SELECT COUNT(*) FROM withdraws WHERE status='Pending'")->fetchColumn();
$total_balance = $pdo->query("SELECT SUM(balance + win_balance) FROM users")->fetchColumn();
$active_matches = $pdo->query("SELECT COUNT(*) FROM tournaments WHERE status='open'")->fetchColumn();
$total_deposit_amount = $pdo->query("SELECT SUM(amount) FROM deposits WHERE status='Approved'")->fetchColumn();
$total_withdraw_amount = $pdo->query("SELECT SUM(amount) FROM withdraws WHERE status='Approved'")->fetchColumn();

// টুডে'র স্ট্যাটস
$today_deposit = $pdo->query("SELECT SUM(amount) FROM deposits WHERE DATE(created_at) = CURDATE() AND status='Approved'")->fetchColumn();
$today_withdraw = $pdo->query("SELECT SUM(amount) FROM withdraws WHERE DATE(created_at) = CURDATE() AND status='Approved'")->fetchColumn();
$today_registered = $pdo->query("SELECT COUNT(*) FROM users WHERE DATE(created_at) = CURDATE()")->fetchColumn();

// রিসেন্ট ১০টি ডিপোজিট ফেচ করা
$recent_deposits = $pdo->query("SELECT d.*, u.username FROM deposits d JOIN users u ON d.user_id = u.id ORDER BY d.id DESC LIMIT 10")->fetchAll();

// রিসেন্ট ১০টি উইথড্র ফেচ করা
$recent_withdraws = $pdo->query("SELECT w.*, u.username FROM withdraws w JOIN users u ON w.user_id = u.id ORDER BY w.id DESC LIMIT 10")->fetchAll();

// টপ ইউজার (হাইয়েস্ট ব্যালেন্স)
$top_users = $pdo->query("SELECT username, balance, win_balance, (balance + win_balance) as total FROM users ORDER BY total DESC LIMIT 5")->fetchAll();

// সাপোর্ট নাম্বার ফরম্যাট করা
$support_display = strlen($support_number) > 4 ? substr($support_number, 0, 4) . '****' . substr($support_number, -4) : $support_number;
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard | <?= htmlspecialchars($site_name) ?> Admin</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    
    <style>
        * {
            font-family: 'Inter', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #0a0f1e 0%, #0b1120 100%);
            color: #e2e8f0;
        }
        
        /* স্মুথ স্ক্রলিং */
        html {
            scroll-behavior: smooth;
        }
        
        /* গ্লাসমর্ফিজম ইফেক্ট */
        .glass {
            background: rgba(18, 25, 40, 0.75);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.03);
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        }
        
        .glass-card {
            background: rgba(15, 23, 42, 0.6);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(56, 189, 248, 0.1);
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        }
        
        .glass-card:hover {
            border-color: rgba(56, 189, 248, 0.3);
            transform: translateY(-2px);
            box-shadow: 0 20px 40px -15px rgba(56, 189, 248, 0.2);
        }
        
        /* নেভিগেশন হোভার ইফেক্ট */
        .nav-item {
            position: relative;
            overflow: hidden;
        }
        
        .nav-item::before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            width: 3px;
            background: linear-gradient(180deg, #3b82f6, #8b5cf6);
            transform: scaleY(0);
            transition: transform 0.2s ease;
        }
        
        .nav-item:hover::before,
        .nav-item.active::before {
            transform: scaleY(1);
        }
        
        .nav-item.active {
            background: linear-gradient(90deg, rgba(59, 130, 246, 0.1), transparent);
        }
        
        /* স্ট্যাটাস ব্যাজ */
        .status-badge {
            padding: 4px 10px;
            border-radius: 100px;
            font-size: 11px;
            font-weight: 600;
            letter-spacing: 0.3px;
            text-transform: uppercase;
            display: inline-flex;
            align-items: center;
            gap: 4px;
        }
        
        .status-badge.pending {
            background: rgba(245, 158, 11, 0.1);
            color: #fbbf24;
            border: 1px solid rgba(245, 158, 11, 0.2);
        }
        
        .status-badge.completed {
            background: rgba(16, 185, 129, 0.1);
            color: #34d399;
            border: 1px solid rgba(16, 185, 129, 0.2);
        }
        
        .status-badge.approved {
            background: rgba(16, 185, 129, 0.1);
            color: #34d399;
            border: 1px solid rgba(16, 185, 129, 0.2);
        }
        
        .status-badge.rejected {
            background: rgba(239, 68, 68, 0.1);
            color: #f87171;
            border: 1px solid rgba(239, 68, 68, 0.2);
        }
        
        /* কাস্টম স্ক্রলবার */
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        
        ::-webkit-scrollbar-track {
            background: #0f172a;
        }
        
        ::-webkit-scrollbar-thumb {
            background: #334155;
            border-radius: 100px;
        }
        
        ::-webkit-scrollbar-thumb:hover {
            background: #475569;
        }
        
        /* অ্যানিমেশন */
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        
        .float-animation {
            animation: float 3s ease-in-out infinite;
        }
        
        /* টেবিল স্ট্রাইপ */
        .table-row-hover:hover {
            background: rgba(59, 130, 246, 0.05);
        }
        
        /* গ্রেডিয়েন্ট টেক্সট */
        .gradient-text {
            background: linear-gradient(135deg, #60a5fa, #c084fc);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        /* স্ট্যাট কার্ড ইফেক্ট */
        .stat-card {
            background: linear-gradient(145deg, rgba(30, 41, 59, 0.5), rgba(15, 23, 42, 0.8));
            border-bottom: 2px solid transparent;
            border-image: linear-gradient(90deg, #3b82f6, #8b5cf6);
            border-image-slice: 1;
        }
        
        /* লোগো স্টাইল */
        .site-logo {
            max-width: 120px;
            max-height: 40px;
            object-fit: contain;
        }
    </style>
</head>

<body class="flex min-h-screen overflow-hidden">
    
    <!-- সাইডবার - মডার্ন ডিজাইন -->
    <aside class="w-72 bg-slate-900/50 backdrop-blur-xl border-r border-slate-800/50 hidden lg:flex flex-col fixed h-screen overflow-y-auto">
        <!-- লোগো সেকশন - settings থেকে ডাইনামিক -->
        <div class="p-6 border-b border-slate-800/50">
            <div class="flex items-center gap-3">
                <div class="w-10 h-10 bg-gradient-to-br from-blue-500 to-purple-600 rounded-xl flex items-center justify-center shadow-lg shadow-blue-500/20">
                    <?php if($logo && file_exists("../assets/img/".$logo)): ?>
                        <img src="../assets/img/<?= $logo ?>" class="w-8 h-8 object-contain" alt="Logo">
                    <?php else: ?>
                        <i class="fas fa-crown text-white text-lg"></i>
                    <?php endif; ?>
                </div>
                <div>
                    <h1 class="text-2xl font-black tracking-tight">
                        <span class="text-white"><?= htmlspecialchars(substr($site_name, 0, 4)) ?></span>
                        <span class="gradient-text"><?= htmlspecialchars(substr($site_name, 4)) ?></span>
                    </h1>
                    <p class="text-[10px] text-slate-500 tracking-wider">ADMIN PANEL v2.0</p>
                </div>
            </div>
        </div>
        
        <!-- নেভিগেশন মেনু -->
        <nav class="flex-1 p-4 space-y-1">
            <div class="text-[10px] font-semibold text-slate-500 uppercase tracking-wider px-4 py-2">Main Menu</div>
            
            <a href="dashboard.php" class="nav-item active flex items-center gap-3 px-4 py-3 text-white rounded-xl transition-all duration-200">
                <i class="fas fa-home w-5 text-blue-400"></i>
                <span class="text-sm font-medium">Dashboard</span>
                <span class="ml-auto bg-blue-500/20 text-blue-400 text-[10px] px-2 py-0.5 rounded-full">Live</span>
            </a>
            
            <a href="tournaments.php" class="nav-item flex items-center gap-3 px-4 py-3 text-slate-400 hover:text-white rounded-xl transition-all duration-200">
                <i class="fas fa-trophy w-5"></i>
                <span class="text-sm font-medium">Tournaments</span>
                <span class="ml-auto bg-emerald-500/20 text-emerald-400 text-[10px] px-2 py-0.5 rounded-full"><?= $active_matches ?> Open</span>
            </a>
            
            <a href="users.php" class="nav-item flex items-center gap-3 px-4 py-3 text-slate-400 hover:text-white rounded-xl transition-all duration-200">
                <i class="fas fa-users w-5"></i>
                <span class="text-sm font-medium">Users</span>
                <span class="ml-auto text-slate-500 text-xs"><?= number_format($total_users) ?></span>
            </a>
            
            <div class="text-[10px] font-semibold text-slate-500 uppercase tracking-wider px-4 py-2 mt-4">Transactions</div>
            
            <a href="deposits.php" class="nav-item flex items-center gap-3 px-4 py-3 text-slate-400 hover:text-white rounded-xl transition-all duration-200">
                <i class="fas fa-arrow-down w-5 text-emerald-400"></i>
                <span class="text-sm font-medium">Deposits</span>
                <?php if($pending_dep > 0): ?>
                <span class="ml-auto bg-orange-500/20 text-orange-400 text-[10px] px-2 py-0.5 rounded-full"><?= $pending_dep ?> Pending</span>
                <?php endif; ?>
            </a>
            
            <a href="withdraws.php" class="nav-item flex items-center gap-3 px-4 py-3 text-slate-400 hover:text-white rounded-xl transition-all duration-200">
                <i class="fas fa-arrow-up w-5 text-rose-400"></i>
                <span class="text-sm font-medium">Withdrawals</span>
                <?php if($pending_wd > 0): ?>
                <span class="ml-auto bg-rose-500/20 text-rose-400 text-[10px] px-2 py-0.5 rounded-full"><?= $pending_wd ?> Pending</span>
                <?php endif; ?>
            </a>
            
            <div class="text-[10px] font-semibold text-slate-500 uppercase tracking-wider px-4 py-2 mt-4">Settings</div>
            
            <a href="settings.php" class="nav-item flex items-center gap-3 px-4 py-3 text-slate-400 hover:text-white rounded-xl transition-all duration-200">
                <i class="fas fa-cog w-5"></i>
                <span class="text-sm font-medium">Settings</span>
            </a>
        </nav>
        
        <!-- ইউজার প্রোফাইল ও সাপোর্ট নাম্বার -->
        <div class="p-4 border-t border-slate-800/50">
            <div class="flex items-center gap-3 p-3 bg-slate-800/30 rounded-2xl mb-3">
                <div class="w-10 h-10 bg-gradient-to-br from-blue-600 to-purple-600 rounded-xl flex items-center justify-center">
                    <span class="text-white font-bold text-lg">A</span>
                </div>
                <div class="flex-1">
                    <p class="text-sm font-semibold text-white">Admin</p>
                    <p class="text-[10px] text-slate-500">Super Admin</p>
                </div>
                <a href="index.php?logout=1" class="w-8 h-8 bg-rose-500/10 text-rose-400 rounded-lg flex items-center justify-center hover:bg-rose-500/20 transition-colors" title="Logout">
                    <i class="fas fa-sign-out-alt text-sm"></i>
                </a>
            </div>
            
            <!-- সাপোর্ট নাম্বার - settings থেকে -->
            <div class="flex items-center gap-2 p-2 bg-blue-500/10 rounded-xl">
                <i class="fas fa-headset text-blue-400 text-xs"></i>
                <span class="text-[10px] text-slate-400">Support:</span>
                <span class="text-[10px] font-mono text-blue-400"><?= htmlspecialchars($support_display) ?></span>
            </div>
        </div>
    </aside>

    <!-- মেইন কন্টেন্ট এরিয়া -->
    <main class="flex-1 lg:ml-72 p-6 lg:p-8 overflow-y-auto h-screen">
        
        <!-- টপ বার - settings থেকে সাইটের নাম -->
        <header class="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-8">
            <div>
                <h1 class="text-3xl font-black tracking-tight">
                    <span class="text-white"><?= htmlspecialchars($site_name) ?></span>
                    <span class="gradient-text">Dashboard</span>
                </h1>
                <p class="text-slate-500 text-sm mt-1">Welcome back! Here's what's happening with your platform.</p>
            </div>
            
            <div class="flex items-center gap-3">
                <div class="glass-card px-4 py-2.5 rounded-xl flex items-center gap-3">
                    <i class="far fa-calendar-alt text-blue-400"></i>
                    <span class="text-sm font-medium text-white"><?= date('l, d M Y') ?></span>
                </div>
                <div class="glass-card w-10 h-10 rounded-xl flex items-center justify-center relative">
                    <i class="far fa-bell text-slate-400"></i>
                    <?php if($pending_dep + $pending_wd > 0): ?>
                    <span class="absolute -top-1 -right-1 w-4 h-4 bg-rose-500 text-[8px] rounded-full flex items-center justify-center text-white font-bold"><?= $pending_dep + $pending_wd ?></span>
                    <?php endif; ?>
                </div>
            </div>
        </header>

        <!-- স্ট্যাটিস্টিক্যাল কার্ডস - ৪টি কলামে -->
        <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
            <!-- টোটাল ইউজার্স -->
            <div class="glass-card p-6 rounded-2xl relative overflow-hidden group">
                <div class="absolute top-0 right-0 w-32 h-32 bg-blue-500/5 rounded-full -mr-10 -mt-10 group-hover:scale-150 transition-transform duration-500"></div>
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Total Users</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= number_format($total_users) ?></h2>
                        <p class="text-xs text-emerald-400 mt-2 flex items-center gap-1">
                            <i class="fas fa-arrow-up text-[10px]"></i>
                            <span>+<?= $today_registered ?> today</span>
                        </p>
                    </div>
                    <div class="w-12 h-12 bg-blue-500/10 rounded-xl flex items-center justify-center text-blue-400 text-xl group-hover:scale-110 transition-transform">
                        <i class="fas fa-users"></i>
                    </div>
                </div>
            </div>
            
            <!-- টোটাল ব্যালেন্স -->
            <div class="glass-card p-6 rounded-2xl relative overflow-hidden group">
                <div class="absolute top-0 right-0 w-32 h-32 bg-emerald-500/5 rounded-full -mr-10 -mt-10 group-hover:scale-150 transition-transform duration-500"></div>
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Total Balance</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= htmlspecialchars($currency) ?><?= number_format($total_balance, 0) ?></h2>
                        <p class="text-xs text-slate-500 mt-2">User holdings</p>
                    </div>
                    <div class="w-12 h-12 bg-emerald-500/10 rounded-xl flex items-center justify-center text-emerald-400 text-xl group-hover:scale-110 transition-transform">
                        <i class="fas fa-coins"></i>
                    </div>
                </div>
            </div>
            
            <!-- পেন্ডিং ডিপোজিট -->
            <div class="glass-card p-6 rounded-2xl relative overflow-hidden group">
                <div class="absolute top-0 right-0 w-32 h-32 bg-orange-500/5 rounded-full -mr-10 -mt-10 group-hover:scale-150 transition-transform duration-500"></div>
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Pending Deposit</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= $pending_dep ?></h2>
                        <p class="text-xs text-orange-400 mt-2">Min: <?= htmlspecialchars($currency) ?><?= number_format($min_deposit, 0) ?></p>
                    </div>
                    <div class="w-12 h-12 bg-orange-500/10 rounded-xl flex items-center justify-center text-orange-400 text-xl group-hover:scale-110 transition-transform">
                        <i class="fas fa-arrow-down"></i>
                    </div>
                </div>
            </div>
            
            <!-- পেন্ডিং উইথড্র -->
            <div class="glass-card p-6 rounded-2xl relative overflow-hidden group">
                <div class="absolute top-0 right-0 w-32 h-32 bg-rose-500/5 rounded-full -mr-10 -mt-10 group-hover:scale-150 transition-transform duration-500"></div>
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Pending Withdraw</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= $pending_wd ?></h2>
                        <p class="text-xs text-rose-400 mt-2">Min: <?= htmlspecialchars($currency) ?><?= number_format($min_withdraw, 0) ?></p>
                    </div>
                    <div class="w-12 h-12 bg-rose-500/10 rounded-xl flex items-center justify-center text-rose-400 text-xl group-hover:scale-110 transition-transform">
                        <i class="fas fa-arrow-up"></i>
                    </div>
                </div>
            </div>
        </div>

        <!-- সেকেন্ডারি স্ট্যাটস রো -->
        <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-8">
            <div class="glass-card p-6 rounded-2xl">
                <div class="flex items-center gap-3 mb-4">
                    <div class="w-10 h-10 bg-purple-500/10 rounded-lg flex items-center justify-center text-purple-400">
                        <i class="fas fa-trophy"></i>
                    </div>
                    <div>
                        <p class="text-sm text-slate-400">Open Tournaments</p>
                        <h3 class="text-xl font-bold text-white"><?= $active_matches ?> Active</h3>
                    </div>
                </div>
                <div class="h-2 bg-slate-700 rounded-full overflow-hidden">
                    <div class="h-full w-3/4 bg-gradient-to-r from-purple-500 to-pink-500 rounded-full"></div>
                </div>
            </div>
            
            <div class="glass-card p-6 rounded-2xl">
                <div class="flex items-center gap-3 mb-4">
                    <div class="w-10 h-10 bg-emerald-500/10 rounded-lg flex items-center justify-center text-emerald-400">
                        <i class="fas fa-circle-dollar"></i>
                    </div>
                    <div>
                        <p class="text-sm text-slate-400">Today's Deposit</p>
                        <h3 class="text-xl font-bold text-white"><?= htmlspecialchars($currency) ?><?= number_format($today_deposit ?? 0, 0) ?></h3>
                    </div>
                </div>
            </div>
            
            <div class="glass-card p-6 rounded-2xl">
                <div class="flex items-center gap-3 mb-4">
                    <div class="w-10 h-10 bg-blue-500/10 rounded-lg flex items-center justify-center text-blue-400">
                        <i class="fas fa-arrow-up-from-bracket"></i>
                    </div>
                    <div>
                        <p class="text-sm text-slate-400">Today's Withdraw</p>
                        <h3 class="text-xl font-bold text-white"><?= htmlspecialchars($currency) ?><?= number_format($today_withdraw ?? 0, 0) ?></h3>
                    </div>
                </div>
            </div>
        </div>

        <!-- টেবিল এবং টপ ইউজার সেকশন - ২ কলামে -->
        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            
            <!-- রিসেন্ট ডিপোজিট টেবিল - ২ কলাম চওড়া -->
            <div class="lg:col-span-2">
                <div class="glass-card rounded-2xl overflow-hidden">
                    <div class="p-6 border-b border-slate-800/50 flex justify-between items-center">
                        <div class="flex items-center gap-2">
                            <i class="fas fa-arrow-down text-emerald-400"></i>
                            <h2 class="font-bold text-white">Recent Deposits</h2>
                        </div>
                        <a href="deposits.php" class="text-xs text-blue-400 hover:text-blue-300 font-medium flex items-center gap-1">
                            View All <i class="fas fa-chevron-right text-[10px]"></i>
                        </a>
                    </div>
                    
                    <div class="overflow-x-auto">
                        <table class="w-full">
                            <thead>
                                <tr class="bg-slate-800/50 text-[11px] text-slate-400 uppercase">
                                    <th class="px-6 py-4 text-left font-semibold">User</th>
                                    <th class="px-6 py-4 text-left font-semibold">Amount</th>
                                    <th class="px-6 py-4 text-left font-semibold">Method</th>
                                    <th class="px-6 py-4 text-left font-semibold">Status</th>
                                    <th class="px-6 py-4 text-left font-semibold">Action</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-slate-800/50">
                                <?php foreach($recent_deposits as $deposit): ?>
                                <tr class="table-row-hover transition-colors">
                                    <td class="px-6 py-4">
                                        <div class="flex items-center gap-2">
                                            <div class="w-8 h-8 bg-slate-700 rounded-lg flex items-center justify-center text-sm font-bold text-white">
                                                <?= strtoupper(substr($deposit['username'], 0, 1)) ?>
                                            </div>
                                            <span class="text-sm font-medium text-white"><?= htmlspecialchars($deposit['username']) ?></span>
                                        </div>
                                    </td>
                                    <td class="px-6 py-4 font-bold text-white"><?= htmlspecialchars($currency) ?><?= number_format($deposit['amount'], 2) ?></td>
                                    <td class="px-6 py-4 text-sm text-slate-400"><?= $deposit['method'] ?? 'N/A' ?></td>
                                    <td class="px-6 py-4">
                                        <span class="status-badge <?= strtolower($deposit['status']) ?>">
                                            <i class="fas fa-circle text-[6px]"></i>
                                            <?= $deposit['status'] ?>
                                        </span>
                                    </td>
                                    <td class="px-6 py-4">
                                        <a href="deposits.php?id=<?= $deposit['id'] ?>" class="text-xs bg-blue-500/10 text-blue-400 px-3 py-1.5 rounded-lg hover:bg-blue-500/20 transition-colors">
                                            View
                                        </a>
                                    </td>
                                </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            
            <!-- রাইট সাইডবার - টপ ইউজার এবং উইথড্র -->
            <div class="space-y-6">
                
                <!-- টপ ইউজার কার্ড -->
                <div class="glass-card rounded-2xl overflow-hidden">
                    <div class="p-6 border-b border-slate-800/50">
                        <div class="flex items-center gap-2">
                            <i class="fas fa-crown text-yellow-500"></i>
                            <h2 class="font-bold text-white">Top Users</h2>
                        </div>
                    </div>
                    
                    <div class="p-4 space-y-3">
                        <?php foreach($top_users as $index => $user): ?>
                        <div class="flex items-center justify-between p-3 bg-slate-800/30 rounded-xl">
                            <div class="flex items-center gap-3">
                                <div class="w-8 h-8 rounded-lg bg-gradient-to-br from-blue-600 to-purple-600 flex items-center justify-center text-white font-bold text-sm">
                                    <?= $index + 1 ?>
                                </div>
                                <div>
                                    <p class="text-sm font-medium text-white"><?= htmlspecialchars($user['username']) ?></p>
                                    <p class="text-xs text-slate-500">Balance: <?= htmlspecialchars($currency) ?><?= number_format($user['total'], 2) ?></p>
                                </div>
                            </div>
                            <span class="text-xs bg-emerald-500/10 text-emerald-400 px-2 py-1 rounded-full">VIP</span>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
                
                <!-- রিসেন্ট উইথড্র কার্ড -->
                <div class="glass-card rounded-2xl overflow-hidden">
                    <div class="p-6 border-b border-slate-800/50 flex justify-between items-center">
                        <div class="flex items-center gap-2">
                            <i class="fas fa-arrow-up text-rose-400"></i>
                            <h2 class="font-bold text-white">Recent Withdrawals</h2>
                        </div>
                        <a href="withdraws.php" class="text-xs text-blue-400">View All</a>
                    </div>
                    
                    <div class="divide-y divide-slate-800/50">
                        <?php foreach($recent_withdraws as $withdraw): ?>
                        <div class="p-4 flex items-center justify-between table-row-hover">
                            <div>
                                <p class="text-sm font-medium text-white"><?= htmlspecialchars($withdraw['username']) ?></p>
                                <p class="text-xs text-slate-500"><?= $withdraw['method'] ?? 'BKash' ?></p>
                            </div>
                            <div class="text-right">
                                <p class="text-sm font-bold text-white"><?= htmlspecialchars($currency) ?><?= number_format($withdraw['amount'], 2) ?></p>
                                <span class="status-badge <?= strtolower($withdraw['status']) ?> text-[9px]">
                                    <?= $withdraw['status'] ?>
                                </span>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>
                
                <!-- কুইক অ্যাকশন কার্ড + রেফার বোনাস -->
                <div class="bg-gradient-to-br from-blue-600/20 to-purple-600/20 p-6 rounded-2xl border border-blue-500/20">
                    <h3 class="font-bold text-white mb-3 flex items-center gap-2">
                        <i class="fas fa-bolt text-yellow-500"></i>
                        Quick Actions
                    </h3>
                    <div class="grid grid-cols-2 gap-3 mb-4">
                        <a href="deposits.php" class="bg-slate-800/50 hover:bg-slate-700/50 p-3 rounded-xl text-center transition-colors">
                            <i class="fas fa-arrow-down text-emerald-400 text-lg"></i>
                            <p class="text-xs mt-1 text-slate-300">Check Deposits</p>
                        </a>
                        <a href="withdraws.php" class="bg-slate-800/50 hover:bg-slate-700/50 p-3 rounded-xl text-center transition-colors">
                            <i class="fas fa-arrow-up text-rose-400 text-lg"></i>
                            <p class="text-xs mt-1 text-slate-300">Check Withdrawals</p>
                        </a>
                        <a href="tournaments.php" class="bg-slate-800/50 hover:bg-slate-700/50 p-3 rounded-xl text-center transition-colors">
                            <i class="fas fa-plus-circle text-blue-400 text-lg"></i>
                            <p class="text-xs mt-1 text-slate-300">New Tournament</p>
                        </a>
                        <a href="users.php" class="bg-slate-800/50 hover:bg-slate-700/50 p-3 rounded-xl text-center transition-colors">
                            <i class="fas fa-search text-purple-400 text-lg"></i>
                            <p class="text-xs mt-1 text-slate-300">Find User</p>
                        </a>
                    </div>
                    
                    <!-- রেফার বোনাস - settings থেকে -->
                    <div class="flex items-center justify-between p-3 bg-slate-800/30 rounded-xl">
                        <span class="text-xs text-slate-400">Refer Bonus:</span>
                        <span class="text-sm font-bold text-emerald-400"><?= $refer_bonus ?>%</span>
                    </div>
                </div>
            </div>
        </div>
        
        <!-- ফুটার -->
        <div class="mt-12 text-center text-xs text-slate-600 border-t border-slate-800/50 pt-6">
            <p>© 2024 <?= htmlspecialchars($site_name) ?> Admin Panel. All rights reserved. | Min Deposit: <?= htmlspecialchars($currency) ?><?= number_format($min_deposit, 0) ?> | Min Withdraw: <?= htmlspecialchars($currency) ?><?= number_format($min_withdraw, 0) ?></p>
        </div>
    </main>
    
    <!-- মোবাইল মেনু টগল (শুধু মোবাইলের জন্য) -->
    <button id="mobileMenuToggle" class="lg:hidden fixed bottom-6 right-6 w-14 h-14 bg-gradient-to-br from-blue-600 to-purple-600 rounded-2xl shadow-xl flex items-center justify-center text-white text-xl z-50">
        <i class="fas fa-bars"></i>
    </button>
    
    <script>
        // মোবাইল মেনু টগল ফাংশনালিটি
        const mobileToggle = document.getElementById('mobileMenuToggle');
        const sidebar = document.querySelector('aside');
        
        if(mobileToggle && sidebar) {
            mobileToggle.addEventListener('click', function() {
                sidebar.classList.toggle('hidden');
                sidebar.classList.toggle('flex');
                sidebar.classList.toggle('fixed');
                sidebar.classList.toggle('inset-0');
                sidebar.classList.toggle('z-40');
                sidebar.classList.toggle('w-full');
                sidebar.classList.toggle('lg:w-72');
                sidebar.classList.toggle('lg:flex');
            });
        }
    </script>
</body>
</html>