/**
 * TurniX Chatbot - Stili Widget
 *
 * Design moderno e responsive che si integra con il brand TurniX
 */

/* ============================================
   VARIABILI
   ============================================ */
:root {
  --turnix-primary: #BA1817;
  --turnix-primary-hover: #9a1312;
  --turnix-dark: #2c3e50;
  --turnix-light: #f8f9fa;
  --turnix-border: #dee2e6;
  --chat-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
  --chat-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   BUBBLE (pulsante floating)
   ============================================ */
#turnix-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--turnix-primary) 0%, #d41f1e 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(186, 24, 23, 0.4);
  z-index: 9999;
  transition: var(--chat-transition);
  animation: float 3s ease-in-out infinite;
}

#turnix-chat-bubble:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(186, 24, 23, 0.6);
}

#turnix-chat-bubble i {
  color: white;
  font-size: 28px;
}

/* Badge "Posso aiutarti?" */
#turnix-chat-bubble .chat-badge {
  position: absolute;
  top: -12px;
  right: -8px;
  background: white;
  color: var(--turnix-primary);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  animation: pulse 2s infinite;
  pointer-events: none;
}

/* Nasconde badge dopo interazione */
#turnix-chat-bubble.interacted .chat-badge {
  display: none;
}

/* Animazione floating */
@keyframes float {
  0%, 100% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-8px);
  }
}

/* Animazione pulse per badge */
@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* ============================================
   FINESTRA CHAT
   ============================================ */
#turnix-chat-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 400px;
  max-width: calc(100vw - 48px);
  height: 600px;
  max-height: calc(100vh - 140px);
  background: white;
  border-radius: 16px;
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  z-index: 9998;
  transition: var(--chat-transition);
  overflow: hidden;
}

#turnix-chat-window.hidden {
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
}

/* ============================================
   HEADER CHAT
   ============================================ */
