/* AI Chat Widget - Styles */

/* Chat Widget Variables */
:root {
  --chat-primary: #FFD166;
  --chat-background: #0A0E1F;
  --chat-secondary: #1A2A5E;
  --chat-accent: #3B5EDB;
  --chat-text: #FFFFFF;
  --chat-text-secondary: #A0A8B8;
  --chat-border: rgba(255, 255, 255, 0.1);
  --chat-shadow: rgba(0, 0, 0, 0.3);
}

/* Floating Chat Button */
.chat-widget-button {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-primary), #FFE066);
  border: none;
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(255, 209, 102, 0.4);
  transition: all 0.3s ease;
  font-size: 24px;
  color: var(--chat-background);
  animation: chat-pulse 2s infinite;
}

.chat-widget-button:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(255, 209, 102, 0.6);
}

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

.chat-widget-button.minimized {
  animation: none;
}

@keyframes chat-pulse {
  0%, 100% {
    box-shadow: 0 4px 20px rgba(255, 209, 102, 0.4);
  }
  50% {
    box-shadow: 0 4px 25px rgba(255, 209, 102, 0.7);
  }
}

/* Chat Widget Container */
.chat-widget {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 400px;
  height: 600px;
  background: rgba(10, 14, 31, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  box-shadow: 0 20px 40px var(--chat-shadow);
  z-index: 999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  transition: all 0.3s ease;
}

/* Mobile Styles */
@media (max-width: 480px) {
  .chat-widget {
    width: 100%;
    height: 100%;
    height: 100dvh; /* Use dynamic viewport height */
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    border-radius: 20px 20px 0 0;
    position: fixed;
    z-index: 9999; /* Ensure it's above everything including modals */
    animation: slideUpMobile 0.3s ease-out forwards;
  }

  @keyframes slideUpMobile {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  .chat-widget-button {
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    font-size: 20px;
    z-index: 9998; /* Below open widget but above other elements */
  }

  /* Improve mobile chat header */
  .chat-header {
    padding: 12px 16px;
  }

  .chat-header-title {
    font-size: 14px;
  }

  /* Improve mobile messages */
  .chat-messages {
    padding: 16px;
  }

  /* Improve mobile input area */
  .chat-input-area {
    padding: 12px 16px;
    background: rgba(10, 14, 31, 0.95);
    backdrop-filter: blur(10px);
  }

  .chat-input {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px 16px;
  }

  .chat-send-btn {
    width: 48px;
    height: 48px;
    font-size: 16px;
  }
}

@media (max-width: 768px) and (min-width: 481px) {
  .chat-widget {
    width: 90vw;
    max-width: 400px;
    height: 70vh;
    max-height: 600px;
  }

  .chat-widget-button {
    width: 58px;
    height: 58px;
    font-size: 22px;
  }
}

/* Touch interaction styles */
.touch-active {
  transform: scale(0.95);
  opacity: 0.8;
}

/* Mobile-specific improvements */
@media (max-width: 768px) {
  .chat-widget-button {
    /* Add subtle shadow for better visibility */
    box-shadow: 0 4px 20px rgba(255, 209, 102, 0.5);
  }

  .chat-widget {
    /* Ensure proper touch scrolling */
    -webkit-overflow-scrolling: touch;
  }

  .chat-messages {
    /* Better scrolling on mobile */
    -webkit-overflow-scrolling: touch;
  }

  /* Improve button touch targets */
  .chat-history-btn,
  .chat-new-conversation-btn,
  .chat-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Prevent text selection on mobile */
  .chat-widget * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }

  /* Allow text selection in input and messages */
  .chat-input,
  .message {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, var(--chat-secondary), var(--chat-accent));
  padding: 16px 20px;
  border-bottom: 1px solid var(--chat-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  font-size: 16px;
  color: var(--chat-text);
  flex: 1;
  min-width: 0;
}

.chat-header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--chat-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--chat-background);
  flex-shrink: 0;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chat-history-btn,
.chat-new-conversation-btn,
.chat-close-btn {
  background: transparent;
  border: none;
  color: var(--chat-text);
  font-size: 16px;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  transition: all 0.2s ease;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-history-btn:hover,
.chat-new-conversation-btn:hover,
.chat-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: scale(1.05);
}

.chat-history-btn:active,
.chat-new-conversation-btn:active,
.chat-close-btn:active {
  transform: scale(0.95);
}

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

/* Custom Scrollbar for Messages */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

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

/* Message Bubbles */
.message {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  animation: message-appear 0.3s ease-out;
}

.message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-primary));
  color: var(--chat-background);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: rgba(26, 42, 94, 0.6);
  color: var(--chat-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}

