/* Variables CSS */
:root {
  --chatbot-primary: #f45a2a;
  --chatbot-primary-dark: #005ee9;
  --chatbot-text: #1f2937;
  --chatbot-bg: #f9fafb;
  --chatbot-white: #ffffff;
  --chatbot-border: #e5e7eb;
  --chatbot-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

/* Conteneur principal */
#chatbot-container {
  position: fixed;
  bottom: 70px;
  right: 15px;
  z-index: 2147483647;
  isolation: isolate;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

#chatbot-window {
    z-index: 2147483647;
}

/* Bouton flottant */
#chatbot-button {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  position: relative;
}

#chatbot-button img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
}

/* Tooltip au survol */
#chatbot-tooltip {
  position: absolute;
  right: calc(100% + 0.75rem);
  top: 50%;
  transform: translateY(-50%);
  background: var(--chatbot-white);
  color: var(--chatbot-text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  transform: translateY(-50%) translateX(10px);
}

#chatbot-tooltip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: var(--chatbot-white);
  border-right: none;
}

#chatbot-button:hover #chatbot-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

#chatbot-button:hover {
  transform: scale(1.08);
}

#chatbot-button.hidden {
  display: none;
}

/* Fenêtre du chat */
#chatbot-window {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 40px);
  background: var(--chatbot-white);
  border-radius: 16px;
  box-shadow: var(--chatbot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
  z-index: 9;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* En-tête */
#chatbot-header {
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

#chatbot-header-avatar {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
}

#chatbot-header-text {
  display: flex;
  flex-direction: column;
}

#chatbot-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: white !important;
  line-height: 1.2;
}

#chatbot-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 5px;
}

#chatbot-header-status::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #34d399;
  border-radius: 50%;
  display: inline-block;
}

#chatbot-close {
  background: transparent;
  border: none;
  color: var(--chatbot-white);
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

#chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Zone des messages */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--chatbot-bg);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

#chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chatbot-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* Messages */
.chatbot-message {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Avatar dans les messages */
.chatbot-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.chatbot-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.chatbot-message-content {
  max-width: 75%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
}

.chatbot-message.user {
  flex-direction: row-reverse;
}

.chatbot-message.user .chatbot-message-content {
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  border-bottom-right-radius: 4px;
}

.chatbot-message.bot .chatbot-message-content {
  background: var(--chatbot-white);
  color: var(--chatbot-text);
  border: 1px solid var(--chatbot-border);
  border-bottom-left-radius: 4px;
}

/* Message de chargement */
.chatbot-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.chatbot-typing span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chatbot-primary);
  animation: typing 1.4s infinite;
}

.chatbot-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  30% {
    opacity: 1;
    transform: scale(1);
  }
}

/* Zone de saisie */
#chatbot-input-container {
  padding: 16px;
  background: var(--chatbot-white);
  border-top: 1px solid var(--chatbot-border);
  display: flex;
  gap: 10px;
}

#chatbot-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--chatbot-border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

#chatbot-input:focus {
  border-color: var(--chatbot-primary);
}

#chatbot-send {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  fill: none;
  stroke: var(--chatbot-white);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

#chatbot-send svg {
  stroke: currentColor;
}

#chatbot-send:hover:not(:disabled) {
  background: var(--chatbot-primary-dark);
}

#chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Responsive */
@media (max-width: 480px) {
  #chatbot-container {
    bottom: 70px;
    right: 10px;
  }

  #chatbot-button {
    width: 4rem;
    height: 4rem;
  }

  #chatbot-tooltip {
    display: none;
  }

  #chatbot-window {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }

  #chatbot-header {
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  #chatbot-header-avatar {
    width: 36px;
    height: 36px;
  }

  #chatbot-messages {
    padding: 16px;
  }

  .chatbot-message-content {
    max-width: 85%;
  }

  #chatbot-input-container {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  #chatbot-input {
    padding: 10px 14px;
    font-size: 16px;
  }
}
