/* ============================
   Wrapper generale
   ============================ */

.aisa-chat-floating {
  position: fixed;
  bottom: 50px;
  right: 50px;
  /*
   * Il wrapper deve stare sopra anche agli header sticky dei page builder
   * (Divi, Elementor, ecc.). I figli non possono superare lo stacking
   * context del genitore, quindi alzare soltanto il widget non basta.
   */
  z-index: 2147483000;
  isolation: isolate;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.aisa-chat-floating {
  --aisa-primary: #0f766e;
  --aisa-overlay: rgba(255, 255, 255, 0.55);

  /* nuovi default */
  --aisa-chat-bg: #ffffff;
  --aisa-bubble-bg: #e5f3ff;
  --aisa-text-color: #111827;
}

/* Isoliamo box-sizing e font dai CSS del tema */
.aisa-chat-floating,
.aisa-chat-floating * {
  box-sizing: border-box;
}

/* ============================
   Overlay sfocato
   ============================ */

.aisa-chat-floating::before {
  content: "";
  position: fixed;
  inset: 0;
  /* colore preso dalla variabile, fallback bianco 55% */
  background: var(--aisa-overlay, rgba(255, 255, 255, 0.55));
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  z-index: 0;
}

.aisa-chat-floating.aisa-chat-floating--open::before {
  opacity: 0.35;
  pointer-events: auto;
}

/* ============================
   Pill di apertura
   ============================ */

.aisa-chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: none;
  background: var(--aisa-primary, #0f766e);
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  cursor: pointer;
  font-size: 13px;
  line-height: 1.3;
}

.aisa-chat-toggle--hidden {
  display: none;
}

.aisa-chat-toggle-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  object-fit: cover;
  background: var(--aisa-primary, #0f766e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.aisa-chat-avatar--placeholder {
  background: var(--aisa-primary, #0f766e);
  color: #fff;
}

.aisa-chat-toggle-text {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.2;
}

.aisa-chat-toggle-sub {
  font-size: 11px;
  opacity: 0.9;
}

/* ============================
   Pannello chat
   ============================ */

.aisa-chat-widget {
  display: flex;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  transform: translateX(105%);
  flex-direction: column;
  width: clamp(360px, 32vw, 460px);
  height: 100dvh;
  background: var(--aisa-chat-bg, #ffffff);
  border-radius: 20px 0 0 20px;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.25);
  z-index: 1;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.24s ease, opacity 0.18s ease, visibility 0.24s;
}

.aisa-chat-widget--open {
  transform: translateX(0);
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

/* ============================
   Header
   ============================ */

.aisa-chat-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid #e2e8f0;
  background: var(--aisa-header-bg, #f8fafc);
}

.aisa-chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  margin-right: 10px;
  object-fit: cover;
  flex-shrink: 0;
}

.aisa-chat-header-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.aisa-chat-context-label {
  margin: 0 0 3px;
  color: var(--aisa-primary, #0f766e);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.1;
  text-transform: uppercase;
}

.aisa-chat-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--aisa-text-color);
}

.aisa-chat-subtitle {
  font-size: 12px;
  color: var(--aisa-header-subtitle, #64748b);
}

.aisa-chat-close {
  border: none;
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  color: #64748b;
}

.aisa-chat-close:hover {
  color: #0f172a;
}

/* ============================
   Corpo (area messaggi)
   ============================ */

.aisa-chat-body {
  position: relative; /* utile se in futuro usiamo offsetTop */
  padding: 10px;
  background: var(--aisa-chat-bg, #f9fafb);
  flex: 1;
  min-height: 0;
  overflow-y: auto; /* scroll interno dopo max-height */
}

.aisa-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================
   Messaggi
   ============================ */

.aisa-chat-message {
  display: flex;
}

.aisa-chat-message--assistant {
  justify-content: flex-start;
}

.aisa-chat-message--user {
  justify-content: flex-end;
}

.aisa-chat-message-bubble {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.aisa-chat-message--assistant .aisa-chat-message-bubble {
  background: var(--aisa-bubble-bg);
  color: var(--aisa-text-color);
}

.aisa-chat-message--user .aisa-chat-message-bubble {
  background: var(--aisa-primary, #0f766e);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* ============================
   Input
   ============================ */

.aisa-chat-input-row {
  display: flex;
  align-items: flex-end;
  border-top: 1px solid #e2e8f0;
  padding: 6px 8px;
  gap: 6px;
  background: var(--aisa-chat-bg, #ffffff);

}

.aisa-chat-input {
  flex: 1;
  border: none;
  padding: 8px 10px;
  font-size: 14px; /* evitiamo 16px enormi in alcuni temi */
  line-height: 1.4;
  resize: none;
  overflow-y: hidden;
  box-sizing: border-box;
  color: var(--aisa-text-color);
  background: var(--aisa-chat-bg);
  border-radius: 8px;
}

.aisa-chat-input::placeholder {
  color: var(--aisa-text-color);
  opacity: 0.5; /* più chiaro ma coerente col tema */
}

.aisa-chat-input:focus {
  outline: none;
  box-shadow: 0 0 0 1px #e2e8f0;
}

.aisa-chat-send {
  border: none;
  background: var(--aisa-primary, #0f766e);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: 999px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.aisa-chat-send:hover {
  filter: brightness(0.9);
}

.aisa-chat-send:disabled {
  cursor: wait;
  opacity: 0.55;
}

/* ============================
   Typing indicator
   ============================ */

.aisa-chat-message--loading .aisa-chat-message-bubble {
  background: #e5f3ff;
  color: #0f172a;
  border-bottom-left-radius: 4px;
}

.aisa-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.aisa-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #0f172a;
  opacity: 0.4;
  animation: aisaTyping 1s infinite ease-in-out;
}

.aisa-typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.aisa-typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes aisaTyping {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

/* ============================
   CTA
   ============================ */

.aisa-chat-message-bubble--cta {
  margin-top: 4px;
  background: var(--aisa-bubble-bg);
  color: var(--aisa-text-color);
}

.aisa-chat-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.aisa-chat-cta-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--aisa-primary, #0f766e);
  color: var(--aisa-primary, #0f766e);
  background: #ffffff;
}

.aisa-chat-cta-btn:hover {
  background: var(--aisa-primary, #0f766e);
  color: #ffffff;
}
/* ============================
   Animazione comparsa CTA
   ============================ */

.aisa-chat-cta-anim {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
}

.aisa-chat-cta-anim.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ============================
   Approfondimenti (mini link)
   ============================ */
.aisa-chat-sources-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0 0 4px 0;
  cursor: pointer;
  font-size: 11px;
  color: var(--aisa-text-color);
  opacity: 0.8;
}

.aisa-chat-sources-toggle:hover {
  opacity: 1;
}

.aisa-chat-sources-arrow {
  font-size: 11px;
}
/* Bolla che contiene il titolo "Approfondimenti" e le pill */
.aisa-chat-message-bubble--sources {
  margin-top: 4px;
  background: var(--aisa-bubble-bg);
  color: var(--aisa-text-color);
}

/* ============================
   Approfondimenti (mini link)
   ============================ */

.aisa-chat-message-bubble--links {
  margin-top: 4px;
  background: var(--aisa-bubble-bg);
  color: var(--aisa-text-color);
}

.aisa-chat-links-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: inherit;
}

.aisa-chat-links-toggle-icon {
  font-size: 11px;
  opacity: 0.8;
  transition: transform 0.15s ease-out;
}

.aisa-links-open .aisa-chat-links-toggle-icon {
  transform: rotate(180deg);
}

.aisa-chat-links-body {
  display: none;
  margin-top: 6px;
  flex-wrap: wrap;
  gap: 6px;
}

.aisa-chat-link-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-decoration: none;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: #ffffff;
  color: var(--aisa-text-color);
}

.aisa-chat-link-pill:hover {
  border-color: var(--aisa-primary);
  color: var(--aisa-primary);
}

/* Domande contestuali: azioni conversazionali, non link inventati. */
.aisa-chat-suggestions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 2px 0 4px;
}

.aisa-chat-suggestion {
  max-width: 92%;
  padding: 7px 11px;
  border: 1px solid var(--aisa-primary, #0f766e);
  border-color: color-mix(in srgb, var(--aisa-primary) 45%, transparent);
  border-radius: 999px;
  background: transparent;
  color: var(--aisa-primary, #0f766e);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  line-height: 1.25;
  text-align: left;
}

.aisa-chat-suggestion:hover,
.aisa-chat-suggestion:focus-visible {
  background: var(--aisa-primary, #0f766e);
  color: #fff;
}
/* ============================
   Mobile
   ============================ */

@media (max-width: 768px) {
  .aisa-chat-floating {
    right: 16px;
    bottom: 20px;
  }

  .aisa-chat-widget {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: min(82dvh, 760px);
    max-width: none;
    border-radius: 20px 20px 0 0;
    transform: translateY(105%);
  }

  .aisa-chat-widget--open {
    transform: translateY(0);
  }
}
/* Normalizza header (avatar + nome + sottotitolo) su tutti i temi */
.aisa-chat-widget .aisa-chat-header {
  display: flex !important;
  align-items: center !important;
  gap: 10px;
}

.aisa-chat-widget .aisa-chat-header-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Titolo e sottotitolo: niente margini strani ereditati dal tema */
.aisa-chat-widget .aisa-chat-header-text .aisa-chat-title,
.aisa-chat-widget .aisa-chat-header-text .aisa-chat-subtitle {
  margin: 0 !important;
  padding: 0 !important;
  line-height: 1.2 !important;
}

/* Sottotitolo leggermente staccato dal titolo */
.aisa-chat-widget .aisa-chat-header-text .aisa-chat-subtitle {
  margin-top: 2px !important;
  font-size: 13px;
  color: #6b7280;
}
/* Footer "Powered by" */
.aisa-chat-footer {
  padding: 6px 10px 8px;
  border-top: 1px solid #e2e8f0;
  background: var(--aisa-header-bg, #f8fafc);
font-size: 11px;
  text-align: center;
  line-height: 1.3;
  color: rgba(15, 23, 42, 0.60);
}

.aisa-chat-footer a {
  text-decoration: none;
  color: var(--aisa-footer-text, #0f172a); /* usa il colore calcolato */
  font-weight: 500;
  opacity: 0.8;
}

.aisa-chat-footer a:hover {
  opacity: 1;
  text-decoration: underline;
}

