:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1c1e21;
  --muted: #65676b;
  --line: #e4e6eb;
  --primary: #1877f2;
  --primary-soft: #e7f0fe;
  --ok: #1f9d55;
  --ok-soft: #e3f6ea;
  --warn: #b7791f;
  --warn-soft: #fdf3dd;
  --err: #d93025;
  --err-soft: #fde8e6;
  --bubble-user: #eef0f3;
  --bubble-ai: #1877f2;
  --bubble-human: #1f9d55;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 1px 8px rgba(0, 0, 0, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --panel: #232427;
    --text: #e4e6eb;
    --muted: #a0a3a8;
    --line: #36383c;
    --primary: #4b9bff;
    --primary-soft: #1d2c44;
    --ok: #3fbf74;
    --ok-soft: #1b3326;
    --warn: #e0a94a;
    --warn-soft: #3a2f19;
    --err: #ff6b5f;
    --err-soft: #3d1f1d;
    --bubble-user: #303236;
    --bubble-ai: #2d6fd1;
    --bubble-human: #23864a;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
small, .muted { color: var(--muted); }
code { background: var(--bubble-user); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; word-break: break-all; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: 0 20px; height: 54px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--primary); white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
.topbar nav a {
  color: var(--muted); padding: 6px 12px; border-radius: 8px; white-space: nowrap;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.on { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.logout { color: var(--muted); white-space: nowrap; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) {
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .grid.cols-2 { grid-template-columns: 1fr; }
}
.stat .num { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat .label { color: var(--muted); font-size: 13px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.wrap-text { max-width: 380px; white-space: pre-wrap; word-break: break-word; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  background: var(--bubble-user); color: var(--muted);
}
.badge.ai { background: var(--primary-soft); color: var(--primary); }
.badge.human, .badge.warn, .badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.replied, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.error { background: var(--err-soft); color: var(--err); }
.dot { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--err); color: #fff; font-size: 11px; text-align: center; }

/* ---------- 表单 ---------- */
input[type=text], input[type=password], input[type=number], input[type=search], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 80px; }
textarea.tall { min-height: 260px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
label { display: block; font-weight: 600; margin: 14px 0 6px; }
label .muted { font-weight: 400; }
.check { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; margin: 10px 0; }
.check input { margin-top: 4px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; font: inherit; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.inline { display: inline; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs a { padding: 4px 12px; border-radius: 999px; color: var(--muted); border: 1px solid var(--line); background: var(--panel); }
.tabs a.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.tabs a:hover { text-decoration: none; }

/* 开关 */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: none; }
.switch {
  position: relative; width: 44px; height: 24px; border-radius: 12px; border: none; cursor: pointer;
  background: var(--line); transition: background .15s; flex-shrink: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch.on { background: var(--ok); }
.switch.on::after { left: 23px; }

/* 提示 */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.err { background: var(--err-soft); color: var(--err); }
.note { padding: 10px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin: 10px 0; }
.note.info { background: var(--primary-soft); color: var(--primary); }

/* ---------- 聊天 ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 62vh; overflow-y: auto; padding: 4px 4px 10px; }
.msg { display: flex; flex-direction: column; max-width: 75%; }
.msg .bubble { padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; }
.msg .meta { font-size: 11.5px; color: var(--muted); margin: 2px 6px; }
.msg.user { align-self: flex-start; }
.msg.user .bubble { background: var(--bubble-user); border-bottom-left-radius: 4px; }
.msg.assistant, .msg.human { align-self: flex-end; align-items: flex-end; }
.msg.assistant .bubble { background: var(--bubble-ai); color: #fff; border-bottom-right-radius: 4px; }
.msg.human .bubble { background: var(--bubble-human); color: #fff; border-bottom-right-radius: 4px; }
.msg.system { align-self: center; max-width: 90%; }
.msg.system .bubble { background: transparent; color: var(--muted); font-size: 12.5px; padding: 2px 8px; text-align: center; }
.composer { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 14px; margin-top: 8px; }

/* 登录 */
.login { max-width: 360px; margin: 12vh auto 0; }

/* 设置页底部保存栏 */
.savebar {
  position: sticky; bottom: 12px; z-index: 5; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 16px; box-shadow: 0 4px 18px rgba(0, 0, 0, .10);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
td.name { white-space: nowrap; }
.ok-text { color: var(--ok); }
.err-text { color: var(--err); }
ol.steps { padding-left: 20px; margin: 0; }
ol.steps li { margin: 6px 0; }
input.secret { -webkit-text-security: disc; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
input.secret:placeholder-shown { -webkit-text-security: none; font-family: inherit; }
label .badge { font-weight: 400; margin-left: 4px; vertical-align: 1px; }
