:root {
  --fond: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --texte: #16202a;
  --texte-2: #4b5966;
  --texte-3: #6f7c88;
  --bord: #d9e0e6;
  --accent: #17324d;
  --accent-texte: #ffffff;
  --vert: #16794c;
  --vert-fond: #e3f4ea;
  --rouge: #b42318;
  --rouge-fond: #fdecea;
  --verrou: #4a5866;
  --verrou-fond: #e8ecf0;
  --ambre: #8a5a00;
  --ambre-fond: #fff4dc;
  --ombre: 0 1px 2px rgba(16, 24, 32, .06), 0 2px 8px rgba(16, 24, 32, .05);
  --rayon: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #0f1419; --surface: #171e25; --surface-2: #1e2731; --texte: #e6edf3;
    --texte-2: #b3c0cc; --texte-3: #8695a3; --bord: #2b3742; --accent: #8cc4ff; --accent-texte: #0b1520;
    --vert: #5fd39a; --vert-fond: #12301f; --rouge: #ff8a80; --rouge-fond: #3a1714;
    --verrou: #a9b6c2; --verrou-fond: #232d37; --ambre: #f5c36b; --ambre-fond: #33270e;
    --ombre: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fond: #0f1419; --surface: #171e25; --surface-2: #1e2731; --texte: #e6edf3;
  --texte-2: #b3c0cc; --texte-3: #8695a3; --bord: #2b3742; --accent: #8cc4ff; --accent-texte: #0b1520;
  --vert: #5fd39a; --vert-fond: #12301f; --rouge: #ff8a80; --rouge-fond: #3a1714;
  --verrou: #a9b6c2; --verrou-fond: #232d37; --ambre: #f5c36b; --ambre-fond: #33270e;
  --ombre: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--texte);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; overflow-wrap: anywhere; }
.consequences code { background: var(--surface); }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }
h1, h2, h3 { line-height: 1.25; margin: 0; }

.bouton {
  appearance: none; border: 1px solid var(--bord); background: var(--surface); color: var(--texte);
  padding: .55rem .95rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.bouton:hover { border-color: var(--texte-3); }
.bouton:active { transform: translateY(1px); }
.bouton:focus-visible, input:focus-visible, .carte:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.bouton:disabled { opacity: .45; cursor: not-allowed; }
.bouton-principal { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
.bouton-principal:hover { border-color: var(--accent); filter: brightness(1.08); }
.bouton-discret { background: transparent; }

/* Connexion */
.page-connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.carte-connexion {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--bord);
  border-radius: 14px; padding: 28px; box-shadow: var(--ombre);
}
.carte-connexion h1 { font-size: 1.4rem; margin: 18px 0 4px; }
.sous-titre { color: var(--texte-2); margin: 0 0 18px; font-size: .92rem; }
.carte-connexion form { display: grid; gap: 6px; }
.carte-connexion label { font-weight: 600; font-size: .9rem; margin-top: 8px; }
.carte-connexion input {
  font: inherit; padding: .65rem .75rem; border-radius: 8px; border: 1px solid var(--bord);
  background: var(--surface); color: var(--texte);
}
.carte-connexion .bouton { margin-top: 16px; padding: .7rem; }
.erreur { background: var(--rouge-fond); color: var(--rouge); padding: .6rem .8rem; border-radius: 8px; font-size: .9rem; }

.marque { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .01em; }
.pastille-marque { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); box-shadow: 6px 6px 0 -2px var(--vert); }

