<?php
session_start();
if (!isset($_SESSION['admin_logged_in'])) { header("Location: login.php"); exit(); }
require_once '../common/config.php';
include '../admin/header.php';

// ইউজার তালিকা আনা
$users = $conn->query("SELECT * FROM users WHERE role = 'user' ORDER BY id DESC");
?>

<div class="max-w-7xl mx-auto px-4 py-10">
    <div class="flex flex-col md:flex-row justify-between items-center mb-10 gap-4">
        <div>
            <h2 class="text-2xl md:text-3xl font-bold logo-font tracking-wider uppercase">
                USER <span class="text-blue-400 glow-text">REGISTRY</span>
            </h2>
            <p class="text-gray-500 text-xs font-bold uppercase tracking-[3px]">Manage active accounts and balances</p>
        </div>
        <a href="index.php" class="text-gray-400 hover:text-white uppercase text-[10px] tracking-widest border-b border-white/10 pb-1">
            <i class="fa-solid fa-arrow-left mr-2"></i> Back to Dashboard
        </a>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
        <?php while($user = $users->fetch_assoc()): ?>
            <div class="cyber-card p-6 border-t-4 border-blue-500/30 relative overflow-hidden group">
                <div class="flex items-center space-x-4 mb-6">
                    <div class="w-12 h-12 bg-blue-500/10 rounded-xl flex items-center justify-center text-blue-400 border border-blue-500/20">
                        <i class="fa-solid fa-user-shield text-xl"></i>
                    </div>
                    <div class="min-w-0">
                        <h3 class="text-white font-bold truncate uppercase"><?php echo $user['username']; ?></h3>
                        <p class="text-[9px] text-gray-500 font-mono"><?php echo $user['email']; ?></p>
                    </div>
                </div>

                <div class="bg-black/30 p-4 rounded-xl border border-white/5 mb-6">
                    <span class="text-[9px] font-bold text-gray-500 uppercase tracking-widest block mb-1">Current Balance</span>
                    <h4 class="text-2xl font-black text-cyan-400 tracking-tighter">৳<?php echo number_format($user['balance'], 2); ?></h4>
                </div>

                <a href="user-details.php?id=<?php echo $user['id']; ?>" class="block w-full bg-blue-600 hover:bg-blue-500 text-white text-center py-3 rounded-lg text-[10px] font-black uppercase tracking-widest transition-all">
                    View Activity & Manage
                </a>
            </div>
        <?php endwhile; ?>
    </div>
</div>