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

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

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

$msg = ""; 
$msgType = "";

// ১. ডিপোজিট অ্যাকশন হ্যান্ডলিং
if(isset($_GET['action']) && isset($_GET['id'])) {
    $did = $_GET['id']; 
    $status = $_GET['status']; 
    $amount = $_GET['amount'] ?? 0; 
    $uid = $_GET['uid'] ?? 0;

    // ডাবল চেক: ট্রানজ্যাকশনটি এখনও পেন্ডিং কিনা
    $check = $pdo->prepare("SELECT status FROM deposits WHERE id = ?");
    $check->execute([$did]);
    $currentStatus = $check->fetchColumn();

    if($currentStatus == 'Pending') {
        if($status == 'Approved') {
            try {
                $pdo->beginTransaction();
                // ইউজারের ব্যালেন্সে টাকা যোগ করা
                $pdo->prepare("UPDATE users SET balance = balance + ? WHERE id = ?")->execute([$amount, $uid]);
                $pdo->prepare("UPDATE deposits SET status='Approved' WHERE id=?")->execute([$did]);
                
                // নোটিফিকেশন তৈরি করা
                $pdo->prepare("INSERT INTO notifications (user_id, msg, type) VALUES (?, ?, ?)")
                    ->execute([$uid, "Your deposit of {$currency}{$amount} has been approved!", 'success']);
                
                $pdo->commit();
                $msg = "Deposit Approved Successfully!"; 
                $msgType = "success";
            } catch(Exception $e) {
                $pdo->rollBack();
                $msg = "Error processing deposit!"; 
                $msgType = "error";
            }
        } else {
            // রিজেক্ট করা
            $pdo->prepare("UPDATE deposits SET status='Rejected' WHERE id=?")->execute([$did]);
            $pdo->prepare("INSERT INTO notifications (user_id, msg, type) VALUES (?, ?, ?)")
                ->execute([$uid, "Your deposit request has been rejected. Please contact support.", 'error']);
            $msg = "Deposit Rejected!"; 
            $msgType = "error";
        }
    } else {
        $msg = "This deposit has already been processed!"; 
        $msgType = "info";
    }
}

// বাল্ক অ্যাকশন (একাধিক ডিপোজিট একসাথে)
if(isset($_POST['bulk_action']) && isset($_POST['selected_ids'])) {
    $ids = $_POST['selected_ids'];
    $action = $_POST['bulk_action'];
    
    if(!empty($ids)) {
        $placeholders = implode(',', array_fill(0, count($ids), '?'));
        
        if($action == 'approve_selected') {
            // সিলেক্টেড ডিপোজিটগুলোর ডিটেইলস ফেচ
            $stmt = $pdo->prepare("SELECT * FROM deposits WHERE id IN ($placeholders) AND status='Pending'");
            $stmt->execute($ids);
            $selected_deposits = $stmt->fetchAll();
            
            try {
                $pdo->beginTransaction();
                foreach($selected_deposits as $dep) {
                    $pdo->prepare("UPDATE users SET balance = balance + ? WHERE id = ?")->execute([$dep['amount'], $dep['user_id']]);
                    $pdo->prepare("UPDATE deposits SET status='Approved' WHERE id=?")->execute([$dep['id']]);
                }
                $pdo->commit();
                $msg = count($ids) . " deposits approved successfully!"; 
                $msgType = "success";
            } catch(Exception $e) {
                $pdo->rollBack();
                $msg = "Error processing bulk approval!"; 
                $msgType = "error";
            }
        } elseif($action == 'reject_selected') {
            $pdo->prepare("UPDATE deposits SET status='Rejected' WHERE id IN ($placeholders)")->execute($ids);
            $msg = count($ids) . " deposits rejected!"; 
            $msgType = "info";
        }
    }
}

// ২. পেন্ডিং ডিপোজিট লিস্ট ফেচিং
$deposits = $pdo->query("SELECT d.*, u.username, u.phone, u.balance FROM deposits d JOIN users u ON d.user_id = u.id WHERE d.status = 'Pending' ORDER BY d.id DESC")->fetchAll();

