/* ============================================================================
   Family Conversations - Styles pour les conversations familiales avec Ped'IA
   ========================================================================= */

/* Note: Les styles de .chat-fullscreen-controls sont définis dans style.css
   On ne les surcharge pas ici pour éviter les conflits */

/* 🔥 Ombre orangée pour les conversations familiales */
body.family-conversation-active .chat-fullscreen-layout {
  position: relative;
}

/* Ombre sur un pseudo-élément toujours visible */
body.family-conversation-active .chat-fullscreen-layout::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* Ombres INTERNES subtiles et discrètes */
  box-shadow:
    inset 0 0 40px rgba(255, 150, 64, 0.25),
    inset 0 0 80px rgba(255, 150, 64, 0.18),
    inset 0 0 120px rgba(255, 150, 64, 0.12);
  /* Toujours au-dessus de tout */
  z-index: 9999;
  /* Ne pas bloquer les interactions */
  pointer-events: none;
}

/* Sur mobile, ajuster pour que tout soit visible */
@media (max-width: 768px) {
  body.family-conversation-active .chat-fullscreen {
    /* Enlever tout margin/padding qui pourrait créer un espace */
    margin: 0 !important;
    padding: 0 !important;
  }

  /* S'assurer que le layout prend toute la hauteur disponible */
  body.family-conversation-active .chat-fullscreen-layout {
    min-height: calc(100vh - var(--header-height, 64px)) !important;
    max-height: calc(100vh - var(--header-height, 64px)) !important;
  }

  /* S'assurer que le scroll se fait uniquement dans le conteneur de messages */
  body.family-conversation-active .chat-messages,
  body.family-conversation-active #ai-chat-messages {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* Family conversation indicator - Caché car info maintenant dans pedia-mode-toggle */
.family-conv-indicator {
  display: none !important;
}

.family-conv-icon {
  font-size: 1.1rem;
}

.family-conv-participants {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.family-conv-leave-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  padding: 0;
  transition: background 0.2s;
}

.family-conv-leave-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Ped'IA mode toggle - Positionnée au-dessus du formulaire */
.pedia-mode-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0.04) 100%);
  border-radius: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);

  /* Positionnement fixe en bas, AU-DESSUS du formulaire */
  position: fixed !important;
  bottom: calc(100px + env(safe-area-inset-bottom)) !important; /* Au-dessus du formulaire + safe area iOS */
  left: 50% !important;
  transform: translateX(-50%) !important;
  z-index: 9999 !important; /* Au-dessus du chat mais sous les modals */
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
}

.pedia-mode-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #ffe1c8;
  padding-left: 0.5rem;
  white-space: nowrap;
}

.pedia-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: none;
  background: transparent;
  color: #c5cceb;
  border-radius: 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.pedia-mode-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #e9edff;
}

.pedia-mode-btn.active {
  background: linear-gradient(135deg, rgba(110, 163, 255, 0.25) 0%, rgba(255, 150, 64, 0.25) 100%);
  color: #6ea3ff;
  box-shadow: 0 2px 6px rgba(110, 163, 255, 0.3);
}

.pedia-mode-icon {
  font-size: 1rem;
  line-height: 1;
}

.pedia-mode-text {
  font-size: 0.85rem;
}

/* Séparateur entre modes et bouton quitter */
.pedia-mode-separator {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 0.5rem;
}

/* Bouton Quitter dans la barre des modes */
.pedia-mode-leave-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: none;
  background: transparent;
  color: #ff9640;
  border-radius: 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.pedia-mode-leave-btn:hover {
  background: rgba(255, 100, 100, 0.15);
  color: #ff6464;
}

.pedia-mode-leave-btn .pedia-mode-icon {
  font-size: 1rem;
}

.pedia-mode-leave-btn .pedia-mode-text {
  font-size: 0.85rem;
}

/* Invite family button */
.btn-invite-family {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.btn-invite-family .btn-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.btn-invite-family .btn-text {
  font-size: 0.9rem;
}

/* Bouton invite dans l'historique */
.chat-history-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.75rem;
}

.btn-invite-family-history {
  width: 100%;
  justify-content: center;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  border-radius: 0.5rem;
}

.btn-invite-family-history .btn-icon {
  font-size: 1.1rem;
  line-height: 1;
}

.btn-invite-family-history .btn-text {
  font-size: 0.9rem;
}

/* Dialog d'invitation - Overlay */
.family-invite-dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 1.5rem;
  animation: overlay-fadein 0.3s ease-out;
}

