/**
 * Caftan AI Chat — Widget v1.5.7
 */

#caftan-chat-widget {
  --caftan-primary: #111111;
  --caftan-primary-soft: rgba(17, 17, 17, 0.1);
  --caftan-primary-strong: #000000;
  --caftan-offset: 22px;
  --caftan-radius: 22px;
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  z-index: 999999;
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
}

/* Thème clair — noir & blanc */
#caftan-chat-widget.caftan-theme-light {
  --caftan-bg: #ffffff;
  --caftan-header: #0a0a0a;
  --caftan-surface: #f5f5f5;
  --caftan-bubble-user-bg: #111111;
  --caftan-bubble-user-text: #ffffff;
  --caftan-bubble-bot-bg: #f0f0f0;
  --caftan-bubble-bot-text: #111111;
  --caftan-border: rgba(0, 0, 0, 0.12);
  --caftan-muted: #777777;
  --caftan-composer-bg: #ffffff;
  --caftan-input-bg: #f5f5f5;
  --caftan-messages-bg: #ffffff;
  --caftan-fab-bg: #ffffff;
  --caftan-fab-icon-filter: none;
  --caftan-link-bg: rgba(0, 0, 0, 0.06);
  --caftan-link-color: #111111;
  --caftan-link-border: rgba(0, 0, 0, 0.2);
}

/* Thème sombre — noir & blanc */
#caftan-chat-widget.caftan-theme-dark {
  --caftan-bg: #0a0a0a;
  --caftan-header: #000000;
  --caftan-surface: #1a1a1a;
  --caftan-bubble-user-bg: #ffffff;
  --caftan-bubble-user-text: #111111;
  --caftan-bubble-bot-bg: #222222;
  --caftan-bubble-bot-text: #f5f5f5;
  --caftan-border: rgba(255, 255, 255, 0.14);
  --caftan-muted: #999999;
  --caftan-composer-bg: #0a0a0a;
  --caftan-input-bg: #1a1a1a;
  --caftan-messages-bg: #0a0a0a;
  --caftan-fab-bg: #111111;
  --caftan-fab-icon-filter: invert(1);
  --caftan-link-bg: rgba(255, 255, 255, 0.08);
  --caftan-link-color: #ffffff;
  --caftan-link-border: rgba(255, 255, 255, 0.25);
}

#caftan-chat-widget *,
#caftan-chat-widget *::before,
#caftan-chat-widget *::after { box-sizing: border-box; }

#caftan-chat-widget.caftan-pos-bottom-right #caftan-chat-fab-wrap,
#caftan-chat-widget.caftan-pos-bottom-right #caftan-chat-popup {
  right: var(--caftan-offset); left: auto;
}
#caftan-chat-widget.caftan-pos-bottom-left #caftan-chat-fab-wrap,
#caftan-chat-widget.caftan-pos-bottom-left #caftan-chat-popup {
  left: var(--caftan-offset); right: auto;
}

/* FAB */
#caftan-chat-fab-wrap {
  position: fixed;
  bottom: var(--caftan-offset);
  z-index: 999999;
  display: flex;
  align-items: center;
  gap: 10px;
}
#caftan-chat-widget.caftan-pos-bottom-right #caftan-chat-fab-wrap { flex-direction: row; }
#caftan-chat-widget.caftan-pos-bottom-left #caftan-chat-fab-wrap { flex-direction: row-reverse; }

#caftan-chat-help-label {
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  background: #111;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#caftan-chat-widget.caftan-pos-bottom-left #caftan-chat-help-label { transform: translateX(-8px); }
#caftan-chat-fab-wrap:hover #caftan-chat-help-label,
#caftan-chat-fab-wrap:focus-within #caftan-chat-help-label {
  opacity: 1;
  transform: translateX(0);
}
#caftan-chat-widget.is-open #caftan-chat-help-label { display: none; }
@media (max-width: 768px) {
  #caftan-chat-help-label { display: none !important; }
}

