/**
 * 看宝AI知识库 - 聊天组件样式 V2.0
 * 现代化设计，人性化交互
 */

/* ==================== 聊天按钮 ==================== */

.chat-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  color: #fff;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
  transition: all 0.3s ease;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
  }
  50% {
    box-shadow: 0 4px 30px rgba(102, 126, 234, 0.8);
  }
  100% {
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.5);
  }
}

.chat-toggle-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 30px rgba(102, 126, 234, 0.7);
  animation: none;
}

/* ==================== 聊天面板 ==================== */

.chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 400px;
  height: 580px;
  max-height: calc(100vh - 48px);
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  z-index: 10001;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

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

/* ==================== 聊天头部 ==================== */

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

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  font-size: 28px;
}

.chat-header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-title {
  font-weight: 600;
  font-size: 16px;
}

.chat-status {
  font-size: 12px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-status::before {
  content: '';
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  animation: blink 2s infinite;
}

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

.chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

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

/* ==================== 消息区域 ==================== */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8fafc;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* ==================== 消息气泡 ==================== */

.chat-message {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: messageEnter 0.3s ease;
  clear: both;
}

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

.chat-message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message.ai {
  align-self: flex-start;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  overflow: hidden;
}

.message-avatar img {
  width: 36px;
  height: 36px;
  object-fit: cover;
}

.ai-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.user-avatar {
  background: #e2e8f0;
}

.message-content {
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.6;
  max-width: 100%;
  box-sizing: border-box;
  overflow-wrap: break-word;
}

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

.chat-message.ai .message-content {
  background: #fff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.message-text {
  font-size: 14px;
  word-break: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.message-text p {
  margin: 0 0 8px 0;
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text a {
  color: #667eea;
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
  word-break: break-all;
}

.message-text a:hover {
  border-bottom-color: #667eea;
}

.chat-message.user .message-text a {
  color: #fff;
  border-bottom-color: rgba(255, 255, 255, 0.5);
}

.chat-message.user .message-text a:hover {
  border-bottom-color: #fff;
}

/* ==================== 来源卡片 ==================== */

.message-sources {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #e2e8f0;
}

.sources-title {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 8px;
  font-weight: 500;
}

.source-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 8px;
  text-decoration: none;
  color: #334155;
  font-size: 13px;
  margin-bottom: 6px;
  transition: all 0.2s;
}

.source-card:last-child {
  margin-bottom: 0;
}

.source-card:hover {
  background: #e2e8f0;
  transform: translateX(4px);
}

.source-icon {
  font-size: 14px;
}

.source-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-arrow {
  color: #94a3b8;
  transition: transform 0.2s;
}

.source-card:hover .source-arrow {
  transform: translateX(4px);
  color: #667eea;
}

/* ==================== 快捷问题 ==================== */

.chat-quick-questions {
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

.quick-questions-title {
  font-size: 12px;
  color: #64748b;
  margin-bottom: 10px;
  font-weight: 500;
}

.quick-questions-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-question {
  padding: 8px 14px;
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  border-radius: 20px;
  font-size: 13px;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.quick-question:hover {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-style: solid;
  border-color: transparent;
  transform: translateY(-2px);
}

/* ==================== 输入区域 ==================== */

.chat-input-area {
  display: flex;
  gap: 10px;
  padding: 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  padding: 12px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

#chat-input:focus {
  border-color: #667eea;
}

#chat-input::placeholder {
  color: #94a3b8;
}

#chat-input:disabled {
  background: #f8fafc;
  cursor: not-allowed;
}

.chat-send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-send-btn:hover:not(.loading) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

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

.chat-send-btn.loading {
  cursor: not-allowed;
  opacity: 0.8;
}

/* 加载动画 */
.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== 响应式设计 ==================== */

@media (max-width: 480px) {
  .chat-panel {
    width: calc(100% - 16px);
    height: calc(100vh - 80px);
    bottom: 8px;
    right: 8px;
    border-radius: 16px;
    max-height: calc(100vh - 60px);
  }
  
  .chat-toggle-btn {
    width: 52px;
    height: 52px;
    bottom: 16px;
    right: 16px;
  }
  
  .chat-header {
    padding: 12px 16px;
  }
  
  .chat-title {
    font-size: 14px;
  }
  
  .chat-messages {
    padding: 12px;
    gap: 10px;
  }
  
  .chat-message {
    max-width: 92%;
    gap: 8px;
  }
  
  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  
  .message-avatar img {
    width: 28px !important;
    height: 28px !important;
  }
  
  .message-content {
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.5;
  }
  
  .message-text {
    font-size: 13px;
    word-break: break-word;
    overflow-wrap: break-word;
  }
  
  .message-text a {
    word-break: break-all;
    max-width: 100%;
    display: inline-block;
  }
  
  .message-sources {
    margin-top: 10px;
    padding-top: 10px;
  }
  
  .source-card {
    padding: 8px 10px;
    font-size: 12px;
  }
  
  .source-title {
    max-width: 180px;
  }
  
  .quick-questions-list {
    flex-direction: column;
    gap: 6px;
  }
  
  .quick-question {
    width: 100%;
    text-align: center;
    padding: 10px 12px;
    font-size: 12px;
  }
  
  .chat-input-area {
    padding: 12px;
    gap: 8px;
  }
  
  #chat-input {
    padding: 10px 14px;
    font-size: 13px;
  }
  
  .chat-send-btn {
    width: 42px;
    height: 42px;
  }
}

/* 文本自适应 */
.message-text {
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

.message-text a {
  word-break: break-all;
  max-width: 100%;
}

/* 来源卡片文本溢出处理 */
.source-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}

/* ==================== 深色模式支持 ==================== */

@media (prefers-color-scheme: dark) {
  .chat-panel {
    background: #1e293b;
  }
  
  .chat-messages {
    background: #0f172a;
  }
  
  .chat-message.ai .message-content {
    background: #334155;
    color: #f1f5f9;
  }
  
  .message-sources {
    border-top-color: #475569;
  }
  
  .sources-title {
    color: #94a3b8;
  }
  
  .source-card {
    background: #334155;
    color: #e2e8f0;
  }
  
  .source-card:hover {
    background: #475569;
  }
  
  .chat-quick-questions {
    background: #1e293b;
    border-top-color: #475569;
  }
  
  .quick-question {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
  }
  
  .chat-input-area {
    background: #1e293b;
    border-top-color: #475569;
  }
  
  #chat-input {
    background: #334155;
    border-color: #475569;
    color: #f1f5f9;
  }
  
  #chat-input::placeholder {
    color: #94a3b8;
  }
  
  .user-avatar {
    background: #475569;
  }
  
  .chat-messages::-webkit-scrollbar-thumb {
    background: #475569;
  }
}
