/* ============================================================
   Messagerie (chat) client <-> admin — MadaPayExchange
   Icône flottante + fenêtre de discussion (côté client), et styles
   du panneau "Messages" côté admin. Fichier séparé pour ne toucher
   à aucun style existant dans style.css.
   ============================================================ */

#mp-chat-bubble {
  /* Même gabarit que les icônes de contact du pied de page (ex. Facebook,
     30x30) pour rester discret et cohérent avec le reste du site, au lieu
     d'un gros bouton disproportionné. */
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px) + 14px);
  bottom: max(18px, env(safe-area-inset-bottom, 0px) + 14px);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #00d97e, #00b869);
  border: none;
  box-shadow: 0 6px 16px rgba(0, 217, 126, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 99998;
  transition: transform .15s ease;
}
#mp-chat-bubble:hover { transform: scale(1.08); }
#mp-chat-bubble svg { width: 16px; height: 16px; color: #06110c; }

#mp-chat-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 999px;
  background: #ff5c5c;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  font-family: 'Inter', system-ui, sans-serif;
  display: none;
  align-items: center;
  justify-content: center;
  border: 1.5px solid #0b0f14;
}

#mp-chat-window {
  position: fixed;
  right: max(18px, env(safe-area-inset-right, 0px) + 14px);
  bottom: max(62px, env(safe-area-inset-bottom, 0px) + 56px);
  width: 340px;
  max-width: calc(100vw - 24px);
  height: 460px;
  max-height: calc(100vh - 130px);
  background: #121a24;
  border: 1px solid #1e2833;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 99999;
  font-family: 'Inter', system-ui, sans-serif;
}
#mp-chat-window.mp-open { display: flex; }
#mp-chat-window.mp-minimized { height: auto; }
#mp-chat-window.mp-minimized #mp-chat-body,
#mp-chat-window.mp-minimized #mp-chat-input-row,
#mp-chat-window.mp-minimized #mp-chat-hint { display: none; }

#mp-chat-header {
  background: #0f151d;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1e2833;
  cursor: pointer;
  flex-shrink: 0;
}
#mp-chat-header-title { display: flex; flex-direction: column; gap: 2px; }
#mp-chat-header-title .mp-t1 {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: #e7ecef;
}
#mp-chat-header-title .mp-t2 {
  font-size: 11px;
  color: #00d97e;
  display: flex;
  align-items: center;
  gap: 5px;
}
#mp-chat-header-title .mp-t2 .mp-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #00d97e;
  display: inline-block;
  box-shadow: 0 0 0 0 rgba(0,217,126,.6);
  animation: mp-pulse 1.6s infinite;
}
@keyframes mp-pulse {
  0% { box-shadow: 0 0 0 0 rgba(0,217,126,.5); }
  70% { box-shadow: 0 0 0 6px rgba(0,217,126,0); }
  100% { box-shadow: 0 0 0 0 rgba(0,217,126,0); }
}
#mp-chat-header-actions { display: flex; gap: 8px; }
#mp-chat-header-actions button {
  background: transparent;
  border: none;
  color: #7c8894;
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 6px;
}
#mp-chat-header-actions button:hover { color: #e7ecef; background: #1e2833; }
#mp-chat-header-actions svg { width: 16px; height: 16px; }

#mp-chat-hint {
  font-size: 11px;
  color: #7c8894;
  padding: 8px 14px;
  border-bottom: 1px solid #1e2833;
  flex-shrink: 0;
}

#mp-chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mp-msg { max-width: 78%; display: flex; flex-direction: column; gap: 4px; }
.mp-msg.mp-from-client { align-self: flex-end; align-items: flex-end; }
.mp-msg.mp-from-admin { align-self: flex-start; align-items: flex-start; }

/* Ligne contenant la bulle + le bouton menu (⋮), pour pouvoir placer le
   bouton du côté "extérieur" de la bulle selon l'expéditeur. */
.mp-msg-row { display: flex; align-items: flex-end; gap: 2px; max-width: 100%; }
.mp-msg.mp-from-client .mp-msg-row { flex-direction: row-reverse; }
.mp-msg.mp-from-admin .mp-msg-row { flex-direction: row; }

