/* Chatbot widget – posizione in basso a sinistra; z-index massimo per stare sempre sopra header, cookie bar, altri overlay */
:root {
  --chatbot-header-offset: 0px;
}

#chatbot-widget-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 2147483647;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  background: transparent;
  pointer-events: none;
}
#chatbot-widget-container #chatbot-toggle,
#chatbot-widget-container #chatbot-window {
  pointer-events: auto;
}

#chatbot-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: #1a365d;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

#chatbot-toggle:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
}

#chatbot-toggle svg {
  width: 28px;
  height: 28px;
}

#chatbot-window {
  display: none;
  position: absolute;
  bottom: 70px;
  left: 0;
  width: 400px;
  max-width: calc(100vw - 40px);
  height: 610px;
  max-height: 85vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  flex-direction: column;
  overflow: hidden;
}

#chatbot-window.open {
  display: flex;
}

#chatbot-header {
  background: #1a365d;
  color: white;
  padding: 12px 16px;
  padding-right: 48px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

/* Header collassato dopo avvio chat: più spazio per i messaggi */
#chatbot-header.chatbot-header-collapsed {
  padding: 8px 16px 8px 12px;
  padding-right: 48px;
  flex-shrink: 0;
}
#chatbot-header.chatbot-header-collapsed .chatbot-header-hint,
#chatbot-header.chatbot-header-collapsed .chatbot-header-bot,
#chatbot-header.chatbot-header-collapsed .chatbot-header-contact {
  display: none !important;
}
#chatbot-header.chatbot-header-collapsed .chatbot-header-title {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chatbot-header-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: rgba(255,255,255,0.2);
  color: white;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chatbot-header-close:hover {
  background: rgba(255,255,255,0.35);
}
/* X in basso a destra per chiudere (più comodo per l'utente) */
.chatbot-footer-close {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: rgba(26, 54, 93, 0.9);
  color: white;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 10;
}
.chatbot-footer-close:hover {
  background: #1a365d;
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.chatbot-header-title {
  font-size: 15px;
}
.chatbot-header-hint {
  display: block;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.95;
  margin-top: 4px;
  line-height: 1.35;
}
.chatbot-header-hint strong {
  font-weight: 600;
}
.chatbot-header-bot {
  font-size: 11px;
  font-weight: 400;
  opacity: 0.9;
}
.chatbot-header-contact {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 400;
  opacity: 0.95;
  line-height: 1.4;
}
.chatbot-header-contact a {
  color: white;
  text-decoration: underline;
}
.chatbot-header-contact a:hover {
  opacity: 0.9;
}

#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: #f7fafc;
}

.chatbot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  line-height: 1.4;
  word-wrap: break-word;
}

.chatbot-msg.user {
  margin-left: auto;
  background: #1a365d;
  color: white;
  border-bottom-right-radius: 4px;
}

.chatbot-msg.bot {
  margin-right: auto;
  background: white;
  color: #1a202c;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.chatbot-msg.bot a {
  color: #1a365d;
  text-decoration: underline;
  word-break: break-all;
}

.chatbot-msg.bot a:hover {
  color: #2c5282;
}

.chatbot-msg.error {
  background: #fed7d7;
  color: #c53030;
  font-size: 14px;
}

.chatbot-loading-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chatbot-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #e2e8f0;
  border-top-color: #1a365d;
  border-radius: 50%;
  animation: chatbot-spin 0.8s linear infinite;
}
.chatbot-loading-text {
  font-size: 14px;
  color: #4a5568;
}
@keyframes chatbot-spin {
  to { transform: rotate(360deg); }
}

#chatbot-input-area {
  padding: 10px 12px;
  background: white;
  border-top: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#chatbot-input {
  width: 100%;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
  box-sizing: border-box;
}

.chatbot-input-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#chatbot-input:focus {
  border-color: #1a365d;
  box-shadow: 0 0 0 2px rgba(26, 54, 93, 0.2);
}

/* Su iPhone/iOS Safari non ingrandisce la pagina al focus se l'input ha font-size >= 16px */
@media screen and (max-width: 768px) {
  #chatbot-input,
  #chatbot-contact-form input {
    font-size: 16px;
  }
}

#chatbot-send {
  padding: 10px 16px;
  background: #1a365d;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

