@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --aria-accent:       #4f8ef7;
  --aria-accent-dark:  #2563eb;
  --aria-accent-light: rgba(79,142,247,0.1);
  --aria-bg:           #ffffff;
  --aria-surface:      #f4f6fb;
  --aria-border:       #e2e8f0;
  --aria-text:         #1e293b;
  --aria-text-muted:   #94a3b8;
  --aria-radius:       18px;
  --aria-font:         'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ── Tailles par type d'écran ──────────────────────────────────────────────
   Toutes les dimensions du widget partent de ces variables. Elles sont réglées
   plus bas pour chaque famille d'appareils (ordinateur, tablette, téléphone,
   téléphone couché). --aria-vh et --aria-kb sont tenues à jour par chat.js :
   hauteur réellement visible et hauteur du clavier quand il est sorti. */
#aria-chat-root {
  --aria-edge:     24px;   /* distance au bord de l'écran */
  --aria-launcher: 60px;   /* diamètre du bouton rond */
  --aria-win-w:    380px;  /* fenêtre de chat */
  --aria-win-h:    620px;
  --aria-notif-w:  340px;  /* petite notification d'arrivée */
  --aria-fs:       15px;   /* taille du texte */
  --aria-pad:      13px 17px;  /* intérieur des bulles */
  --aria-head-h:   112px;  /* hauteur de l'en-tête */
}

/* Remise à zéro des marges du thème. Elle est plus forte qu'une simple classe : toutes les règles
   du widget commencent donc par #aria-chat-root (ou par un identifiant) pour garder leurs marges. */
#aria-chat-root *, #aria-chat-root *::before, #aria-chat-root *::after { box-sizing:border-box; margin:0; padding:0; }
#aria-chat-root {
  font-family:var(--aria-font); position:fixed; z-index:999999;
  bottom:calc(var(--aria-edge) + env(safe-area-inset-bottom, 0px));
  -webkit-text-size-adjust:100%; text-size-adjust:100%;
}
#aria-chat-root.aria-pos-right { right:calc(var(--aria-edge) + env(safe-area-inset-right, 0px)); }
#aria-chat-root.aria-pos-left  { left:calc(var(--aria-edge) + env(safe-area-inset-left, 0px)); }

/* ── Bouton rond ── */
#aria-toggle {
  width:var(--aria-launcher); height:var(--aria-launcher); border-radius:50%; border:none; cursor:pointer;
  background:var(--aria-accent); color:#fff; font-size:24px;
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 4px 20px rgba(79,142,247,.45);
  transition:transform .25s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
  position:relative; -webkit-tap-highlight-color:transparent;
}
#aria-toggle:hover { transform:scale(1.1); }
#aria-toggle:active { transform:scale(.95); }
#aria-toggle.aria-open { background:#64748b; box-shadow:0 4px 14px rgba(0,0,0,.2); }
@keyframes aria-pulse {
  0%   { box-shadow:0 0 0 0 rgba(79,142,247,.4),0 4px 20px rgba(79,142,247,.45); }
  70%  { box-shadow:0 0 0 13px rgba(79,142,247,0),0 4px 20px rgba(79,142,247,.45); }
  100% { box-shadow:0 0 0 0 rgba(79,142,247,0),0 4px 20px rgba(79,142,247,.45); }
}
#aria-toggle:not(.aria-open) { animation:aria-pulse 2.5s ease-out infinite; }
#aria-badge {
  position:absolute; top:-4px; right:-4px;
  background:#ef4444; color:#fff; font-size:11px; font-weight:700;
  min-width:21px; height:21px; padding:0 4px; border-radius:11px;
  display:flex; align-items:center; justify-content:center; border:2px solid #fff;
}
#aria-badge.aria-hidden { display:none; }