// ৩. টোটাল পরিসংখ্যান
$total_pending_amount = $pdo->query("SELECT SUM(amount) FROM deposits WHERE status='Pending'")->fetchColumn();
$total_approved_today = $pdo->query("SELECT SUM(amount) FROM deposits WHERE status='Approved' AND DATE(created_at) = CURDATE()")->fetchColumn();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Deposit Management | <?= 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 href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    
    <style>
        * {
            font-family: 'Inter', sans-serif;
        }
        
        body {
            background: linear-gradient(135deg, #0a0f1e 0%, #0b1120 100%);
            color: #e2e8f0;
        }
        
        /* গ্লাসমর্ফিজম ইফেক্ট */
        .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.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);
        }
        
        /* গ্রেডিয়েন্ট টেক্সট */
        .gradient-text {
            background: linear-gradient(135deg, #60a5fa, #c084fc);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        /* কাস্টম স্ক্রলবার */
        ::-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;
        }
        
        /* টেবিল স্ট্রাইপ */
        .table-row-hover:hover {
            background: rgba(59, 130, 246, 0.05);
        }
        
        /* অ্যাকশন বাটন */
        .action-btn {
            width: 36px;
            height: 36px;
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s ease;
        }
    </style>
</head>
<body class="flex min-h-screen overflow-hidden">
    
    <!-- সাইডবার - settings থেকে ডাইনামিক -->
    <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">
        <!-- লোগো সেকশন -->
        <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 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-home w-5"></i>
                <span class="text-sm font-medium">Dashboard</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>
            </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>
            </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 active flex items-center gap-3 px-4 py-3 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>
                <span class="ml-auto bg-orange-500/20 text-orange-400 text-[10px] px-2 py-0.5 rounded-full"><?= count($deposits) ?> Pending</span>
            </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>
            </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 mt-auto">
            <div class="flex items-center gap-3 p-3 bg-slate-800/30 rounded-2xl">
                <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>
        </div>
    </aside>

    <!-- মেইন কন্টেন্ট এরিয়া -->
    <main class="flex-1 lg:ml-72 p-6 lg:p-8 overflow-y-auto h-screen">
        
        <!-- টপ বার -->
        <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">Deposit</span>
                    <span class="gradient-text">Management</span>
                </h1>
                <p class="text-slate-500 text-sm mt-1">Review and process user deposit requests.</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(count($deposits) > 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"><?= count($deposits) ?></span>
                    <?php endif; ?>
                </div>
            </div>
        </header>

        <!-- এলার্ট মেসেজ -->
        <?php if($msg): ?>
        <script>
            Swal.fire({
                icon: '<?= $msgType ?>',
                title: '<?= $msg ?>',
                toast: true,
                position: 'top-end',
                showConfirmButton: false,
                timer: 3000,
                background: '#1e293b',
                color: '#fff',
                iconColor: '<?= $msgType == "success" ? "#34d399" : ($msgType == "error" ? "#f87171" : "#60a5fa") ?>'
            });
        </script>
        <?php endif; ?>

        <!-- স্ট্যাটিস্টিক্যাল কার্ডস -->
        <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">
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Pending Requests</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= count($deposits) ?></h2>
                    </div>
                    <div class="w-12 h-12 bg-orange-500/10 rounded-xl flex items-center justify-center text-orange-400 text-xl">
                        <i class="fas fa-clock"></i>
                    </div>
                </div>
            </div>
            
            <div class="glass-card p-6 rounded-2xl">
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Pending Amount</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= htmlspecialchars($currency) ?><?= number_format($total_pending_amount ?? 0, 0) ?></h2>
                    </div>
                    <div class="w-12 h-12 bg-yellow-500/10 rounded-xl flex items-center justify-center text-yellow-400 text-xl">
                        <i class="fas fa-coins"></i>
                    </div>
                </div>
            </div>
            
            <div class="glass-card p-6 rounded-2xl">
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Approved Today</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= htmlspecialchars($currency) ?><?= number_format($total_approved_today ?? 0, 0) ?></h2>
                    </div>
                    <div class="w-12 h-12 bg-emerald-500/10 rounded-xl flex items-center justify-center text-emerald-400 text-xl">
                        <i class="fas fa-check-circle"></i>
                    </div>
                </div>
            </div>
            
            <div class="glass-card p-6 rounded-2xl">
                <div class="flex items-start justify-between">
                    <div>
                        <p class="text-slate-500 text-xs font-medium uppercase tracking-wider">Min Deposit</p>
                        <h2 class="text-3xl font-black text-white mt-2"><?= htmlspecialchars($currency) ?><?= number_format($min_deposit, 0) ?></h2>
                    </div>
                    <div class="w-12 h-12 bg-blue-500/10 rounded-xl flex items-center justify-center text-blue-400 text-xl">
                        <i class="fas fa-arrow-down"></i>
                    </div>
                </div>
            </div>
        </div>

        <!-- বাল্ক অ্যাকশন ফর্ম -->
        <?php if(!empty($deposits)): ?>
        <form method="POST" id="bulkForm" class="mb-6">
            <div class="glass-card p-4 rounded-xl flex flex-wrap gap-4 items-center justify-between">
                <div class="flex items-center gap-3">
                    <input type="checkbox" id="selectAll" class="w-4 h-4 rounded border-slate-600 bg-slate-800 text-blue-600 focus:ring-blue-500">
                    <label for="selectAll" class="text-sm text-slate-300">Select All</label>
                </div>
                
                <div class="flex gap-3">
                    <select name="bulk_action" class="bg-slate-800 border border-slate-700 rounded-xl px-4 py-2 text-sm text-white" required>
                        <option value="">Bulk Action</option>
                        <option value="approve_selected">Approve Selected</option>
                        <option value="reject_selected">Reject Selected</option>
                    </select>
                    
                    <button type="submit" onclick="return confirm('Are you sure you want to process selected deposits?')" class="bg-blue-600 hover:bg-blue-500 text-white px-6 py-2 rounded-xl text-sm font-bold transition">
                        Apply to Selected
                    </button>
                </div>
            </div>
        </form>
        <?php endif; ?>

        <!-- ডিপোজিট টেবিল -->
        <div class="glass-card rounded-2xl overflow-hidden border border-slate-700">
            <div class="p-6 border-b border-slate-700/50 bg-slate-800/30">
                <div class="flex justify-between items-center">
                    <h2 class="font-bold text-white flex items-center gap-2">
                        <i class="fas fa-list text-blue-400"></i>
                        Pending Deposit Requests
                    </h2>
                    <span class="bg-orange-500/10 text-orange-400 text-xs px-3 py-1.5 rounded-full font-medium">
                        <?= count($deposits) ?> Request(s) Pending
                    </span>
                </div>
            </div>
            
            <div class="overflow-x-auto">
                <table class="w-full text-left">
                    <thead>
                        <tr class="bg-slate-800/50 text-[11px] text-slate-400 uppercase">
                            <th class="px-6 py-4 w-10">
                                <span class="sr-only">Select</span>
                            </th>
                            <th class="px-6 py-4 font-semibold">User Details</th>
                            <th class="px-6 py-4 font-semibold">Payment Info</th>
                            <th class="px-6 py-4 font-semibold">Amount</th>
                            <th class="px-6 py-4 font-semibold">Date & Time</th>
                            <th class="px-6 py-4 font-semibold text-center">Actions</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-slate-800/50">
                        <?php if(empty($deposits)): ?>
                            <tr>
                                <td colspan="6" class="px-6 py-16 text-center">
                                    <div class="flex flex-col items-center gap-3">
                                        <div class="w-20 h-20 bg-slate-800/50 rounded-full flex items-center justify-center text-4xl">
                                            💰
                                        </div>
                                        <h3 class="text-lg font-semibold text-white">No Pending Deposits</h3>
                                        <p class="text-sm text-slate-500">All deposit requests have been processed.</p>
                                    </div>
                                </td>
                            </tr>
                        <?php endif; ?>

                        <?php foreach($deposits as $d): ?>
                        <tr class="table-row-hover transition-colors">
                            <td class="px-6 py-4">
                                <input type="checkbox" name="selected_ids[]" value="<?= $d['id'] ?>" form="bulkForm" class="row-checkbox w-4 h-4 rounded border-slate-600 bg-slate-800 text-blue-600 focus:ring-blue-500">
                            </td>
                            <td class="px-6 py-4">
                                <div class="flex items-center gap-3">
                                    <div class="w-10 h-10 bg-gradient-to-br from-blue-600/30 to-purple-600/30 rounded-xl flex items-center justify-center text-lg font-bold text-white">
                                        <?= strtoupper(substr($d['username'], 0, 1)) ?>
                                    </div>
                                    <div>
                                        <div class="font-bold text-white"><?= htmlspecialchars($d['username']) ?></div>
                                        <div class="text-xs text-slate-500 flex items-center gap-1 mt-0.5">
                                            <i class="fas fa-phone-alt text-[8px]"></i>
                                            <?= $d['phone'] ?>
                                        </div>
                                        <div class="text-[10px] text-slate-600">ID: <?= $d['user_id'] ?></div>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4">
                                <div class="space-y-1">
                                    <span class="status-badge pending text-[9px] inline-flex">
                                        <i class="fas fa-university"></i>
                                        <?= $d['method'] ?>
                                    </span>
                                    <div class="text-xs font-mono text-slate-400 bg-slate-800/30 px-2 py-1 rounded-lg select-all">
                                        <?= $d['transaction_id'] ?>
                                    </div>
                                </div>
                            </td>
                            <td class="px-6 py-4">
                                <div class="text-xl font-black text-emerald-400"><?= htmlspecialchars($currency) ?><?= number_format($d['amount'], 2) ?></div>
                                <div class="text-[10px] text-slate-500">Current Balance: <?= htmlspecialchars($currency) ?><?= number_format($d['balance'] ?? 0, 0) ?></div>
                            </td>
                            <td class="px-6 py-4">
                                <div class="text-sm text-white"><?= date('d M Y', strtotime($d['created_at'])) ?></div>
                                <div class="text-xs text-slate-500"><?= date('h:i A', strtotime($d['created_at'])) ?></div>
                            </td>
                            <td class="px-6 py-4">
                                <div class="flex items-center justify-center gap-2">
                                    <a href="?action=process&status=Approved&id=<?= $d['id'] ?>&amount=<?= $d['amount'] ?>&uid=<?= $d['user_id'] ?>" 
                                       onclick="return confirm('Approve this deposit of <?= htmlspecialchars($currency) ?><?= $d['amount'] ?> for <?= htmlspecialchars($d['username']) ?>?')"
                                       class="action-btn bg-emerald-500/10 hover:bg-emerald-500 text-emerald-400 hover:text-white transition-all group"
                                       title="Approve Deposit">
                                        <i class="fas fa-check"></i>
                                    </a>
                                    
                                    <a href="?action=process&status=Rejected&id=<?= $d['id'] ?>&amount=0&uid=<?= $d['user_id'] ?>" 
                                       onclick="return confirm('Reject this deposit request?')"
                                       class="action-btn bg-rose-500/10 hover:bg-rose-500 text-rose-400 hover:text-white transition-all group"
                                       title="Reject Deposit">
                                        <i class="fas fa-times"></i>
                                    </a>
                                    
                                    <button onclick="viewDetails(<?= htmlspecialchars(json_encode($d)) ?>)" 
                                            class="action-btn bg-blue-500/10 hover:bg-blue-500 text-blue-400 hover:text-white transition-all group"
                                            title="View Details">
                                        <i class="fas fa-eye"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            
            <?php if(!empty($deposits)): ?>
            <div class="p-4 border-t border-slate-700/50 bg-slate-800/30 text-xs text-slate-500">
                <i class="fas fa-info-circle mr-1"></i>
                Click on Transaction ID to copy. Double-check user details before approving.
            </div>
            <?php endif; ?>
        </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. | Secure Deposit Management System</p>
        </div>
    </main>

    <!-- ডিটেইলস ভিউ মোডাল -->
    <div id="detailsModal" class="hidden fixed inset-0 bg-black/80 backdrop-blur-sm flex items-center justify-center z-50 p-4">
        <div class="glass-card rounded-2xl w-full max-w-md border border-slate-700">
            <div class="p-6 border-b border-slate-700 flex justify-between items-center">
                <h2 class="text-xl font-bold text-white flex items-center gap-2">
                    <i class="fas fa-info-circle text-blue-500"></i>
                    Deposit Details
                </h2>
                <button onclick="document.getElementById('detailsModal').classList.add('hidden')" class="w-8 h-8 bg-slate-700 rounded-lg hover:bg-slate-600 transition flex items-center justify-center">
                    <i class="fas fa-times text-slate-400"></i>
                </button>
            </div>
            
            <div class="p-6 space-y-4" id="modalContent">
                <!-- জাভাস্ক্রিপ্ট দিয়ে পূরণ করা হবে -->
            </div>
            
            <div class="p-6 border-t border-slate-700">
                <button onclick="document.getElementById('detailsModal').classList.add('hidden')" class="w-full py-3 bg-slate-700 hover:bg-slate-600 rounded-xl font-bold text-white transition">
                    Close
                </button>
            </div>
        </div>
    </div>

    <!-- মোবাইল মেনু টগল -->
    <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');
            });
        }
        
        // সিলেক্ট অল ফাংশন
        const selectAllCheckbox = document.getElementById('selectAll');
        if(selectAllCheckbox) {
            selectAllCheckbox.addEventListener('change', function() {
                const checkboxes = document.querySelectorAll('.row-checkbox');
                checkboxes.forEach(cb => cb.checked = this.checked);
            });
        }
        
        // ডিটেইলস ভিউ ফাংশন
        function viewDetails(deposit) {
            const modal = document.getElementById('detailsModal');
            const content = document.getElementById('modalContent');
            
            content.innerHTML = `
                <div class="space-y-3">
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Username</span>
                        <span class="text-sm font-bold text-white">${deposit.username}</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Phone</span>
                        <span class="text-sm font-bold text-white">${deposit.phone}</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Amount</span>
                        <span class="text-sm font-bold text-emerald-400">${'<?= $currency ?>'}${Number(deposit.amount).toFixed(2)}</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Method</span>
                        <span class="text-sm font-bold text-white">${deposit.method}</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Transaction ID</span>
                        <span class="text-sm font-mono text-blue-400">${deposit.transaction_id}</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Date & Time</span>
                        <span class="text-sm font-bold text-white">${new Date(deposit.created_at).toLocaleString()}</span>
                    </div>
                    <div class="flex justify-between items-center p-3 bg-slate-800/50 rounded-xl">
                        <span class="text-sm text-slate-400">Current Balance</span>
                        <span class="text-sm font-bold text-white">${'<?= $currency ?>'}${Number(deposit.balance || 0).toFixed(2)}</span>
                    </div>
                </div>
            `;
            
            modal.classList.remove('hidden');
        }
        
        // ট্রানজেকশন আইডি কপি করার ফিচার
        document.querySelectorAll('.select-all').forEach(element => {
            element.addEventListener('click', function() {
                const text = this.innerText;
                navigator.clipboard.writeText(text).then(() => {
                    Swal.fire({
                        icon: 'success',
                        title: 'Transaction ID Copied!',
                        toast: true,
                        position: 'top-end',
                        showConfirmButton: false,
                        timer: 1500,
                        background: '#1e293b',
                        color: '#fff'
                    });
                });
            });
        });
        
        // মোডাল বন্ধ করতে Escape কী প্রেস
        document.addEventListener('keydown', function(e) {
            if(e.key === 'Escape') {
                document.getElementById('detailsModal').classList.add('hidden');
            }
        });
        
        // মোডালের বাইরে ক্লিক করলে বন্ধ
        window.onclick = function(event) {
            const modal = document.getElementById('detailsModal');
            if(event.target == modal) {
                modal.classList.add('hidden');
            }
        }
    </script>
</body>
</html>