.mp-bubble {
  padding: 8px 11px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  color: #e7ecef;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}
.mp-from-client .mp-bubble { background: #00693f; border-bottom-right-radius: 3px; }
.mp-from-admin .mp-bubble { background: #1c2733; border-bottom-left-radius: 3px; }
.mp-bubble-deleted { font-style: italic; opacity: .7; }

.mp-bubble img {
  max-width: 100%;
  border-radius: 8px;
  display: block;
  margin-top: 4px;
  cursor: pointer;
}

.mp-msg-time { font-size: 10px; color: #7c8894; padding: 0 2px; }
.mp-edited-tag { font-size: 10px; color: rgba(231,236,239,0.6); margin-left: 5px; font-style: italic; }
.mp-deleted-label { font-size: 12px; color: #9aa4ae; }

/* Citation du message auquel on répond, affichée en haut de la bulle. */
.mp-reply-quote {
  display: block;
  border-left: 2px solid rgba(231,236,239,0.5);
  padding: 3px 7px;
  margin-bottom: 5px;
  border-radius: 4px;
  background: rgba(0,0,0,0.18);
  font-size: 11.5px;
  line-height: 1.35;
  color: rgba(231,236,239,0.75);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mp-reply-quote .mp-reply-who { display: block; font-weight: 700; color: #00d97e; font-size: 11px; }

/* Bouton ⋮ et menu déroulant (répondre / modifier / supprimer) */
.mp-msg-menu-btn {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #7c8894;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: .75;
}
.mp-msg-menu-btn:hover { background: #1e2833; color: #e7ecef; opacity: 1; }
.mp-msg-menu-btn svg { width: 14px; height: 14px; }

.mp-msg { position: relative; }
.mp-msg-menu {
  position: absolute;
  top: 22px;
  z-index: 5;
  display: none;
  flex-direction: column;
  min-width: 190px;
  background: #1c2733;
  border: 1px solid #2a3946;
  border-radius: 10px;
  box-shadow: 0 10px 26px rgba(0,0,0,0.4);
  overflow: hidden;
  padding: 4px;
}
.mp-msg.mp-from-client .mp-msg-menu { right: 0; }
.mp-msg.mp-from-admin .mp-msg-menu { left: 0; }
.mp-msg-menu.mp-show { display: flex; }
.mp-msg-menu button {
  background: transparent;
  border: none;
  color: #e7ecef;
  text-align: left;
  font-size: 12.5px;
  font-family: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.mp-msg-menu button:hover { background: #263340; }
.mp-msg-menu button.mp-menu-danger { color: #ff5c5c; }
.mp-msg-menu button.mp-menu-danger:hover { background: rgba(255,92,92,0.12); }

/* Bannière au-dessus du champ de saisie : "Réponse à ..." ou "Modifier le
   message", avec un bouton pour annuler. */
#mp-chat-composer-banner { display: none; padding: 0 10px; }
#mp-chat-composer-banner.mp-show { display: block; }
.mp-composer-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #0f151d;
  border: 1px solid #1e2833;
  border-left: 3px solid #00d97e;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
}
.mp-edit-banner { border-left-color: #ffb020; }
.mp-banner-text { display: flex; flex-direction: column; gap: 1px; overflow: hidden; }
.mp-banner-text strong { font-size: 11.5px; color: #e7ecef; }
.mp-banner-text span {
  font-size: 11.5px;
  color: #7c8894;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}
.mp-composer-banner button {
  background: transparent;
  border: none;
  color: #7c8894;
  cursor: pointer;
  display: flex;
  padding: 3px;
  flex-shrink: 0;
}
.mp-composer-banner button:hover { color: #e7ecef; }
.mp-composer-banner button svg { width: 13px; height: 13px; }

/* Indicateur "... est en train d'écrire" */
#mp-chat-typing {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 0 14px 6px;
  font-size: 11px;
  color: #7c8894;
  flex-shrink: 0;
}
#mp-chat-typing.mp-show { display: flex; }
.mp-typing-dots { display: inline-flex; gap: 3px; }
.mp-typing-dots i {
  width: 4px; height: 4px; border-radius: 50%;
  background: #00d97e;
  display: inline-block;
  animation: mp-typing-bounce 1.2s infinite ease-in-out;
}
.mp-typing-dots i:nth-child(2) { animation-delay: .15s; }
.mp-typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes mp-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

#mp-chat-empty {
  margin: auto;
  text-align: center;
  color: #7c8894;
  font-size: 12px;
  padding: 20px;
}

#mp-chat-login-notice {
  margin: auto;
  text-align: center;
  padding: 24px 18px;
  color: #7c8894;
  font-size: 13px;
}
#mp-chat-login-notice a.btn {
  display: inline-block;
  margin-top: 12px;
}

#mp-chat-input-row {
  border-top: 1px solid #1e2833;
  padding: 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}
#mp-chat-input {
  flex: 1;
  resize: none;
  max-height: 80px;
  min-height: 36px;
  background: #0f151d;
  border: 1px solid #1e2833;
  border-radius: 10px;
  color: #e7ecef;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
#mp-chat-input:focus { outline: none; border-color: #00d97e; }

#mp-chat-attach-btn, #mp-chat-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#mp-chat-attach-btn {
  background: #1c2733;
  color: #7c8894;
}
#mp-chat-attach-btn:hover { color: #e7ecef; }
#mp-chat-send-btn {
  background: #00d97e;
  color: #06110c;
}
#mp-chat-send-btn:hover { background: #00c473; }
#mp-chat-send-btn:disabled { opacity: .5; cursor: default; }
#mp-chat-attach-btn svg, #mp-chat-send-btn svg { width: 17px; height: 17px; }

#mp-chat-preview {
  padding: 0 10px 8px;
  display: none;
}
#mp-chat-preview.mp-show { display: flex; align-items: center; gap: 8px; }
#mp-chat-preview img {
  width: 44px; height: 44px; object-fit: cover; border-radius: 8px;
  border: 1px solid #1e2833;
}
#mp-chat-preview button {
  background: transparent; border: none; color: #ff5c5c; cursor: pointer; font-size: 12px;
}

@media (max-width: 480px) {
  #mp-chat-window {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: max(58px, env(safe-area-inset-bottom, 0px) + 52px);
  }
  #mp-chat-bubble {
    right: max(14px, env(safe-area-inset-right, 0px) + 10px);
    bottom: max(14px, env(safe-area-inset-bottom, 0px) + 10px);
  }
}

/* Variantes génériques (classe, pas id) des mêmes éléments — réutilisées
   côté panneau admin, qui a ses propres identifiants DOM. */
.mp-composer-banner-wrap { display: none; padding: 0 10px; }
.mp-composer-banner-wrap.mp-show { display: block; }
.mp-typing-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 14px 8px;
  font-size: 11px;
  color: #7c8894;
  flex-shrink: 0;
}
.mp-typing-indicator.mp-show { display: flex; }

/* ============================================================
   Panneau admin — onglet "Messages"
   ============================================================ */

.chat-admin-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  height: 560px;
  max-height: 70vh;
}
@media (max-width: 760px) {
  .chat-admin-layout { grid-template-columns: 1fr; height: auto; }
}

