:root {
    --fond: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --bordure: #e2e5ea;
    --texte: #1d2330;
    --texte-2: #5b6474;
    --accent: #2457c5;
    --ok: #1f8a4c;
    --ok-fond: #e5f4ec;
    --alerte: #b26a00;
    --alerte-fond: #fff2dc;
    --critique: #c62828;
    --critique-fond: #fde8e8;
    --majeure: #d84315;
    --majeure-fond: #fbe9e3;
    --hors-ligne: #6b4bb8;
    --hors-ligne-fond: #efe9fb;
    --inactif: #7a8291;
    --inactif-fond: #eef0f3;
    --ombre: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --rayon: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --fond: #11141a;
        --surface: #1a1e26;
        --surface-2: #20252f;
        --bordure: #2d3340;
        --texte: #e6e9ef;
        --texte-2: #9aa3b2;
        --accent: #7aa2ff;
        --ok: #4cc782;
        --ok-fond: #15301f;
        --alerte: #f0a63a;
        --alerte-fond: #33260f;
        --critique: #ff6b6b;
        --critique-fond: #3a1717;
        --majeure: #ff8a50;
        --majeure-fond: #3a2017;
        --hors-ligne: #b39dfa;
        --hors-ligne-fond: #2a2240;
        --inactif: #8a93a3;
        --inactif-fond: #252a33;
        --ombre: none;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --fond: #11141a;
    --surface: #1a1e26;
    --surface-2: #20252f;
    --bordure: #2d3340;
    --texte: #e6e9ef;
    --texte-2: #9aa3b2;
    --accent: #7aa2ff;
    --ok: #4cc782;
    --ok-fond: #15301f;
    --alerte: #f0a63a;
    --alerte-fond: #33260f;
    --critique: #ff6b6b;
    --critique-fond: #3a1717;
    --majeure: #ff8a50;
    --majeure-fond: #3a2017;
    --hors-ligne: #b39dfa;
    --hors-ligne-fond: #2a2240;
    --inactif: #8a93a3;
    --inactif-fond: #252a33;
    --ombre: none;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--fond);
    color: var(--texte);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--texte-2); text-transform: uppercase; letter-spacing: .04em; }

