/* 🎨 Ped'IA Enhanced Input - Design inspiré du log critique */

.pedia-enhanced-container {
  display: flex;
  align-items: center;
  justify-content: center; /* Centre tout le contenu */
  gap: 0.5rem;
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  padding: 0 10px; /* Un peu d'espace sur les côtés */
}

/* Bouton emoji (génération d'image) - dans le flex, juste à gauche de l'input */
.pedia-emoji-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  color: rgba(255, 255, 255, 0.7);
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  cursor: pointer;
  opacity: 1;
  visibility: visible;
  pointer-events: all;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.05);
  z-index: 15;
  font-size: 20px;
}

.pedia-emoji-btn:hover {
  opacity: 1;
  transform: scale(1.1);
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.05);
}

/* Wrapper pour l'input avec position relative pour le bouton send */
.pedia-input-wrapper {
  position: relative;
  display: inline-flex; /* inline-flex pour s'adapter à la taille du contenu */
  align-items: flex-start; /* Alignement en haut pour gérer l'expansion du textarea */
}

/* Input principal avec expansion */
.pedia-enhanced-input-field {
  width: 280px; /* Largeur au repos */
  min-height: 48px;
  max-height: 150px;
  padding: 0.875rem 3rem 0.875rem 1.25rem;
  border-radius: 24px;
  outline: none;
  /* Glass Liquid Effect */
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.15),
    inset 0 -1px 1px rgba(0, 0, 0, 0.05),
    0 8px 32px rgba(31, 38, 135, 0.25);
  color: #f5f7ff;
  font-size: 15px;
  line-height: 1.4;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 400;
  transition: height 0.2s ease-out, width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.05), all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.05), backdrop-filter 0.3s ease;
  z-index: 10;
  resize: none;
  overflow-y: auto;
}

.pedia-enhanced-input-field::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

/* Expansion au focus ou quand il y a du texte */
.pedia-enhanced-input-field:focus,
.pedia-enhanced-input-field:valid {
  width: 450px; /* S'élargit significativement */
  /* Glass Liquid Effect - Focus state */
  border-color: rgba(255, 214, 153, 0.5);
  background: rgba(255, 255, 255, 0.12);
  box-shadow:
    0 0 0 3px rgba(255, 150, 64, 0.15),
    inset 0 1px 1px rgba(255, 255, 255, 0.2),
    inset 0 -1px 1px rgba(0, 0, 0, 0.05),
    0 8px 32px rgba(31, 38, 135, 0.3);
}

/* Responsive - Mobile */
@media (max-width: 768px) {
  .pedia-enhanced-input-field {
    width: 220px !important; /* Plus compact sur mobile au repos */
  }

  .pedia-enhanced-input-field:focus,
  .pedia-enhanced-input-field:valid {
    width: 260px !important; /* Expansion très réduite sur mobile */
  }

  /* Popup Ped'IA sur mobile - encore plus réduit */
  #pedia-popup .pedia-enhanced-input-field,
  #pedia-popup-chat-form .pedia-enhanced-input-field {
    width: 180px !important;
  }

  #pedia-popup .pedia-enhanced-input-field:focus,
  #pedia-popup .pedia-enhanced-input-field:valid,
  #pedia-popup-chat-form .pedia-enhanced-input-field:focus,
  #pedia-popup-chat-form .pedia-enhanced-input-field:valid {
    width: 240px !important; /* Très conservateur sur mobile dans la popup */
  }

  /* Messages.html sur mobile */
  body.messages-page .pedia-enhanced-input-field,
  #message-input.pedia-enhanced-input-field {
    width: 180px !important;
  }

  body.messages-page .pedia-enhanced-input-field:focus,
  body.messages-page .pedia-enhanced-input-field:valid,
  #message-input.pedia-enhanced-input-field:focus,
  #message-input.pedia-enhanced-input-field:valid {
    width: 240px !important; /* Expansion très modérée sur mobile */
  }
}

/* Bouton d'envoi circulaire avec gradient - à l'intérieur à droite, apparaît quand l'input a du texte */
.pedia-send-btn {
  position: absolute;
  top: 6px; /* Position fixe en haut pour rester aligné avec la première ligne du textarea */
  right: 0.375rem;
  transform: scale(0);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  outline: none;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.05);
  z-index: 20;

  /* Gradient bleu */
  background: linear-gradient(135deg, #4E7CD8 0%, #2563eb 100%);
  color: #ffffff;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(78, 124, 216, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.pedia-enhanced-input-field:valid ~ .pedia-send-btn {
  transform: scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: all;
}

