/* ========== 全局变量（GitHub Dark 配色）========== */
:root {
  --bg-base: #0d1117;
  --bg-card: #161b22;
  --bg-elevated: #1c2128;
  --border: #30363d;
  --border-soft: #21262d;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, 0.15);
  --text-primary: #f0f6fc;
  --text-secondary: #c9d1d9;
  --text-muted: #8b949e;
  --success: #3fb950;
  --warning: #d29922;
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.12);
  --shadow: 0 8px 24px rgba(1, 4, 9, 0.6);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }

/* ========== 用户端聊天页（480px 固定布局，移动端自适应）========== */
.chat-app {
  width: 480px;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 60px rgba(1, 4, 9, 0.5);
  overflow: hidden;
}

/* 顶部导航 */
.chat-header {
  flex-shrink: 0;
  z-index: 10;
  background: linear-gradient(180deg, #161b22 0%, #0d1117 100%);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.agent-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #58a6ff 0%, #1f6feb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 3px var(--accent-soft);
  overflow: hidden;
}
.agent-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.agent-info { flex: 1; min-width: 0; }
.agent-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.agent-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); position: relative; }
.status-dot::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  background: var(--success); opacity: 0.3; animation: ping 2s infinite;
}
@keyframes ping {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(2); opacity: 0; }
}

/* 消息区 */
.chat-messages {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.message-row { display: flex; gap: 10px; animation: msgIn 0.3s var(--ease); }
.message-row.user { flex-direction: row-reverse; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
  overflow: hidden;
}
.message-avatar img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.message-row.agent .message-avatar {
  background: linear-gradient(135deg, #58a6ff 0%, #1f6feb 100%); color: #fff;
}
.message-row.user .message-avatar {
  background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border);
}

.message-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.message-row.agent .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  color: var(--text-primary);
}
.message-row.user .message-bubble {
  background: linear-gradient(135deg, #1f6feb 0%, #1158c7 100%);
  color: #fff;
  border-top-right-radius: 4px;
}

/* 消息内链接按钮 */
.message-links, .msg-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.btn {
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  transition: all 0.25s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  border: none;
  white-space: nowrap;
}
/* action 按钮：实心渐变 + 悬停上浮 */
.btn-action {
  background: linear-gradient(135deg, #2f7cf6 0%, #58a6ff 100%);
  color: #fff;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(47, 124, 246, 0.35);
}
.btn-action::after {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 60%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shine 2.8s ease-in-out infinite;
}
@keyframes shine {
  0% { left: -100%; }
  50% { left: 120%; }
  100% { left: 120%; }
}
.btn-action:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 16px rgba(47, 124, 246, 0.5);
}
.btn-action:active { transform: translateY(0); }
.btn-action > * { position: relative; z-index: 1; }

/* info 按钮：描边药丸 */
.btn-info {
  background: rgba(88, 166, 255, 0.08);
  color: var(--accent);
  border: 1px solid rgba(88, 166, 255, 0.3);
}
.btn-info:hover {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.btn-info:active { transform: translateY(0); }

/* 输入中状态 */
.typing-indicator { display: inline-flex; align-items: center; gap: 6px; padding: 12px 16px; color: var(--text-muted); font-size: 13px; }
.typing-indicator .typing-text { white-space: nowrap; }
.typing-indicator .typing-dots { display: inline-flex; gap: 3px; }
.typing-indicator .typing-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted);
  animation: typing 1.4s infinite;
}
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* 快捷问题区 */
.quick-replies {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border-soft);
  background: var(--bg-base);
}
.quick-reply {
  padding: 8px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 13px;
  color: var(--text-secondary);
  transition: all 0.2s var(--ease);
}
.quick-reply:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* 输入区 */
.chat-input-area {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  resize: none;
  max-height: 120px;
  min-height: 42px;
  outline: none;
  transition: border-color 0.2s var(--ease);
}
.chat-input:focus { border-color: var(--accent); }
.chat-send {
  width: 42px; height: 42px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: #fff; flex-shrink: 0;
  transition: all 0.2s var(--ease);
}
.chat-send:hover { background: #4493f8; transform: scale(1.05); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* 弹窗遮罩 */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(1, 4, 9, 0.75);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  animation: modalIn 0.3s var(--ease);
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 12px; }
.modal-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* 评价星级 */
.rating { display: flex; gap: 8px; justify-content: center; margin: 16px 0; }
.rating-star {
  font-size: 28px; color: var(--border); cursor: pointer;
  transition: all 0.2s var(--ease);
}
.rating-star.active, .rating-star:hover { color: var(--warning); transform: scale(1.15); }

/* ========== 客服后台（多栏布局）========== */
.admin-app {
  height: 100vh;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 顶部栏 */
.admin-topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.admin-brand { display: flex; align-items: center; gap: 10px; }
.admin-brand-logo {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #58a6ff 0%, #1f6feb 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700;
}
.admin-brand-text { font-size: 15px; font-weight: 600; }
.admin-topbar-info { font-size: 13px; color: var(--text-muted); }

/* 统计栏 */
.admin-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 16px 24px;
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-soft);
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.stat-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.stat-value.accent { color: var(--accent); }
.stat-value.success { color: var(--success); }
.stat-value.warning { color: var(--warning); }

