/* ========================================
   6. MESSAGING SECTION
   ======================================== */

/* Main messaging page */
/* ===== MESSAGING SECTION - Style UI Moderne (comme duaTimeCalculator) ===== */
#messaging {
  font-family: Arial, sans-serif;
  background: var(--gradient-light);
  min-height: 100vh;
  padding: 1rem;
  color: var(--primary-color);
}

#messaging .page-header-wrapper {
  max-width: 800px;
  margin: 0 auto 1.25rem;
}

/* Header avec Gradient et Emoji */
.messaging-header {
  text-align: center;
  margin-bottom: 2rem;
  padding: 1.5rem 0;
  background: var(--gradient-primary);
  color: white;
  border-radius: 1rem;
  box-shadow: 0 4px 8px rgba(39, 76, 119, 0.3);
  position: relative;
  overflow: hidden;
}

.messaging-header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="80" cy="40" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="40" cy="80" r="1" fill="rgba(255,255,255,0.1)"/></svg>');
  opacity: 0.3;
}

.messaging-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin: 0;
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.messaging-header h1::before {
  content: "💬";
  font-size: 1.8rem;
}

.messaging-header p {
  margin: 0.5rem 0 0;
  font-size: 1.1rem;
  opacity: 0.9;
  position: relative;
  z-index: 2;
}

/* Container centré */
.messaging-container {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

/* Cartes messaging - Full blue */
.messaging-card {
  background: var(--gradient-primary);
  border: none;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 8px 20px rgba(39, 76, 119, 0.25);
  position: relative;
  display: flex;
  flex-direction: column;
  color: white;
}

.messaging-card-content {
  background: #fff;
  border-radius: 0 0 1rem 1rem;
  min-height: 400px;
  padding: 1.5rem;
}

/* En-têtes des cartes avec titres d'emoji */
.messaging-card-header {
  background: var(--gradient-primary);
  color: white;
  padding: 1rem 1.5rem;
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
}

.messaging-card-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  z-index: 2;
  position: relative;
}

/* Ajout d'emojis spécifiques pour chaque carte */
.messaging-card:nth-child(1) .messaging-card-title::before {
  content: "📨";
  font-size: 1.1rem;
}

.messaging-card:nth-child(2) .messaging-card-title::before {
  content: "📬";
  font-size: 1.1rem;
}

.messaging-actions {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.messaging-action-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.6rem 1rem;
  border-radius: 0.5rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.3s ease, transform 0.3s ease;
  position: relative;
  overflow: hidden;
  min-width: 100px;
  height: 38px;
  font-size: 0.9rem;
  font-weight: 500;
  gap: 0.4rem;
}

/* Boutons d'action messaging avec icônes Feather */

/* Effet de brillance sur hover */
.messaging-action-btn::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left 0.5s;
}

.messaging-action-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.messaging-action-btn:hover::after {
  left: 100%;
}

/* Contenu des cartes optimisé */
.messaging-card-content {
  flex: 1;
  overflow-y: auto;
}

/* Liste des messages optimisée */
.messaging-list {
  list-style-type: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* --- Selection bar --- */
.messaging-selection-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(39, 76, 119, 0.08);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  margin-top: 0.5rem;
  animation: slideDown 0.25s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.messaging-selection-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-color);
  white-space: nowrap;
}

.messaging-selection-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.messaging-selection-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: none;
  border-radius: 0.4rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.messaging-selection-btn:hover {
  transform: translateY(-1px);
}

.messaging-selection-btn svg {
  width: 14px;
  height: 14px;
}

.messaging-selection-btn--read {
  background: var(--gradient-primary);
  color: white;
}

.messaging-selection-btn--delete {
  background: linear-gradient(135deg, #ff4d4d 0%, #ff6b6b 100%);
  color: white;
}

/* Header layout: allow wrapping so all buttons stay visible */
.messaging-card-header {
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* --- Message item redesign --- */
.message-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  background: white;
  border: 1px solid rgba(39, 76, 119, 0.12);
  border-radius: 0.75rem;
  padding: 0;
  cursor: pointer;
  position: relative;
  transition: box-shadow 0.3s ease, border-color 0.3s ease, background 0.3s ease;
}

.message-item:hover {
  box-shadow: 0 4px 12px rgba(39, 76, 119, 0.12);
  border-color: var(--secondary-color);
}

/* Unread = bold, visible */
.message-item:not(.read) .message-title {
  font-weight: 700;
}

/* Read = dimmed */
.message-item.read {
  opacity: 0.65;
  background: rgba(248, 249, 250, 0.8);
}

/* Selected highlight */
.message-item.selected {
  background: rgba(39, 76, 119, 0.06);
  border-color: var(--secondary-color);
}

/* --- Unread dot indicator --- */
.message-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--secondary-color);
  flex-shrink: 0;
  transition: opacity 0.3s ease;
}

.message-item.read .message-unread-dot {
  opacity: 0;
}

/* --- Header row (icon + meta + chevron) --- */
.message-header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  padding: 0.75rem;
}

.message-icon {
  background: var(--gradient-primary);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
}

.message-icon svg {
  width: 16px;
  height: 16px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
}

