/* ===========================================
   INSTAPANEL — Messagerie (client mail embarqué)
   3 volets : dossiers | liste | lecture
   =========================================== */

.mail-app {
  display: grid;
  grid-template-columns: 220px 380px 1fr;
  gap: 0;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  height: calc(100vh - 200px);
  min-height: 460px;
}

/* --- Volet dossiers --- */
.mail-folders {
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow-y: auto;
  padding: 12px 8px;
      height: calc(100vh - 200px);
    min-height: 460px;
}
.mail-folder {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-light);
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.mail-folder:hover { background: var(--border-light); color: var(--text); }
.mail-folder.active { background: var(--primary); color: var(--white); }
.mail-folder .mail-folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-folder .mail-folder-count {
  flex: 0 0 auto;
  min-width: 20px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--primary-dark);
}
.mail-folder.active .mail-folder-count { background: var(--white); color: var(--primary); }
.mail-folder .mail-folder-count.zero { display: none; }

/* --- Volet liste --- */
.mail-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
      height: calc(100vh - 200px);
    min-height: 460px;
}
.mail-search {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.mail-search input {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-family: var(--font-family);
  font-size: 14px;
  outline: none;
}
.mail-search input:focus { border-color: var(--accent-dark); }
.mail-list {
  overflow-y: auto;
  flex: 1;
      height: calc(100vh - 200px);
    min-height: 460px;
}
.mail-item {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  transition: background .12s;
}
.mail-item:hover { background: var(--bg); }
.mail-item.active { background: var(--accent-light); }
.mail-item.unseen { background: #fff; }
.mail-item.unseen .mail-item-from,
.mail-item.unseen .mail-item-subject { font-weight: 700; color: var(--text); }
.mail-item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: baseline;
}
.mail-item-from {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-item-date { flex: 0 0 auto; font-size: 12px; color: var(--text-muted); }
.mail-item-subject {
  font-size: 13.5px;
  color: var(--text);
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-item-snippet {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.mail-item-paper {
  display: inline-block;
  margin-left: 6px;
  color: var(--text-light);
  vertical-align: middle;
}
.mail-loadmore { padding: 12px; text-align: center; }

/* --- Volet lecture --- */
.mail-reading-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.mail-reading-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}
.mail-reading-empty svg { width: 56px; height: 56px; opacity: .35; margin-bottom: 12px; }
.mail-reading-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.mail-reading-subject { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.mail-reading-meta { font-size: 13px; color: var(--text-light); line-height: 1.6; }
.mail-reading-meta b { color: var(--text); font-weight: 600; }
.mail-reading-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.mail-attachments {
  padding: 12px 22px;
  border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: 8px;
}
.mail-attach {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.mail-attach:hover { background: var(--accent-light); }
.mail-body-wrap { flex: 1; overflow: hidden; }
.mail-body-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.mail-body-text { padding: 22px; white-space: pre-wrap; font-size: 14px; color: var(--text); line-height: 1.6; overflow-y: auto; height: 100%; }

/* --- Compose modal --- */
.mail-compose .modal { max-width: 640px; width: 92%; }
.mail-compose textarea.form-textarea { min-height: 220px; font-family: var(--font-family); }

/* --- États de chargement / vide --- */
.mail-empty { padding: 30px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* --- Responsive --- */
@media (max-width: 1100px) {
  .mail-app { grid-template-columns: 180px 300px 1fr; }
}
@media (max-width: 820px) {
  .mail-app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  .mail-folders { display: flex; flex-wrap: wrap; gap: 6px; border-right: 0; border-bottom: 1px solid var(--border); }
  .mail-folder { flex: 0 0 auto; }
  .mail-list-pane { border-right: 0; border-bottom: 1px solid var(--border); max-height: 50vh; }
  .mail-reading-pane { min-height: 50vh; }
}

/* ── P4 : compléments client mail ─────────────────────────────────────────── */

.page-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Bascule Cc / Cci dans la modale de composition */
.mail-cc-toggle {
  float: right;
  background: none;
  border: none;
  color: var(--primary, #3498db);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* Actions du volet lecture : répondre, répondre à tous, transférer */
.mail-reading-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Pièces jointes attachées à un message en cours de rédaction */
.mail-compose-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.mail-compose-attachments:empty {
  margin-top: 0;
}
.mail-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border-light, #e4e7eb);
  border-radius: var(--radius-pill, 999px);
  font-size: 12px;
  background: var(--bg, #fff);
  max-width: 100%;
}
.mail-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}
.mail-chip-size {
  color: var(--text-muted, #8a94a6);
}
.mail-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted, #8a94a6);
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}
.mail-chip-remove:hover {
  color: var(--danger, #e74c3c);
}
.mail-attach-hint {
  font-size: 11px;
  color: var(--text-muted, #8a94a6);
  margin-top: 6px;
}
.mail-attach-hint.over {
  color: var(--danger, #e74c3c);
  font-weight: 600;
}

/* Pièce jointe en cours de téléchargement depuis le volet lecture */
.mail-attach.busy {
  opacity: 0.55;
  pointer-events: none;
}
