<?php
/**
 * TOPBD — Complete Production Admin Control Panel
 * Database-Driven & Directly Connected to Public Frontend
 */

require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/auth.php';
require_once __DIR__ . '/../includes/ranking.php';
require_once __DIR__ . '/../includes/PaymentManager.php';

require_admin();

$db = get_db();
$message = '';
$error = '';
$activeTab = $_GET['tab'] ?? 'dashboard';

// Handle POST actions with CSRF validation
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $token = $_POST['csrf_token'] ?? '';
    if (!verify_csrf($token)) {
        $error = 'Invalid security session token. Please try again.';
    } else {
        $action = $_POST['action'] ?? '';

        // 1. General & Bid Settings Update
        if ($action === 'save_general_settings') {
            $settingsKeys = [
                'site_name', 'site_subtitle', 'site_url', 'currency_symbol',
                'minimum_bid_increment', 'initial_minimum_bid', 'visitor_timeout_seconds',
                'pagination_size', 'maintenance_mode'
            ];
            foreach ($settingsKeys as $key) {
                if (isset($_POST[$key])) {
                    $stmt = $db->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
                    $stmt->execute([$key, trim($_POST[$key]), trim($_POST[$key])]);
                }
            }
            $message = 'General settings saved successfully!';
        }

        // 2. Change Admin Password
        if ($action === 'change_admin_password') {
            $currentPass = $_POST['current_password'] ?? '';
            $newPass = $_POST['new_password'] ?? '';
            $confirmPass = $_POST['confirm_password'] ?? '';

            if (empty($newPass) || strlen($newPass) < 6) {
                $error = 'New password must be at least 6 characters.';
            } elseif ($newPass !== $confirmPass) {
                $error = 'New password and confirmation do not match.';
            } else {
                $adminId = $_SESSION['admin_user_id'];
                $checkStmt = $db->prepare("SELECT password_hash FROM admins WHERE id = ?");
                $checkStmt->execute([$adminId]);
                $admin = $checkStmt->fetch();

                if ($admin && password_verify($currentPass, $admin['password_hash'])) {
                    $newHash = password_hash($newPass, PASSWORD_DEFAULT);
                    $upd = $db->prepare("UPDATE admins SET password_hash = ? WHERE id = ?");
                    $upd->execute([$newHash, $adminId]);
                    $message = 'Admin password updated successfully!';
                } else {
                    $error = 'Current password is incorrect.';
                }
            }
        }

        // 3. Design & Colors Settings
        if ($action === 'save_design_settings') {
            $colorKeys = [
                'primary_color', 'secondary_color', 'accent_color', 'background_color',
                'card_color', 'header_bg', 'footer_bg', 'border_color', 'text_color',
                'muted_text_color', 'rank1_bg', 'rank1_border', 'rank2_bg', 'rank3_bg',
                'border_radius'
            ];
            foreach ($colorKeys as $key) {
                if (isset($_POST[$key])) {
                    $stmt = $db->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
                    $stmt->execute([$key, trim($_POST[$key]), trim($_POST[$key])]);
                }
            }
            $message = 'Visual design & color theme updated successfully!';
        }

        // 4. Frontend Texts Update
        if ($action === 'save_frontend_texts') {
            $textKeys = [
                'site_logo_text', 'live_ranking_badge', 'tab_all_time', 'tab_today',
                'visitor_badge_prefix', 'claim_hero_title', 'claim_hero_desc',
                'category_all', 'category_more', 'outbid_btn_text', 'current_bid_label',
                'next_bid_label', 'additional_amount_label', 'payment_method_label',
                'modal_target_label', 'modal_name_placeholder', 'modal_url_placeholder',
                'total_generated_prefix', 'total_generated_suffix', 'footer_attribution',
                'footer_brand_tagline'
            ];
            foreach ($textKeys as $key) {
                if (isset($_POST[$key])) {
                    $stmt = $db->prepare("INSERT INTO frontend_texts (text_key, text_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE text_value = ?");
                    $stmt->execute([$key, trim($_POST[$key]), trim($_POST[$key])]);
                }
            }
            $message = 'Frontend copy and text labels updated successfully!';
        }

        // 5. Developer / Built-by Popup Settings
        if ($action === 'save_developer_settings') {
            $devKeys = [
                'developer_enabled', 'developer_name', 'developer_handle',
                'developer_bio', 'developer_image', 'developer_github', 'developer_twitter'
            ];
            foreach ($devKeys as $key) {
                $val = trim($_POST[$key] ?? '');
                $stmt = $db->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
                $stmt->execute([$key, $val, $val]);
            }
            $message = 'Developer attribution popup updated successfully!';
        }

        // 6. Payment Gateway Configuration
        if ($action === 'save_gateway_config') {
            $gwId = $_POST['gateway_id'] ?? '';
            $isEnabled = isset($_POST['is_enabled']) ? 1 : 0;
            $mode = ($_POST['mode'] ?? 'test') === 'live' ? 'live' : 'test';
            $merchantId = trim($_POST['merchant_id'] ?? '');
            $storeId = trim($_POST['store_id'] ?? '');
            $username = trim($_POST['username'] ?? '');
            $password = trim($_POST['password'] ?? '');
            $appKey = trim($_POST['app_key'] ?? '');
            $appSecret = trim($_POST['app_secret'] ?? '');
            $apiUrl = trim($_POST['api_url'] ?? '');
            $callbackUrl = trim($_POST['callback_url'] ?? '');

            $stmt = $db->prepare("UPDATE gateway_configs SET 
                is_enabled = ?, mode = ?, merchant_id = ?, store_id = ?, username = ?, 
                password = ?, app_key = ?, app_secret = ?, api_url = ?, callback_url = ? 
                WHERE gateway_id = ?");
            $stmt->execute([
                $isEnabled, $mode, $merchantId, $storeId, $username,
                $password, $appKey, $appSecret, $apiUrl, $callbackUrl, $gwId
            ]);
            $message = "Payment gateway [{$gwId}] settings saved!";
        }

        // 7. Listings CRUD
        if ($action === 'add_listing') {
            $name = trim($_POST['name'] ?? '');
            $url = trim($_POST['url'] ?? '');
            $imageUrl = trim($_POST['image_url'] ?? '');
            $categoryId = (int)($_POST['category_id'] ?? 1);
            $initialBid = (float)($_POST['current_bid'] ?? 10);
            $isActive = isset($_POST['is_active']) ? 1 : 0;

            if (!empty($name) && !empty($url)) {
                if (empty($imageUrl)) {
                    $imageUrl = 'https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?w=200&auto=format&fit=crop&q=80';
                }
                $ins = $db->prepare("INSERT INTO listings (name, image_url, url, category_id, current_bid, clicks, hearts, is_active, created_at, updated_at, last_bid_at) VALUES (?, ?, ?, ?, ?, 0, 0, ?, NOW(), NOW(), NOW())");
                $ins->execute([$name, $imageUrl, $url, $categoryId, $initialBid, $isActive]);
                $message = 'New listing created successfully with 0 clicks & 0 hearts!';
            } else {
                $error = 'Listing name and URL are required.';
            }
        } elseif ($action === 'edit_listing') {
            $id = (int)($_POST['id'] ?? 0);
            $name = trim($_POST['name'] ?? '');
            $url = trim($_POST['url'] ?? '');
            $imageUrl = trim($_POST['image_url'] ?? '');
            $categoryId = (int)($_POST['category_id'] ?? 1);
            $currentBid = (float)($_POST['current_bid'] ?? 0);
            $isActive = isset($_POST['is_active']) ? 1 : 0;

            $upd = $db->prepare("UPDATE listings SET name = ?, url = ?, image_url = ?, category_id = ?, current_bid = ?, is_active = ?, updated_at = NOW() WHERE id = ?");
            $upd->execute([$name, $url, $imageUrl, $categoryId, $currentBid, $isActive, $id]);
            $message = "Listing #{$id} updated successfully!";
        } elseif ($action === 'delete_listing') {
            $id = (int)($_POST['id'] ?? 0);
            $delBids = $db->prepare("DELETE FROM bids WHERE listing_id = ?");
            $delBids->execute([$id]);
            $del = $db->prepare("DELETE FROM listings WHERE id = ?");
            $del->execute([$id]);
            $message = "Listing #{$id} deleted.";
        }

        // 8. Categories CRUD
        if ($action === 'add_category') {
            $catName = trim($_POST['name'] ?? '');
            $slug = trim($_POST['slug'] ?? '');
            $icon = trim($_POST['icon'] ?? 'Sparkles');
            $order = (int)($_POST['display_order'] ?? 0);
            $isActive = isset($_POST['is_active']) ? 1 : 0;

            if (empty($slug)) {
                $slug = strtolower(preg_replace('/[^a-zA-Z0-9]+/', '-', $catName));
            }

            if (!empty($catName)) {
                $ins = $db->prepare("INSERT INTO categories (name, slug, icon, display_order, is_active) VALUES (?, ?, ?, ?, ?)");
                $ins->execute([$catName, $slug, $icon, $order, $isActive]);
                $message = 'Category added successfully!';
            } else {
                $error = 'Category name is required.';
            }
        } elseif ($action === 'edit_category') {
            $id = (int)($_POST['id'] ?? 0);
            $catName = trim($_POST['name'] ?? '');
            $slug = trim($_POST['slug'] ?? '');
            $icon = trim($_POST['icon'] ?? 'Sparkles');
            $order = (int)($_POST['display_order'] ?? 0);
            $isActive = isset($_POST['is_active']) ? 1 : 0;

            $upd = $db->prepare("UPDATE categories SET name = ?, slug = ?, icon = ?, display_order = ?, is_active = ? WHERE id = ?");
            $upd->execute([$catName, $slug, $icon, $order, $isActive, $id]);
            $message = "Category #{$id} updated!";
        } elseif ($action === 'delete_category') {
            $id = (int)($_POST['id'] ?? 0);
            $del = $db->prepare("DELETE FROM categories WHERE id = ?");
            $del->execute([$id]);
            $message = "Category deleted.";
        }

        // 9. Menu Items CRUD
        if ($action === 'add_menu_item') {
            $title = trim($_POST['title'] ?? '');
            $url = trim($_POST['url'] ?? '');
            $target = trim($_POST['target'] ?? '_self');
            $order = (int)($_POST['display_order'] ?? 0);
            $isActive = isset($_POST['is_active']) ? 1 : 0;

            if (!empty($title) && !empty($url)) {
                $ins = $db->prepare("INSERT INTO menu_items (title, url, target, display_order, is_active) VALUES (?, ?, ?, ?, ?)");
                $ins->execute([$title, $url, $target, $order, $isActive]);
                $message = 'Navigation menu item added!';
            }
        } elseif ($action === 'edit_menu_item') {
            $id = (int)($_POST['id'] ?? 0);
            $title = trim($_POST['title'] ?? '');
            $url = trim($_POST['url'] ?? '');
            $target = trim($_POST['target'] ?? '_self');
            $order = (int)($_POST['display_order'] ?? 0);
            $isActive = isset($_POST['is_active']) ? 1 : 0;

            $upd = $db->prepare("UPDATE menu_items SET title = ?, url = ?, target = ?, display_order = ?, is_active = ? WHERE id = ?");
            $upd->execute([$title, $url, $target, $order, $isActive, $id]);
            $message = "Menu item updated!";
        } elseif ($action === 'delete_menu_item') {
            $id = (int)($_POST['id'] ?? 0);
            $del = $db->prepare("DELETE FROM menu_items WHERE id = ?");
            $del->execute([$id]);
            $message = "Menu item removed.";
        }

        // 10. Content Pages Update
        if ($action === 'save_page_content') {
            $slug = trim($_POST['slug'] ?? '');
            $title = trim($_POST['title'] ?? '');
            $content = trim($_POST['content'] ?? '');

            if (!empty($slug)) {
                $stmt = $db->prepare("INSERT INTO pages (slug, title, content, updated_at) VALUES (?, ?, ?, NOW()) ON DUPLICATE KEY UPDATE title = ?, content = ?, updated_at = NOW()");
                $stmt->execute([$slug, $title, $content, $title, $content]);
                $message = "Page [{$slug}] content saved successfully!";
            }
        }

        // 11. Manual Verification / Status Override of Payment
        if ($action === 'verify_payment_manual') {
            $txnId = trim($_POST['transaction_id'] ?? '');
            try {
                $res = PaymentManager::verifyAndActivatePayment($txnId, ['mode' => 'admin_manual_override']);
                $message = "Transaction {$txnId} verified! Listing #{$res['listing_id']} is now active.";
            } catch (Exception $e) {
                $error = "Manual verification failed: " . $e->getMessage();
            }
        }
    }
}

