*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ════════════════════════════════════════
   TOKENS — thème sombre (défaut)
════════════════════════════════════════ */
:root,
[data-theme="dark"] {
  --bg:             #0f1115;
  --bg-messages:    #131722;
  --surface:        #1c2133;
  --surface-2:      #232b3e;
  --surface-3:      #2a334a;
  --border:         #252d3d;
  --border-subtle:  #1e2536;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.35);
  --shadow-md:      0 4px 16px rgba(0,0,0,.4);
  --shadow-lg:      0 8px 32px rgba(0,0,0,.5);
  --text:           #e2e8f0;
  --text-sub:       #8b95aa;
  --muted:          #4a5568;
  --accent:         #4f9cf9;
  --accent-hover:   #6aaafc;
  --accent-text:    #fff;
  --success:        #34d399;
  --danger:         #f87171;
  --warning:        #fbbf24;
  --bubble-self-bg:         #2563eb;
  --bubble-self-txt:        #eff6ff;
  --partner-neutral-bg:     #1e2740;
  --partner-neutral-txt:    #cbd5e1;
  --partner-blue-bg:        #0f2a52;
  --partner-blue-txt:       #93c5fd;
  --partner-pink-bg:        #2d1040;
  --partner-pink-txt:       #f9a8d4;
  --header-bg:      #171b26;
  --input-bg:       #1a1f30;
  --input-border:   #2a334a;
  --toast-bg:       #2d1a1a;
  --toast-border:   #7f1d1d;
  --toast-text:     #fca5a5;
  --modal-bg:       rgba(0,0,0,.8);
  --modal-surface:  #1a1f2e;
  /* Footer — contraste lisible mais discret */
  --footer-color:   #5d6675;
  --footer-bg:      transparent;
  --meta-theme:     #0f1115;
  /* Bannière reconnexion */
  --banner-warn-bg: #1c1207;
  --banner-warn:    #d97706;
  --banner-ok-bg:   #052e16;
  --banner-ok:      #34d399;
  --banner-border:  #2a334a;
}

/* ════════════════════════════════════════
   TOKENS — thème clair
════════════════════════════════════════ */
[data-theme="light"] {
  --bg:             #f5f7fa;
  --bg-messages:    #ffffff;
  --surface:        #ffffff;
  --surface-2:      #f0f3f8;
  --surface-3:      #e8ecf3;
  --border:         #e5e7eb;
  --border-subtle:  #eff1f5;
  --shadow-sm:      0 1px 3px rgba(0,0,0,.07);
  --shadow-md:      0 4px 16px rgba(0,0,0,.09);
  --shadow-lg:      0 8px 32px rgba(0,0,0,.12);
  --text:           #111827;
  --text-sub:       #6b7280;
  --muted:          #9ca3af;
  --accent:         #2563eb;
  --accent-hover:   #1d4ed8;
  --accent-text:    #fff;
  --success:        #10b981;
  --danger:         #ef4444;
  --warning:        #f59e0b;
  --bubble-self-bg:         #2563eb;
  --bubble-self-txt:        #ffffff;
  --partner-neutral-bg:     #f1f5f9;
  --partner-neutral-txt:    #1e293b;
  --partner-blue-bg:        #dbeafe;
  --partner-blue-txt:       #1e40af;
  --partner-pink-bg:        #fce7f3;
  --partner-pink-txt:       #9d174d;
  --header-bg:      #eef1f5;
  --input-bg:       #ffffff;
  --input-border:   #e5e7eb;
  --toast-bg:       #fff1f2;
  --toast-border:   #fecdd3;
  --toast-text:     #be123c;
  --modal-bg:       rgba(0,0,0,.45);
  --modal-surface:  #ffffff;
  /* Footer — contraste lisible mais discret */
  --footer-color:   #7c8798;
  --footer-bg:      transparent;
  --meta-theme:     #eef1f5;
  /* Bannière reconnexion */
  --banner-warn-bg: #fffbeb;
  --banner-warn:    #92400e;
  --banner-ok-bg:   #f0fdf4;
  --banner-ok:      #15803d;
  --banner-border:  #e5e7eb;
}

