/* ============================================
   INDICATORE DIGITAZIONE
   ============================================ */
.mesule-chatbot-typing {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  opacity: 1;
  animation: chatbot-fade-in 0.3s ease-out;
}

.mesule-chatbot-typing .mesule-chatbot-message-avatar {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  color: white;
}

.mesule-chatbot-typing-dots {
  background: var(--chatbot-white);
  padding: 12px 16px;
  border-radius: var(--chatbot-border-radius);
  border: 1px solid var(--chatbot-gray-200);
  display: flex;
  gap: 4px;
  align-items: center;
}

.mesule-chatbot-typing-dots span {
  width: 8px;
  height: 8px;
  background: var(--chatbot-gray-400);
  border-radius: 50%;
  animation: chatbot-typing-bounce 1.4s infinite ease-in-out;
}

.mesule-chatbot-typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}

.mesule-chatbot-typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes chatbot-typing-bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes chatbot-fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   AREA INPUT
   ============================================ */
.mesule-chatbot-input-area {
  border-top: 1px solid var(--chatbot-gray-200);
  background: var(--chatbot-white);
  padding: 16px 20px 12px;
}

.mesule-chatbot-input-container {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.mesule-chatbot-input-container input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid var(--chatbot-gray-200);
  border-radius: var(--chatbot-border-radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--chatbot-white);
  transition: var(--chatbot-transition-fast);
  resize: none;
  outline: none;
}

