:root {
  --fond: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --bordure: #e2e7e5;
  --texte: #14211c;
  --texte-doux: #5d6d66;
  --primaire: #0b5c3f;
  --primaire-clair: #17936a;
  --accent: #2c72b8;
  --alerte: #c0392b;
  --avertissement: #d98324;
  --ok: #17936a;
  --ombre: 0 1px 3px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.04);
  --radius: 10px;
  --mono: 'Consolas', 'SF Mono', 'Menlo', monospace;
}

/* L'attribut hidden doit primer sur les regles display des composants
   (.connexion, .modale et .vue declarent display:flex). */
[hidden] { display: none !important; }

[data-theme="sombre"] {
  --fond: #0e1512;
  --surface: #151f1b;
  --surface-2: #1b2723;
  --bordure: #26332e;
  --texte: #e6edea;
  --texte-doux: #92a29b;
  --primaire: #17936a;
  --primaire-clair: #2bbd8b;
  --accent: #5a9fe0;
  --ombre: 0 1px 3px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--fond);
  color: var(--texte);
  line-height: 1.55;
  font-size: 14px;
}

/* ---------------- Connexion ---------------- */
.connexion {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(150deg, #0b5c3f 0%, #0e3f2d 55%, #0a2a1f 100%);
  padding: 20px;
}
.carte-connexion {
  background: var(--surface); border-radius: 14px; padding: 34px 32px;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.28);
}
.logo-connexion { text-align: center; margin-bottom: 14px; }
.carte-connexion h1 { font-size: 1.3em; text-align: center; color: var(--primaire); }
.sous-titre { text-align: center; color: var(--texte-doux); font-size: .86em; margin-bottom: 22px; }
.carte-connexion label { display: block; margin-bottom: 14px; font-size: .84em; font-weight: 600; color: var(--texte-doux); }
.carte-connexion input {
  width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--bordure);
  border-radius: 8px; font-size: 1em; background: var(--surface-2); color: var(--texte);
}
.erreur-connexion { color: var(--alerte); font-size: .84em; text-align: center; margin-top: 10px; min-height: 18px; }
.note-connexion { font-size: .76em; color: var(--texte-doux); margin-top: 14px; text-align: center; line-height: 1.5; }

/* ---------------- Entete ---------------- */
.entete {
  background: var(--surface); border-bottom: 1px solid var(--bordure);
  padding: 10px 20px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 40;
}
.marque { display: flex; align-items: center; gap: 11px; }
.marque strong { display: block; font-size: .98em; color: var(--primaire); }
.version { font-size: .72em; color: var(--texte-doux); }
.entete-actions { display: flex; align-items: center; gap: 8px; }
.pastille { display: inline-flex; align-items: center; gap: 6px; font-size: .74em; color: var(--texte-doux); }
.pastille i { width: 8px; height: 8px; border-radius: 50%; background: var(--texte-doux); display: block; }
.pastille.actif i { background: var(--ok); box-shadow: 0 0 0 3px rgba(23,147,106,.18); }

/* ---------------- Onglets ---------------- */
.onglets {
  background: var(--surface); border-bottom: 1px solid var(--bordure);
  display: flex; gap: 2px; padding: 0 14px; overflow-x: auto;
  position: sticky; top: 51px; z-index: 39;
}
.onglets button {
  background: none; border: none; padding: 11px 13px; font-size: .84em; cursor: pointer;
  color: var(--texte-doux); border-bottom: 2px solid transparent; white-space: nowrap;
  font-family: inherit;
}
.onglets button:hover { color: var(--texte); }
.onglets button.actif { color: var(--primaire); border-bottom-color: var(--primaire); font-weight: 600; }

/* ---------------- Structure ---------------- */
main { padding: 18px; max-width: 1500px; margin: 0 auto; }
.vue { display: flex; flex-direction: column; gap: 16px; }
.carte {
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--ombre);
}
.carte-plein { padding: 0; overflow: hidden; }
.carte h2 { font-size: .98em; color: var(--primaire); margin-bottom: 10px; }
.grille-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.barre-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.barre-actions h2 { margin: 0; }
.aide { font-size: .82em; color: var(--texte-doux); margin-bottom: 10px; }