#caftan-chat-widget #caftan-chat-toggle {
  all: unset;
  position: relative !important;
  width: 68px !important;
  height: 68px !important;
  border-radius: 50% !important;
  background: var(--caftan-fab-bg) !important;
  color: #111 !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.22),
    0 0 0 2px #111111 !important;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1) !important;
  overflow: visible !important;
}
#caftan-chat-widget.caftan-theme-dark #caftan-chat-toggle {
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.45),
    0 0 0 2px #ffffff !important;
  color: #fff !important;
}
#caftan-chat-widget #caftan-chat-toggle:hover {
  transform: translateY(-3px) scale(1.04) !important;
}
#caftan-chat-widget #caftan-chat-toggle .caftan-bot-face,
#caftan-chat-widget #caftan-chat-toggle .caftan-icon-chat {
  width: 38px !important;
  height: 38px !important;
  object-fit: contain;
  display: block;
  pointer-events: none;
  filter: var(--caftan-fab-icon-filter);
}
#caftan-chat-widget #caftan-chat-toggle .caftan-toggle-ring {
  position: absolute; inset: -6px; border-radius: 50%;
  border: 1.5px solid #111; opacity: 0.35;
  animation: caftan-ring 2.4s ease-out infinite; pointer-events: none;
}
#caftan-chat-widget.caftan-theme-dark #caftan-chat-toggle .caftan-toggle-ring {
  border-color: #fff;
}
#caftan-chat-widget.is-open #caftan-chat-toggle .caftan-toggle-ring { display: none; }
@keyframes caftan-ring {
  0% { transform: scale(0.92); opacity: 0.45; }
  100% { transform: scale(1.28); opacity: 0; }
}
#caftan-chat-widget #caftan-chat-toggle .caftan-icon-close { display: none; }
#caftan-chat-widget.is-open #caftan-chat-toggle .caftan-icon-chat { display: none; }
#caftan-chat-widget.is-open #caftan-chat-toggle .caftan-icon-close { display: block; }

#caftan-chat-badge {
  position: absolute; top: -1px; right: -1px; min-width: 20px; height: 20px;
  border-radius: 999px; background: #111; color: #fff; font-size: 11px; font-weight: 700;
  align-items: center; justify-content: center; padding: 0 5px; border: 2px solid #fff;
}
#caftan-chat-widget.caftan-theme-dark #caftan-chat-badge {
  background: #fff; color: #111; border-color: #111;
}

/* Popup — plus compact */
#caftan-chat-popup {
  position: fixed; bottom: 98px; width: 360px; height: 480px;
  max-height: calc(100vh - 120px); background: var(--caftan-bg); color: var(--caftan-bubble-bot-text);
  border-radius: 16px;
  box-shadow: 0 18px 40px rgba(0,0,0,0.2), 0 0 0 1px var(--caftan-border);
  display: flex; flex-direction: column; overflow: hidden; z-index: 999999;
  opacity: 0; transform: translateY(16px) scale(0.96); pointer-events: none;
  transition: opacity 0.28s cubic-bezier(0.22,1,0.36,1), transform 0.28s cubic-bezier(0.22,1,0.36,1);
}
#caftan-chat-popup.is-visible { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
#caftan-chat-popup[hidden] { display: none !important; }

/* Header — une seule ligne fine */
#caftan-chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: #0a0a0a;
  border-bottom: 1px solid rgba(255,255,255,0.08); flex-shrink: 0;
  height: 48px; box-sizing: border-box;
}
#caftan-chat-logo {
  display: block; width: 28px; height: 28px; object-fit: contain; flex-shrink: 0;
  border-radius: 6px;
}
.caftan-header-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
#caftan-chat-botname {
  font-weight: 700; font-size: 13px; color: #ffffff; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#caftan-chat-status { font-size: 10px; color: #a8a8a8; display: flex; align-items: center; gap: 5px; line-height: 1.1; }