/* ════════════════════════════════════════
   BASE
════════════════════════════════════════ */
html, body { height: 100%; }

/* Anti-zoom global : empêche le redimensionnement du texte sur iOS
   et supprime le double-tap zoom sur tous les éléments interactifs */
html {
  /* Empêche iOS de grossir le texte automatiquement en mode paysage */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Bloque le scroll horizontal à la racine */
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  transition: background .2s ease, color .2s ease;
  -webkit-font-smoothing: antialiased;
  /* Supprime le double-tap zoom + le délai 300ms sur tous les éléments.
     Plus fiable que user-scalable=no seul sur iOS récents. */
  touch-action: manipulation;
  width: 100%;
  max-width: 100%;
}

/* ════════════════════════════════════════
   BANNIÈRE DE RECONNEXION
════════════════════════════════════════ */
.reconnect-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 2000;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  border-bottom: 1px solid var(--banner-border);
  transition: transform .3s ease, opacity .3s ease;
}
.reconnect-banner.hidden {
  transform: translateY(-110%);
  opacity: 0;
  pointer-events: none;
}
.reconnect-banner.reconnecting {
  background: var(--banner-warn-bg);
  color: var(--banner-warn);
}
.reconnect-banner.reconnected {
  background: var(--banner-ok-bg);
  color: var(--banner-ok);
}

/* ════════════════════════════════════════
   BOUTON ICÔNE — glassmorphism moderne
════════════════════════════════════════ */
.btn-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--text-sub);
  /* Glassmorphism — thème sombre */
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.13);
  box-shadow: 0 2px 8px rgba(0,0,0,0.22), inset 0 1px 0 rgba(255,255,255,0.07);
  /* Transition douce */
  transition: background .2s ease, transform .15s cubic-bezier(.34,1.56,.64,1),
              box-shadow .2s ease, border-color .2s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn-icon:hover {
  background: rgba(255,255,255,0.14);
  transform: scale(1.07);
  box-shadow: 0 4px 12px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.1);
}
.btn-icon:active {
  transform: scale(0.9);
  transition: transform .1s ease;
}

/* Thème clair — glassmorphism blanc */
[data-theme="light"] .btn-icon {
  background: rgba(255,255,255,0.72);
  border-color: rgba(0,0,0,0.1);
  box-shadow: 0 1px 6px rgba(0,0,0,0.1), inset 0 1px 0 rgba(255,255,255,0.9);
}
[data-theme="light"] .btn-icon:hover {
  background: rgba(255,255,255,0.92);
  box-shadow: 0 2px 10px rgba(0,0,0,0.13), inset 0 1px 0 rgba(255,255,255,1);
}

