/* =====================================================================
 * Page Mailing (?page=mailing) — préfixe mj-
 * Charte du projet : header h1 16pt, KPI cartes blanches + icône 42px,
 * thead #f8f9fa sticky (cf. css/prospection.css, css/gestion-impayes.css)
 * ===================================================================== */

.page_mailing {
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 10px 40px 10px;
  /* main.css impose « html { text-align: center } » a toute la page : sans ce
     retour a gauche, titres de section, libelles de formulaire et textes du
     panneau Mailjet se centrent. Les cellules numeriques gardent leur
     centrage explicite (.mj-td-num, .mj-th-check). */
  text-align: left;
}

/* main.css impose aussi « table { margin-left: auto; margin-right: auto } » :
   une table plus etroite que son conteneur se centrerait. */
.page_mailing table { margin-left: 0; margin-right: 0; }

/* Boutons : charte du projet (tf-btn / imp-btn / prospection) */
.page_mailing button,
.mj-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f5f5f5;
  font-size: 9pt;
  cursor: pointer;
}
.page_mailing button:hover,
.mj-btn:hover { background: #ebebeb; }
.page_mailing button:disabled,
.mj-btn:disabled { opacity: .5; cursor: not-allowed; }

/* PIEGE DE SPECIFICITE (meme que .ho-btn-* de css/outils.css) : la regle de
   base « .page_mailing button » (0-1-1) bat « .mj-btn-primary » (0-1-0) et
   ecrasait la couleur de fond -> texte blanc sur gris clair, illisible.
   Les variantes sont donc scopees pour reprendre l avantage. */
.page_mailing .mj-btn-primary,
.mj-btn-primary {
  background: var(--main-bg-color);
  border-color: var(--main-bg-color);
  color: #fff;
}
.page_mailing .mj-btn-primary:hover,
.mj-btn-primary:hover { filter: brightness(1.1); background: var(--main-bg-color); }

.page_mailing .mj-btn-export,
.mj-btn-export {
  background: #1f7a4d;
  border-color: #1f7a4d;
  color: #fff;
}
.page_mailing .mj-btn-export:hover,
.mj-btn-export:hover { background: #196340; }

.page_mailing .mj-btn-mini,
.mj-btn-mini { padding: 2px 8px; font-size: 8.5pt; }

/* ---------------- Header ---------------- */
.mj-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 14px 0 10px 0;
}
.mj-header h1 {
  margin: 0;
  font-size: 16pt;
  color: var(--main-bg-color);
  display: flex;
  align-items: center;
  gap: 10px;
}
.mj-sub { font-size: 9pt; color: #6B7280; margin-top: 4px; }
.mj-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.mj-check { display: inline-flex; align-items: center; gap: 6px; font-size: 9pt; cursor: pointer; }
.mj-check-strict { color: #555; }

/* ---------------- Bandeau « pas d'envoi » ---------------- */
.mj-notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #E8F0FB;
  border: 1px solid #C3D4EE;
  border-left: 4px solid #2C4270;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 9pt;
  color: #2C4270;
  margin-bottom: 14px;
}

/* ---------------- KPI ---------------- */
.mj-kpi-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.mj-kpi-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 16px;
  min-width: 170px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.mj-kpi-clic { cursor: pointer; }
.mj-kpi-clic:hover { box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.mj-kpi-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
  background: var(--main-bg-color);
  flex: 0 0 auto;
}
.mj-ki-tiers { background: #2C4270; }
.mj-ki-mail  { background: #1f7a4d; }
.mj-ki-multi { background: #B8860B; }
.mj-ki-alert { background: #C0392B; }
.mj-ki-ok    { background: #2E7D52; }
.mj-ki-bad   { background: #8E1B1B; }
.mj-kpi-content { display: flex; flex-direction: column; }
.mj-kpi-value { font-size: 18pt; font-weight: 600; line-height: 1.1; }
.mj-kpi-label { font-size: 8.5pt; color: #6B7280; }

/* ---------------- Toolbar ---------------- */
.mj-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.mj-toolbar-left,
.mj-toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.mj-search {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  padding: 4px 10px;
}
.mj-search .fa { color: #9ca3af; font-size: 9pt; }
.mj-search input {
  border: none;
  outline: none;
  font-size: 9pt;
  min-width: 240px;
  background: transparent;
}
.mj-count { font-size: 8.5pt; color: #6B7280; }

.mj-chips { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.mj-chip {
  padding: 3px 10px !important;
  font-size: 8.5pt !important;
  border-radius: 999px !important;
  background: #fff !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mj-chip-on {
  background: var(--main-bg-color) !important;
  border-color: var(--main-bg-color) !important;
  color: #fff !important;
}
.mj-chip-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------------- Tableau ---------------- */
.mj-table-wrap {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: auto;
}
.mj-table { width: 100%; border-collapse: collapse; font-size: 9pt; }

/* main.css impose « table { text-align:center } » : on repasse à gauche */
.mj-table td { text-align: left; padding: 7px 10px; border-top: 1px solid #f0f0f0; }

/* main.css impose « thead th, thead th a { background: var(--main-bg-color) } »
   -> surcharger le th ET le a, sinon l'en-tête devient illisible */
.mj-table thead th,
.mj-table thead th a {
  background: #f8f9fa;
  color: #374151;
}
.mj-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  padding: 9px 10px;
  font-weight: 600;
  font-size: 8.5pt;
  border-bottom: 1px solid #e5e7eb;
  white-space: nowrap;
}
.mj-table thead th a.mj-sort { text-decoration: none; }
.mj-table thead th a.mj-sort:hover { text-decoration: underline; }

.mj-table tbody tr:nth-child(even) { background: #fcfcfd; }
.mj-table tbody tr:hover { background: #f3f6fb; }

.mj-th-check, .mj-td-check { width: 34px; text-align: center !important; }
.mj-td-num { text-align: center !important; }
.mj-td-strong { font-weight: 600; }
.mj-td-email { font-family: monospace; font-size: 8.5pt; }
.mj-td-modele, .mj-td-tags { color: #6B7280; font-size: 8.5pt; }
.mj-td-motif { color: #8E1B1B; font-size: 8.5pt; }

.mj-alias, .mj-poste {
  display: block;
  font-size: 7.5pt;
  color: #9ca3af;
  font-weight: 400;
}
.mj-auto { color: #B8860B; margin-left: 4px; }
.mj-bad-flag { color: #C0392B; margin-left: 4px; }
.mj-row-bad { background: #FDF0F0 !important; }

.mj-empty { text-align: center !important; color: #9ca3af; padding: 24px !important; }

.mj-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 7.5pt;
  font-weight: 600;
  white-space: nowrap;
}
.mj-role {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 7.5pt;
  font-weight: 600;
  white-space: nowrap;
}
.mj-role-contact_facturation { background: #EDE7F6; color: #5E35B1; }
.mj-role-tiers_principal     { background: #E0F2F1; color: #00695C; }

/* ---------------- Panneau anomalies ---------------- */
.mj-panel {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  margin-bottom: 14px;
  overflow: hidden;
}
.mj-panel-anomalies { border-left: 4px solid #C0392B; }
.mj-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 9.5pt;
  color: #8E1B1B;
  background: #FDF0F0;
  border-bottom: 1px solid #f0d8d8;
}
.mj-panel-title .mj-btn { margin-left: auto; }

/* ---------------- Responsive (992 / 768, breakpoints du projet) ---------------- */
@media screen and (max-width: 992px) {
  .mj-kpi-card { min-width: 120px; padding: 8px 10px; gap: 8px; }
  .mj-kpi-icon { width: 32px; height: 32px; border-radius: 8px; font-size: 14px; }
  .mj-kpi-value { font-size: 14pt; }
  .mj-kpi-label { font-size: 7.5pt; }
  .mj-search input { min-width: 140px; }
}

@media screen and (max-width: 768px) {
  .mj-hide-mobile { display: none; }
  .mj-kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .mj-kpi-card {
    min-width: 0;
    padding: 4px 6px;
    gap: 4px;
    border-radius: 6px;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
  }
  .mj-kpi-icon { width: 22px; height: 22px; border-radius: 5px; font-size: 10px; }
  .mj-kpi-value { font-size: 10pt; }
  .mj-kpi-label { font-size: 6.5pt; }
  .mj-header h1 { font-size: 13pt; }
  .mj-toolbar-left, .mj-toolbar-right { width: 100%; }
  .mj-search { width: 100%; }
  .mj-search input { min-width: 0; flex: 1; }
  /* « Afficher plus » : ~150 adresses sans pagination sur mobile (comportement
     PC inchangé, la liste complète reste rendue pour la sélection/l'export). */
  .mj-showmore { display: flex; justify-content: center; padding: 12px; }
  .mj-showmore .mj-btn { width: 100%; justify-content: center; }
}

/* ---------------- Impression ---------------- */
@media print {
  .mj-header-actions, .mj-toolbar, .mj-notice { display: none; }
  .mj-table-wrap { border: none; }
  .mj-table thead th { position: static; }
}

/* ---------------- Section Mailjet (listes + campagne) ---------------- */
.mj-panel-title-mj {
  background: #F3F6FB;
  color: #2C4270;
  border-bottom: 1px solid #dde6f3;
  cursor: pointer;
}
.mj-panel-title-mj:hover { background: #E8F0FB; }
.mj-panel-hint { margin-left: auto; font-weight: 400; font-size: 8pt; color: #6B7280; }
.mj-panel-body { padding: 14px; }

.mj-sec-title {
  font-weight: 600;
  font-size: 9.5pt;
  color: #2C4270;
  margin: 16px 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid #eef1f5;
}
.mj-sec-title:first-child { margin-top: 0; }
.mj-sec-note { font-weight: 400; font-size: 8pt; color: #6B7280; margin-left: 8px; }

.mj-warn {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #FFF4E0;
  border: 1px solid #f0dcb4;
  border-left: 4px solid #B8860B;
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 9pt;
  color: #7a5c08;
  margin-bottom: 12px;
}

.mj-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}
.mj-hint { font-size: 8.5pt; color: #6B7280; }
.mj-hint-strong { color: #8E1B1B; font-weight: 600; margin-left: 8px; }

/* Champs : cadrage commun, la charte du projet n'impose rien de special ici */
.mj-panel-body input[type="text"],
.mj-panel-body select,
.mj-panel-body textarea {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 9pt;
  font-family: inherit;
  background: #fff;
}
.mj-panel-body input[type="text"] { min-width: 260px; }
.mj-panel-body textarea { width: 100%; resize: vertical; }

.mj-table-listes { max-width: 720px; }
.mj-rename { display: inline-flex; align-items: center; gap: 4px; }

/* Formulaire de campagne : etiquette figee / champ, comme .adm-form-table */
.mj-form {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 8px 12px;
  align-items: start;
  max-width: 900px;
}
.mj-form > label {
  font-size: 9pt;
  color: #374151;
  padding-top: 6px;
  font-weight: 600;
}
.mj-contenu { display: flex; flex-direction: column; gap: 8px; }
.mj-upload { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------- Modale de confirmation ---------------- */
/* z-index sous la modale « Mise a jour disponible » (2147483000, regle projet) */
.mj-modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.mj-modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
  width: min(560px, 92vw);
  padding: 18px 20px;
}
.mj-modal-title {
  font-size: 11pt;
  font-weight: 600;
  color: var(--main-bg-color);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.mj-modal-lignes { margin: 0 0 16px 0; padding-left: 20px; font-size: 9pt; line-height: 1.6; }
.mj-modal-lignes li { margin-bottom: 3px; }
.mj-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media screen and (max-width: 768px) {
  .mj-form { grid-template-columns: 1fr; }
  .mj-form > label { padding-top: 0; }
  .mj-panel-body input[type="text"] { min-width: 0; width: 100%; }
  .mj-panel-hint { display: none; }
}

/* Nom du tiers : lien vers sa fiche Dolibarr (demande utilisateur).
   main.css colore les <a> globalement -> on impose la couleur du tableau. */
.mj-table a.mj-link {
  color: #1d4ed8;
  text-decoration: none;
  font-weight: 600;
}
.mj-table a.mj-link:hover { text-decoration: underline; }
.mj-table a.mj-link:visited { color: #1d4ed8; }

/* ---------------- Liens du fichier HTML importe ----------------
   Une campagne Mailjet n'accepte PAS de piece jointe : les fichiers joints
   passent par des liens dans le message. On les rend verifiables avant envoi. */
.mj-upload-zone { display: flex; flex-direction: column; gap: 8px; }

.mj-liens {
  background: #F8FAFC;
  border: 1px solid #e5e7eb;
  border-left: 4px solid #5E35B1;
  border-radius: 6px;
  padding: 8px 12px;
}
.mj-liens-titre {
  font-size: 8.5pt;
  font-weight: 600;
  color: #5E35B1;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}
.mj-liens-liste { margin: 0; padding-left: 18px; font-size: 8.5pt; line-height: 1.7; }
.mj-liens-liste li { margin-bottom: 2px; }
.mj-lien-lib { font-weight: 600; margin-right: 8px; }
.mj-liens .mj-link {
  color: #1d4ed8;
  text-decoration: none;
  font-family: monospace;
  font-size: 8pt;
  word-break: break-all;
}
.mj-liens .mj-link:hover { text-decoration: underline; }
.mj-lien-suspect { color: #8E1B1B; }
.mj-lien-flag { color: #C0392B; margin-left: 6px; }

/* ---------------- Modification d un brouillon ---------------- */
.mj-edit-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #FFF4E0;
  border: 1px solid #f0dcb4;
  border-left: 4px solid #B8860B;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 9pt;
  color: #7a5c08;
  margin-bottom: 10px;
}
.mj-edit-bar .mj-btn { margin-left: auto; }
.mj-hint-edit { color: #7a5c08; }

/* Etat d une campagne */
.mj-statut {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 7.5pt;
  font-weight: 600;
  white-space: nowrap;
}
.mj-statut-draft { background: #FFF4E0; color: #7a5c08; }
.mj-statut-sent  { background: #EEF0F2; color: #6B7280; }

/* Une campagne encore en brouillon ressort de la liste */
.mj-row-draft { background: #FFFCF5 !important; }
.mj-td-actions { white-space: nowrap; }
.mj-td-actions .mj-btn { margin-right: 4px; }

.mj-hint-suppr {
  display: block;
  margin-top: 8px;
  padding: 8px 12px;
  background: #F8FAFC;
  border-left: 3px solid #9ca3af;
  border-radius: 4px;
}
.mj-hint-suppr code {
  background: #eef0f2;
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 8pt;
}
