/* ===================================
   AdFlozy AI Chat Widget
   Premium Glassmorphism Style
   =================================== */

/* Chat Toggle Button */
.chat-toggle {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--accent-gradient);
  border: none;
  cursor: pointer;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 8px 32px rgba(139, 92, 246, 0.45),
    0 0 0 0 rgba(139, 92, 246, 0.4);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow 0.3s ease;
  animation: chat-pulse 3s ease-in-out infinite;
}

.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow:
    0 12px 40px rgba(139, 92, 246, 0.6),
    0 0 0 0 rgba(139, 92, 246, 0);
  animation: none;
}

.chat-toggle:active {
  transform: scale(0.95);
}

@keyframes chat-pulse {
  0%, 100% {
    box-shadow:
      0 8px 32px rgba(139, 92, 246, 0.45),
      0 0 0 0 rgba(139, 92, 246, 0.4);
  }
  50% {
    box-shadow:
      0 8px 32px rgba(139, 92, 246, 0.45),
      0 0 0 12px rgba(139, 92, 246, 0);
  }
}

.chat-toggle-icon {
  width: 28px;
  height: 28px;
  color: #fff;
  transition: transform 0.3s ease, opacity 0.2s ease;
}

.chat-toggle .chat-icon-close {
  position: absolute;
  transform: scale(0) rotate(-90deg);
  opacity: 0;
}

.chat-toggle.active .chat-icon-open {
  transform: scale(0) rotate(90deg);
  opacity: 0;
}

.chat-toggle.active .chat-icon-close {
  transform: scale(1) rotate(0);
  opacity: 1;
}

/* Online indicator */
.chat-toggle-online {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: var(--success-green);
  border-radius: 50%;
  border: 2.5px solid var(--bg-color);
  animation: online-blink 2.5s ease-in-out infinite;
}

@keyframes online-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Proactive greeting bubble */
.chat-greeting {
  position: fixed;
  bottom: 7rem;
  right: 2rem;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px 16px 4px 16px;
  padding: 1rem 1.25rem;
  max-width: 280px;
  z-index: 9997;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  transform: translateY(10px) scale(0.9);
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-greeting.visible {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.chat-greeting p {
  font-size: 0.9rem;
  color: var(--text-main);
  line-height: 1.5;
  margin: 0;
}

.chat-greeting p strong {
  color: var(--accent-cyan);
}

.chat-greeting-close {
  position: absolute;
  top: 0.4rem;
  right: 0.5rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px;
  transition: color 0.2s ease;
}

.chat-greeting-close:hover {
  color: var(--text-main);
}

/* Chat Window */
.chat-window {
  position: fixed;
  bottom: 7rem;
  right: 2rem;
  width: 400px;
  max-height: 600px;
  height: 70vh;
  background: rgba(14, 14, 18, 0.92);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow:
    0 25px 80px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(255, 255, 255, 0.05) inset;

  /* Entry animation */
  transform: translateY(20px) scale(0.92);
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* Chat Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(20, 20, 26, 0.6);
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.chat-header-avatar svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.chat-header-avatar::after {
  content: '';
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  background: var(--success-green);
  border-radius: 50%;
  border: 2px solid rgba(14, 14, 18, 0.95);
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
  line-height: 1.3;
}

.chat-header-status {
  font-size: 0.75rem;
  color: var(--success-green);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.chat-header-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-header-close:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

/* Chat Messages Area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Message Bubbles */
.chat-message {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  max-width: 88%;
  animation: msg-appear 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes msg-appear {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.chat-message.bot {
  align-self: flex-start;
}

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-message-avatar svg {
  width: 16px;
  height: 16px;
  color: #fff;
}

.chat-message.user .chat-message-avatar {
  background: rgba(255, 255, 255, 0.1);
}

.chat-bubble {
  padding: 0.85rem 1.1rem;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
}

.chat-message.bot .chat-bubble {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
}

.chat-message.user .chat-bubble {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.3) 0%, rgba(86, 0, 192, 0.35) 100%);
  border: 1px solid rgba(139, 92, 246, 0.2);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing Indicator */
.chat-typing {
  display: flex;
  gap: 0.6rem;
  align-items: flex-end;
  max-width: 88%;
  align-self: flex-start;
  animation: msg-appear 0.3s ease-out;
}

.chat-typing .chat-bubble {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 1rem 1.2rem;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes typing-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Quick Action Chips */
.chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  flex-shrink: 0;
}

.chat-chip {
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 20px;
  border: 1px solid rgba(139, 92, 246, 0.25);
  background: rgba(139, 92, 246, 0.08);
  color: var(--accent-cyan);
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  white-space: nowrap;
}

.chat-chip:hover {
  background: rgba(139, 92, 246, 0.18);
  border-color: rgba(139, 92, 246, 0.4);
  transform: translateY(-1px);
}

.chat-chip:active {
  transform: scale(0.97);
}

/* Chat Input Area */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(20, 20, 26, 0.5);
  flex-shrink: 0;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
}

.chat-input {
  width: 100%;
  padding: 0.8rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.9rem;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.chat-input:focus {
  outline: none;
  border-color: rgba(139, 92, 246, 0.4);
  background: rgba(255, 255, 255, 0.07);
}

.chat-input::placeholder {
  color: rgba(161, 161, 170, 0.6);
}

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-gradient);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  opacity: 0.5;
}

.chat-send-btn.active {
  opacity: 1;
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(139, 92, 246, 0.4);
}

.chat-send-btn:active {
  transform: scale(0.93);
}

.chat-send-btn svg {
  width: 18px;
  height: 18px;
  color: #fff;
}

/* Powered by footer */
.chat-powered {
  text-align: center;
  padding: 0.5rem;
  font-size: 0.65rem;
  color: rgba(161, 161, 170, 0.35);
  flex-shrink: 0;
  letter-spacing: 0.03em;
}

.chat-powered span {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 600;
}

/* Mobile responsive */
@media (max-width: 768px) {
  /* Hide greeting bubble completely on mobile/tablet */
  .chat-greeting {
    display: none !important;
  }
}

@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }

  .chat-toggle {
    bottom: 1.25rem;
    right: 1.25rem;
    width: 56px;
    height: 56px;
  }
}

@media (max-width: 768px) and (min-width: 481px) {
  .chat-window {
    width: 360px;
    max-height: 550px;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .chat-toggle {
    animation: none;
  }

  .chat-window,
  .chat-greeting,
  .chat-message {
    transition-duration: 0.1s;
    animation-duration: 0.1s;
  }

  .typing-dot {
    animation: none;
    opacity: 0.6;
  }
}
