/* Variables CSS - Glassmorphism Design */
:root {
  --chatbot-primary: #f45a2a;
  --chatbot-primary-dark: #d94820;
  --chatbot-text: #1f2937;
  --chatbot-white: #ffffff;
  --chatbot-border: #e5e7eb;

  /* Glassmorphism tokens */
  --chatbot-glass-bg: rgba(255, 255, 255, 0.65);
  --chatbot-glass-bg-light: rgba(255, 255, 255, 0.4);
  --chatbot-glass-blur: 16px;
  --chatbot-glass-border: 1px solid rgba(255, 255, 255, 0.35);
  --chatbot-glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --chatbot-glass-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.18);
  --chatbot-glass-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.4);
  --chatbot-msg-bg: rgba(246, 248, 252, 0.7);
  --chatbot-timestamp-color: rgba(100, 116, 139, 0.7);
  --chatbot-avatar-size: 32px;
}

/* Conteneur principal */
#chatbot-container {
  position: fixed;
  bottom: 90px;
  right: 15px;
  z-index: 2147483647;
  isolation: isolate;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
}

/* Bouton flottant - Glassmorphism + mise en avant */
#chatbot-button {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px var(--chatbot-primary-semi),
    0 8px 32px rgba(0, 0, 0, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
  position: relative;
  z-index: 2;
}

#chatbot-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px var(--chatbot-primary-semi),
    0 12px 40px rgba(0, 0, 0, 0.18);
}

#chatbot-button:hover #chatbot-tooltip {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

#chatbot-button svg {
  stroke: var(--chatbot-white);
  position: relative;
  z-index: 2;
}

#chatbot-button.hidden {
  display: none;
}

/* Anneau de pulse autour du bouton */
#chatbot-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--chatbot-primary);
  opacity: 0;
  animation: chatbot-pulse-ring 2.5s ease-out infinite;
  pointer-events: none;
}

@keyframes chatbot-pulse-ring {
  0% {
    opacity: 0.6;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.5);
  }
}

/* Tooltip */
#chatbot-tooltip {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translateX(8px) translateY(-50%);
  background: var(--chatbot-white);
  color: var(--chatbot-text);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 10px;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.06);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s ease;
  z-index: 1;
}

/* Fleche du tooltip */
#chatbot-tooltip::after {
  content: "";
  position: absolute;
  top: 50%;
  right: -6px;
  transform: translateY(-50%) rotate(45deg);
  width: 10px;
  height: 10px;
  background: var(--chatbot-white);
  border-right: 1px solid rgba(0, 0, 0, 0.06);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

/* Auto-affichage du tooltip au chargement */
#chatbot-button:not(.hidden) #chatbot-tooltip {
  animation: chatbot-tooltip-show 0.4s ease 2s forwards;
}

@keyframes chatbot-tooltip-show {
  0% {
    opacity: 0;
    transform: translateX(8px) translateY(-50%);
  }
  100% {
    opacity: 1;
    transform: translateX(0) translateY(-50%);
  }
}

/* Cacher le tooltip apres un delai */
#chatbot-button:not(.hidden) #chatbot-tooltip {
  animation:
    chatbot-tooltip-show 0.4s ease 2s forwards,
    chatbot-tooltip-hide 0.3s ease 8s forwards;
}

@keyframes chatbot-tooltip-hide {
  0% {
    opacity: 1;
    transform: translateX(0) translateY(-50%);
  }
  100% {
    opacity: 0;
    transform: translateX(8px) translateY(-50%);
  }
}

/* Fenêtre du chat - Glassmorphism */
#chatbot-window {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 600px;
  max-height: calc(100vh - 40px);
  background: var(--chatbot-glass-bg);
  backdrop-filter: blur(var(--chatbot-glass-blur));
  -webkit-backdrop-filter: blur(var(--chatbot-glass-blur));
  border: var(--chatbot-glass-border);
  border-radius: 20px;
  box-shadow: var(--chatbot-glass-shadow-lg), var(--chatbot-glass-highlight);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
  z-index: 2147483647;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* En-tête - Couleur primary */
#chatbot-header {
  background: #1A1D43;
  color: var(--chatbot-white);
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: none;
  box-shadow: 0 4px 12px var(--chatbot-primary-semi);
}

#chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Avatar dans le header */
.chatbot-header-avatar {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 50%;
  background: var(--chatbot-white);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.chatbot-header-avatar svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: var(--chatbot-primary);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Pastille "en ligne" sur l'avatar header */
.chatbot-header-avatar::after {
  content: "";
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

#chatbot-header-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

#chatbot-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--chatbot-white) !important;
  line-height: 1.2;
  font-family: "Plus Jakarta Sans", Sans-serif !important;
}

#chatbot-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  font-weight: 500;
}

#chatbot-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: var(--chatbot-white);
  cursor: pointer;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.2s;
}

#chatbot-close:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Zone des messages */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--chatbot-msg-bg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#chatbot-messages::-webkit-scrollbar {
  width: 5px;
}

#chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

#chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 4px;
}

/* Messages */
.chatbot-message {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-message.user {
  flex-direction: row-reverse;
}

/* Wrapper contenu + timestamp */
.chatbot-message-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.chatbot-message.user .chatbot-message-wrapper {
  align-items: flex-end;
}

.chatbot-message.bot .chatbot-message-wrapper {
  align-items: flex-start;
}

/* Bulle de message */
.chatbot-message-content {
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.6;
  font-size: 14px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Messages utilisateur - couleur de marque */
.chatbot-message.user .chatbot-message-content {
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* Messages bot - Glassmorphism */
.chatbot-message.bot .chatbot-message-content {
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--chatbot-text);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), var(--chatbot-glass-highlight);
}

/* Avatar du bot */
.chatbot-avatar {
  width: var(--chatbot-avatar-size);
  height: var(--chatbot-avatar-size);
  min-width: var(--chatbot-avatar-size);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
  margin-top: 2px;
}

.chatbot-avatar svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--chatbot-primary);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Horodatage */
.chatbot-timestamp {
  font-size: 11px;
  color: var(--chatbot-timestamp-color);
  margin-top: 4px;
  padding: 0 4px;
  user-select: none;
}

/* Indicateur de saisie (typing) */
.chatbot-typing {
  display: flex;
  gap: 5px;
  padding: 4px 0;
}

.chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chatbot-primary);
  opacity: 0.6;
  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 - Glassmorphism */
#chatbot-input-container {
  padding: 16px;
  background: var(--chatbot-glass-bg-light);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, 0.3);
  display: flex;
  gap: 10px;
}

#chatbot-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
  color: var(--chatbot-text);
}

#chatbot-input:focus {
  border-color: var(--chatbot-primary);
  background: rgba(255, 255, 255, 0.7);
}

#chatbot-input::placeholder {
  color: rgba(100, 116, 139, 0.6);
}

#chatbot-send {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--chatbot-primary);
  color: var(--chatbot-white);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#chatbot-send:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===== Styles Markdown (messages bot uniquement) ===== */

.chatbot-message.bot .chatbot-message-content p {
  margin: 0 0 8px 0;
}

.chatbot-message.bot .chatbot-message-content p:last-child {
  margin-bottom: 0;
}

.chatbot-message.bot .chatbot-message-content strong {
  font-weight: 600;
}

.chatbot-message.bot .chatbot-message-content em {
  font-style: italic;
}

.chatbot-message.bot .chatbot-message-content a {
  color: var(--chatbot-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.chatbot-message.bot .chatbot-message-content a:hover {
  opacity: 0.8;
}

/* Code inline */
.chatbot-message.bot .chatbot-message-content code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
}

/* Blocs de code - Glassmorphism */
.chatbot-message.bot .chatbot-message-content pre {
  background: rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.06);
}

.chatbot-message.bot .chatbot-message-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.5;
}

/* Listes */
.chatbot-message.bot .chatbot-message-content ul,
.chatbot-message.bot .chatbot-message-content ol {
  margin: 6px 0;
  padding-left: 20px;
}

.chatbot-message.bot .chatbot-message-content li {
  margin-bottom: 4px;
}

/* Blockquote */
.chatbot-message.bot .chatbot-message-content blockquote {
  border-left: 3px solid var(--chatbot-primary);
  margin: 8px 0;
  padding: 4px 12px;
  color: rgba(31, 41, 55, 0.8);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 0 6px 6px 0;
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
  #chatbot-window {
    width: calc(100vw - 24px);
    height: calc(100vh - 120px);
    bottom: 12px;
    right: 12px;
    border-radius: 16px;
  }

  .chatbot-message-content {
    max-width: 85%;
  }

  .chatbot-message-wrapper {
    max-width: 85%;
  }

  .chatbot-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
  }

  .chatbot-avatar svg {
    width: 15px;
    height: 15px;
  }
}

#chatbot-button img {
  position: relative;
  z-index: 2;
  pointer-events: none;
}