                            <i class="fas fa-user-plus mr-1"></i>
                            Recent User Registrations
                        </h3>
                        <div class="card-tools">
                            <a href="<?php echo base_url('admin/users/create.php'); ?>" class="btn btn-sm btn-primary">
                                <i class="fas fa-plus"></i> Add User
                            </a>
                        </div>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>User</th>
                                        <th>Username</th>
                                        <th>Role</th>
                                        <th>Status</th>
                                        <th>Joined</th>
                                        <th>Actions</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($recent_users as $user): ?>
                                    <tr>
                                        <td>
                                            <?php echo escape_html($user['first_name'] . ' ' . $user['last_name']); ?>
                                        </td>
                                        <td><?php echo escape_html($user['username']); ?></td>
                                        <td>
                                            <?php 
                                            $role_name = db_fetch_value("SELECT role_name FROM roles WHERE role_id = ?", [$user['role_id']]);
                                            echo escape_html($role_name);
                                            ?>
                                        </td>
                                        <td>
                                            <?php if ($user['is_active']): ?>
                                                <span class="badge badge-success">Active</span>
                                            <?php else: ?>
                                                <span class="badge badge-danger">Inactive</span>
                                            <?php endif; ?>
                                        </td>
                                        <td><?php echo time_ago($user['created_at']); ?></td>
                                        <td>
                                            <a href="<?php echo base_url('admin/users/view.php?id=' . $user['user_id']); ?>" 
                                               class="btn btn-sm btn-info" title="View">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                            <a href="<?php echo base_url('admin/users/edit.php?id=' . $user['user_id']); ?>" 
                                               class="btn btn-sm btn-primary" title="Edit">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                        </td>
                                    </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="card-footer text-center">
                        <a href="<?php echo base_url('admin/users/index.php'); ?>">View All Users</a>
                    </div>
                </div>
            </div>

            <!-- Recent Audit Logs -->
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-history mr-1"></i>
                            Recent Activity Log
                        </h3>
                        <div class="card-tools">
                            <a href="<?php echo base_url('admin/users/audit-logs.php'); ?>" class="btn btn-sm btn-primary">
                                View All Logs
                            </a>
                        </div>
                    </div>
                    <div class="card-body p-0">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th>Time</th>
                                        <th>User</th>
                                        <th>Action</th>
                                        <th>Details</th>
                                        <th>IP</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach ($recent_audit as $log): ?>
                                    <tr>
                                        <td><?php echo time_ago($log['created_at']); ?></td>
                                        <td>
                                            <?php if ($log['user_id']): ?>
                                                <a href="<?php echo base_url('admin/users/view.php?id=' . $log['user_id']); ?>">
                                                    <?php echo escape_html($log['first_name'] . ' ' . $log['last_name']); ?>
                                                </a>
                                            <?php else: ?>
                                                <span class="text-muted">System</span>
                                            <?php endif; ?>
                                        </td>
                                        <td>
                                            <span class="badge badge-<?php 
                                                echo $log['action'] == 'login' ? 'success' : 
                                                    ($log['action'] == 'logout' ? 'warning' : 
                                                    ($log['action'] == 'create' ? 'info' : 
                                                    ($log['action'] == 'update' ? 'primary' : 
                                                    ($log['action'] == 'delete' ? 'danger' : 'secondary'))));
                                            ?>">
                                                <?php echo ucfirst($log['action']); ?>
                                            </span>
                                        </td>
                                        <td>
                                            <?php 
                                            $details = [];
                                            if ($log['table_name']) {
                                                $details[] = str_replace('_', ' ', $log['table_name']);
                                            }
                                            if ($log['record_id']) {
                                                $details[] = '#' . $log['record_id'];
                                            }
                                            echo escape_html(implode(' ', $details));
                                            ?>
                                        </td>
                                        <td>
                                            <small class="text-muted"><?php echo $log['ip_address'] ?? 'N/A'; ?></small>
                                        </td>
                                    </tr>
                                    <?php endforeach; ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- System Information -->
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-info-circle mr-1"></i>
                            System Information
                        </h3>
                    </div>
                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-3 col-sm-6">
                                <strong>PHP Version:</strong>
                                <p><?php echo phpversion(); ?></p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>MySQL Version:</strong>
                                <p><?php 
                                    $version = db_fetch_value("SELECT VERSION()");
                                    echo $version;
                                ?></p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>Server Software:</strong>
                                <p><?php echo $_SERVER['SERVER_SOFTWARE'] ?? 'Unknown'; ?></p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>Max Upload Size:</strong>
                                <p><?php echo ini_get('upload_max_filesize'); ?></p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>Memory Limit:</strong>
                                <p><?php echo ini_get('memory_limit'); ?></p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>Max Execution Time:</strong>
                                <p><?php echo ini_get('max_execution_time'); ?>s</p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>Session Save Path:</strong>
                                <p><?php echo session_save_path() ?: 'Default'; ?></p>
                            </div>
                            <div class="col-md-3 col-sm-6">
                                <strong>Timezone:</strong>
                                <p><?php echo date_default_timezone_get(); ?></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.3.0/dist/chart.umd.min.js"></script>

<script>
$(document).ready(function() {
    // Activity Chart
    const ctx = document.getElementById('activityChart').getContext('2d');
    new Chart(ctx, {
        type: 'line',
        data: {
            labels: <?php echo json_encode($activity_data['labels']); ?>,
            datasets: [{
                label: 'Logins',
                data: <?php echo json_encode($activity_data['logins']); ?>,
                borderColor: 'rgb(40, 167, 69)',
                backgroundColor: 'rgba(40, 167, 69, 0.1)',
                tension: 0.1,
                fill: true
            }, {
                label: 'Actions',
                data: <?php echo json_encode($activity_data['actions']); ?>,
                borderColor: 'rgb(23, 162, 184)',
                backgroundColor: 'rgba(23, 162, 184, 0.1)',
                tension: 0.1,
                fill: true
            }]
        },
        options: {
            responsive: true,
            maintainAspectRatio: false,
            plugins: {
                legend: {
                    position: 'top',
                }
            },
            scales: {
                y: {
                    beginAtZero: true,
                    ticks: {
                        stepSize: 1
                    }
                }
            }
        }
    });
});
</script>

<style>
/* Custom bronze color for 3rd place */
.badge.bronze {
    background-color: #cd7f32;
    color: white;
}
.products-list .item {
    padding: 10px 0;
    border-bottom: 1px solid #f4f4f4;
}
.products-list .item:last-child {
    border-bottom: none;
}
</style>

<?php
// Include footer
require_once dirname(__DIR__) . '/views/partials/footer.php';
?>