#chat-toggle {
  position: fixed;
  bottom: 40px;
  left: 20px;
  background: linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  color: white;
  padding: 12px 20px;
  border-radius: 25px;
  cursor: pointer;
  z-index: 9999;
  font-weight: 600;
  font-size: 14px;
  box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35);
  transition: all 0.3s ease;
  border: none;
  width: fit-content;
  display: inline-block;
  white-space: nowrap;
}

#chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(29, 78, 216, 0.5);
}

/* Effet visuel de chargement sur le toggle */
#chat-toggle.generating {
  position: fixed;
  animation: toggle-pulse 1.5s ease-in-out infinite;
  box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35),
    0 0 20px rgba(14, 165, 233, 0.45),
    0 0 40px rgba(29, 78, 216, 0.3);
  transform-origin: left bottom;
}

@keyframes toggle-pulse {

  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35),
      0 0 20px rgba(14, 165, 233, 0.45),
      0 0 40px rgba(29, 78, 216, 0.3);
  }

  50% {
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(29, 78, 216, 0.35),
      0 0 30px rgba(14, 165, 233, 0.65),
      0 0 60px rgba(29, 78, 216, 0.45);
  }
}

#chat-box {
  position: fixed;
  bottom: 120px;
  left: 20px;
  width: 450px;
  height: 550px;
  background: white;
  border: none;
  border-radius: 20px;
  display: none;
  flex-direction: column;
  z-index: 9999;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  animation: slideIn 0.3s ease;
}

#chat-header {
  background: linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  color: white;
  padding: 20px;
  text-align: center;
}

#chat-header h3 {
  margin: 0 0 8px 0;
  font-size: 18px;
  font-weight: 600;
  color: white;
}

#chat-header .warning-text {
  margin: 0;
  font-size: 12px;
  opacity: 0.9;
  line-height: 1.4;
  color: white;
}

#chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  font-size: 14px;
  background: #f8f9fa;
}

#chat-messages .user-message {
  background: #e3f2fd;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 12px;
  border-bottom-left-radius: 4px;
  max-width: 90%;
  margin-left: auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  line-height: 1.4;
  min-height: 44px;
  display: flex;
  align-items: center;
}

#chat-messages .ai-message {
  background: white;
  padding: 12px 16px;
  border-radius: 18px;
  margin-bottom: 12px;
  border-bottom-right-radius: 4px;
  max-width: 90%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border-left: 3px solid #4caf50;
  line-height: 1.5;
  min-height: 44px;
  display: block;
  text-align: left;
}

/* Corps du message IA (markdown léger → HTML) : pas de flex multi-colonnes */
#chat-messages .ai-message .ai-message-body {
  display: block;
  width: 100%;
  text-align: left;
  word-wrap: break-word;
  overflow-wrap: break-word;
  column-count: 1;
}

#chat-messages .ai-message .ai-message-body strong {
  font-weight: 600;
  margin-right: 0;
}

#chat-messages .ai-message.error {
  border-left-color: #f44336;
  background: #ffebee;
}

#chat-messages .user-message strong {
  margin-right: 8px;
}

#chat-messages .ai-message strong {
  margin-right: 8px;
}

#chat-input {
  border-top: 1px solid #e0e0e0;
  display: flex;
  padding: 15px;
  background: white;
  gap: 8px;
}

#chat-input textarea {
  flex: 1;
  border: 2px solid #e0e0e0;
  border-radius: 15px;
  padding: 12px 16px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.3s ease;
  resize: none;
  font-family: inherit;
  line-height: 1.4;
  min-height: 60px;
  max-height: 120px;
}

#chat-input textarea:focus {
  border-color: #2563eb;
}

#chat-input textarea::placeholder {
  color: #999;
  font-style: italic;
}

#chat-input button {
  background: linear-gradient(135deg, #1d4ed8 0%, #0ea5e9 100%);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 25px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s ease;
  min-width: 80px;
}

#chat-input button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.35);
}

#chat-input button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

#chat-input button.loading {
  position: relative;
  cursor: wait;
  opacity: 0.9;
  font-size: 0px;
  /* Cache le texte original du bouton */
}

/* Libellé visible pendant le chargement */
#chat-input button.loading::before {
  content: 'Generating…';
  color: #fff;
  font-size: 14px;
  /* Restaure la taille de police */
  padding-right: 12px;
}

/* Spinner moderne à droite du bouton */
#chat-input button.loading::after {
  content: '';
  position: absolute;
  right: 8px;
  top: 50%;
  width: 14px;
  height: 14px;
  margin-top: -7px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  border-top-color: #ffffff;
  animation: chat-spin 0.7s linear infinite;
}

#chat-undo {
  background: #f44336 !important;
  min-width: 60px;
}

#chat-undo:hover {
  background: #d32f2f !important;
}

/* Scrollbar personnalisée */
#chat-messages::-webkit-scrollbar {
  width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

#chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Animation d'apparition */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Animation du spinner */
@keyframes chat-spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* Responsive */
@media (max-width: 768px) {
  #chat-box {
    width: calc(100vw - 40px);
    left: 20px;
    right: 20px;
  }

  #chat-toggle {
    left: 20px;
    right: 20px;
    text-align: center;
  }
}