/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: #333;
}

/* Chat Bubble Container */
.chat-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: inherit;
  pointer-events: auto;
}

/* Chat Toggle Button */
.chat-toggle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  position: absolute;
  bottom: 4px;
  right: 10px;
}

.chat-toggle:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

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

/* Chat Window */
.chat-window {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 360px;
  max-width: calc(100% - 40px);
  max-height: 80vh;
  background: white;
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e1e5e9;
  opacity: 1;
  transform: translateY(0) scale(1);
  transition: all 0.28s cubic-bezier(.2,.9,.2,1);
}

.chat-window.hidden {
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
}

/* Chat Header */
.chat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-title h3 {
  font-size: 18px;
  font-weight: 600;
  color: white;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  margin-left: 8px;
  animation: pulse 2s infinite;
}

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

.chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-close:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

/* Messages */
.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #f8fafc;
}

.message {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.3s ease-out;
}

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

.message-content {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 18px;
  word-wrap: break-word;
}

.message.user .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: white;
  color: #333;
  border: 1px solid #e1e5e9;
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 11px;
  color: #6b7280;
  margin-top: 4px;
  padding: 0 8px;
}

/* Input */
.chat-input-container {
  padding: 20px;
  background: white;
  border-top: 1px solid #e1e5e9;
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: #f1f5f9;
  border-radius: 25px;
  padding: 8px 16px;
}

#chatInput {
  flex: 1;
  border: none;
  background: none;
  outline: none;
  font-size: 14px;
  color: #333;
  padding: 8px 0;
}

.send-button {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  transition: transform 0.2s ease;
}

.send-button:hover { transform: scale(1.05); }
.send-button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* Spinner */
.loading-spinner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 2000;
}

.loading-spinner.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: white;
  border: 1px solid #e1e5e9;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  max-width: 80px;
}

.typing-indicator span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #667eea;
  margin: 0 2px;
  animation: typing 1.4s infinite ease-in-out;
}

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

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

/* Product card (used by assistant product responses) */
.cb-product {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid #eef2f7;
  box-shadow: 0 2px 6px rgba(16,24,40,0.03);
  margin-bottom: 10px;
}

.cb-product img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  flex: 0 0 64px;
}

.cb-product > div { display: flex; flex-direction: column; min-width: 0; }
.cb-product .cb-title { font-weight: 600; color: #111827; line-height: 1.1; }
.cb-product .cb-actions { margin-top: 8px; display:flex; gap:8px; align-items:center; }
.cb-product .cb-price { color: #374151; font-weight: 600; font-size: 13px; }

/* Ensure assistant HTML messages use full width for content */
.message-content { max-width: 100%; }

/* Tighter message spacing and better visual separation */
.chat-messages { gap: 8px; display: flex !important; flex-direction: column; }

/* Improved scrollbar for the messages pane */
.chat-messages::-webkit-scrollbar { width: 8px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.3); border-radius: 8px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }

/* Header layout tweaks */
.chat-header .chat-title { display:flex; align-items:center; gap:8px; }

/* Input tweaks */
.cb-input { resize: none; width: 100%; min-height: 36px; max-height: 160px; border: none; background: transparent; font-size: 14px; }
.input-wrapper { padding: 10px 12px; }

/* Responsive: slightly larger width on desktop, full-width on small viewports */
/* (legacy duplicate removed) */

/* Mobile-first: fix overflow and alignment */
@media (max-width: 480px) {
  .chat-window {
    left: 12px;
    right: 12px;
    bottom: 70px;
    width: auto;
    height: 72vh;
    max-height: 72vh;
    border-radius: 12px;
  }

  .chat-bubble {
    bottom: 12px;
    right: 12px;
  }

  .chat-header h3 {
    font-size: 16px;
  }

  .message-content {
    font-size: 14px;
    padding: 10px 14px;
  }

  .chat-input-container {
    padding: 16px;
  }

  .input-wrapper {
    padding: 8px 10px;
  }

  #chatInput {
    font-size: 13px;
  }

  .send-button {
    width: 32px;
    height: 32px;
  }
}

/* Tablet optimization */
@media (max-width: 768px) {
  .chat-window {
    width: 90%;
    left: 5%;
    right: 5%;
    bottom: 70px;
    height: 72vh;
    border-radius: 16px;
  }
}


/* Compatibility: older embedded loader product card */
.chat-product-card { display:flex; gap:10px; align-items:flex-start; padding:8px; border-radius:10px; background:#fff; border:1px solid #eef2f7; margin-bottom:8px; }
.chat-product-card img { width:72px; height:72px; object-fit:cover; border-radius:8px; flex:0 0 72px; }
.chat-product-card .chat-card-body { display:flex; flex-direction:column; min-width:0; }
.chat-product-card a { color: var(--cb-primary,#667eea); text-decoration:none; }