.chat-header {
  background: linear-gradient(135deg, var(--turnix-primary) 0%, #d41f1e 100%);
  color: white;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chat-header-logo {
  height: 28px;
  width: auto;
}

.chat-header-info {
  flex: 1;
}

.chat-header-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  line-height: 1.2;
}

.chat-header-status {
  font-size: 12px;
  opacity: 0.9;
  margin: 2px 0 0 0;
}

.chat-header-status::before {
  content: "●";
  color: #4caf50;
  margin-right: 4px;
  animation: blink 2s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.chat-close {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 24px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--chat-transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(90deg);
}

/* ============================================
   MESSAGGI
   ============================================ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(to bottom, #f8f9fa 0%, white 50px);
}

/* Scrollbar personalizzata */
.chat-messages::-webkit-scrollbar {
  width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--turnix-border);
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* Singolo messaggio */
.chat-message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Messaggio utente */
.chat-message.user {
  background: var(--turnix-primary);
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(186, 24, 23, 0.2);
}

/* Messaggio bot */
.chat-message.bot {
  background: var(--turnix-light);
  border: 1px solid var(--turnix-border);
  color: var(--turnix-dark);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Link nei messaggi bot */
.chat-message.bot a {
  color: var(--turnix-primary);
  text-decoration: underline;
  font-weight: 500;
}

.chat-message.bot a:hover {
  color: var(--turnix-primary-hover);
}

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  background: var(--turnix-light);
  border: 1px solid var(--turnix-border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-self: flex-start;
}

.chat-typing span {
  width: 8px;
  height: 8px;
  background: var(--turnix-border);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* ============================================
   FORM EMAIL (fallback)
   ============================================ */
.chat-email-form {
  background: linear-gradient(135deg, #fff9e6 0%, #fff3cd 100%);
  padding: 16px;
  border-radius: 8px;
  border: 2px solid #ffc107;
  margin-top: 8px;
  box-shadow: 0 2px 8px rgba(255, 193, 7, 0.2);
}

.chat-email-form p {
  margin: 0 0 12px 0;
  font-size: 13px;
  color: #856404;
  font-weight: 500;
}

.chat-email-form input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid #ffc107;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 10px;
  transition: var(--chat-transition);
}

.chat-email-form input:focus {
  outline: none;
  border-color: var(--turnix-primary);
  box-shadow: 0 0 0 3px rgba(186, 24, 23, 0.1);
}

.chat-email-form-buttons {
  display: flex;
  gap: 8px;
}

.chat-email-form button,
.chat-email-form a {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--chat-transition);
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

.chat-email-form button {
  background: var(--turnix-primary);
  color: white;
}

.chat-email-form button:hover {
  background: var(--turnix-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(186, 24, 23, 0.3);
}

.chat-email-form a {
  background: white;
  color: var(--turnix-primary);
  border: 2px solid var(--turnix-primary);
}

.chat-email-form a:hover {
  background: var(--turnix-light);
}

/* ============================================
   QUICK ACTIONS (suggerimenti rapidi)
   ============================================ */
.chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chat-quick-action {
  background: white;
  border: 2px solid var(--turnix-primary);
  color: var(--turnix-primary);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--chat-transition);
}

.chat-quick-action:hover {
  background: var(--turnix-primary);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(186, 24, 23, 0.3);
}

/* ============================================
   INPUT AREA
   ============================================ */
.chat-input-container {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--turnix-border);
  background: white;
}

.chat-input-container input {
  flex: 1;
  border: 2px solid var(--turnix-border);
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 14px;
  transition: var(--chat-transition);
}

.chat-input-container input:focus {
  outline: none;
  border-color: var(--turnix-primary);
  box-shadow: 0 0 0 3px rgba(186, 24, 23, 0.1);
}

.chat-input-container input::placeholder {
  color: #adb5bd;
}

.chat-send-button {
  background: var(--turnix-primary);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  transition: var(--chat-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.chat-send-button:hover:not(:disabled) {
  background: var(--turnix-primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(186, 24, 23, 0.4);
}

.chat-send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================
   MOBILE RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  #turnix-chat-bubble {
    bottom: 16px;
    right: 16px;
    width: 56px;
    height: 56px;
  }

  #turnix-chat-bubble i {
    font-size: 24px;
  }

  #turnix-chat-bubble .chat-badge {
    display: none; /* Badge nascosto su mobile per spazio */
  }

  #turnix-chat-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 100px);
    right: 8px;
    bottom: 80px;
    border-radius: 12px;
  }

  .chat-header {
    padding: 14px 16px;
  }

  .chat-header-logo {
    height: 24px;
  }

  .chat-header-title {
    font-size: 14px;
  }

  .chat-header-status {
    font-size: 11px;
  }

  .chat-messages {
    padding: 16px;
    gap: 12px;
  }

  .chat-message {
    max-width: 85%;
    font-size: 13px;
  }

  .chat-input-container {
    padding: 12px 16px;
  }
}

/* Landscape mobile */
@media (max-width: 767px) and (orientation: landscape) {
  #turnix-chat-window {
    height: calc(100vh - 60px);
    bottom: 50px;
  }

  .chat-messages {
    padding: 12px;
  }
}

/* ============================================
   UTILITIES
   ============================================ */

/* Stato loading */
.chat-loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Errore messaggio */
.chat-error {
  background: #f8d7da;
  border-color: #f5c6cb;
  color: #721c24;
}

/* Nascosto */
.hidden {
  display: none !important;
}

/* Fade in animation */
.fade-in {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ============================================
   ACCESSIBILITÀ
   ============================================ */

/* Focus visibile per accessibilità */
#turnix-chat-bubble:focus,
.chat-close:focus,
.chat-send-button:focus,
.chat-input-container input:focus {
  outline: 3px solid rgba(186, 24, 23, 0.4);
  outline-offset: 2px;
}

/* ============================================
   Toast Notifications
   ============================================ */

.chat-toast {
  position: fixed;
  bottom: 100px;
  right: 30px;
  background: #333;
  color: white;
  padding: 15px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
  z-index: 100001;
  max-width: 350px;
  font-size: 14px;
  line-height: 1.4;
}

.chat-toast.show {
  opacity: 1;
  transform: translateY(0);
}

.chat-toast-error {
  background: #d32f2f;
}

.chat-toast-success {
  background: #388e3c;
}

.chat-toast-warning {
  background: #f57c00;
}

.chat-toast-info {
  background: #1976d2;
}

/* Mobile: sposta toast in basso */
@media (max-width: 767px) {
  .chat-toast {
    bottom: 90px;
    right: 15px;
    left: 15px;
    max-width: none;
  }
}

/* ============================================
   Riduzione movimento per utenti sensibili
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
