<?php
require_once '../includes/config.php';
require_once '../includes/telegram.php';
requireAdmin();
$db = getDB();

// Auto-add payment settings if not exists
$payKeys = ['bkash_number','bkash_type','nagad_number','nagad_type','rocket_number','rocket_type','bank_account','bank_name'];
foreach ($payKeys as $k) {
    try { $db->prepare("INSERT IGNORE INTO settings (`key`,`value`) VALUES (?,'')")->execute([$k]); } catch(Exception $e) {}
}

$msg = null;
if (isset($_GET['ok'])) $msg = ['ok'=>true,'text'=>'✅ Saved successfully!'];

// Handle actions
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $action = $_POST['action'] ?? '';

    // Save bKash settings
    if ($action === 'save_bkash') {
        $fields = ['bkash_app_key','bkash_app_secret','bkash_username','bkash_password','bkash_mode'];
        foreach ($fields as $k) {
            $v = trim($_POST[$k] ?? '');
            $db->prepare("INSERT INTO settings (`key`,`value`) VALUES (?,?) ON DUPLICATE KEY UPDATE `value`=?")->execute([$k,$v,$v]);
        }
        $msg = ['ok'=>true,'text'=>'✅ bKash settings saved!'];
        header('Location: deposits.php?ok=1'); exit;
    }

    // Save payment numbers
    if ($action === 'save_payment') {
        $fields = ['bkash_number','bkash_type','nagad_number','nagad_type','rocket_number','rocket_type','bank_account','bank_name'];
        foreach ($fields as $k) {
            $v = trim($_POST[$k] ?? '');
            $db->prepare("INSERT INTO settings (`key`,`value`) VALUES (?,?) ON DUPLICATE KEY UPDATE `value`=?")->execute([$k,$v,$v]);
        }
        $msg = ['ok'=>true,'text'=>'Payment numbers saved!'];
        header('Location: deposits.php?ok=1'); exit;
    }

    // Approve deposit
    if ($action === 'approve') {
        $id = intval($_POST['id']);
        $dep = $db->prepare("SELECT * FROM deposits WHERE id=?")->execute([$id]) 
              ? $db->prepare("SELECT * FROM deposits WHERE id=?")->execute([$id]) : null;
        $db->prepare("SELECT * FROM deposits WHERE id=?")->execute([$id]);
        $dep = $db->prepare("SELECT * FROM deposits WHERE id=?")->execute([$id]);
        $stmt = $db->prepare("SELECT * FROM deposits WHERE id=?");
        $stmt->execute([$id]);
        $dep = $stmt->fetch();
        
        if ($dep && $dep['status'] === 'pending') {
            $db->prepare("UPDATE deposits SET status='approved' WHERE id=?")->execute([$id]);
            $db->prepare("UPDATE users SET balance=balance+? WHERE id=?")->execute([$dep['amount'],$dep['user_id']]);
            // Add transaction record
            $bal_s = $db->prepare("SELECT balance FROM users WHERE id=?");
            $bal_s->execute([$dep['user_id']]);
            $new_bal = $bal_s->fetchColumn();
            $old_bal = $new_bal - $dep['amount'];
            $db->prepare("INSERT INTO transactions (user_id,type,amount,charge,net_amount,balance_before,balance_after,reference,status,note) VALUES (?,?,?,0,?,?,?,?,?,?)")
               ->execute([$dep['user_id'],'deposit',$dep['amount'],$dep['amount'],$old_bal,$new_bal,$dep['transaction_ref'],'success','Deposit approved by admin']);
            // Notification
            $db->prepare("INSERT INTO notifications (user_id,title,message,type) VALUES (?,?,?,'success')")
               ->execute([$dep['user_id'],'✅ Deposit Approved','৳'.number_format($dep['amount'],2).' has been added to your balance.']);
            notifyUser($dep['user_id'], 'Balance যোগ হয়েছে! 💰', ['💰 Amount'=>'৳'.number_format($dep['amount'],2), '📋 Method'=>$dep['method']??'', '🔖 Ref'=>$dep['transaction_ref']??'']);
            $msg = ['ok'=>true,'text'=>'✅ Deposit approved! Balance added.'];
            header('Location: deposits.php?ok=1'); exit;
        }
    }

    // Reject deposit
    if ($action === 'reject') {
        $id   = intval($_POST['id']);
        $note = trim($_POST['reject_note'] ?? 'Rejected by admin');
        $stmt = $db->prepare("SELECT * FROM deposits WHERE id=?");
        $stmt->execute([$id]);
        $dep = $stmt->fetch();
        if ($dep && $dep['status'] === 'pending') {
            $db->prepare("UPDATE deposits SET status='rejected' WHERE id=?")->execute([$id]);
            $db->prepare("INSERT INTO notifications (user_id,title,message,type) VALUES (?,?,?,'error')")
               ->execute([$dep['user_id'],'❌ Deposit Rejected','Your deposit request of ৳'.number_format($dep['amount'],2).' was rejected. Reason: '.$note]);
            $msg = ['ok'=>true,'text'=>'Deposit rejected.'];
            header('Location: deposits.php?ok=1'); exit;
        }
    }
}