.caftan-status-dot { width: 6px; height: 6px; border-radius: 50%; background: #2ecc71; flex-shrink: 0; animation: caftan-online 1.9s infinite; }
@keyframes caftan-online {
  0% { box-shadow: 0 0 0 0 rgba(46,204,113,0.5); }
  70% { box-shadow: 0 0 0 6px rgba(46,204,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(46,204,113,0); }
}
#caftan-chat-close {
  all: unset; width: 26px; height: 26px; border-radius: 6px;
  color: #b0b0b0; cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#caftan-chat-close:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* Messages */
#caftan-chat-messages {
  flex: 1; overflow-y: auto; padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--caftan-messages-bg);
  scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.2) transparent;
  min-height: 0;
}
.caftan-msg { display: flex; flex-direction: column; max-width: 100%; width: 100%; animation: caftan-msg-in 0.28s cubic-bezier(0.22,1,0.36,1); }
@keyframes caftan-msg-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.caftan-msg-user { align-self: flex-end; align-items: flex-end; width: auto; max-width: 88%; }
.caftan-msg-assistant { align-self: stretch; align-items: stretch; width: 100%; max-width: 100%; }
.caftan-msg-row { display: flex; align-items: flex-start; gap: 8px; max-width: 100%; width: 100%; }

.caftan-mini-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #ffffff; color: #111;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12);
  overflow: hidden;
}
#caftan-chat-widget.caftan-theme-dark .caftan-mini-avatar {
  background: #222; box-shadow: 0 0 0 1px rgba(255,255,255,0.2);
}
.caftan-mini-avatar img.caftan-bot-face {
  width: 16px; height: 16px; display: block; object-fit: contain;
  filter: var(--caftan-fab-icon-filter);
}

.caftan-bubble {
  flex: 1; min-width: 0;
  padding: 10px 12px; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap;
  font-size: 13.5px; line-height: 1.5; box-shadow: none;
}
.caftan-msg-user .caftan-bubble {
  background: var(--caftan-bubble-user-bg);
  color: var(--caftan-bubble-user-text);
  border-radius: 16px 16px 4px 16px; font-weight: 500;
  flex: 0 1 auto;
}
.caftan-msg-assistant .caftan-bubble {
  background: var(--caftan-bubble-bot-bg); color: var(--caftan-bubble-bot-text);
  border-radius: 4px 14px 14px 14px; border: 1px solid var(--caftan-border);
}
.caftan-msg-welcome .caftan-bubble {
  border-color: rgba(0,0,0,0.18);
}
.caftan-bubble a.caftan-link-chip, .caftan-bubble a {
  display: inline-block; margin-top: 4px; margin-right: 4px; padding: 4px 10px; border-radius: 999px;
  background: var(--caftan-link-bg); border: 1px solid var(--caftan-link-border);
  color: var(--caftan-link-color) !important; text-decoration: none !important;
  font-size: 12px; font-weight: 600;
}
.caftan-msg-user .caftan-bubble a {
  background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.35); color: #fff !important;
}
#caftan-chat-widget.caftan-theme-dark .caftan-msg-user .caftan-bubble a {
  background: rgba(0,0,0,0.08); border-color: rgba(0,0,0,0.2); color: #111 !important;
}
.caftan-bubble-error { font-style: italic; opacity: 0.9; }
.caftan-msg-time { font-size: 10px; color: var(--caftan-muted); margin-top: 5px; padding: 0 6px; }

