/* ==========================================================================
   Assistant IA — bouton flottant + overlay plein écran
   Mêmes tokens que le reste du plugin : navy #00004F, orange #E26600 (rare),
   Montserrat, angles droits (border-radius: 0) partout.
   ========================================================================== */

#arw-ai-fab-zone, #arw-ai-overlay {
  --ai-navy: #00004F;
  --ai-navy-2: #0E0E73;
  --ai-orange: #E26600;
  --ai-border: #E4E6F0;
  --ai-bg-soft: #F7F8FB;
  --ai-text: #20222E;
  --ai-text-muted: #6B6E82;
  font-family: 'Montserrat', sans-serif;
  box-sizing: border-box;
}
#arw-ai-overlay *, #arw-ai-fab-zone * { box-sizing: border-box; }

/* ------------------------------------------------------------ Bouton flottant */
#arw-ai-fab-zone {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 999998;
  display: flex;
  align-items: center;
  gap: 12px;
}

#arw-ai-fab {
  flex: none;
  width: 58px;
  height: 58px;
  border: none;
  border-radius: 0;
  background: var(--ai-navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 26px -8px rgba(0,0,60,.45);
  transition: transform .2s ease, background .2s ease;
  animation: arwAiPulse 2.6s ease-in-out 1.2s 2;
}
#arw-ai-fab:hover { background: var(--ai-navy-2); transform: translateY(-2px); }
#arw-ai-fab svg { width: 24px; height: 24px; }
#arw-ai-fab-zone.is-hidden { display: none; }

/* Infobulle discrète qui attire l'oeil à l'arrivée sur le site, puis
   s'efface d'elle-même : ne doit pas rester en permanence à l'écran. */
#arw-ai-fab-hint {
  order: -1;
  background: #fff;
  color: var(--ai-navy);
  border: 1px solid var(--ai-border);
  box-shadow: 0 8px 22px -10px rgba(0,0,60,.35);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(8px);
  transition: opacity .35s ease, transform .35s ease;
  pointer-events: none;
}
#arw-ai-fab-hint.is-visible {
  opacity: 1;
  transform: translateX(0);
}

@keyframes arwAiPulse {
  0%, 100% { box-shadow: 0 10px 26px -8px rgba(0,0,60,.45); }
  50% { box-shadow: 0 10px 26px -8px rgba(0,0,60,.45), 0 0 0 8px rgba(0,0,79,.12); }
}

@media (max-width: 560px) {
  #arw-ai-fab-hint { font-size: 12px; padding: 9px 12px; }
}

/* --------------------------------------------------------------- Overlay 100% */
/* 100dvh (hauteur de viewport "dynamique") suit le clavier virtuel sur
   mobile ; 100vh reste en repli pour les navigateurs qui ne le supportent
   pas encore. Sans ça, le clavier ouvert masque le champ de saisie. */
#arw-ai-overlay {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  z-index: 999999;
  background: #fff;
  display: flex;
  flex-direction: column;
  color: var(--ai-text);
  overflow: hidden;
}
#arw-ai-overlay[hidden] { display: none; }
body.arw-ai-locked { overflow: hidden; height: 100%; }

