/* ============================================================
   v22 — section #chat « Message your Smart Bot like a teammate. »
   Tout est scopé sous #chat. Chargé après chat-v17.css et chat-v18.css.
   Objectif : la démo doit se comporter comme une vraie app Mac.
   ============================================================ */

#chat {
  --chat-shell: #ffffff;
  --chat-rail: #f6f6f7;
  --chat-line: rgba(11, 18, 32, .09);
  --chat-line-soft: rgba(11, 18, 32, .055);
  --chat-blue: #2267f5;
  --chat-blue-deep: #1a58dc;
  --chat-bubble: #f0f0f2;
  --chat-ink: rgba(11, 18, 32, .92);
  --chat-muted: #6b7280;
  --chat-ease: cubic-bezier(.2, .7, .2, 1);
  --dot-ring: var(--chat-rail);
  padding: 92px 28px 104px;
}

/* ---------- Titre ---------- */
#chat > h2 {
  text-wrap: balance;
  max-width: 18em;
  margin-inline: auto;
  letter-spacing: -.045em;
}
#chat > h2.reveal { transition-delay: 0ms; }
#chat > .teammate-chat.reveal { transition-delay: 90ms; }
#chat > .teammate-demo-note.reveal { transition-delay: 180ms; }

/* ---------- Le châssis, façon fenêtre macOS ---------- */
#chat .teammate-chat {
  margin-top: 46px;
  border: 1px solid var(--chat-line);
  border-radius: 20px;
  background: var(--chat-shell);
  box-shadow:
    0 1px 2px rgba(11, 18, 32, .04),
    0 10px 26px -12px rgba(11, 18, 32, .16),
    0 34px 62px -30px rgba(11, 18, 32, .22);
  transition: box-shadow .5s var(--chat-ease);
}
#chat .teammate-chat:focus-within {
  box-shadow:
    0 1px 2px rgba(11, 18, 32, .05),
    0 14px 32px -12px rgba(11, 18, 32, .19),
    0 44px 76px -32px rgba(11, 18, 32, .26);
}

/* ---------- Rail des bots ---------- */
#chat .teammate-bots {
  gap: 4px;
  padding: 10px 8px;
  border-right: 1px solid var(--chat-line-soft);
  background: var(--chat-rail);
  border-radius: 19px 0 0 19px;
}
#chat .teammate-bot {
  --dot-ring: var(--chat-rail);
  position: relative;
  min-height: 44px;
  padding: 9px 4px 10px;
  border-radius: 12px;
  color: var(--chat-ink);
  font-weight: 500;
  letter-spacing: -.01em;
  transition: background .22s var(--chat-ease), box-shadow .22s var(--chat-ease), transform .22s var(--chat-ease);
}
#chat .teammate-bot small {
  color: var(--chat-muted);
  font-size: 10.5px;
  line-height: 14px;
  font-weight: 400;
  letter-spacing: .002em;
  transition: color .22s var(--chat-ease);
}
#chat .teammate-bot:hover { background: rgba(11, 18, 32, .045); }
#chat .teammate-bot:active { transform: scale(.975); }
#chat .teammate-bot[aria-pressed="true"] {
  --dot-ring: #ffffff;
  background: #ffffff;
  box-shadow: 0 1px 1px rgba(11, 18, 32, .05), 0 0 0 1px rgba(11, 18, 32, .06);
}
#chat .teammate-bot[aria-pressed="true"] small { color: #4b5563; }
#chat .teammate-bot-name { display: block; }

/* ---------- Avatars : initiales et présence ---------- */
#chat .teammate-avatar {
  position: relative;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .005em;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(11, 18, 32, .045);
  transition: background .3s var(--chat-ease), color .3s var(--chat-ease);
}
#chat .teammate-bot .teammate-avatar::after,
#chat .teammate-chat-header .teammate-avatar::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #34c759;
  box-shadow: 0 0 0 2px var(--dot-ring);
}
#chat .teammate-chat-header .teammate-avatar {
  --dot-ring: #ffffff;
  width: 34px;
  height: 34px;
  font-size: 14px;
}
/* Trois teintes franchement distinctes : indigo, sarcelle, vert. Les pastilles
   de v18 (deux bleus quasi identiques) ne laissaient pas lire « trois collègues ». */
#chat .teammate-bot[data-bot="sam"] .teammate-avatar,
#chat .teammate-chat[data-active-bot="sam"] [data-active-avatar] { background: #d3e8ef; color: #0a6379; }
#chat .teammate-bot[data-bot="maya"] .teammate-avatar,
#chat .teammate-chat[data-active-bot="maya"] [data-active-avatar] { background: #cfe6cf; color: #05650a; }

