/* =========================================================================
   LockLead — Chatbot widget (production)
   Bulle en bas à droite. Responsive : panneau ancré sur desktop,
   plein écran sur mobile. Préfixe .ll- pour ne rien casser sur le site.
   ========================================================================= */

.ll-chat,
.ll-chat * {
  box-sizing: border-box;
}

.ll-chat {
  --ll-navy: #1a365d;
  --ll-navy-700: #16314f;
  --ll-accent: #e0651a;
  --ll-bg: #ffffff;
  --ll-bubble-bot: #f1f5f9;
  --ll-bubble-user: #1a365d;
  --ll-text: #1f2937;
  --ll-text-soft: #64748b;
  --ll-border: #e7ecf2;
  --ll-radius: 16px;
  --ll-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  position: fixed;
  z-index: 2147483000; /* au-dessus de tout */
  font-family: var(--ll-font);
}

/* ---------- Lanceur (la bulle) ---------- */
.ll-launcher {
  position: fixed;
  right: 20px;
  right: max(20px, env(safe-area-inset-right));
  bottom: 20px;
  bottom: max(20px, env(safe-area-inset-bottom));
  height: 60px;
  padding: 0;
  border: none;
  border-radius: 30px;
  background: var(--ll-navy);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(16, 31, 51, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 2147483001;
  animation: ll-pop 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}
@keyframes ll-pop {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.ll-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(16, 31, 51, 0.34);
}
.ll-launcher:active {
  transform: translateY(0);
}
.ll-launcher-ico {
  width: 60px;
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ll-launcher-ico svg {
  width: 28px;
  height: 28px;
}
.ll-launcher .ll-ico-close { display: none; }
.ll-chat.ll-open .ll-launcher .ll-ico-chat { display: none; }
.ll-chat.ll-open .ll-launcher .ll-ico-close { display: block; }

/* Label "Une question ?" : déplié (largeur animée) après chargement */
.ll-launcher-label {
  max-width: 0;
  white-space: nowrap;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  opacity: 0;
  transition: max-width 0.35s ease, opacity 0.25s ease, padding 0.35s ease;
  padding: 0;
}
.ll-chat.ll-label-visible .ll-launcher-label {
  max-width: 160px;
  opacity: 1;
  padding-left: 16px;
}
/* Quand le chat est ouvert, le lanceur redevient un rond simple */
.ll-chat.ll-open .ll-launcher { border-radius: 50%; }
.ll-chat.ll-open .ll-launcher-label { max-width: 0; opacity: 0; padding-left: 0; }

/* ---------- Bulle de message proactive ---------- */
.ll-proactive {
  position: fixed;
  right: 20px;
  right: max(20px, env(safe-area-inset-right));
  bottom: 92px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  max-width: 280px;
  background: #fff;
  color: var(--ll-text);
  font-size: 14.5px;
  line-height: 1.4;
  padding: 14px 16px 14px 16px;
  padding-right: 34px;
  border-radius: 16px;
  border-bottom-right-radius: 5px;
  box-shadow: 0 12px 32px rgba(16, 31, 51, 0.22);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 2147483000;
}
.ll-chat.ll-proactive-visible .ll-proactive {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
/* quand le panneau est ouvert, jamais de bulle proactive */
.ll-chat.ll-open .ll-proactive { opacity: 0 !important; pointer-events: none !important; }
.ll-proactive-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--ll-text-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.ll-proactive-close:hover { background: #f1f5f9; }
.ll-proactive-close svg { width: 13px; height: 13px; }
.ll-proactive-text {
  display: block;
  font-weight: 500;
}

/* ---------- Panneau ---------- */
.ll-panel {
  position: fixed;
  right: 20px;
  right: max(20px, env(safe-area-inset-right));
  bottom: 92px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: 384px;
  max-width: calc(100vw - 40px);
  height: 620px;
  max-height: calc(100dvh - 120px);
  background: var(--ll-bg);
  border: 1px solid var(--ll-border);
  border-radius: var(--ll-radius);
  box-shadow: 0 20px 60px rgba(16, 31, 51, 0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.ll-chat.ll-open .ll-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ---------- En-tête ---------- */
.ll-header {
  background: var(--ll-navy);
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.ll-header .ll-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ll-header .ll-avatar svg {
  width: 20px;
  height: 20px;
}
.ll-header .ll-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}
.ll-header .ll-sub {
  font-size: 12px;
  opacity: 0.8;
  margin-top: 2px;
}
.ll-header .ll-close {
  margin-left: auto;
  background: transparent;
  border: none;
  color: #fff;
  opacity: 0.85;
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 8px;
}
.ll-header .ll-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- Fil de messages ---------- */
.ll-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fbfcfd;
  scroll-behavior: smooth;
}
.ll-msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ll-msg-bot {
  align-self: flex-start;
  background: var(--ll-bubble-bot);
  color: var(--ll-text);
  border-bottom-left-radius: 5px;
}
.ll-msg-user {
  align-self: flex-end;
  background: var(--ll-bubble-user);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.ll-msg-error {
  align-self: flex-start;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-bottom-left-radius: 5px;
}

/* indicateur "en train d'écrire" */
.ll-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}
.ll-typing span {
  width: 7px;
  height: 7px;
  background: #9aa7b5;
  border-radius: 50%;
  animation: ll-bounce 1.2s infinite ease-in-out;
}
.ll-typing span:nth-child(2) { animation-delay: 0.18s; }
.ll-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes ll-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* curseur de frappe pendant le streaming */
.ll-caret::after {
  content: "▍";
  margin-left: 1px;
  color: var(--ll-text-soft);
  animation: ll-blink 1s steps(2) infinite;
}
@keyframes ll-blink { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

/* ---------- Boutons d'action (toujours visibles) ---------- */
.ll-actions {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--ll-border);
  background: var(--ll-bg);
}
.ll-action {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 8px;
  font-family: var(--ll-font);
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid var(--ll-border);
  transition: background 0.12s ease, border-color 0.12s ease;
}
.ll-action svg { width: 15px; height: 15px; flex-shrink: 0; }
.ll-action-primary {
  background: var(--ll-accent);
  color: #fff;
  border-color: var(--ll-accent);
}
.ll-action-primary:hover { background: #c8570f; }
.ll-action-secondary {
  background: #fff;
  color: var(--ll-navy);
}
.ll-action-secondary:hover { background: #f4f7fa; }

/* ---------- Saisie ---------- */
.ll-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--ll-border);
  background: var(--ll-bg);
  flex-shrink: 0;
}
.ll-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--ll-border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--ll-font);
  font-size: 14.5px;
  line-height: 1.4;
  max-height: 120px;
  color: var(--ll-text);
  background: #fff;
  outline: none;
}
.ll-input:focus { border-color: var(--ll-navy); }
.ll-input:disabled { background: #f4f6f8; color: #9aa7b5; }
.ll-send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: 12px;
  background: var(--ll-navy);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s ease, opacity 0.12s ease;
}
.ll-send:hover { background: var(--ll-navy-700); }
.ll-send:disabled { opacity: 0.4; cursor: not-allowed; }
.ll-send svg { width: 19px; height: 19px; }

.ll-footnote {
  text-align: center;
  font-size: 10.5px;
  color: var(--ll-text-soft);
  padding: 0 12px 8px;
  background: var(--ll-bg);
  flex-shrink: 0;
}

/* ---------- Mobile : plein écran ---------- */
@media (max-width: 480px) {
  .ll-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border: none;
    border-radius: 0;
  }
  .ll-chat.ll-open .ll-launcher {
    display: none; /* on libère l'écran ; la croix d'en-tête ferme */
  }
  .ll-msg { max-width: 90%; font-size: 15px; }

  /* Mobile : pas de bulle proactive (intrusif sur petit écran) */
  .ll-proactive { display: none !important; }
  /* Label gardé court et lisible */
  .ll-chat.ll-label-visible .ll-launcher-label { max-width: 130px; }
}

@media (prefers-reduced-motion: reduce) {
  .ll-panel, .ll-launcher, .ll-proactive, .ll-launcher-label { transition: none; }
  .ll-typing span, .ll-caret::after, .ll-launcher { animation: none; }
}
