/* ============================================================================
   admin.css — LE POSTE D'OBSERVATION

   Monde : une salle de contrôle, pas le paravent. Personne ne joue depuis
   cette page — un seul lecteur, jamais à la table, qui compare des nombres.
   Densité et neutralité priment sur toute expression : c'est du Operate au
   sens strict. Le cramoisi reste l'unique accent d'interface (navigation
   active, bouton principal) ; les DONNÉES portent les teintes --serie-* de
   tokens.css, validées pour ça, et le texte ne prend jamais leur couleur.
   ========================================================================= */

:root {
    --chart-grid:  var(--rule);
    --chart-axis:  var(--text-dim);
    --nav-l: 228px;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--ink-950);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
input[type="number"], .tabular, table.data td.num, .kpi-sub { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

::selection { background: var(--crimson-fond); color: var(--text); }
* { scrollbar-width: thin; scrollbar-color: var(--ink-600) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--ink-600); border-radius: 99px; border: 3px solid transparent; background-clip: content-box; }
:where(a, button, input, select, [tabindex]):focus-visible { outline: 2px solid var(--crimson-clair); outline-offset: 2px; border-radius: var(--r-sm); }

code { font-family: var(--font-num); font-size: 0.8em; color: var(--text-mid); background: var(--ink-950); padding: 1px 5px; border-radius: var(--r-sm); }

/* ===== CONTRÔLES ===== */
.btn, button:where(:not(.gate-eye):not(.barlist-ligne):not(.segment button):not(th button)) {
    font-family: inherit; font-size: 0.82rem; font-weight: 600;
    padding: 8px 14px; border: 1px solid var(--ink-600);
    background: var(--ink-700); color: var(--text);
    border-radius: var(--r-md); cursor: pointer;
    transition: background .15s ease, border-color .15s ease;
}
.btn:hover, button:where(:not(.gate-eye):not(.barlist-ligne):not(.segment button):not(th button)):hover { background: var(--ink-600); border-color: var(--rule-strong); }
/* Le survol ASSOMBRIT un aplat : éclaircir ferait tomber le contraste du
   texte au moment précis où on vise (voir CLAUDE.md, --crimson-fond). */
.btn-primary { background: var(--crimson-fond); border-color: var(--crimson-fond); color: white; }
.btn-primary:hover { background: var(--crimson-fond-actif); border-color: var(--crimson-fond-actif); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--text-mid); }
.btn-quiet:hover { background: var(--ink-700); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--crimson-dim); color: var(--crimson-clair); }
.btn-danger:hover { background: var(--crimson-wash); border-color: var(--crimson); }
.btn-sm { padding: 4px 9px; font-size: 0.74rem; }
button:disabled { opacity: .45; cursor: not-allowed; }

select, input[type="text"], input[type="password"], input[type="search"] {
    font-family: inherit; font-size: 0.86rem;
    background: var(--ink-950); color: var(--text);
    border: 1px solid var(--ink-600); border-radius: var(--r-md);
    padding: 7px 10px;
}
input[type="text"], input[type="password"] { width: 100%; }
select:focus, input:focus { border-color: var(--crimson-clair); outline: none; }
input::placeholder { color: var(--text-dim); }
label { font-size: 0.78rem; color: var(--text-mid); }

/* Le contrôle à segments : période, palmarès. L'état est dans aria-pressed. */
.segment { display: inline-flex; gap: 2px; padding: 2px; background: var(--ink-950); border: 1px solid var(--rule); border-radius: var(--r-md); }
.segment button {
    font-family: inherit; font-size: 0.78rem; font-weight: 600;
    background: transparent; color: var(--text-mid); border: 0;
    padding: 5px 10px; border-radius: var(--r-sm); cursor: pointer;
}
.segment button:hover { color: var(--text); background: var(--ink-700); }
.segment button[aria-pressed="true"] { background: var(--ink-600); color: var(--text); }
.segment-sm { margin-bottom: var(--s3); }

/* ============================================================================
   LE SEUIL
   ========================================================================= */