/* En-tête */
.entete {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--fond) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--bord); padding: 14px max(16px, calc((100vw - 1240px) / 2)) 0;
}
.entete-ligne { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.entete-ligne form { margin: 0; }
.resume { margin: 6px 0 0; color: var(--texte-2); font-size: .9rem; font-variant-numeric: tabular-nums; }
.avertissement { margin: 2px 0 10px; color: var(--texte-3); font-size: .82rem; }
.onglets { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.onglet {
  appearance: none; border: 0; background: transparent; color: var(--texte-2); font: inherit; font-weight: 600;
  padding: .6rem .9rem; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.onglet[aria-selected="true"] { color: var(--texte); border-bottom-color: var(--accent); }
.onglet .compte { color: var(--texte-3); font-weight: 500; margin-left: 4px; font-variant-numeric: tabular-nums; }
.outils-filtre { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 10px 0 12px; }
#recherche {
  flex: 1 1 260px; min-width: 0; font: inherit; padding: .5rem .75rem; border-radius: 8px;
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte);
}
.filtres-niveau { display: flex; flex-wrap: wrap; gap: 6px; }
.puce-filtre {
  appearance: none; font: inherit; font-size: .85rem; font-weight: 600; padding: .35rem .7rem; border-radius: 999px;
  border: 1px solid var(--bord); background: var(--surface); color: var(--texte-2); cursor: pointer;
}
.puce-filtre[aria-pressed="true"] { background: var(--texte); color: var(--fond); border-color: var(--texte); }

/* Contenu */
.contenu { padding: 18px max(16px, calc((100vw - 1240px) / 2)) 140px; }
.intro-onglet { color: var(--texte-2); margin: 0 0 18px; max-width: 80ch; }
.categorie { margin: 0 0 28px; }
.categorie-titre { display: flex; align-items: baseline; gap: 10px; margin: 0 0 10px; font-size: 1.05rem; }
.categorie-titre .compte { color: var(--texte-3); font-weight: 500; font-size: .85rem; }
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 12px; }
.vide { color: var(--texte-3); padding: 40px 0; text-align: center; }

.carte {
  position: relative; background: var(--surface); border: 1px solid var(--bord); border-left: 4px solid var(--bord);
  border-radius: var(--rayon); padding: 14px 14px 12px; box-shadow: var(--ombre); display: flex; flex-direction: column; gap: 8px;
}
.carte.n-vert { border-left-color: var(--vert); }
.carte.n-rouge { border-left-color: var(--rouge); }
.carte.n-verrouille {
  border-left-color: var(--verrou); background:
  repeating-linear-gradient(135deg, var(--surface) 0 14px, var(--surface-2) 14px 15px);
}
.carte.coche { box-shadow: 0 0 0 2px var(--accent), var(--ombre); }
.carte-tete { display: flex; gap: 12px; align-items: flex-start; }
.visuel {
  flex: none; width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
  background: var(--surface-2); color: var(--accent);
}
.n-vert .visuel { color: var(--vert); background: var(--vert-fond); }
.n-rouge .visuel { color: var(--rouge); background: var(--rouge-fond); }
.n-verrouille .visuel { color: var(--verrou); background: var(--verrou-fond); }
.icone { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.fonction-libelle { margin: 1px 0 0; font-size: .78rem; color: var(--texte-3); }
.chiffres { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr); gap: 10px; margin: 0;
  padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.n-verrouille .chiffres { background: var(--surface); border: 1px solid var(--bord); }
.chiffre { min-width: 0; }
.chiffre dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texte-3); font-weight: 700; }
.chiffre dd { margin: 1px 0 0; }
.chiffre .taille, .chiffre .usage { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--texte); font-size: .95rem; }
.chiffre .na { color: var(--texte-3); font-weight: 600; font-size: .86rem; }
.usage-source { font-size: .76rem; color: var(--texte-3); line-height: 1.35; overflow-wrap: anywhere; }
.ligne-resume { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 8px 16px; margin-top: 6px; }
.ligne-resume .resume { margin: 0; }
.compteur {
  display: grid; grid-template-columns: auto auto; column-gap: 10px; align-items: baseline;
  padding: 6px 12px; border-radius: 10px; background: var(--surface); border: 1px solid var(--bord);
}
.compteur-libelle { font-size: .78rem; font-weight: 700; color: var(--texte-2); text-transform: uppercase; letter-spacing: .04em; }
.compteur-valeur { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--vert); text-align: right; }
.compteur-detail { grid-column: 1 / -1; font-size: .76rem; color: var(--texte-3); }
.case { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.cadenas { width: 20px; height: 20px; flex: none; color: var(--verrou); margin-top: 1px; }
.carte-titre { flex: 1; min-width: 0; }
.carte-titre h3 { font-size: 1rem; overflow-wrap: anywhere; }
.carte-titre label { cursor: pointer; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.etiquette {
  font-size: .74rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2);
  color: var(--texte-2); white-space: nowrap;
}
.etiquette-root { background: var(--ambre-fond); color: var(--ambre); }
.etiquette.niveau-vert { background: var(--vert-fond); color: var(--vert); }
.etiquette.niveau-rouge { background: var(--rouge-fond); color: var(--rouge); }
.etiquette.niveau-verrouille { background: var(--verrou-fond); color: var(--verrou); }
.etiquette.statut-actif::before, .etiquette.statut-inactif::before, .etiquette.statut-arrete::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px;
}
.etiquette.statut-actif::before { background: var(--vert); }
.etiquette.statut-inactif::before { background: var(--texte-3); }
.etiquette.statut-arrete::before { background: var(--ambre); }
.role { margin: 0; color: var(--texte); }
.raison { margin: 0; font-size: .86rem; color: var(--texte-2); }

