<h4 class="mb-4"><i class="fas fa-heartbeat me-2"></i><?= lang('admin.system_health') ?></h4>
<div class="row g-3 mb-4">
    <div class="col-md-3"><div class="card border-success h-100"><div class="card-body"><h6 class="text-muted">Active Members</h6><h3 class="mb-0"><?= number_format($health['active_members']) ?></h3><small class="text-muted">of <?= number_format($health['total_members']) ?> total</small></div></div></div>
    <div class="col-md-3"><div class="card border-primary h-100"><div class="card-body"><h6 class="text-muted">Active Users</h6><h3 class="mb-0"><?= $health['active_users'] ?></h3><small class="text-muted"><?= $health['active_sessions'] ?> sessions</small></div></div></div>
    <div class="col-md-3"><div class="card border-danger h-100"><div class="card-body"><h6 class="text-muted">Errors Today</h6><h3 class="mb-0"><?= $health['errors_today'] ?></h3></div></div></div>
    <div class="col-md-3"><div class="card border-warning h-100"><div class="card-body"><h6 class="text-muted">DQ Issues</h6><h3 class="mb-0"><?= $health['open_dq_issues'] ?></h3><small class="text-muted"><?= $health['pending_notifications'] ?> pending notifications</small></div></div></div>
</div>
<div class="row g-4">
    <div class="col-md-6"><div class="card"><div class="card-header">Server Information</div><div class="card-body">
        <table class="table table-sm table-borderless mb-0">
            <tr><td class="text-muted" width="40%">PHP Version</td><td><?= e($health['php_version']) ?></td></tr>
            <tr><td class="text-muted">MySQL Version</td><td><?= e($health['mysql_version']) ?></td></tr>
            <tr><td class="text-muted">Web Server</td><td><?= e($health['server_software']) ?></td></tr>
            <tr><td class="text-muted">Memory Usage</td><td><?= e($health['memory_usage']) ?> / <?= e($health['memory_limit']) ?></td></tr>
            <tr><td class="text-muted">Max Upload</td><td><?= e($health['max_upload']) ?></td></tr>
            <tr><td class="text-muted">Max POST</td><td><?= e($health['max_post']) ?></td></tr>
            <tr><td class="text-muted">Timezone</td><td><?= e($health['timezone']) ?></td></tr>
            <tr><td class="text-muted">Disk Free</td><td><?= e($health['disk_free']) ?> / <?= e($health['disk_total']) ?></td></tr>
            <tr><td class="text-muted">Storage Used</td><td><?= e($health['storage_used']) ?></td></tr>
        </table>
    </div></div></div>
    <div class="col-md-6"><div class="card"><div class="card-header">Recent Errors</div><div class="card-body" style="max-height:400px;overflow:auto">
        <?php if (empty($recentErrors)): ?>
        <div class="text-center text-muted py-4"><i class="fas fa-check-circle fa-3x mb-2 text-success"></i><p>No recent errors</p></div>
        <?php else: ?>
        <div class="list-group list-group-flush">
            <?php foreach ($recentErrors as $err): ?>
            <div class="list-group-item px-0">
                <div class="d-flex justify-content-between">
                    <span class="badge bg-<?= $err['error_level'] === 'critical' ? 'danger' : ($err['error_level'] === 'error' ? 'warning' : 'info') ?>"><?= e($err['error_level']) ?></span>
                    <small class="text-muted"><?= format_datetime($err['created_at']) ?></small>
                </div>
                <small class="text-truncate d-block" style="max-width:100%"><?= e(str_limit($err['message'], 120)) ?></small>
                <?php if ($err['file_path']): ?><small class="text-muted"><?= e(basename($err['file_path'])) ?>:<?= $err['line_number'] ?></small><?php endif; ?>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div></div></div>
</div>