/* AI Shopping Assistant - Frontend Styles */

:root {
  --ai-primary-color: #3B82F6;
  --ai-secondary-color: #8B5CF6;
  --ai-text-color: #374151;
  --ai-bg-color: #ffffff;
  --ai-border-color: #e5e7eb;
  --ai-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
  --ai-shadow-lg: 0 20px 40px rgba(0, 0, 0, 0.15);
}

/* Chat Widget Container */
.ai-chat-widget {
  position: fixed;
  z-index: 999999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --primary-color: var(--ai-primary-color);
  --secondary-color: var(--ai-secondary-color);
  direction: ltr; /* Keep general structure LTR */
}

/* Keep LTR for general layout, only message content will be RTL */
.ai-chat-widget * {
  direction: ltr;
  text-align: left;
}

.ai-chat-bottom-right {
  bottom: 20px;
  right: 20px;
}

.ai-chat-bottom-left {
  bottom: 20px;
  left: 20px;
}

/* Chat Button */
.ai-chat-button {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  cursor: pointer;
  box-shadow: var(--ai-shadow);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ai-chat-button:hover {
  transform: scale(1.1);
  box-shadow: var(--ai-shadow-lg);
}

.ai-chat-button:active {
  transform: scale(0.95);
}

.ai-chat-button svg {
  width: 24px;
  height: 24px;
  transition: all 0.3s ease;
}

.ai-chat-button.ai-chat-open .ai-chat-icon {
  display: none;
}

.ai-chat-button.ai-chat-open .ai-close-icon {
  display: block !important;
  transform: rotate(45deg);
}

.ai-chat-button.ai-chat-open {
  background: #ef4444;
  transform: rotate(45deg);
}

.ai-chat-button.ai-chat-open:hover {
  background: #dc2626;
  transform: rotate(45deg) scale(1.1);
}

/* Unread Badge */
.ai-unread-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ef4444;
  color: white;
  border-radius: 50%;
  min-width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  animation: ai-pulse 2s infinite;
}

/* Chat Window */
.ai-chat-window {
  position: absolute;
  bottom: 70px;
  width: 350px;
  height: 500px;
  background: var(--ai-bg-color);
  border-radius: 16px;
  box-shadow: var(--ai-shadow-lg);
  border: 1px solid var(--ai-border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: ai-slide-up 0.3s ease-out;
}

.ai-chat-bottom-left .ai-chat-window {
  right: 0;
}

.ai-chat-bottom-right .ai-chat-window {
  right: 0;
}

/* Chat Header */
.ai-chat-header {
  background: var(--primary-color);
  color: white;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-chat-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-chat-avatar {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-chat-avatar svg {
  width: 18px;
  height: 18px;
}

.ai-chat-header-text h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--secondary-color);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.ai-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  opacity: 0.9;
  margin-top: 2px;
}

.ai-status-dot {
  width: 8px;
  height: 8px;
  background: #10b981;
  border-radius: 50%;
  animation: ai-pulse 2s infinite;
}

.ai-chat-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.ai-chat-close svg {
  width: 18px;
  height: 18px;
}

/* Messages Container */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.ai-chat-messages::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 10px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Messages */
.ai-message {
  display: flex;
  gap: 8px;
  max-width: 100%;
  margin-bottom: 12px;
}

.ai-message-user {
  justify-content: flex-end; /* User messages on the right */
}

.ai-message-assistant {
  justify-content: flex-start; /* Bot messages on the left */
}

/* Hide avatars */
.ai-message-avatar {
  display: none;
}

.ai-message-content {
  max-width: 280px;
}

.ai-message-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  direction: rtl; /* RTL only for message content */
  text-align: right; /* RTL text alignment */
}

.ai-message-assistant .ai-message-bubble {
  background: white;
  color: var(--ai-text-color);
  border-bottom-left-radius: 6px; /* Standard positioning for assistant */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--ai-border-color);
}

.ai-message-user .ai-message-bubble {
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  border-bottom-right-radius: 6px; /* Standard positioning for user */
}

.ai-message-time {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
  text-align: right;
  direction: rtl;
}

.ai-message-user .ai-message-time {
  text-align: right; /* Keep consistent RTL for timestamps */
}

/* Typing Indicator */
.ai-typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-typing-dots {
  display: flex;
  gap: 4px;
}

.ai-typing-dot {
  width: 8px;
  height: 8px;
  background: #9ca3af;
  border-radius: 50%;
  animation: ai-typing 1.4s infinite ease-in-out;
}

.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }

/* Quick Actions - Completely Hidden */
.ai-quick-actions {
  display: none !important; /* Force hide suggested prompts */
}

/* Input Container */
.ai-chat-input-container {
  border-top: 1px solid var(--ai-border-color);
  background: white;
  padding: 16px;
}

.ai-chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.ai-chat-input-wrapper {
  flex: 1;
  position: relative;
}