.consequences {
  border-radius: 8px; padding: 8px 10px; font-size: .86rem; background: var(--rouge-fond); color: var(--texte);
}
.n-verrouille .consequences { background: var(--verrou-fond); }
.consequences h4 { margin: 0 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--rouge); }
.n-verrouille .consequences h4 { color: var(--verrou); }
.consequences ul { margin: 0; padding-left: 1.1em; }
.consequences li { margin: 2px 0; }
.certitude { font-size: .74rem; font-weight: 700; padding: 0 .35rem; border-radius: 4px; margin-left: 4px; white-space: nowrap; }
.certitude.certaine { background: var(--surface); color: var(--rouge); }
.certitude.probable { background: var(--ambre-fond); color: var(--ambre); }
/* Rouge : conséquences visibles au survol, au focus clavier et quand l'élément est coché. */
.n-rouge .consequences { display: none; }
.n-rouge:hover .consequences, .n-rouge:focus-within .consequences, .n-rouge.coche .consequences { display: block; }
.indice-survol { font-size: .78rem; color: var(--rouge); margin: 0; }
.n-rouge:hover .indice-survol, .n-rouge:focus-within .indice-survol, .n-rouge.coche .indice-survol { display: none; }
@media (hover: none) { .n-rouge .consequences { display: block; } .indice-survol { display: none; } }

details.details { font-size: .86rem; color: var(--texte-2); }
details.details summary { cursor: pointer; font-weight: 600; color: var(--texte-2); padding: 2px 0; }
details.details dl { margin: 6px 0 0; display: grid; gap: 6px; }
details.details dt { font-weight: 700; color: var(--texte); font-size: .8rem; }
details.details dd { margin: 0; overflow-wrap: anywhere; }
details.details ul { margin: 0; padding-left: 1.1em; }

/* Barre de sélection */
.barre-selection {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--surface); border-top: 1px solid var(--bord);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, .08); padding: 12px max(16px, calc((100vw - 1240px) / 2));
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
}
.barre-texte { font-variant-numeric: tabular-nums; font-size: .92rem; }
.barre-texte strong { font-size: 1rem; }
.barre-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Dialogue */
.dialogue {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--bord); border-radius: 14px;
  padding: 18px; background: var(--surface); color: var(--texte); box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.dialogue[open] { display: flex; flex-direction: column; gap: 10px; }
.dialogue::backdrop { background: rgba(10, 16, 22, .55); }
.dialogue-tete { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dialogue-tete h2 { font-size: 1.1rem; }
.dialogue-aide { margin: 0; color: var(--texte-2); font-size: .88rem; }
#prompt {
  width: 100%; min-height: 50vh; resize: vertical; font: 13.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  padding: 12px; border-radius: 8px; border: 1px solid var(--bord); background: var(--surface-2); color: var(--texte);
  white-space: pre-wrap;
}
.dialogue-pied { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.copie-etat { color: var(--vert); font-size: .88rem; font-weight: 600; }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .barre-actions { width: 100%; }
  .barre-actions .bouton { flex: 1 1 100%; }
  .chiffres { grid-template-columns: 1fr; }
  .compteur { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