.mesule-chatbot-input-container input:focus {
  border-color: var(--chatbot-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.mesule-chatbot-input-container input::placeholder {
  color: var(--chatbot-gray-500);
}

.mesule-chatbot-send {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: var(--chatbot-border-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--chatbot-transition-fast);
  font-size: 16px;
  flex-shrink: 0;
}

.mesule-chatbot-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.mesule-chatbot-send:active {
  transform: translateY(0);
}

.mesule-chatbot-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.mesule-chatbot-footer {
  text-align: center;
  margin-top: 8px;
}

.mesule-chatbot-footer small {
  color: var(--chatbot-gray-500);
  font-size: 11px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet */
@media (max-width: 768px) {
  .mesule-chatbot-container {
    bottom: 16px;
    right: 16px;
  }

  .mesule-chatbot-window {
    width: 340px;
    height: 480px;
    bottom: 70px;
  }

  .mesule-chatbot-button {
    width: 56px;
    height: 56px;
  }

  .mesule-chatbot-icon,
  .mesule-chatbot-close-icon {
    font-size: 22px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .mesule-chatbot-container {
    bottom: 12px;
    right: 12px;
    left: 12px;
  }

  .mesule-chatbot-window {
    width: 100%;
    height: 70vh;
    max-height: 500px;
    bottom: 60px;
    right: 0;
    border-radius: var(--chatbot-border-radius);
  }

  .mesule-chatbot-header {
    padding: 12px 16px;
    border-radius: var(--chatbot-border-radius) var(--chatbot-border-radius) 0 0;
  }

  .mesule-chatbot-messages {
    padding: 16px;
  }

  .mesule-chatbot-input-area {
    padding: 12px 16px 8px;
  }

  .mesule-chatbot-message-user .mesule-chatbot-message-text {
    max-width: 85%;
  }
}

/* Mobile molto piccolo */
@media (max-width: 320px) {
  .mesule-chatbot-window {
    height: 75vh;
  }

  .mesule-chatbot-header-text h3 {
    font-size: 14px;
  }

  .mesule-chatbot-header-text p {
    font-size: 11px;
  }

  .mesule-chatbot-messages {
    padding: 12px;
  }

  .mesule-chatbot-message {
    margin-bottom: 12px;
  }
}

/* ============================================
   ACCESSIBILITÀ
   ============================================ */

/* Focus visibile per navigazione da tastiera */
.mesule-chatbot-button:focus-visible,
.mesule-chatbot-send:focus-visible,
.mesule-chatbot-minimize:focus-visible {
  outline: 2px solid var(--chatbot-accent);
  outline-offset: 2px;
}

.mesule-chatbot-input-container input:focus-visible {
  outline: none; /* Già gestito dal border e box-shadow */
}

/* Riduzione movimento per utenti con preferenze di accessibilità */
@media (prefers-reduced-motion: reduce) {
  .mesule-chatbot-button,
  .mesule-chatbot-window,
  .mesule-chatbot-message,
  .mesule-chatbot-icon,
  .mesule-chatbot-close-icon,
  .mesule-chatbot-send,
  .mesule-chatbot-minimize {
    transition: none;
    animation: none;
  }

  .mesule-chatbot-button::before {
    animation: none;
  }

  .mesule-chatbot-typing-dots span {
    animation: none;
  }

  .mesule-chatbot-messages {
    scroll-behavior: auto;
  }
}

/* ============================================
   TEMI SCURI (SUPPORTO AUTOMATICO)
   ============================================ */
@media (prefers-color-scheme: dark) {
  :root {
    --chatbot-white: #1f2937;
    --chatbot-gray-50: #111827;
    --chatbot-gray-100: #1f2937;
    --chatbot-gray-200: #374151;
    --chatbot-gray-300: #4b5563;
    --chatbot-gray-800: #f9fafb;
    --chatbot-gray-500: #9ca3af;
  }

  .mesule-chatbot-window {
    border-color: var(--chatbot-gray-300);
  }

  .mesule-chatbot-message-text {
    color: var(--chatbot-gray-800);
  }

  .mesule-chatbot-message-user .mesule-chatbot-message-text {
    background: var(--chatbot-gray-200);
    color: var(--chatbot-gray-800);
  }

  .mesule-chatbot-input-container input {
    background: var(--chatbot-gray-100);
    color: var(--chatbot-gray-800);
    border-color: var(--chatbot-gray-300);
  }

  .mesule-chatbot-input-container input::placeholder {
    color: var(--chatbot-gray-500);
  }
}

/* ============================================
   STATI HOVER AVANZATI
   ============================================ */

/* Effetti hover per messaggio bot */
.mesule-chatbot-message-bot:hover .mesule-chatbot-message-text {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

/* Effetti hover per messaggio utente */
.mesule-chatbot-message-user:hover .mesule-chatbot-message-text {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ============================================
   UTILITIES E CLASSI DI SUPPORTO
   ============================================ */

/* Classe per nascondere elementi mantenendo accessibilità */
.mesule-chatbot-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Classe per disabilitare le interazioni */
.mesule-chatbot-disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* Classe per messaggi in evidenza */
.mesule-chatbot-message-highlight .mesule-chatbot-message-text {
  border-left: 4px solid var(--chatbot-accent);
  background: linear-gradient(135deg, var(--chatbot-accent) 0%, var(--chatbot-primary) 100%);
  color: white;
}

/* ============================================
   ANIMAZIONI AGGIUNTIVE
   ============================================ */

/* Animazione per l'apertura del chatbot */
@keyframes chatbot-window-appear {
  0% {
    opacity: 0;
    transform: translateY(30px) scale(0.9);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Animazione per nuovi messaggi */
@keyframes chatbot-message-slide-in {
  0% {
    opacity: 0;
    transform: translateX(-20px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

.mesule-chatbot-message-bot {
  animation: chatbot-message-slide-in 0.3s ease-out;
}

.mesule-chatbot-message-user {
  animation: chatbot-message-slide-in 0.3s ease-out;
  animation-direction: reverse;
}

/* ============================================
   COMPATIBILITÀ BROWSER
   ============================================ */

/* Fallback per browser più vecchi */
.mesule-chatbot-window {
  background: #ffffff; /* Fallback per var(--chatbot-white) */
}

.mesule-chatbot-button {
  background: #2563eb; /* Fallback per gradient */
}

/* Supporto per Safari */
@supports (-webkit-backdrop-filter: blur(10px)) {
  .mesule-chatbot-avatar,
  .mesule-chatbot-minimize {
    -webkit-backdrop-filter: blur(10px);
  }
}


:root {
  /* Colori principali (personalizzabili via JavaScript)*/
  --chatbot-primary: #2563eb;
  --chatbot-secondary: #1e40af;
  --chatbot-accent: #3b82f6;
  --chatbot-success: #10b981;
  --chatbot-warning: #f59e0b;
  --chatbot-error: #ef4444;

  /* Colori neutri */
  --chatbot-white: #ffffff;
  --chatbot-gray-50: #f9fafb;
  --chatbot-gray-100: #f3f4f6;
  --chatbot-gray-200: #e5e7eb;
  --chatbot-gray-300: #d1d5db;
  --chatbot-gray-400: #9ca3af;
  --chatbot-gray-500: #6b7280;
  --chatbot-gray-600: #4b5563;
  --chatbot-gray-700: #374151;
  --chatbot-gray-800: #1f2937;
  --chatbot-gray-900: #111827;

  /* Dimensioni */
  --chatbot-border-radius: 12px;
  --chatbot-border-radius-lg: 16px;
  --chatbot-shadow: 0 10px 25px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --chatbot-shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25);

  /* Animazioni */
  --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --chatbot-transition-fast: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);

  /* Z-index */
  --chatbot-z-index: 9999;
}

/* ============================================
   RESET E BASE
   ============================================ */
.mesule-chatbot-container * {
  box-sizing: border-box;
}

/* ============================================
   CONTENITORE PRINCIPALE
   ============================================ */
.mesule-chatbot-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: var(--chatbot-z-index);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--chatbot-gray-800);
}

/* ============================================
   PULSANTE DI APERTURA
   ============================================ */
.mesule-chatbot-button {
  position: relative;
  width: 50px;
  height: 50px;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--chatbot-shadow);
  transition: var(--chatbot-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.mesule-chatbot-button:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: var(--chatbot-shadow-lg);
}

.mesule-chatbot-button:active {
  transform: translateY(0) scale(0.98);
}

/* Icone del pulsante */
.mesule-chatbot-icon,
.mesule-chatbot-close-icon {
  font-size: 24px;
  transition: var(--chatbot-transition);
  position: absolute;
  color: white;
}

.mesule-chatbot-close-icon {
  opacity: 0;
  transform: rotate(180deg) scale(0.8);
}

.mesule-chatbot-open .mesule-chatbot-icon {
  opacity: 0;
  transform: rotate(-180deg) scale(0.8);
}

.mesule-chatbot-open .mesule-chatbot-close-icon {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Effetto pulsazione */
.mesule-chatbot-button::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  opacity: 0;
  animation: chatbot-pulse 2s infinite;
  z-index: -1;
}

@keyframes chatbot-pulse {
  0%, 70%, 100% {
    transform: scale(1);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.3;
  }
}

/* ============================================
   FINESTRA DELLA CHAT
   ============================================ */
.mesule-chatbot-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  height: 500px;
  background: var(--chatbot-white);
  border-radius: var(--chatbot-border-radius-lg);
  box-shadow: var(--chatbot-shadow-lg);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: var(--chatbot-transition);
  overflow: hidden;
  border: 1px solid var(--chatbot-gray-200);
}

.mesule-chatbot-open .mesule-chatbot-window {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* ============================================
   HEADER DELLA CHAT
   ============================================ */
.mesule-chatbot-header {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: var(--chatbot-border-radius-lg) var(--chatbot-border-radius-lg) 0 0;
}

.mesule-chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mesule-chatbot-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  backdrop-filter: blur(10px);
}

.mesule-chatbot-header-text h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.mesule-chatbot-header-text p {
  margin: 2px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
}

.mesule-chatbot-minimize {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--chatbot-transition-fast);
  backdrop-filter: blur(10px);
}

.mesule-chatbot-minimize:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

/* ============================================
   AREA MESSAGGI
   ============================================ */
.mesule-chatbot-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: linear-gradient(to bottom, var(--chatbot-gray-50) 0%, var(--chatbot-white) 100%);
}

.mesule-chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

.mesule-chatbot-messages::-webkit-scrollbar-track {
  background: var(--chatbot-gray-100);
  border-radius: 3px;
}

.mesule-chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--chatbot-gray-300);
  border-radius: 3px;
}

.mesule-chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chatbot-gray-400);
}