#chatbot-send:hover {
  background: #2c5282;
}

#chatbot-send:disabled {
  background: #a0aec0;
  cursor: not-allowed;
}

.chatbot-hidden {
  display: none !important;
}

/* Scelta lingua */
#chatbot-lang-choice {
  padding: 16px;
  background: #f7fafc;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.chatbot-lang-intro-en, .chatbot-lang-intro-it {
  margin: 0 0 8px 0;
  font-weight: 600;
  color: #1a202c;
  font-size: 14px;
}
.chatbot-lang-intro-it { margin-top: 4px; }
.chatbot-privacy-notice-wrap {
  margin: 12px 0;
  padding: 10px 12px;
  background: #edf2f7;
  border-left: 3px solid #1a365d;
  font-size: 12px;
  color: #2d3748;
  line-height: 1.45;
}
.chatbot-privacy-notice-en, .chatbot-privacy-notice-it { margin: 0; }
.chatbot-privacy-notice-it { margin-top: 6px; }
.chatbot-privacy-notice-wrap a { color: #1a365d; text-decoration: underline; }
.chatbot-declaration-en, .chatbot-declaration-it {
  margin: 10px 0 0 0;
  font-size: 12px;
  font-weight: 500;
  color: #4a5568;
}
.chatbot-declaration-it { margin-top: 4px; }
.chatbot-step2-msg {
  margin: 0 0 10px 0;
  font-size: 13px;
  color: #2d3748;
  line-height: 1.45;
}
.chatbot-step2-declaration { margin-top: 10px; }
.chatbot-lang-continue-wrap {
  margin-top: 16px;
}
#chatbot-lang-continue {
  width: 100%;
  padding: 10px 14px;
  background: #1a365d;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
#chatbot-lang-continue:hover:not(:disabled) {
  background: #2c5282;
}
#chatbot-lang-continue:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.chatbot-bot-notice, .chatbot-bot-notice-it {
  margin: 0 0 12px 0;
  padding: 8px 10px;
  background: #edf2f7;
  border-left: 3px solid #1a365d;
  font-size: 12px;
  color: #2d3748;
  line-height: 1.4;
}
.chatbot-bot-notice-it {
  margin-top: 4px;
}
.chatbot-lang-question {
  margin: 0 0 4px 0;
  font-weight: 600;
  color: #1a202c;
}
.chatbot-lang-sub {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: #4a5568;
}
.chatbot-lang-buttons {
  display: flex;
  gap: 10px;
}
.chatbot-lang-buttons button {
  flex: 1;
  padding: 10px 14px;
  background: #1a365d;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.chatbot-lang-buttons button:hover {
  background: #2c5282;
}
.chatbot-lang-buttons button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.chatbot-lang-buttons button:disabled:hover {
  background: #1a365d;
}

.chatbot-consent-wrap {
  margin-top: 14px;
  text-align: right;
}
.chatbot-privacy-label,
.chatbot-terms-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: #4a5568;
  font-weight: normal;
  margin-bottom: 0;
  min-width: 0;
  overflow-wrap: break-word;
  word-wrap: break-word;
}
.chatbot-terms-label {
  margin-top: 10px;
}
.chatbot-privacy-label input[type="checkbox"],
.chatbot-terms-label input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 2px;
}
.chatbot-privacy-label a,
.chatbot-terms-label a {
  color: #1a365d;
  text-decoration: underline;
}
.chatbot-privacy-label a:hover,
.chatbot-terms-label a:hover {
  color: #2c5282;
}
.chatbot-privacy-label a:visited,
.chatbot-terms-label a:visited {
  color: #1a365d;
}
.chatbot-privacy-en,
.chatbot-privacy-it,
.chatbot-terms-en,
.chatbot-terms-it {
  display: block;
  min-width: 0;
  overflow-wrap: break-word;
}
.chatbot-privacy-it,
.chatbot-terms-it {
  margin-top: 4px;
}

/* Pulsante "Termina chat" */
.chatbot-end-link {
  width: 100%;
  margin-top: 8px;
  padding: 6px 0;
  background: transparent !important;
  color: #1a365d !important;
  font-size: 12px;
  text-decoration: underline;
  cursor: pointer;
  border: none;
}
.chatbot-end-link:hover {
  color: #2c5282 !important;
}

