:root {
  --fond: #f4f5f7;
  --surface: #ffffff;
  --texte: #1c2230;
  --doux: #5f6b7d;
  --bord: #e1e4ea;
  --accent: #7a1f3d;        /* bordeaux */
  --accent-clair: #f6e9ee;
  --vert: #1f7a4d;
  --vert-clair: #e5f4ec;
  --rouge: #b42318;
  --rouge-clair: #fdecea;
  --orange: #a15c07;
  --orange-clair: #fdf3e2;
  --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 {
    --fond: #12151b; --surface: #1b1f27; --texte: #e8eaef; --doux: #9aa3b2;
    --bord: #2c323d; --accent: #d9708f; --accent-clair: #3a2029;
    --vert: #5cc192; --vert-clair: #18332a; --rouge: #f0857b; --rouge-clair: #3b1e1c;
    --orange: #e6a959; --orange-clair: #382a17; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--fond); color: var(--texte); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
input, select, textarea, button { font: inherit; color: inherit; }

/* Connexion */
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.carte-connexion { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--bord); border-radius: 14px; padding: 32px 28px; box-shadow: var(--ombre); display: grid; gap: 14px; }
.carte-connexion h1 { text-align: center; font-size: 24px; }
.sous-titre { text-align: center; color: var(--doux); margin: -8px 0 6px; }
.aide { text-align: center; color: var(--doux); font-size: 13px; margin: 0; }
.logo { width: 48px; height: 48px; margin: 0 auto; border-radius: 12px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 22px; }
.logo.petit { width: 32px; height: 32px; font-size: 16px; border-radius: 8px; margin: 0; }

/* Formulaires */
label { display: grid; gap: 4px; font-size: 13px; color: var(--doux); font-weight: 500; }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--bord); border-radius: 8px; background: var(--surface); font-size: 15px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 70px; resize: vertical; }
input[readonly] { background: var(--fond); }
.erreur { color: var(--rouge); margin: 0; font-size: 14px; min-height: 0; }
.erreur:empty { display: none; }

/* Boutons */
.btn { border: 1px solid var(--bord); background: var(--surface); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--fond); }
.btn.primaire { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primaire:hover { filter: brightness(1.08); }
.btn.danger { color: var(--rouge); }
.btn.lien { border: 0; background: none; padding: 0; color: var(--doux); text-decoration: underline; }
.btn.petit { padding: 4px 9px; font-size: 13px; }
.btn.icone { display: none; padding: 6px 10px; }
.btn:disabled { opacity: .55; cursor: wait; }

/* Mise en page */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.barre { background: var(--surface); border-right: 1px solid var(--bord); display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.marque { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 8px 18px; }
nav { display: grid; gap: 2px; flex: 1; align-content: start; overflow-y: auto; }
nav button { text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--doux); font-weight: 500; }
nav button:hover { background: var(--fond); color: var(--texte); }
nav button.actif { background: var(--accent-clair); color: var(--accent); }
nav .sep { border-top: 1px solid var(--bord); margin: 8px 4px; }
.profil { border-top: 1px solid var(--bord); padding: 12px 8px 0; display: grid; gap: 2px; }
.profil .role { color: var(--doux); font-size: 13px; margin-bottom: 6px; }
.contenu { padding: 24px 28px; min-width: 0; }
.entete { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.entete h2 { font-size: 22px; flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tableau de bord */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 16px; box-shadow: var(--ombre); }
.kpi .lib { color: var(--doux); font-size: 13px; }
.kpi .val { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sous { color: var(--doux); font-size: 12px; margin-top: 2px; }
.kpi.positif .val { color: var(--vert); }
.kpi.negatif .val { color: var(--rouge); }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.bloc { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); padding: 16px; box-shadow: var(--ombre); min-width: 0; }
.bloc h3 { font-size: 15px; margin-bottom: 10px; }
.vide { color: var(--doux); padding: 18px 0; text-align: center; }

/* Tables */
.outils { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.outils input { max-width: 320px; }
.table-wrap { background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon); overflow-x: auto; box-shadow: var(--ombre); }
.bloc .table-wrap { border: 0; box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--bord); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--doux); font-weight: 600; background: var(--fond); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.acts { text-align: right; }
td.acts .btn + .btn { margin-left: 6px; }
td.texte { white-space: normal; max-width: 280px; }
tr.alerte td { background: var(--rouge-clair); }
.compteur { color: var(--doux); font-size: 13px; padding: 8px 2px; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--fond); color: var(--doux); }
.badge.vert { background: var(--vert-clair); color: var(--vert); }
.badge.rouge { background: var(--rouge-clair); color: var(--rouge); }
.badge.orange { background: var(--orange-clair); color: var(--orange); }
.badge.accent { background: var(--accent-clair); color: var(--accent); }

/* Dialogue */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--texte); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 20, 30, .45); }
#form-dialogue { padding: 22px; display: grid; gap: 14px; max-height: 90vh; overflow-y: auto; }
#dialogue-corps { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#dialogue-corps .large { grid-column: 1 / -1; }
.pied { display: flex; justify-content: flex-end; gap: 8px; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; padding: 12px; background: var(--fond); border: 1px dashed var(--bord); border-radius: 8px; text-align: center; user-select: all; word-break: break-all; }
.note { color: var(--doux); font-size: 13px; margin: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--texte); color: var(--surface); padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100vw - 32px); z-index: 10; }
.toast.visible { opacity: 1; transform: translateX(-50%); }
.toast.erreur-toast { background: var(--rouge); color: #fff; }

/* Mobile */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .barre { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 5; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--ombre); }
  .barre.ouverte { transform: none; }
  .btn.icone { display: inline-block; }
  .contenu { padding: 16px; }
  .grille-2 { grid-template-columns: 1fr; }
  #dialogue-corps { grid-template-columns: 1fr; }
  .outils input { max-width: none; }
}
.ligne-mdp { display: flex; gap: 6px; }
.ligne-mdp input { flex: 1; min-width: 0; }
@media (max-width: 480px) { .ligne-mdp { flex-wrap: wrap; } .ligne-mdp input { flex-basis: 100%; } }