/* Variante compacte (header chat) */
.btn-icon-sm {
  width: 30px; height: 30px;
  border: none;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.btn-icon-sm:hover {
  background: rgba(255,255,255,0.1);
  box-shadow: none;
  transform: scale(1.07);
}
[data-theme="light"] .btn-icon-sm       { background: transparent; box-shadow: none; }
[data-theme="light"] .btn-icon-sm:hover { background: rgba(0,0,0,0.06); }

/* SVG à l'intérieur des boutons icône */
.btn-icon svg,
.btn-icon-sm svg {
  width: 16px; height: 16px;
  stroke: currentColor;
  display: block;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .15s ease;
  pointer-events: none;
}
.btn-icon-sm svg { width: 15px; height: 15px; }

/* Spans conteneurs des icônes — alignement flex */
.icon-dark, .icon-light,
.icon-sound-on, .icon-sound-off {
  display: flex; align-items: center; justify-content: center;
  line-height: 0;
}

/* Animation lors du changement d'état (classe ajoutée par JS) */
@keyframes icon-flip {
  0%   { transform: rotate(0deg)   scale(1); }
  45%  { transform: rotate(200deg) scale(0.72); }
  100% { transform: rotate(360deg) scale(1); }
}
.btn-spinning svg {
  animation: icon-flip .32s cubic-bezier(.4,0,.2,1);
}

/* Thème — affichage conditionnel des icônes */
[data-theme="dark"]  .icon-light { display: none; }
[data-theme="dark"]  .icon-dark  { display: flex; }
[data-theme="light"] .icon-dark  { display: none; }
[data-theme="light"] .icon-light { display: flex; }

/* Son — affichage conditionnel des icônes */
[data-sound="on"]  .icon-sound-off { display: none; }
[data-sound="on"]  .icon-sound-on  { display: flex; }
[data-sound="off"] .icon-sound-on  { display: none; }
[data-sound="off"] .icon-sound-off { display: flex; }

/* ════════════════════════════════════════
   MODAL +18
════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: var(--modal-surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 32px 32px;
  max-width: 360px; width: 100%;
  text-align: center;
  display: flex; flex-direction: column; gap: 16px;
  box-shadow: var(--shadow-lg);
  animation: pop-in .22s cubic-bezier(.34,1.56,.64,1);
}
@keyframes pop-in {
  from { transform: scale(.88); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.modal-icon   { font-size: 2.8rem; }
.modal-box h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -.2px; }
.modal-box p  { color: var(--text-sub); font-size: 14px; line-height: 1.65; }
.modal-box p strong { color: var(--text); font-weight: 600; }
.modal-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.modal-refuse  { color: var(--muted); font-size: 13px; text-decoration: none; padding: 4px 0; }
.modal-refuse:hover { color: var(--danger); }

/* ════════════════════════════════════════
   COMPTEUR EN LIGNE
════════════════════════════════════════ */
.dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  animation: dot-pulse 2.4s ease-in-out infinite;
}
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}
#user-count-badge {
  display: flex; align-items: center; gap: 7px;
  background: color-mix(in srgb, var(--success) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--success) 22%, transparent);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 13px; font-weight: 500;
  color: var(--success);
}

/* ════════════════════════════════════════
   FOOTER VERSION — contraste corrigé
════════════════════════════════════════ */
.app-footer {
  text-align: center;
  font-size: 12px;
  color: var(--footer-color);
  opacity: 0.65;
  padding: 10px 0 8px;
  letter-spacing: .15px;
  user-select: none;
  flex-shrink: 0;
  transition: color .2s;
}
.app-footer:hover { opacity: .9; }
/* Footer dans le chat : fond cohérent avec la barre d'actions */
.app-footer-chat {
  padding: 6px 0 8px;
  background: var(--header-bg);
  border-top: 1px solid var(--border-subtle);
}
.version-tag { font-weight: 600; }

/* ════════════════════════════════════════
   ÉCRAN ACCUEIL
════════════════════════════════════════ */
#screen-home {
  display: flex; flex-direction: column;
  flex: 1;
  padding: 20px 24px 0;
}
.home-topbar {
  display: flex; justify-content: space-between; align-items: center;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.home-center {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 28px;
  text-align: center;
}
.home-brand { display: flex; flex-direction: column; gap: 10px; align-items: center; }
#screen-home h1 {
  font-size: 2.4rem; font-weight: 800;
  letter-spacing: -1.5px; line-height: 1;
}
#screen-home h1 span { color: var(--accent); }
.home-tagline { color: var(--text-sub); font-size: 15px; max-width: 260px; line-height: 1.6; }

/* Badges de confiance */
.trust-row   { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 340px; }
.trust-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 13px;
  font-size: 12.5px; color: var(--text-sub); font-weight: 500;
  transition: transform .18s cubic-bezier(.34,1.56,.64,1), background .15s ease;
  cursor: default;
}
.trust-badge:hover { transform: translateY(-2px); background: var(--surface-3); }