/* ── Fenêtre de chat ── */
#aria-window {
  position:absolute; bottom:calc(var(--aria-launcher) + 12px);
  width:var(--aria-win-w);
  height:min(var(--aria-win-h), calc(100vh - var(--aria-launcher) - var(--aria-edge) - 28px));
  background:var(--aria-bg); border-radius:var(--aria-radius);
  box-shadow:0 24px 60px rgba(0,0,0,.16), 0 4px 16px rgba(0,0,0,.08);
  border:1px solid var(--aria-border);
  display:flex; flex-direction:column; overflow:hidden;
  transform-origin:bottom center;
  transition:opacity .22s ease, transform .28s cubic-bezier(.34,1.56,.64,1), visibility 0s;
}
@supports (height:100dvh) {
  #aria-window { height:min(var(--aria-win-h), calc(100dvh - var(--aria-launcher) - var(--aria-edge) - 28px)); }
}
#aria-window.aria-pos-right { right:0; }
#aria-window.aria-pos-left  { left:0; }
#aria-window.aria-hidden {
  opacity:0; transform:scale(.93) translateY(14px); pointer-events:none; visibility:hidden;
  transition:opacity .22s ease, transform .28s cubic-bezier(.34,1.56,.64,1), visibility 0s linear .28s;
}

/* ── En-tête ── */
#aria-header {
  position:relative; min-height:var(--aria-head-h);
  padding:18px 18px 16px;
  display:flex; align-items:flex-end; gap:13px;
  flex-shrink:0; overflow:hidden; background:var(--aria-accent);
}
#aria-header-bg { position:absolute; inset:0; background-size:cover; background-position:center; z-index:0; }
#aria-header-overlay { position:absolute; inset:0; background:linear-gradient(to bottom,rgba(0,0,0,.1) 0%,rgba(0,0,0,.55) 100%); z-index:1; }
#aria-header-content { position:relative; z-index:2; display:flex; align-items:flex-end; gap:13px; width:100%; }
#aria-chat-root .aria-avatar {
  width:48px; height:48px; border-radius:50%;
  background:rgba(255,255,255,.2); display:flex; align-items:center; justify-content:center;
  font-size:20px; color:#fff; flex-shrink:0; border:2.5px solid rgba(255,255,255,.7); overflow:hidden;
}
#aria-chat-root .aria-avatar img { width:100%; height:100%; object-fit:cover; border-radius:50%; }
#aria-chat-root .aria-header-info { flex:1; min-width:0; }
#aria-chat-root .aria-header-name  { font-size:16px; font-weight:700; color:#fff; text-shadow:0 1px 4px rgba(0,0,0,.35); }
#aria-chat-root .aria-header-status { display:flex; align-items:center; gap:5px; margin-top:3px; font-size:12px; color:rgba(255,255,255,.88); }
#aria-chat-root .aria-dot { width:7px; height:7px; border-radius:50%; background:#4ade80; box-shadow:0 0 5px #4ade80; flex-shrink:0; }
#aria-close-btn {
  position:absolute; top:10px; right:10px; z-index:3;
  width:34px; height:34px; border-radius:10px; border:none;
  background:rgba(255,255,255,.22); color:#fff; font-size:18px; line-height:1; cursor:pointer;
  display:flex; align-items:center; justify-content:center; backdrop-filter:blur(4px);
  transition:background .15s;
}
#aria-close-btn:hover { background:rgba(255,255,255,.38); }

/* ── Messages ── */
#aria-messages {
  flex:1; min-height:0; overflow-y:auto; padding:16px 14px;
  display:flex; flex-direction:column; gap:12px;
  background:var(--aria-surface);
  overscroll-behavior:contain; -webkit-overflow-scrolling:touch;
}
#aria-messages::-webkit-scrollbar { width:4px; }
#aria-messages::-webkit-scrollbar-thumb { background:var(--aria-border); border-radius:2px; }

#aria-chat-root .aria-row { display:flex; align-items:flex-end; gap:9px; animation:aria-fadein .22s ease; }
#aria-chat-root .aria-row.aria-user { flex-direction:row-reverse; }
@keyframes aria-fadein { from{opacity:0;transform:translateY(7px)} to{opacity:1;transform:translateY(0)} }

