/* 🎨 Styles avancés pour les messages */

.messages-main {
  min-height: 100vh;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  padding: 80px 20px 20px;
}

/* ✅ Fix layout (page client) : éviter le conflit avec .messages-container du thème chef
   et garantir une zone de saisie toujours visible (style WhatsApp/Instagram). */
.messages-main .messages-container {
  max-width: 1400px;
  margin: 0 auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 120px);
}

.messages-main .messages-header {
  padding: 18px 24px;
  border-bottom: 1px solid #e9ecef;
  background: #fff;
  flex: 0 0 auto;
}

.messages-main .messages-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.messages-main .conversations-sidebar,
.messages-main .conversation-area,
.messages-main .chat-active {
  min-height: 0;
}

.messages-main .conversation-area {
  height: 100%;
}

.messages-main .conversation-active {
  height: 100%;
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  min-height: 0;
  overflow: hidden;
}

.messages-main .conversations-list {
  flex: 1;
  overflow-y: auto;
}

.messages-main .chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: 24px;
}

.messages-main .message-input-area {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-top: 1px solid #e9ecef;
  position: relative;
  z-index: 2;
}

.messages-main .typing-indicator {
  padding: 10px 16px;
  border-top: 1px solid #f1f3f5;
  background: rgba(255, 255, 255, 0.92);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.messages-main .chat-form {
  align-items: flex-end;
}

.messages-main .chat-form textarea {
  border-radius: 18px;
  background: #f1f3f5;
  border: 1px solid #e9ecef;
  min-height: 44px;
}

.messages-main .chat-form textarea:focus {
  background: #fff;
  border-color: var(--primary);
}

.messages-main .btn-send-message {
  height: 44px;
}

.messages-main .scroll-to-bottom {
  bottom: 92px;
}

@media (max-width: 992px) {
  .messages-main .messages-container {
    height: calc(100vh - 120px);
  }
  .messages-main .messages-layout {
    grid-template-columns: 1fr;
  }
}

.conversations-search input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e9ecef;
  border-radius: 50px;
  font-size: 14px;
  transition: all 0.3s ease;
}

.conversations-search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(255, 138, 0, 0.1);
}

#clear-search {
  display: none;
}

.conversation-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.conversation-preview .last-message {
  font-size: 13px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.unread-badge {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 50px;
  min-width: 20px;
  text-align: center;
}

.conversation-item.active .unread-badge {
  background: #fff;
  color: var(--primary);
}

.chat-form .message-input-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-form .char-count {
  font-size: 12px;
  color: #999;
}

.messages-main .btn-send-message {
  width: auto;
  height: 44px;
  padding: 0 16px;
  gap: 8px;
  font-size: 14px;
  border-radius: 10px;
}

.conversations-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #eee;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 2;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.toolbar-title {
  font-weight: 800;
  color: #2d2d2d;
}

.pill-count {
  background: #fff3cd;
  color: #8a6d3b;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 700;
}

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

.btn-ghost {
  background: #fff;
  border: 1px solid #eee;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-ghost:hover {
  background: #fff6e0;
  border-color: #f1d9a5;
}

.conversations-search {
  display: flex;
  align-items: center;
  gap: 8px;
}

.conversations-search input {
  flex: 1;
}

.scroll-to-bottom {
  position: absolute;
  right: 18px;
  bottom: 110px;
  background: var(--secondary);
  color: #fff;
  border: none;
  border-radius: 999px;
  width: 40px;
  height: 40px;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  z-index: 5;
}

.scroll-to-bottom.show {
  display: flex;
}

/* Indicateur de lecture (read receipts) */
.read-receipt {
  font-size: 12px;
  margin-left: 4px;
  color: #999;
}

.read-receipt.read {
  color: var(--success);
}

/* Statut d'envoi (pending / failed) */
.send-state {
  font-size: 11px;
  margin-left: 6px;
  opacity: 0.85;
}

.send-state.pending {
  color: #888;
}

.send-state.failed {
  color: var(--error);
}

.btn-retry {
  background: transparent;
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: var(--error);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  cursor: pointer;
  margin-left: 6px;
}

.btn-retry:hover {
  border-color: rgba(220, 38, 38, 0.65);
}

/* Bouton supprimer message */
.btn-delete-message {
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  padding: 4px 8px;
  margin-left: 8px;
  opacity: 0;
  transition: all 0.2s ease;
}

.message:hover .btn-delete-message {
  opacity: 1;
}

.btn-delete-message:hover {
  color: var(--error);
}

/* Bouton supprimer conversation */
.btn-delete-conversation {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--error);
  color: white;
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: all 0.2s ease;
}

.conversation-item:hover .btn-delete-conversation {
  opacity: 1;
}

.btn-delete-conversation:hover {
  background: #d32f2f;
  transform: translateY(-50%) scale(1.1);
}

/* Indicateur "en train d'écrire" */
.typing-bubble {
  background: #f0f0f0;
  padding: 12px 16px !important;
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
  animation-delay: 0s;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingDot {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* Message modéré */
.message.moderated .message-bubble {
  background: #fff3cd !important;
  color: #856404;
  font-style: italic;
  border-left: 4px solid #ffc107;
}

.message.moderated .fa-shield-alt {
  margin-right: 8px;
  color: var(--warning);
}

.message-bubble {
  position: relative;
}

.message-bubble .btn-delete-message {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 8px;
}

/* Améliorations responsive */
@media (max-width: 992px) {
  .btn-delete-conversation {
    opacity: 1;
    width: 28px;
    height: 28px;
    font-size: 12px;
  }
  
  .btn-delete-message {
    opacity: 1;
    font-size: 12px;
  }
}

/* Animation slide pour les toasts */
@keyframes slideIn {
  from {
    transform: translateX(400px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

.notification-toast {
  position: fixed;
  top: 80px;
  right: 20px;
  background: white;
  padding: 16px 20px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  min-width: 320px;
  animation: slideIn 0.3s ease;
}

.notification-toast.success {
  border-left: 4px solid var(--success);
}

.notification-toast.error {
  border-left: 4px solid var(--error);
}

.notification-toast.info {
  border-left: 4px solid var(--info);
}