/* ---------------- KPIs ---------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--radius);
  padding: 13px 15px; box-shadow: var(--ombre);
}
.kpi .valeur { font-size: 1.65em; font-weight: 700; color: var(--primaire); line-height: 1.15; }
.kpi .libelle { font-size: .76em; color: var(--texte-doux); }
.kpi .detail { font-size: .72em; color: var(--texte-doux); margin-top: 3px; }

/* ---------------- Boutons ---------------- */
.btn {
  padding: 7px 13px; border-radius: 7px; border: 1px solid var(--bordure);
  background: var(--surface); color: var(--texte); font-size: .82em; cursor: pointer;
  font-family: inherit; text-decoration: none; display: inline-block; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primaire { background: var(--primaire); border-color: var(--primaire); color: #fff; font-weight: 600; }
.btn-primaire:hover { background: var(--primaire-clair); border-color: var(--primaire-clair); }
.btn-fantome { background: transparent; }
.btn-danger { border-color: var(--alerte); color: var(--alerte); }
.btn-petit { padding: 4px 9px; font-size: .76em; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- Formulaires ---------------- */
input, select, textarea {
  padding: 8px 11px; border: 1px solid var(--bordure); border-radius: 7px;
  background: var(--surface-2); color: var(--texte); font-size: .86em; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primaire-clair); outline-offset: -1px; }
.ligne-form { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.ligne-form input { flex: 1; min-width: 130px; }
form label { display: block; margin-bottom: 10px; font-size: .8em; font-weight: 600; color: var(--texte-doux); }
form label input, form label textarea, form label select { width: 100%; margin-top: 4px; font-weight: 400; }

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; font-size: .82em; }
th { text-align: left; padding: 8px 9px; background: var(--surface-2); color: var(--texte-doux); font-weight: 600; font-size: .92em; border-bottom: 1px solid var(--bordure); }
td { padding: 8px 9px; border-bottom: 1px solid var(--bordure); vertical-align: top; }
tr:last-child td { border-bottom: none; }
.table-defile { max-height: 420px; overflow-y: auto; }

/* ---------------- Etiquettes ---------------- */
.etq {
  display: inline-block; padding: 2px 8px; border-radius: 11px; font-size: .72em;
  font-weight: 600; background: var(--surface-2); color: var(--texte-doux); border: 1px solid var(--bordure);
}
.etq-ok { background: rgba(23,147,106,.12); color: var(--ok); border-color: rgba(23,147,106,.3); }
.etq-alerte { background: rgba(192,57,43,.1); color: var(--alerte); border-color: rgba(192,57,43,.3); }
.etq-avert { background: rgba(217,131,36,.12); color: var(--avertissement); border-color: rgba(217,131,36,.3); }
.etq-info { background: rgba(44,114,184,.1); color: var(--accent); border-color: rgba(44,114,184,.3); }

/* ---------------- Comptes ---------------- */
.grille-comptes { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 14px; }
.carte-compte {
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--ombre); display: flex; flex-direction: column; gap: 10px;
}
.compte-entete { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.compte-titre { font-weight: 700; font-size: .96em; }
.compte-num { font-size: .78em; color: var(--texte-doux); font-family: var(--mono); }
.compte-lignes { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .79em; }
.compte-lignes dt { color: var(--texte-doux); }
.compte-lignes dd { text-align: right; font-weight: 600; }
.barre { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; border: 1px solid var(--bordure); }
.barre span { display: block; height: 100%; background: var(--primaire-clair); }
.barre.avert span { background: var(--avertissement); }
.barre.alerte span { background: var(--alerte); }
.compte-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.qr-boite { text-align: center; padding: 8px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--bordure); }
.qr-boite img { max-width: 190px; border-radius: 6px; background: #fff; padding: 6px; }
.qr-info { font-size: .74em; color: var(--texte-doux); margin-top: 5px; }

/* ---------------- Inbox ---------------- */
.inbox { display: grid; grid-template-columns: 290px 1fr; gap: 14px; height: calc(100vh - 170px); }
.inbox-liste, .inbox-fil {
  background: var(--surface); border: 1px solid var(--bordure);
  border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden;
}
.inbox-entete { padding: 10px 12px; border-bottom: 1px solid var(--bordure); background: var(--surface-2); }
.inbox-entete select { width: 100%; }
#liste-conversations { overflow-y: auto; flex: 1; }
.conv {
  padding: 10px 12px; border-bottom: 1px solid var(--bordure); cursor: pointer; display: flex;
  justify-content: space-between; gap: 8px; align-items: flex-start;
}
.conv:hover { background: var(--surface-2); }
.conv.actif { background: rgba(23,147,106,.1); border-left: 3px solid var(--primaire); }
.conv-nom { font-weight: 600; font-size: .85em; }
.conv-apercu { font-size: .76em; color: var(--texte-doux); }
.conv-badge { background: var(--primaire); color: #fff; border-radius: 10px; padding: 1px 7px; font-size: .68em; font-weight: 700; }
.fil { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--fond); }
.bulle { max-width: 68%; padding: 8px 12px; border-radius: 12px; font-size: .85em; box-shadow: var(--ombre); word-break: break-word; }
.bulle.entrant { background: var(--surface); align-self: flex-start; border-bottom-left-radius: 3px; }
.bulle.sortant { background: rgba(23,147,106,.16); align-self: flex-end; border-bottom-right-radius: 3px; }
.bulle .meta { font-size: .7em; color: var(--texte-doux); margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.composeur { display: flex; gap: 8px; padding: 11px; border-top: 1px solid var(--bordure); background: var(--surface); }
.composeur input { flex: 1; }
.trace { padding: 0 12px 12px; max-height: 210px; overflow-y: auto; background: var(--surface); }

/* ---------------- Flux et blocs ---------------- */
.flux { max-height: 300px; overflow-y: auto; font-family: var(--mono); font-size: .74em; }
.flux-ligne { padding: 5px 8px; border-bottom: 1px solid var(--bordure); display: flex; gap: 9px; align-items: baseline; }
.flux-ligne:first-child { animation: surligne 1.4s ease; }
@keyframes surligne { from { background: rgba(23,147,106,.22); } to { background: transparent; } }
.flux-heure { color: var(--texte-doux); }
.flux-type { color: var(--primaire); font-weight: 700; min-width: 190px; }
.flux-detail { color: var(--texte-doux); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bloc {
  background: var(--surface-2); border: 1px solid var(--bordure); border-left: 3px solid var(--primaire-clair);
  border-radius: 7px; padding: 11px 13px; font-family: var(--mono); font-size: .76em;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word; margin-top: 10px;
}
code { font-family: var(--mono); background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .92em; }

/* ---------------- Controles ---------------- */
.controle { display: flex; gap: 9px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--bordure); font-size: .8em; }
.controle:last-child { border-bottom: none; }
.controle-num {
  width: 20px; height: 20px; border-radius: 50%; background: var(--primaire); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: .72em; font-weight: 700; flex-shrink: 0;
}
.controle.refus .controle-num { background: var(--alerte); }
.controle.differe .controle-num { background: var(--avertissement); }
.controle-detail { color: var(--texte-doux); font-size: .92em; }

/* ---------------- Modale ---------------- */
.modale { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modale-boite { background: var(--surface); border-radius: 12px; max-width: 680px; width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modale-entete { padding: 14px 18px; border-bottom: 1px solid var(--bordure); display: flex; justify-content: space-between; align-items: center; }
.modale-entete h3 { font-size: 1em; color: var(--primaire); }
.modale-corps { padding: 18px; overflow-y: auto; }

/* ---------------- Toasts ---------------- */
#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface); border: 1px solid var(--bordure); border-left: 4px solid var(--primaire);
  border-radius: 8px; padding: 10px 15px; font-size: .84em; box-shadow: 0 6px 22px rgba(0,0,0,.16);
  max-width: 380px; animation: entree .22s ease;
}
.toast.erreur { border-left-color: var(--alerte); }
.toast.avert { border-left-color: var(--avertissement); }
@keyframes entree { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }


.vide { text-align: center; color: var(--texte-doux); padding: 26px; font-size: .85em; }

@media (max-width: 980px) {
  .grille-2 { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox-liste { max-height: 260px; }
  .inbox-fil { height: 480px; }
}

.bulle .actions-bulle { margin-left: 8px; display: none; }
.bulle:hover .actions-bulle { display: inline; }
.lien { background: none; border: none; color: var(--accent); cursor: pointer; font-size: .92em; padding: 0 3px; text-decoration: underline; }
.bulle .reaction { display: inline-block; margin-left: 6px; font-size: 1.05em; }
.bulle .retire { color: var(--texte-doux); }
