:root {
  --ai-primary: #a855f7;
  --ai-secondary: #6366f1;
  --ai-bg: #1a1b1e;
  --ai-glass: rgba(26, 27, 30, 0.95);
  --ai-border: rgba(255, 255, 255, 0.1);
  --ai-text: #ffffff;
  --ai-text-muted: #9ca3af;
  --ai-font: "Outfit", -apple-system, BlinkMacSystemFont, sans-serif;
  --ai-radius: 20px;
  --ai-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.ai-chat-widget {
  position: fixed;
  bottom: 110px;
  right: 30px;
  z-index: 9999;
  font-family: var(--ai-font);
}

/* --- Badge Animation --- */
.chat-badge {
  position: absolute;
  top: -55px;
  right: 0;
  background: linear-gradient(135deg, var(--ai-secondary), var(--ai-primary));
  color: white;
  padding: 10px 20px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(168, 85, 247, 0.4);
  animation: float 3s ease-in-out infinite;
  pointer-events: none;
  white-space: nowrap;
}

.chat-badge::after {
  content: "";
  position: absolute;
  bottom: -6px;
  right: 25px;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--ai-primary);
}

/* --- Toggle Button --- */
.chat-toggle {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--ai-secondary) 0%,
    var(--ai-primary) 100%
  );
  box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.7);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  animation: pulse-ring 2s infinite;
}

.chat-toggle:hover {
  transform: scale(1.1) rotate(5deg);
}

.chat-toggle svg {
  width: 32px;
  height: 32px;
  color: white;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* --- Main Window --- */
.chat-window {
  position: absolute;
  bottom: 90px;
  right: 0;
  width: 380px;
  height: 600px;
  background: var(--ai-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--ai-border);
  border-radius: var(--ai-radius);
  box-shadow: var(--ai-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.9) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

/* --- Header --- */
.chat-header {
  background: rgba(255, 255, 255, 0.03);
  padding: 20px;
  border-bottom: 1px solid var(--ai-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-dot {
  width: 10px;
  height: 10px;
  background: #22c55e;
  border-radius: 50%;
  box-shadow: 0 0 10px #22c55e;
  animation: blink 2s infinite;
}

.chat-header h3 {
  margin: 0;
  font-size: 16px;
  color: white;
  font-weight: 600;
  letter-spacing: 0.5px;
}

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

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

.message {
  max-width: 85%;
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
  word-wrap: break-word;
}

.message.ai {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ai-text);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-contact-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.85em;
  line-height: 1.5;
}

.chat-contact-footer a {
  color: var(--ai-primary);
  text-decoration: none;
  font-weight: 600;
}

.chat-contact-footer a:hover {
  text-decoration: underline;
}

.message.user {
  background: linear-gradient(135deg, var(--ai-secondary), var(--ai-primary));
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.message img.message-image {
  max-width: 100%;
  border-radius: 12px;
  margin-top: 10px;
  border: 2px solid rgba(255, 255, 255, 0.1);
}

/* --- Typing Indicator --- */
.typing-indicator {
  padding: 0 24px 12px;
  font-size: 12px;
  color: var(--ai-text-muted);
  font-style: italic;
  opacity: 0.7;
  animation: fadeIn 0.5s;
  display: none;
}

/* --- Image Preview Section --- */
.image-preview-container {
  padding: 12px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--ai-border);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideUp 0.3s ease-out;
}

#imagePreview {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  object-fit: cover;
  border: 2px solid var(--ai-primary);
}

.remove-image {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.remove-image:hover {
  background: #ef4444;
}

/* --- Input Area --- */
.chat-suggestions {
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.suggestion-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--ai-border);
  color: var(--ai-primary);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.suggestion-btn:hover {
  background: rgba(168, 85, 247, 0.15);
  border-color: var(--ai-primary);
  transform: translateY(-2px);
}

.chat-input-area {
  padding: 16px 20px;
  background: rgba(0, 0, 0, 0.2);
  border-top: 1px solid var(--ai-border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.image-upload-btn {
  color: var(--ai-text-muted);
  cursor: pointer;
  transition: color 0.3s;
  display: flex;
  align-items: center;
}
.image-upload-btn:hover {
  color: var(--ai-primary);
}

.chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--ai-border);
  border-radius: 14px;
  padding: 12px 16px;
  color: white;
  font-size: 14px;
  outline: none;
  transition: all 0.3s;
}

.chat-input:focus {
  border-color: var(--ai-secondary);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, var(--ai-secondary), var(--ai-primary));
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.2s,
    box-shadow 0.2s;
}

.chat-send:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(168, 85, 247, 0.4);
}

/* --- Animations --- */
@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(168, 85, 247, 0.7);
  }
  70% {
    box-shadow: 0 0 0 15px rgba(168, 85, 247, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(168, 85, 247, 0);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 600px) {
  /* 
     * Mobile Optimization Redesign
     * Goal: Premium Feel, Fullscreen/Bottom Sheet, Aligned Controls
     */

  /* 1. Hide chat badge on mobile - clutter */
  .chat-badge {
    display: none !important;
  }

  /* 2. Position Chat Toggle next to Sticky App Bar */
  .ai-chat-widget {
    bottom: 18px; /* Adjusted to align center-to-center with Sticky CTA */
    right: 15px;
    z-index: 10000; /* Higher than sticky CTA (99) */
  }

  .chat-toggle {
    width: 50px;
    height: 50px;
    box-shadow: 0 4px 15px rgba(168, 85, 247, 0.4);
  }

  .chat-toggle svg {
    width: 24px;
    height: 24px;
  }

  /* 3. Full Screen / Bottom Sheet Modal */
  .chat-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100dvh; /* Dynamic viewport height */
    max-height: 100dvh;
    border-radius: 0;
    background: rgba(26, 27, 30, 0.98); /* Almost opaque */
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    transform-origin: bottom center;
    transform: translateY(110%); /* Slide form bottom */
    opacity: 0;
    transition:
      transform 0.4s cubic-bezier(0.19, 1, 0.22, 1),
      opacity 0.4s ease;
    z-index: 10001; /* Above everything */
    display: flex;
    flex-direction: column;
  }

  .chat-window.active {
    transform: translateY(0);
    opacity: 1;
  }

  /* Close Button for Mobile */
  .mobile-close-btn {
    display: flex !important; /* Visible on mobile */
  }

  .chat-header {
    padding: 15px 20px;
    /* Safe area for iPhone notch */
    padding-top: max(20px, env(safe-area-inset-top));
  }

  .chat-messages {
    padding-bottom: 80px; /* Space for input area */
  }

  /* Adjust Input Area for mobile keyboard */
  .chat-input-area {
    padding-bottom: max(15px, env(safe-area-inset-bottom));
    background: #1a1b1e; /* Solid background to hide content behind */
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.5);
  }

  /* Adjustments when keyboard is open (detected via JS) */
  .chat-window.keyboard-open .chat-messages {
    padding-bottom: 20px;
  }

  .chat-window.keyboard-open .chat-input-area {
    padding-bottom: 10px;
  }

  .chat-messages {
    -webkit-overflow-scrolling: touch;
  }
}