// Fetch dashboard statistics
$totalRevenue = RankingEngine::getTotalGenerated();
$listingsCount = (int)$db->query("SELECT COUNT(*) FROM listings")->fetchColumn();
$activeListingsCount = (int)$db->query("SELECT COUNT(*) FROM listings WHERE is_active = 1")->fetchColumn();
$categoriesCount = (int)$db->query("SELECT COUNT(*) FROM categories")->fetchColumn();
$totalBidsCount = (int)$db->query("SELECT COUNT(*) FROM bids")->fetchColumn();
$liveVisitors = RankingEngine::getLiveVisitors((int)get_setting('visitor_timeout_seconds', '180'));

// Payment filtering params
$filterGateway = trim($_GET['filter_gateway'] ?? 'all');
$filterStatus = trim($_GET['filter_status'] ?? 'all');
$filterMode = trim($_GET['filter_mode'] ?? 'all');
$searchPay = trim($_GET['search_pay'] ?? '');

$paySql = "SELECT * FROM payments WHERE 1=1";
$payParams = [];

if ($filterGateway !== 'all' && !empty($filterGateway)) {
    $paySql .= " AND gateway = ?";
    $payParams[] = $filterGateway;
}
if ($filterStatus !== 'all' && !empty($filterStatus)) {
    $paySql .= " AND status = ?";
    $payParams[] = $filterStatus;
}
if ($filterMode !== 'all' && !empty($filterMode)) {
    $paySql .= " AND mode = ?";
    $payParams[] = $filterMode;
}
if (!empty($searchPay)) {
    $paySql .= " AND (transaction_id LIKE ? OR listing_name LIKE ? OR ip_address LIKE ?)";
    $payParams[] = "%{$searchPay}%";
    $payParams[] = "%{$searchPay}%";
    $payParams[] = "%{$searchPay}%";
}

$paySql .= " ORDER BY created_at DESC LIMIT 100";
$payStmt = $db->prepare($paySql);
$payStmt->execute($payParams);
$payments = $payStmt->fetchAll();

