html, body {
  height: 100%;
  margin: 0;
  font-family: 'Segoe UI', sans-serif;
  background: #f3f4f6;
}

header {
  padding: 1rem;
  text-align: center;
  background-color: #2c7be5;
  color: white;
  font-size: 1.2rem;
  font-weight: bold;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  /* Ajout pour résoudre le problème mobile */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
  /* Assure un centrage parfait */
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
}

#clear-history {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  font-weight: normal;
}

#clear-history:hover {
  background: rgba(255, 255, 255, 0.3);
}

#clear-history:active {
  background: rgba(255, 255, 255, 0.4);
}

/* Responsive - masquer le texte sur petits écrans */
@media (max-width: 480px) {
  #clear-history {
    padding: 0.5rem;
    font-size: 1rem;
  }
  
  #clear-history .clear-text {
    display: none;
  }
}

#chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: 60px; /* hauteur du header */
  max-width: 800px;
  margin: 0 auto;
  box-sizing: border-box;
}

#chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: white;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  /* CORRECTION : Force une hauteur minimale pour permettre le scroll */
  min-height: 0;
  /* Améliore le scroll sur mobile */
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 75%;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  /* Empêche les messages de déborder */
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.user {
  align-self: flex-end;
  background: #d1e7dd;
  color: #0f5132;
}

.gustave {
  align-self: flex-start;
  background: #f1f1f1;
  color: #333;
}

/* Styles pour les formations */
.formations-container {
  align-self: flex-start;
  max-width: 75%;
  background: #e8f4fd;
  border: 1px solid #bee5eb;
  border-radius: 12px;
  padding: 1rem;
  margin-top: -0.5rem;
  margin-bottom: 0.5rem;
}

.formations-title {
  color: #004085;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.formations-list {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
  color: #004085;
}

.formation-item {
  margin: 0.25rem 0;
  font-size: 0.9rem;
}

.formations-encouragement {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: #004085;
  font-style: italic;
}

form {
  display: flex;
  border-top: 1px solid #ddd;
  background: white;
  /* CORRECTION : Assure que le formulaire a une taille fixe */
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

input {
  flex: 1;
  padding: 1rem;
  border: none;
  font-size: 1rem;
}

button {
  padding: 1rem;
  background: #2c7be5;
  color: white;
  border: none;
  font-weight: bold;
  cursor: pointer;
  /* Empêche le bouton de rétrécir */
  flex-shrink: 0;
}

button:hover {
  background: #1a68d1;
}

.loader {
  padding: 0.5rem 1rem;
  font-size: 1.5rem;
  display: flex;
  gap: 0.2rem;
  align-items: center;
  background: white;
  /* Assure que le loader a une taille fixe */
  flex-shrink: 0;
}

.hidden {
  display: none;
}

.dot {
  animation: blink 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}