.chat-conv-list {
  background: #0f151d;
  border: 1px solid #1e2833;
  border-radius: 14px;
  overflow-y: auto;
  padding: 6px;
}
.chat-conv-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 2px;
}
.chat-conv-item:hover { background: #1c2733; }
.chat-conv-item.active { background: #16321f; border: 1px solid #00d97e; }
.chat-conv-top { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.chat-conv-name { font-weight: 600; font-size: 13px; color: #e7ecef; }
.chat-conv-preview {
  font-size: 12px;
  color: #7c8894;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-conv-unread {
  background: #ff5c5c;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
}

.chat-admin-panel {
  background: #0f151d;
  border: 1px solid #1e2833;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-admin-panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid #1e2833;
  font-weight: 700;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
}
.chat-admin-panel-header .hint { font-weight: 400; }
.chat-admin-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-admin-input-row {
  border-top: 1px solid #1e2833;
  padding: 10px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.chat-admin-input-row textarea {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 100px;
  background: #121a24;
  border: 1px solid #1e2833;
  border-radius: 10px;
  color: #e7ecef;
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13px;
}
.chat-admin-input-row textarea:focus { outline: none; border-color: #00d97e; }
.chat-admin-input-row textarea {
  transition: border-color .15s ease;
  line-height: 1.4;
}
/* Les boutons héritent de .btn (width:100%, margin-top:24px), ce qui
   déformait la ligne de saisie ; on neutralise ça ici pour que le champ
   de texte, le trombone et "Envoyer" s'alignent proprement. */
.chat-admin-input-row .btn {
  width: auto;
  margin-top: 0;
  flex-shrink: 0;
}
.chat-admin-input-row #chatAdminAttachBtn {
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-admin-input-row #chatAdminAttachBtn svg { width: 16px; height: 16px; }
.chat-admin-input-row #chatAdminSendBtn {
  display: flex;
  align-items: center;
  gap: 6px;
}
.chat-admin-input-row #chatAdminSendBtn svg { width: 15px; height: 15px; }

/* ============================================================
   Visionneuse d'image plein écran (lightbox) — widget client.
   Permet de bien voir une image déjà envoyée/reçue dans le chat,
   puis de revenir directement à la conversation en la fermant.
   Même esprit visuel que la modale d'images du panneau admin.
   ============================================================ */

#mp-img-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: rgba(0, 0, 0, 0.88);
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: 24px;
}
#mp-img-modal.mp-open { display: flex; }
#mp-img-modal img {
  max-width: 92vw;
  max-height: 82vh;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  cursor: default;
}
#mp-img-modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}
#mp-img-modal-hint {
  position: absolute;
  bottom: 18px;
  left: 0;
  right: 0;
  text-align: center;
  color: #9aa4ae;
  font-size: 12px;
  font-family: 'Inter', system-ui, sans-serif;
}