.message.system {
  align-self: center;
  background: rgba(255, 209, 102, 0.1);
  color: var(--chat-primary);
  border: 1px solid rgba(255, 209, 102, 0.3);
  font-size: 13px;
  text-align: center;
  max-width: 90%;
}

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

/* Typing Indicator */
.typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(26, 42, 94, 0.6);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
  color: var(--chat-text-secondary);
  font-size: 13px;
}

.typing-dots {
  display: flex;
  gap: 4px;
}

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

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

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

/* Chat Input Area */
.chat-input-area {
  padding: 16px 20px;
  border-top: 1px solid var(--chat-border);
  background: rgba(10, 14, 31, 0.8);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

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

.chat-input {
  width: 100%;
  min-height: 44px;
  max-height: 120px;
  padding: 12px 16px;
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  background: rgba(26, 42, 94, 0.4);
  color: var(--chat-text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s ease;
}

.chat-input:focus {
  border-color: var(--chat-primary);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.2);
}

.chat-input::placeholder {
  color: var(--chat-text-secondary);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chat-accent), var(--chat-primary));
  border: none;
  color: var(--chat-background);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(59, 94, 219, 0.3);
}

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

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.chat-send-btn.rate-limited {
  background: linear-gradient(135deg, #dc2626, #ef4444) !important;
  animation: rate-limit-pulse 2s infinite;
}

@keyframes rate-limit-pulse {
  0%, 100% {
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
  }
  50% {
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.6);
  }
}

/* Error States */
.chat-error {
  background: rgba(220, 38, 38, 0.1);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: #ff6b6b;
  padding: 8px 12px;
  border-radius: 8px;
  margin: 8px 0;
  font-size: 13px;
  text-align: center;
}

/* Privacy Notice */
.privacy-notice {
  font-size: 11px;
  color: var(--chat-text-secondary);
  text-align: center;
  margin-top: 8px;
  line-height: 1.3;
}

.privacy-notice a {
  color: var(--chat-primary);
  text-decoration: none;
}

.privacy-notice a:hover {
  text-decoration: underline;
}

/* Loading States */
.chat-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  color: var(--chat-text-secondary);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--chat-border);
  border-top: 2px solid var(--chat-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .chat-widget-button,
  .message,
  .chat-send-btn,
  .typing-dot {
    animation: none;
  }

  .chat-widget,
  .chat-widget-button {
    transition: none;
  }
}

/* Focus states for keyboard navigation */
.chat-widget-button:focus,
.chat-history-btn:focus,
.chat-close-btn:focus,
.chat-input:focus,
.chat-send-btn:focus {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* Review Link Styling */
.review-link {
  color: var(--chat-primary);
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px dotted var(--chat-primary);
  transition: all 0.2s ease;
}

.review-link:hover {
  color: #FFE066;
  border-bottom-color: #FFE066;
  background: rgba(255, 209, 102, 0.1);
  padding: 2px 4px;
  border-radius: 3px;
}

/* Affiliate Disclosure Styling */
.message.assistant i {
  display: block;
  font-size: 0.85em;
  color: var(--chat-text-secondary);
  margin-top: 8px;
  font-style: italic;
  opacity: 0.8;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .chat-widget {
    border: 2px solid var(--chat-text);
  }

  .message.user {
    background: var(--chat-text);
    color: var(--chat-background);
  }

  .message.assistant {
    background: var(--chat-background);
    color: var(--chat-text);
    border: 2px solid var(--chat-text);
  }

  .review-link {
    border-bottom: 2px solid var(--chat-primary);
  }
}
