:root {
  --chatbot-color: #FF2621;
  --text-dark: #1a1a1a;
}

/* =========================
   ISOLATION CSS
   (protection contre les thèmes WordPress)
   ========================= */

#chatbot-widget * {
  box-sizing: border-box !important;
}

/* Neutralise la typographie héritée du thème */
#chatbot-window {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  font-size: 16px !important;
  font-weight: normal !important;
  line-height: normal !important;
  text-transform: none !important;
  letter-spacing: normal !important;
  word-spacing: normal !important;
}

/* Neutralise les marges/paddings du thème dans les bulles */
#chatbot-widget .msg-bubble p {
  margin: 0 0 0.5em !important;
}
#chatbot-widget .msg-bubble p:last-child {
  margin-bottom: 0 !important;
}
#chatbot-widget .msg-bubble ul,
#chatbot-widget .msg-bubble ol {
  margin: 0.3em 0 !important;
  padding-left: 1.4em !important;
}
#chatbot-widget .msg-bubble li {
  margin: 0 !important;
  list-style-position: outside !important;
}

/* =========================
   ANIMATION DE FRAPPE
   ========================= */

#chatbot-widget .typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  vertical-align: middle;
}

#chatbot-widget .typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #1a1a1a;
  display: inline-block;
  font-size: 0;
  animation: typing-bounce 1.1s ease-in-out infinite;
}

#chatbot-widget .typing-dots span:nth-child(2) { animation-delay: 0.18s; }
#chatbot-widget .typing-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: 0.35; }
  30%           { transform: translateY(-4px); opacity: 1;    }
}

/* =========================
   WIDGET PRINCIPAL
   ========================= */

#chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

/* =========================
   TOOLTIP
   ========================= */

#chatbot-tooltip {
  position: absolute;
  bottom: 134px;
  right: 10px;
  background: #fff;
  color: var(--text-dark);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.13);
  display: none;
  min-width: 160px;
  max-width: 220px;
  white-space: normal;
}

#chatbot-tooltip::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 42px;
  border: 7px solid transparent;
  border-top-color: #fff;
  border-bottom: none;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.06));
}

/* =========================
   BOUTON D'OUVERTURE
   ========================= */

#chatbot-button {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#chatbot-button:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.28);
}

#chatbot-button video,
#chatbot-button img {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  max-width: none !important;
  max-height: none !important;
  pointer-events: none !important;
}

/* Masque les contrôles natifs du navigateur */
#chatbot-button video::-webkit-media-controls,
#chatbot-button video::-webkit-media-controls-enclosure,
#chatbot-button video::-webkit-media-controls-panel,
#chatbot-header-avatar video::-webkit-media-controls,
#chatbot-header-avatar video::-webkit-media-controls-enclosure,
#chatbot-header-avatar video::-webkit-media-controls-panel {
  display: none !important;
}

/* Neutralise MediaElement.js (MEJS) dans le bouton :
   on laisse MEJS s'initialiser mais on cache son interface */
#chatbot-button .mejs-container {
  width: 120px !important;
  height: 120px !important;
  min-width: 0 !important;
  border-radius: 50% !important;
  overflow: hidden !important;
  background: transparent !important;
}
#chatbot-button .mejs-inner,
#chatbot-button .mejs-mediaelement,
#chatbot-button mediaelementwrapper {
  width: 100% !important;
  height: 100% !important;
}
#chatbot-button .mejs-controls,
#chatbot-button .mejs-layers,
#chatbot-button .mejs-offscreen {
  display: none !important;
}

/* =========================
   FENÊTRE DE CHAT
   ========================= */

#chatbot-window {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 360px;
  height: 520px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
}

#chatbot-window.is-open {
  animation: chatbot-open 0.28s ease-out forwards;
}

#chatbot-window.is-closing {
  animation: chatbot-close 0.2s ease-in forwards;
}

@keyframes chatbot-open {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes chatbot-close {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(14px); }
}

/* =========================
   HEADER
   ========================= */

#chatbot-header {
  padding: 11px 18px;
  background: var(--chatbot-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

#chatbot-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#chatbot-header-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.25);
  border: 2px solid rgba(255, 255, 255, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

#chatbot-header-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

#chatbot-header-avatar img,
#chatbot-header-avatar video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;
  display: block !important;
  max-width: none !important;
  max-height: none !important;
}

#chatbot-header-avatar .avatar-initial {
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

#chatbot-header-name {
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
}

