:root {
  --es-chat-bg: #0f111a;
  --es-chat-border: rgba(153, 25, 94, 0.35);
  --es-chat-shadow: 0 20px 45px rgba(3, 0, 12, 0.65);
  --es-chat-user: #99195e;
  --es-chat-assistant: rgba(25, 32, 48, 0.95);
  --es-chat-text: #f5f7ff;
  --es-chat-muted: rgba(255, 255, 255, 0.55);
}

.es-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 340px;
  max-height: 380px;
  display: flex;
  flex-direction: column;
  border-radius: 3px;
  border: 1px solid var(--es-chat-border);
  background: var(--es-chat-bg);
  box-shadow: var(--es-chat-shadow);
  z-index: 9999;
  overflow: hidden;
  backdrop-filter: blur(12px);
  transition: max-height 0.4s ease, transform 0.35s ease, box-shadow 0.35s ease;
}

/* Stato collassato: mostra solo l'header finché l'utente non interagisce */
.es-chat-widget.es-chat-collapsed {
  max-height: 62px;
  cursor: pointer;
}

.es-chat-widget.es-chat-collapsed .es-chat-messages,
.es-chat-widget.es-chat-collapsed .es-chat-form {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}

.es-chat-widget.es-chat-collapsed .es-chat-form {
  padding-left: 16px;
  padding-right: 16px;
}

.es-chat-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, #1d1f2f 0%, #33152a 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  /* Header leggermente più grande per coerenza con il corpo del sito */
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.es-chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: radial-gradient(circle at top, rgba(153, 25, 94, 0.16), transparent 60%);
  transition: opacity 0.3s ease, padding 0.3s ease, max-height 0.3s ease;
}

.es-chat-message {
  padding: 14px 16px;
  border-radius: 3px;
  /* Messaggi più leggibili: corpo ~16px rispetto al default browser */
  font-size: 1rem;
  line-height: 1.58;
  color: var(--es-chat-text);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  word-break: break-word;
}

.es-chat-message-user {
  align-self: flex-end;
  background: var(--es-chat-user);
  border-top-right-radius: 0px;
}

.es-chat-message-assistant {
  align-self: flex-start;
  background: var(--es-chat-assistant);
  border-top-left-radius: 0px;
  color: rgba(255, 255, 255, 0.9);
}

.es-chat-cta-bubble {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.es-chat-cta-copy {
  font-size: 0.95rem;
  color: var(--es-chat-muted);
  margin: 0;
}

.es-chat-cta-button {
  border: none;
  border-radius: 3px;
  background: #99195e;
  color: #fff;
  font-weight: 600;
  padding: 12px 18px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(153, 25, 94, 0.4);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: pulseMagenta 3.5s ease-in-out infinite;
}

.es-chat-cta-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 34px rgba(153, 25, 94, 0.45);
  animation: none;
}

@keyframes pulseMagenta {
  0%, 100% { box-shadow: 0 0 0 0 rgba(233, 30, 99, 0.5); }
  50%      { box-shadow: 0 0 0 12px rgba(233, 30, 99, 0); }
}

@media (prefers-reduced-motion: reduce) {
  .es-chat-cta-button { animation: none; }
}

.es-chat-cta-fallback {
  font-size: 0.9rem;
  display: inline-flex;
  color: var(--es-chat-muted);
  text-decoration: underline;
}

.es-chat-message-assistant a.es-chat-link {
  color: var(--es-chat-user);
  font-weight: 600;
  text-decoration: underline;
}

.es-chat-message-assistant a.es-chat-cta-link {
  display: inline-block;
  margin-top: 8px;
  padding: 10px 16px;
  border-radius: 3px;
  background: #99195e;
  color: #fff;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(153, 25, 94, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.es-chat-message-assistant a.es-chat-cta-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(153, 25, 94, 0.45);
}

.es-chat-form {
  display: flex;
  gap: 10px;
  padding: 14px 16px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(10, 10, 16, 0.9);
  transition: opacity 0.3s ease, padding 0.3s ease, max-height 0.3s ease;
}

#es-chat-input {
  flex: 1;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(18, 20, 32, 0.95);
  padding: 14px;
  color: var(--es-chat-text);
  font-size: 1rem;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

#es-chat-input:focus {
  outline: none;
  border-color: rgba(153, 25, 94, 0.65);
  box-shadow: 0 0 0 2px rgba(153, 25, 94, 0.25);
}

#es-chat-send {
  border: none;
  border-radius: 3px;
  padding: 0 18px;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: var(--es-chat-user);
  /* Commento tecnico: il bottone di invio eredita il rosa istituzionale per evidenziare l'azione primaria. */
  color: #fff;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#es-chat-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#es-chat-send:hover:not(:disabled) {
  transform: translateY(-1px);
}

.es-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 720px) {
  .es-chat-widget {
    /* Allineamento ai safe-area iOS per non sovrapporre home indicator / bordi arrotondati */
    right: max(16px, env(safe-area-inset-right, 0px));
    left: max(16px, env(safe-area-inset-left, 0px));
    width: auto;
    max-width: none;
    bottom: max(16px, env(safe-area-inset-bottom, 0px));
    max-height: calc(100dvh - 32px - env(safe-area-inset-bottom, 0px));
  }
}

/* Animazione fade-in + zoom per il messaggio di benvenuto quando il widget si apre */
.es-chat-bubble-zoom {
  animation: esChatBubbleFadeIn 1.2s ease-out;
}

@keyframes esChatBubbleFadeIn {
  0% {
    opacity: 0;
    transform: scale(0.85) translateY(10px);
  }

  50% {
    opacity: 0.6;
    transform: scale(1.02) translateY(-2px);
  }

  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Animazione fade-in per il bottone CTA "Prenota una call al volo!!" */
.es-chat-cta-bubble {
  animation: esChatCtaFadeIn 1.5s ease-out;
}

@keyframes esChatCtaFadeIn {
  0% {
    opacity: 0;
    transform: translateY(20px);
  }

  60% {
    opacity: 0.7;
    transform: translateY(-5px);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