// Fetch datasets for other tabs
$listings = $db->query("SELECT l.*, c.name AS category_name FROM listings l LEFT JOIN categories c ON l.category_id = c.id ORDER BY l.current_bid DESC, l.last_bid_at DESC")->fetchAll();
$categories = $db->query("SELECT * FROM categories ORDER BY display_order ASC, id ASC")->fetchAll();
$gateways = $db->query("SELECT * FROM gateway_configs ORDER BY gateway_id ASC")->fetchAll();
$menuItems = $db->query("SELECT * FROM menu_items ORDER BY display_order ASC")->fetchAll();
$pages = $db->query("SELECT * FROM pages ORDER BY slug ASC")->fetchAll();
$settings = $db->query("SELECT setting_key, setting_value FROM settings")->fetchAll(PDO::FETCH_KEY_PAIR);
$frontendTexts = $db->query("SELECT text_key, text_value FROM frontend_texts")->fetchAll(PDO::FETCH_KEY_PAIR);

$currency = $settings['currency_symbol'] ?? '৳';
?>
<!DOCTYPE html>
<html lang="en" class="dark">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Admin Dashboard — <?= e($settings['site_name'] ?? 'TOPBD') ?></title>
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        body {
            background-color: #0A0D0F;
            color: #F0F4F8;
            font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
        }
        ::-webkit-scrollbar { width: 6px; height: 6px; }
        ::-webkit-scrollbar-track { background: #0A0D0F; }
        ::-webkit-scrollbar-thumb { background: #222A33; border-radius: 3px; }
    </style>
</head>
<body class="min-h-screen flex flex-col antialiased">

    <!-- Admin Header -->
    <header class="sticky top-0 z-40 w-full border-b border-[#222A33] bg-[#0E1216]/95 backdrop-blur-md px-4 sm:px-8 py-3.5 flex items-center justify-between">
        <div class="flex items-center gap-3">
            <div class="w-8 h-8 rounded-lg bg-emerald-600 flex items-center justify-center font-bold text-white shadow-lg shadow-emerald-950/60">
                BD
            </div>
            <div>
                <h1 class="font-extrabold text-base sm:text-lg tracking-tight text-white font-mono flex items-center gap-2">
                    <?= e($settings['site_name'] ?? 'TOPBD') ?> <span class="text-xs px-2 py-0.5 rounded bg-emerald-950 text-emerald-400 border border-emerald-800">Admin Control</span>
                </h1>
            </div>
        </div>

        <div class="flex items-center gap-3 sm:gap-4 text-xs">
            <a href="/" target="_blank" class="px-3 py-1.5 rounded-lg bg-[#141A20] hover:bg-[#1A222A] border border-[#222A33] text-slate-300 hover:text-white flex items-center gap-1.5 transition-colors">
                <span>View Public Board</span>
                <span>↗</span>
            </a>
            <a href="logout.php" class="px-3 py-1.5 rounded-lg bg-rose-950/60 hover:bg-rose-900 border border-rose-800/80 text-rose-300 font-semibold transition-colors">
                Sign Out
            </a>
        </div>
    </header>

    <div class="flex-1 flex flex-col md:flex-row max-w-7xl w-full mx-auto p-4 sm:p-6 gap-6">
        <!-- Sidebar Navigation -->
        <aside class="w-full md:w-60 shrink-0 space-y-1.5">
            <div class="p-3 bg-[#13181D] border border-[#222A33] rounded-2xl space-y-1 text-xs font-medium">
                <?php
                $tabs = [
                    'dashboard' => ['label' => '📊 Dashboard', 'id' => 'dashboard'],
                    'listings' => ['label' => '🏆 Listings & Bids', 'id' => 'listings'],
                    'categories' => ['label' => '📁 Categories', 'id' => 'categories'],
                    'gateways' => ['label' => '💳 Payment Gateways', 'id' => 'gateways'],
                    'payments' => ['label' => '🧾 Payment Transactions', 'id' => 'payments'],
                    'design' => ['label' => '🎨 Colors & Design', 'id' => 'design'],
                    'texts' => ['label' => '✍️ Frontend Texts', 'id' => 'texts'],
                    'menu' => ['label' => '🔗 Navigation Menu', 'id' => 'menu'],
                    'pages' => ['label' => '📄 Content & Legal Pages', 'id' => 'pages'],
                    'developer' => ['label' => '👨‍💻 Developer Popup', 'id' => 'developer'],
                    'settings' => ['label' => '⚙️ General & Security', 'id' => 'settings'],
                ];
                foreach ($tabs as $key => $tab):
                    $isActive = ($activeTab === $key);
                ?>
                    <a href="?tab=<?= $key ?>" class="flex items-center px-3 py-2.5 rounded-xl transition-all <?= $isActive ? 'bg-emerald-600 text-white font-bold shadow-md' : 'text-slate-400 hover:bg-[#1A222A] hover:text-slate-200' ?>">
                        <?= $tab['label'] ?>
                    </a>
                <?php endforeach; ?>
            </div>

            <!-- Live Status Quick Card -->
            <div class="p-4 bg-[#13181D] border border-[#222A33] rounded-2xl text-xs space-y-2">
                <div class="text-[10px] text-slate-500 uppercase font-bold tracking-wider">Live Health</div>
                <div class="flex justify-between items-center">
                    <span class="text-slate-400">Live Visitors:</span>
                    <span class="font-mono font-bold text-emerald-400"><?= $liveVisitors ?> active</span>
                </div>
                <div class="flex justify-between items-center">
                    <span class="text-slate-400">Verified Revenue:</span>
                    <span class="font-mono font-bold text-amber-400"><?= $currency ?><?= number_format($totalRevenue, 0) ?></span>
                </div>
            </div>
        </aside>

        <!-- Main Content View -->
        <main class="flex-1 min-w-0">
            <!-- Flash Messages -->
            <?php if (!empty($message)): ?>
                <div class="mb-4 p-4 rounded-xl bg-emerald-950/80 border border-emerald-700 text-emerald-300 text-xs font-semibold flex items-center justify-between">
                    <span>✅ <?= e($message) ?></span>
                    <button onclick="this.parentElement.remove()" class="text-emerald-400 hover:text-white">&times;</button>
                </div>
            <?php endif; ?>

            <?php if (!empty($error)): ?>
                <div class="mb-4 p-4 rounded-xl bg-rose-950/80 border border-rose-700 text-rose-300 text-xs font-semibold flex items-center justify-between">
                    <span>❌ <?= e($error) ?></span>
                    <button onclick="this.parentElement.remove()" class="text-rose-400 hover:text-white">&times;</button>
                </div>
            <?php endif; ?>

            <!-- TAB 1: DASHBOARD OVERVIEW -->
            <?php if ($activeTab === 'dashboard'): ?>
                <div class="space-y-6">
                    <div class="grid grid-cols-2 sm:grid-cols-4 gap-3 sm:gap-4">
                        <div class="p-4 rounded-2xl bg-[#13181D] border border-[#222A33] space-y-1">
                            <span class="text-[10px] uppercase font-bold text-slate-500">Verified Revenue</span>
                            <div class="text-xl sm:text-2xl font-black font-mono text-emerald-400"><?= $currency ?><?= number_format($totalRevenue, 0) ?></div>
                            <span class="text-[10px] text-slate-400">All-time successful bids</span>
                        </div>
                        <div class="p-4 rounded-2xl bg-[#13181D] border border-[#222A33] space-y-1">
                            <span class="text-[10px] uppercase font-bold text-slate-500">Active Listings</span>
                            <div class="text-xl sm:text-2xl font-black font-mono text-white"><?= $activeListingsCount ?> / <?= $listingsCount ?></div>
                            <span class="text-[10px] text-slate-400">Visible on leaderboard</span>
                        </div>
                        <div class="p-4 rounded-2xl bg-[#13181D] border border-[#222A33] space-y-1">
                            <span class="text-[10px] uppercase font-bold text-slate-500">Live Visitors</span>
                            <div class="text-xl sm:text-2xl font-black font-mono text-teal-400"><?= $liveVisitors ?></div>
                            <span class="text-[10px] text-slate-400">Active within 3 mins</span>
                        </div>
                        <div class="p-4 rounded-2xl bg-[#13181D] border border-[#222A33] space-y-1">
                            <span class="text-[10px] uppercase font-bold text-slate-500">Total Bids</span>
                            <div class="text-xl sm:text-2xl font-black font-mono text-amber-400"><?= $totalBidsCount ?></div>
                            <span class="text-[10px] text-slate-400">Competitive outbids</span>
                        </div>
                    </div>

                    <!-- Top 5 Current Leaderboard -->
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <div class="flex items-center justify-between">
                            <h2 class="font-bold text-sm text-white">Current Top 5 Leaderboard</h2>
                            <a href="?tab=listings" class="text-xs text-emerald-400 hover:underline">Manage All Listings →</a>
                        </div>
                        <div class="space-y-2">
                            <?php foreach (array_slice($listings, 0, 5) as $idx => $item): ?>
                                <div class="flex items-center justify-between p-3 rounded-xl bg-[#0A0D0F] border border-[#222A33] text-xs">
                                    <div class="flex items-center gap-3">
                                        <span class="font-mono font-bold text-amber-400">#<?= $idx + 1 ?></span>
                                        <img src="<?= e($item['image_url']) ?>" class="w-7 h-7 rounded-lg object-cover" />
                                        <div>
                                            <div class="font-bold text-white"><?= e($item['name']) ?></div>
                                            <span class="text-[10px] text-slate-500"><?= e($item['category_name']) ?></span>
                                        </div>
                                    </div>
                                    <div class="font-mono font-bold text-emerald-400">
                                        <?= $currency ?><?= number_format($item['current_bid'], 0) ?>
                                    </div>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div>

            <!-- TAB 2: LISTINGS CRUD -->
            <?php elseif ($activeTab === 'listings'): ?>
                <div class="space-y-6">
                    <!-- Add Listing Form -->
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">Add New Public Listing</h2>
                        <form method="POST" class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
                            <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                            <input type="hidden" name="action" value="add_listing" />

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Title / Brand / Creator Name</label>
                                <input type="text" name="name" required placeholder="e.g. Acme Software" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white focus:outline-none" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Destination URL</label>
                                <input type="url" name="url" required placeholder="https://example.com" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white focus:outline-none" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Category</label>
                                <select name="category_id" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white focus:outline-none">
                                    <?php foreach ($categories as $cat): ?>
                                        <option value="<?= $cat['id'] ?>"><?= e($cat['name']) ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Initial Bid (<?= $currency ?>)</label>
                                <input type="number" name="current_bid" value="10" min="1" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono focus:outline-none" />
                            </div>

                            <div class="sm:col-span-2">
                                <label class="block text-slate-300 font-semibold mb-1">Image / Logo URL (Square 1:1)</label>
                                <input type="url" name="image_url" placeholder="https://images.unsplash.com/..." class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white focus:outline-none" />
                            </div>

                            <div class="flex items-center gap-2">
                                <input type="checkbox" name="is_active" id="add_active" value="1" checked class="rounded bg-[#0A0D0F] border-slate-700" />
                                <label for="add_active" class="text-slate-300">Publish Immediately (Active)</label>
                            </div>

                            <div class="sm:col-span-2">
                                <button type="submit" class="px-5 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                    Create Listing (Starts with 0 Clicks / 0 Hearts)
                                </button>
                            </div>
                        </form>
                    </div>

                    <!-- Existing Listings Table -->
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">All Listings (<?= count($listings) ?>)</h2>
                        <div class="overflow-x-auto">
                            <table class="w-full text-left text-xs text-slate-300">
                                <thead class="border-b border-[#222A33] text-slate-500 uppercase text-[10px]">
                                    <tr>
                                        <th class="py-2.5">Item</th>
                                        <th class="py-2.5">Category</th>
                                        <th class="py-2.5 font-mono">Current Bid</th>
                                        <th class="py-2.5">Clicks / Hearts</th>
                                        <th class="py-2.5">Status</th>
                                        <th class="py-2.5 text-right">Actions</th>
                                    </tr>
                                </thead>
                                <tbody class="divide-y divide-[#222A33]">
                                    <?php foreach ($listings as $l): ?>
                                        <tr>
                                            <td class="py-3 flex items-center gap-2.5">
                                                <img src="<?= e($l['image_url']) ?>" class="w-8 h-8 rounded-lg object-cover" />
                                                <div class="min-w-0">
                                                    <div class="font-bold text-white truncate max-w-[180px]"><?= e($l['name']) ?></div>
                                                    <a href="<?= e($l['url']) ?>" target="_blank" class="text-[10px] text-slate-400 hover:text-emerald-400 truncate block"><?= e($l['url']) ?></a>
                                                </div>
                                            </td>
                                            <td class="py-3"><?= e($l['category_name']) ?></td>
                                            <td class="py-3 font-mono font-bold text-emerald-400"><?= $currency ?><?= number_format($l['current_bid'], 0) ?></td>
                                            <td class="py-3 font-mono text-[11px]">👆 <?= number_format($l['clicks']) ?> · ❤️ <?= number_format($l['hearts']) ?></td>
                                            <td class="py-3">
                                                <span class="px-2 py-0.5 rounded text-[10px] font-bold <?= $l['is_active'] ? 'bg-emerald-950 text-emerald-400' : 'bg-slate-800 text-slate-400' ?>">
                                                    <?= $l['is_active'] ? 'Active' : 'Inactive' ?>
                                                </span>
                                            </td>
                                            <td class="py-3 text-right">
                                                <form method="POST" class="inline" onsubmit="return confirm('Delete this listing and bid history?');">
                                                    <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                                                    <input type="hidden" name="action" value="delete_listing" />
                                                    <input type="hidden" name="id" value="<?= $l['id'] ?>" />
                                                    <button type="submit" class="px-2.5 py-1 rounded bg-rose-950/60 hover:bg-rose-900 text-rose-300 text-[10px] font-bold cursor-pointer">
                                                        Delete
                                                    </button>
                                                </form>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>

            <!-- TAB 3: CATEGORIES CRUD -->
            <?php elseif ($activeTab === 'categories'): ?>
                <div class="space-y-6">
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">Add New Category</h2>
                        <form method="POST" class="grid grid-cols-1 sm:grid-cols-4 gap-3 text-xs">
                            <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                            <input type="hidden" name="action" value="add_category" />

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Category Name</label>
                                <input type="text" name="name" required placeholder="e.g. Developer" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Slug</label>
                                <input type="text" name="slug" placeholder="e.g. developer" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Display Order</label>
                                <input type="number" name="display_order" value="1" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div class="flex items-end">
                                <button type="submit" class="w-full py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                    + Add Category
                                </button>
                            </div>
                        </form>
                    </div>

                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">Categories List (<?= count($categories) ?>)</h2>
                        <div class="grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs">
                            <?php foreach ($categories as $cat): ?>
                                <div class="p-3.5 rounded-xl bg-[#0A0D0F] border border-[#222A33] flex items-center justify-between">
                                    <div>
                                        <span class="font-bold text-white"><?= e($cat['name']) ?></span>
                                        <span class="text-[10px] text-slate-500 block font-mono">slug: <?= e($cat['slug']) ?> · order: <?= $cat['display_order'] ?></span>
                                    </div>
                                    <form method="POST" onsubmit="return confirm('Delete category?');">
                                        <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                                        <input type="hidden" name="action" value="delete_category" />
                                        <input type="hidden" name="id" value="<?= $cat['id'] ?>" />
                                        <button type="submit" class="px-2 py-1 rounded bg-rose-950/60 hover:bg-rose-900 text-rose-300 text-[10px] font-bold">
                                            Delete
                                        </button>
                                    </form>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div>

            <!-- TAB 4: PAYMENT GATEWAYS CONFIGURATION -->
            <?php elseif ($activeTab === 'gateways'): ?>
                <div class="space-y-6">
                    <div class="p-4 rounded-xl bg-emerald-950/40 border border-emerald-800/60 text-xs text-emerald-300">
                        💡 Configure live production credentials or switch any gateway to <strong>Sandbox Test Mode</strong> for development. In live mode, payments execute real merchant API handshakes with server-side validation.
                    </div>

                    <?php foreach ($gateways as $gw): 
                        $gid = $gw['gateway_id'];
                    ?>
                        <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                            <div class="flex items-center justify-between border-b border-[#222A33] pb-3">
                                <div class="flex items-center gap-3">
                                    <span class="w-8 h-8 rounded-lg flex items-center justify-center font-bold text-xs 
                                        <?= $gid === 'bkash' ? 'bg-pink-900/60 text-pink-400 border border-pink-700/50' : 
                                           ($gid === 'nagad' ? 'bg-orange-900/60 text-orange-400 border border-orange-700/50' : 
                                           ($gid === 'rocket' ? 'bg-purple-900/60 text-purple-400 border border-purple-700/50' : 
                                           ($gid === 'sslcommerz' ? 'bg-blue-900/60 text-blue-400 border border-blue-700/50' : 'bg-cyan-900/60 text-cyan-400 border border-cyan-700/50'))) ?>">
                                        <?= strtoupper(substr($gid, 0, 2)) ?>
                                    </span>
                                    <div>
                                        <h3 class="font-bold text-base text-white"><?= e($gw['name']) ?></h3>
                                        <span class="text-[10px] font-mono text-slate-500 uppercase">Gateway ID: <?= e($gid) ?></span>
                                    </div>
                                </div>
                                <span class="px-2.5 py-1 rounded-full text-xs font-bold font-mono <?= $gw['is_enabled'] ? 'bg-emerald-950 text-emerald-400 border border-emerald-700' : 'bg-slate-800 text-slate-400' ?>">
                                    <?= $gw['is_enabled'] ? ($gw['mode'] === 'live' ? 'LIVE PRODUCTION' : 'SANDBOX TEST') : 'DISABLED' ?>
                                </span>
                            </div>

                            <form method="POST" class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
                                <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                                <input type="hidden" name="action" value="save_gateway_config" />
                                <input type="hidden" name="gateway_id" value="<?= e($gid) ?>" />

                                <div class="flex items-center gap-4 sm:col-span-2 p-3 bg-[#0A0D0F] border border-[#222A33] rounded-xl">
                                    <label class="flex items-center gap-2 text-slate-300 font-semibold cursor-pointer">
                                        <input type="checkbox" name="is_enabled" value="1" <?= $gw['is_enabled'] ? 'checked' : '' ?> class="rounded" />
                                        <span>Enable this Gateway on Public Checkout</span>
                                    </label>

                                    <div class="flex items-center gap-3 ml-auto">
                                        <span class="text-slate-400 font-medium">Environment:</span>
                                        <label class="inline-flex items-center gap-1.5 text-slate-300 cursor-pointer">
                                            <input type="radio" name="mode" value="test" <?= $gw['mode'] === 'test' ? 'checked' : '' ?> />
                                            <span class="text-amber-400 font-semibold">Sandbox (Test)</span>
                                        </label>
                                        <label class="inline-flex items-center gap-1.5 text-slate-300 cursor-pointer ml-2">
                                            <input type="radio" name="mode" value="live" <?= $gw['mode'] === 'live' ? 'checked' : '' ?> />
                                            <span class="text-emerald-400 font-semibold">Live Production</span>
                                        </label>
                                    </div>
                                </div>

                                <?php if ($gid === 'bkash'): ?>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">bKash Merchant Wallet / MSISDN</label>
                                        <input type="text" name="merchant_id" value="<?= e($gw['merchant_id']) ?>" placeholder="e.g. 01700000000" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">bKash API Username</label>
                                        <input type="text" name="username" value="<?= e($gw['username']) ?>" placeholder="sandbox_user or merchant_username" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">bKash API Password</label>
                                        <input type="password" name="password" value="<?= e($gw['password']) ?>" placeholder="API Password" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">bKash App Key</label>
                                        <input type="text" name="app_key" value="<?= e($gw['app_key']) ?>" placeholder="App Key from bKash Developer Portal" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">bKash App Secret</label>
                                        <input type="text" name="app_secret" value="<?= e($gw['app_secret']) ?>" placeholder="App Secret" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">bKash Base API URL</label>
                                        <input type="url" name="api_url" value="<?= e($gw['api_url']) ?>" placeholder="https://tokenized.sandbox.bka.sh/v1.2.0-beta" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div class="sm:col-span-2">
                                        <label class="block text-slate-300 font-semibold mb-1">Callback / Webhook URL</label>
                                        <input type="text" name="callback_url" value="<?= e($gw['callback_url'] ?: '/payments/bkash.php') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>

                                <?php elseif ($gid === 'nagad'): ?>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">Nagad Merchant ID</label>
                                        <input type="text" name="merchant_id" value="<?= e($gw['merchant_id']) ?>" placeholder="e.g. 683002007104245" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">Nagad API Base URL</label>
                                        <input type="url" name="api_url" value="<?= e($gw['api_url']) ?>" placeholder="http://sandbox.mynagad.com:10080/remote-payment-gateway-1.0/api/dfs" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div class="sm:col-span-2">
                                        <label class="block text-slate-300 font-semibold mb-1">Nagad Public Key (PG Public Key)</label>
                                        <textarea name="app_key" rows="2" placeholder="-----BEGIN PUBLIC KEY-----..." class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono text-[11px]"><?= e($gw['app_key']) ?></textarea>
                                    </div>
                                    <div class="sm:col-span-2">
                                        <label class="block text-slate-300 font-semibold mb-1">Merchant Private Key</label>
                                        <textarea name="app_secret" rows="2" placeholder="-----BEGIN RSA PRIVATE KEY-----..." class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono text-[11px]"><?= e($gw['app_secret']) ?></textarea>
                                    </div>
                                    <div class="sm:col-span-2">
                                        <label class="block text-slate-300 font-semibold mb-1">Nagad Callback Return URL</label>
                                        <input type="text" name="callback_url" value="<?= e($gw['callback_url'] ?: '/payments/nagad.php') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>

                                <?php elseif ($gid === 'rocket'): ?>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">DBBL Rocket Biller / Merchant Account</label>
                                        <input type="text" name="merchant_id" value="<?= e($gw['merchant_id']) ?>" placeholder="e.g. 019000000009" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">Rocket Secret Key / PIN Hash</label>
                                        <input type="password" name="app_key" value="<?= e($gw['app_key']) ?>" placeholder="DBBL Secret Auth Token" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div class="sm:col-span-2">
                                        <label class="block text-slate-300 font-semibold mb-1">Rocket Callback URL</label>
                                        <input type="text" name="callback_url" value="<?= e($gw['callback_url'] ?: '/payments/rocket.php') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>

                                <?php elseif ($gid === 'sslcommerz'): ?>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">SSLCommerz Store ID</label>
                                        <input type="text" name="store_id" value="<?= e($gw['store_id']) ?>" placeholder="e.g. yourstorelive or testbox" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">SSLCommerz Store Password / Secret</label>
                                        <input type="password" name="password" value="<?= e($gw['password']) ?>" placeholder="Store Password" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">SSLCommerz API URL</label>
                                        <input type="url" name="api_url" value="<?= e($gw['api_url']) ?>" placeholder="https://sandbox.sslcommerz.com/gwprocess/v4/api.php" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">SSLCommerz IPN / Callback URL</label>
                                        <input type="text" name="callback_url" value="<?= e($gw['callback_url'] ?: '/payments/sslcommerz.php') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>

                                <?php elseif ($gid === 'shurjopay'): ?>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">shurjoPay Merchant Username</label>
                                        <input type="text" name="username" value="<?= e($gw['username']) ?>" placeholder="sp_merchant_username" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">shurjoPay Merchant Password</label>
                                        <input type="password" name="password" value="<?= e($gw['password']) ?>" placeholder="sp_password" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">shurjoPay Store Prefix (Client Prefix)</label>
                                        <input type="text" name="store_id" value="<?= e($gw['store_id']) ?>" placeholder="e.g. SP or NOK" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div>
                                        <label class="block text-slate-300 font-semibold mb-1">shurjoPay Engine API URL</label>
                                        <input type="url" name="api_url" value="<?= e($gw['api_url']) ?>" placeholder="https://engine.spg.shurjopay.com/api" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                    <div class="sm:col-span-2">
                                        <label class="block text-slate-300 font-semibold mb-1">shurjoPay Return / Callback URL</label>
                                        <input type="text" name="callback_url" value="<?= e($gw['callback_url'] ?: '/payments/shurjopay.php') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                    </div>
                                <?php endif; ?>

                                <div class="sm:col-span-2 pt-2 border-t border-[#222A33]">
                                    <button type="submit" class="px-5 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold text-xs shadow-lg shadow-emerald-950/40 cursor-pointer">
                                        Save <?= e($gw['name']) ?> Configuration
                                    </button>
                                </div>
                            </form>
                        </div>
                    <?php endforeach; ?>
                </div>

            <!-- TAB 5: PAYMENTS AUDIT & VERIFICATION -->
            <?php elseif ($activeTab === 'payments'): ?>
                <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-5">
                    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 border-b border-[#222A33] pb-4">
                        <div>
                            <h2 class="font-bold text-base text-white">Payment Transactions & Audit Ledger</h2>
                            <p class="text-xs text-slate-400">Strict server-verified payment logs. Listings are activated ONLY upon verification.</p>
                        </div>
                        <span class="text-xs text-emerald-400 font-mono font-bold bg-emerald-950/60 border border-emerald-800/60 px-3 py-1.5 rounded-xl">
                            Total Records: <?= count($payments) ?>
                        </span>
                    </div>

                    <!-- Search & Filter Controls -->
                    <form method="GET" class="grid grid-cols-1 sm:grid-cols-4 gap-3 text-xs bg-[#0A0D0F] border border-[#222A33] p-3.5 rounded-xl">
                        <input type="hidden" name="tab" value="payments" />
                        
                        <div>
                            <label class="block text-slate-400 mb-1 font-medium">Search Txn / Name / IP</label>
                            <input type="text" name="search_pay" value="<?= e($searchPay) ?>" placeholder="e.g. TXN-BKASH or 127.0.0.1" class="w-full px-3 py-1.5 bg-[#13181D] border border-[#222A33] rounded-lg text-white font-mono" />
                        </div>

                        <div>
                            <label class="block text-slate-400 mb-1 font-medium">Gateway</label>
                            <select name="filter_gateway" class="w-full px-3 py-1.5 bg-[#13181D] border border-[#222A33] rounded-lg text-white font-mono">
                                <option value="all" <?= $filterGateway === 'all' ? 'selected' : '' ?>>All Gateways</option>
                                <option value="bkash" <?= $filterGateway === 'bkash' ? 'selected' : '' ?>>bKash</option>
                                <option value="nagad" <?= $filterGateway === 'nagad' ? 'selected' : '' ?>>Nagad</option>
                                <option value="rocket" <?= $filterGateway === 'rocket' ? 'selected' : '' ?>>Rocket</option>
                                <option value="sslcommerz" <?= $filterGateway === 'sslcommerz' ? 'selected' : '' ?>>SSLCommerz</option>
                                <option value="shurjopay" <?= $filterGateway === 'shurjopay' ? 'selected' : '' ?>>shurjoPay</option>
                            </select>
                        </div>

                        <div>
                            <label class="block text-slate-400 mb-1 font-medium">Status</label>
                            <select name="filter_status" class="w-full px-3 py-1.5 bg-[#13181D] border border-[#222A33] rounded-lg text-white font-mono">
                                <option value="all" <?= $filterStatus === 'all' ? 'selected' : '' ?>>All Statuses</option>
                                <option value="success" <?= $filterStatus === 'success' ? 'selected' : '' ?>>Success (Active)</option>
                                <option value="pending" <?= $filterStatus === 'pending' ? 'selected' : '' ?>>Pending</option>
                                <option value="failed" <?= $filterStatus === 'failed' ? 'selected' : '' ?>>Failed</option>
                                <option value="cancelled" <?= $filterStatus === 'cancelled' ? 'selected' : '' ?>>Cancelled</option>
                            </select>
                        </div>

                        <div class="flex items-end gap-2">
                            <div class="flex-1">
                                <label class="block text-slate-400 mb-1 font-medium">Mode</label>
                                <select name="filter_mode" class="w-full px-3 py-1.5 bg-[#13181D] border border-[#222A33] rounded-lg text-white font-mono">
                                    <option value="all" <?= $filterMode === 'all' ? 'selected' : '' ?>>All Modes</option>
                                    <option value="live" <?= $filterMode === 'live' ? 'selected' : '' ?>>Live</option>
                                    <option value="test" <?= $filterMode === 'test' ? 'selected' : '' ?>>Sandbox</option>
                                </select>
                            </div>
                            <button type="submit" class="px-4 py-1.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 text-white font-bold cursor-pointer">
                                Filter
                            </button>
                        </div>
                    </form>

                    <div class="overflow-x-auto">
                        <table class="w-full text-left text-xs text-slate-300">
                            <thead class="border-b border-[#222A33] text-slate-500 uppercase text-[10px]">
                                <tr>
                                    <th class="py-2.5 font-mono">Txn ID</th>
                                    <th class="py-2.5">Listing</th>
                                    <th class="py-2.5 font-mono">Amount</th>
                                    <th class="py-2.5">Gateway</th>
                                    <th class="py-2.5">Mode</th>
                                    <th class="py-2.5">Status</th>
                                    <th class="py-2.5 font-mono">IP Address</th>
                                    <th class="py-2.5">Date</th>
                                    <th class="py-2.5 text-right">Actions</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-[#222A33]">
                                <?php if (empty($payments)): ?>
                                    <tr>
                                        <td colspan="9" class="py-8 text-center text-slate-500 font-mono">No payment transactions matching filter criteria.</td>
                                    </tr>
                                <?php else: ?>
                                    <?php foreach ($payments as $p): ?>
                                        <tr>
                                            <td class="py-3 font-mono font-bold text-slate-200"><?= e($p['transaction_id']) ?></td>
                                            <td class="py-3 max-w-[150px] truncate text-white font-semibold" title="<?= e($p['listing_name']) ?>">
                                                <?= e($p['listing_name']) ?>
                                            </td>
                                            <td class="py-3 font-mono font-bold text-emerald-400"><?= $currency ?><?= number_format($p['amount'], 0) ?></td>
                                            <td class="py-3 uppercase font-mono text-[10px] font-bold"><?= e($p['gateway']) ?></td>
                                            <td class="py-3">
                                                <span class="px-2 py-0.5 rounded text-[10px] font-bold font-mono <?= $p['mode'] === 'live' ? 'bg-emerald-950 text-emerald-400 border border-emerald-800' : 'bg-amber-950 text-amber-400 border border-amber-800' ?>">
                                                    <?= strtoupper($p['mode']) ?>
                                                </span>
                                            </td>
                                            <td class="py-3">
                                                <span class="px-2 py-0.5 rounded text-[10px] font-bold <?= $p['status'] === 'success' ? 'bg-emerald-950 text-emerald-400 border border-emerald-800' : ($p['status'] === 'pending' ? 'bg-amber-950 text-amber-400 border border-amber-800' : 'bg-rose-950 text-rose-400 border border-rose-800') ?>">
                                                    <?= strtoupper($p['status']) ?>
                                                </span>
                                            </td>
                                            <td class="py-3 font-mono text-[10px] text-slate-400"><?= e($p['ip_address'] ?: 'N/A') ?></td>
                                            <td class="py-3 text-[10px] text-slate-500"><?= date('M d, H:i', strtotime($p['created_at'])) ?></td>
                                            <td class="py-3 text-right">
                                                <?php if ($p['status'] === 'pending'): ?>
                                                    <form method="POST" class="inline">
                                                        <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                                                        <input type="hidden" name="action" value="verify_payment_manual" />
                                                        <input type="hidden" name="transaction_id" value="<?= e($p['transaction_id']) ?>" />
                                                        <button type="submit" class="px-2.5 py-1 rounded-lg bg-emerald-700 hover:bg-emerald-600 text-white text-[10px] font-bold shadow cursor-pointer" onclick="return confirm('Verify this transaction manually and promote the listing?');">
                                                            Approve & Verify
                                                        </button>
                                                    </form>
                                                <?php else: ?>
                                                    <span class="text-[10px] text-slate-500 font-mono">Verified</span>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                            </tbody>
                        </table>
                    </div>
                </div>

            <!-- TAB 6: DESIGN & COLORS -->
            <?php elseif ($activeTab === 'design'): ?>
                <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                    <h2 class="font-bold text-sm text-white">Visual Design & Theme Customizer</h2>
                    <p class="text-xs text-slate-400">All color changes immediately apply as dynamic CSS variables on the live public board.</p>

                    <form method="POST" class="grid grid-cols-1 sm:grid-cols-3 gap-4 text-xs">
                        <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                        <input type="hidden" name="action" value="save_design_settings" />

                        <?php
                        $colorFields = [
                            'primary_color' => ['label' => 'Primary Brand Color', 'def' => '#006A4E'],
                            'secondary_color' => ['label' => 'Secondary Red Accent', 'def' => '#F42A41'],
                            'accent_color' => ['label' => 'Gold / Amber Accent', 'def' => '#F59E0B'],
                            'background_color' => ['label' => 'Body Canvas Background', 'def' => '#0A0D0F'],
                            'card_color' => ['label' => 'Standard Card Background', 'def' => '#13181D'],
                            'border_color' => ['label' => 'Border & Dividers Color', 'def' => '#222A33'],
                            'header_bg' => ['label' => 'Sticky Header Background', 'def' => '#0A0D0FEE'],
                            'footer_bg' => ['label' => 'Footer Background', 'def' => '#07090B'],
                            'text_color' => ['label' => 'Main Heading Text Color', 'def' => '#F0F4F8'],
                            'muted_text_color' => ['label' => 'Muted Body Text Color', 'def' => '#8A99A8'],
                            'rank1_bg' => ['label' => 'Rank #1 Card Background', 'def' => '#1C2422'],
                            'rank1_border' => ['label' => 'Rank #1 Card Border', 'def' => '#EAB308'],
                            'rank2_bg' => ['label' => 'Rank #2 Card Background', 'def' => '#171E24'],
                            'rank3_bg' => ['label' => 'Rank #3 Card Background', 'def' => '#141B20'],
                            'border_radius' => ['label' => 'Global Border Radius', 'def' => '12px'],
                        ];
                        foreach ($colorFields as $k => $f):
                            $val = $settings[$k] ?? $f['def'];
                        ?>
                            <div class="space-y-1">
                                <label class="block text-slate-300 font-semibold"><?= $f['label'] ?></label>
                                <div class="flex items-center gap-2">
                                    <?php if (str_starts_with($val, '#')): ?>
                                        <input type="color" value="<?= e(substr($val, 0, 7)) ?>" onchange="this.nextElementSibling.value=this.value" class="w-8 h-8 rounded bg-transparent cursor-pointer border border-slate-700" />
                                    <?php endif; ?>
                                    <input type="text" name="<?= $k ?>" value="<?= e($val) ?>" class="flex-1 px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                                </div>
                            </div>
                        <?php endforeach; ?>

                        <div class="sm:col-span-3 pt-2">
                            <button type="submit" class="px-6 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                Save Visual Theme
                            </button>
                        </div>
                    </form>
                </div>

            <!-- TAB 7: FRONTEND TEXTS -->
            <?php elseif ($activeTab === 'texts'): ?>
                <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                    <h2 class="font-bold text-sm text-white">Frontend Labels & Copy Settings</h2>
                    <p class="text-xs text-slate-400">Edit any label across the public board without modifying template code.</p>

                    <form method="POST" class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
                        <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                        <input type="hidden" name="action" value="save_frontend_texts" />

                        <?php foreach ($frontendTexts as $tKey => $tVal): ?>
                            <div class="space-y-1">
                                <label class="block text-slate-400 font-mono text-[10px] uppercase font-bold"><?= e($tKey) ?></label>
                                <?php if (strlen($tVal) > 60): ?>
                                    <textarea name="<?= e($tKey) ?>" rows="2" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white"><?= e($tVal) ?></textarea>
                                <?php else: ?>
                                    <input type="text" name="<?= e($tKey) ?>" value="<?= e($tVal) ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                                <?php endif; ?>
                            </div>
                        <?php endforeach; ?>

                        <div class="sm:col-span-2 pt-2">
                            <button type="submit" class="px-6 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                Save Frontend Texts
                            </button>
                        </div>
                    </form>
                </div>

            <!-- TAB 8: NAVIGATION MENU -->
            <?php elseif ($activeTab === 'menu'): ?>
                <div class="space-y-6">
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">Add Navigation Menu Item</h2>
                        <form method="POST" class="grid grid-cols-1 sm:grid-cols-4 gap-3 text-xs">
                            <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                            <input type="hidden" name="action" value="add_menu_item" />

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Title</label>
                                <input type="text" name="title" required placeholder="Rules" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">URL / Link</label>
                                <input type="text" name="url" required placeholder="/rules" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Display Order</label>
                                <input type="number" name="display_order" value="1" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div class="flex items-end">
                                <button type="submit" class="w-full py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                    + Add Menu Item
                                </button>
                            </div>
                        </form>
                    </div>

                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">Current Header Links (<?= count($menuItems) ?>)</h2>
                        <div class="space-y-2 text-xs">
                            <?php foreach ($menuItems as $m): ?>
                                <div class="p-3 rounded-xl bg-[#0A0D0F] border border-[#222A33] flex items-center justify-between">
                                    <div>
                                        <span class="font-bold text-white"><?= e($m['title']) ?></span>
                                        <span class="text-[10px] text-slate-500 block font-mono"><?= e($m['url']) ?> · order: <?= $m['display_order'] ?></span>
                                    </div>
                                    <form method="POST" onsubmit="return confirm('Remove menu link?');">
                                        <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                                        <input type="hidden" name="action" value="delete_menu_item" />
                                        <input type="hidden" name="id" value="<?= $m['id'] ?>" />
                                        <button type="submit" class="px-2.5 py-1 rounded bg-rose-950/60 hover:bg-rose-900 text-rose-300 text-[10px] font-bold">
                                            Remove
                                        </button>
                                    </form>
                                </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div>

            <!-- TAB 9: CONTENT & LEGAL PAGES -->
            <?php elseif ($activeTab === 'pages'): ?>
                <div class="space-y-6">
                    <?php foreach ($pages as $pg): ?>
                        <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                            <h2 class="font-bold text-sm text-white">Edit Page: <?= e($pg['title']) ?> (<?= e($pg['slug']) ?>)</h2>
                            <form method="POST" class="space-y-3 text-xs">
                                <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                                <input type="hidden" name="action" value="save_page_content" />
                                <input type="hidden" name="slug" value="<?= e($pg['slug']) ?>" />

                                <div>
                                    <label class="block text-slate-300 font-semibold mb-1">Page Title</label>
                                    <input type="text" name="title" value="<?= e($pg['title']) ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                                </div>

                                <div>
                                    <label class="block text-slate-300 font-semibold mb-1">Content (HTML / Text)</label>
                                    <textarea name="content" rows="6" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono leading-relaxed"><?= e($pg['content']) ?></textarea>
                                </div>

                                <button type="submit" class="px-4 py-2 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold cursor-pointer">
                                    Save <?= e($pg['title']) ?> Content
                                </button>
                            </form>
                        </div>
                    <?php endforeach; ?>
                </div>

            <!-- TAB 10: DEVELOPER POPUP -->
            <?php elseif ($activeTab === 'developer'): ?>
                <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                    <h2 class="font-bold text-sm text-white">Developer Attribution & Popup</h2>
                    <p class="text-xs text-slate-400">Controls the interactive developer profile modal triggered when visitors click "Built by @arafat".</p>

                    <form method="POST" class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
                        <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                        <input type="hidden" name="action" value="save_developer_settings" />

                        <div class="sm:col-span-2">
                            <label class="flex items-center gap-2 text-slate-300">
                                <input type="checkbox" name="developer_enabled" value="1" <?= ($settings['developer_enabled'] ?? '1') === '1' ? 'checked' : '' ?> />
                                <span>Enable Developer Attribution Popup Modal</span>
                            </label>
                        </div>

                        <div>
                            <label class="block text-slate-300 font-semibold mb-1">Developer Full Name</label>
                            <input type="text" name="developer_name" value="<?= e($settings['developer_name'] ?? 'Arafat Rahman') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                        </div>

                        <div>
                            <label class="block text-slate-300 font-semibold mb-1">Username / Handle</label>
                            <input type="text" name="developer_handle" value="<?= e($settings['developer_handle'] ?? '@arafat') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                        </div>

                        <div class="sm:col-span-2">
                            <label class="block text-slate-300 font-semibold mb-1">Bio / Profile Description</label>
                            <textarea name="developer_bio" rows="3" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white"><?= e($settings['developer_bio'] ?? '') ?></textarea>
                        </div>

                        <div class="sm:col-span-2">
                            <label class="block text-slate-300 font-semibold mb-1">Profile Picture URL</label>
                            <input type="url" name="developer_image" value="<?= e($settings['developer_image'] ?? '') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                        </div>

                        <div>
                            <label class="block text-slate-300 font-semibold mb-1">GitHub / Code Profile URL</label>
                            <input type="url" name="developer_github" value="<?= e($settings['developer_github'] ?? '') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                        </div>

                        <div>
                            <label class="block text-slate-300 font-semibold mb-1">Twitter / X / Social URL</label>
                            <input type="url" name="developer_twitter" value="<?= e($settings['developer_twitter'] ?? '') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                        </div>

                        <div class="sm:col-span-2 pt-2">
                            <button type="submit" class="px-6 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                Save Developer Profile
                            </button>
                        </div>
                    </form>
                </div>

            <!-- TAB 11: GENERAL SETTINGS & SECURITY -->
            <?php elseif ($activeTab === 'settings'): ?>
                <div class="space-y-6">
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">General Platform Settings</h2>
                        <form method="POST" class="grid grid-cols-1 sm:grid-cols-2 gap-4 text-xs">
                            <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                            <input type="hidden" name="action" value="save_general_settings" />

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Site Name / Logo Title</label>
                                <input type="text" name="site_name" value="<?= e($settings['site_name'] ?? 'TOPBD') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Site Subtitle</label>
                                <input type="text" name="site_subtitle" value="<?= e($settings['site_subtitle'] ?? "Bangladesh's Live Ranking & Outbid Marketplace") ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Site Base URL</label>
                                <input type="url" name="site_url" value="<?= e($settings['site_url'] ?? 'https://topbd.app') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Currency Symbol</label>
                                <input type="text" name="currency_symbol" value="<?= e($settings['currency_symbol'] ?? '৳') ?>" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Minimum Bid Increment (৳)</label>
                                <input type="number" name="minimum_bid_increment" value="<?= e($settings['minimum_bid_increment'] ?? '1') ?>" min="1" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Initial Minimum Bid (৳)</label>
                                <input type="number" name="initial_minimum_bid" value="<?= e($settings['initial_minimum_bid'] ?? '10') ?>" min="1" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Visitor Online Timeout (Seconds)</label>
                                <input type="number" name="visitor_timeout_seconds" value="<?= e($settings['visitor_timeout_seconds'] ?? '180') ?>" min="30" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Listings Per Page (Pagination Size)</label>
                                <input type="number" name="pagination_size" value="<?= e($settings['pagination_size'] ?? '50') ?>" min="10" max="100" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white font-mono" />
                            </div>

                            <div class="sm:col-span-2 pt-2">
                                <button type="submit" class="px-6 py-2.5 rounded-xl bg-emerald-600 hover:bg-emerald-500 text-white font-bold shadow-md cursor-pointer">
                                    Save General Settings
                                </button>
                            </div>
                        </form>
                    </div>

                    <!-- Security & Password Change -->
                    <div class="bg-[#13181D] border border-[#222A33] rounded-2xl p-5 space-y-4">
                        <h2 class="font-bold text-sm text-white">Change Admin Password</h2>
                        <form method="POST" class="grid grid-cols-1 sm:grid-cols-3 gap-4 text-xs">
                            <input type="hidden" name="csrf_token" value="<?= e(csrf_token()) ?>" />
                            <input type="hidden" name="action" value="change_admin_password" />

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Current Password</label>
                                <input type="password" name="current_password" required placeholder="••••••••" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">New Password (min 6 chars)</label>
                                <input type="password" name="new_password" required placeholder="••••••••" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div>
                                <label class="block text-slate-300 font-semibold mb-1">Confirm New Password</label>
                                <input type="password" name="confirm_password" required placeholder="••••••••" class="w-full px-3 py-2 bg-[#0A0D0F] border border-[#222A33] rounded-xl text-white" />
                            </div>

                            <div class="sm:col-span-3">
                                <button type="submit" class="px-6 py-2.5 rounded-xl bg-rose-700 hover:bg-rose-600 text-white font-bold cursor-pointer">
                                    Update Password
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            <?php endif; ?>
        </main>
    </div>

    <!-- Admin Footer -->
    <footer class="border-t border-[#222A33] py-4 text-center text-xs text-slate-500 mt-auto bg-[#0A0D0F]">
        <?= e($settings['site_name'] ?? 'TOPBD') ?> Control Center · PHP 8+ & MySQL Production Build
    </footer>
</body>
</html>