/* 主区域：左列表 + 右详情 */
.admin-main {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
}

/* 左侧会话列表 */
.session-list {
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.session-list-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: center;
}
.session-filter {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.session-list-body { flex: 1; overflow-y: auto; padding: 8px; }

.session-group-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 8px 6px;
  font-weight: 600;
}

.session-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s var(--ease);
  margin-bottom: 4px;
  border: 1px solid transparent;
  position: relative;
}
.session-item:hover { background: var(--bg-elevated); }
.session-item.active { background: var(--bg-elevated); border-color: var(--accent); }
.session-item.urgent {
  border-color: var(--danger);
  animation: urgentPulse 2s infinite;
}
@keyframes urgentPulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--danger-soft); }
  50% { box-shadow: 0 0 0 4px var(--danger-soft); }
}
.session-item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.session-user { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.session-time { font-size: 11px; color: var(--text-muted); }
.session-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 6px;
}
.session-tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-weight: 600;
}
.tag-pending { background: var(--danger-soft); color: var(--danger); }
.tag-ai { background: rgba(88, 166, 255, 0.12); color: var(--accent); }
.tag-human { background: rgba(63, 185, 80, 0.12); color: var(--success); }
.tag-closed { background: rgba(139, 148, 158, 0.12); color: var(--text-muted); }
.tag-attention { background: rgba(210, 153, 34, 0.12); color: var(--warning); margin-left: 4px; }
.unread-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 2px 6px; border-radius: var(--radius-pill);
  min-width: 18px; text-align: center;
}

/* 右侧详情 */
.session-detail {
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
  min-height: 0;
}
.detail-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.detail-user-info { display: flex; align-items: center; gap: 10px; }
.detail-user-name { font-size: 15px; font-weight: 600; }
.detail-meta { font-size: 12px; color: var(--text-muted); }
.detail-actions { display: flex; gap: 8px; }

.btn-sm {
  padding: 6px 14px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  transition: all 0.2s var(--ease);
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm.primary:hover { background: #4493f8; }
.btn-sm.danger { color: var(--danger); border-color: var(--danger); }
.btn-sm.danger:hover { background: var(--danger); color: #fff; }
.btn-sm.success { color: var(--success); border-color: var(--success); }
.btn-sm.success:hover { background: var(--success); color: #fff; }

.detail-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-input-area {
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  padding: 12px 16px;
}
.quick-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}
.quick-template {
  padding: 4px 10px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  transition: all 0.15s var(--ease);
}
.quick-template:hover { border-color: var(--accent); color: var(--accent); }

.detail-input-row { display: flex; gap: 8px; align-items: flex-end; }
.detail-input {
  flex: 1;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 13px;
  resize: none;
  max-height: 100px;
  min-height: 40px;
  outline: none;
}
.detail-input:focus { border-color: var(--accent); }
.detail-send {
  padding: 0 16px;
  height: 40px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s var(--ease);
}
.detail-send:hover { background: #4493f8; }
.detail-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* 空状态 */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  gap: 8px;
}
.empty-state-icon { font-size: 48px; opacity: 0.3; }

/* 提示横幅 */
.notice-banner {
  background: rgba(210, 153, 34, 0.1);
  border-left: 3px solid var(--warning);
  color: var(--warning);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

/* 滚动条美化 */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ========== Tab 切换栏 ========== */
.admin-tabs {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
}
.admin-tab {
  padding: 12px 20px;
  font-size: 14px;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.2s var(--ease);
}
.admin-tab:hover { color: var(--text-secondary); }
.admin-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ========== 知识库管理 ========== */
.kb-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
}
.kb-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}
.kb-toolbar-left, .kb-toolbar-right { display: flex; gap: 8px; align-items: center; }
.kb-search {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  width: 260px;
  outline: none;
}
.kb-search:focus { border-color: var(--accent); }
.kb-filter {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
}
.kb-table-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 24px;
}
.kb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.kb-table th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.kb-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
  color: var(--text-secondary);
}
.kb-table tr:hover { background: var(--bg-card); }
.kb-cat-tag {
  display: inline-block;
  padding: 3px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
}
.kb-keywords { display: flex; flex-wrap: wrap; gap: 4px; }
.kb-keyword-chip {
  font-size: 11px;
  padding: 2px 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
}
.kb-answer-preview {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.kb-actions { display: flex; gap: 4px; }
.kb-footer-info {
  padding: 12px 24px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

/* 知识库编辑弹窗 */
.kb-modal { width: 560px; max-width: 90vw; }
.kb-form { display: flex; flex-direction: column; gap: 14px; margin: 12px 0; }
.kb-form-row { display: flex; flex-direction: column; gap: 6px; }
.kb-form-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.kb-form-row .hint {
  font-weight: 400;
  font-size: 11px;
  color: var(--text-muted);
}
.kb-form-row input,
.kb-form-row textarea {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  font-family: inherit;
  resize: vertical;
}
.kb-form-row input:focus,
.kb-form-row textarea:focus { border-color: var(--accent); }

/* 响应式：小屏适配后台 */
@media (max-width: 900px) {
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
  .admin-main { grid-template-columns: 1fr; grid-template-rows: 40vh 1fr; }
  .session-list { max-height: none; }
  .kb-search { width: 160px; }
}
