/**
 * @fileoverview Professional Chat Widget Styles for Chahua Web Store
 * @description LINE-inspired chat widget with modern UI and smooth animations
 * @dependencies 
 *   - global.css (base font families)
 * @features
 *   - Floating chat widget with toggle button
 *   - LINE-inspired green theme design
 *   - Smooth slide-up animations
 *   - Responsive chat interface
 *   - Professional chat bubble styling
 * @animations
 *   - slideUp: Chat box entrance animation (0.3s)
 *   - Hover effects on toggle button
 *   - Smooth transitions throughout
 * @performance 
 *   - Fixed positioning for optimal performance
 *   - Hardware-accelerated animations
 *   - Efficient chat message rendering
 * @calledBy All pages with chat widget enabled
 * @example
 * // Chat widget structure:
 * <div class="cha-chat-widget">
 *   <button class="cha-chat-toggle">
 *     <img src="chat-icon.png" alt="Chat">
 *   </button>
 *   <div class="cha-chat-box">Chat Interface</div>
 * </div>
 */

/* css/chat-widget-pro.css */
/* LINE-Inspired Chat Widget Styles */

/* --- Main Widget Container --- */
.cha-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.cha-chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #00B900; /* LINE Green */
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 185, 0, 0.3);
  transition: all 0.3s ease;
}
.cha-chat-toggle img { width: 28px; height: 28px; border-radius: 50%; }
.cha-chat-toggle:hover { transform: scale(1.05); box-shadow: 0 6px 20px rgba(0, 185, 0, 0.4); }

/* --- Chat Box --- */
.cha-chat-box {
  position: absolute;
  bottom: 70px;
  right: 0;
  width: 340px;
  height: 480px;
  max-height: 60vh;
  background: #FFFFFF;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #E5E5EA;
}
.cha-chat-box.open { display: flex; animation: slideUp 0.3s ease-out; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(15px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Header แบบ LINE --- */
.cha-chat-header {
  padding: 12px 16px;
  background: #00B900;
  border-bottom: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  min-height: 52px;
}
.header-details { display: flex; align-items: center; gap: 10px; }
.header-avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.2); }
.header-title { flex: 1; }
.header-name { 
  font-weight: 600; 
  color: white; 
  font-size: 14px;
  margin-bottom: 2px;
}
.header-status { 
  font-size: 11px; 
  color: rgba(255,255,255,0.8); 
  font-weight: normal;
}
.control-btn { 
  background: none; 
  border: none; 
  color: white; 
  font-size: 18px; 
  cursor: pointer; 
  padding: 6px;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}
.control-btn:hover { background: rgba(255,255,255,0.1); }

/* --- Messages Area แบบ LINE --- */
.cha-chat-messages {
  flex-grow: 1;
  padding: 12px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #F7F7F7;
}
.cha-chat-message { 
  display: flex; 
  gap: 8px; 
  max-width: 80%; 
  align-items: flex-end;
}
.cha-chat-message.cha-user { 
  align-self: flex-end; 
  flex-direction: row-reverse; 
  gap: 4px;
}
.message-avatar { 
  width: 24px; 
  height: 24px; 
  border-radius: 50%; 
  flex-shrink: 0; 
}
.message-content { 
  padding: 8px 12px; 
  border-radius: 18px; 
  line-height: 1.4; 
  font-size: 13px;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.cha-bot .message-content { 
  background: white; 
  border-top-left-radius: 4px; 
  color: #333;
  border: 1px solid #E5E5EA;
}
.cha-user .message-content { 
  background: #00B900; 
  color: white; 
  border-top-right-radius: 4px; 
}
.message-time { 
  font-size: 10px; 
  color: #8E8E93; 
  margin-top: 2px; 
  padding: 0 4px; 
  align-self: flex-end;
}
.cha-user .message-time { 
  text-align: right; 
}

/* --- Thinking Indicator แบบ LINE --- */
.ai-thinking { 
  display: flex; 
  align-items: center; 
  gap: 8px; 
  padding: 8px 16px; 
  background: #F7F7F7;
}
.thinking-avatar img { 
  width: 24px; 
  height: 24px; 
  border-radius: 50%; 
}
.thinking-dots span { 
  width: 6px; 
  height: 6px; 
  border-radius: 50%; 
  background: #8E8E93; 
  display: inline-block; 
  margin: 0 1px; 
  animation: thinking 1.2s infinite ease-in-out both; 
}
.thinking-dots span:nth-child(1) { animation-delay: -0.24s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.12s; }
@keyframes thinking { 
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; } 
  40% { transform: scale(1.0); opacity: 1; } 
}