// Fetch settings
$settings = [];
foreach ($db->query("SELECT * FROM settings")->fetchAll() as $s) $settings[$s['key']] = $s['value'];

// Filter
$filterStatus = $_GET['status'] ?? '';
$filterSearch = $_GET['search'] ?? '';
$where = "WHERE 1=1";
$params = [];
if ($filterStatus) { $where .= " AND d.status=?"; $params[] = $filterStatus; }
if ($filterSearch) {
    $where .= " AND (u.name LIKE ? OR u.phone LIKE ? OR d.transaction_ref LIKE ? OR d.sender_number LIKE ?)";
    $params = array_merge($params, ["%$filterSearch%","%$filterSearch%","%$filterSearch%","%$filterSearch%"]);
}

$deps = $db->prepare("SELECT d.*, u.name as uname, u.phone as uphone, u.balance as ubal FROM deposits d JOIN users u ON d.user_id=u.id $where ORDER BY d.created_at DESC LIMIT 100");
$deps->execute($params);
$deposits = $deps->fetchAll();

// Stats
$stats = [
    'total'    => $db->query("SELECT COUNT(*) FROM deposits")->fetchColumn(),
    'pending'  => $db->query("SELECT COUNT(*) FROM deposits WHERE status='pending'")->fetchColumn(),
    'approved' => $db->query("SELECT COUNT(*) FROM deposits WHERE status='approved'")->fetchColumn(),
    'revenue'  => $db->query("SELECT COALESCE(SUM(amount),0) FROM deposits WHERE status='approved'")->fetchColumn(),
    'today'    => $db->query("SELECT COUNT(*) FROM deposits WHERE DATE(created_at)=CURDATE()")->fetchColumn(),
    'today_amt'=> $db->query("SELECT COALESCE(SUM(amount),0) 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">
<title>Deposits - Admin</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/admin.css">
<style>
.stats-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:12px;margin-bottom:20px}
.stat-box{background:white;border-radius:12px;padding:16px;box-shadow:0 2px 8px rgba(0,0,0,0.05);text-align:center;border-top:3px solid var(--primary)}
.stat-box.green{border-color:#38a169}.stat-box.yellow{border-color:#d69e2e}.stat-box.red{border-color:#e53e3e}
.stat-num{font-size:24px;font-weight:800;color:var(--dark)}
.stat-lbl{font-size:11px;color:#888;margin-top:3px;font-weight:600}
.card{background:white;border-radius:12px;box-shadow:0 2px 8px rgba(0,0,0,0.05);margin-bottom:18px;overflow:hidden}
.card-h{padding:14px 18px;border-bottom:1px solid #f5f5f5;font-size:14px;font-weight:700;color:var(--dark);display:flex;align-items:center;gap:8px}
.card-b{padding:18px}
.alert{padding:11px 16px;border-radius:10px;font-size:13px;font-weight:600;margin-bottom:16px}
.alert-ok{background:#f0fff4;color:#276749;border:1px solid #c6f6d5}
.alert-err{background:#fff5f5;color:#c53030;border:1px solid #fed7d7}
.frow{display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:12px}
.fg{display:flex;flex-direction:column;gap:5px}
.fg label{font-size:12px;font-weight:600;color:#555}
.fg input,.fg select{padding:9px 12px;border:2px solid #e8ecf4;border-radius:9px;font-size:13px;outline:none}
.fg input:focus{border-color:var(--primary)}
.btn{padding:9px 16px;border:none;border-radius:9px;font-size:13px;font-weight:700;cursor:pointer;display:inline-flex;align-items:center;gap:6px}
.btn-primary{background:var(--primary);color:white}
.btn-sm{padding:5px 11px;font-size:12px;border-radius:7px;cursor:pointer;border:none;font-weight:600}
.btn-ok{background:#f0fff4;color:#276749}.btn-rj{background:#fff5f5;color:#e53e3e}
.filter-bar{display:flex;gap:10px;flex-wrap:wrap;padding:14px 18px;border-bottom:1px solid #f5f5f5;align-items:center}
.filter-input{padding:8px 12px;border:2px solid #e8ecf4;border-radius:9px;font-size:13px;outline:none}
.filter-input:focus{border-color:var(--primary)}
.filter-btn{padding:8px 14px;background:var(--primary);color:white;border:none;border-radius:9px;font-size:13px;font-weight:600;cursor:pointer}
table{width:100%;border-collapse:collapse}
th{padding:10px 12px;text-align:left;font-size:11px;color:#888;font-weight:700;text-transform:uppercase;border-bottom:2px solid #f5f5f5;white-space:nowrap}
td{padding:11px 12px;border-bottom:1px solid #f9f9f9;font-size:13px;vertical-align:middle}
tr:last-child td{border:none}
tr:hover td{background:#fafbff}
.badge{display:inline-block;padding:3px 10px;border-radius:20px;font-size:11px;font-weight:700}
.badge-pending{background:#fffaf0;color:#d69e2e}
.badge-approved{background:#f0fff4;color:#38a169}
.badge-rejected{background:#fff5f5;color:#e53e3e}
.user-cell strong{font-size:13px;display:block}
.user-cell small{color:#888;font-size:11px}
.pay-num-grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.pay-card{background:#f8fafc;border-radius:12px;padding:16px;border:2px solid #e8ecf4}
.pay-card h4{font-size:13px;font-weight:700;margin-bottom:10px;display:flex;align-items:center;gap:8px}
.proof-img{width:60px;height:60px;border-radius:8px;object-fit:cover;cursor:pointer;border:2px solid #e8ecf4}
.modal-ov{display:none;position:fixed;inset:0;background:rgba(0,0,0,0.5);z-index:9999;align-items:center;justify-content:center}
.modal-ov.show{display:flex}
.modal-box{background:white;border-radius:14px;padding:22px;width:92%;max-width:420px}
.modal-box h3{font-size:15px;font-weight:700;margin-bottom:14px}
.gap-btn{display:flex;gap:8px;margin-top:12px}
</style>
</head>
<body>
<?php include '../includes/admin_sidebar.php'; ?>

<div class="main">
<div class="topbar">
    <div class="topbar-left">
        <button class="menu-toggle" onclick="openSidebar()"><i class="fas fa-bars"></i></button>
        <span class="topbar-title">Deposit Management</span>
    </div>
</div>

<div class="content">
<?php if($msg): ?>
<div class="alert <?= $msg['ok']?'alert-ok':'alert-err' ?>"><?= htmlspecialchars($msg['text']) ?></div>
<?php endif; ?>

<!-- Stats -->
<div class="stats-grid">
    <div class="stat-box"><div class="stat-num"><?= $stats['total'] ?></div><div class="stat-lbl">Total Requests</div></div>
    <div class="stat-box yellow"><div class="stat-num"><?= $stats['pending'] ?></div><div class="stat-lbl">⏳ Pending</div></div>
    <div class="stat-box green"><div class="stat-num"><?= $stats['approved'] ?></div><div class="stat-lbl">✅ Approved</div></div>
    <div class="stat-box green"><div class="stat-num"><?= CURRENCY ?><?= number_format($stats['revenue'],0) ?></div><div class="stat-lbl">Total Approved</div></div>
    <div class="stat-box"><div class="stat-num"><?= $stats['today'] ?></div><div class="stat-lbl">📅 Today</div></div>
    <div class="stat-box green"><div class="stat-num"><?= CURRENCY ?><?= number_format($stats['today_amt'],0) ?></div><div class="stat-lbl">Today Amount</div></div>
</div>

<!-- bKash API Settings -->
<div class="card">
    <div class="card-h"><i class="fas fa-mobile-alt" style="color:#E2136E"></i> bKash Payment Gateway API</div>
    <div class="card-b">
        <?php
        $bkSettings = [];
        foreach(['bkash_app_key','bkash_app_secret','bkash_username','bkash_password','bkash_mode'] as $k) {
            $bkSettings[$k] = getSetting($k) ?: '';
        }
        $bkConfigured = !empty($bkSettings['bkash_app_key']) && !empty($bkSettings['bkash_username']);
        ?>
        <?php if($bkConfigured): ?>
        <div style="background:#f0fff4;border-radius:10px;padding:10px 14px;margin-bottom:14px;font-size:13px;color:#276749;font-weight:600">
            ✅ bKash API Connected — Users can pay directly via bKash
        </div>
        <?php else: ?>
        <div style="background:#fffaf0;border-radius:10px;padding:10px 14px;margin-bottom:14px;font-size:13px;color:#92400e">
            ⚠️ bKash API not configured — Add credentials to enable auto payment
        </div>
        <?php endif; ?>
        <form method="POST">
            <input type="hidden" name="action" value="save_bkash">
            <div class="frow">
                <div class="fg">
                    <label>App Key</label>
                    <input type="text" name="bkash_app_key" placeholder="bKash App Key" value="<?= htmlspecialchars($bkSettings['bkash_app_key']) ?>">
                </div>
                <div class="fg">
                    <label>App Secret</label>
                    <input type="password" name="bkash_app_secret" placeholder="bKash App Secret" value="<?= htmlspecialchars($bkSettings['bkash_app_secret']) ?>">
                </div>
                <div class="fg">
                    <label>Username</label>
                    <input type="text" name="bkash_username" placeholder="bKash Username" value="<?= htmlspecialchars($bkSettings['bkash_username']) ?>">
                </div>
                <div class="fg">
                    <label>Password</label>
                    <input type="password" name="bkash_password" placeholder="bKash Password" value="<?= htmlspecialchars($bkSettings['bkash_password']) ?>">
                </div>
                <div class="fg">
                    <label>Mode</label>
                    <select name="bkash_mode">
                        <option value="sandbox" <?= $bkSettings['bkash_mode']==='sandbox'?'selected':'' ?>>🧪 Sandbox (Test)</option>
                        <option value="live"    <?= $bkSettings['bkash_mode']==='live'   ?'selected':'' ?>>🔴 Live</option>
                    </select>
                </div>
            </div>
            <div style="font-size:12px;color:#888;margin-bottom:12px">
                Callback URL: <code style="background:#f5f5f5;padding:3px 8px;border-radius:6px"><?= getSetting('site_url') ?: 'https://p1.enotice.top/telecom' ?>/api/bkash_callback.php</code>
            </div>
            <button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Save bKash Settings</button>
        </form>
    </div>
</div>

<!-- Payment Numbers Settings -->
<div class="card">
    <div class="card-h"><i class="fas fa-mobile-alt" style="color:#E2136E"></i> Payment Method Numbers</div>
    <div class="card-b">
    <form method="POST">
        <input type="hidden" name="action" value="save_payment">
        <div class="pay-num-grid">
            <div class="pay-card">
                <h4><i class="fas fa-mobile-alt" style="color:#E2136E"></i> bKash</h4>
                <div class="fg" style="margin-bottom:8px">
                    <label>bKash Number</label>
                    <input type="text" name="bkash_number" placeholder="01XXXXXXXXX" value="<?= htmlspecialchars($settings['bkash_number']??'') ?>">
                </div>
                <div class="fg">
                    <label>Account Type</label>
                    <select name="bkash_type">
                        <option <?= ($settings['bkash_type']??'')==='personal'?'selected':'' ?> value="personal">Personal</option>
                        <option <?= ($settings['bkash_type']??'')==='agent'?'selected':'' ?> value="agent">Agent</option>
                        <option <?= ($settings['bkash_type']??'')==='merchant'?'selected':'' ?> value="merchant">Merchant</option>
                    </select>
                </div>
            </div>
            <div class="pay-card">
                <h4><i class="fas fa-mobile-alt" style="color:#F05829"></i> Nagad</h4>
                <div class="fg" style="margin-bottom:8px">
                    <label>Nagad Number</label>
                    <input type="text" name="nagad_number" placeholder="01XXXXXXXXX" value="<?= htmlspecialchars($settings['nagad_number']??'') ?>">
                </div>
                <div class="fg">
                    <label>Account Type</label>
                    <select name="nagad_type">
                        <option <?= ($settings['nagad_type']??'')==='personal'?'selected':'' ?> value="personal">Personal</option>
                        <option <?= ($settings['nagad_type']??'')==='agent'?'selected':'' ?> value="agent">Agent</option>
                        <option <?= ($settings['nagad_type']??'')==='merchant'?'selected':'' ?> value="merchant">Merchant</option>
                    </select>
                </div>
            </div>
            <div class="pay-card">
                <h4><i class="fas fa-rocket" style="color:#8C3494"></i> Rocket</h4>
                <div class="fg" style="margin-bottom:8px">
                    <label>Rocket Number</label>
                    <input type="text" name="rocket_number" placeholder="01XXXXXXXXX" value="<?= htmlspecialchars($settings['rocket_number']??'') ?>">
                </div>
                <div class="fg">
                    <label>Account Type</label>
                    <select name="rocket_type">
                        <option <?= ($settings['rocket_type']??'')==='personal'?'selected':'' ?> value="personal">Personal</option>
                        <option <?= ($settings['rocket_type']??'')==='agent'?'selected':'' ?> value="agent">Agent</option>
                    </select>
                </div>
            </div>
            <div class="pay-card">
                <h4><i class="fas fa-university" style="color:#1a3c8f"></i> Bank</h4>
                <div class="fg" style="margin-bottom:8px">
                    <label>Bank Account / Details</label>
                    <input type="text" name="bank_account" placeholder="Bank Name | A/C No" value="<?= htmlspecialchars($settings['bank_account']??'') ?>">
                </div>
                <div class="fg">
                    <label>Bank Name</label>
                    <input type="text" name="bank_name" placeholder="Dutch Bangla Bank" value="<?= htmlspecialchars($settings['bank_name']??'') ?>">
                </div>
            </div>
        </div>
        <div style="margin-top:14px">
            <button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> Save Payment Numbers</button>
        </div>
    </form>
    </div>
</div>

<!-- Deposit List -->
<div class="card">
    <div class="card-h"><i class="fas fa-list" style="color:var(--primary)"></i> All Deposits (<?= count($deposits) ?>)</div>

    <!-- Filters -->
    <form method="GET" class="filter-bar">
        <input type="text" name="search" class="filter-input" placeholder="Search name / phone / ref..." value="<?= htmlspecialchars($filterSearch) ?>" style="flex:1;min-width:150px">
        <select name="status" class="filter-input">
            <option value="">All Status</option>
            <option value="pending"  <?= $filterStatus==='pending' ?'selected':'' ?>>⏳ Pending</option>
            <option value="approved" <?= $filterStatus==='approved'?'selected':'' ?>>✅ Approved</option>
            <option value="rejected" <?= $filterStatus==='rejected'?'selected':'' ?>>❌ Rejected</option>
        </select>
        <button type="submit" class="filter-btn"><i class="fas fa-search"></i> Filter</button>
        <?php if($filterStatus||$filterSearch): ?><a href="deposits.php" style="color:#888;font-size:13px;padding:8px">Clear</a><?php endif; ?>
    </form>

    <?php if(empty($deposits)): ?>
    <div style="text-align:center;padding:40px;color:#aaa"><i class="fas fa-inbox" style="font-size:30px;display:block;margin-bottom:10px"></i>No deposits found</div>
    <?php else: ?>
    <div style="overflow-x:auto">
    <table>
        <thead><tr>
            <th>User</th><th>Amount</th><th>Method</th>
            <th>Sender No.</th><th>TrxID / Ref</th>
            <th>Proof</th><th>Date</th><th>Status</th><th>Action</th>
        </tr></thead>
        <tbody>
        <?php foreach($deposits as $d): ?>
        <tr>
            <td>
                <div class="user-cell">
                    <strong><?= htmlspecialchars($d['uname']) ?></strong>
                    <small><?= $d['uphone'] ?> • Bal: <?= CURRENCY ?><?= number_format($d['ubal'],2) ?></small>
                </div>
            </td>
            <td><strong style="color:var(--primary);font-size:15px"><?= CURRENCY ?><?= number_format($d['amount'],2) ?></strong></td>
            <td><span style="background:#f0f4ff;color:var(--primary);padding:4px 10px;border-radius:20px;font-size:12px;font-weight:700"><?= strtoupper($d['method']) ?></span></td>
            <td style="font-family:monospace;font-size:12px"><?= $d['sender_number'] ?: '-' ?></td>
            <td style="font-family:monospace;font-size:11px;color:#666"><?= htmlspecialchars($d['transaction_ref']) ?></td>
            <td>
                <?php if($d['proof_image']): ?>
                <img src="../<?= $d['proof_image'] ?>" class="proof-img" onclick="showImg('../<?= $d['proof_image'] ?>')" onerror="this.style.display='none'">
                <?php else: ?>
                <span style="color:#ddd;font-size:12px">—</span>
                <?php endif; ?>
            </td>
            <td style="font-size:11px;color:#888;white-space:nowrap"><?= date('d M y, h:i A', strtotime($d['created_at'])) ?></td>
            <td><span class="badge badge-<?= $d['status'] ?>"><?= ucfirst($d['status']) ?></span></td>
            <td>
                <?php if($d['status']==='pending'): ?>
                <div style="display:flex;gap:5px;align-items:center">
                    <form method="POST" style="display:inline">
                        <input type="hidden" name="action" value="approve">
                        <input type="hidden" name="id" value="<?= $d['id'] ?>">
                        <button type="submit" class="btn-sm btn-ok" onclick="return confirm('Approve ৳<?= number_format($d['amount'],0) ?> for <?= htmlspecialchars($d['uname']) ?>?')">
                            <i class="fas fa-check"></i> Approve
                        </button>
                    </form>
                    <button class="btn-sm btn-rj" onclick="openReject(<?= $d['id'] ?>,'<?= htmlspecialchars($d['uname'],ENT_QUOTES) ?>')">
                        <i class="fas fa-times"></i> Reject
                    </button>
                </div>
                <?php else: ?>
                <span style="color:#ddd">—</span>
                <?php endif; ?>
            </td>
        </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    </div>
    <?php endif; ?>
</div>

</div><!-- content -->
</div><!-- main -->

<!-- Reject Modal -->
<div class="modal-ov" id="rejectModal">
    <div class="modal-box">
        <h3><i class="fas fa-times-circle" style="color:#e53e3e"></i> Reject Deposit</h3>
        <p id="rejectUserName" style="font-size:13px;color:#666;margin-bottom:12px"></p>
        <form method="POST">
            <input type="hidden" name="action" value="reject">
            <input type="hidden" name="id" id="rejectId">
            <div class="fg">
                <label>Reason (optional)</label>
                <input type="text" name="reject_note" placeholder="Invalid TrxID, wrong amount, etc." id="rejectNote">
            </div>
            <div class="gap-btn">
                <button type="submit" class="btn" style="background:#e53e3e;color:white"><i class="fas fa-times"></i> Confirm Reject</button>
                <button type="button" class="btn" style="background:#f5f5f5" onclick="closeReject()">Cancel</button>
            </div>
        </form>
    </div>
</div>

<!-- Image Modal -->
<div class="modal-ov" id="imgModal" onclick="closeImg()">
    <div style="max-width:90vw;max-height:90vh">
        <img id="proofImg" src="" style="max-width:100%;max-height:90vh;border-radius:12px">
    </div>
</div>

<script>
function openReject(id, name) {
    document.getElementById('rejectId').value = id;
    document.getElementById('rejectUserName').textContent = 'User: ' + name;
    document.getElementById('rejectModal').classList.add('show');
}
function closeReject() { document.getElementById('rejectModal').classList.remove('show'); }
document.getElementById('rejectModal').addEventListener('click', e => { if(e.target===document.getElementById('rejectModal')) closeReject(); });

function showImg(src) {
    document.getElementById('proofImg').src = src;
    document.getElementById('imgModal').classList.add('show');
}
function closeImg() { document.getElementById('imgModal').classList.remove('show'); }
</script>
</body>
</html>
