/* Bot AI Customer Service — stile del widget chat.
 * Difensivo: il widget vive dentro temi WP arbitrari (Storefront, ecc.) che
 * applicano stili aggressivi a `button`/`input`/`a`. Per restare identico ovunque
 * azzeriamo l'ereditarietà del tema e usiamo `!important` SOLO sulle proprietà
 * visive critiche dei controlli. Tutto è scoped sotto #botai-root. */

/* ---- Reset difensivo: neutralizza il CSS del tema ospite ---- */
#botai-root, #botai-root *, #botai-root *::before, #botai-root *::after {
  box-sizing: border-box !important;
}
#botai-root {
  position: fixed; bottom: 20px; right: 20px; z-index: 2147483000;
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif !important;
  font-size: 14px; line-height: 1.45; color: #1f2937;
  --botai-accent: #0f172a;       /* navy header/launcher */
  --botai-accent-2: #1e293b;
  --botai-user: #2563eb;         /* bolla utente */
  --botai-radius: 16px;
}

/* Azzera completamente i controlli che il tema "trucca" (padding/colori/pill). */
#botai-root button,
#botai-root input,
#botai-root a {
  -webkit-appearance: none !important; appearance: none !important;
  margin: 0 !important; box-shadow: none !important;
  text-transform: none !important; letter-spacing: normal !important;
  font-family: inherit !important; line-height: normal !important;
  min-width: 0 !important; width: auto; max-width: none !important;
  text-decoration: none !important; outline: none;
}

/* ---- Launcher (bolla flottante) ---- */
#botai-toggle {
  width: 60px !important; height: 60px !important; padding: 0 !important;
  border: 0 !important; border-radius: 50% !important;
  background: var(--botai-accent) !important; color: #fff !important;
  font-size: 26px !important; line-height: 60px !important; cursor: pointer;
  box-shadow: 0 6px 18px rgba(15,23,42,.32) !important;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease, box-shadow .15s ease;
}
#botai-toggle:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 10px 24px rgba(15,23,42,.4) !important; }
#botai-toggle:active { transform: scale(.96); }

/* ---- Pannello chat ---- */
#botai-panel {
  position: absolute; bottom: 76px; right: 0;
  width: 370px; max-width: calc(100vw - 32px);
  height: 540px; max-height: calc(100vh - 110px);
  background: #fff; border: 1px solid rgba(15,23,42,.08);
  border-radius: var(--botai-radius); overflow: hidden;
  box-shadow: 0 16px 48px rgba(15,23,42,.24);
  display: flex; flex-direction: column;
  animation: botai-in .18s ease;
}
#botai-panel[hidden] { display: none; }
@keyframes botai-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---- Header ---- */
#botai-header {
  background: linear-gradient(135deg, var(--botai-accent), var(--botai-accent-2));
  color: #fff; padding: 14px 16px; flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
}
#botai-title { font-weight: 600; font-size: 15px; flex: 1 1 auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Logo white-label (opzionale): piccolo, in testa al titolo. */
#botai-logo {
  flex: 0 0 auto; height: 26px !important; width: auto !important; max-width: 120px !important;
  border-radius: 6px !important; object-fit: contain; background: rgba(255,255,255,.12);
}
#botai-logo[hidden] { display: none; }
#botai-close {
  flex: 0 0 auto; width: 30px !important; height: 30px !important; padding: 0 !important;
  border: 0 !important; border-radius: 50% !important;
  background: rgba(255,255,255,.14) !important; color: #fff !important;
  font-size: 20px !important; line-height: 30px !important; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
#botai-close:hover { background: rgba(255,255,255,.28) !important; }