@keyframes overlay-fadein {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Dialog d'invitation - Contenu */
.family-invite-dialog {
  background: linear-gradient(145deg, #0a0e17 0%, #111827 100%);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 1.25rem;
  padding: 0;
  max-width: 480px;
  width: 100%;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 0 80px rgba(110, 163, 255, 0.08);
  animation: dialog-appear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  overflow: hidden;
}

@keyframes dialog-appear {
  from {
    transform: scale(0.85) translateY(20px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

.family-invite-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.75rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.02));
}

.family-invite-dialog-header h3 {
  margin: 0;
  font-size: 1.35rem;
  color: #ffe1c8;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.family-invite-dialog-close {
  background: none;
  border: none;
  font-size: 1.75rem;
  color: #c5cceb;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.family-invite-dialog-close:hover {
  background: rgba(255, 100, 100, 0.15);
  color: #ff6464;
  transform: scale(1.1);
}

.family-invite-dialog-body {
  padding: 1.75rem 1.5rem;
  color: #e9edff;
}

.family-invite-dialog-body > p {
  color: #c5cceb;
  margin: 0 0 1.25rem 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

.family-invite-coparents {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0 0 1.5rem 0;
}

.family-invite-coparent-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1rem 1.125rem;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.875rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
  position: relative;
  overflow: hidden;
  min-width: 0; /* Important pour permettre au flex child de shrink */
}

.family-invite-coparent-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(110, 163, 255, 0.08), rgba(255, 150, 64, 0.08));
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.family-invite-coparent-item:hover {
  border-color: rgba(110, 163, 255, 0.5);
  background: rgba(110, 163, 255, 0.08);
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(110, 163, 255, 0.15);
}

.family-invite-coparent-item:hover::before {
  opacity: 1;
}

.family-invite-coparent-item input[type="radio"]:checked ~ * {
  /* Styles pour l'état sélectionné */
}

.family-invite-coparent-item:has(input[type="radio"]:checked) {
  border-color: #6ea3ff;
  background: linear-gradient(135deg, rgba(110, 163, 255, 0.15), rgba(110, 163, 255, 0.08));
  box-shadow: 0 0 0 2px rgba(110, 163, 255, 0.2);
}

.family-invite-coparent-item:has(input[type="radio"]:checked)::before {
  opacity: 1;
}

.family-invite-coparent-item span {
  color: #e9edff;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s ease;
  /* 🔧 FIX: Contraindre le texte pour éviter le débordement */
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.family-invite-coparent-item input[type="radio"] {
  cursor: pointer;
  accent-color: #6ea3ff;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.family-invite-coparent-item:hover input[type="radio"] {
  transform: scale(1.1);
}

.family-invite-coparent-item input[type="radio"]:checked + span {
  color: #6ea3ff;
  font-weight: 600;
}

.family-invite-message {
  margin-top: 0;
}

.family-invite-message label {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.625rem;
  color: #ffe1c8;
  letter-spacing: -0.01em;
}

.family-invite-message textarea {
  width: 100%;
  min-height: 90px;
  padding: 0.875rem 1rem;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  border-radius: 0.875rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
  box-sizing: border-box;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.03));
  color: #e9edff;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.family-invite-message textarea::placeholder {
  color: #8891b3;
  opacity: 0.7;
}

.family-invite-message textarea:focus {
  outline: none;
  border-color: #6ea3ff;
  background: rgba(110, 163, 255, 0.08);
  box-shadow: 0 0 0 3px rgba(110, 163, 255, 0.15);
}

.family-invite-dialog-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(to top, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
}

/* Dialog modale pour invitation (ancienne version - à garder pour compatibilité) */
.family-invitation-dialog {
  border: none;
  border-radius: 1rem;
  padding: 0;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.family-invitation-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.family-invitation-content {
  padding: 2rem;
}

.family-invitation-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.family-invitation-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.family-invitation-title {
  flex: 1;
}

.family-invitation-title h3 {
  margin: 0 0 0.25rem 0;
  font-size: 1.5rem;
  color: var(--color-text, #333);
}

.family-invitation-title p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text-secondary, #666);
}

.family-invitation-body {
  margin-bottom: 1.5rem;
}

.family-invitation-coparent {
  background: var(--color-bg-light, #f5f5f5);
  padding: 1rem;
  border-radius: 0.5rem;
  margin-bottom: 1rem;
}

.family-invitation-coparent-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-text-secondary, #666);
  margin-bottom: 0.5rem;
}

.family-invitation-coparent-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text, #333);
}

.family-invitation-message {
  margin-top: 1rem;
}

.family-invitation-message label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--color-text, #333);
}