#aria-chat-root .aria-msg-avatar {
  width:30px; height:30px; border-radius:50%;
  background:var(--aria-accent-light); color:var(--aria-accent);
  font-size:14px; display:flex; align-items:center; justify-content:center;
  flex-shrink:0; overflow:hidden; border:1.5px solid var(--aria-border);
}
#aria-chat-root .aria-msg-avatar img { width:100%; height:100%; object-fit:cover; border-radius:50%; }
#aria-chat-root .aria-row.aria-user .aria-msg-avatar { background:#e2e8f0; color:#64748b; border-color:#e2e8f0; }

#aria-chat-root .aria-bubble-wrap { display:flex; flex-direction:column; max-width:82%; min-width:0; }
#aria-chat-root .aria-admin-label { font-size:10.5px; color:#059669; font-weight:600; margin-bottom:4px; padding-left:2px; }

/* Bulles : taille et marges suivent l'appareil (les !important protègent du thème du site) */
#aria-chat-root .aria-bubble {
  display:block !important;
  padding:var(--aria-pad) !important;
  font-size:var(--aria-fs) !important;
  line-height:1.55 !important;
  letter-spacing:0.01em;
  font-family:var(--aria-font);
  overflow-wrap:anywhere; word-break:break-word;
}
#aria-chat-root .aria-row.aria-bot .aria-bubble {
  background:var(--aria-bg);
  border:1px solid var(--aria-border);
  border-radius:18px 18px 18px 5px;
  color:var(--aria-text);
  box-shadow:0 2px 14px rgba(0,0,0,.07);
}
#aria-chat-root .aria-row.aria-user .aria-bubble {
  background:var(--aria-accent);
  color:#fff;
  border-radius:18px 18px 5px 18px;
  box-shadow:0 2px 12px rgba(79,142,247,.35);
}
#aria-chat-root .aria-bubble-admin {
  background:#f0fdf4 !important;
  border:1px solid #bbf7d0 !important;
  color:#14532d !important;
  border-radius:18px 18px 18px 5px !important;
}

/* Indicateur « en train d'écrire » */
#aria-chat-root .aria-typing {
  display:flex; align-items:center; gap:5px;
  padding:14px 18px;
  background:var(--aria-bg); border:1px solid var(--aria-border);
  border-radius:18px 18px 18px 5px; width:fit-content;
  box-shadow:0 2px 14px rgba(0,0,0,.07);
}
#aria-chat-root .aria-typing span {
  width:7px; height:7px; border-radius:50%;
  background:var(--aria-text-muted); display:block;
  animation:aria-bounce 1.2s ease-in-out infinite;
}
#aria-chat-root .aria-typing span:nth-child(2){animation-delay:.18s}
#aria-chat-root .aria-typing span:nth-child(3){animation-delay:.36s}
@keyframes aria-bounce{0%,80%,100%{transform:translateY(0);opacity:.4}40%{transform:translateY(-5px);opacity:1}}

#aria-chat-root .aria-system { text-align:center; font-size:11.5px; color:var(--aria-text-muted); padding:2px 16px; font-style:italic; }

/* ── Boutons de choix (Oui / Non) ── */
#aria-chat-root .aria-choices {
  display:flex; flex-direction:column; gap:8px;
  padding:2px 0 2px 39px;
  animation:aria-fadein .25s ease;
}
#aria-chat-root .aria-choice-btn {
  width:100%; min-height:42px; padding:9px 15px;
  border-radius:12px; border:1.5px solid var(--aria-border);
  background:var(--aria-bg); color:var(--aria-text);
  font-size:var(--aria-fs); font-family:var(--aria-font); font-weight:500;
  cursor:pointer; text-align:left;
  transition:all .18s; box-shadow:0 1px 4px rgba(0,0,0,.06);
}
#aria-chat-root .aria-choice-btn:hover { border-color:var(--aria-accent); background:var(--aria-accent-light); color:var(--aria-accent); transform:translateY(-1px); }
#aria-chat-root .aria-choice-primary { border-color:var(--aria-accent); color:var(--aria-accent); background:var(--aria-accent-light); }
#aria-chat-root .aria-choice-primary:hover { background:var(--aria-accent); color:#fff; }

