/* ══════════════════════════════════════════════════════
   LegalFlash — Widget de chat (visiteur)
   Variables du design system uniquement (style.css).
   Le bouton WhatsApp flottant occupe le coin bas-droit (bottom:28px) :
   le lanceur du chat se place juste au-dessus.
══════════════════════════════════════════════════════ */
.lf-chat { position: fixed; right: 28px; bottom: 92px; z-index: 9990; font-family: var(--font-body); line-height: 1.5; }
.lf-chat.is-open { z-index: 10001; }
.lf-chat *, .lf-chat *::before, .lf-chat *::after { box-sizing: border-box; }
.lf-chat [hidden] { display: none !important; }

/* ── Lanceur ── */
.lf-chat-launcher {
  position: relative; display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; margin-left: auto; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--bolt); color: var(--navy-0);
  box-shadow: 0 6px 30px rgba(255,214,0,.35);
  transition: transform .2s, box-shadow .2s;
}
.lf-chat-launcher:hover { transform: scale(1.06); box-shadow: 0 10px 40px rgba(255,214,0,.5); }
.lf-chat-launcher svg { width: 26px; height: 26px; }
.lf-chat-badge {
  position: absolute; top: -5px; right: -5px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--danger); color: #fff; font: 700 .72rem/22px var(--font-head); text-align: center;
}

/* ── Fenêtre ── */
.lf-chat-panel {
  position: absolute; right: 0; bottom: 70px; display: flex; flex-direction: column;
  width: min(380px, calc(100vw - 32px)); height: min(600px, calc(100vh - 170px));
  background: var(--navy-2); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: 0 24px 80px rgba(0,0,0,.6); overflow: hidden;
}
.lf-chat-panel::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; z-index: 2; background: linear-gradient(90deg, var(--bolt), var(--bolt-2), transparent); }

.lf-chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: linear-gradient(135deg, var(--navy-3), var(--navy-4)); border-bottom: 1px solid var(--border-2); }
.lf-chat-head-text { flex: 1; min-width: 0; }
.lf-chat-title { display: block; margin: 0; font: 700 .95rem/1.2 var(--font-head); color: var(--white); }
.lf-chat-status { display: flex; align-items: center; gap: 6px; font-size: .74rem; color: var(--text-2); }
.lf-chat-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex-shrink: 0; }
.lf-chat-dot.is-on { background: var(--success); }
.lf-chat-x { flex-shrink: 0; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--text-1); font-size: 1.5rem; line-height: 1; cursor: pointer; }
.lf-chat-x:hover { background: rgba(255,255,255,.08); }

/* ── Messages ── */
.lf-chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.lf-cm { display: flex; flex-direction: column; max-width: 88%; }
.lf-cm-bubble { padding: 10px 14px; border-radius: 14px; font-size: .9rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.lf-cm-meta { margin-top: 3px; font-size: .68rem; color: var(--text-3); }
.lf-cm a { text-decoration: underline; text-underline-offset: 2px; }

.lf-cm-bot { align-self: flex-start; }
.lf-cm-bot .lf-cm-bubble { background: var(--navy-3); border: 1px solid var(--border-2); color: var(--text-1); border-bottom-left-radius: 4px; }
.lf-cm-bot a, .lf-cm-agent a, .lf-cm-system a { color: var(--bolt); }

.lf-cm-visitor { align-self: flex-end; align-items: flex-end; }
.lf-cm-visitor .lf-cm-bubble { background: var(--bolt); color: var(--navy-0); font-weight: 500; border-bottom-right-radius: 4px; }
.lf-cm-visitor.is-pending { opacity: .6; }

/* Conseiller humain : bordure jaune + nom → clairement distinct du bot */
.lf-cm-agent { align-self: flex-start; }
.lf-cm-agent .lf-cm-bubble { background: var(--navy-4); border: 1px solid var(--bolt); color: var(--white); border-bottom-left-radius: 4px; }
.lf-cm-agent .lf-cm-meta { color: var(--bolt); font-weight: 600; }

.lf-cm-system { align-self: center; max-width: 94%; text-align: center; }
.lf-cm-system .lf-cm-bubble { background: transparent; color: var(--text-2); font-size: .8rem; padding: 4px 8px; }

.lf-cm-typing .lf-cm-bubble { display: inline-flex; gap: 4px; padding: 12px 14px; }
.lf-cm-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--text-2); animation: lf-blink 1.2s infinite ease-in-out; }
.lf-cm-typing i:nth-child(2) { animation-delay: .2s; }
.lf-cm-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes lf-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ── Suggestions, avis ── */
.lf-chat-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.lf-chat-chips:empty { display: none; }
.lf-chip { min-height: 38px; padding: 8px 14px; border: 1px solid rgba(255,214,0,.4); border-radius: 20px; background: transparent; color: var(--text-1); font: 500 .8rem/1.3 var(--font-body); text-align: left; cursor: pointer; transition: background .15s, color .15s, border-color .15s; }
.lf-chip:hover { background: var(--bolt); color: var(--navy-0); border-color: var(--bolt); }
.lf-fb { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: .76rem; color: var(--text-2); }
.lf-fb button { min-height: 32px; padding: 4px 12px; border: 1px solid var(--border-2); border-radius: 16px; background: var(--navy-1); color: var(--text-1); font: 500 .76rem var(--font-body); cursor: pointer; }
.lf-fb button:hover { border-color: var(--bolt); }