/* ════════════════════════════════════════
   SÉLECTEUR DE COULEUR
════════════════════════════════════════ */
.color-picker { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.color-picker-label {
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1px; font-weight: 600;
}
.color-options { display: flex; gap: 10px; }
.color-btn {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  padding: 11px 16px;
  background: var(--surface); border: 2px solid var(--border);
  border-radius: 14px; cursor: pointer;
  color: var(--text-sub); font-size: 12px; font-weight: 500; font-family: inherit;
  min-width: 68px;
  transition: border-color .15s, background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}
.color-btn:hover  { border-color: var(--accent); color: var(--text); }
.color-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  color: var(--text);
}
.color-swatch { width: 22px; height: 22px; border-radius: 50%; display: block; }
.swatch-neutral { background: #94a3b8; }
.swatch-blue    { background: #3b82f6; }
.swatch-pink    { background: #ec4899; }

/* ════════════════════════════════════════
   BOUTON PRINCIPAL
════════════════════════════════════════ */
.btn-primary {
  padding: 15px 44px;
  border-radius: 14px; border: none;
  background: var(--accent); color: var(--accent-text);
  font-size: 15px; font-weight: 700;
  cursor: pointer; font-family: inherit;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: background .15s, transform .12s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary:hover  {
  background: var(--accent-hover);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 50%, transparent);
  transform: translateY(-2px);
}
.btn-primary:active { transform: scale(.97) translateY(0); }

/* ════════════════════════════════════════
   ÉCRAN CHAT
════════════════════════════════════════ */
#screen-chat {
  display: none; flex-direction: column;
  flex: 1; min-height: 0;
  background: var(--bg-messages);
}

/* ── Header ── */
#chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border-subtle);
  min-height: 54px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}

/* Bloc central statut */
#chat-status-block {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 2px;
}
.status-main-row {
  display: flex; align-items: center; gap: 6px;
}
#chat-status-icon { font-size: 13px; flex-shrink: 0; line-height: 1; }
#chat-status {
  font-size: 13.5px; font-weight: 600;
  color: var(--text-sub);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: color .2s;
}
#chat-status.connected { color: var(--success); }
#chat-status.waiting   { color: var(--accent); }
#chat-status.left      { color: var(--danger); }

/* Sous-texte contextuel dans le header */
.status-sub {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
  line-height: 1;
  animation: fade-in .2s ease;
}
.status-sub.hidden { display: none; }

/* Indicateur "écrit…" dans le header */
.typing-hint {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--text-sub);
  font-style: italic;
  animation: fade-in .15s ease;
}
.typing-hint.hidden { display: none; }
.typing-dots { display: flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--text-sub);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(-2px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Groupe droite du header */
.header-right-group {
  display: flex; align-items: center; gap: 6px; flex-shrink: 0;
}
#user-count-chat {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--success); font-weight: 500;
}

/* ── Zone d'attente ── */
#waiting-detail {
  display: none; flex: 1;
  flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px;
}
.wait-card {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 290px; width: 100%;
  box-shadow: var(--shadow-md);
  text-align: center;
  animation: card-enter .3s cubic-bezier(.34,1.3,.64,1) both;
}
@keyframes card-enter {
  from { opacity: 0; transform: translateY(12px) scale(.96); }
  to   { opacity: 1; transform: translateY(0)    scale(1);   }
}
.wait-spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.wait-title { font-size: 15px; font-weight: 600; color: var(--text); }
.wait-sub   { font-size: 13px; color: var(--text-sub); line-height: 1.6; }
.wait-sub.no-user { color: var(--muted); }

/* ── Messages ── */
#messages {
  flex: 1; overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex; flex-direction: column;
  gap: 3px;
  scroll-behavior: smooth;
}
#messages::-webkit-scrollbar { width: 4px; }
#messages::-webkit-scrollbar-track { background: transparent; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Carte de début de conversation (compacte) ── */
.conv-card {
  align-self: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  margin: 6px 0 10px;
  display: flex; flex-direction: column; gap: 6px;
  max-width: 280px; width: 100%;
  animation: msg-appear .25s ease both;
  box-shadow: var(--shadow-sm);
}
.conv-card-row {
  display: flex; align-items: center; gap: 9px;
  font-size: 12.5px; color: var(--text-sub);
}
.conv-card-row span:first-child { font-size: 14px; flex-shrink: 0; opacity: .85; }