/* ── Saisie du numéro ── */
#aria-phone-bar {
  display:flex; gap:7px; padding:11px 12px;
  border-top:1px solid var(--aria-border); background:#fafbff;
  flex-shrink:0; align-items:center; animation:aria-fadein .2s ease;
}
#aria-phone-bar.aria-hidden { display:none; }
#aria-phone-input {
  flex:1; min-width:0; height:44px; padding:0 14px;
  border:1px solid var(--aria-border); border-radius:10px;
  font-size:15px; font-family:var(--aria-font); outline:none; color:var(--aria-text); background:#fff;
}
#aria-phone-input:focus { border-color:var(--aria-accent); }
#aria-phone-send {
  height:44px; padding:0 16px; background:var(--aria-accent); color:#fff;
  border:none; border-radius:10px; font-size:14px; font-weight:600;
  cursor:pointer; font-family:var(--aria-font); transition:background .15s; flex-shrink:0;
}
#aria-phone-send:hover { background:var(--aria-accent-dark); }
#aria-phone-cancel {
  width:38px; height:44px; border:1px solid var(--aria-border);
  background:transparent; border-radius:10px; cursor:pointer;
  color:var(--aria-text-muted); font-size:16px; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
}
#aria-phone-cancel:hover { background:#fee2e2; border-color:#fca5a5; color:#dc2626; }

/* ── Zone de saisie ── */
#aria-footer {
  padding:11px 12px; border-top:1px solid var(--aria-border);
  background:var(--aria-bg); display:flex; gap:8px; align-items:flex-end; flex-shrink:0;
}
#aria-input {
  flex:1; min-width:0; min-height:44px; max-height:100px;
  padding:11px 14px; font-size:15px; font-family:var(--aria-font);
  color:var(--aria-text); background:var(--aria-surface);
  border:1px solid var(--aria-border); border-radius:12px;
  outline:none; resize:none; line-height:1.4; transition:border-color .18s;
  scrollbar-width:none;
}
#aria-input:focus { border-color:var(--aria-accent); background:#fff; }
#aria-input::placeholder { color:var(--aria-text-muted); }
#aria-send-btn {
  width:44px; height:44px; border-radius:12px; border:none;
  background:var(--aria-accent); color:#fff; cursor:pointer;
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
  transition:background .18s,transform .18s,opacity .18s;
  box-shadow:0 2px 8px rgba(79,142,247,.35);
}
#aria-send-btn:hover  { background:var(--aria-accent-dark); transform:scale(1.05); }
#aria-send-btn:active { transform:scale(.93); }
#aria-send-btn:disabled { opacity:.4; cursor:default; transform:none; }
#aria-file-btn {
  width:44px; height:44px; border-radius:12px;
  border:1px solid var(--aria-border); background:var(--aria-surface); color:var(--aria-text-muted);
  display:flex; align-items:center; justify-content:center;
  cursor:pointer; flex-shrink:0;
  transition:background .15s, color .15s, border-color .15s;
}
#aria-file-btn:hover { background:var(--aria-accent-light); color:var(--aria-accent); border-color:var(--aria-accent); }

#aria-branding {
  text-align:center; padding:4px 0 8px;
  font-size:10px; color:#cbd5e1; font-family:var(--aria-font);
  background:var(--aria-bg); flex-shrink:0; letter-spacing:.03em;
}

