:root {
  --bleu: #1a73e8;
  --bleu-fonce: #174ea6;
  --fond: #f6f8fc;
  --bord: #e3e6ea;
  --texte: #202124;
  --gris: #5f6368;
  --gris-clair: #80868b;
  --rouge: #d93025;
  --vert: #188038;
  --ombre: 0 1px 3px rgba(60, 64, 67, 0.15);
  --radius: 12px;
}

/* Mode sombre : on redefinit les variables + les surfaces blanches */
:root { --surface: #ffffff; }
:root[data-theme="dark"] {
  --bleu: #8ab4f8;
  --bleu-fonce: #aecbfa;
  --fond: #1b1c1d;
  --surface: #26282b;
  --bord: #3c4043;
  --texte: #e8eaed;
  --gris: #bdc1c6;
  --gris-clair: #9aa0a6;
  --ombre: 0 1px 3px rgba(0, 0, 0, 0.5);
}
:root[data-theme="dark"] header,
:root[data-theme="dark"] .cote,
:root[data-theme="dark"] .principal,
:root[data-theme="dark"] .carte,
:root[data-theme="dark"] .compose,
:root[data-theme="dark"] .login-card,
:root[data-theme="dark"] .menu-contacts,
:root[data-theme="dark"] .editeur,
:root[data-theme="dark"] .barre-format select,
:root[data-theme="dark"] .login-card input,
:root[data-theme="dark"] .grille-form input,
:root[data-theme="dark"] .grille-form select,
:root[data-theme="dark"] .pj-vignette,
:root[data-theme="dark"] .mini { background: var(--surface); color: var(--texte); }
:root[data-theme="dark"] .recherche { background: #3c4043; }
:root[data-theme="dark"] .recherche input { color: var(--texte); }
:root[data-theme="dark"] .ligne-msg.non-lu { background: #2a2d2f; }
:root[data-theme="dark"] .login { background: linear-gradient(135deg, #1b1c1d, #26282b); }
:root[data-theme="dark"] #login { background: linear-gradient(135deg, #1b1c1d, #26282b); }
:root[data-theme="dark"] .chip { background: #3c4659; color: #aecbfa; }
:root[data-theme="dark"] input::placeholder { color: var(--gris-clair); }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--texte);
  background: var(--fond);
  font-size: 14px;
}
button { font-family: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ---------------- Connexion ---------------- */
#login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8f0fe, #f6f8fc);
}
.login-card {
  background: #fff;
  padding: 40px;
  border-radius: 16px;
  box-shadow: 0 2px 10px rgba(60, 64, 67, 0.2);
  width: 360px;
  text-align: center;
}
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card p { color: var(--gris); margin: 0 0 24px; font-size: 13px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 12px;
  border: 1px solid var(--bord);
  border-radius: 8px;
  font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--bleu); }
.login-card button {
  width: 100%;
  padding: 12px;
  background: var(--bleu);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 4px;
}
.login-card button:hover { background: var(--bleu-fonce); }
.erreur { color: var(--rouge); font-size: 13px; min-height: 18px; margin-top: 6px; }
.logo {
  width: 56px; height: 56px; border-radius: 14px;
  background: var(--bleu); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 16px;
}

/* ---------------- App ---------------- */
#app { display: flex; flex-direction: column; height: 100vh; }
header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--bord);
}
header .marque { font-size: 20px; font-weight: 600; color: var(--bleu); display: flex; align-items: center; gap: 10px; }
header .marque .logo { width: 34px; height: 34px; font-size: 18px; border-radius: 9px; margin: 0; }
header .spacer { flex: 1; }
header .moi { color: var(--gris); font-size: 13px; }
header .moi b { color: var(--texte); }
.btn-plat {
  background: #fff; border: 1px solid var(--bord); color: var(--gris);
  padding: 7px 14px; border-radius: 8px; font-size: 13px;
}
.btn-plat:hover { background: var(--fond); }

.corps { display: flex; flex: 1; overflow: hidden; }

/* Barre laterale */
.cote { width: 230px; padding: 16px 12px; border-right: 1px solid var(--bord); background: #fff; overflow-y: auto; }
.btn-ecrire {
  width: 100%; padding: 14px; background: var(--bleu); color: #fff; border: none;
  border-radius: 24px; font-size: 15px; font-weight: 600; margin-bottom: 20px;
  box-shadow: var(--ombre); display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-ecrire:hover { background: var(--bleu-fonce); }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  border-radius: 0 20px 20px 0; cursor: pointer; color: var(--gris); font-weight: 500; margin-bottom: 2px;
}
.nav-item:hover { background: var(--fond); }
.nav-item.actif { background: #d3e3fd; color: var(--bleu-fonce); font-weight: 600; }
.nav-item .pastille { margin-left: auto; font-size: 12px; background: var(--bleu); color: #fff; border-radius: 10px; padding: 1px 8px; }
.sep { border-top: 1px solid var(--bord); margin: 14px 4px; }
.cote .titre-section { font-size: 11px; text-transform: uppercase; color: var(--gris-clair); padding: 6px 16px; letter-spacing: .5px; }

/* Zone principale */
.principal { flex: 1; overflow-y: auto; background: #fff; }

/* Liste des messages */
.liste-msg { }
.ligne-msg {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid #f1f3f4; cursor: pointer;
}
.ligne-msg:hover { box-shadow: inset 0 0 0 100px rgba(0,0,0,.015); }
.ligne-msg.non-lu { background: #f8faff; font-weight: 600; }
.ligne-msg .exp { width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ligne-msg .obj { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--gris); }
.ligne-msg.non-lu .obj { color: var(--texte); }
.ligne-msg .date { color: var(--gris-clair); font-size: 12px; width: 90px; text-align: right; }
.ligne-msg .etoile { color: #dadce0; font-size: 16px; }
.ligne-msg .etoile.on { color: #f4b400; }
.ligne-msg .trombone { color: var(--gris-clair); }
.vide { padding: 60px; text-align: center; color: var(--gris-clair); }

/* Lecture d'un message */
.lecture { padding: 24px 32px; max-width: 900px; }
.lecture h2 { font-size: 22px; margin: 0 0 16px; font-weight: 500; }
.lecture .meta { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--bord); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--bleu); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 16px; flex-shrink: 0;
}
.lecture .meta .de { font-weight: 600; }
.lecture .meta .a { color: var(--gris); font-size: 13px; }
.lecture .meta .date { margin-left: auto; color: var(--gris-clair); font-size: 13px; }
.contenu { line-height: 1.6; word-wrap: break-word; }
.contenu img { max-width: 100%; }
.pjs { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--bord); }
.pjs .titre { font-size: 13px; color: var(--gris); margin-bottom: 10px; }
.pj {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--bord);
  border-radius: 8px; padding: 10px 14px; margin: 0 8px 8px 0; text-decoration: none; color: var(--texte);
}
.pj:hover { background: var(--fond); }
.barre-actions { display: flex; gap: 8px; margin-bottom: 16px; }

/* Compose (modal) */
.modal-fond {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex;
  align-items: center; justify-content: center; z-index: 50;
}
.compose {
  background: #fff; width: 640px; max-width: 95vw; max-height: 92vh; border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.compose .entete { background: #404040; color: #fff; padding: 12px 16px; font-size: 14px; display: flex; align-items: center; }
.compose .entete .x { margin-left: auto; cursor: pointer; font-size: 18px; opacity: .8; }
.compose .champ { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--bord); }
.compose .champ label { color: var(--gris); width: 80px; font-size: 13px; }
.compose .champ input { flex: 1; border: none; outline: none; font-size: 14px; }
.destinataires { flex-wrap: wrap; }
.chip { background: #e8f0fe; color: var(--bleu-fonce); border-radius: 14px; padding: 3px 10px; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.chip span { cursor: pointer; font-weight: bold; }
.ajout-dest { position: relative; }
.menu-contacts {
  position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--bord);
  border-radius: 8px; box-shadow: var(--ombre); max-height: 200px; overflow-y: auto; z-index: 5;
}
.menu-contacts div { padding: 10px 14px; cursor: pointer; }
.menu-contacts div:hover { background: var(--fond); }
.menu-contacts .menu-titre {
  padding: 6px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--gris-clair); cursor: default; background: var(--fond);
}
.menu-contacts .menu-titre:hover { background: var(--fond); }
.menu-contacts .menu-groupe { font-weight: 600; color: var(--bleu-fonce); }

.barre-format { display: flex; flex-wrap: wrap; gap: 4px; padding: 6px 12px; border-bottom: 1px solid var(--bord); background: var(--fond); align-items: center; }
.barre-format button {
  border: none; background: transparent; width: 30px; height: 30px; border-radius: 6px; font-size: 15px; color: var(--gris);
}
.barre-format button:hover { background: #e3e6ea; }
.barre-format select { border: 1px solid var(--bord); border-radius: 6px; padding: 4px; font-size: 13px; background: #fff; }
.barre-format input[type=color] { width: 28px; height: 28px; border: none; background: none; padding: 0; cursor: pointer; }
.barre-format .div { width: 1px; height: 20px; background: var(--bord); margin: 0 4px; }

.editeur {
  flex: 1; min-height: 220px; max-height: 45vh; overflow-y: auto; padding: 16px; outline: none; line-height: 1.6;
}
.editeur:empty:before { content: attr(data-vide); color: var(--gris-clair); }
.compose .bas { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--bord); }
.btn-envoyer { background: var(--bleu); color: #fff; border: none; padding: 10px 24px; border-radius: 20px; font-weight: 600; }
.btn-envoyer:hover { background: var(--bleu-fonce); }
.btn-envoyer:disabled { opacity: .6; cursor: default; }
.icone-pj { background: none; border: none; font-size: 18px; color: var(--gris); }
.liste-pj-jointes { font-size: 12px; color: var(--gris); }

/* Admin */
.admin { padding: 24px 32px; max-width: 1100px; }
.admin h2 { font-weight: 500; }
.onglets { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--bord); }
.onglets button { background: none; border: none; padding: 12px 18px; color: var(--gris); font-size: 14px; border-bottom: 2px solid transparent; }
.onglets button.actif { color: var(--bleu); border-bottom-color: var(--bleu); font-weight: 600; }
.carte { background: #fff; border: 1px solid var(--bord); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.carte h3 { margin: 0 0 16px; font-size: 15px; }
.grille-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grille-form label { display: block; font-size: 12px; color: var(--gris); margin-bottom: 4px; }
.grille-form input, .grille-form select { width: 100%; padding: 9px 12px; border: 1px solid var(--bord); border-radius: 8px; font-size: 14px; }
.grille-form .pleine { grid-column: 1 / -1; }
.apercu-sign { background: var(--fond); border-radius: 8px; padding: 12px; white-space: pre-wrap; font-size: 13px; color: var(--gris); margin-top: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--bord); }
th { color: var(--gris); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.mdp-cell { font-family: "Consolas", monospace; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #e8f0fe; color: var(--bleu-fonce); }
.badge.admin { background: #fce8e6; color: var(--rouge); }
.mini { padding: 5px 10px; font-size: 12px; border-radius: 6px; border: 1px solid var(--bord); background: #fff; color: var(--gris); }
.mini:hover { background: var(--fond); }
.mini.danger { color: var(--rouge); border-color: #f3c0bb; }
.log-ligne { font-size: 13px; }
.log-ligne .quand { color: var(--gris-clair); width: 150px; }
.log-ligne .qui { font-weight: 600; }
.log-ligne .act { color: var(--bleu-fonce); }
.filtre-log { margin-bottom: 12px; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #323232; color: #fff; padding: 12px 20px; border-radius: 8px; z-index: 100; box-shadow: var(--ombre);
}
@media (max-width: 700px) {
  .cote { width: 64px; }
  .cote .btn-ecrire span, .nav-item span.txt, .cote .titre-section { display: none; }
  .ligne-msg .exp { width: 110px; }
}

/* ======================= Ajouts v1.2 ======================= */

/* Barre de recherche dans l'en-tete */
.recherche {
  display: flex; align-items: center; gap: 8px; background: var(--fond);
  border: 1px solid var(--bord); border-radius: 22px; padding: 8px 16px; width: 420px; max-width: 40vw;
}
.recherche .loupe { color: var(--gris-clair); font-size: 14px; }
.recherche input { border: none; outline: none; background: transparent; flex: 1; font-size: 14px; color: var(--texte); }
.recherche .effacer-rech { cursor: pointer; color: var(--gris-clair); }
.btn-icone { background: none; border: none; font-size: 18px; padding: 6px 8px; border-radius: 8px; }
.btn-icone:hover { background: var(--fond); }
.pastille.gris { background: var(--gris-clair); }
.bandeau-rech { padding: 14px 20px; color: var(--gris); font-size: 13px; border-bottom: 1px solid var(--bord); }

/* Etiquettes dans la liste */
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; background: var(--fond);
  border: 1px solid var(--bord); color: var(--gris); padding: 1px 6px; border-radius: 6px; margin-left: 8px; }
.tag.lu { color: var(--vert); border-color: #b6d7bf; }

/* Galerie d'images (apercu dans le message) */
.galerie { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
.galerie img { max-width: 280px; max-height: 280px; border-radius: 10px; border: 1px solid var(--bord); object-fit: cover; }
.pj-taille { color: var(--gris-clair); margin-left: 6px; font-size: 12px; }

/* Fil de discussion */
.fil { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--bord); }
.fil-titre { font-size: 13px; color: var(--gris); margin-bottom: 10px; }
.fil-item { display: flex; gap: 12px; padding: 8px 12px; border: 1px solid var(--bord); border-radius: 8px; margin-bottom: 6px; cursor: pointer; }
.fil-item:hover { background: var(--fond); }
.fil-de { font-weight: 600; width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fil-obj { flex: 1; color: var(--gris); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fil-date { color: var(--gris-clair); font-size: 12px; }

.btn-plat.danger { color: var(--rouge); border-color: #f3c0bb; }

/* Zone de pieces jointes (upload intelligent) */
.zone-pj { padding: 10px 16px; border-top: 1px solid var(--bord); }
.pj-depot {
  border: 2px dashed var(--bord); border-radius: 10px; padding: 14px; text-align: center;
  color: var(--gris); font-size: 13px; transition: .15s;
}
.pj-depot.survol { border-color: var(--bleu); background: rgba(26,115,232,.06); color: var(--bleu-fonce); }
.lien-pj { color: var(--bleu); cursor: pointer; text-decoration: underline; }
.pj-indice { font-size: 11px; color: var(--gris-clair); margin-top: 4px; }
.pj-apercus { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.pj-apercus:empty { display: none; }
.pj-vignette {
  width: 120px; border: 1px solid var(--bord); border-radius: 10px; padding: 8px; position: relative;
  background: var(--surface); text-align: center;
}
.pj-ico { height: 56px; display: flex; align-items: center; justify-content: center; font-size: 34px; }
.pj-ico img { max-width: 100%; max-height: 56px; border-radius: 6px; object-fit: cover; }
.pj-nom { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pj-sz { font-size: 10px; color: var(--gris-clair); }
.pj-x {
  position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--rouge); color: #fff; font-size: 12px; display: flex; align-items: center;
  justify-content: center; cursor: pointer; box-shadow: var(--ombre);
}
.info-compose { color: var(--vert); font-size: 13px; }
.suppr-draft { cursor: pointer; }

/* En-tete : laisser respirer la recherche */
header .recherche { margin-left: 8px; }
@media (max-width: 700px) {
  .recherche { width: 160px; max-width: 160px; }
  header .moi { display: none; }
}