#gate {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: var(--s5);
    background: radial-gradient(ellipse at 50% 30%, var(--ink-800), var(--ink-950) 70%);
}
.gate-card {
    width: 100%; max-width: 360px;
    background: var(--ink-900); border: 1px solid var(--rule-strong);
    border-radius: var(--r-lg); padding: var(--s6) var(--s5) var(--s5);
    box-shadow: var(--shadow-pop);
}
.gate-marque { color: var(--crimson-clair); margin-bottom: var(--s3); }
.gate-d20 { width: 34px; height: 34px; display: block; }
.gate-card h1 { margin: 0 0 4px 0; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.gate-sub { margin: 0 0 var(--s5) 0; font-size: 0.82rem; color: var(--text-mid); line-height: 1.5; }
.gate-field { margin-bottom: var(--s4); position: relative; }
.gate-field label { display: block; margin-bottom: 6px; }
.gate-field input { padding: 10px 12px; font-size: 0.95rem; }
.gate-field input[type="password"], .gate-field input#gate-password { padding-right: 40px; }
.gate-eye {
    position: absolute; right: 6px; bottom: 6px;
    width: 30px; height: 30px; display: grid; place-items: center;
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; border-radius: var(--r-sm);
}
.gate-eye svg { width: 18px; height: 18px; }
.gate-eye:hover, .gate-eye[aria-pressed="true"] { color: var(--text); }
.gate-submit { width: 100%; padding: 10px 14px; font-size: 0.9rem; }
.gate-error {
    background: var(--crimson-wash); border: 1px solid var(--crimson-dim);
    color: var(--crimson-clair); border-radius: var(--r-md);
    padding: 8px 11px; font-size: 0.82rem; margin-bottom: var(--s4);
    display: none;
}
.gate-error.show { display: block; }
.gate-foot { margin: var(--s5) 0 0; font-size: 0.75rem; color: var(--text-dim); line-height: 1.5; }

/* ============================================================================
   LE TABLEAU — navigation à gauche, filtres en haut, sections au centre
   ========================================================================= */
#dashboard { display: none; }
.adm { display: grid; grid-template-columns: var(--nav-l) minmax(0, 1fr); min-height: 100vh; }

.adm-nav {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: var(--s4);
    padding: var(--s5) var(--s3);
    background: var(--ink-900); border-right: 1px solid var(--crease);
}
.adm-nav-tete { padding: 0 var(--s3); display: flex; flex-direction: column; gap: 2px; }
.adm-nav-titre { font-size: 0.95rem; font-weight: 700; }
.adm-nav-sous { font-size: 0.76rem; color: var(--text-dim); }
.adm-nav nav { display: flex; flex-direction: column; gap: 2px; }
.adm-nav a {
    display: block; padding: 8px var(--s3); border-radius: var(--r-md);
    color: var(--text-mid); text-decoration: none; font-size: 0.86rem; font-weight: 600;
    border-left: 2px solid transparent;
}
.adm-nav a:hover { background: var(--ink-800); color: var(--text); }
.adm-nav a[aria-current="page"] { background: var(--ink-800); color: var(--text); border-left-color: var(--crimson); border-radius: 0 var(--r-md) var(--r-md) 0; }
.adm-quitter { margin-top: auto; text-align: left; }

.adm-corps { min-width: 0; display: flex; flex-direction: column; }
.adm-filtres {
    position: sticky; top: 0; z-index: 10;
    display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4);
    padding: var(--s3) var(--s5);
    background: var(--ink-950); border-bottom: 1px solid var(--rule);
}
.adm-filtres.inactif .filtre, .adm-filtres.inactif .filtre-etat { opacity: .35; pointer-events: none; }
.filtre { display: flex; align-items: center; gap: var(--s2); }
.filtre > span { font-size: 0.74rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.filtre select { min-width: 200px; max-width: 320px; }
.filtre-etat { font-size: 0.8rem; color: var(--text-mid); }
#btn-refresh { margin-left: auto; }

.adm-main {
    padding: var(--s5); max-width: 1440px; width: 100%;
    display: flex; flex-direction: column; gap: var(--s5);
    transition: opacity .2s ease;
}
/* Recharger garde le cadre, à opacité réduite : pas de squelette, pas de saut. */
.adm-main.recharge { opacity: .55; }
.adm-section { display: flex; flex-direction: column; gap: var(--s4); }
.adm-h { margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.01em; }
.retour { color: var(--text-mid); text-decoration: none; font-size: 0.82rem; }
.retour:hover { color: var(--text); }

/* ===== TUILES ===== */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s3); }
/* Huit tuiles en deux rangées de quatre, plutôt que cinq et trois. */
#kpi-vue { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { #kpi-vue { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi-tile {
    background: var(--ink-900); border: 1px solid var(--rule);
    border-radius: var(--r-lg); padding: var(--s4);
    display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.kpi-label { font-size: 0.76rem; color: var(--text-mid); font-weight: 600; }