.ai-chat-input {
  width: 100%;
  border: 1px solid var(--ai-border-color);
  border-radius: 20px;
  padding: 10px 45px 10px 16px; /* Padding on right for button */
  font-size: 14px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
  min-height: 40px;
  max-height: 100px;
  direction: ltr; /* LTR by default */
  text-align: left;
}

.ai-chat-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.ai-chat-send {
  position: absolute;
  right: 4px; /* Button on the right */
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--primary-color);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  direction: ltr; /* Keep button icon LTR */
}

.ai-chat-send:hover {
  background: var(--secondary-color);
  transform: translateY(-50%) scale(1.1);
}

.ai-chat-send:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  transform: translateY(-50%);
}

.ai-chat-send svg {
  width: 16px;
  height: 16px;
}

.ai-loading-icon {
  animation: ai-spin 1s linear infinite;
}

/* Product Cards */
.ai-product-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.ai-product-card {
  background: white;
  border: 1px solid var(--ai-border-color);
  border-radius: 8px;
  padding: 12px;
  text-decoration: none;
  color: inherit;
  transition: all 0.2s;
}

.ai-product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.ai-product-image {
  width: 100%;
  height: 80px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 8px;
}

.ai-product-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ai-product-price {
  font-size: 12px;
  color: var(--primary-color);
  font-weight: 600;
}

/* Animations */
@keyframes ai-slide-up {
  0% {
    transform: translateY(100%);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes ai-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes ai-typing {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

@keyframes ai-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Responsive Design */
@media (max-width: 768px) {
  .ai-chat-widget {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }
  
  .ai-chat-window {
    width: 100%;
    height: 70vh;
    max-height: 500px;
    bottom: 70px;
  }
  
  .ai-chat-bottom-right .ai-chat-window,
  .ai-chat-bottom-left .ai-chat-window {
    right: 0;
    left: 0;
  }
}

@media (max-width: 480px) {
  .ai-chat-window {
    height: 80vh;
    border-radius: 12px;
  }
  
  .ai-message-content {
    max-width: 200px;
  }
}

/* Greeting Tooltip Styles */
#ai-shopping-assistant-widget .ai-greeting-tooltip {
  position: absolute !important;
  background: red !important; /* Temporary debug color */
  color: white !important;
  padding: 12px 16px !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
  max-width: 250px !important;
  min-width: 200px !important;
  z-index: 10001 !important;
  opacity: 1 !important; /* Force visible for debugging */
  visibility: visible !important; /* Force visible for debugging */
  transform: translateX(0) !important; /* Remove transform for debugging */
  transition: all 0.3s ease !important;
  font-size: 14px !important;
  line-height: 1.4 !important;
  border: 2px solid yellow !important; /* Debug border */
  bottom: 10px !important;
  pointer-events: none !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  display: block !important;
  font-family: inherit !important;
  font-weight: normal !important;
  text-decoration: none !important;
  text-transform: none !important;
  letter-spacing: normal !important;
}

/* Tooltip positioning for bottom-right placement (widget on right, tooltip on left) */
#ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-right .ai-greeting-tooltip {
  right: 75px !important;
  transform: translateX(0) !important; /* Remove transform for debugging */
}

/* Tooltip positioning for bottom-left placement (widget on left, tooltip on right) */
#ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-left .ai-greeting-tooltip {
  left: 75px !important;
  transform: translateX(0) !important; /* Remove transform for debugging */
}

/* Show tooltip on hover */
#ai-shopping-assistant-widget.ai-chat-widget:hover .ai-greeting-tooltip {
  opacity: 1 !important;
  visibility: visible !important;
}

#ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-right:hover .ai-greeting-tooltip {
  transform: translateX(0) !important;
}

#ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-left:hover .ai-greeting-tooltip {
  transform: translateX(0) !important;
}

/* Hide tooltip when chat is open */
#ai-shopping-assistant-widget.ai-chat-open .ai-greeting-tooltip,
#ai-shopping-assistant-widget.ai-chat-widget.ai-chat-open .ai-greeting-tooltip {
  opacity: 0 !important;
  visibility: hidden !important;
}

/* Responsive tooltip adjustments */
@media (max-width: 768px) {
  #ai-shopping-assistant-widget .ai-greeting-tooltip {
    max-width: 200px !important;
    min-width: 160px !important;
    font-size: 13px !important;
    padding: 10px 12px !important;
    bottom: 8px !important;
  }
  
  #ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-right .ai-greeting-tooltip {
    right: 65px !important;
  }
  
  #ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-left .ai-greeting-tooltip {
    left: 65px !important;
  }
}

@media (max-width: 480px) {
  #ai-shopping-assistant-widget .ai-greeting-tooltip {
    max-width: 180px !important;
    min-width: 140px !important;
    font-size: 12px !important;
    padding: 8px 10px !important;
    bottom: 5px !important;
    white-space: normal !important;
    max-height: 60px !important;
    overflow: hidden !important;
  }
  
  #ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-right .ai-greeting-tooltip {
    right: 60px !important;
  }
  
  #ai-shopping-assistant-widget.ai-chat-widget.ai-chat-bottom-left .ai-greeting-tooltip {
    left: 60px !important;
  }
}