.pedia-send-btn:hover,
.pedia-send-btn:focus-visible {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(78, 124, 216, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.pedia-send-btn:active {
  transform: scale(0.95);
}

.pedia-send-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.5;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2));
}

/* Sélection de texte */
.pedia-enhanced-input-field::selection {
  background-color: rgba(255, 150, 64, 0.3);
  color: #ffffff;
}

/* Retirer le fond noir du bloc chat-actions */
.chat-input .chat-actions {
  background: transparent !important;
  padding: 0.5rem 0 0 0 !important;
}

/* Retirer aussi le fond noir spécifiquement dans la popup Ped'IA */
#pedia-popup-chat-form .chat-actions,
#pedia-popup .chat-actions {
  background: transparent !important;
  padding: 0 !important;
}

/* Override TOUS les arrière-plans du formulaire dans /ped-ia et popup */
body.ped-ia-chat-active .chat-input,
.pedia-popup-chat .chat-input,
#pedia-popup-chat-form,
.chat-fullscreen-stage .chat-input {
  background: transparent !important;
}

/* Réduction de la largeur pour la popup Ped'IA (espace limité) */
#pedia-popup .pedia-enhanced-input-field,
#pedia-popup-chat-form .pedia-enhanced-input-field {
  width: 240px; /* Plus compact au repos dans la popup */
}

#pedia-popup .pedia-enhanced-input-field:focus,
#pedia-popup .pedia-enhanced-input-field:valid,
#pedia-popup-chat-form .pedia-enhanced-input-field:focus,
#pedia-popup-chat-form .pedia-enhanced-input-field:valid {
  width: 350px; /* Expansion modérée dans la popup (au lieu de 450px) */
}

/* Réduction pour la page messages.html */
body.messages-page .pedia-enhanced-input-field,
#message-input.pedia-enhanced-input-field {
  width: 250px; /* Plus compact au repos */
}

body.messages-page .pedia-enhanced-input-field:focus,
body.messages-page .pedia-enhanced-input-field:valid,
#message-input.pedia-enhanced-input-field:focus,
#message-input.pedia-enhanced-input-field:valid {
  width: 380px; /* Expansion modérée (au lieu de 450px) */
}

/* Retirer le style conteneur sur mobile pour /ped-ia et popup Ped'IA */
@media (max-width: 768px) {
  /* 🔥 FIX ZONE NOIRE: Retirer le fond noir du formulaire */
  body.ped-ia-chat-active .chat-input {
    border-top: none !important;
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: none !important;
    padding: 12px 16px !important;
    /* 🔥 Forcer le formulaire à être VRAIMENT visible */
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px)) !important;
    transform: translateY(0) translateZ(0) !important;
    transition: none !important;
    z-index: 10000 !important; /* Au-dessus de tout */
    margin: 0 !important;
    width: 100% !important;
    max-height: none !important;
    min-height: auto !important;
  }

  .pedia-popup-chat .chat-input,
  #pedia-popup-chat-form {
    border-top: none !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 12px 16px !important;
  }

  /* 🔥 FIX: Retirer complètement l'espace bottom-nav sur /ped-ia */
  body.ped-ia-chat-active {
    padding-bottom: 0 !important;
    overflow-x: hidden !important;
  }

  /* 🔥 FIX: S'assurer que les messages prennent la bonne hauteur */
  /* iOS: padding-bottom 120px car le formulaire est fixed */
  body.ped-ia-chat-active .chat-messages,
  body.ped-ia-chat-active #ai-chat-messages {
    padding-bottom: 120px !important; /* Plus d'espace pour être sûr */
    max-height: calc(100svh - 200px) !important; /* Laisser de la place au formulaire */
  }

  /* 🔧 ANDROID: padding-bottom réduit car le formulaire est dans le flow (pas fixed) */
  html.platform-android body.ped-ia-chat-active .chat-messages,
  html.platform-android body.ped-ia-chat-active #ai-chat-messages,
  body.platform-android.ped-ia-chat-active .chat-messages,
  body.platform-android.ped-ia-chat-active #ai-chat-messages {
    padding-bottom: 16px !important;
    max-height: none !important;
  }

  /* 🔥 FIX: Container principal ne doit pas déborder */
  body.ped-ia-chat-active .chat-window,
  body.ped-ia-chat-active .chat-fullscreen {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    max-height: 100svh !important;
  }
}