.message-title {
  font-weight: 500;
  margin: 0;
  color: var(--primary-color);
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.message-date {
  font-size: 0.78rem;
  color: #8b8c89;
  margin: 0;
  white-space: nowrap;
  flex-shrink: 0;
}

/* --- Chevron --- */
.message-chevron {
  flex-shrink: 0;
  color: #8b8c89;
  transition: transform 0.35s ease;
  margin-right: 0.25rem;
}

.message-item.expanded .message-chevron {
  transform: rotate(180deg);
}

/* --- Body (collapsed by default) --- */
.message-body {
  width: 100%;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease, opacity 0.3s ease, padding 0.4s ease;
  opacity: 0;
  padding: 0 1rem;
  border-top: 0 solid transparent;
}

.message-item.expanded .message-body {
  max-height: 500px;
  opacity: 1;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid rgba(39, 76, 119, 0.1);
  overflow-y: auto;
}

.message-body-content {
  font-size: 0.9rem;
  line-height: 1.6;
  color: #495057;
}

.message-body-content p {
  margin: 0 0 0.5rem 0;
}

.message-body-content a {
  color: var(--secondary-color);
  text-decoration: underline;
}

.message-body-content ul, .message-body-content ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.message-body-content code {
  background: rgba(39, 76, 119, 0.1);
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
  font-size: 0.85em;
}

.message-body-content pre {
  background: rgba(39, 76, 119, 0.1);
  padding: 0.75rem;
  border-radius: 0.5rem;
  overflow-x: auto;
}

/* Actions inside the body */
.message-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: flex-end;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(39, 76, 119, 0.08);
  flex-wrap: nowrap;
}

.message-read-btn {
  background: var(--gradient-primary);
  border: none;
  color: white;
  padding: 0.4rem 0.9rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.message-read-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(39, 76, 119, 0.3);
}

.message-delete-btn {
  background: linear-gradient(135deg, #ff4d4d 0%, #ff6b6b 100%);
  border: none;
  color: white;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 0.5rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.message-delete-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(255, 77, 77, 0.3);
}

/* Message loading state */
.message-loading,
.message-error,
.message-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: #6c757d;
  gap: 1rem;
  text-align: center;
}

.message-loading .loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(39, 76, 119, 0.1);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.message-error {
  color: #dc3545;
}

.message-empty svg,
.message-error svg {
  width: 48px;
  height: 48px;
  stroke-width: 1.5;
}

/* Message type icon backgrounds */
.message-item.message-info .message-icon { background: var(--gradient-primary); }
.message-item.message-warning .message-icon { background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%); }
.message-item.message-success .message-icon { background: linear-gradient(135deg, #28a745 0%, #20c997 100%); }
.message-item.message-system .message-icon { background: linear-gradient(135deg, #6c757d 0%, #495057 100%); }
.message-item.message-promo .message-icon { background: linear-gradient(135deg, #6f42c1 0%, #e83e8c 100%); }

/* Media Queries pour la gestion de la sidebar comme les autres sections */
@media (min-width: 1245px) {
  #messaging {
    padding: 1.5rem;
  }
}

/* Desktop moyen avec sidebar déployée (1024-1244px) - See consolidated media query above */

/* Responsive design */
@media (max-width: 1024px) {
  .messaging-actions {
    flex-direction: row;
    gap: 0.5rem;
    flex-wrap: nowrap;
  }

  .messaging-action-btn {
    font-size: 0.75rem;
    padding: 0.4rem 0.8rem;
    min-width: 90px;
  }
}

@media (max-width: 640px) {
  #messaging {
    padding: 0.5rem;
    padding-bottom: calc(var(--spacing-xxl) + var(--spacing-md));
  }

  .messaging-title {
    font-size: var(--h1-size);
  }

  .messaging-card-title {
    font-size: 1.1rem;
    min-width: fit-content;
  }

  .messaging-card-header {
    flex-direction: column;
    gap: 0.5rem;
    align-items: stretch;
    padding: 0.75rem;
  }

  .messaging-actions {
    display: flex;
    flex-direction: row;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: center;
  }

  .messaging-selection-bar {
    flex-direction: row;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
  }

  .messaging-card-content {
    width: 100%;
    padding: 0.75rem 0.5rem;
    min-height: 300px;
  }

  .message-item {
    border-radius: var(--border-radius-md);
  }

  .message-header-row {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .message-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
  }

  .message-title {
    font-size: 0.85rem;
  }

  .message-date {
    font-size: 0.7rem;
  }

  .message-icon {
    width: 28px;
    height: 28px;
  }

  .message-icon svg {
    width: 14px;
    height: 14px;
  }

  .message-body {
    padding: 0 0.75rem;
  }

  .message-item.expanded .message-body {
    padding: 0.5rem 0.75rem 0.75rem;
  }

  .message-actions {
    flex-direction: row;
    justify-content: flex-end;
  }

  .message-read-btn {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }

  .message-delete-btn {
    width: 28px;
    height: 28px;
  }

  .messaging-count {
    width: 20px;
    height: 20px;
    font-size: 10px;
    top: -8px;
    right: -8px;
    line-height: 1;
    border: 1px solid var(--background-color);
  }
}