.chatbot-input-actions .chatbot-end-link {
  width: auto;
  margin-top: 0;
}

/* Form contatti */
#chatbot-contact-form {
  padding: 16px;
  background: #f7fafc;
  border-top: 1px solid #e2e8f0;
}
.chatbot-form-title {
  margin: 0 0 2px 0;
  font-weight: 600;
  font-size: 14px;
  color: #1a202c;
}
.chatbot-form-sub {
  margin: 0 0 12px 0;
  font-size: 12px;
  color: #4a5568;
}
.chatbot-form-buttons {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  align-items: center;
}
.chatbot-close-form-btn {
  padding: 10px 16px;
  background: #e2e8f0;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  font-size: 14px;
  color: #4a5568;
  cursor: pointer;
}
.chatbot-close-form-btn:hover {
  background: #cbd5e0;
  color: #1a202c;
}
#chatbot-contact-form label {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  color: #2d3748;
}
.chatbot-req {
  color: #e53e3e;
}
.chatbot-phone-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.chatbot-phone-row select {
  width: 100px;
  flex-shrink: 0;
  padding: 8px 8px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
}
.chatbot-phone-row input {
  flex: 1;
  min-width: 0;
}
#chatbot-contact-form input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 14px;
  box-sizing: border-box;
}
#chatbot-contact-form .chatbot-form-buttons button[type="submit"] {
  padding: 10px 20px;
  background: #1a365d;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
#chatbot-contact-form .chatbot-form-buttons button[type="submit"]:hover {
  background: #2c5282;
}

/* Messaggio di ringraziamento */
#chatbot-thank-you {
  padding: 20px 16px;
  background: #f0fff4;
  border-top: 1px solid #9ae6b4;
  text-align: center;
}
.chatbot-thank-msg, .chatbot-thank-msg-it {
  margin: 0;
  font-size: 14px;
  color: #276749;
}
.chatbot-thank-msg-it {
  margin-top: 4px;
  font-size: 13px;
}
.chatbot-thank-disclaimer,
.chatbot-thank-disclaimer-it {
  margin: 12px 0 0 0;
  font-size: 12px;
  color: #2d3748;
}
.chatbot-thank-disclaimer-it {
  margin-top: 4px;
}

/* Messaggio "solo da smartphone" (quando aperto da PC) */
#chatbot-desktop-message {
  padding: 20px 16px;
  background: #f7fafc;
}
.chatbot-desktop-msg, .chatbot-desktop-msg-it {
  margin: 0 0 6px 0;
  font-weight: 600;
  font-size: 14px;
  color: #1a202c;
}
.chatbot-desktop-sub, .chatbot-desktop-sub-it {
  margin: 0;
  font-size: 13px;
  color: #4a5568;
}
.chatbot-desktop-sub-it {
  margin-top: 4px;
}

/* Feedback "la risposta è stata corretta?" */
.chatbot-feedback-wrap {
  margin: 4px 0 12px 0;
  padding: 8px 12px;
  background: #edf2f7;
  border-radius: 8px;
  font-size: 13px;
}
.chatbot-feedback-question {
  margin: 0 0 8px 0;
  color: #2d3748;
  font-weight: 500;
}
.chatbot-feedback-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chatbot-feedback-btn {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid #cbd5e0;
  background: #fff;
  color: #2d3748;
}
.chatbot-feedback-btn:hover {
  background: #f7fafc;
  border-color: #1a365d;
  color: #1a365d;
}
.chatbot-feedback-yes {
  border-color: #48bb78;
  color: #276749;
}
.chatbot-feedback-yes:hover {
  background: #f0fff4;
  border-color: #38a169;
}
.chatbot-feedback-no:hover {
  border-color: #e53e3e;
  color: #c53030;
}
.chatbot-feedback-main-menu {
  border-color: #1a365d;
  color: #1a365d;
}
.chatbot-feedback-main-menu:hover {
  background: #ebf8ff;
  border-color: #2b6cb0;
  color: #2b6cb0;
}