.kpi-ligne { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s2); }
.kpi-value { font-size: 1.85rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; white-space: nowrap; }
.kpi-value .unit { font-size: 1rem; font-weight: 600; color: var(--text-mid); margin-left: 3px; }
.kpi-sub { font-size: 0.76rem; color: var(--text-dim); line-height: 1.4; }
.spark { flex: none; margin-bottom: 4px; }

/* ===== BLOCS ===== */
.blk {
    background: var(--ink-900); border: 1px solid var(--rule);
    border-radius: var(--r-lg); padding: var(--s4) var(--s4) var(--s5);
    min-width: 0;
}
.blk-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.blk-large { grid-column: 1 / -1; }
.blk h3 { margin: 0 0 var(--s3) 0; font-size: 0.9rem; font-weight: 700; color: var(--text); }
.blk-title { margin-top: var(--s5) !important; }
.blk-tete { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); margin-bottom: var(--s3); }
.blk-tete h3 { margin: 0; flex: 1; }
.blk-tete input[type="search"] { width: 220px; }
.hint { font-size: 0.78rem; color: var(--text-dim); margin: calc(-1 * var(--s2)) 0 var(--s3); line-height: 1.5; }
.blk-empty { font-size: 0.82rem; color: var(--text-dim); font-style: italic; padding: var(--s3) 0; margin: 0; }
.blk-error {
    font-size: 0.8rem; color: var(--crimson-clair); background: var(--crimson-wash);
    border: 1px solid var(--crimson-dim); border-radius: var(--r-md);
    padding: var(--s3); font-family: var(--font-num);
}

