<?php $pageTitle = 'Users & Roles'; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <p class="text-secondary mb-0">System users and role management</p>
    <div class="d-flex gap-2">
        <a href="<?= base_url('admin/user-create') ?>" class="btn-cix btn-cix-accent btn-cix-sm"><i class="fas fa-plus"></i> New User</a>
        <a href="<?= base_url('admin/roles') ?>" class="btn-cix btn-cix-primary btn-cix-sm"><i class="fas fa-shield-alt"></i> Roles</a>
    </div>
</div>
<div class="card-cix">
    <div class="table-responsive">
        <table class="table-cix"><thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Status</th><th>Last Login</th></tr></thead>
        <tbody><?php if (empty($users)): ?><tr><td colspan="5" class="text-center text-secondary p-4">No users</td></tr>
        <?php else: foreach ($users as $u): ?>
        <tr><td><strong><?= e($u['first_name'] . ' ' . $u['last_name']) ?></strong></td><td class="text-secondary"><?= e($u['email']) ?></td>
        <td><span class="badge-cix badge-submitted"><?= e($u['role_name']) ?></span></td>
        <td><span class="badge-cix <?= $u['is_active'] ? 'badge-active' : 'badge-rejected' ?>"><?= $u['is_active'] ? 'Active' : 'Inactive' ?></span></td>
        <td class="text-secondary small"><?= $u['last_login_at'] ? time_elapsed($u['last_login_at']) : 'Never' ?></td></tr>
        <?php endforeach; endif; ?></tbody></table>
    </div>
</div>
