#root {
  /* Variables de style scopées pour le chatbot pour éviter les conflits */
  --primary-color: #007aff;
  --background-color: #1c1c1e;
  --surface-color: #2c2c2e;
  --text-color: #ffffff;
  --user-message-bg: #007aff;
  --bot-message-bg: #3a3a3c;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --border-radius: 20px;

  /* Force la couleur du texte pour tout le composant, résolvant les conflits d'héritage */
  color: var(--text-color);

  /* Positionnement par défaut en bas à droite */
  position: fixed;
  bottom: 20px; 
  right: 20px;
  z-index: 10000;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

.chat-bubble-button {
  background-color: var(--primary-color);
  color: white;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.chat-bubble-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.chat-bubble-button svg {
  width: 32px;
  height: 32px;
  transition: opacity 0.2s ease;
  position: absolute;
}

.chat-bubble-button .icon-open {
  opacity: 1;
}

.chat-bubble-button .icon-close {
  opacity: 0;
}

.chat-bubble-button.open .icon-open {
  opacity: 0;
}

.chat-bubble-button.open .icon-close {
  opacity: 1;
}


.chat-window {
  position: fixed;
  /* Position par défaut, au-dessus de la bulle */
  bottom: 90px; 
  right: 20px;
  width: 370px;
  max-width: calc(100vw - 40px);
  height: 70vh;
  max-height: 600px;
  background-color: var(--background-color);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease;
  transform: scale(0);
  opacity: 0;
  z-index: 10000;
}

.chat-window.open {
  transform: scale(1);
  opacity: 1;
}

.chat-header {
  background-color: var(--surface-color);
  padding: 10px 15px 10px 20px;
  color: var(--text-color);
  font-weight: bold;
  font-size: 1.1em;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header .avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.restart-button {
  margin-left: auto;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  padding: 5px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.restart-button svg {
  width: 20px;
  height: 20px;
}

.restart-button:hover:not(:disabled) {
  background-color: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.restart-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}


.message-list {
  flex-grow: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 80%;
  padding: 10px 15px;
  border-radius: var(--border-radius);
  line-height: 1.5;
  overflow-wrap: break-word; /* modern property for text wrapping */
  white-space: pre-wrap; /* Respects newlines and wraps text */
}

/* Target only the bubble containing the loader for centering */
.message:has(.loading-indicator) {
  min-height: 41.5px;
  display: flex;
  align-items: center;
}

.bot-message {
  background-color: var(--bot-message-bg);
  color: var(--text-color);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}

.user-message {
  background-color: var(--user-message-bg);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
}

.loading-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.7);
  animation: dot-flash 1.4s infinite ease-in-out both;
}

.loading-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-indicator span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes dot-flash {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

.chat-input-form {
  display: flex;
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background-color: var(--surface-color);
}

.chat-input {
  flex-grow: 1;
  background-color: var(--bot-message-bg);
  border: none;
  padding: 12px 15px;
  border-radius: 20px;
  color: var(--text-color);
  font-size: 1em;
}

.chat-input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--primary-color);
}

.send-button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 10px;
  color: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-button svg {
  width: 24px;
  height: 24px;
}

@media (max-width: 480px) {
  .chat-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 90px);
    bottom: 75px;
    right: 10px;
    max-height: none;
  }
  #root {
    bottom: 10px;
    right: 10px;
  }
}
