/* Sentinelle — page Statistiques : graphiques en HTML/CSS rendus côté serveur (views/stats.php).
   Chargé avant glass.css. Marques fines (barres ≤ 24px, bout arrondi 4px côté donnée, carré côté ligne de base),
   écart de 2px entre segments empilés, grille en filets discrets. Couleurs d'état : --c (Severity::COLOR). */

/* ---- sélecteur de période ---- */
.period {
    display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: var(--r);
    background: var(--surface); box-shadow: var(--shadow-sm);
}
.period a { padding: 5px 12px; border-radius: var(--r-sm); color: var(--text-2); font-size: .85rem; font-weight: 500; white-space: nowrap; }
.period a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.period a[aria-current] { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-text); font-weight: 600; }

/* ---- chiffres clés ---- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3); margin: 0 0 var(--s4); }
.kpis .card + .card { margin-top: 0; }
.kpi { display: flex; flex-direction: column; padding: var(--s4) var(--s5) 0; overflow: hidden; }
.kpi p { margin: 0; }
.kpi-label { font-size: .8rem; font-weight: 500; color: var(--text-2); }
.kpi-value { margin-top: var(--s1) !important; font-size: 2rem; font-weight: 700; line-height: 1.15; letter-spacing: -.03em; }
.kpi-sub { font-size: .8rem; color: var(--text-3); }
.kpi .delta { margin: var(--s2) 0 var(--s3); }
.kpi .spark { display: block; width: calc(100% + 2 * var(--s5)); height: 38px; margin: auto calc(-1 * var(--s5)) 0; color: var(--accent); }

.delta { font-size: .78rem; color: var(--text-3); white-space: nowrap; }
.delta b { font-weight: 700; color: var(--text-2); font-variant-numeric: tabular-nums; }
.delta.good b { color: var(--success); }
.delta.bad b { color: var(--danger); }

.spark { color: var(--text-3); overflow: visible; }
.spark polyline { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark polygon { fill: currentColor; opacity: .1; }

/* ---- cartes de graphique ---- */
.card.viz { margin: 0 0 var(--s4); }
.viz-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: var(--s3) var(--s5); margin-bottom: var(--s4); }
.viz-head h2 { margin: 0; font-size: .98rem; }
.viz-head p { margin: 2px 0 0; }
.viz-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); margin: 0 0 var(--s4); }
.viz-grid > .card.viz { margin: 0; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); margin: 2px 0 0; padding: 0; font-size: .78rem; color: var(--text-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

/* ---- colonnes (état du parc, apparus / corrigés) ---- */
.vchart { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0 var(--s2); }
.vy { position: relative; height: var(--h); min-width: 1.6rem; font-size: .7rem; color: var(--text-3); font-variant-numeric: tabular-nums; }
.vy span { position: absolute; right: 0; transform: translateY(50%); line-height: 1; }
.vplot { position: relative; height: var(--h); border-bottom: 1px solid var(--border-strong); }
.gl { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--border); }
.gl.base { border-top-color: var(--border-strong); }
.vcols, .vx { display: flex; justify-content: space-around; gap: 2px; }
.vcols { position: absolute; inset: 0; }
.vcol, .vx span { flex: 1 1 0; min-width: 0; max-width: 24px; }
.vcol { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; border-radius: 4px 4px 0 0; outline: none; }
.vcol i { display: block; flex: none; background: var(--c); background-clip: padding-box; }
.vcol i + i { border-top: 2px solid transparent; }
.vcol i:first-child { border-radius: 4px 4px 0 0; }
.vcol:hover, .vcol:focus-visible { background: color-mix(in srgb, var(--text) 7%, transparent); }
.vcol:focus-visible { box-shadow: var(--focus); }
.vx { height: 1.5rem; font-size: .7rem; color: var(--text-3); }
.vx span { position: relative; }
.vx em { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font-style: normal; white-space: nowrap; font-variant-numeric: tabular-nums; }

.flow .vplot { border-bottom: 0; }
.flow .vcol { justify-content: stretch; border-radius: 4px; }
.flow .up, .flow .down { flex: 1 1 0; display: flex; flex-direction: column; min-height: 0; }
.flow .up { justify-content: flex-end; padding-bottom: 1px; }
.flow .down { justify-content: flex-start; padding-top: 1px; }
.flow .vcol .down i { border-radius: 0 0 4px 4px; }
.flow-sum { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s5); margin: 0 0 var(--s4); font-size: .86rem; color: var(--text-2); }
.flow-sum b { margin-right: 2px; font-size: 1.15rem; font-weight: 700; color: var(--text); }
.flow-sum .delta { font-size: .86rem; white-space: normal; }

