/* ============================================================
   Chatbot visiteur : bulle flottante et panneau de discussion
   Charge uniquement quand le widget est actif (partials/chatbot.php).
   z-index : au-dessus de l'en-tete (100) et du sous-menu (120), sous la lightbox (1000).
   ============================================================ */

.abo-chat { --chat-gap: 1.25rem; --chat-bottom: calc(var(--chat-gap) + env(safe-area-inset-bottom, 0px)); font-family:'Fira Sans', system-ui, sans-serif; }
.abo-chat[hidden], .abo-chat [hidden] { display:none !important; }

/* Texte reserve aux lecteurs d'ecran */
.abo-chat-sr { position:absolute; width:1px; height:1px; margin:-1px; padding:0; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0; }

/* --- Bulle --- */
.abo-chat-bubble {
  position:fixed; right:calc(var(--chat-gap) + env(safe-area-inset-right, 0px)); bottom:var(--chat-bottom); z-index:500;
  width:3.5rem; height:3.5rem; display:grid; place-items:center;
  border:2px solid #fff; border-radius:var(--radius-pill); background:var(--blue); color:#fff; cursor:pointer;
  box-shadow:0 12px 32px rgba(0,0,255,.18), var(--shadow-md);
  transition:background var(--dur-base) var(--ease-tide), transform var(--dur-base) var(--ease-tide);
  -webkit-tap-highlight-color:transparent;
}
.abo-chat-bubble:hover { background:var(--blue-deep); transform:translateY(-2px); }
.abo-chat-bubble:focus-visible { outline:3px solid var(--blue-cyan); outline-offset:3px; }
.abo-chat-bubble svg { width:1.6rem; height:1.6rem; }
.abo-chat.is-open .abo-chat-bubble { visibility:hidden; }

/* Le menu mobile ouvert et la visionneuse passent devant : la bulle s'efface */
body:has(.site-nav.nav-open) .abo-chat-bubble,
html.is-lightbox-open .abo-chat { visibility:hidden; }

/* --- Panneau --- */
.abo-chat-panel {
  position:fixed; z-index:510;
  right:calc(var(--chat-gap) + env(safe-area-inset-right, 0px)); bottom:var(--chat-bottom);
  width:min(24rem, calc(100vw - 2 * var(--chat-gap)));
  height:min(38rem, calc(100vh - 2 * var(--chat-gap) - 4rem));
  display:flex; flex-direction:column; overflow:hidden;
  background:#fff; color:var(--fg-1);
  border:1px solid var(--border); border-radius:1rem;
  box-shadow:0 10px 34px rgba(24,51,131,.16), var(--shadow-lg);
  font-size:var(--text-sm); line-height:1.55;
}

