/* AI 客服浮动气泡 */
.agent-chat-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary, #409eff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.agent-chat-bubble:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}
.agent-chat-bubble:active {
  transform: scale(0.97);
}
.agent-chat-bubble img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}
.agent-chat-bubble svg {
  width: 28px;
  height: 28px;
}
.agent-chat-bubble.disabled {
  background: #c0c4cc;
  cursor: not-allowed;
}
.agent-chat-bubble.disabled:hover {
  transform: none;
}

/* 聊天窗口 */
.agent-chat-window {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: agent-chat-slide-in 0.2s ease-out;
}
@keyframes agent-chat-slide-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* 窗口头部 */
.agent-chat-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--color-primary, #409eff);
  color: #fff;
  flex-shrink: 0;
}
.agent-chat-header-name {
  flex: 1;
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-chat-header-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  padding: 4px 8px;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
}
.agent-chat-header-btn:hover {
  color: #fff;
}
.agent-chat-contact-btn {
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  padding: 2px 10px;
  margin-right: 4px;
}
.agent-chat-contact-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* 消息区域 */
.agent-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.agent-chat-msg {
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  animation: agent-chat-fade-in 0.15s ease;
}
@keyframes agent-chat-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.agent-chat-msg.user {
  align-items: flex-end;
}
.agent-chat-msg.assistant {
  align-items: flex-start;
}
.agent-chat-bubble-text {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}
.agent-chat-msg.user .agent-chat-bubble-text {
  background: var(--color-primary, #409eff);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.agent-chat-msg.assistant .agent-chat-bubble-text {
  background: #f4f4f5;
  color: #303133;
  border-bottom-left-radius: 4px;
}
/* Markdown 渲染样式 */
.agent-chat-bubble-text p { margin: 0 0 8px; }
.agent-chat-bubble-text p:last-child { margin-bottom: 0; }
.agent-chat-bubble-text code {
  background: rgba(0,0,0,0.06);
  padding: 1px 4px;
  border-radius: 3px;
  font-size: 0.9em;
}
.agent-chat-bubble-text pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}
.agent-chat-bubble-text pre code {
  background: none;
  padding: 0;
  color: inherit;
}
.agent-chat-bubble-text ul, .agent-chat-bubble-text ol {
  margin: 4px 0;
  padding-left: 20px;
}
.agent-chat-bubble-text li { margin: 2px 0; }
.agent-chat-bubble-text strong { font-weight: 600; }
.agent-chat-bubble-text a { color: #409eff; text-decoration: none; }
.agent-chat-bubble-text a:hover { text-decoration: underline; }
.agent-chat-msg-time {
  font-size: 11px;
  color: #909399;
  margin-top: 4px;
  padding: 0 4px;
}
.agent-chat-msg-actions {
  align-self: flex-start;
  margin-top: 2px;
  padding: 0 4px;
}
.agent-chat-copy-btn {
  background: none;
  border: none;
  color: #c0c4cc;
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s, color 0.2s;
}
.agent-chat-msg:hover .agent-chat-copy-btn { opacity: 1; }
.agent-chat-copy-btn:hover { color: #409eff; }
.agent-chat-copy-btn.copied { color: #67c23a; opacity: 1; }

/* 工具状态 */
.agent-chat-tool-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 13px;
  color: #909399;
}
.agent-chat-tool-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid #e0e0e0;
  border-top-color: var(--color-primary, #409eff);
  border-radius: 50%;
  animation: agent-chat-spin 0.6s linear infinite;
}
@keyframes agent-chat-spin {
  to { transform: rotate(360deg); }
}

/* 来源引用 */
.agent-chat-sources {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.agent-chat-source-link {
  font-size: 12px;
  color: var(--color-primary, #409eff);
  text-decoration: none;
  padding: 2px 8px;
  background: rgba(64, 158, 255, 0.08);
  border-radius: 4px;
}
.agent-chat-source-link:hover {
  background: rgba(64, 158, 255, 0.15);
}

/* 输入区域 */
.agent-chat-input-area {
  display: flex;
  align-items: flex-end;
  padding: 12px 16px;
  border-top: 1px solid #ebeef5;
  flex-shrink: 0;
  background: #fff;
}
.agent-chat-input {
  flex: 1;
  border: 1px solid #dcdfe6;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  resize: none;
  max-height: 100px;
  line-height: 1.5;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.agent-chat-input:focus {
  border-color: var(--color-primary, #409eff);
}
.agent-chat-send-btn {
  margin-left: 8px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary, #409eff);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.agent-chat-send-btn:disabled {
  background: #c0c4cc;
  cursor: not-allowed;
}
.agent-chat-send-btn svg {
  width: 18px;
  height: 18px;
}

/* 欢迎消息 */
.agent-chat-welcome {
  text-align: center;
  padding: 24px 16px;
  color: #606266;
  font-size: 14px;
  line-height: 1.6;
}

/* 错误提示 */
.agent-chat-error {
  padding: 8px 12px;
  margin: 4px 0;
  background: #fef0f0;
  color: #f56c6c;
  border-radius: 8px;
  font-size: 13px;
}
.agent-chat-contact-info {
  margin: 8px 0;
  padding: 12px 16px;
  background: #f0f9eb;
  color: #67c23a;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

/* 登录提示 */
.agent-chat-login-prompt {
  text-align: center;
  padding: 32px 16px;
}
.agent-chat-login-prompt p {
  color: #606266;
  font-size: 14px;
  margin-bottom: 16px;
}
.agent-chat-login-btn {
  display: inline-block;
  padding: 8px 24px;
  background: var(--color-primary, #409eff);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ====== 会员中心对话历史 Tab ====== */
.chat-history-list {
  padding: 0;
}
.chat-history-loading {
  text-align: center;
  padding: 40px;
  color: #909399;
  font-size: 14px;
}
.chat-history-empty {
  text-align: center;
  padding: 48px 16px;
  color: #909399;
}
.chat-history-empty svg {
  width: 48px;
  height: 48px;
  color: #dcdfe6;
  margin-bottom: 12px;
}
.chat-history-card {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.chat-history-card:hover {
  background: #f5f7fa;
}
.chat-history-card:active {
  background: #ecf0f5;
}
.chat-history-card-info {
  flex: 1;
  min-width: 0;
}
.chat-history-card-title {
  font-size: 14px;
  color: #303133;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-history-card-meta {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
  display: flex;
  gap: 8px;
}
.chat-history-card-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 500;
}
.chat-history-card-badge.active {
  background: rgba(64, 158, 255, 0.1);
  color: var(--color-primary, #409eff);
}
.chat-history-card-badge.archived {
  background: #f4f4f5;
  color: #909399;
}
.chat-history-arrow {
  color: #c0c4cc;
  font-size: 14px;
}

/* 对话详情 */
.chat-history-detail {
  padding: 0;
}
.chat-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  color: var(--color-primary, #409eff);
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
.chat-detail-header {
  padding: 8px 0 12px;
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 12px;
}
.chat-detail-title {
  font-size: 15px;
  font-weight: 500;
  color: #303133;
}
.chat-detail-stats {
  font-size: 12px;
  color: #909399;
  margin-top: 4px;
}

/* 分页 */
.chat-history-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 16px;
}
.chat-history-page-btn {
  padding: 6px 14px;
  border: 1px solid #dcdfe6;
  border-radius: 6px;
  background: #fff;
  color: #606266;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chat-history-page-btn:disabled {
  color: #c0c4cc;
  cursor: not-allowed;
}
.chat-history-page-info {
  font-size: 13px;
  color: #909399;
}

/* ====== 移动端适配 ====== */
@media (max-width: 480px) {
  .agent-chat-window {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
  .agent-chat-bubble {
    bottom: 16px;
    right: 16px;
    width: 48px;
    height: 48px;
  }
  .agent-chat-bubble svg {
    width: 24px;
    height: 24px;
  }
  .agent-chat-bubble img {
    width: 28px;
    height: 28px;
  }
  .agent-chat-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}