/* --- Footer แบบ LINE --- */
.cha-chat-footer { 
  flex-shrink: 0; 
  border-top: 1px solid #E5E5EA; 
  background: white; 
}
.ai-suggestions { 
  display: flex; 
  gap: 6px; 
  padding: 10px 16px; 
  overflow-x: auto; 
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.ai-suggestions::-webkit-scrollbar { display: none; }
.suggestion-btn { 
  background: #F0F0F0; 
  border: 1px solid #E5E5EA; 
  color: #333; 
  padding: 6px 10px; 
  border-radius: 16px; 
  font-size: 11px; 
  cursor: pointer; 
  transition: all 0.2s; 
  white-space: nowrap; 
  font-weight: 500;
}
.suggestion-btn:hover { 
  background: #00B900; 
  color: white; 
  border-color: #00B900; 
}
.input-area { 
  display: flex; 
  padding: 8px 16px 12px 16px; 
  gap: 8px; 
  align-items: flex-end;
}
.cha-chat-input { 
  flex: 1;
  resize: none; 
  border: 1px solid #E5E5EA; 
  background: white; 
  color: #333; 
  border-radius: 20px; 
  padding: 8px 12px; 
  font-size: 13px; 
  min-height: 36px;
  max-height: 80px;
  font-family: inherit;
  line-height: 1.4;
}
.cha-chat-input:focus { 
  outline: none; 
  border-color: #00B900; 
}
.cha-chat-send { 
  background: #00B900; 
  border: none; 
  border-radius: 50%; 
  width: 36px; 
  height: 36px; 
  color: white; 
  cursor: pointer; 
  flex-shrink: 0; 
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}
.cha-chat-send:hover { 
  background: #009900; 
}
.cha-chat-send svg { 
  width: 16px; 
  height: 16px; 
}
.footer-branding { 
  text-align: center; 
  font-size: 10px; 
  color: #8E8E93; 
  padding: 4px 0 8px 0; 
}
.footer-branding a { 
  color: #00B900; 
  text-decoration: none; 
}

/* --- Responsive Design สำหรับมือถือ --- */
@media (max-width: 768px) {
  .cha-chat-widget {
    bottom: 15px;
    right: 15px;
  }
  
  .cha-chat-toggle {
    width: 52px;
    height: 52px;
  }
  .cha-chat-toggle img { width: 26px; height: 26px; }
  
  .cha-chat-box {
    width: calc(100vw - 30px);
    height: calc(100vh - 120px);
    max-height: none;
    right: -15px;
    bottom: 65px;
    border-radius: 12px;
  }
  
  .cha-chat-header {
    padding: 10px 12px;
    min-height: 48px;
  }
  
  .header-avatar { width: 28px; height: 28px; }
  .header-name { font-size: 13px; }
  .header-status { font-size: 10px; }
  .control-btn { 
    width: 28px; 
    height: 28px; 
    font-size: 16px; 
  }
  
  .cha-chat-messages {
    padding: 8px 12px;
    gap: 6px;
  }
  
  .message-content {
    font-size: 12px;
    padding: 6px 10px;
  }
  
  .message-time {
    font-size: 9px;
  }
  
  .ai-suggestions {
    padding: 8px 12px;
    gap: 4px;
  }
  
  .suggestion-btn {
    font-size: 10px;
    padding: 4px 8px;
  }
  
  .input-area {
    padding: 6px 12px 10px 12px;
  }
  
  .cha-chat-input {
    font-size: 12px;
    padding: 6px 10px;
    min-height: 32px;
    max-height: 60px;
  }
  
  .cha-chat-send {
    width: 32px;
    height: 32px;
  }
  .cha-chat-send svg {
    width: 14px;
    height: 14px;
  }
  
  .footer-branding {
    font-size: 9px;
    padding: 2px 0 6px 0;
  }
}

@media (max-width: 480px) {
  .cha-chat-widget {
    bottom: 10px;
    right: 10px;
  }
  
  .cha-chat-box {
    width: calc(100vw - 20px);
    height: calc(100vh - 100px);
    right: -10px;
    bottom: 60px;
    border-radius: 8px;
  }
  
  .cha-chat-header {
    padding: 8px 10px;
    min-height: 44px;
  }
  
  .cha-chat-messages {
    padding: 6px 10px;
  }
  
  .input-area {
    padding: 4px 10px 8px 10px;
  }
}

/* --- Dark Theme Support --- */
.cha-chat-widget.cha-dark-theme .cha-chat-box {
  background: #1C1C1E;
}

.cha-chat-widget.cha-dark-theme .cha-chat-header {
  background: #2C2C2E;
}

.cha-chat-widget.cha-dark-theme .cha-chat-messages {
  background: #1C1C1E;
}

.cha-chat-widget.cha-dark-theme .cha-bot .message-content {
  background: #2C2C2E;
  color: #FFFFFF;
  border-color: #3A3A3C;
}

.cha-chat-widget.cha-dark-theme .cha-chat-input {
  background: #2C2C2E;
  color: #FFFFFF;
  border-color: #3A3A3C;
}

.cha-chat-widget.cha-dark-theme .cha-chat-footer {
  background: #1C1C1E;
  border-color: #3A3A3C;
}

/* --- Scrollbar Styling แบบ LINE --- */
.cha-chat-messages::-webkit-scrollbar {
  width: 4px;
}

.cha-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.cha-chat-messages::-webkit-scrollbar-thumb {
  background: #C7C7CC;
  border-radius: 2px;
}

.cha-chat-messages::-webkit-scrollbar-thumb:hover {
  background: #8E8E93;
}

/* --- Animation Improvements --- */
.cha-chat-message {
  animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* --- Focus States สำหรับ Accessibility --- */
.cha-chat-toggle:focus,
.control-btn:focus,
.suggestion-btn:focus,
.cha-chat-send:focus {
  outline: 2px solid #00B900;
  outline-offset: 2px;
}

.cha-chat-input:focus {
  box-shadow: 0 0 0 2px rgba(0, 185, 0, 0.2);
}