/* ── Bulle d'accroche / réponse du technicien (chat fermé) ── */
#aria-teaser {
  position:absolute; bottom:calc(var(--aria-launcher) + 14px); right:0;
  width:max-content; max-width:min(320px, calc(100vw - 2 * var(--aria-edge)));
  background:#fff; color:var(--aria-text);
  padding:13px 17px; border-radius:18px 18px 4px 18px;
  font-size:14.5px; font-family:var(--aria-font); font-weight:500; line-height:1.5;
  box-shadow:0 6px 24px rgba(0,0,0,.18); border:1px solid var(--aria-border);
  cursor:pointer;
  animation:aria-teaser-in .35s cubic-bezier(.34,1.56,.64,1);
  transition:transform .15s, box-shadow .15s;
}
#aria-teaser:hover { transform:translateY(-2px); box-shadow:0 8px 28px rgba(0,0,0,.22); }
#aria-chat-root.aria-pos-left #aria-teaser { right:auto; left:0; border-radius:18px 18px 18px 4px; }
@keyframes aria-teaser-in {
  from { opacity:0; transform:translateY(20px) scale(.9); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
#aria-chat-root .aria-teaser-admin { border-left:3px solid var(--aria-accent) !important; }
#aria-chat-root .aria-teaser-label {
  font-size:11px; color:var(--aria-accent); font-weight:700;
  margin-bottom:5px; text-transform:uppercase; letter-spacing:.04em;
}
#aria-chat-root .aria-teaser-msg { color:var(--aria-text); font-weight:400; line-height:1.55; }

/* ── Petite notification d'arrivée : le message + deux réponses rapides ── */
#aria-notif {
  position:absolute; bottom:calc(var(--aria-launcher) + 16px); right:0;
  width:min(var(--aria-notif-w), calc(100vw - 2 * var(--aria-edge)));
  animation:aria-teaser-in .35s cubic-bezier(.34,1.56,.64,1);
}
#aria-chat-root.aria-pos-left #aria-notif { right:auto; left:0; }
#aria-chat-root .aria-notif-card {
  background:#fff; color:var(--aria-text);
  border-radius:16px; border:1px solid var(--aria-border);
  box-shadow:0 10px 34px rgba(15,23,42,.18), 0 2px 8px rgba(15,23,42,.08);
  overflow:hidden;
}
#aria-chat-root .aria-notif-msg {
  padding:17px 20px 15px; cursor:pointer;
  font-size:var(--aria-fs); line-height:1.5; font-weight:400;
  overflow-wrap:anywhere;
}
#aria-chat-root .aria-notif-actions { border-top:1px solid var(--aria-border); padding:4px 0 6px; display:flex; flex-direction:column; }
#aria-chat-root .aria-notif-btn {
  display:block; width:100%; min-height:42px; padding:8px 20px;
  background:transparent; border:none; border-radius:0; box-shadow:none;
  text-align:left; cursor:pointer; margin:0; height:auto; min-width:0;
  text-transform:none; letter-spacing:normal; text-decoration:none;   /* neutralise le style des boutons du thème */
  color:var(--aria-accent); font-size:var(--aria-fs); font-weight:500; line-height:1.3;
  transition:background .15s;
  -webkit-tap-highlight-color:transparent;
}
#aria-chat-root .aria-notif-btn:hover,
#aria-chat-root .aria-notif-btn:focus-visible { background:var(--aria-accent-light); outline:none; }
#aria-chat-root .aria-notif-x {
  position:absolute; top:-13px; right:-9px; z-index:1;
  width:32px; height:32px; min-width:0; min-height:0; margin:0; border-radius:50%; padding:0;
  border:1px solid var(--aria-border); background:#fff; color:#64748b;
  font-size:19px; line-height:1; cursor:pointer;
  display:flex; align-items:center; justify-content:center;
  box-shadow:0 2px 10px rgba(15,23,42,.16);
  -webkit-tap-highlight-color:transparent;
}
#aria-chat-root .aria-notif-x:hover { color:var(--aria-text); }
#aria-chat-root.aria-pos-left .aria-notif-x { right:auto; left:-9px; }

/* ── Police Outfit partout dans le widget (y compris champs et boutons, que les thèmes écrasent souvent) ── */
#aria-chat-root, #aria-chat-root input, #aria-chat-root textarea, #aria-chat-root button {
  font-family:var(--aria-font) !important;
}

/* ═══════════════════ Adaptation à l'appareil ═══════════════════ */

/* Grand écran d'ordinateur */
@media (min-width:1600px) {
  #aria-chat-root { --aria-win-w:400px; --aria-win-h:660px; --aria-notif-w:360px; }
}

/* Tablette (iPad, tablettes Android) et petit portable */
@media (max-width:1024px) {
  #aria-chat-root { --aria-edge:20px; --aria-launcher:58px; --aria-win-w:370px; --aria-win-h:600px; --aria-notif-w:330px; }
}

