<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-users-cog me-2 text-primary"></i>Users</h5>
    <a class="btn btn-sm btn-primary" href="<?= url('/Users/create') ?>"><i class="fas fa-plus me-1"></i>New User</a>
</div>

<?php if (!empty($flash)): ?><div class="alert alert-info py-2 small"><?= e($flash) ?></div><?php endif; ?>

<div class="rs-card p-3">
<?php if (empty($users)): ?>
    <p class="text-muted small mb-0">No users yet.</p>
<?php else: ?>
    <table class="table table-sm table-hover mb-0">
        <thead><tr><th>Username</th><th>Name</th><th>Role</th><th>Email</th><th>Phone</th><th>Last Login</th><th>Status</th><th></th></tr></thead>
        <tbody>
            <?php foreach ($users as $u): ?>
                <tr>
                    <td><a href="<?= url('/Users/edit/' . (int) $u['user_id']) ?>" class="fw-semibold text-decoration-none"><?= e($u['username']) ?></a></td>
                    <td class="small"><?= e(trim(($u['f_name'] ?? '') . ' ' . ($u['l_name'] ?? ''))) ?></td>
                    <td><span class="badge bg-secondary text-uppercase"><?= e($u['role_name'] ?? '—') ?></span></td>
                    <td class="small text-muted"><?= e($u['email'] ?? '') ?></td>
                    <td class="small text-muted"><?= e($u['phone'] ?? '') ?></td>
                    <td class="small text-muted"><?= e($u['last_login_at'] ?? '—') ?></td>
                    <td><span class="badge bg-secondary text-uppercase"><?= e($u['status']) ?></span></td>
                    <td class="text-end"><a href="<?= url('/Users/delete/' . (int) $u['user_id']) ?>" class="text-danger small" onclick="return confirm('Delete user?')"><i class="fas fa-trash"></i></a></td>
                </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
<?php endif; ?>
</div>