/* Fase filtri: caselle cliccabili (Orari, Servizi, ecc.) */
.chatbot-choices-wrap {
  margin: 8px 0 12px 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 95%;
}
.chatbot-choice-btn {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #1a365d;
  background: #fff;
  color: #1a365d;
  transition: background 0.15s, color 0.15s;
}
.chatbot-choice-btn:hover {
  background: #1a365d;
  color: #fff;
}
.chatbot-choices-secondary .chatbot-choice-btn {
  border-color: #2c5282;
  color: #2c5282;
  background: #edf2f7;
}
.chatbot-choices-secondary .chatbot-choice-btn:hover {
  background: #2c5282;
  color: #fff;
}
.chatbot-more-wrap {
  margin: 10px 0 12px 0;
}
.chatbot-other-choice-question {
  width: 100%;
  margin: 0 0 10px 0;
  font-size: 13px;
  color: #2d3748;
  line-height: 1.4;
  font-weight: 500;
}
.chatbot-more-btn {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid #718096;
  background: #fff;
  color: #4a5568;
}
.chatbot-more-btn:hover {
  background: #e2e8f0;
  border-color: #1a365d;
  color: #1a365d;
}

/* Promemoria dopo inattività: feedback + continuare o lasciare dati */
.chatbot-idle-prompt {
  margin: 10px 0 12px 0;
  padding: 12px 14px;
  background: #ebf8ff;
  border: 1px solid #90cdf4;
  border-radius: 10px;
  font-size: 13px;
}
.chatbot-idle-prompt .chatbot-idle-feedback-question {
  margin: 0 0 8px 0;
  color: #2d3748;
  font-weight: 500;
}
.chatbot-idle-prompt .chatbot-idle-feedback-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.chatbot-idle-prompt .chatbot-idle-feedback-btns .chatbot-idle-btn {
  border: 1px solid #cbd5e0;
  background: #fff;
  color: #2d3748;
}
.chatbot-idle-prompt .chatbot-feedback-yes {
  border-color: #48bb78;
  color: #276749;
}
.chatbot-idle-prompt .chatbot-feedback-yes:hover {
  background: #f0fff4;
  border-color: #38a169;
}
.chatbot-idle-prompt .chatbot-feedback-no:hover {
  border-color: #e53e3e;
  color: #c53030;
}
.chatbot-idle-prompt .chatbot-feedback-main-menu {
  border-color: #1a365d;
  color: #1a365d;
}
.chatbot-idle-prompt .chatbot-feedback-main-menu:hover {
  background: #ebf8ff;
  border-color: #2b6cb0;
  color: #2b6cb0;
}
.chatbot-idle-text {
  margin: 0 0 10px 0;
  color: #2b6cb0;
  line-height: 1.4;
  font-weight: 500;
}
.chatbot-idle-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chatbot-idle-btn {
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  font-weight: 500;
}
.chatbot-idle-continue {
  background: #e2e8f0;
  color: #2d3748;
}
.chatbot-idle-continue:hover {
  background: #cbd5e0;
}
.chatbot-idle-leave {
  background: #1a365d;
  color: white;
}
.chatbot-idle-leave:hover {
  background: #2c5282;
}

/* Desktop: abbassa la maschera del bot (valore da ?top= nell'URL embed, default 220px) */
@media (min-width: 769px) {
  #chatbot-window.open {
    transform: translateY(var(--chatbot-desktop-translate-y, 220px));
  }
}

/* Mobile: full viewport quando chat aperta, niente scroll pagina sotto; spazio in alto per menu sticky */
@media (max-width: 768px) {
  /* Allinea l'icona chat con l'icona WhatsApp: 2-3px più in basso e stessa dimensione */
  #chatbot-widget-container {
    bottom: 7px;
  }
  #chatbot-toggle {
    width: 60px;
    height: 60px;
  }
  #chatbot-toggle svg {
    width: 30px;
    height: 30px;
  }
  body.chat-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
    left: 0;
    top: 0;
  }
  body.chat-open #chatbot-widget-container {
    top: var(--chatbot-header-offset, 0);
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: calc(100vh - var(--chatbot-header-offset, 0px));
    max-width: none;
    border-radius: 0;
  }
  body.chat-open #chatbot-window.open {
    top: 0;
    left: 0;
    right: 0;
    bottom: 70px;
    width: 100%;
    height: auto;
    max-width: none;
    max-height: none;
    border-radius: 0;
    box-shadow: none;
  }
}
