<div class="d-flex justify-content-between align-items-center mb-3">
    <h5 class="fw-bold mb-0"><i class="fas fa-triangle-exclamation me-2 text-danger"></i>Incidents (read-only)</h5>
    <a href="<?= url('/ClientPortal') ?>" class="btn btn-sm btn-outline-secondary"><i class="fas fa-arrow-left me-1"></i>Portal</a>
</div>

<form method="get" action="<?= url('/ClientPortal/incidents') ?>" class="rs-card p-2 mb-3">
    <div class="row g-2 align-items-end">
        <div class="col-md-3"><select name="severity" class="form-select form-select-sm"><option value="">Any severity</option><?php foreach (['low','medium','high','critical'] as $s): ?><option value="<?= $s ?>" <?= ($filters['severity'] ?? '') === $s ? 'selected' : '' ?>><?= $s ?></option><?php endforeach; ?></select></div>
        <div class="col-md-3"><select name="status" class="form-select form-select-sm"><option value="">Any status</option><?php foreach (['draft','open','investigating','rca','closed_permanent','closed_temporary','cancelled'] as $s): ?><option value="<?= $s ?>" <?= ($filters['status'] ?? '') === $s ? 'selected' : '' ?>><?= $s ?></option><?php endforeach; ?></select></div>
        <div class="col-md-2"><button type="submit" class="btn btn-sm btn-outline-primary w-100"><i class="fas fa-filter me-1"></i>Filter</button></div>
    </div>
</form>

<div class="rs-card p-3">
<?php if (empty($incidents)): ?><p class="text-muted small mb-0">No incidents found.</p><?php else: ?>
    <table class="table table-sm table-hover mb-0">
        <thead><tr><th>Code</th><th>Title</th><th>Category</th><th>Severity</th><th>Status</th><th>Started</th><th>Closed</th></tr></thead>
        <tbody><?php foreach ($incidents as $i): ?><tr>
            <td class="small"><?= e($i['code'] ?? '#' . $i['incident_id']) ?></td>
            <td><?= e($i['title']) ?></td>
            <td class="small"><span class="badge bg-secondary text-uppercase"><?= e($i['category']) ?></span></td>
            <td><span class="badge bg-secondary text-uppercase"><?= e($i['severity']) ?></span></td>
            <td><span class="badge bg-secondary text-uppercase"><?= e($i['status']) ?></span></td>
            <td class="small text-muted"><?= e($i['start_at'] ?? '—') ?></td>
            <td class="small text-muted"><?= e($i['closed_at'] ?? '—') ?></td>
        </tr><?php endforeach; ?></tbody>
    </table>
<?php endif; ?>
</div>