.abo-chat-head { display:flex; align-items:center; gap:.75rem; padding:.875rem 1rem; background:var(--blue); color:#fff; flex:0 0 auto; }
.abo-chat-avatar { width:2.25rem; height:2.25rem; flex:0 0 2.25rem; display:grid; place-items:center; border-radius:var(--radius-pill); background:rgba(255,255,255,.16); }
.abo-chat-avatar svg { width:1.2rem; height:1.2rem; }
.abo-chat-head-text { flex:1 1 auto; min-width:0; }
.abo-chat-title { font-size:1rem; font-weight:700; line-height:1.25; margin:0; color:#fff; }
.abo-chat-subtitle { font-size:var(--text-xs); opacity:.85; margin:0; }
.abo-chat-close { width:2.25rem; height:2.25rem; flex:0 0 2.25rem; display:grid; place-items:center; border:1px solid rgba(255,255,255,.45); border-radius:var(--radius-pill); background:transparent; color:#fff; cursor:pointer; transition:background var(--dur-base) var(--ease-tide), color var(--dur-base) var(--ease-tide); }
.abo-chat-close:hover { background:#fff; color:var(--blue); }
.abo-chat-close:focus-visible { outline:3px solid var(--blue-cyan); outline-offset:2px; }
.abo-chat-close svg { width:1.1rem; height:1.1rem; }

.abo-chat-scroll { flex:1 1 auto; overflow-y:auto; overscroll-behavior:contain; padding:1rem; display:flex; flex-direction:column; gap:.75rem; background:var(--bg-alt); position:relative; }

.abo-chat-notice { font-size:var(--text-xs); color:var(--fg-2); background:#fff; border:1px solid var(--border); border-radius:.75rem; padding:.75rem .875rem; }
.abo-chat-notice p { margin:0 0 .35rem; }
.abo-chat-notice a, .abo-chat-check a { color:var(--blue); font-weight:600; text-decoration:underline; }

/* --- Messages --- */
.abo-chat-log { display:flex; flex-direction:column; gap:.625rem; }
.abo-chat-msg { max-width:88%; padding:.625rem .875rem; border-radius:1rem; white-space:pre-wrap; overflow-wrap:anywhere; word-break:normal; }
.abo-chat-msg--user { align-self:flex-end; background:var(--blue); color:#fff; border-bottom-right-radius:var(--radius-sm); }
.abo-chat-msg--assistant { align-self:flex-start; background:#fff; color:var(--fg-1); border:1px solid var(--border); border-bottom-left-radius:var(--radius-sm); box-shadow:var(--shadow-sm); }
.abo-chat-msg--info { align-self:stretch; max-width:none; background:#fff; color:var(--fg-1); border:1px solid var(--border); border-left:3px solid var(--blue-cyan); border-radius:.75rem; }

/* --- Indicateur de redaction --- */
.abo-chat-typing { display:flex; align-items:center; gap:.5rem; align-self:flex-start; font-size:var(--text-xs); color:var(--fg-2); }
.abo-chat-dots { display:inline-flex; gap:.2rem; padding:.55rem .7rem; background:#fff; border:1px solid var(--border); border-radius:1rem; }
.abo-chat-dots span { width:.4rem; height:.4rem; border-radius:50%; background:var(--blue); opacity:.35; animation:abo-chat-dot 1.2s infinite var(--ease-tide); }
.abo-chat-dots span:nth-child(2) { animation-delay:.2s; }
.abo-chat-dots span:nth-child(3) { animation-delay:.4s; }
@keyframes abo-chat-dot { 0%, 80%, 100% { opacity:.35; transform:translateY(0); } 40% { opacity:1; transform:translateY(-3px); } }

/* --- Formulaire de rappel --- */
.abo-chat-lead, .abo-chat-closed { background:#fff; border:1px solid var(--border); border-radius:.75rem; padding:.875rem; display:flex; flex-direction:column; gap:.75rem; }
.abo-chat-lead-intro, .abo-chat-closed p { margin:0; color:var(--fg-1); }
.abo-chat-field { display:flex; flex-direction:column; gap:.3rem; }
.abo-chat-field > label:not(.abo-chat-check) { font-size:var(--text-xs); font-weight:700; color:var(--fg-1); text-transform:uppercase; letter-spacing:.08em; }
.abo-chat-field input[type="text"], .abo-chat-field input[type="email"] {
  font-family:inherit; font-size:.9375rem; padding:.6rem .75rem; border-radius:.5rem;
  background:#fff; border:1px solid var(--border); color:var(--fg-1); outline:none;
  transition:border-color .2s, box-shadow .2s;
}
.abo-chat-field input:focus { border-color:var(--blue); box-shadow:0 0 0 3px rgba(0,0,255,.08); }
.abo-chat-field input[aria-invalid="true"] { border-color:rgba(220,53,53,.6); }
.abo-chat-check { display:flex; align-items:flex-start; gap:.5rem; font-size:var(--text-xs); color:var(--fg-2); cursor:pointer; }
.abo-chat-check input { margin-top:.2rem; flex:0 0 auto; accent-color:var(--blue); }
.abo-chat-field-error { margin:0; font-size:var(--text-xs); color:#8b1a1a; }
.abo-chat-lead-submit, .abo-chat-closed .btn { align-self:stretch; }
.abo-chat-lead-submit:disabled { opacity:.6; cursor:wait; }

/* Champ piege : hors ecran pour les humains */
.abo-chat-trap { position:absolute; left:-10000px; top:auto; width:1px; height:1px; overflow:hidden; }

/* --- Erreurs --- */
.abo-chat-error { margin:0; padding:.625rem .875rem; border-radius:.5rem; font-size:var(--text-xs); background:rgba(220,53,53,.1); border:1px solid rgba(220,53,53,.3); color:#8b1a1a; }

/* --- Zone de saisie --- */
.abo-chat-form { flex:0 0 auto; padding:.75rem 1rem calc(.75rem + env(safe-area-inset-bottom, 0px)); border-top:1px solid var(--border); background:#fff; display:flex; flex-direction:column; gap:.4rem; }
.abo-chat-compose { display:flex; align-items:flex-end; gap:.5rem; }
.abo-chat-compose textarea {
  flex:1 1 auto; min-width:0; resize:none; font-family:inherit; font-size:.9375rem; line-height:1.4;
  padding:.55rem .75rem; border-radius:.75rem; border:1px solid var(--border); background:#fff; color:var(--fg-1);
  max-height:6rem; outline:none; transition:border-color .2s, box-shadow .2s;
}
.abo-chat-compose textarea:focus { border-color:var(--blue); box-shadow:0 0 0 3px rgba(0,0,255,.08); }
.abo-chat-compose textarea:disabled { background:var(--bg-alt); color:var(--fg-3); cursor:not-allowed; }
.abo-chat-send {
  flex:0 0 auto; font-family:inherit; font-size:var(--text-sm); font-weight:600;
  padding:.6rem 1rem; border-radius:var(--radius-pill); border:2px solid var(--blue);
  background:var(--blue); color:#fff; cursor:pointer; transition:background var(--dur-base) var(--ease-tide), border-color var(--dur-base) var(--ease-tide);
}
.abo-chat-send:hover { background:var(--blue-deep); border-color:var(--blue-deep); }
.abo-chat-send:disabled { opacity:.5; cursor:not-allowed; background:var(--blue); border-color:var(--blue); }
.abo-chat-send:focus-visible, .abo-chat-contact:focus-visible, .abo-chat-notice a:focus-visible { outline:3px solid var(--blue-cyan); outline-offset:2px; }
.abo-chat-meta { display:flex; justify-content:space-between; gap:.75rem; font-size:var(--text-xs); color:var(--fg-3); }
.abo-chat-contact { align-self:flex-start; font-size:var(--text-xs); font-weight:600; color:var(--blue); }

/* --- Mobile : panneau quasi plein ecran --- */
@media (max-width:599px) {
  .abo-chat { --chat-gap: 1rem; }
  .abo-chat-panel {
    top:max(.5rem, env(safe-area-inset-top, 0px)); bottom:max(.5rem, env(safe-area-inset-bottom, 0px));
    left:.5rem; right:.5rem; width:auto; height:auto; border-radius:1rem;
  }
  .abo-chat-form { padding-bottom:.75rem; }
  /* Bas du pied de page degage : la bulle ne recouvre pas les mentions */
  .site-footer-v2 { padding-bottom:calc(4.5rem + env(safe-area-inset-bottom, 0px)); }
  /* 16 px minimum : evite le zoom automatique d'iOS au focus */
  .abo-chat-compose textarea, .abo-chat-field input[type="text"], .abo-chat-field input[type="email"] { font-size:1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .abo-chat-bubble, .abo-chat-close, .abo-chat-send { transition:none; }
  .abo-chat-bubble:hover { transform:none; }
  .abo-chat-dots span { animation:none; opacity:.7; }
}