/* ===== GRAPHIQUES (SVG) ===== */
.chart-svg { display: block; overflow: visible; max-width: 100%; }
.chart-grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart-axis-label { fill: var(--chart-axis); font-size: 11px; font-family: var(--font); }
.chart-value-label { fill: var(--text-mid); font-size: 11px; font-family: var(--font); font-weight: 600; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { stroke: var(--ink-900); stroke-width: 2; pointer-events: none; }
.chart-crosshair { stroke: var(--text-dim); stroke-width: 1; pointer-events: none; }
.chart-reference { stroke: var(--text-mid); stroke-width: 1; }
.chart-hit { cursor: default; }
.heat-vide { fill: var(--ink-800); }
.heat-cell:hover, .heat-vide:hover { stroke: var(--text); stroke-width: 1; }

.chart-legende { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); margin-top: var(--s3); font-size: 0.78rem; color: var(--text-mid); }
.chart-legende span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legende .cle-carre { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-legende .cle-ligne { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

/* L'infobulle : la VALEUR d'abord, en fort ; le libellé ensuite, en retrait. */
.chart-tip {
    position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50;
    background: var(--ink-950); border: 1px solid var(--rule-strong);
    border-radius: var(--r-md); padding: 7px 10px; font-size: 0.78rem;
    box-shadow: var(--shadow-lift); max-width: 280px; opacity: 0;
    transition: opacity .08s ease;
}
.chart-tip.show { opacity: 1; }
.tip-titre { color: var(--text-mid); margin-bottom: 3px; font-size: 0.74rem; }
.tip-ligne { display: flex; align-items: center; gap: 6px; }
.tip-ligne i { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tip-ligne b { color: var(--text); font-variant-numeric: tabular-nums; }
.tip-ligne span { color: var(--text-mid); }

/* Barres classées : nom, piste, valeur. La barre porte la couleur, le texte
   reste en encre. Bout arrondi côté donnée, carré à la base. */
.barlist { display: flex; flex-direction: column; gap: 3px; }
.barlist-ligne {
    display: grid; grid-template-columns: minmax(90px, min(34%, 220px)) minmax(0, 1fr) 64px;
    align-items: center; gap: var(--s3); padding: 5px 6px; margin: 0 -6px;
    background: none; border: 0; color: inherit; font: inherit; text-align: left;
    border-radius: var(--r-sm);
}
button.barlist-ligne { cursor: pointer; }
.barlist-ligne:hover { background: var(--ink-800); }
.barlist-nom { font-size: 0.84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist-piste { position: relative; height: 12px; display: flex; }
.barlist-barre { height: 100%; border-radius: 0 4px 4px 0; }
.barlist-piste.stack { width: var(--plein); gap: 2px; }
.stack-seg { height: 100%; min-width: 2px; flex-basis: 0; }
.stack-seg:last-child { border-radius: 0 4px 4px 0; }
.stack-seg:hover { opacity: .85; }
.barlist-val { font-size: 0.82rem; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-mid); }

/* Anneau : la légende porte la valeur et la part — on ne lit jamais un angle. */
.donut { display: flex; align-items: center; gap: var(--s5); flex-wrap: wrap; }
.donut-svg { flex: none; }
.donut-seg { stroke: var(--ink-900); stroke-width: 2; }
.donut-seg:hover { opacity: .85; }
.donut-total { fill: var(--text); font-size: 22px; font-weight: 700; font-family: var(--font); }
.donut-sous { fill: var(--text-dim); font-size: 11px; font-family: var(--font); }
.donut-legende { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 160px; }
.donut-legende li { display: grid; grid-template-columns: 10px 1fr auto 44px; align-items: center; gap: var(--s2); font-size: 0.82rem; }
.donut-legende i { width: 10px; height: 10px; border-radius: 2px; }
.donut-legende b { font-variant-numeric: tabular-nums; font-weight: 600; }
.donut-legende em { font-style: normal; color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; }

/* Barre divergente (écart à l'espérance) : deux directions depuis un centre. */
.div-bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 64px; align-items: center; gap: var(--s3); padding: 5px 0; }
.div-bar-name { font-size: 0.84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.div-bar-track { position: relative; height: 12px; }
.div-bar-mid { position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--rule-strong); }
.div-bar-fill { position: absolute; top: 0; bottom: 0; }
.div-bar-fill.pos { background: var(--chart-div-pos); left: 50%; border-radius: 0 4px 4px 0; }
.div-bar-fill.neg { background: var(--chart-div-neg); right: 50%; border-radius: 4px 0 0 4px; }
.div-bar-value { font-size: 0.82rem; font-variant-numeric: tabular-nums; text-align: right; color: var(--text-mid); }
.div-legend { display: flex; gap: var(--s4); font-size: 0.78rem; color: var(--text-mid); margin-bottom: var(--s3); }
.div-legend span { display: inline-flex; align-items: center; gap: 6px; }
.div-legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ===== TABLES ===== */
.tbl-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
table.data th {
    text-align: left; padding: 0; font-size: 0.72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim);
    border-bottom: 1px solid var(--rule-strong); white-space: nowrap;
}
table.data th button {
    all: unset; display: block; width: 100%; box-sizing: border-box;
    padding: 7px 10px; cursor: pointer;
}
table.data th.num button { text-align: right; }
table.data th button:hover { color: var(--text); }
table.data th[aria-sort="ascending"] button::after { content: ' ↑'; }
table.data th[aria-sort="descending"] button::after { content: ' ↓'; }
table.data th.num, table.data td.num { text-align: right; }
table.data td { padding: 7px 10px; border-bottom: 1px solid var(--rule); }
table.data tbody tr:hover td { background: var(--ink-800); }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tr.cliquable { cursor: pointer; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.pill.jade { background: var(--jade-wash); color: var(--jade); }
.pill.crimson { background: var(--crimson-wash); color: var(--crimson-clair); }
.pill.dim { background: var(--ink-700); color: var(--text-mid); }

/* ===== LE JOURNAL D'UN COMBAT ===== */
.journal { max-height: 520px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; font-size: 0.84rem; }
.journal-round {
    position: sticky; top: 0; background: var(--ink-900);
    padding: var(--s2) 0 4px; font-size: 0.72rem; font-weight: 700;
    color: var(--text-dim); text-transform: uppercase; letter-spacing: .08em;
}
.journal-ligne { display: grid; grid-template-columns: 130px 1fr; gap: var(--s3); padding: 4px 6px; border-radius: var(--r-sm); }
.journal-ligne:hover { background: var(--ink-800); }
.journal-type { color: var(--text-dim); font-size: 0.76rem; }
.journal-ligne.type-kill .journal-type, .journal-ligne.type-ko .journal-type { color: var(--crimson-clair); }

/* ===== COMPTES ===== */
.acc-actions { display: flex; gap: 6px; white-space: nowrap; justify-content: flex-end; }
.acc-row-editing input, .acc-row-editing select { min-width: 0; }
.edit-mdp { display: flex; gap: var(--s2); }
.edit-mdp input { max-width: 260px; }
.acc-self { color: var(--text-dim); font-size: 0.76rem; font-style: italic; }
.compte-form {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3);
    padding: var(--s3); margin-bottom: var(--s4);
    background: var(--ink-950); border: 1px solid var(--rule); border-radius: var(--r-md);
}
.compte-form label { display: flex; flex-direction: column; gap: 5px; min-width: 180px; }
.compte-form-actions { display: flex; gap: var(--s2); }

/* ===== JOURNAL DES ERREURS ===== */
.err-head { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s3); flex-wrap: wrap; }
.err-head h3 { margin: 0; }
.err-head .hint { flex: 1; }
.err-src {
    display: inline-block; padding: 1px 7px; border-radius: 99px;
    font-size: 0.7rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
}
.err-src-serveur { background: var(--crimson-wash); color: var(--crimson-clair); border: 1px solid var(--crimson-dim); }
.err-src-client  { background: var(--jade-wash);    color: var(--jade);    border: 1px solid var(--jade); }
.err-msg  { color: var(--text); font-size: 0.84rem; }
.err-lieu { color: var(--text-dim); font-size: 0.74rem; margin-top: 1px; }
.err-detail { margin-top: 4px; }
.err-detail summary { cursor: pointer; color: var(--text-dim); font-size: 0.74rem; }
.err-detail pre {
    margin: 4px 0 0 0; padding: 8px; max-height: 220px; overflow: auto;
    background: var(--ink-950); border: 1px solid var(--rule);
    border-radius: var(--r-sm); font-size: 0.72rem; color: var(--text-mid);
    white-space: pre-wrap; word-break: break-word;
}
.int-alerte { color: var(--crimson-clair); }