/* ---- barres horizontales (menaces, problèmes, serveurs, sites) ---- */
.hgroup { margin: var(--s5) 0 var(--s1); font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.viz-head + .hgroup { margin-top: 0; }
.hbars { list-style: none; display: grid; gap: 2px; margin: 0; padding: 0; }
.hbar {
    display: grid; grid-template-columns: minmax(9rem, 15rem) minmax(4rem, 1fr) 5.5rem; align-items: center; gap: var(--s2) var(--s4);
    margin: 0 calc(-1 * var(--s2)); padding: 7px var(--s2); border-radius: var(--r); font-size: .86rem; outline: none;
}
.hbar[data-tip]:hover, .hbar[data-tip]:focus-visible { background: var(--surface-3); }
.hbar:focus-visible { box-shadow: var(--focus); }
.hbar-label { min-width: 0; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.hbar-label a { color: var(--text); font-weight: 600; }
.hbar-label a:hover { color: var(--accent-text); }
.hbar-track { display: block; height: 12px; overflow: hidden; border-radius: 0 4px 4px 0; background: var(--surface-3); }
.hbar-track > i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }
.hbar-val { text-align: right; white-space: nowrap; color: var(--text-2); font-variant-numeric: tabular-nums; }
.hbar-val b { font-weight: 700; color: var(--text); }
.hbar-val .muted { font-size: .78rem; }

.threats .hbar { grid-template-columns: minmax(9rem, 15rem) minmax(4rem, 1fr) 5.5rem 10.5rem 5rem; }
.threats .spark { width: 100%; height: 24px; }
.codes .hbar { grid-template-columns: minmax(9rem, 1.4fr) minmax(4rem, 1fr) 5rem 5.5rem; }
.hbar-track.stack { display: flex; width: var(--w); background: none; }
.stack > i { flex: 1 1 0; min-width: 0; height: 100%; border-radius: 0; background: var(--c); background-clip: padding-box; }
.stack > i + i { border-left: 2px solid transparent; }
.worst .hbar { grid-template-columns: minmax(8rem, 1.2fr) minmax(4rem, 1fr) 5rem 5.5rem; }
.codes .badge, .worst .badge { justify-self: start; font-size: .7rem; }

/* ---- données brutes + infobulle ---- */
.card.viz-data { margin: 0 0 var(--s3); padding: var(--s4) var(--s5); }
.viz-data[open] > summary { margin-bottom: var(--s3); }
.viz-data .table-wrap { max-height: 28rem; overflow: auto; }
.viz-data thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-solid, var(--surface)); }
.viz-data td { padding: 7px 14px; font-size: .84rem; }
.viz-data .num { text-align: right; font-variant-numeric: tabular-nums; }
.viz-note { max-width: 90ch; margin: var(--s3) 0 0; }

.viz-tip {
    position: fixed; z-index: 60; min-width: 9rem; max-width: 19rem; padding: var(--s2) var(--s3); pointer-events: none;
    background: var(--surface-solid, var(--surface)); border: 1px solid var(--border-strong); border-radius: var(--r);
    box-shadow: var(--shadow-lg); font-size: .8rem; color: var(--text-2);
}
.viz-tip p { display: flex; align-items: center; gap: 7px; margin: 0; line-height: 1.55; }
.viz-tip .viz-tip-t { display: block; margin-bottom: 3px; font-weight: 600; color: var(--text); }
.viz-tip i { flex: none; width: 12px; height: 3px; border-radius: 2px; }
.viz-tip i.none { display: none; }
.viz-tip b { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.viz-tip .viz-tip-n { display: block; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); font-size: .76rem; color: var(--text-3); }

/* ---- responsive ---- */
@media (max-width: 1100px) {
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .viz-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
    .kpi { padding: var(--s3) var(--s4) 0; }
    .kpi-value { font-size: 1.6rem; }
    .kpi .spark { width: calc(100% + 2 * var(--s4)); margin: auto calc(-1 * var(--s4)) 0; }
    .kpi .delta { white-space: normal; }
    .hbar, .threats .hbar, .codes .hbar, .worst .hbar { grid-template-columns: minmax(0, 1fr) 5.5rem; gap: 4px var(--s3); }
    .hbar-label { grid-column: 1 / -1; }
    .codes .hbar-label, .worst .hbar-label { grid-column: auto; }
    .codes .badge, .worst .badge { grid-area: 1 / 2; justify-self: end; }
    .vx em { font-size: .66rem; }
}
