/* ==========================================================================
   SilvestroFisio chatbot widget
   ========================================================================== */

#sf-chatbot {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 9999;
  font-family: var(--wp--preset--font-family--sans);
}

/* Toggle button */
.sf-chatbot-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.875rem 1.25rem 0.875rem 1rem;
  border: 0;
  border-radius: 999px;
  /* primary-dark per contrast AAA con white text (6.47:1 vs 4.83:1) */
  background: var(--wp--preset--color--primary-dark);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(26, 58, 57, 0.18),
              0 0 0 0 rgba(44, 166, 164, 0.55);
  transition: background .15s ease, box-shadow .15s ease;
  /* Anim: saltellino discreto + alone pulsante */
  animation: sf-chat-bounce 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite,
             sf-chat-glow   2.4s ease-out infinite;
  transform-origin: center;
  will-change: transform, box-shadow;
}
.sf-chatbot-toggle:hover {
  background: #991B1B;
  /* Pausa l'animazione: l'utente sta per cliccare, non lo confondiamo */
  animation-play-state: paused;
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 12px 32px rgba(26, 58, 57, 0.28),
              0 0 0 6px rgba(44, 166, 164, 0.18);
}
.sf-chatbot-toggle:active {
  transform: translateY(0) scale(0.98);
}

.sf-chatbot-toggle-icon {
  font-size: 1.15rem;
  line-height: 1;
  display: inline-block;
  /* Wave dell'icona 💬 sincronizzato col bounce */
  animation: sf-chat-wave 3.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  transform-origin: 70% 70%;
}

#sf-chatbot.is-open .sf-chatbot-toggle { display: none; }

/* Animazioni "ehi sono qui" */
@keyframes sf-chat-bounce {
  0%, 60%, 100% { transform: translateY(0) scale(1); }
  10%  { transform: translateY(-7px) scale(1.02); }
  20%  { transform: translateY(0) scale(1); }
  28%  { transform: translateY(-3px) scale(1.01); }
  36%  { transform: translateY(0) scale(1); }
}

@keyframes sf-chat-glow {
  0% {
    box-shadow: 0 6px 20px rgba(26, 58, 57, 0.18),
                0 0 0 0 rgba(44, 166, 164, 0.55);
  }
  70% {
    box-shadow: 0 6px 20px rgba(26, 58, 57, 0.18),
                0 0 0 16px rgba(44, 166, 164, 0);
  }
  100% {
    box-shadow: 0 6px 20px rgba(26, 58, 57, 0.18),
                0 0 0 0 rgba(44, 166, 164, 0);
  }
}

@keyframes sf-chat-wave {
  0%, 60%, 100% { transform: rotate(0); }
  10%  { transform: rotate(-12deg); }
  20%  { transform: rotate(8deg); }
  30%  { transform: rotate(-4deg); }
  40%  { transform: rotate(0); }
}

/* Reduced motion: nessuna animazione */
@media (prefers-reduced-motion: reduce) {
  .sf-chatbot-toggle,
  .sf-chatbot-toggle-icon {
    animation: none !important;
  }
  .sf-chatbot-toggle:hover { transform: none; }
}

/* Panel */
.sf-chatbot-panel {
  width: min(380px, calc(100vw - 2.5rem));
  height: min(540px, calc(100vh - 3rem));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(26, 58, 57, 0.22);
  overflow: hidden;
}
.sf-chatbot-panel[hidden] { display: none; }

/* Header */
.sf-chatbot-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, var(--wp--preset--color--primary) 0%, var(--wp--preset--color--primary-dark) 100%);
  color: #fff;
}
.sf-chatbot-header h3 {
  margin: 0;
  font-family: var(--wp--preset--font-family--serif);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sf-chatbot-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.35;
}
.sf-chatbot-close {
  flex-shrink: 0;
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .15s ease;
  padding: 0;
}
.sf-chatbot-close:hover { background: rgba(255, 255, 255, 0.18); }

/* Messages */
.sf-chatbot-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--wp--preset--color--bg);
  font-size: 0.9375rem;
  line-height: 1.55;
}
.sf-msg {
  max-width: 85%;
  padding: 0.75rem 1rem;
  border-radius: 14px;
  word-wrap: break-word;
}
.sf-msg p { margin: 0 0 0.5rem; }
.sf-msg p:last-child { margin: 0; }
.sf-msg a {
  color: var(--wp--preset--color--primary-dark);
  text-decoration: underline;
  font-weight: 500;
}
.sf-msg-disclaimer {
  margin-top: 0.5rem !important;
  font-size: 0.78rem !important;
  color: var(--wp--preset--color--fg-muted);
}
.sf-msg--bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--wp--preset--color--border);
  color: var(--wp--preset--color--fg);
  border-bottom-left-radius: 4px;
}
.sf-msg--user {
  align-self: flex-end;
  background: var(--wp--preset--color--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sf-msg--user a { color: var(--wp--preset--color--primary-soft); }
.sf-msg--error {
  align-self: stretch;
  background: var(--wp--preset--color--sand-soft);
  border: 1px solid var(--wp--preset--color--accent);
  color: var(--wp--preset--color--fg);
  font-size: 0.85rem;
  text-align: center;
}

.sf-msg--typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 4px;
  padding: 0.85rem 1rem;
  background: #fff;
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.sf-msg--typing span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--wp--preset--color--fg-subtle);
  animation: sf-typing 1.2s infinite;
}
.sf-msg--typing span:nth-child(2) { animation-delay: 0.15s; }
.sf-msg--typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sf-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* Form */
.sf-chatbot-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  background: #fff;
  border-top: 1px solid var(--wp--preset--color--border);
}
#sf-chatbot-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--wp--preset--color--border);
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.4;
  background: var(--wp--preset--color--bg);
  max-height: 120px;
  min-height: 44px;
  color: var(--wp--preset--color--fg);
  transition: border-color .15s ease, background .15s ease;
}
#sf-chatbot-input:focus {
  outline: none;
  border-color: var(--wp--preset--color--primary);
  background: #fff;
}
.sf-chatbot-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--wp--preset--color--primary);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease;
}
.sf-chatbot-send:hover:not(:disabled) { background: var(--wp--preset--color--primary-dark); }
.sf-chatbot-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Mobile fullscreen */
@media (max-width: 560px) {
  #sf-chatbot { right: 1rem; bottom: 1rem; }
  .sf-chatbot-panel {
    width: calc(100vw - 1rem);
    height: calc(100vh - 1rem);
    bottom: 0.5rem;
    right: 0.5rem;
    max-width: none;
  }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  .sf-msg--typing span { animation: none; }
  .sf-chatbot-toggle:hover { transform: none; }
}