/* ============================================
   MESSAGGI
   ============================================ */
.mesule-chatbot-message {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  opacity: 0;
  transform: translateY(10px);
  transition: var(--chatbot-transition);
}

.mesule-chatbot-message-visible {
  opacity: 1;
  transform: translateY(0);
}

.mesule-chatbot-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--chatbot-gray-100);
  overflow: hidden;
}

.mesule-chatbot-message-bot .mesule-chatbot-message-avatar {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  color: white;
}

.mesule-chatbot-message-user .mesule-chatbot-message-avatar {
  background: var(--chatbot-gray-200);
  color: var(--chatbot-gray-600);
}

.mesule-chatbot-message-content {
  flex: 1;
  min-width: 0;
}

.mesule-chatbot-message-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--chatbot-gray-600);
  margin-bottom: 4px;
}

.mesule-chatbot-message-text {
  background: var(--chatbot-white);
  padding: 12px 16px;
  border-radius: var(--chatbot-border-radius);
  border: 1px solid var(--chatbot-gray-200);
  word-wrap: break-word;
  line-height: 1.4;
  position: relative;
}

.mesule-chatbot-message-bot .mesule-chatbot-message-text {
  background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-secondary) 100%);
  color: white;
  border-color: var(--chatbot-primary);
}

.mesule-chatbot-message-user .mesule-chatbot-message-text {
  background: var(--chatbot-gray-100);
  border-color: var(--chatbot-gray-300);
  margin-left: auto;
  margin-right: 0;
  max-width: 80%;
}

.mesule-chatbot-message-error .mesule-chatbot-message-text {
  background: var(--chatbot-error);
  color: white;
  border-color: var(--chatbot-error);
}

.mesule-chatbot-message-time {
  font-size: 11px;
  color: var(--chatbot-gray-500);
  margin-top: 4px;
}