/* ---------- En-tête de conversation ---------- */
#chat .teammate-chat-header {
  height: 60px;
  padding: 0 18px;
  border-bottom: 1px solid var(--chat-line-soft);
  font-weight: 600;
  letter-spacing: -.012em;
}
#chat .teammate-identity { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
#chat .teammate-identity > span { line-height: 17px; }
#chat .teammate-role {
  color: var(--chat-muted);
  font-size: 10.5px;
  line-height: 13px;
  font-weight: 400;
  letter-spacing: .01em;
}
/* Le rôle suit data-active-bot : aucun JS requis, donc jamais désynchronisé. */
#chat .teammate-role::after { content: "Writing"; }
#chat .teammate-chat[data-active-bot="sam"] .teammate-role::after { content: "Strategy"; }
#chat .teammate-chat[data-active-bot="maya"] .teammate-role::after { content: "Product"; }

/* Petit fondu quand on change de bot. */
#chat .teammate-chat-header [data-active-avatar],
#chat .teammate-chat-header .teammate-identity { animation: chat-identity-in .34s var(--chat-ease) both; }
#chat .teammate-chat[data-swapping] .teammate-chat-header [data-active-avatar],
#chat .teammate-chat[data-swapping] .teammate-chat-header .teammate-identity { animation: none; }
@keyframes chat-identity-in { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }

/* ---------- Conversation ---------- */
#chat .teammate-conversation { height: 386px; grid-template-rows: 60px minmax(0, 1fr) auto; }
#chat .teammate-messages {
  padding: 20px 20px 18px;
  scrollbar-width: thin;
  scrollbar-color: rgba(11, 18, 32, .18) transparent;
  /* Le contenu se fond aux bords plutôt que d'être tranché net. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 16px, #000 calc(100% - 16px), transparent 100%);
}
#chat .teammate-messages::-webkit-scrollbar { width: 8px; }
#chat .teammate-messages::-webkit-scrollbar-track { background: transparent; }
#chat .teammate-messages::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(11, 18, 32, .16);
  background-clip: content-box;
}
#chat .teammate-messages:hover::-webkit-scrollbar-thumb { background: rgba(11, 18, 32, .26); background-clip: content-box; }

/* ---------- Bulles ---------- */
/* L'horodatage passe sur la ligne de base du dernier mot au lieu de prendre
   une ligne à lui seul : bulles plus compactes, moins de bruit. */
#chat .teammate-message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 8px 13px 8px;
  border-radius: 18px;
  letter-spacing: -.008em;
  transition: transform .3s var(--chat-ease);
}
#chat .teammate-chat .teammate-message p { flex: 0 1 auto; min-width: 0; }
/* La conversation se cale en bas du volet, comme dans une vraie app de messages.
   L'auto se résout à 0 dès que le contenu déborde : rien n'est inaccessible. */
#chat .teammate-message:first-child { margin-top: auto; }
#chat .teammate-message + .teammate-message { margin-top: 8px; }
#chat .teammate-outgoing + .teammate-outgoing,
#chat .teammate-incoming + .teammate-incoming { margin-top: 3px; }
#chat .teammate-outgoing {
  background: var(--chat-blue);
  box-shadow: 0 1px 2px rgba(34, 103, 245, .22);
  transform-origin: 100% 100%;
}
#chat .teammate-incoming {
  background: var(--chat-bubble);
  color: var(--chat-ink);
  transform-origin: 0 100%;
}
/* Regroupement : coins internes rabotés, horodatage sur la dernière bulle du groupe. */
#chat .teammate-outgoing:has(+ .teammate-outgoing) { border-bottom-right-radius: 7px; }
#chat .teammate-outgoing + .teammate-outgoing { border-top-right-radius: 7px; }
#chat .teammate-incoming:has(+ .teammate-incoming) { border-bottom-left-radius: 7px; }
#chat .teammate-incoming + .teammate-incoming { border-top-left-radius: 7px; }
#chat .teammate-outgoing:has(+ .teammate-outgoing) .teammate-time,
#chat .teammate-incoming:has(+ .teammate-incoming) .teammate-time { display: none; }
#chat .teammate-time { flex: none; margin: 0 0 1px; font-size: 10px; letter-spacing: .01em; opacity: .58; }
#chat .teammate-outgoing .teammate-time { opacity: .8; }
#chat .teammate-mention {
  background: rgba(34, 103, 245, .12);
  color: var(--chat-blue-deep);
  border-radius: 5px;
  font-weight: 600;
}

/* Entrée des bulles : transform + opacity uniquement. */
#chat .teammate-message.is-waiting { opacity: 0; }
#chat .teammate-message.is-entering { animation: chat-bubble-in .46s var(--chat-ease) both; }
@keyframes chat-bubble-in {
  from { opacity: 0; transform: translate3d(0, 12px, 0) scale(.96); }
  to { opacity: 1; transform: none; }
}

