/**
 * ACM · Side chat drawer — stili
 * Componente condiviso, indipendente dalla pagina: drawer laterale da destra
 * con dentro una chat AI, apribile da QUALSIASI elemento con classe
 * "acm-chat-trigger" (bottone Elementor, floating button, HTML custom, ecc).
 *
 * Presuppone le variabili di tokens.css (design-system/) già incluse PRIMA
 * di questo file nel CSS personalizzato globale di Elementor:
 *   --black, --white, --g1..--g6, --r-lg, --r-md, --r-pill, --font, --font-c
 *
 * Namespacing: tutte le classi hanno prefisso "acm-chat-" per non entrare
 * in conflitto con le classi "ar-", "s1-", ecc. del prototipo statico.
 */

.acm-chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.acm-chat-backdrop.open { opacity: 1; pointer-events: auto; }

.acm-chat-drawer {
  position: fixed;
  z-index: 9999;
  top: 0;
  right: 0;
  transform: translateX(100%);
  pointer-events: none;
  width: min(560px, 100vw);
  height: 100dvh;
  background: var(--white, #fff);
  border-left: 1px solid var(--g4, #d1d1d6);
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.22);
  transition: transform 0.45s cubic-bezier(.32,0,.15,1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.acm-chat-drawer.open { pointer-events: auto; transform: translateX(0); }

.acm-chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 26px 30px 18px;
  border-bottom: 1px solid var(--g5, #f5f5f7);
  flex-shrink: 0;
}
.acm-chat-eyebrow {
  font-size: 10px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase;
  /* Audit accessibilità 2026-09-22: --g3 su bianco = 3,62:1, sotto 4,5 richiesto per testo. --g2
     (5,07:1, calcolato con la formula WCAG) è il token più chiaro fra quelli disponibili che passa
     — non --black (16,83:1, molto più scuro del necessario, cambierebbe il peso visivo). */
  color: var(--g2, #6e6e73); margin-bottom: 8px;
}
.acm-chat-title { font-size: 24px; font-weight: 400; letter-spacing: -0.5px; color: var(--black, #1d1d1f); }
.acm-chat-close {
  width: 34px; height: 34px; min-width: 34px; min-height: 34px; border-radius: 50%;
  background: var(--g5, #f5f5f7) !important; border: none; cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background .2s;
}
.acm-chat-close:hover,
.acm-chat-close:focus {
  background: var(--g4, #d1d1d6) !important;
  color: inherit !important;
}
.acm-chat-close svg {
  width: 16px !important; height: 16px !important; flex-shrink: 0;
  stroke: var(--black, #1d1d1f) !important; fill: none !important;
  stroke-width: 2px; stroke-linecap: round; stroke-linejoin: round;
}

.acm-chat-body {
  padding: 20px 30px 24px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.acm-chat-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; flex-shrink: 0; }
.acm-chat-chips button {
  font-family: var(--font, sans-serif);
  /* Audit accessibilità 2026-09-22: bordo --g4 su bianco = 1,52:1, sotto 3:1 richiesto per i
     componenti. --g3 (3,62:1) è il token più chiaro che passa — stesso valore già usato per
     l'eyebrow del pannello prima di questo giro, coerente con la scala del sistema. */
  font-size: 12px; padding: 7px 14px; border: 1px solid var(--g3, #86868b);
  border-radius: var(--r-pill, 999px); background: var(--white, #fff); cursor: pointer; color: var(--g1, #3a3a3c);
  transition: border-color .2s, background .2s;
}
.acm-chat-chips button:hover,
.acm-chat-chips button:focus {
  border-color: var(--g3, #86868b) !important;
  background: var(--white, #fff) !important;
  color: var(--g1, #3a3a3c) !important;
}

.acm-chat-scroll {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  min-height: 200px;
}

.acm-chat-msg { display: flex; gap: 10px; padding: 8px 0; }
.acm-chat-msg.user { flex-direction: row-reverse; }
.acm-chat-av {
  width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 600; background: var(--g5, #f5f5f7); color: var(--g2, #6e6e73);
}
.acm-chat-msg.user .acm-chat-av { background: var(--black, #1d1d1f); color: #fff; }
.acm-chat-bubble {
  max-width: 82%; font-size: 14px; line-height: 1.6; padding: 11px 15px;
  border-radius: 4px 16px 16px 16px; background: var(--g5, #f5f5f7); color: var(--black, #1d1d1f);
}
.acm-chat-msg.user .acm-chat-bubble { background: var(--black, #1d1d1f); color: #fff; border-radius: 16px 4px 16px 16px; }
.acm-chat-bubble p { font-family: var(--font, sans-serif); font-size: 14px; margin-bottom: 6px; }
.acm-chat-bubble p:last-child { margin-bottom: 0; }
.acm-chat-bubble strong { font-weight: 500; }

.acm-chat-typing { display: flex; gap: 4px; padding: 2px 0; }
.acm-chat-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--g3, #86868b);
  animation: acmChatDot 1.4s infinite;
}
.acm-chat-typing span:nth-child(2) { animation-delay: .15s; }
.acm-chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes acmChatDot { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.acm-chat-inputbar {
  display: flex; align-items: flex-end; gap: 8px; margin-top: 12px; flex-shrink: 0;
  /* Bordo --g4→--g3, stesso motivo di .acm-chat-chips button sopra: 1,52:1 → 3,62:1. */
  background: var(--g5, #f5f5f7); border: 1px solid var(--g3, #86868b);
  border-radius: var(--r-lg, 20px); padding: 8px 8px 8px 16px;
}
.acm-chat-inputbar textarea {
  flex: 1; border: none; background: none; outline: none; resize: none;
  font-family: var(--font, sans-serif); font-size: 15px; max-height: 100px; min-height: 24px;
  line-height: 1.5; padding: 4px 0; color: var(--black, #1d1d1f);
}
.acm-chat-inputbar button {
  /* Audit stile 2026-09-22: 10px non combacia con nessuno dei 4 token di raggio del sistema
     (--r-sm 4px, --r-md 14px, --r-lg 20px, --r-pill 999px). --r-md è il più vicino nella scala,
     stesso token già usato per elementi di dimensione simile (.s1-chat-av{border-radius:var(--r-md)}). */
  width: 36px; height: 36px; min-width: 36px; min-height: 36px; border-radius: var(--r-md, 14px); border: none; padding: 0;
  background: var(--black, #1d1d1f) !important; color: #fff !important; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  opacity: .4; pointer-events: none; transition: opacity .2s;
}
.acm-chat-inputbar button.active { opacity: 1; pointer-events: auto; }
.acm-chat-inputbar button:hover,
.acm-chat-inputbar button:focus {
  background: var(--black, #1d1d1f) !important;
  color: #fff !important;
}
.acm-chat-inputbar button svg {
  width: 16px !important; height: 16px !important; flex-shrink: 0;
  stroke: #fff !important; fill: none !important;
}

/* ── FAB di fallback (usala solo se NON usi il floating button nativo di Elementor) ── */
.acm-chat-fab {
  position: fixed; z-index: 9997; right: 24px; bottom: 24px; height: 54px; padding: 0 6px;
  border-radius: var(--r-pill, 999px); background: var(--black, #1d1d1f) !important; color: #fff !important;
  border: 1px solid rgba(255,255,255,.14); cursor: pointer; display: flex; align-items: center;
  box-shadow: 0 12px 34px rgba(0,0,0,.3); transition: transform .2s, padding .3s; overflow: hidden;
}
.acm-chat-fab:hover,
.acm-chat-fab:focus {
  background: var(--black, #1d1d1f) !important;
  color: #fff !important;
  transform: translateY(-2px);
}
.acm-chat-fab-ic { width: 42px; height: 42px; flex: 0 0 42px; display: flex; align-items: center; justify-content: center; font-size: 20px; }
.acm-chat-fab-lbl {
  font-family: var(--font, sans-serif); font-size: 14px; font-weight: 500; white-space: nowrap;
  max-width: 0; opacity: 0; transition: max-width .3s cubic-bezier(.32,0,.15,1), opacity .25s, padding .3s;
}
.acm-chat-fab:hover .acm-chat-fab-lbl, .acm-chat-fab:focus-visible .acm-chat-fab-lbl { max-width: 160px; opacity: 1; padding-right: 14px; }

@media (max-width: 768px) {
  .acm-chat-drawer { width: 100vw; border-left: none; }
}
@media (prefers-reduced-motion: reduce) {
  .acm-chat-drawer, .acm-chat-backdrop, .acm-chat-fab, .acm-chat-msg { transition-duration: .001ms !important; animation-duration: .001ms !important; }
}