/* ── Bulles ── */
.bubble + .bubble.self,
.bubble + .bubble.other { margin-top: 2px; }
.bubble + .system-msg,
.system-msg + .bubble   { margin-top: 8px; }

.bubble {
  /* Telegram-style : largeur min pour les messages courts */
  min-width: 64px;
  max-width: 72%;
  padding: 9px 13px;
  line-height: 1.55;
  word-break: break-word;
  font-size: 14.5px;
  animation: msg-appear .18s cubic-bezier(.2,.8,.4,1) both;
}
@keyframes msg-appear {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* Soi — bulle bleue, coin bas-droite coupé (Telegram) */
.bubble.self {
  background: var(--bubble-self-bg);
  color: var(--bubble-self-txt);
  border-radius: 18px 18px 4px 18px;
  align-self: flex-end;
  box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
/* Autre — coin bas-gauche coupé */
.bubble.other {
  background: var(--partner-neutral-bg);
  color: var(--partner-neutral-txt);
  border-radius: 18px 18px 18px 4px;
  align-self: flex-start;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.bubble.other.color-blue {
  background: var(--partner-blue-bg); color: var(--partner-blue-txt);
  border-color: color-mix(in srgb, var(--partner-blue-bg) 70%, var(--border));
}
.bubble.other.color-pink {
  background: var(--partner-pink-bg); color: var(--partner-pink-txt);
  border-color: color-mix(in srgb, var(--partner-pink-bg) 70%, var(--border));
}

.system-msg {
  text-align: center; color: var(--muted);
  font-size: 12.5px; padding: 4px 12px;
  font-style: italic;
  animation: msg-appear .18s ease both;
}

/* ── Saisie ── */
#input-area {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px;
  background: var(--header-bg);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  /* Empêche tout débordement — critique sur mobile */
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
}
#msg-input {
  /* flex: 1 1 0 + min-width: 0 : la paire obligatoire pour
     qu'un flex-enfant puisse rétrécir sous sa taille intrinsèque */
  flex: 1 1 0;
  min-width: 0;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 22px;
  padding: 10px 16px;
  color: var(--text); font-size: 14.5px;
  outline: none; resize: none; font-family: inherit;
  max-height: 120px; line-height: 1.45;
  transition: border-color .15s, box-shadow .15s;
}
#msg-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent);
}
#msg-input::placeholder { color: var(--muted); }
#msg-input:disabled     { opacity: .4; cursor: not-allowed; }

#btn-send {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
  -webkit-tap-highlight-color: transparent;
}
#btn-send:hover    { background: var(--accent-hover); transform: scale(1.05); }
#btn-send:active   { transform: scale(.95); }
#btn-send:disabled { background: var(--surface-3); box-shadow: none; cursor: not-allowed; }
#btn-send svg { width: 18px; height: 18px; fill: #fff; margin-left: 2px; }

/* ── Barre d'actions ── */
#action-bar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 8px 16px 10px;
  background: var(--header-bg);
}
.btn {
  border: none; border-radius: 10px;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 6px;
  transition: background .15s, color .15s, opacity .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .75; }
.btn-skip {
  padding: 9px 22px;
  background: var(--surface-2); color: var(--text-sub);
  border: 1px solid var(--border); flex: 0 0 auto;
}
.btn-skip:hover { background: var(--surface-3); color: var(--text); }
.btn-leave {
  padding: 9px 18px;
  background: transparent; color: var(--muted);
  border: 1px solid transparent; flex: 0 0 auto;
}
.btn-leave:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }

/* ── Indicateur de frappe (bulle messages) ── */
.typing-indicator {
  display: flex; align-items: center; gap: 4px;
  padding: 10px 13px;
  background: var(--partner-neutral-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 18px 18px 18px 4px;
  align-self: flex-start;
  animation: msg-appear .15s ease both;
}
.typing-indicator span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.3s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .15s; }
.typing-indicator span:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: .5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ════════════════════════════════════════
   TOAST ANTI-SPAM
════════════════════════════════════════ */
#spam-toast {
  position: fixed;
  bottom: 76px; left: 50%;
  transform: translateX(-50%);
  background: var(--toast-bg); border: 1px solid var(--toast-border);
  color: var(--toast-text);
  font-size: 13px; font-weight: 500;
  padding: 9px 18px; border-radius: 22px;
  pointer-events: none; opacity: 0;
  transition: opacity .22s;
  white-space: nowrap; z-index: 500;
  max-width: calc(100% - 32px); text-align: center;
  box-shadow: var(--shadow-md);
}
#spam-toast.show { opacity: 1; }

/* ════════════════════════════════════════
   MOBILE — correctifs spécifiques (≤ 640 px)
   Le rendu desktop reste inchangé.
════════════════════════════════════════ */
@media (max-width: 640px) {

  /* ── Anti-débordement horizontal ── */
  html, body {
    overflow-x: hidden;
    max-width: 100%;
    touch-action: manipulation;
  }

  /* ── font-size ≥ 16px sur tous les éléments interactifs ──
     iOS Safari zoome automatiquement sur tout input dont le
     font-size est < 16px. On couvre input, textarea, button et select. */
  input, textarea, button, select {
    font-size: 16px;
  }

  /* ── Zone de saisie — fix clavier iOS ── */
  #input-area {
    padding: 8px 12px;
    gap: 8px;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    overflow: hidden;
  }
  #msg-input {
    flex: 1 1 0;
    min-width: 0;
    width: 0;
    font-size: 16px;
    padding: 9px 12px;
  }
  /* Bouton envoyer — taille fixe, ne rétrécit jamais */
  #btn-send {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
  }

  /* ── Footer chat — masqué quand l'input est actif ──
     Libère de la place verticale quand le clavier est ouvert. */
  #input-area:focus-within ~ .app-footer-chat {
    display: none;
  }

  /* ── Footer — plus discret sur mobile ── */
  .app-footer {
    font-size: 11px;
    padding: 7px 0 6px;
    opacity: 0.55;
  }
  .app-footer-chat {
    padding: 5px 0;
    padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
  }

  /* ── Barre d'actions ── */
  #action-bar {
    gap: 8px;
    padding: 7px 14px;
    padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px));
    justify-content: center;
  }
  .btn-skip {
    padding: 8px 18px;
    font-size: 13px;
    flex: 0 0 auto;
  }
  .btn-leave {
    padding: 8px 14px;
    font-size: 13px;
    flex: 0 0 auto;
  }

  /* ── Carte de début de conversation ── */
  .conv-card {
    max-width: min(calc(100vw - 48px), 320px);
    padding: 8px 11px;
    gap: 5px;
    border-radius: 12px;
  }
  .conv-card-row { font-size: 12px; gap: 7px; }
  .conv-card-row span:first-child { font-size: 13px; }

  /* ── Zone d'attente ── */
  #waiting-detail { padding: 24px 16px; }
  .wait-card {
    padding: 26px 20px;
    gap: 12px;
    max-width: min(calc(100vw - 40px), 290px);
  }

  /* ── Header ── */
  #chat-header { padding: 7px 10px; min-height: 50px; gap: 8px; }
  #chat-status { font-size: 13px; }
  .status-sub  { font-size: 10.5px; max-width: 180px; }

  /* ── Messages ── */
  #messages { padding: 12px 10px 6px; }
  .bubble   { max-width: 80%; font-size: 14px; }

  /* ── Toast ── */
  #spam-toast {
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
  }
}
