:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --ink: #1c1c21;
  --ink-2: #5d5d66;
  --ink-3: #8a8a94;
  --line: #e6e6ea;
  --accent: #4f46e5;
  --accent-ink: #4338ca;
  --accent-soft: #eef0ff;
  --ok: #15803d;
  --ok-soft: #e9f7ef;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #b91c1c;
  --danger-soft: #fdeeee;
  --radius: 10px;
  --sidebar-w: 224px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  outline: none;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 220px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 8px 14px; font-weight: 500;
  transition: border-color .15s, background .15s, color .15s;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { color: var(--accent); background: var(--accent-soft); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* ---------- 登录 / 注册 ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-panel { width: 100%; max-width: 380px; }
.auth-brand { margin-bottom: 28px; }
.auth-brand h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: .01em; }
.auth-brand p { color: var(--ink-2); margin: 0; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
.auth-form .btn { margin-top: 6px; padding: 10px; }
.auth-switch { margin-top: 18px; text-align: center; color: var(--ink-2); font-size: 13px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- 应用外壳 ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { padding: 6px 10px 18px; }
.sidebar-brand h1 { font-size: 16px; margin: 0; letter-spacing: .01em; }
.sidebar-brand p { margin: 2px 0 0; font-size: 12px; color: var(--ink-3); }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav a:hover:not(.active) { background: var(--bg); color: var(--ink); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1px solid var(--line); }
.sidebar-foot a { padding: 9px 10px; border-radius: 8px; color: var(--ink-2); font-size: 13px; }
.sidebar-foot a:hover { background: var(--bg); color: var(--ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; border-bottom: 1px solid var(--line); background: var(--bg);
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-user { color: var(--ink-2); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.content { padding: 24px 28px 48px; max-width: 1040px; width: 100%; }

/* ---------- 文档管理 ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; }
.toolbar-note { color: var(--ink-3); font-size: 13px; }

.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--ink-3); font-weight: 600; background: var(--bg); }
tr:last-child td { border-bottom: none; }
td.title-cell { font-weight: 500; max-width: 280px; }
td .sub { color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.actions { display: flex; gap: 4px; white-space: nowrap; }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
}
.badge-pending { background: var(--warn-soft); color: var(--warn); }
.badge-embedded { background: var(--ok-soft); color: var(--ok); }
.badge-failed { background: var(--danger-soft); color: var(--danger); }

.pagination { display: flex; align-items: center; gap: 12px; margin-top: 14px; justify-content: flex-end; font-size: 13px; color: var(--ink-2); }

/* ---------- 抽屉编辑器 ---------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(28, 28, 33, .35);
  opacity: 0; transition: opacity .18s; z-index: 20;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 94vw);
  background: var(--surface); z-index: 21; transform: translateX(100%);
  transition: transform .2s; display: flex; flex-direction: column;
  box-shadow: -12px 0 40px rgba(28, 28, 33, .12);
}
.drawer.open { transform: none; }
.drawer-mask.open { opacity: 1; }
.drawer-head { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-body { padding: 20px 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.drawer-body label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
.drawer-foot { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- 账户设置 ---------- */
.profile-section { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 22px 24px; margin-bottom: 18px; }
.profile-section h2 { margin: 0 0 4px; font-size: 15px; }
.profile-section .desc { color: var(--ink-3); font-size: 13px; margin: 0 0 16px; }
.form-grid { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
.form-grid label { font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 6px; }
.api-key-row { display: flex; gap: 10px; align-items: center; }
.api-key-row input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.api-key-row .btn { flex: none; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.toast.error { background: var(--danger); }

.check-row {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.check-row input { width: auto; cursor: pointer; }

.muted { color: var(--ink-3); }
.row-pending td { background: var(--danger-soft); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.nav-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 1;
}
@media (max-width: 760px) {
  .sidebar { width: 64px; padding: 12px 8px; }
  .sidebar-brand p, .nav a span, .sidebar-foot a span { display: none; }
  .content { padding: 18px 16px 40px; }
}

/* ---------- 会话记录 ---------- */
.search-row { display: flex; gap: 10px; align-items: center; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; }
.conv-q, .conv-a {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px 14px; font-size: 13px;
}
.conv-q { border-left: 3px solid var(--accent); }
.conv-a { border-left: 3px solid var(--ok); }
/* ---------- 人工客服（微信 PC 式两栏） ---------- */
.content.agent-content {
  max-width: none; padding: 0;
  height: calc(100vh - 56px); display: flex;
}
.agent-wrap { flex: 1; display: flex; min-width: 0; height: 100%; background: #f2f2f2; }
.agent-sidebar {
  width: 300px; flex: none; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
}
.agent-sidebar-head {
  padding: 14px 16px 10px; display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; font-weight: 600; border-bottom: 1px solid var(--line);
}
.agent-sessions { flex: 1; overflow-y: auto; }
.agent-session-row { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.agent-session-row:hover { background: var(--bg); }
.agent-session-row.active { background: var(--accent-soft); }
.agent-session-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.agent-session-name {
  font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent-session-time { color: var(--ink-3); font-size: 12px; flex: none; }
.agent-session-preview {
  margin-top: 3px; color: var(--ink-3); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent-session-badges { margin-top: 6px; display: flex; gap: 6px; }
.agent-chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: #f2f2f2; }
.agent-chat-head {
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 12px;
}
.agent-chat-head strong { font-size: 15px; }
.agent-thread {
  flex: 1; overflow-y: auto; padding: 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.chat-msg {
  max-width: 68%; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; line-height: 1.55; word-break: break-word;
}
.chat-msg .meta { font-size: 11px; color: var(--ink-3); margin-bottom: 4px; }
.chat-msg.customer { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.chat-msg.agent { align-self: flex-end; background: #95ec69; }
.chat-msg.bot {
  align-self: center; background: rgba(0, 0, 0, .06); color: var(--ink-2);
  font-size: 12px; max-width: 90%; text-align: center;
}
.agent-foot { border-top: 1px solid var(--line); background: var(--surface); padding: 12px 16px; }
.agent-send { display: flex; flex-direction: column; gap: 8px; }
.agent-send textarea { min-height: 60px; }
.agent-send-actions { display: flex; gap: 8px; justify-content: flex-end; }
.agent-foot-actions { display: flex; justify-content: center; }
