<?php require BASE_PATH . '/app/Views/layout/header.php'; ?>
<?php
$h = static fn(mixed $value): string => htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
$bytes = static function (int $value): string {
    if ($value <= 0) return '—';
    $units = ['o','Ko','Mo','Go','To']; $i = 0; $number = (float)$value;
    while ($number >= 1024 && $i < count($units)-1) { $number /= 1024; $i++; }
    return number_format($number, $i === 0 ? 0 : 1, ',', ' ') . ' ' . $units[$i];
};
?>
<style>
.axiom-console{max-width:1500px;margin:0 auto;padding:24px}.axiom-console *{box-sizing:border-box}.hero{display:flex;justify-content:space-between;align-items:center;gap:24px;padding:28px;border-radius:24px;background:linear-gradient(135deg,#0f172a,#1d4ed8);color:#fff;margin-bottom:20px}.hero h1{margin:4px 0 8px;font-size:clamp(1.6rem,3vw,2.55rem)}.kicker{font-size:.76rem;letter-spacing:.14em;font-weight:800;opacity:.8}.version{padding:14px 18px;border:1px solid rgba(255,255,255,.25);border-radius:16px;background:rgba(255,255,255,.1);white-space:nowrap}.back{display:inline-flex;margin-bottom:16px;text-decoration:none;font-weight:800;color:#1d4ed8}.nav{display:flex;gap:10px;overflow:auto;padding:2px 0 16px}.nav a{white-space:nowrap;padding:9px 13px;border-radius:999px;background:#eff6ff;color:#1d4ed8;text-decoration:none;font-weight:750}.grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px}.panel{background:#fff;border:1px solid #e5e7eb;border-radius:18px;padding:20px;box-shadow:0 8px 28px rgba(15,23,42,.06);margin-bottom:18px}.panel h2{margin:0 0 16px;font-size:1.15rem}.metrics{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px}.metric{padding:14px;border-radius:14px;background:#f8fafc;min-width:0}.metric span{display:block;color:#64748b;font-size:.8rem}.metric strong{display:block;font-size:1.2rem;overflow:hidden;text-overflow:ellipsis}.check{display:flex;gap:12px;align-items:flex-start;padding:12px 0;border-bottom:1px solid #eef2f7}.check:last-child{border-bottom:0}.dot{width:12px;height:12px;border-radius:50%;margin-top:5px;background:#f59e0b;flex:0 0 auto}.dot.ok{background:#16a34a}.check strong{display:block}.check small,.muted{color:#64748b}.table-wrap{overflow:auto}table{width:100%;border-collapse:collapse;min-width:620px}th,td{text-align:left;padding:10px;border-bottom:1px solid #e5e7eb;font-size:.9rem}th{background:#f8fafc}.badge{display:inline-flex;padding:4px 9px;border-radius:999px;font-size:.76rem;font-weight:800;background:#fef3c7;color:#92400e}.badge.ok{background:#dcfce7;color:#166534}.badge.bad{background:#fee2e2;color:#991b1b}.extensions{display:flex;flex-wrap:wrap;gap:8px;margin-top:14px}.hash{font-family:monospace;font-size:.74rem;max-width:230px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.empty{padding:18px;text-align:center;color:#64748b;background:#f8fafc;border-radius:12px}.section-status{float:right}.issues{margin:0;padding-left:20px}.issues li{margin:6px 0;color:#92400e}@media(max-width:850px){.axiom-console{padding:14px}.hero{align-items:flex-start;flex-direction:column}.grid{grid-template-columns:1fr}.metrics{grid-template-columns:1fr}table{min-width:560px}}
</style>
<main class="axiom-console">
<a class="back" href="/public/administration/axiom">← Retour à AXIOM Studio</a>
<section class="hero"><div><span class="kicker">AXIOM PLATFORM · CORE 9.3.4</span><h1>Console administrateur</h1><p>Santé, environnement, sauvegardes, audit, intégrité et cohérence réunis sur une seule page.</p></div><div class="version">Application <strong><?= $h($appVersion) ?></strong><br>Core <strong><?= $h($coreVersion) ?></strong></div></section>
<nav class="nav"><a href="#sante">Santé</a><a href="#environnement">Environnement</a><a href="#sauvegardes">Sauvegardes</a><a href="#audit">Audit</a><a href="#coherence">Cohérence</a><a href="#integrite">Intégrité</a><a href="#modules">Modules</a></nav>

<div class="grid" id="sante">
<section class="panel"><h2>Contrôles principaux</h2><?php foreach ($checks as $name=>$check): ?><div class="check"><span class="dot <?= ($check['status']??'')==='ok'?'ok':'' ?>"></span><div><strong><?= $h(ucfirst((string)$name)) ?></strong><small><?= $h($check['message']??'') ?></small></div></div><?php endforeach; ?></section>
<section class="panel"><h2>Base de données <span class="badge <?= ($databaseHealth['status']??'')==='ok'?'ok':'' ?> section-status"><?= ($databaseHealth['status']??'')==='ok'?'OK':'À vérifier' ?></span></h2><div class="metrics"><div class="metric"><span>Base</span><strong><?= $h($databaseHealth['database']?:'—') ?></strong></div><div class="metric"><span>Tables</span><strong><?= (int)$databaseHealth['tables'] ?></strong></div><div class="metric"><span>Serveur</span><strong><?= $h($databaseHealth['server_version']) ?></strong></div></div><p class="muted"><?= $h($databaseHealth['message']) ?></p><small><?= $h($databaseHealth['charset']) ?> · <?= $h($databaseHealth['collation']) ?></small></section>
</div>

<div class="grid" id="environnement">
<section class="panel"><h2>Environnement d’exécution <span class="badge <?= ($runtime['status']??'')==='ok'?'ok':'' ?> section-status"><?= ($runtime['status']??'')==='ok'?'Conforme':'Alerte' ?></span></h2><div class="metrics"><div class="metric"><span>PHP</span><strong><?= $h($runtime['php_version']) ?></strong></div><div class="metric"><span>Mémoire</span><strong><?= $h($runtime['memory_limit']) ?></strong></div><div class="metric"><span>Temps max.</span><strong><?= $h($runtime['max_execution_time']) ?> s</strong></div></div><div class="extensions"><?php foreach ($runtime['extensions'] as $extension=>$loaded): ?><span class="badge <?= $loaded?'ok':'bad' ?>"><?= $h($extension) ?></span><?php endforeach; ?></div><p class="muted"><?= $h($runtime['os']) ?> · <?= $h($runtime['sapi']) ?> · <?= $h($runtime['timezone']) ?></p></section>
<section class="panel"><h2>Capacité disque</h2><div class="metrics"><div class="metric"><span>Libre</span><strong><?= $bytes((int)$runtime['disk_free_bytes']) ?></strong></div><div class="metric"><span>Total</span><strong><?= $bytes((int)$runtime['disk_total_bytes']) ?></strong></div><div class="metric"><span>Disponible</span><strong><?= $runtime['disk_free_percent']===null?'—':$h($runtime['disk_free_percent']).' %' ?></strong></div></div><?php if (!empty($runtime['warnings'])): ?><ul class="issues"><?php foreach ($runtime['warnings'] as $warning): ?><li><?= $h($warning) ?></li><?php endforeach; ?></ul><?php else: ?><p class="muted">Aucune alerte environnementale.</p><?php endif; ?></section>
</div>

<div class="grid">
<section class="panel" id="sauvegardes"><h2>Sauvegardes <span class="badge <?= ($backups['status']??'')==='ok'?'ok':'' ?> section-status"><?= (int)$backups['count'] ?></span></h2><div class="metrics"><div class="metric"><span>Fichiers</span><strong><?= (int)$backups['count'] ?></strong></div><div class="metric"><span>Volume</span><strong><?= $bytes((int)$backups['total_bytes']) ?></strong></div><div class="metric"><span>État</span><strong><?= ($backups['status']??'')==='ok'?'Disponible':'Absente' ?></strong></div></div><?php if (!empty($backups['latest'])): ?><div class="table-wrap"><table><thead><tr><th>Fichier</th><th>Date</th><th>Taille</th></tr></thead><tbody><?php foreach ($backups['latest'] as $item): ?><tr><td title="<?= $h($item['path']) ?>"><?= $h($item['name']) ?></td><td><?= $h($item['modified_at']) ?></td><td><?= $bytes((int)$item['size']) ?></td></tr><?php endforeach; ?></tbody></table></div><?php else: ?><div class="empty">Aucune sauvegarde trouvée.</div><?php endif; ?></section>
<section class="panel" id="audit"><h2>Journal d’audit <span class="badge <?= ($audit['status']??'')==='ok'?'ok':'' ?> section-status"><?= ($audit['status']??'')==='ok'?'Actif':'À configurer' ?></span></h2><div class="metrics"><div class="metric"><span>Total</span><strong><?= (int)$audit['total'] ?></strong></div><div class="metric"><span>24 dernières heures</span><strong><?= (int)$audit['last_24h'] ?></strong></div><div class="metric"><span>Table</span><strong><?= $h($audit['table']?:'—') ?></strong></div></div><p class="muted"><?= $h($audit['message']) ?></p><?php if (!empty($audit['recent'])): ?><div class="table-wrap"><table><thead><tr><th>Date</th><th>Action</th><th>Module</th><th>Utilisateur</th></tr></thead><tbody><?php foreach ($audit['recent'] as $row): ?><tr><td><?= $h($row['date']) ?></td><td><?= $h($row['action']) ?></td><td><?= $h($row['module']) ?></td><td><?= $h($row['user']) ?></td></tr><?php endforeach; ?></tbody></table></div><?php endif; ?></section>
</div>

<section class="panel" id="coherence"><h2>Vérificateur de cohérence <span class="badge <?= ($consistency['status']??'')==='ok'?'ok':'' ?> section-status"><?= ($consistency['status']??'')==='ok'?'Conforme':'À examiner' ?></span></h2><p class="muted"><?= $h($consistency['message']) ?></p><div class="table-wrap"><table><thead><tr><th>Type</th><th>Élément</th><th>État</th><th>Détail</th></tr></thead><tbody><?php foreach ($consistency['checks'] as $row): ?><tr><td><?= $h($row['type']) ?></td><td><code><?= $h($row['name']) ?></code></td><td><span class="badge <?= ($row['status']??'')==='ok'?'ok':'' ?>"><?= ($row['status']??'')==='ok'?'OK':'Alerte' ?></span></td><td><?= $h($row['message']) ?></td></tr><?php endforeach; ?></tbody></table></div></section>

<section class="panel" id="integrite"><h2>Intégrité des fichiers critiques</h2><div class="metrics"><div class="metric"><span>Conformes</span><strong><?= (int)$integrity['summary']['ok'] ?></strong></div><div class="metric"><span>Modifiés</span><strong><?= (int)$integrity['summary']['modified'] ?></strong></div><div class="metric"><span>Manquants</span><strong><?= (int)$integrity['summary']['missing'] ?></strong></div></div><div class="table-wrap"><table><thead><tr><th>Fichier</th><th>État</th><th>Empreinte actuelle</th></tr></thead><tbody><?php foreach ($integrity['files'] as $file): ?><tr><td><code><?= $h($file['path']) ?></code></td><td><span class="badge <?= $file['status']==='ok'?'ok':($file['status']==='missing'?'bad':'') ?>"><?= $file['status']==='ok'?'Conforme':($file['status']==='missing'?'Manquant':'Modifié') ?></span></td><td class="hash" title="<?= $h($file['actual']) ?>"><?= $h($file['actual']?:'—') ?></td></tr><?php endforeach; ?></tbody></table></div></section>

<div class="grid" id="modules"><section class="panel"><h2>Modules détectés</h2><div class="table-wrap"><table><thead><tr><th>Code</th><th>Nom</th><th>Version</th><th>État</th></tr></thead><tbody><?php foreach ($modules as $module): ?><tr><td><code><?= $h($module['code']) ?></code></td><td><?= $h($module['name']) ?></td><td><?= $h($module['version']) ?></td><td><span class="badge <?= ($module['status']??'')==='ok'?'ok':'' ?>"><?= ($module['status']??'')==='ok'?'Conforme':'À vérifier' ?></span></td></tr><?php endforeach; ?></tbody></table></div></section><section class="panel"><h2>Migrations versionnées</h2><div class="table-wrap"><table><thead><tr><th>Version</th><th>Fichier</th><th>État</th></tr></thead><tbody><?php foreach ($migrations as $migration): ?><tr><td><code><?= $h($migration['version']) ?></code></td><td><?= $h($migration['file']) ?></td><td><span class="badge <?= !empty($migration['applied'])?'ok':'' ?>"><?= !empty($migration['applied'])?'Appliquée':'En attente' ?></span></td></tr><?php endforeach; ?></tbody></table></div></section></div>
</main>
<?php require BASE_PATH . '/app/Views/layout/footer.php'; ?>
