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

:root {
  --chat-bg-primary: #ffffff;
  --chat-bg-secondary: #f8fafc;
  --chat-bg-message-ai: #f1f5f9;
  --chat-bg-message-user: #3b82f6;
  --chat-text-primary: #0f172a;
  --chat-text-secondary: #64748b;
  --chat-accent: #3b82f6;
  --chat-accent-hover: #2563eb;
  --chat-border: #e2e8f0;
  --chat-shadow: rgba(0, 0, 0, 0.08);
  --chat-shadow-lg: rgba(0, 0, 0, 0.12);
  --chat-font: 'Inter', 'Noto Sans JP', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

/* 气泡按钮 */
.gaiei-chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 30px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.3), 0 2px 8px rgba(0, 0, 0, 0.1);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 9998;
}

.gaiei-chat-bubble:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 12px 32px rgba(59, 130, 246, 0.4), 0 4px 12px rgba(0, 0, 0, 0.15);
}

.gaiei-chat-bubble:active {
  transform: translateY(0) scale(1);
}

.gaiei-chat-bubble svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.gaiei-chat-bubble.open .icon-chat {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}

.gaiei-chat-bubble.open .icon-close {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.gaiei-chat-bubble .icon-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}

/* 主容器 */
.gaiei-chat-container {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: min(360px, 90vw);
  height: min(560px, 80vh);
  max-height: 600px;
  background: var(--chat-bg-primary);
  border-radius: 20px;
  box-shadow: 0 20px 60px var(--chat-shadow-lg), 0 0 1px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), visibility 0.3s ease;
  font-family: var(--chat-font);
  border: 1px solid var(--chat-border);
}

.gaiei-chat-container.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* 头部 */
.gaiei-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 18px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border-bottom: none;
}

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

.gaiei-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.gaiei-chat-avatar svg {
  width: 22px;
  height: 22px;
  fill: white;
}

.gaiei-chat-title {
  font-size: 16px;
  font-weight: 700;
  color: white;
  letter-spacing: -0.01em;
}

.gaiei-chat-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.gaiei-chat-status::before {
  content: '';
  width: 6px;
  height: 6px;
  background: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  animation: pulse 2s ease-in-out infinite;
}

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

/* 语言切换 */
.gaiei-chat-lang-selector {
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  padding: 4px;
  border-radius: 10px;
}

.gaiei-chat-lang-btn {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--chat-font);
  letter-spacing: 0.02em;
}

.gaiei-chat-lang-btn:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.gaiei-chat-lang-btn.active {
  background: white;
  color: var(--chat-accent);
}

/* 消息区域 */
.gaiei-chat-messages {
  flex: 1 1 auto;
  min-height: 280px;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-gutter: stable;
  scroll-behavior: smooth;
  background: var(--chat-bg-secondary);
}

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

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

.gaiei-chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

.gaiei-chat-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chat-text-secondary);
}

/* 消息气泡 */
.gaiei-chat-message {
  max-width: 85%;
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.6;
  animation: messageIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  word-wrap: break-word;
  font-weight: 400;
}

@keyframes messageIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.gaiei-chat-message.ai {
  align-self: flex-start;
  background: var(--chat-bg-message-ai);
  color: var(--chat-text-primary);
  border-radius: 6px 18px 18px 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.gaiei-chat-message.user {
  align-self: flex-end;
  background: var(--chat-bg-message-user);
  color: white;
  border-radius: 18px 6px 18px 18px;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

/* 输入中动画 */
.gaiei-chat-message.typing {
  display: flex;
  gap: 5px;
  padding: 16px 20px;
  background: var(--chat-bg-message-ai);
}

.gaiei-chat-message.typing span {
  width: 8px;
  height: 8px;
  background: var(--chat-text-secondary);
  border-radius: 50%;
  animation: typingDot 1.4s infinite ease-in-out;
}

.gaiei-chat-message.typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.gaiei-chat-message.typing span:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* FAQ 快速问题区域 */
.gaiei-chat-faq {
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
  max-height: 150px;
  overflow-y: auto;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-bg-primary);
  scrollbar-gutter: stable;
}

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

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

.gaiei-chat-faq::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

.gaiei-chat-faq-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--chat-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
  position: sticky;
  top: 0;
  background: var(--chat-bg-primary);
  padding: 4px 0;
  z-index: 1;
}

.gaiei-chat-faq-btn {
  padding: 10px 14px;
  background: var(--chat-bg-secondary);
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  color: var(--chat-text-primary);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  font-family: var(--chat-font);
  line-height: 1.4;
  flex-shrink: 0;
  font-weight: 500;
}

.gaiei-chat-faq-btn:hover {
  background: white;
  border-color: var(--chat-accent);
  color: var(--chat-accent);
  transform: translateX(2px);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.gaiei-chat-faq-btn:active {
  transform: scale(0.98);
}

/* 输入区域 */
.gaiei-chat-input-area {
  padding: 16px 20px 20px;
  background: var(--chat-bg-primary);
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.gaiei-chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--chat-bg-secondary);
  border: 2px solid var(--chat-border);
  border-radius: 12px;
  color: var(--chat-text-primary);
  font-size: 14px;
  outline: none;
  resize: none;
  max-height: 100px;
  font-family: var(--chat-font);
  transition: all 0.2s ease;
  font-weight: 400;
}

.gaiei-chat-input::placeholder {
  color: var(--chat-text-secondary);
}

.gaiei-chat-input:focus {
  border-color: var(--chat-accent);
  background: white;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.gaiei-chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--chat-accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.gaiei-chat-send-btn:hover {
  background: var(--chat-accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.gaiei-chat-send-btn:active {
  transform: translateY(0) scale(0.95);
}

.gaiei-chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.gaiei-chat-send-btn svg {
  width: 20px;
  height: 20px;
  fill: white;
}

/* 响应式设计 */
@media (max-width: 1024px) and (min-width: 769px) {
  .gaiei-chat-container {
    width: min(360px, 88vw);
    height: min(540px, 78vh);
  }
}

@media (max-width: 768px) and (min-width: 481px) {
  .gaiei-chat-container {
    width: min(340px, 90vw);
    height: min(520px, 76vh);
    right: 20px;
    bottom: 84px;
  }

  .gaiei-chat-bubble {
    bottom: 20px;
    right: 20px;
  }
}

@media (max-width: 480px) {
  .gaiei-chat-container {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  .gaiei-chat-bubble {
    bottom: 20px;
    right: 20px;
  }

  .gaiei-chat-container.open ~ .gaiei-chat-bubble {
    opacity: 0;
    pointer-events: none;
  }

  .gaiei-chat-messages {
    min-height: 220px;
    padding: 20px 16px;
  }

  .gaiei-chat-faq {
    max-height: 130px;
    padding: 14px 16px 16px;
  }

  .gaiei-chat-header {
    padding: 18px 16px 16px;
    border-radius: 0;
  }

  .gaiei-chat-input-area {
    padding: 14px 16px 20px;
  }
}

/* 深色模式支持（可选） */
@media (prefers-color-scheme: dark) {
  :root {
    --chat-bg-primary: #1e293b;
    --chat-bg-secondary: #0f172a;
    --chat-bg-message-ai: #334155;
    --chat-text-primary: #f1f5f9;
    --chat-text-secondary: #94a3b8;
    --chat-border: #334155;
    --chat-shadow: rgba(0, 0, 0, 0.3);
    --chat-shadow-lg: rgba(0, 0, 0, 0.5);
  }

  .gaiei-chat-message.ai {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .gaiei-chat-input:focus {
    background: var(--chat-bg-secondary);
  }
}