.arw-ai-header {
  flex: 0 0 auto;
  background: var(--ai-navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 14px 20px;
}
.arw-ai-header__title { font-weight: 700; font-size: 15.5px; }
#arw-ai-close {
  width: 44px; height: 44px; border-radius: 0;
  border: none;
  background: transparent; color: #fff;
  font-size: 30px; line-height: 1; font-weight: 300; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#arw-ai-close:hover, #arw-ai-close:active { background: rgba(255,255,255,.14); }

/* Zone de contenu : formulaire de contact OU fil de discussion, jamais les deux. */
.arw-ai-body {
  flex: 1 1 auto;
  min-height: 0; /* indispensable pour que le scroll interne fonctionne dans une colonne flex */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------------------------------------- Formulaire lead */
.arw-ai-lead {
  max-width: 420px;
  margin: auto;
  width: 100%;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.arw-ai-lead__intro { margin: 0 0 4px; font-size: 14.5px; color: var(--ai-text-muted); line-height: 1.6; }
.arw-ai-field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; color: var(--ai-text-muted); }
.arw-ai-field input {
  font-family: 'Montserrat', sans-serif; font-size: 16px; font-weight: 500; color: var(--ai-text);
  border: 1px solid var(--ai-border); border-radius: 0; padding: 13px 14px;
  min-height: 48px;
}
.arw-ai-field input:focus { outline: 2px solid var(--ai-navy); outline-offset: 1px; }

.arw-ai-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.arw-ai-lead__error { margin: 0; font-size: 13px; color: #B3261E; font-weight: 600; }

.arw-ai-lead__submit {
  border: none; border-radius: 0; background: var(--ai-navy); color: #fff;
  font-family: 'Montserrat', sans-serif; font-weight: 700; font-size: 14.5px;
  padding: 15px 20px; min-height: 48px; cursor: pointer; margin-top: 4px;
}
.arw-ai-lead__submit:hover { background: var(--ai-navy-2); }
.arw-ai-lead__submit:disabled { opacity: .6; cursor: default; }

/* -------------------------------------------------------------------- Thread */
.arw-ai-thread {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* C'est CE conteneur qui scrolle réellement (et pas son parent) : le JS
   doit cibler #arw-ai-messages pour que le scroll automatique fonctionne. */
.arw-ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  max-width: 760px; width: 100%; margin: 0 auto;
  padding: 20px 20px 12px;
  display: flex; flex-direction: column; gap: 14px;
}

.arw-ai-msg { display: flex; }
.arw-ai-msg.is-user { justify-content: flex-end; }
.arw-ai-msg.is-model { justify-content: flex-start; }
.arw-ai-msg .bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 0;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.arw-ai-msg.is-user .bubble { background: var(--ai-navy); color: #fff; }
.arw-ai-msg.is-model .bubble { background: var(--ai-bg-soft); color: var(--ai-text); border: 1px solid var(--ai-border); }
.arw-ai-msg.is-error .bubble { background: #FBEAEA; color: #7A1F17; border: 1px solid #EAC6C3; }
.arw-ai-msg .bubble strong { font-weight: 700; color: inherit; }
.arw-ai-msg .bubble .arw-ai-list {
  margin: 6px 0 4px; padding-left: 20px;
}
.arw-ai-msg .bubble .arw-ai-list li { margin-bottom: 4px; }
.arw-ai-msg.is-user .bubble .arw-ai-list { list-style-type: '– '; }
.arw-ai-msg.is-model .bubble .arw-ai-list { list-style-type: '– '; color: var(--ai-navy); }
.arw-ai-msg.is-model .bubble .arw-ai-list li { color: var(--ai-text); }

.arw-ai-typing .bubble { display: flex; align-items: center; gap: 5px; padding: 14px 16px; }
.arw-ai-typing .dot { width: 6px; height: 6px; background: var(--ai-text-muted); border-radius: 50%; animation: arwAiBounce 1s infinite ease-in-out; }
.arw-ai-typing .dot:nth-child(2) { animation-delay: .15s; }
.arw-ai-typing .dot:nth-child(3) { animation-delay: .3s; }
@keyframes arwAiBounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ------------------------------------------------------------------ Composer */
/* Toujours visible, jamais recouvert par le clavier virtuel (grâce au
   100dvh sur l'overlay) ; padding-bottom tient compte de l'encoche/barre
   de gestes iOS via env(safe-area-inset-bottom). */
.arw-ai-composer {
  flex: 0 0 auto;
  max-width: 760px; width: 100%; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom, 0px));
}
.arw-ai-composer[hidden] { display: none; }
.arw-ai-composer textarea {
  flex: 1 1 auto; resize: none;
  font-family: 'Montserrat', sans-serif; font-size: 16px; color: var(--ai-text);
  border: 1px solid var(--ai-border); border-radius: 0;
  padding: 13px 14px; min-height: 48px; max-height: 140px; line-height: 1.4;
}
.arw-ai-composer textarea:focus { outline: 2px solid var(--ai-navy); outline-offset: 1px; }
.arw-ai-composer button {
  flex: none; width: 48px; height: 48px;
  border: none; border-radius: 0; background: var(--ai-navy); color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.arw-ai-composer button:hover { background: var(--ai-navy-2); }
.arw-ai-composer button:disabled { opacity: .5; }
.arw-ai-composer button svg { width: 18px; height: 18px; }

.arw-ai-footer {
  flex: 0 0 auto;
  text-align: center; font-size: 11.5px; color: var(--ai-text-muted);
  padding: 0 20px calc(10px + env(safe-area-inset-bottom, 0px));
  margin: 0;
}
.arw-ai-footer a { color: var(--ai-navy); font-weight: 700; margin-left: 6px; }

@media (max-width: 560px) {
  .arw-ai-lead { padding: 22px 16px; }
  .arw-ai-messages { padding: 16px 12px 8px; }
  .arw-ai-composer { padding: 10px 10px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .arw-ai-msg .bubble { max-width: 88%; }
}

@media (prefers-reduced-motion: reduce) {
  #arw-ai-fab, .arw-ai-typing .dot, .arw-ai-messages { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