/* ---- Messaggi ---- */
#botai-messages {
  flex: 1 1 auto; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 8px;
  background: #f8fafc; -webkit-overflow-scrolling: touch;
}
.botai-msg {
  padding: 10px 13px; border-radius: 14px; max-width: 82%;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  font-size: 14px; line-height: 1.5; box-shadow: 0 1px 2px rgba(15,23,42,.06);
}
.botai-user { background: var(--botai-user); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.botai-bot  { background: #fff; color: #1f2937; align-self: flex-start;
  border: 1px solid #e5e7eb; border-bottom-left-radius: 4px; }
.botai-msg a { color: inherit; text-decoration: underline !important; font-weight: 600; word-break: break-all; }
.botai-user a { color: #fff; }

/* ---- Fonti (link alla pagina/sezione di origine della risposta) ---- */
.botai-sources { margin-top: 8px; padding-top: 6px; border-top: 1px solid #eef0f3;
  font-size: 12px !important; line-height: 1.4; color: #64748b; }
.botai-sources a { color: var(--botai-accent, #2563eb) !important; font-weight: 600;
  text-decoration: underline !important; word-break: break-word; }

/* ---- Bottoni d'acquisto (Aggiungi al carrello / Vai al checkout) ---- */
.botai-actions { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.botai-cta {
  display: inline-block; padding: 9px 14px; border-radius: 10px;
  font-size: 13px !important; font-weight: 700 !important; line-height: 1.2;
  text-decoration: none !important; cursor: pointer; word-break: normal;
  border: 1px solid transparent; transition: background .15s ease, transform .1s ease; }
.botai-cta:hover { transform: translateY(-1px); }
.botai-cta:active { transform: translateY(0); }
/* "Aggiungi al carrello": verde commerce, alta affordance */
.botai-cta-cart { background: #16a34a !important; color: #fff !important; }
.botai-cta-cart:hover { background: #15803d !important; }
/* "Vai al checkout": accento del brand (navy) */
.botai-cta-checkout { background: var(--botai-accent) !important; color: #fff !important; }
.botai-cta-checkout:hover { background: var(--botai-accent-2) !important; }

/* ---- Indicatore "sta scrivendo" ---- */
.botai-typing { display: inline-flex; gap: 4px; align-items: center; padding: 14px 14px !important; }
.botai-typing span { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; display: inline-block;
  animation: botai-bounce 1.2s infinite ease-in-out both; }
.botai-typing span:nth-child(2) { animation-delay: .15s; }
.botai-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes botai-bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

/* ---- Input ---- */
#botai-form { display: flex; align-items: stretch; gap: 8px; padding: 10px;
  border-top: 1px solid #e5e7eb; background: #fff; flex: 0 0 auto; }
#botai-input {
  flex: 1 1 auto; border: 1px solid #cbd5e1 !important; border-radius: 22px !important;
  padding: 11px 15px !important; height: 44px !important;
  font-size: 15px !important; color: #1f2937 !important; background: #fff !important;
  outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
#botai-input:focus { border-color: var(--botai-user) !important; box-shadow: 0 0 0 3px rgba(37,99,235,.15) !important; }
#botai-form button {
  flex: 0 0 auto; height: 44px !important; min-width: 64px !important; padding: 0 18px !important;
  border: 0 !important; border-radius: 22px !important;
  background: var(--botai-accent) !important; color: #fff !important;
  font-size: 14px !important; font-weight: 600; cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
#botai-form button:hover { background: var(--botai-accent-2) !important; }
#botai-form button:active { transform: scale(.96); }

/* ---- "Powered by" (white-label) ---- */
#botai-powered { display: block; font-size: 11px !important; text-align: center;
  padding: 6px 4px 2px; color: #94a3b8 !important; background: #fff; flex: 0 0 auto;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#botai-powered[hidden] { display: none; }

/* ---- Privacy ---- */
#botai-privacy { display: block; font-size: 11px !important; text-align: center;
  padding: 6px 4px 8px; color: #94a3b8 !important; background: #fff; flex: 0 0 auto; }
#botai-privacy:hover { color: #64748b !important; text-decoration: underline !important; }
#botai-privacy[hidden] { display: none; }

/* ---- Mobile: pannello a (quasi) tutto schermo ---- */
@media (max-width: 480px) {
  #botai-root { bottom: 16px; right: 16px; }
  #botai-toggle { width: 56px !important; height: 56px !important; line-height: 56px !important; font-size: 24px !important; }
  #botai-panel {
    position: fixed; inset: 0; right: 0; bottom: 0; left: 0;
    width: 100vw; max-width: 100vw;
    height: 100%; height: 100dvh; max-height: 100dvh;
    border-radius: 0; border: 0;
    /* rispetta notch/barra di sistema */
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #botai-header { padding-top: calc(14px + env(safe-area-inset-top, 0px)); }
  .botai-msg { max-width: 88%; font-size: 15px; }
  #botai-input { font-size: 16px !important; } /* evita lo zoom automatico iOS */
  /* a chat aperta nascondiamo il launcher: la X nell'header chiude */
  #botai-root.botai-open #botai-toggle { display: none; }
}