.family-invitation-message textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  border: 1px solid var(--color-border, #e0e0e0);
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.family-invitation-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* Messages dans conversation familiale */
.chat-message--family {
  position: relative;
}

/* Styles pour les messages parent - SPÉCIFICITÉ AUGMENTÉE */
.pedia-popup-chat .chat-messages .chat-message--parent {
  display: flex !important;
  flex-direction: column !important;
  gap: 0.25rem !important;
  margin-bottom: 1rem !important;
  max-width: 85% !important;
  animation: fadeInUp 0.3s ease !important;
  align-items: flex-start !important; /* Override align-items: flex-end */
  width: auto !important;
  min-height: 50px !important;
  visibility: visible !important;
  opacity: 1 !important;
  margin-right: 0 !important; /* Annuler margin-right: auto */
  margin-left: 0 !important;
}

.pedia-popup-chat .chat-messages .chat-message--pedia {
  display: flex !important;
  flex-direction: column !important;
  gap: 0.25rem !important;
  margin-bottom: 1rem !important;
  max-width: 85% !important;
  animation: fadeInUp 0.3s ease !important;
  align-items: flex-start !important; /* Override align-items: flex-end */
  width: auto !important;
  min-height: 50px !important;
  visibility: visible !important;
  opacity: 1 !important;
  margin-right: 0 !important;
  margin-left: 0 !important;
}

.chat-message-sender {
  font-size: 0.85rem !important;
  font-weight: 600 !important;
  color: var(--color-primary, #667eea) !important;
  margin-bottom: 0.25rem !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.chat-message-sender--pedia {
  color: var(--color-secondary, #764ba2);
}

.chat-message-sender--self {
  color: #ff9640;
}

.chat-message-sender--other {
  color: #6ea3ff;
}

.chat-message-sender--parent1 {
  color: #667eea;
}

.chat-message-sender--parent2 {
  color: #f093fb;
}

.chat-message-content {
  background: linear-gradient(150deg, rgba(255, 182, 110, 0.28), rgba(48, 24, 12, 0.2)) !important;
  border: 1px solid rgba(255, 196, 140, 0.45) !important;
  box-shadow: 0 14px 32px rgba(40, 12, 4, 0.42) !important;
  color: #fff8f0 !important;
  padding: 14px 18px !important;
  border-radius: 18px !important;
  line-height: 1.4 !important;
  font-size: 0.9rem !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  min-height: fit-content !important;
  height: auto !important;
  width: 100% !important;

  /* 🔧 FIX: Empêcher le débordement du texte sur mobile */
  word-wrap: break-word !important;
  overflow-wrap: break-word !important;
  word-break: break-word !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
  white-space: pre-wrap !important;
}

.chat-message--pedia .chat-message-content {
  background: linear-gradient(160deg, rgba(110, 163, 255, 0.32), rgba(36, 58, 104, 0.22));
  border-color: rgba(138, 182, 255, 0.38);
}

.chat-message-time {
  font-size: 0.75rem !important;
  color: rgba(214, 222, 255, 0.5) !important;
  margin-top: 0.25rem !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Badge participants en ligne */
.participant-online-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #4caf50;
  border-radius: 50%;
  margin-left: 0.25rem;
  animation: pulse-online 2s infinite;
}

@keyframes pulse-online {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Notification invitation */
.family-invitation-notification {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: white;
  border-radius: 1rem;
  padding: 1rem 1.5rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  max-width: 350px;
  animation: slide-in-right 0.3s ease-out;
  z-index: 10000;
}

@keyframes slide-in-right {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.family-invitation-notification-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.family-invitation-notification-icon {
  font-size: 2rem;
  line-height: 1;
}

.family-invitation-notification-title {
  flex: 1;
  font-weight: 600;
  color: var(--color-text, #333);
}

.family-invitation-notification-message {
  font-size: 0.9rem;
  color: var(--color-text-secondary, #666);
  margin-bottom: 1rem;
}

.family-invitation-notification-actions {
  display: flex;
  gap: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {

  .pedia-mode-toggle {
    width: auto;
    max-width: 90%;
    justify-content: center;
    /* Position simple et fixe sur mobile */
    bottom: calc(100px + env(safe-area-inset-bottom)) !important;
  }

  .btn-invite-family {
    width: 100%;
    justify-content: center;
  }

  .family-conv-indicator {
    width: 100%;
    justify-content: center;
  }

  .pedia-mode-label {
    display: none;
  }

  .pedia-mode-btn {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
  }

  .family-invitation-notification {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    max-width: none;
  }

  /* 🔧 Améliorations mobile pour le dialog d'invitation */
  .family-invite-dialog-overlay {
    padding: 1rem;
  }

  .family-invite-dialog {
    max-width: 100%;
    border-radius: 1rem;
  }

  .family-invite-dialog-header {
    padding: 1.25rem 1rem;
  }

  .family-invite-dialog-header h3 {
    font-size: 1.15rem;
    line-height: 1.3;
    padding-right: 0.5rem;
  }

  .family-invite-dialog-close {
    width: 32px;
    height: 32px;
    font-size: 1.5rem;
  }

  .family-invite-dialog-body {
    padding: 1.25rem 1rem;
  }

  .family-invite-dialog-body > p {
    font-size: 0.9rem;
  }

  .family-invite-coparent-item {
    padding: 0.875rem 1rem;
    gap: 0.75rem;
  }

  .family-invite-coparent-item span {
    font-size: 0.95rem;
  }

  .family-invite-message textarea {
    min-height: 80px;
    font-size: 0.9rem;
  }

  .family-invite-dialog-footer {
    padding: 1.25rem 1rem;
    gap: 0.625rem;
  }

  .family-invite-dialog-footer .btn {
    flex: 1;
    font-size: 0.9rem;
    padding: 0.75rem 1rem;
  }
}
