/* 聊天框样式 */
.chat-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-size: 14px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
}

/* 聊天按钮 */
.chat-button {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
  transition: all 0.3s ease;
  position: relative;
}

.chat-button:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
}

.chat-icon {
  font-size: 24px;
  color: white;
}

.chat-text {
  display: none;
  color: white;
  font-size: 14px;
  font-weight: 500;
}

.chat-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  background: #ff4757;
  color: white;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  min-width: 20px;
  padding: 0 4px;
  opacity: 0;
  transform: scale(0);
  transition: all 0.3s ease;
  z-index: 10;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(255, 71, 87, 0.3);
}

.chat-badge.show {
  opacity: 1;
  transform: scale(1);
}

/* 聊天窗口 */
.chat-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 350px;
  height: 500px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatWindowSlideIn 0.3s ease;
}

.chat-window.show {
  display: flex;
}

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

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

.chat-header-info h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.chat-status {
  font-size: 12px;
  opacity: 0.9;
}

.chat-header-actions {
  display: flex;
  gap: 10px;
}

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

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

/* 消息区域 */
.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  background: #f8f9fa;
}

.chat-message {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
  animation: messageSlideIn 0.3s ease;
}

.user-message {
  justify-content: flex-end;
  .message-avatar {
    order: 2;
  }
  .message-content {
    order: 1;
  }
}

.bot-message {
  justify-content: flex-start;
}

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  margin-right: 10px;
  flex-shrink: 0;
}

.user-message .message-avatar {
  background: #667eea;
  color: white;
  margin-left: 10px;
  margin-right: 0;
}

.bot-message .message-avatar {
  background: #e9ecef;
  color: #495057;
  margin-right: 10px;
  margin-left: 0;
}

.message-content {
  max-width: 70%;
  background: white;
  padding: 10px 15px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.user-message .message-content {
  background: #667eea;
  color: white;
}

.message-content p {
  margin: 0 0 5px 0;
  line-height: 1.4;
  word-wrap: break-word;
}

.message-time {
  font-size: 11px;
  opacity: 0.7;
  display: block;
  margin-top: 5px;
}

/* 打字状态指示器 */
.chat-typing {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: #6c757d;
  background: #f8f9fa;
}

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

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6c757d;
  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;
  }
}

/* 输入区域 */
.chat-input-area {
  padding: 15px 20px;
  background: white;
  border-top: 1px solid #e9ecef;
}

.chat-input-container {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

#chatInput {
  flex: 1;
  border: 1px solid #e9ecef;
  border-radius: 20px;
  padding: 8px 15px;
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 36px;
  line-height: 1.4;
  font-family: inherit;
}

#chatInput:focus {
  border-color: #667eea;
}

.chat-send-btn {
  background: #667eea;
  border: none;
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: #5a6fd8;
}

.chat-send-btn:disabled {
  background: #e9ecef;
  cursor: not-allowed;
}

.chat-input-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 5px;
}

.char-count {
  font-size: 11px;
  color: #6c757d;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .chat-container {
    bottom: 10px;
    right: 10px;
    left: 10px;
  }

  .chat-button {
    width: 50px;
    height: 50px;
  }

  .chat-icon {
    font-size: 20px;
  }

  .chat-window {
    width: 100%;
    height: calc(100vh - 144px);
    bottom: 70px;
    right: 0;
    left: 0;
    border-radius: 12px 12px 0 0;
  }

  .message-content {
    max-width: 80%;
  }
}

@media (max-width: 480px) {
  .chat-window {
    height: calc(100vh - 144px);
    bottom: 60px;
  }

  .chat-header {
    padding: 12px 15px;
  }

  .chat-messages {
    padding: 15px;
  }

  .chat-input-area {
    padding: 10px 15px;
  }
}

/* 平板适配 */
@media (min-width: 769px) and (max-width: 1024px) {
  .chat-window {
    width: 300px;
    height: 450px;
  }
}

/* 滚动条样式 */
.chat-messages::-webkit-scrollbar {
  width: 4px;
}

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

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

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

/* 暗色主题支持 */
@media (prefers-color-scheme: dark) {
  .chat-window {
    background: #2d3748;
    color: #e2e8f0;
  }

  .chat-messages {
    background: #1a202c;
  }

  .message-content {
    background: #2d3748;
    color: #e2e8f0;
  }

  .user-message .message-content {
    background: #667eea;
    color: white;
  }

  .chat-input-area {
    background: #2d3748;
    border-top-color: #4a5568;
  }

  #chatInput {
    background: #1a202c;
    border-color: #4a5568;
    color: #e2e8f0;
  }

  #chatInput:focus {
    border-color: #667eea;
  }
}