/* Écran tactile : champs à 16 px (sinon l'iPhone zoome sur la page dès qu'on touche le champ) */
@media (hover:none) and (pointer:coarse) {
  #aria-chat-root #aria-input, #aria-chat-root #aria-phone-input { font-size:16px; }
  #aria-toggle:hover, #aria-chat-root .aria-choice-btn:hover, #aria-teaser:hover { transform:none; }
}

/* Téléphone (iPhone, Android) tenu debout :
   la fenêtre devient un panneau qui monte du bas, jamais plus haut que l'écran ni caché par le clavier */
@media (max-width:600px) {
  #aria-chat-root {
    --aria-edge:16px; --aria-launcher:54px; --aria-notif-w:320px;
    --aria-fs:15px; --aria-pad:11px 15px; --aria-head-h:92px;
  }
  #aria-window, #aria-window.aria-pos-right, #aria-window.aria-pos-left {
    position:fixed; left:8px; right:8px; width:auto;
    bottom:calc(8px + env(safe-area-inset-bottom, 0px) + var(--aria-kb, 0px));
    height:min(640px, calc(100vh - 16px));
    transform-origin:bottom center;
  }
  @supports (height:100dvh) {
    #aria-window, #aria-window.aria-pos-right, #aria-window.aria-pos-left {
      height:min(640px, calc(var(--aria-vh, 100dvh) - 16px - env(safe-area-inset-bottom, 0px)));
    }
  }
  /* Fenêtre ouverte : le bouton rond est derrière elle, on ferme avec la croix de l'en-tête */
  #aria-toggle.aria-open { display:none; }
  #aria-close-btn { width:38px; height:38px; font-size:20px; }
  #aria-chat-root .aria-avatar { width:42px; height:42px; }
  #aria-header { padding:14px 16px 13px; }
  #aria-messages { padding:14px 12px; }
  #aria-branding { display:none; }
  #aria-footer { padding-bottom:12px; }
}

/* Très petit téléphone (iPhone SE 1re génération, anciens Android) */
@media (max-width:350px) {
  #aria-chat-root { --aria-edge:12px; --aria-launcher:50px; --aria-fs:14.5px; --aria-pad:10px 13px; }
  #aria-chat-root .aria-notif-msg { padding:14px 16px 12px; }
  #aria-chat-root .aria-notif-btn { padding:8px 16px; }
  #aria-file-btn { display:none; }
}

/* Téléphone couché (peu de hauteur) : fenêtre sur toute la hauteur, en-tête réduit */
@media (max-height:520px) {
  #aria-chat-root { --aria-edge:12px; --aria-launcher:50px; --aria-head-h:58px; --aria-pad:9px 13px; }
  #aria-window, #aria-window.aria-pos-right, #aria-window.aria-pos-left {
    position:fixed; top:auto; width:min(420px, calc(100vw - 16px));
    bottom:calc(8px + var(--aria-kb, 0px));
    height:calc(100vh - 16px);
  }
  @supports (height:100dvh) {
    #aria-window, #aria-window.aria-pos-right, #aria-window.aria-pos-left { height:calc(var(--aria-vh, 100dvh) - 16px); }
  }
  #aria-window.aria-pos-right { right:calc(8px + env(safe-area-inset-right, 0px)); left:auto; }
  #aria-window.aria-pos-left  { left:calc(8px + env(safe-area-inset-left, 0px)); right:auto; }
  #aria-toggle.aria-open { display:none; }
  #aria-header { padding:9px 14px; align-items:center; }
  #aria-chat-root .aria-avatar { width:36px; height:36px; }
  #aria-branding { display:none; }
  #aria-notif { width:min(300px, calc(100vw - 2 * var(--aria-edge))); }
  #aria-chat-root .aria-notif-msg { padding:12px 16px 10px; }
}

/* Respect du réglage « réduire les animations » */
@media (prefers-reduced-motion:reduce) {
  #aria-toggle:not(.aria-open), #aria-notif, #aria-teaser, #aria-chat-root .aria-row { animation:none; }
  #aria-window { transition:opacity .15s ease; }
}