/* ── Barre d'outils (humain / WhatsApp) ── */
.lf-chat-tools { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-top: 1px solid var(--border-2); background: var(--navy-1); }
.lf-tool { flex: 1; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border-2); border-radius: 8px; background: transparent; color: var(--text-1); font: 600 .76rem var(--font-head); text-decoration: none; cursor: pointer; }
.lf-tool:hover { border-color: var(--bolt); color: var(--white); opacity: 1; }
.lf-tool-wa { flex: 0 0 auto; border-color: rgba(37,211,102,.5); color: #25D366; }
.lf-tool-wa:hover { background: #25D366; color: #fff; border-color: #25D366; }
.lf-tool.is-pulse { border-color: var(--bolt); background: rgba(255,214,0,.12); animation: lf-pulse 2s infinite; }
@keyframes lf-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,214,0,.35); } 50% { box-shadow: 0 0 0 6px rgba(255,214,0,0); } }
.lf-tool-end { flex: 0 0 auto; border: 0; color: var(--text-3); font-weight: 500; }

/* ── Saisie ── */
.lf-chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--border-2); background: var(--navy-2); }
.lf-chat-input { flex: 1; min-height: 44px; max-height: 110px; resize: none; padding: 10px 12px; border: 1px solid var(--border-2); border-radius: 10px; background: var(--navy-1); color: var(--text-1); font: inherit; font-size: 1rem; line-height: 1.4; color-scheme: dark; }
.lf-chat-input::placeholder { color: var(--text-3); }
.lf-chat-input:focus-visible { outline: 2px solid var(--bolt); outline-offset: 1px; border-color: var(--bolt); }
.lf-chat-send { flex-shrink: 0; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border: 0; border-radius: 10px; background: var(--bolt); color: var(--navy-0); cursor: pointer; }
.lf-chat-send:disabled { opacity: .5; cursor: not-allowed; }
.lf-chat-send svg { width: 20px; height: 20px; }
.lf-chat-end { padding: 14px 16px; border-top: 1px solid var(--border-2); text-align: center; color: var(--text-2); font-size: .84rem; }
.lf-chat-end .lf-chip { margin-top: 10px; }

/* ── Formulaire de transfert (dans le fil) ── */
.lf-handoff { align-self: stretch; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--navy-1); display: flex; flex-direction: column; gap: 10px; }
.lf-handoff label { font: 600 .76rem var(--font-head); color: var(--text-1); }
.lf-handoff .lf-chat-input { width: 100%; min-height: 42px; }
.lf-handoff .lf-herr { margin: 2px 0 0; font-size: .74rem; color: var(--danger); }
.lf-handoff .lf-herr:empty { display: none; }
.lf-handoff-check { display: flex; align-items: flex-start; gap: 8px; font: 400 .74rem/1.45 var(--font-body) !important; color: var(--text-2) !important; }
.lf-handoff-check input { width: 18px; height: 18px; margin-top: 1px; flex-shrink: 0; accent-color: var(--bolt); }
.lf-handoff-actions { display: flex; gap: 8px; }
.lf-handoff-actions .lf-btn { flex: 1; justify-content: center; padding: 11px 14px; font-size: .82rem; }
.lf-handoff-actions .lf-btn:disabled { opacity: .6; cursor: progress; }
.lf-handoff-cancel { flex: 0 0 auto; padding: 0 12px; border: 1px solid var(--border-2); border-radius: 8px; background: transparent; color: var(--text-2); font: 500 .8rem var(--font-body); cursor: pointer; }
.lf-hp-chat { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.lf-chat :focus-visible { outline: 2px solid var(--bolt); outline-offset: 2px; }
.lf-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Mobile : feuille quasi plein écran ── */
@media (max-width: 640px) {
  .lf-chat { right: 16px; bottom: 84px; }
  .lf-chat.is-open .lf-chat-launcher { display: none; }
  .lf-chat-panel { position: fixed; left: 8px; right: 8px; bottom: 8px; width: auto; height: min(680px, calc(100vh - 16px)); height: min(680px, calc(100dvh - 16px)); border-radius: 16px; }
  .lf-chip { min-height: 42px; }
  .lf-cm { max-width: 92%; }
}

@media (prefers-reduced-motion: reduce) {
  .lf-chat-launcher, .lf-chip { transition: none; }
  .lf-cm-typing i, .lf-tool.is-pulse { animation: none; }
  .lf-cm-typing i { opacity: .6; }
}
