@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600&display=swap');

:root {
  --ai-chat-primary: #4f77ff;
  --ai-chat-primary-hover: #3d5fcc;
  --ai-chat-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --ai-chat-shadow: 0 20px 40px rgba(79, 119, 255, 0.15);
  --ai-chat-glow: 0 0 20px rgba(79, 119, 255, 0.3);
}

#ai-chat-widget {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  gap: 15px;
  align-items: flex-end;
}

#ai-chat-toggle,
#wechat-toggle,
#back-to-top {
  background: var(--ai-chat-gradient);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--ai-chat-shadow);
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  padding: 14px 20px;
  min-width: 130px;
  position: relative;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#ai-chat-toggle:hover,
#wechat-toggle:hover,
#back-to-top:hover {
  transform: translateX(-8px) translateY(-2px);
  box-shadow: var(--ai-chat-glow), var(--ai-chat-shadow);
}

#ai-chat-toggle .button-text,
#wechat-toggle .button-text,
#back-to-top .button-text {
  color: white;
  font-size: 14px;
  font-weight: 600;
  margin-left: 10px;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

#wechat-toggle {
  background: linear-gradient(135deg, #07c160 0%, #00a854 100%);
}

#wechat-toggle:hover {
  box-shadow: 0 0 20px rgba(7, 193, 96, 0.4), var(--ai-chat-shadow);
}

#back-to-top {
  background: linear-gradient(135deg, #4f77ff 0%, #4b4ca2 100%);
}

#ai-chat-window {
  position: absolute;
  bottom: 0px;
  right: 0px;
  width: 380px;
  height: 520px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
}

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

#ai-chat-header {
  background: var(--ai-chat-gradient);
  color: white;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

#ai-chat-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
  pointer-events: none;
}

#ai-chat-header h4 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.header-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
}

#ai-chat-clear,
#ai-chat-close {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

#ai-chat-close {
  font-size: 20px;
}

#ai-chat-clear:hover,
#ai-chat-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

#ai-chat-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  position: relative;
}

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

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

#ai-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(79, 119, 255, 0.3);
  border-radius: 3px;
}

.ai-message,
.user-message {
  margin-bottom: 20px;
  display: flex;
  animation: messageSlide 0.3s ease-out;
}

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

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

.user-message {
  justify-content: flex-end;
}

.message-content {
  max-width: 85%;
  padding: 16px 20px;
  border-radius: 20px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.ai-message .message-content {
  background: white;
  color: #2d3748;
  border-bottom-left-radius: 8px;
  border: 1px solid rgba(79, 119, 255, 0.1);
}

/* Markdown样式 */
.ai-message .message-content h1,
.ai-message .message-content h2,
.ai-message .message-content h3,
.ai-message .message-content h4,
.ai-message .message-content h5,
.ai-message .message-content h6 {
  margin: 12px 0 8px 0;
  font-weight: 600;
  color: #1a202c;
}

.ai-message .message-content p {
  margin: 8px 0;
  line-height: 1.6;
}

.ai-message .message-content ul,
.ai-message .message-content ol {
  margin: 8px 0;
  padding-left: 20px;
}

.ai-message .message-content li {
  margin: 4px 0;
}

.ai-message .message-content code {
  background: #f7fafc;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  color: #e53e3e;
}

.ai-message .message-content pre {
  background: #f7fafc;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  border-left: 4px solid var(--ai-chat-primary);
}

.ai-message .message-content pre code {
  background: none;
  padding: 0;
  color: #2d3748;
}

.ai-message .message-content blockquote {
  border-left: 4px solid var(--ai-chat-primary);
  padding-left: 16px;
  margin: 8px 0;
  color: #4a5568;
  font-style: italic;
}

.ai-message .message-content strong {
  font-weight: 600;
  color: #1a202c;
}

.ai-message .message-content em {
  font-style: italic;
}

.ai-message .message-content a {
  color: var(--ai-chat-primary);
  text-decoration: none;
}

.ai-message .message-content a:hover {
  text-decoration: underline;
}

.user-message .message-content {
  background: var(--ai-chat-gradient);
  color: white;
  border-bottom-right-radius: 8px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

#ai-chat-input-area {
  padding: 20px 24px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(79, 119, 255, 0.1);
  display: flex;
  gap: 12px;
  align-items: center;
}

#ai-chat-input {
  flex: 1;
  padding: 14px 18px;
  margin: 0;
  border: 2px solid rgba(79, 119, 255, 0.2);
  border-radius: 16px;
  outline: none;
  font-size: 14px;
  color: #2d3748;
  resize: none;
  min-height: 20px;
  max-height: 60px;
  line-height: 20px;
  font-family: inherit;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.8);
  transition: all 0.3s ease;
}

#ai-chat-input:focus {
  border-color: var(--ai-chat-primary);
  background: white;
  box-shadow: 0 0 0 3px rgba(79, 119, 255, 0.1);
}

#ai-chat-send {
  padding: 10px 20px !important;
  background: var(--ai-chat-gradient);
  color: white;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s ease;
  height: 48px !important;
  line-height: 1 !important;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79, 119, 255, 0.3);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

#ai-chat-send:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(79, 119, 255, 0.4);
}

#ai-chat-send:disabled {
  background: #e2e8f0;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 16px 20px;
  background: white;
  border-radius: 20px;
  border-bottom-left-radius: 8px;
  max-width: 80%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(79, 119, 255, 0.1);
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--ai-chat-primary);
  border-radius: 50%;
  animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

/* 微信二维码弹窗样式 */
#wechat-qr-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.qr-content {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(20px);
  border-radius: 20px;
  width: auto;
  max-width: 350px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.3);
  animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.qr-header {
  background: linear-gradient(135deg, #07c160 0%, #00a854 100%);
  color: white;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
}

.qr-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255, 255, 255, 0.1) 0%, transparent 100%);
  pointer-events: none;
}

.qr-header h4 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

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

#wechat-close:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.qr-body {
  padding: 30px;
  text-align: center;
}

.qr-body img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin-bottom: 20px;
  display: block;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.qr-body p {
  margin: 0;
  color: #64748b;
  font-size: 14px;
  font-weight: 500;
}

/* 建议问题样式 */
.suggested-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  animation: messageSlide 0.3s ease-out;
}

.suggestion-btn {
  color: white;
  padding: 8px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  height: 32px !important;
  line-height: 1 !important;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.suggestion-btn:hover {
  color: white;
  transform: translateY(-1px);
}

@media (max-width: 480px) {
  #ai-chat-window {
    width: 340px;
    height: 480px;
  }

  #ai-chat-widget {
    right: 15px;
    bottom: 15px;
  }

  .qr-content {
    width: 300px;
    margin: 20px;
  }

  .suggestion-btn {
    font-size: 12px;
    padding: 6px 12px;
  }
}
