<?php use App\Core\Csrf; $status=(string)($report['status']??'warning'); $counts=$report['counts']??[]; ?>
<style>
.hm{max-width:1440px;margin:auto}.hm-hero{padding:24px;border-radius:20px;background:linear-gradient(135deg,#13233a,#284866);color:#fff;display:flex;justify-content:space-between;gap:20px;align-items:center}.hm-score{font-size:44px;font-weight:800}.hm-actions{display:flex;gap:8px;flex-wrap:wrap}.hm-btn{border:0;border-radius:10px;padding:10px 14px;cursor:pointer;background:#fff;color:#17324d}.hm-kpis,.hm-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(230px,1fr));gap:14px;margin-top:18px}.hm-kpi,.hm-card,.hm-panel{background:#fff;border:1px solid #dfe6ee;border-radius:16px;padding:17px;box-shadow:0 6px 20px rgba(20,40,65,.06)}.hm-kpi b{font-size:28px;display:block}.hm-card header{display:flex;justify-content:space-between;gap:10px}.hm-badge{padding:5px 10px;border-radius:999px;font-size:12px;font-weight:700}.hm-badge.ok{background:#dcfce7;color:#166534}.hm-badge.warning{background:#fef3c7;color:#92400e}.hm-badge.critical{background:#fee2e2;color:#991b1b}.hm-meta{display:flex;gap:14px;color:#64748b;font-size:13px}.hm-details{font-size:13px;color:#475569;margin-top:10px;overflow-wrap:anywhere}.hm-panel{margin-top:20px;overflow:auto}.hm-table{width:100%;border-collapse:collapse;min-width:760px}.hm-table th,.hm-table td{padding:10px;border-bottom:1px solid #edf1f5;text-align:left;font-size:13px}.hm-alert{border-left:4px solid #d97706}.hm-alert.critical{border-left-color:#dc2626}@media(max-width:700px){.hm-hero{align-items:flex-start;flex-direction:column}.hm-score{font-size:36px}}
</style>
<div class="hm">
<section class="hm-hero"><div><small>Administration · Système</small><h1>Health Monitor Enterprise</h1><p>Supervision consolidée, métriques techniques et intégrité des fichiers critiques.</p></div><div><div class="hm-score"><?= (int)($report['score']??0) ?> %</div><small>Contrôle : <?= htmlspecialchars((string)($report['checked_at']??'')) ?></small><div class="hm-actions" style="margin-top:12px"><form method="post" action="/public/administration/systeme/sante/analyser"><?= Csrf::field() ?><button class="hm-btn">Relancer l'analyse</button></form><?php if(!empty($report['alerts'])): ?><form method="post" action="/public/administration/systeme/sante/acquitter"><?= Csrf::field() ?><button class="hm-btn">Acquitter les alertes</button></form><?php endif ?><form method="post" action="/public/administration/systeme/sante/baseline" onsubmit="return confirm('Recalculer la baseline d’intégrité à partir de l’état actuel ?');"><?= Csrf::field() ?><button class="hm-btn">Créer la baseline</button></form></div></div></section>
<section class="hm-kpis"><article class="hm-kpi"><span>Composants conformes</span><b><?= (int)($counts['ok']??0) ?></b></article><article class="hm-kpi"><span>Vigilances</span><b><?= (int)($counts['warning']??0) ?></b></article><article class="hm-kpi"><span>Critiques</span><b><?= (int)($counts['critical']??0) ?></b></article><article class="hm-kpi"><span>Alertes actives</span><b><?= count($report['alerts']??[]) ?></b></article></section>
<?php if(!empty($report['alerts'])): ?><section class="hm-panel"><h2>Alertes actives</h2><div class="hm-grid"><?php foreach($report['alerts'] as $a): ?><article class="hm-card hm-alert <?= htmlspecialchars((string)$a['severity']) ?>"><header><strong><?= htmlspecialchars((string)$a['component']) ?></strong><span class="hm-badge <?= htmlspecialchars((string)$a['severity']) ?>"><?= htmlspecialchars((string)$a['severity']) ?></span></header><p><?= htmlspecialchars((string)$a['message']) ?></p><small><?= (int)$a['occurrences'] ?> occurrence(s) · dernière détection <?= htmlspecialchars((string)$a['last_seen_at']) ?></small></article><?php endforeach ?></div></section><?php endif ?>
<section class="hm-grid"><?php foreach(($report['components']??[]) as $item): ?><article class="hm-card"><header><strong><?= htmlspecialchars((string)$item['label']) ?></strong><span class="hm-badge <?= htmlspecialchars((string)$item['status']) ?>"><?= htmlspecialchars((string)$item['status_label']) ?></span></header><p><?= htmlspecialchars((string)$item['message']) ?></p><div class="hm-meta"><span>Score <?= (int)$item['score'] ?>/100</span><span><?= (int)$item['duration_ms'] ?> ms</span></div><?php if(!empty($item['details'])): ?><div class="hm-details"><?php foreach($item['details'] as $k=>$v): ?><div><b><?= htmlspecialchars((string)$k) ?> :</b> <?= htmlspecialchars(is_scalar($v)?(string)$v:'—') ?></div><?php endforeach ?></div><?php endif ?></article><?php endforeach ?></section>

<section class="hm-panel"><h2>Intégrité des fichiers critiques</h2><?php $integrity=$report['integrity']??[]; ?><div class="hm-kpis"><article class="hm-kpi"><span>Fichiers de référence</span><b><?= (int)($integrity['baseline_count']??0) ?></b></article><article class="hm-kpi"><span>Modifiés</span><b><?= (int)($integrity['changed']??0) ?></b></article><article class="hm-kpi"><span>Manquants</span><b><?= (int)($integrity['missing']??0) ?></b></article><article class="hm-kpi"><span>Ajoutés</span><b><?= (int)($integrity['added']??0) ?></b></article></div><?php foreach(['changed_files'=>'Fichiers modifiés','missing_files'=>'Fichiers manquants','added_files'=>'Fichiers ajoutés'] as $key=>$label): if(!empty($integrity[$key])): ?><h3><?= htmlspecialchars($label) ?></h3><div class="hm-details"><?php foreach($integrity[$key] as $file): ?><div><?= htmlspecialchars((string)$file) ?></div><?php endforeach ?></div><?php endif; endforeach ?></section>
<section class="hm-panel"><h2>Métriques techniques — 24 heures</h2><table class="hm-table"><thead><tr><th>Métrique</th><th>Moyenne</th><th>Maximum</th><th>Unité</th><th>Échantillons</th></tr></thead><tbody><?php foreach(($report['metrics']??[]) as $row): ?><tr><td><?= htmlspecialchars((string)$row['metric_key']) ?></td><td><?= htmlspecialchars((string)$row['average_value']) ?></td><td><?= htmlspecialchars((string)$row['maximum_value']) ?></td><td><?= htmlspecialchars((string)$row['metric_unit']) ?></td><td><?= (int)$row['samples'] ?></td></tr><?php endforeach ?></tbody></table></section>
<section class="hm-panel"><h2>Tendance sur 7 jours</h2><table class="hm-table"><thead><tr><th>Jour</th><th>Score moyen</th><th>Vigilances</th><th>Critiques</th></tr></thead><tbody><?php foreach(($report['trends']??[]) as $row): ?><tr><td><?= htmlspecialchars((string)$row['day']) ?></td><td><?= htmlspecialchars((string)$row['average_score']) ?></td><td><?= (int)$row['warning_count'] ?></td><td><?= (int)$row['critical_count'] ?></td></tr><?php endforeach ?></tbody></table></section>
<section class="hm-panel"><h2>Historique récent</h2><table class="hm-table"><thead><tr><th>Date</th><th>Composant</th><th>État</th><th>Score</th><th>Durée</th><th>Message</th></tr></thead><tbody><?php foreach(($report['history']??[]) as $row): ?><tr><td><?= htmlspecialchars((string)$row['created_at']) ?></td><td><?= htmlspecialchars((string)$row['component']) ?></td><td><?= htmlspecialchars((string)$row['status']) ?></td><td><?= (int)$row['score'] ?></td><td><?= (int)$row['duration_ms'] ?> ms</td><td><?= htmlspecialchars((string)$row['message']) ?></td></tr><?php endforeach ?></tbody></table></section>
</div>