.admin-foot { text-align: center; font-size: 0.74rem; color: var(--text-dim); padding: var(--s3) 0 var(--s6); margin: 0; }

/* ===== ÉCRANS ÉTROITS ===== */
@media (max-width: 1100px) {
    .blk-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
    .adm { grid-template-columns: minmax(0, 1fr); }
    /* La navigation devient une bande qui défile, en haut. */
    .adm-nav {
        position: static; height: auto; flex-direction: row; align-items: center;
        padding: var(--s2) var(--s3); overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--crease);
    }
    .adm-nav-tete { display: none; }
    .adm-nav nav { flex-direction: row; }
    .adm-nav a { white-space: nowrap; border-left: 0; border-bottom: 2px solid transparent; border-radius: var(--r-md); }
    .adm-nav a[aria-current="page"] { border-bottom-color: var(--crimson); border-radius: var(--r-md) var(--r-md) 0 0; }
    .adm-quitter { margin: 0 0 0 auto; white-space: nowrap; }
    .adm-filtres { padding: var(--s3); gap: var(--s3); }
    .filtre select { min-width: 0; max-width: 60vw; }
    .adm-main { padding: var(--s3); }
    .kpi-row, #kpi-vue { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
    .kpi-tile { padding: var(--s3); }
    .kpi-value { font-size: 1.4rem; }
    .spark { display: none; }
    .barlist-ligne { grid-template-columns: minmax(70px, 38%) minmax(0, 1fr) 52px; gap: var(--s2); }
    .div-bar-row { grid-template-columns: 84px 1fr 52px; gap: var(--s2); }
    .journal-ligne { grid-template-columns: 1fr; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .adm-main, .chart-tip, .btn { transition: none; }
}
