/* WA Chat widget. Tutto con prefisso .itwa per non toccare il tema. */
.itwa {
  --itwa-color: #25D366;
  --itwa-x: 20px;
  --itwa-y: 20px;
  position: fixed;
  bottom: calc(var(--itwa-y) + env(safe-area-inset-bottom, 0px));
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: #111b21;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.itwa.is-visible { opacity: 1; transform: none; pointer-events: auto; }
.itwa--right { right: var(--itwa-x); }
.itwa--left { left: var(--itwa-x); }
.itwa *, .itwa *::before, .itwa *::after { box-sizing: border-box; }
.itwa svg { display: block; }

/* Azzera gli stili che il tema applica a tutti i button. L'ID vince sulle regole del tema. */
#itwa-root button {
  all: unset;
  box-sizing: border-box;
}
#itwa-root svg { fill: none; }
#itwa-root svg path[fill="currentColor"] { fill: currentColor; }

#itwa-root .itwa-fab {
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  outline: 0;
  position: relative !important;
  width: 60px !important;
  height: 60px !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: var(--itwa-color) !important;
  color: #fff !important;
  cursor: pointer !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: transform .2s ease, box-shadow .2s ease !important;
}
#itwa-root.itwa--left .itwa-fab { margin-right: auto !important; }
#itwa-root.itwa--right .itwa-fab { margin-left: auto !important; }
#itwa-root .itwa-fab:hover, #itwa-root .itwa-fab:focus, #itwa-root .itwa-fab:active { background: var(--itwa-color) !important; color: #fff !important; }
#itwa-root .itwa-fab:hover { transform: scale(1.06) !important; box-shadow: 0 6px 18px rgba(0, 0, 0, .3) !important; }
#itwa-root .itwa-fab:focus-visible, #itwa-root .itwa-close:focus-visible, #itwa-root .itwa-cta:focus-visible { outline: 3px solid #111b21; outline-offset: 3px; }
#itwa-root .itwa-fab svg { width: 32px !important; height: 32px !important; }

/* bottone chiamata sopra WhatsApp */
#itwa-root .itwa-call {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 60px !important;
  height: 60px !important;
  margin: 0 0 12px !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  color: #fff !important;
  text-decoration: none !important;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25) !important;
  transition: transform .2s ease, box-shadow .2s ease !important;
}
#itwa-root.itwa--right .itwa-call { margin-left: auto !important; }
#itwa-root.itwa--left .itwa-call { margin-right: auto !important; }
#itwa-root .itwa-call:hover { transform: scale(1.06) !important; box-shadow: 0 6px 18px rgba(0, 0, 0, .3) !important; color: #fff !important; }
#itwa-root .itwa-call:focus-visible { outline: 3px solid #111b21; outline-offset: 3px; }
#itwa-root .itwa-call svg { width: 100% !important; height: 100% !important; }
#itwa-root .itwa-call svg .itwa-call-bg { fill: var(--itwa-call-color, #11AFA6) !important; }
.itwa.is-open .itwa-call { display: none !important; }

.itwa-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: #e53935;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #fff;
}

.itwa-box {
  width: 340px;
  max-width: calc(100vw - 2 * var(--itwa-x));
  margin-bottom: 14px;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .22);
  opacity: 0;
  transform: translateY(10px) scale(.97);
  transform-origin: bottom right;
  transition: opacity .2s ease, transform .2s ease;
}
#itwa-root.itwa--left .itwa-box { transform-origin: bottom left; }
.itwa.is-open .itwa-box { opacity: 1; transform: none; }
.itwa-box[hidden] { display: none; }

.itwa-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: var(--itwa-color);
  color: #fff;
}
.itwa-avatar {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.itwa-avatar svg { width: 26px; height: 26px; }
.itwa-avatar img { width: 100%; height: 100%; object-fit: cover; }
.itwa-who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.itwa-name { font-size: 16px; font-weight: 600; }
.itwa-sub { font-size: 13px; opacity: .9; }
#itwa-root .itwa-close {
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: none !important;
  outline: 0;
  flex: 0 0 32px !important;
  width: 32px !important;
  height: 32px !important;
  margin: 0 !important;
  padding: 6px !important;
  border: 0 !important;
  border-radius: 50% !important;
  background: transparent !important;
  color: #fff !important;
  cursor: pointer !important;
}
#itwa-root .itwa-close:focus, #itwa-root .itwa-close:active { background: transparent !important; color: #fff !important; }
#itwa-root .itwa-close:hover { background: rgba(255, 255, 255, .18) !important; color: #fff !important; }

.itwa-body {
  padding: 20px 16px;
  min-height: 110px;
  background-color: #efeae2;
  background-image: radial-gradient(rgba(0, 0, 0, .035) 1px, transparent 1px);
  background-size: 14px 14px;
}
.itwa-bubble {
  position: relative;
  display: inline-block;
  max-width: 90%;
  padding: 9px 12px;
  border-radius: 0 10px 10px 10px;
  background: #fff;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
  white-space: pre-line;
  word-wrap: break-word;
}
.itwa-bubble::before {
  content: "";
  position: absolute;
  top: 0;
  left: -8px;
  border-top: 0 solid transparent;
  border-right: 8px solid #fff;
  border-bottom: 10px solid transparent;
}

#itwa-root .itwa-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 12px;
  padding: 12px 16px;
  border-radius: 24px;
  background: var(--itwa-color);
  color: #fff !important;
  font-weight: 600;
  text-decoration: none !important;
  transition: filter .2s ease;
}
#itwa-root .itwa-cta:hover { filter: brightness(.93); }
#itwa-root .itwa-cta svg { width: 20px; height: 20px; }

@media (max-width: 480px) {
  #itwa-root .itwa-fab, #itwa-root .itwa-call { width: 56px !important; height: 56px !important; }
  .itwa-box { width: calc(100vw - 2 * var(--itwa-x)); }
}

@media (prefers-reduced-motion: reduce) {
  .itwa, .itwa-box, #itwa-root .itwa-fab { transition: none; }
}

@media print { .itwa { display: none !important; } }