.caftan-typing { display: flex; align-items: center; gap: 5px; padding: 14px 16px; }
.caftan-typing span {
  width: 7px; height: 7px; border-radius: 50%; background: #111;
  animation: caftan-pulse 1.2s infinite ease-in-out;
}
#caftan-chat-widget.caftan-theme-dark .caftan-typing span { background: #fff; }
.caftan-typing span:nth-child(2) { animation-delay: 0.15s; }
.caftan-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes caftan-pulse {
  0%,80%,100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Bas unifié : WhatsApp + saisie (plus de “blocs séparés”) */
#caftan-chat-composer {
  flex-shrink: 0; padding: 8px 10px 8px; background: var(--caftan-composer-bg);
  border-top: 1px solid var(--caftan-border);
  display: flex; flex-direction: column; gap: 6px;
}
.caftan-advisor-btn,
#caftan-advisor-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 0; padding: 8px 10px; border-radius: 10px;
  background: #25d366; color: #fff !important;
  text-decoration: none !important; font-weight: 700; font-size: 12px;
  box-shadow: none; flex-shrink: 0;
}
.caftan-advisor-btn[hidden], #caftan-advisor-btn[hidden] { display: none !important; }
.caftan-whatsapp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  align-self: center; width: fit-content; max-width: 94%; margin: 2px auto 4px;
  padding: 10px 14px; background: #25d366; color: #fff !important;
  text-decoration: none !important; border-radius: 999px; font-weight: 700; font-size: 12px;
}
#caftan-chat-input-area {
  display: flex; align-items: center; gap: 0;
  padding: 4px 4px 4px 12px;
  background: var(--caftan-input-bg);
  border: 1px solid var(--caftan-border);
  border-radius: 999px;
  box-shadow: none;
  overflow: hidden;
}
#caftan-chat-input-area:focus-within {
  border-color: #111;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.06);
}
#caftan-chat-widget.caftan-theme-dark #caftan-chat-input-area:focus-within {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.08);
}
/* Neutraliser styles thème WP / navigateur (évite double cadre) */
#caftan-chat-widget #caftan-chat-input {
  flex: 1 !important;
  min-width: 0 !important;
  width: 100% !important;
  height: 36px !important;
  margin: 0 !important;
  padding: 0 8px 0 0 !important;
  border: 0 !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
  background-color: transparent !important;
  border-radius: 0 !important;
  color: var(--caftan-bubble-bot-text) !important;
  font-size: 16px !important; /* 16px = pas de zoom iOS */
  line-height: 36px !important;
  -webkit-appearance: none !important;
  appearance: none !important;
}
#caftan-chat-widget #caftan-chat-input:focus,
#caftan-chat-widget #caftan-chat-input:active {
  border: 0 !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent !important;
}
#caftan-chat-input::placeholder { color: var(--caftan-muted); opacity: 1; }
#caftan-chat-widget #caftan-chat-send {
  all: unset;
  width: 34px !important;
  height: 34px !important;
  border-radius: 50% !important;
  background: #111111 !important;
  color: #ffffff !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  flex-shrink: 0 !important;
}
#caftan-chat-widget.caftan-theme-dark #caftan-chat-send {
  background: #ffffff !important;
  color: #111111 !important;
}
#caftan-chat-widget #caftan-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
#caftan-chat-footer {
  display: flex; align-items: center; justify-content: center; gap: 5px; margin-top: 0;
  font-size: 9px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--caftan-muted);
}
.caftan-footer-dot { width: 4px; height: 4px; border-radius: 50%; background: #111; }
#caftan-chat-widget.caftan-theme-dark .caftan-footer-dot { background: #fff; }

/* Tablette / petit desktop */
@media (max-width: 768px) {
  #caftan-chat-popup {
    width: min(380px, calc(100vw - 24px));
    height: min(520px, calc(100dvh - 110px));
    max-height: calc(100dvh - 110px);
  }
}

/* Mobile plein écran */
@media (max-width: 480px) {
  #caftan-chat-widget {
    --caftan-offset: 14px;
  }
  #caftan-chat-fab-wrap {
    bottom: calc(var(--caftan-offset) + env(safe-area-inset-bottom, 0px));
  }
  #caftan-chat-widget #caftan-chat-toggle {
    width: 58px !important;
    height: 58px !important;
  }
  #caftan-chat-popup {
    width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    border-radius: 0 !important;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #caftan-chat-header {
    height: 52px;
    padding: 8px 12px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    height: auto;
    min-height: 52px;
  }
  #caftan-chat-messages {
    padding: 12px;
    gap: 10px;
  }
  #caftan-chat-composer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 8px;
  }
  .caftan-advisor-btn,
  #caftan-advisor-btn {
    padding: 11px 12px;
    font-size: 13px;
    border-radius: 12px;
  }
  #caftan-chat-widget #caftan-chat-input {
    height: 40px !important;
    line-height: 40px !important;
  }
  #caftan-chat-widget #caftan-chat-send {
    width: 38px !important;
    height: 38px !important;
  }
  /* Sur mobile ouvert : FAB masqué (fermeture via X header) */
  #caftan-chat-widget.is-open #caftan-chat-fab-wrap {
    display: none;
  }
}