.discret { color: var(--texte-2); }
.erreur { color: var(--critique); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.carte-info { margin-top: 12px; padding: 12px; border: 1px solid var(--bord, #ccd); border-radius: 8px; }
.carte-info .mono { word-break: break-all; user-select: all; }

/* Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.connexion-carte { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.connexion-carte label { display: grid; gap: 4px; font-weight: 600; }

input, select, textarea {
    font: inherit;
    color: var(--texte);
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: 8px;
    padding: 8px 10px;
    min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.bouton {
    font: inherit;
    border: 1px solid var(--bordure);
    background: var(--surface);
    color: var(--texte);
    border-radius: 8px;
    padding: 7px 12px;
    cursor: pointer;
}
.bouton:hover { border-color: var(--accent); }
.bouton.principal { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.bouton.danger { color: var(--critique); border-color: var(--critique); }
.bouton:disabled { opacity: .5; cursor: default; }
.discret-bouton { border-color: transparent; background: transparent; color: var(--texte-2); }

/* Structure */
.entete {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--bordure);
}
.marque { font-weight: 700; color: var(--texte); font-size: 16px; }
.onglets { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; min-width: 0; }
.onglets a { padding: 6px 12px; border-radius: 8px; color: var(--texte-2); font-weight: 600; }
.onglets a.actif { background: var(--surface-2); color: var(--texte); }
.onglets a:hover { text-decoration: none; color: var(--texte); }
.utilisateur { display: flex; align-items: center; gap: 12px; }
.bouton-menu { display: none; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0;
    font-size: 22px; line-height: 1; border: 1px solid var(--bordure); border-radius: 8px; background: var(--surface); color: var(--texte); cursor: pointer; }
.voile-menu[hidden] { display: none; }

.vue { padding: 20px; max-width: 1500px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }

.carte {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--rayon);
    box-shadow: var(--ombre);
    padding: 16px;
    min-width: 0;
}

.grille { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.ligne { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.espace { flex: 1; }

/* Totaux */
.totaux { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.total {
    background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon);
    padding: 14px 16px; cursor: pointer; text-align: left; font: inherit; color: inherit; box-shadow: var(--ombre);
}
.total strong { display: block; font-size: 28px; line-height: 1.1; }
.total.selectionne { outline: 2px solid var(--accent); }
.total.critique strong { color: var(--critique); }
.total.hors_ligne strong { color: var(--hors-ligne); }
.total.alerte strong { color: var(--alerte); }
.total.ok strong { color: var(--ok); }
.total.inactif strong { color: var(--inactif); }

/* Pastilles d'état */
.etat {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.etat::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.etat.ok { color: var(--ok); background: var(--ok-fond); }
.etat.alerte, .etat.avertissement { color: var(--alerte); background: var(--alerte-fond); }
.etat.critique, .etat.erreur { color: var(--critique); background: var(--critique-fond); }
.etat.hors_ligne { color: var(--hors-ligne); background: var(--hors-ligne-fond); }
.etat.inactif, .etat.info { color: var(--inactif); background: var(--inactif-fond); }

.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 700; background: var(--surface-2); border: 1px solid var(--bordure); }
.badge.alerte { color: var(--alerte); border-color: var(--alerte); }
.badge.critique { color: var(--critique); border-color: var(--critique); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.info { color: var(--accent, #2457c5); border-color: var(--accent, #2457c5); }

/* Filtres des alertes (puces cliquables avec compteur) */
.puces { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.puce { border: 1px solid var(--bordure); background: var(--surface); color: var(--texte-2); border-radius: 999px; padding: 3px 10px;
    font: inherit; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.puce.actif { background: var(--accent, #2457c5); border-color: var(--accent, #2457c5); color: #fff; }
.puce-compte { font-size: 11px; font-weight: 700; background: rgba(127, 127, 127, .2); border-radius: 999px; padding: 0 6px; }
.message-alerte { white-space: pre-line; max-height: 7.5em; overflow: auto; }
tr.inactive td { opacity: .55; }

/* Formulaire des zones réseau */
.formulaire-zone { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--bordure); display: grid; gap: 8px; }
.formulaire-zone h4 { margin: 0; font-size: 14px; }
details > summary { cursor: pointer; font-weight: 600; }
label.case { display: inline-flex; align-items: center; gap: 4px; margin-right: 10px; white-space: nowrap; font-size: 13px; }
.barre-volume { height: 10px; min-width: 80px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.barre-volume span { display: block; height: 100%; background: var(--accent, #2457c5); }
tr.ligne-critique td { background: color-mix(in srgb, var(--critique) 10%, transparent); }
details textarea { width: 100%; box-sizing: border-box; margin: 8px 0; font-size: 12px; }
.formulaire-zone input[type=text] { min-width: 180px; flex: 1 1 180px; }
.formulaire-zone input[type=number] { width: 220px; max-width: 100%; }

/* Cartographie réseau (SVG) */
.carte-svg { display: block; width: 100%; height: 70vh; min-height: 420px; margin-top: 8px; background: var(--surface-2);
    border: 1px solid var(--bordure); border-radius: 8px; cursor: grab; touch-action: none; user-select: none; }
.carte-svg:active { cursor: grabbing; }
.carte-svg .anneau { fill: none; stroke: var(--bordure); stroke-dasharray: 4 6; }
.carte-svg .flux { fill: none; stroke: var(--texte-2); opacity: .75; }
.carte-svg .flux-internet { stroke: #7b1fa2; }
.carte-svg .flux-rupture { stroke: #c62828; opacity: 1; }
.carte-svg .flux:hover { opacity: 1; }
.carte-svg .fleche { fill: var(--texte-2); }
.carte-svg .noeud { cursor: pointer; }
.carte-svg .noeud:focus { outline: none; }
.carte-svg .noeud:focus .disque, .carte-svg .noeud:hover .disque { stroke: var(--texte); stroke-width: 3; }
.carte-svg .disque { stroke: var(--surface); stroke-width: 2; }
.carte-svg .noeud-rupture .disque { stroke: #c62828; stroke-width: 4; }
.carte-svg .compte { fill: #fff; font-size: 12px; font-weight: 700; pointer-events: none; }
.carte-svg .etiquette { fill: var(--texte); font-size: 12px; pointer-events: none; }
.carte-svg .etiquette-groupe { fill: var(--texte-2); font-size: 14px; font-weight: 700; }
.carte-svg .alerte-noeud { fill: #d98a00; stroke: var(--surface); stroke-width: 2; }
.carte-svg .alerte-noeud.suspect { fill: #c62828; }
.legende-carte { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0; font-size: 12px; color: var(--texte-2); }
.legende-carte .pastille { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.legende-carte .trait-rouge { display: inline-block; width: 18px; height: 3px; background: #c62828; vertical-align: middle; }
.carte-reseau-detail h4 { margin: 12px 0 4px; }
@media (max-width: 700px) { .carte-svg { height: 60vh; min-height: 320px; } }

/* Tableaux */
.table-defilement { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--bordure); vertical-align: top; }
th { font-size: 12px; color: var(--texte-2); font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tr.cliquable { cursor: pointer; }
tr.cliquable:hover td { background: var(--surface-2); }
td.nombre, th.nombre { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.raisons { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.raisons li { font-size: 12px; }
.raisons li.critique { color: var(--critique); }
.raisons li.alerte { color: var(--alerte); }

/* Jauges */
.jauge { height: 8px; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--bordure); overflow: hidden; }
.jauge > span { display: block; height: 100%; background: var(--ok); }
.jauge.alerte > span { background: var(--alerte); }
.jauge.critique > span { background: var(--critique); }
.disque { display: grid; gap: 4px; margin-bottom: 12px; }

/* Définitions */
.definitions { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.definitions dt { color: var(--texte-2); }
.definitions dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Courbes */
.courbe { width: 100%; height: 70px; display: block; }
.courbe polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.courbe .zone { fill: var(--accent); opacity: .08; stroke: none; }
.courbe-legende { display: flex; justify-content: space-between; font-size: 12px; color: var(--texte-2); margin-bottom: 2px; }

/* Événements */
.evenement-details { background: var(--surface-2); }
.evenement-details pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 8px; font-size: 12px; }
.filtres { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.vide { color: var(--texte-2); padding: 12px 0; }

.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--bordure); }
.chip.en-retard { border-color: var(--alerte); color: var(--alerte); }
/* Serveur Linux : comptes d'UID 0 supplémentaires, bases ouvertes sur le réseau */
.chip.critique { border-color: var(--critique); color: var(--critique); background: var(--critique-fond); }
.chip.alerte { border-color: var(--alerte); color: var(--alerte); background: var(--alerte-fond); }

.compteur {
    display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 999px;
    background: var(--critique); color: #fff; font-size: 11px; line-height: 18px; text-align: center;
}
.onglets { overflow: visible; }
.onglets a { white-space: nowrap; }
.periodes { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--bordure); border-radius: 8px; padding: 2px; }
.periodes button { font: inherit; font-size: 12px; border: 0; background: transparent; color: var(--texte-2); padding: 3px 10px; border-radius: 6px; cursor: pointer; }
.periodes button.actif { background: var(--surface); color: var(--texte); font-weight: 700; box-shadow: var(--ombre); }
.courbe.serie-2 polyline { stroke: var(--alerte); }
.courbe.serie-2 .zone { fill: var(--alerte); }
.cve-liste { margin: 6px 0 0; padding-left: 18px; font-size: 12px; }
.cve-liste li { margin: 2px 0; }
.direction-externe { color: var(--alerte); font-weight: 600; }
.statistiques { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.statistique { background: var(--surface-2); border: 1px solid var(--bordure); border-radius: 8px; padding: 10px 12px; }
.statistique strong { display: block; font-size: 20px; }

.score-valeur { font-size: 24px; }
.marque { display: inline-flex; align-items: center; gap: 8px; }
.logo { height: 28px; width: auto; max-width: 140px; }
.logo-connexion { height: 48px; max-width: 220px; justify-self: start; }
.etat.majeure { color: var(--majeure); background: var(--majeure-fond); }
.statistique { color: inherit; text-decoration: none; }
a.statistique:hover { border-color: var(--accent); text-decoration: none; }
.statistique.niveau-critique strong { color: var(--critique); }
.statistique.niveau-majeure strong { color: var(--majeure); }
.statistique.niveau-alerte strong { color: var(--alerte); }
.statistique.niveau-info strong { color: var(--inactif); }
td .etat { margin-left: 6px; }
.formulaire dd input[type=text], .formulaire dd textarea, .formulaire dd select { width: 100%; max-width: 760px; }
textarea { font: inherit; color: var(--texte); background: var(--surface); border: 1px solid var(--bordure); border-radius: 8px; padding: 8px 10px; }
.filtres textarea { flex: 1; min-width: 240px; }
textarea.brouillon { width: 100%; margin: 8px 0; font-size: 12px; }
.texte-long { white-space: pre-wrap; overflow-wrap: anywhere; }
a.bouton { display: inline-block; text-decoration: none; }
.qr-cadre { width: 220px; max-width: 100%; padding: 8px; background: #fff; border-radius: 8px; border: 1px solid var(--bordure); }
.qr { display: block; width: 100%; height: auto; shape-rendering: crispEdges; }
#utilisateur-nom { color: var(--texte); font-weight: 600; }

.message-flottant {
    position: fixed; bottom: 16px; right: 16px; z-index: 10;
    background: var(--texte); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--ombre);
}

@media (max-width: 700px) {
    html, body { font-size: 14px; overflow-x: hidden; }
    /* En-tête : marque et compte sur une ligne, onglets défilants dessous */
    .entete { gap: 6px 8px; padding: 8px 12px; }
    .marque { font-size: 15px; white-space: nowrap; flex: 1 1 auto; min-width: 0; }
    .utilisateur { gap: 4px; font-size: 13px; margin-left: auto; }
    .utilisateur #actualisation { display: none; }
    .utilisateur #utilisateur-nom { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
    .utilisateur .bouton { padding: 4px 6px; font-size: 12px; }
    /* Menu latéral : bouton ☰, panneau qui glisse depuis la gauche */
    .bouton-menu { display: inline-flex; }
    .onglets {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 50; width: min(78vw, 280px);
        flex-direction: column; gap: 2px; padding: 16px 10px; overflow-y: auto;
        background: var(--surface); box-shadow: var(--ombre);
        transform: translateX(-105%); transition: transform .2s ease; visibility: hidden;
    }
    body.menu-ouvert .onglets { transform: none; visibility: visible; }
    .onglets a { padding: 12px 14px; font-size: 16px; border-radius: 8px; display: flex; align-items: center; justify-content: space-between; }
    .onglets a.actif { background: var(--surface-2); color: var(--texte); box-shadow: inset 3px 0 0 var(--accent, #2457c5); }
    .voile-menu { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4); }
    body.menu-ouvert { overflow: hidden; }

    .vue { padding: 10px; gap: 10px; }
    .carte { padding: 12px; border-radius: 8px; }
    h1 { font-size: 18px; }
    h3 { font-size: 12px; }
    .grille { grid-template-columns: 1fr; gap: 10px; }

    /* Compteurs sur deux colonnes, compacts */
    .totaux, .statistiques { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .total, .statistique { padding: 8px 10px; }
    .total strong, .statistique strong { font-size: 20px; }
    .statistique .discret { font-size: 11px; }

    /* Tableaux : une carte par ligne, libellé de colonne à gauche */
    .table-defilement { overflow-x: visible; }
    table.reactif, table.reactif tbody, table.reactif tr, table.reactif td { display: block; width: 100%; }
    table.reactif thead { display: none; }
    table.reactif tr { border: 1px solid var(--bordure); border-radius: 8px; margin-bottom: 8px; padding: 6px 10px; background: var(--surface); }
    table.reactif tr[hidden] { display: none; }
    /* Libellé à gauche, valeur à droite : cartes deux fois moins hautes */
    table.reactif td { border: 0; padding: 3px 0; text-align: left; overflow-wrap: anywhere;
        display: grid; grid-template-columns: 34% minmax(0, 1fr); column-gap: 8px; align-items: baseline; }
    table.reactif td > * { grid-column: 2; justify-self: start; max-width: 100%; }
    table.reactif td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 9; color: var(--texte-2); font-size: 11px;
        font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 400;
        text-transform: uppercase; letter-spacing: .03em; }
    table.reactif td[data-label=""] { display: block; }
    table.reactif td[data-label=""]::before { content: none; }
    /* Titre de l'alerte et textes longs : pleine largeur sous le libellé */
    table.reactif td.large { display: block; }
    table.reactif td.large::before { display: block; margin-bottom: 2px; }
    table.reactif td:empty { display: none; }
    table.reactif td.nombre { text-align: left; }
    tr.cliquable:hover td { background: transparent; }

    .vue, .carte { min-width: 0; overflow-wrap: anywhere; }
    .filtres { gap: 6px; }
    .filtres > * { max-width: 100%; }
    .filtres input[type=search], .filtres input[type=text], .filtres select, .filtres textarea { flex: 1 1 100%; width: 100%; }
    select { max-width: 100%; }
    .formulaire { grid-template-columns: 1fr; }
    .formulaire-zone input[type=number] { width: 100%; }
    .formulaire dt { margin-top: 6px; }
}