#chatbot-header-subtitle {
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
  font-weight: 500;
  margin-top: 3px;
}

#chatbot-close {
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  font-size: 18px;
  line-height: 1;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

#chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* =========================
   MESSAGES
   ========================= */

#messages {
  flex: 1;
  padding: 16px 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#messages::-webkit-scrollbar {
  width: 4px;
}

#messages::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 4px;
}

#messages::-webkit-scrollbar-track {
  background: transparent;
}

#chatbot-widget .msg-wrapper {
  display: flex;
  width: 100%;
}

#chatbot-widget .user-wrapper {
  justify-content: flex-end;
}

#chatbot-widget .assistant-wrapper {
  justify-content: flex-start;
}

#chatbot-widget .msg-bubble {
  max-width: 80%;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.5;
  word-break: break-word;
}

#chatbot-widget .user-bubble {
  background: var(--chatbot-color);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
}

#chatbot-widget .user-bubble a {
  color: rgba(255, 255, 255, 0.88);
  text-decoration: underline;
}

#chatbot-widget .assistant-bubble {
  background: #f1f1f1;
  color: var(--text-dark);
  border-radius: 4px 18px 18px 18px;
}

#chatbot-widget .assistant-bubble a {
  color: var(--chatbot-color);
  text-decoration: underline;
}

/* =========================
   ZONE DE SAISIE
   ========================= */

#chatbot-input {
  display: flex !important;
  align-items: center !important;
  padding: 10px 12px !important;
  border-top: 1px solid #f0f0f0 !important;
  gap: 8px !important;
  background: #fff !important;
  flex-shrink: 0 !important;
  flex-grow: 0 !important;
  height: auto !important;
  min-height: unset !important;
  max-height: none !important;
  width: 100% !important;
}

#chatbot-widget #chatbot-input textarea {
  flex: 1 !important;
  border: 1.5px solid #e8e8e8 !important;
  border-radius: 22px !important;
  padding: 8px 14px !important;
  font-size: 14px !important;
  resize: none !important;
  outline: none !important;
  background: #f7f7f7 !important;
  transition: border-color 0.2s ease, background 0.2s ease;
  height: 38px !important;
  min-height: 38px !important;
  max-height: 100px !important;
  overflow-y: hidden !important;
  line-height: 1.4 !important;
  font-family: inherit !important;
  box-shadow: none !important;
  width: auto !important;
  display: block !important;
  float: none !important;
  position: static !important;
}

#chatbot-widget #chatbot-input textarea:focus {
  border-color: var(--chatbot-color) !important;
  background: #fff !important;
}

#chatbot-widget #chatbot-input textarea::placeholder {
  color: #bbb;
}

/* =========================
   BOUTON ENVOYER
   ========================= */

#chatbot-widget #chatbot-send {
  width: 42px !important;
  height: 42px !important;
  min-width: 42px !important;
  min-height: 42px !important;
  border-radius: 50% !important;
  border: none !important;
  background: var(--chatbot-color) !important;
  color: #fff !important;
  font-size: 16px !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
  transition: transform 0.15s ease, opacity 0.15s ease;
  padding: 0 0 0 2px !important;
  box-shadow: none !important;
  line-height: 1 !important;
  letter-spacing: 0 !important;
}

#chatbot-widget #chatbot-send:hover {
  transform: scale(1.08);
}

#chatbot-widget #chatbot-send:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  transform: none;
}

/* =========================
   SCROLLBAR FIREFOX
   ========================= */

#messages {
  scrollbar-width: thin;
  scrollbar-color: #ddd transparent;
}

/* =========================
   RESPONSIVE MOBILE
   ========================= */

@media (max-width: 480px) {
  #chatbot-widget {
    right: 10px;
    bottom: 10px;
  }

  #chatbot-window {
    width: calc(100vw - 20px);
    height: calc(100vh - 160px);
    border-radius: 16px;
  }
}

/* =========================
   ACCESSIBILITÉ (MOUVEMENT RÉDUIT)
   ========================= */

@media (prefers-reduced-motion: reduce) {
  #chatbot-widget .typing-dots span {
    animation: none;
    opacity: 1;
  }

  #chatbot-window.is-open,
  #chatbot-window.is-closing {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}
