/* AI 聊天机器人样式 */

/* 触发按钮 */
.chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
}

.chatbot-trigger {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark, #1a5a42));
  color: #fff;
  border: none;
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(45, 122, 95, 0.3);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chatbot-trigger:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 24px rgba(45, 122, 95, 0.4);
}

.chatbot-trigger:focus-visible,
.chatbot-close:focus-visible,
.chatbot-action-btn:focus-visible,
.chatbot-quick-btn:focus-visible,
.chatbot-send:focus-visible,
.chatbot-input:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 3px;
}

.chatbot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* 聊天窗口 */
.chatbot-window {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  height: min(560px, calc(100dvh - 112px));
  min-height: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.chatbot-window.active {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.chatbot-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-dark, #1a5a42));
  color: #fff;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatbot-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.chatbot-name {
  font-size: 14px;
  font-weight: 600;
}

.chatbot-status {
  font-size: 11px;
  opacity: 0.9;
}

.chatbot-close,
.chatbot-action-btn {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
  font-size: 14px;
}

.chatbot-close:hover,
.chatbot-action-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* 消息区域 */
.chatbot-messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

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

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.chatbot-welcome {
  text-align: center;
  padding: 24px 16px;
}

.chatbot-welcome-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-primary-alpha, rgba(45, 122, 95, 0.1));
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 12px;
}

.chatbot-welcome-text p {
  margin: 4px 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* 消息气泡 */
.chatbot-message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 14px;
  animation: messageIn 0.3s ease;
}

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

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

.chatbot-message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-muted);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.chatbot-message-user .chatbot-message-avatar {
  background: var(--color-primary);
  color: #fff;
}

.chatbot-message-bubble {
  max-width: 80%;
}

.chatbot-message-text {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.6;
  word-break: break-word;
}

.chatbot-message-bot .chatbot-message-text {
  background: var(--bg-muted);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.chatbot-message-user .chatbot-message-text {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chatbot-message-time {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 4px;
  padding: 0 4px;
}

.chatbot-message-user .chatbot-message-time {
  text-align: right;
}

/* Markdown 渲染 */
.chatbot-message-bot .chatbot-message-text p {
  margin: 0 0 8px;
}

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

.chatbot-message-bot .chatbot-message-text strong {
  font-weight: 600;
}

.chatbot-message-bot .chatbot-message-text code {
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--font-mono, monospace);
}

.chatbot-message-bot .chatbot-message-text pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  font-size: 12px;
  line-height: 1.5;
}

.chatbot-message-bot .chatbot-message-text pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.chatbot-message-bot .chatbot-message-text a {
  color: var(--color-primary);
  text-decoration: underline;
}

.chatbot-sources {
  margin: 8px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  background: var(--bg-surface);
}

.chatbot-sources-title {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
}

.chatbot-sources ul {
  display: grid;
  gap: 5px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.chatbot-sources a {
  display: block;
  min-height: 28px;
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.45;
  text-decoration: none;
}

.chatbot-sources a:hover,
.chatbot-sources a:focus-visible {
  color: var(--color-primary);
  text-decoration: underline;
}

.chatbot-sources a span {
  display: inline-block;
  margin-right: 6px;
  color: var(--text-tertiary);
  font-size: 10px;
}

.chatbot-message-bot .chatbot-message-text ul,
.chatbot-message-bot .chatbot-message-text ol {
  margin: 8px 0;
  padding-left: 20px;
}

.chatbot-message-bot .chatbot-message-text li {
  margin: 4px 0;
}

/* 打字动画 */
.chatbot-loading .chatbot-typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.chatbot-loading .chatbot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-tertiary);
  animation: typing 1.4s infinite;
}

.chatbot-loading .chatbot-typing span:nth-child(2) {
  animation-delay: 0.2s;
}

.chatbot-loading .chatbot-typing span:nth-child(3) {
  animation-delay: 0.4s;
}

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

/* 快捷问题 */
.chatbot-quick-questions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 10px;
}

.chatbot-quick-btn {
  padding: 5px 10px;
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.chatbot-quick-btn:hover {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}

/* 输入区域 */
.chatbot-input-area {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
  align-items: flex-end;
}

.chatbot-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  font-size: 13px;
  background: var(--bg-base);
  color: var(--text-primary);
  resize: none;
  max-height: 100px;
  font-family: inherit;
  line-height: 1.4;
}

.chatbot-input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.chatbot-input::placeholder {
  color: var(--text-tertiary);
}

.chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  border: none;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chatbot-send:hover {
  background: var(--color-primary-dark, #1a5a42);
  transform: scale(1.05);
}

/* 响应式 */
@media (max-width: 768px) {
  .chatbot-widget {
    bottom: 80px;
    right: 16px;
  }
  
  .chatbot-window {
    width: calc(100vw - 32px);
    right: -8px;
    height: min(70dvh, calc(100dvh - 112px));
    max-height: none;
  }

  .chatbot-input-area {
    padding-left: 12px;
    padding-right: 12px;
  }
  
  .chatbot-trigger {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
  
  .chatbot-messages {
    max-height: none;
  }

  .chatbot-sources a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot-trigger,
  .chatbot-window,
  .chatbot-message,
  .chatbot-loading .chatbot-typing span {
    animation: none;
    transition: none;
  }
}
