/* ============================================================
   Page MES MAILS — messagerie triée par l'IA (doc/PLAN_ASSISTANT_IA_V2_PHASE3.md)
   Charte : en-tête h1 16pt --main-bg-color, cartes blanches arrondies, boutons 5px 14px, KPI comme pilotage / impayés
   ============================================================ */
.page_mails {
  --ml-line: #e0e0e0; --ml-muted: #888; --ml-alerte: #e53935; --ml-ok: #43a047; --ml-warn: #ff9800;
  padding: 18px 22px 30px; text-align: left; min-height: calc(100vh - 60px);
}
[v-cloak] { display: none; }
.ml-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.ml-header h1 { margin: 0; font-size: 16pt; color: var(--main-bg-color); text-align: left; }
.ml-header h1 .fa { margin-right: 6px; }
.ml-sub { color: var(--ml-muted); font-size: 8.5pt; margin-top: 2px; }
.ml-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page_mails .ml-btn { padding: 5px 14px; border: 1px solid #ccc; border-radius: 6px; background: #f5f5f5; color: #333; cursor: pointer; font-size: 9pt; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.page_mails .ml-btn-primary { background: var(--main-bg-color); border-color: var(--main-bg-color); color: #fff; }
.page_mails .ml-btn-danger { background: #c62828; border-color: #c62828; color: #fff; }
.page_mails .ml-btn-ia { background: #6a1b9a; border-color: #6a1b9a; color: #fff; }
.page_mails .ml-btn:disabled { opacity: 0.6; cursor: wait; }
.page_mails .ml-btn-sm { padding: 3px 9px; font-size: 8.5pt; }
.ml-bandeau { padding: 8px 12px; border-radius: 6px; font-size: 9pt; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.ml-bandeau-err { background: #fdecea; color: #b71c1c; }
.ml-bandeau-warn { background: #fff3e0; color: #e65100; }
.ml-bandeau-info { background: #e3f2fd; color: #0d47a1; }
.ml-bandeau-ok { background: #e8f5e9; color: #1b5e20; }
.ml-card { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); padding: 14px 18px; }

/* === KPI === */
.ml-kpi-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.ml-kpi { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); padding: 10px 14px; display: flex; align-items: center; gap: 12px; min-width: 150px; cursor: pointer; border: 2px solid transparent; }
.ml-kpi.ml-kpi-actif { border-color: var(--main-bg-color); }
.ml-kpi-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; background: var(--main-bg-color); }
.ml-kpi-icon.ml-ki-alerte { background: var(--ml-alerte); }
.ml-kpi-icon.ml-ki-warn { background: var(--ml-warn); }
.ml-kpi-icon.ml-ki-ok { background: var(--ml-ok); }
.ml-kpi-value { font-size: 18pt; font-weight: 700; line-height: 1; display: block; }
.ml-kpi-label { font-size: 8.5pt; color: var(--ml-muted); }

/* === Filtres === */
.ml-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.ml-toolbar input[type=text], .ml-toolbar select { padding: 5px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 9pt; }
.ml-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.ml-chip { padding: 3px 10px; border-radius: 12px; border: 1px solid #ccc; background: #fff; font-size: 8.5pt; cursor: pointer; }
.ml-chip.ml-chip-actif { background: var(--main-bg-color); color: #fff; border-color: var(--main-bg-color); }
.ml-chip small { opacity: 0.75; margin-left: 3px; }

/* === Liste === */
.ml-layout { display: grid; grid-template-columns: minmax(0, 1fr) 520px; gap: 14px; align-items: start; }
.ml-liste { padding: 0; overflow: hidden; }
.ml-row { display: grid; grid-template-columns: 8px 150px minmax(0, 1fr) 130px 70px; gap: 10px; align-items: center; padding: 9px 14px; border-bottom: 1px solid #f0f0f0; cursor: pointer; font-size: 9pt; }
.ml-row:hover { background: #fafafa; }
.ml-row.ml-row-actif { background: #eef5f4; }
.ml-row.ml-row-nonlu .ml-objet { font-weight: 700; }
.ml-prio { width: 8px; height: 8px; border-radius: 50%; background: #cfd8dc; }
.ml-prio-haute { background: var(--ml-alerte); } .ml-prio-basse { background: #b0bec5; }
.ml-de { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ml-de small { display: block; color: var(--ml-muted); font-size: 8pt; }
.ml-objet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ml-resume { color: var(--ml-muted); font-size: 8.5pt; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ml-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 8pt; color: #fff; background: #607d8b; white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.ml-badge-manuel { outline: 2px solid #ffb300; }
.ml-badge-boite { background: #8e24aa; }
.ml-badge-lecture { background: #90a4ae; }
.ml-date { color: var(--ml-muted); font-size: 8pt; text-align: right; }
.ml-vide { color: var(--ml-muted); text-align: center; padding: 30px; font-size: 10pt; }

/* === Détail === */
.ml-detail { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; }
.ml-detail h2 { font-size: 12pt; margin: 0 0 6px; color: #222; }
.ml-meta { font-size: 8.5pt; color: var(--ml-muted); line-height: 1.5; }
.ml-meta b { color: #333; }
.ml-lien { background: #e8f5e9; border-radius: 6px; padding: 6px 10px; font-size: 8.5pt; margin: 8px 0; }
.ml-lien a { color: var(--main-bg-color); font-weight: 600; text-decoration: none; }
.ml-lien-inconnu { background: #fff8e1; }
.ml-tri { background: #f3e5f5; border-radius: 6px; padding: 8px 10px; font-size: 9pt; margin: 8px 0; }
.ml-tri .ml-tri-moteur { color: var(--ml-muted); font-size: 8pt; }
.ml-corps { white-space: pre-wrap; font-size: 9.5pt; line-height: 1.5; border-top: 1px solid var(--ml-line); padding-top: 10px; margin-top: 8px; max-height: 360px; overflow-y: auto; word-break: break-word; }
.ml-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--ml-line); }
.ml-cat-select { padding: 4px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 9pt; }
.ml-pieces { font-size: 8.5pt; color: #555; margin-top: 4px; }
.ml-pieces .fa { margin-right: 4px; }
.ml-historique { font-size: 8pt; color: var(--ml-muted); margin-top: 8px; }

/* === Connexion de la boîte === */
.ml-form { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 8px 12px; align-items: center; max-width: 640px; }
.ml-form label { font-weight: 600; font-size: 9pt; width: auto; margin: 0; }
.ml-form input, .ml-form select { padding: 5px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 9pt; width: 100%; box-sizing: border-box; }
.ml-form-titre { grid-column: 1 / -1; font-weight: 600; color: #555; margin-top: 6px; font-size: 9.5pt; }
.ml-form-pied { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.ml-boite-ligne { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid #f0f0f0; font-size: 9pt; flex-wrap: wrap; }
.ml-boite-ligne .fa { color: var(--main-bg-color); }

/* === Modales === */
.ml-modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 9999; display: flex; align-items: center; justify-content: center; padding: 16px; }
.ml-modal { background: #fff; border-radius: 10px; width: 720px; max-width: 100%; max-height: 92vh; overflow-y: auto; padding: 18px 22px; box-shadow: 0 10px 40px rgba(0,0,0,0.25); text-align: left; }
.ml-modal h3 { margin: 0 0 10px; font-size: 12pt; color: var(--main-bg-color); }
.ml-modal textarea { width: 100%; box-sizing: border-box; min-height: 180px; padding: 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 9.5pt; font-family: inherit; }
.ml-modal-pied { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
.ml-modal .ml-note { font-size: 8.5pt; color: var(--ml-muted); margin-top: 6px; }

/* === Responsive (jamais hors @media) === */
.page_mails .ml-retour { display: none; }
@media (max-width: 1199px) { .ml-layout { grid-template-columns: minmax(0, 1fr) 420px; } }
@media (max-width: 992px) {
  .page_mails { padding: 12px 12px 24px; }
  .ml-layout { grid-template-columns: minmax(0, 1fr); }
  .ml-detail { position: fixed; inset: 0; z-index: 300; max-height: none; border-radius: 0; display: none; overflow-y: auto; }
  body.ml-mobile-panel-open .ml-detail { display: block; }
  body.ml-mobile-panel-open .ml-liste, body.ml-mobile-panel-open .ml-kpi-row, body.ml-mobile-panel-open .ml-toolbar, body.ml-mobile-panel-open .ml-header, body.ml-mobile-panel-open .ml-connexion { display: none; }
  .page_mails .ml-retour { display: inline-flex; margin-bottom: 8px; background: var(--main-bg-color); color: #fff; border-color: var(--main-bg-color); }
  .ml-row { grid-template-columns: 8px minmax(0, 1fr) auto; grid-template-areas: "p d i" "p o o"; row-gap: 2px; align-items: start; }
  .ml-row > .ml-prio { grid-area: p; margin-top: 5px; } .ml-row > .ml-de { grid-area: d; } .ml-row > .ml-date { grid-area: i; } .ml-row > div:nth-child(3) { grid-area: o; min-width: 0; }
  .ml-row .ml-de small span { display: none; }
  .ml-row .ml-resume, .ml-row .ml-col-cat { display: none; }
  .ml-form { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
  .ml-header h1 { font-size: 13pt; }
  .ml-kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .ml-kpi { min-width: 0; padding: 4px 6px; gap: 4px; border-radius: 6px; }
  .ml-kpi-icon { width: 22px; height: 22px; border-radius: 5px; font-size: 10px; }
  .ml-kpi-value { font-size: 10pt; } .ml-kpi-label { font-size: 6.5pt; }
  .ml-modal { padding: 12px 14px; }
}

/* ===== Rangement par dossiers et réponses préparées (phase 3b) ===== */
.page_mails .ml-ki-dossier { background: #6d4c41; }
.page_mails .ml-ico-rangement { color: #8d6e63; } .page_mails .ml-ico-rangement.ml-conf-haute { color: #5d4037; } .page_mails .ml-ico-rangement.ml-conf-basse { color: #bcaaa4; }
.page_mails .ml-ico-range { color: #2e7d32; } .page_mails .ml-ico-prep { color: #6a1b9a; }
.page_mails .ml-rangement { margin: 8px 0; padding: 8px 10px; border: 1px solid #d7ccc8; border-left: 4px solid #8d6e63; border-radius: 6px; background: #fbf7f5; font-size: 9.5pt; text-align: left; }
.page_mails .ml-rangement-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.page_mails .ml-rangement .ml-cat-select { max-width: 260px; }
.page_mails .ml-boite-profil { font-size: 9pt; }
.page_mails .ml-profil-resume { font-size: 9.5pt; line-height: 1.45; margin: 8px 0; }
.page_mails .ml-profil-dossier { padding: 6px 0; border-top: 1px solid #eee; font-size: 9.5pt; text-align: left; }
.page_mails .ml-note-prep { background: #f3e5f5; border-color: #ce93d8; }
.page_mails .ml-signature { margin-top: 8px; text-align: left; }
.page_mails .ml-signature pre { font: inherit; font-size: 9pt; white-space: pre-wrap; background: #f8f9fa; border: 1px dashed #ccc; border-radius: 6px; padding: 6px 8px; margin: 4px 0 0; max-height: 120px; overflow: auto; }

/* ===== Liste : ligne d'état discrète (boîte, réponse, dossier, étiquettes, copies) ===== */
.page_mails .ml-row { border-left: 3px solid transparent; }
.page_mails .ml-meta-ligne { display: flex; flex-wrap: wrap; gap: 3px 8px; margin-top: 3px; font-size: 7.5pt; color: #8a8a8a; line-height: 1.5; }
.page_mails .ml-meta-detail { font-size: 8.5pt; margin-top: 4px; }
.page_mails .ml-m-boite { font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.page_mails .ml-m-point { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.page_mails .ml-m-rep-ok { color: #2e7d32; } .page_mails .ml-m-rep-todo { color: #e65100; font-weight: 600; }
.page_mails .ml-m-dossier .fa { color: #a1887f; }
.page_mails .ml-m-tag { background: #eef1f5; border: 1px solid #dde3ea; color: #546e7a; border-radius: 8px; padding: 0 6px; }
.page_mails .ml-m-aussi { color: #6a1b9a; }
.page_mails .ml-m-traite-ok { color: #2e7d32; }
.page_mails .ml-aussi { margin: 6px 0; padding: 5px 8px; background: #f3e5f5; border-radius: 6px; font-size: 9pt; text-align: left; }
.page_mails .ml-rangement-attente { color: #8a8a8a; border-left-color: #d7ccc8; }
.page_mails .ml-ki-repondre { background: #ef6c00; }
.page_mails .ml-liste .ml-badge { font-size: 7.5pt; padding: 1px 7px; }

/* ===== Menu du clic droit et vue agrandie (double-clic) ===== */
.page_mails .ml-ctx { position: fixed; z-index: 10040; background: #fff; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); padding: 6px 0; min-width: 230px; max-width: 340px; font-size: 9.5pt; text-align: left; animation: navDropdownFadeIn 0.12s ease; }
.page_mails .ml-ctx a { display: flex; align-items: center; gap: 8px; padding: 7px 14px; color: #333; cursor: pointer; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page_mails .ml-ctx a:hover { background: #f1f5f4; }
.page_mails .ml-ctx a .fa { width: 16px; text-align: center; color: #78909c; }
.page_mails .ml-ctx-titre { padding: 4px 14px 6px; font-size: 8.5pt; font-weight: 600; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-bottom: 1px solid #eee; margin-bottom: 4px; }
.page_mails .ml-ctx-sep { height: 1px; background: #eee; margin: 4px 0; }
.page_mails .ml-ctx-info { padding: 6px 14px; font-size: 8.5pt; color: #999; }
.page_mails .ml-ctx-chevron { margin-left: auto; font-size: 8pt; }
.page_mails .ml-ctx-dossiers { max-height: 240px; overflow-y: auto; border-top: 1px solid #f0f0f0; border-bottom: 1px solid #f0f0f0; background: #fafafa; }
.page_mails .ml-ctx-dossiers a { padding: 5px 14px 5px 38px; font-size: 9pt; }
.page_mails .ml-ctx-filtre { width: calc(100% - 24px); margin: 6px 12px; padding: 5px 8px; border: 1px solid #ddd; border-radius: 6px; font-size: 9pt; box-sizing: border-box; }
.page_mails .ml-modal.ml-modal-grand { width: min(1100px, 96vw); max-width: 96vw; max-height: 92vh; display: flex; flex-direction: column; }
.page_mails .ml-grand { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.page_mails .ml-grand-tete { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.page_mails .ml-grand-tete h3 { margin: 0 0 6px; font-size: 14pt; text-align: left; }
.page_mails .ml-grand-corps { flex: 1; min-height: 160px; overflow-y: auto; margin-top: 10px; padding: 12px 14px; background: #fcfcfc; border: 1px solid #eee; border-radius: 8px; white-space: pre-wrap; word-break: break-word; font-size: 10.5pt; line-height: 1.55; text-align: left; }
.page_mails .ml-m-coche { color: #2e7d32; }
@media (max-width: 768px) { .page_mails .ml-modal.ml-modal-grand { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; } }

/* ===== Mail affiché en HTML (cadre isolé, comme Outlook) ===== */
.page_mails .ml-corps.ml-corps-html, .page_mails .ml-grand-corps.ml-corps-html { padding: 0; white-space: normal; background: #fff; }
.page_mails .ml-corps.ml-corps-html { max-height: 60vh; }
.page_mails .ml-mail-html { display: block; width: 100%; height: 300px; border: 0; background: #fff; }
.page_mails .ml-grand-outils { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 8px; font-size: 8.5pt; }
.page_mails .ml-bascule { display: inline-flex; border: 1px solid #ddd; border-radius: 6px; overflow: hidden; }
.page_mails .ml-bascule a { padding: 3px 10px; cursor: pointer; color: #666; text-decoration: none; }
.page_mails .ml-bascule a.ml-bascule-actif { background: var(--main-bg-color); color: #fff; }
.page_mails .ml-images-bloquees { color: #b26a00; } .page_mails .ml-images-bloquees a { cursor: pointer; text-decoration: underline; margin-left: 4px; }