/* ---------- Indicateur de frappe ---------- */
#chat .teammate-typing { display: flex; align-items: center; gap: 5px; padding: 12px 14px; }
#chat .teammate-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(11, 18, 32, .42);
  animation: chat-typing 1.25s var(--chat-ease) infinite;
}
#chat .teammate-typing i:nth-child(2) { animation-delay: .16s; }
#chat .teammate-typing i:nth-child(3) { animation-delay: .32s; }
@keyframes chat-typing {
  0%, 62%, 100% { transform: translateY(0); opacity: .38; }
  28% { transform: translateY(-3.5px); opacity: .9; }
}

/* ---------- Composer ---------- */
#chat .teammate-composer { padding: 10px 12px 12px; border-top: 1px solid var(--chat-line-soft); }
#chat .teammate-field {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex: 1;
  min-width: 0;
  padding: 4px 4px 4px 14px;
  border: 1px solid rgba(11, 18, 32, .07);
  border-radius: 21px;
  background: var(--chat-bubble);
  transition: background .24s var(--chat-ease), border-color .24s var(--chat-ease), box-shadow .24s var(--chat-ease);
}
#chat .teammate-field:hover { border-color: rgba(11, 18, 32, .13); }
#chat .teammate-field:focus-within {
  background: #ffffff;
  border-color: var(--chat-blue);
  box-shadow: 0 0 0 3px rgba(34, 103, 245, .15);
}
#chat .teammate-interactive textarea.teammate-placeholder {
  padding: 7px 0;
  height: 34px;
  background: transparent;
  border-radius: 0;
  color: var(--chat-ink);
  letter-spacing: -.008em;
  scrollbar-width: thin;
}
#chat .teammate-interactive textarea.teammate-placeholder::placeholder { color: var(--chat-muted); }
#chat .teammate-interactive textarea.teammate-placeholder:focus-visible { outline: 0; }

#chat .teammate-send {
  position: relative;
  width: 34px;
  height: 34px;
  color: #ffffff;
  background: var(--chat-blue);
  box-shadow: 0 1px 2px rgba(34, 103, 245, .3);
  transition: background .2s var(--chat-ease), color .2s var(--chat-ease), transform .24s var(--chat-ease), box-shadow .2s var(--chat-ease), opacity .2s var(--chat-ease);
}
/* Cible tactile de 44 px sans agrandir le disque. */
#chat .teammate-send::before { content: ""; position: absolute; inset: -5px; border-radius: 50%; }
#chat .teammate-send-icon { width: 18px; height: 18px; transform: translateX(.5px); }
#chat .teammate-send:hover:not(:disabled) { background: var(--chat-blue-deep); transform: scale(1.06); }
#chat .teammate-send:active:not(:disabled) { transform: scale(.93); box-shadow: 0 0 0 rgba(34, 103, 245, 0); }
#chat .teammate-send:disabled {
  background: transparent;
  color: rgba(11, 18, 32, .26);
  box-shadow: none;
  transform: scale(.9);
}
#chat .teammate-send:disabled .teammate-send-icon { opacity: 1; }
#chat .teammate-interactive :is(button, textarea, ol):focus-visible { outline: 2px solid var(--chat-blue); outline-offset: 2px; }
#chat .teammate-bot:focus-visible { outline-offset: 1px; }
#chat .teammate-messages:focus-visible { outline-offset: -3px; border-radius: 3px; }

/* ---------- Légende ---------- */
#chat .teammate-demo-note {
  margin-top: 16px;
  color: var(--chat-muted);
  font-size: 11.5px;
  letter-spacing: .006em;
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  #chat { padding: 66px 20px 74px; }
  #chat .teammate-chat { margin-top: 34px; }
}
@media (max-width: 540px) {
  #chat .teammate-bots {
    gap: 4px;
    padding: 7px;
    border-right: 0;
    border-bottom: 1px solid var(--chat-line-soft);
    border-radius: 19px 19px 0 0;
  }
  #chat .teammate-bot { min-height: 44px; padding: 8px 6px; gap: 8px; }
  #chat .teammate-bot .teammate-avatar { width: 26px; height: 26px; font-size: 11.5px; }
  #chat .teammate-bot .teammate-avatar::after { width: 8px; height: 8px; }
  #chat .teammate-conversation { height: 362px; grid-template-rows: 56px minmax(0, 1fr) auto; }
  #chat .teammate-chat-header { height: 56px; padding: 0 14px; }
  #chat .teammate-messages { padding: 18px 14px 16px; }
  #chat .teammate-composer { padding: 8px 10px 10px; }
}

/* ---------- Mouvement réduit ---------- */
@media (prefers-reduced-motion: reduce) {
  #chat .teammate-message.is-waiting { opacity: 1; }
  #chat .teammate-message,
  #chat .teammate-send,
  #chat .teammate-bot { transform: none !important; }
}
