/* ============================================================
   我的记忆库 — 样式
   ============================================================ */
:root {
  /* —— 中性色（白 / 灰，无彩） —— */
  --bg: #f7f7f8;
  --bg-soft: #f0f1f2;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  /* 主色 = 近黑。所有「强调」都用它，不再有彩色主色 */
  --ink: #1a1a1c;
  --ink-hover: #303034;
  --ink-soft: #f1f1f2;
  --ink-border: #dededf;

  --border: #e8e8ea;
  --border-strong: #d8d8db;
  --text: #1a1a1c;
  --text-2: #46474b;
  --muted: #8b8b90;

  /* 兼容既有调用：primary / accent 一律指向中性墨色 */
  --primary: var(--ink);
  --primary-dark: var(--ink-hover);
  --primary-soft: var(--ink-soft);
  --accent: var(--ink);

  /* 语义色：只在真正表达语义时出现（成功 / 警告 / 错误） */
  --ok: #2f7d51;
  --warn: #b06a1d;
  --danger: #b0392f;

  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(24, 24, 27, .045);
  --shadow-md: 0 1px 3px rgba(24, 24, 27, .05), 0 8px 24px -12px rgba(24, 24, 27, .1);
  --shadow-lg: 0 24px 60px -20px rgba(24, 24, 27, .22);
  --font: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei UI", "Microsoft YaHei", "Hiragino Sans GB", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", ui-monospace, Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.62;
  letter-spacing: .005em;
}
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
b, strong { font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* 统一键盘可达性：只对键盘操作显示焦点环 */
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; border-radius: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfcfd2; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b1b1b6; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ===================== 布局 ===================== */
.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

.topbar {
  flex: none;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* 品牌标记：白底细边 + 墨色线性图标，不用渐变色块 */
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center; color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
}
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 14.5px; font-weight: 600; letter-spacing: .01em; line-height: 1.25; }
.brand-text p { font-size: 11.5px; color: var(--muted); line-height: 1.4; white-space: nowrap; }

/* 标签：改成底部细线指示，而不是圆角胶囊块 */
.tabs { display: flex; gap: 2px; margin-left: 6px; flex: none; align-self: stretch; }
.tab {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  border: 0; background: transparent; cursor: pointer;
  padding: 0 12px; font-size: 13.5px; color: var(--muted);
  transition: color .15s;
}
.tab:hover { color: var(--text-2); }
.tab.is-active { color: var(--text); font-weight: 600; }
.tab.is-active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px;
  height: 2px; background: var(--text); border-radius: 2px 2px 0 0;
}
.badge {
  font-size: 11px; font-weight: 600; line-height: 1;
  padding: 3px 6px; border-radius: 5px;
  background: var(--bg-soft); color: var(--muted);
}
.tab.is-active .badge { background: var(--ink-soft); color: var(--text-2); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.model-pick {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 0 8px 0 10px; height: 34px; color: var(--muted);
}

/* 回答策略切换：仅知识库 / 知识库优先 —— 中性分段控件 */
.mode-pick {
  display: flex; align-items: center; gap: 2px; height: 34px; padding: 3px;
  background: var(--bg-soft); border-radius: 8px;
}
.mode-pick button {
  border: 0; background: transparent; cursor: pointer; height: 28px; padding: 0 10px;
  border-radius: 6px; font-size: 12.5px; font-weight: 500; color: var(--muted);
  white-space: nowrap; font-family: inherit;
  transition: background .14s, color .14s;
}
.mode-pick button:hover { color: var(--text-2); }
.mode-pick button.is-on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
/* 放开知识库限制：用左侧竖线 + 警示色文字提示，而不是整块琥珀底色 */
.mode-pick button.is-on.wide { background: var(--surface); color: var(--warn); box-shadow: var(--shadow-sm); }
.model-pick select {
  border: 0; background: transparent; outline: none; cursor: pointer;
  font-size: 13px; color: var(--text-2); max-width: 150px; height: 32px;
}
.user-area { display: flex; align-items: center; gap: 8px; }

.body { flex: 1; display: flex; min-height: 0; }

/* ===================== 侧边栏 ===================== */
.sidebar {
  flex: none; width: 248px; background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 10px;
  transition: transform .22s ease;
}
.app.view-kb .sidebar { display: none; }
.sb-label { font-size: 11px; font-weight: 600; color: var(--muted); letter-spacing: .08em; padding: 8px 8px 2px; }
.sb-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.sb-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer;
  font-size: 13.2px; color: var(--text-2);
  transition: background .14s;
}
.sb-item:hover { background: var(--bg-soft); }
.sb-item.is-active { background: var(--ink-soft); color: var(--text); font-weight: 600; }
.sb-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-item .del,
.sb-item .ren { opacity: 0; flex: none; border: 0; background: transparent; cursor: pointer; color: var(--muted); padding: 2px; border-radius: 5px; line-height: 0; }
.sb-item:hover .del,
.sb-item:hover .ren,
.sb-item.is-active .del,
.sb-item.is-active .ren { opacity: 1; }
.sb-item .del:hover { color: var(--danger); background: #f6e9e8; }
.sb-item .ren:hover { color: var(--text); background: var(--bg-soft); }
.sb-empty { padding: 16px 10px; font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.7; }
.sb-foot { border-top: 1px solid var(--border); padding-top: 10px; font-size: 12px; color: var(--muted); }
.sidebar-mask { display: none; }

/* ===================== 主区域 ===================== */
.main { flex: 1; min-width: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.is-active { display: flex; }

/* ---------- 聊天 ---------- */
.chat-scroll { flex: 1; overflow-y: auto; }
.chat-inner { max-width: 780px; margin: 0 auto; padding: 30px 22px 18px; }

.welcome { text-align: center; padding: 54px 10px 26px; }
/* 欢迎图标：白底细边，不用渐变 */
.welcome-icon {
  width: 52px; height: 52px; margin: 0 auto 18px; border-radius: 13px;
  display: grid; place-items: center; color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--border-strong);
}
.welcome h2 { font-size: 20px; font-weight: 600; letter-spacing: .01em; }
.welcome > p { margin-top: 9px; color: var(--muted); font-size: 13.5px; max-width: 440px; margin-inline: auto; line-height: 1.7; }
.suggests { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 24px; }
.suggest {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; color: var(--text-2);
  cursor: pointer; transition: border-color .14s, color .14s, background .14s;
}
.suggest:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-2); }
.kb-hint { margin-top: 22px; font-size: 12.4px; color: var(--muted); }
.kb-hint button { border: 0; background: none; color: var(--text-2); cursor: pointer; font-size: inherit; text-decoration: underline; text-underline-offset: 3px; padding: 0 2px; }
.kb-hint button:hover { color: var(--text); }

.messages { display: flex; flex-direction: column; gap: 22px; padding-bottom: 12px; }
.msg { display: flex; gap: 11px; }
.msg.user { flex-direction: row-reverse; }
/* 头像：中性面块 + 细边，去掉彩色渐变 */
.avatar {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-size: 11.5px; font-weight: 600;
  background: var(--surface); color: var(--text-2);
  border: 1px solid var(--border-strong);
}
.msg.user .avatar { background: var(--ink); color: #fff; border-color: var(--ink); }
.bubble-wrap { min-width: 0; max-width: 100%; display: flex; flex-direction: column; gap: 8px; }
.msg.user .bubble-wrap { align-items: flex-end; }
/* 助手气泡：无边框、无阴影，用底色区分 */
.bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 13px 16px;
  font-size: 14.2px; line-height: 1.78; word-break: break-word; overflow-wrap: anywhere;
}
/* 用户气泡：近黑实底，白字 */
.msg.user .bubble {
  background: var(--ink); color: #fff;
  border-color: var(--ink); max-width: 78%;
}
.msg.user .bubble a { color: #fff; text-decoration: underline; text-underline-offset: 3px; }
.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 9px; }
.bubble h4 { font-size: 14.6px; margin: 14px 0 7px; font-weight: 600; }
.bubble h5 { font-size: 14px; margin: 12px 0 6px; font-weight: 600; }
.bubble ul, .bubble ol { margin: 6px 0 10px; padding-left: 21px; }
.bubble li { margin: 3px 0; }
.bubble code {
  font-family: var(--mono); font-size: 12.6px; background: var(--bg-soft);
  padding: 2px 5px; border-radius: 5px; color: var(--text);
}
.bubble pre.md-pre {
  background: #1c1c1e; color: #ececee; border-radius: 9px; padding: 12px 14px;
  overflow-x: auto; font-size: 12.6px; margin: 10px 0; line-height: 1.65;
}
.bubble pre.md-pre code { background: none; color: inherit; padding: 0; font-size: inherit; }
.bubble blockquote { margin: 8px 0; padding: 4px 0 4px 12px; border-left: 2px solid var(--border-strong); color: var(--muted); }
.bubble a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--border-strong); }
.bubble a:hover { text-decoration-color: var(--text); }
.bubble table { border-collapse: collapse; margin: 10px 0; font-size: 13.2px; width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble th { background: var(--surface-2); font-weight: 600; }

/* 思考步骤 */
.steps { display: flex; flex-direction: column; gap: 5px; font-size: 12.6px; color: var(--muted); }
.step { display: flex; align-items: center; gap: 7px; }
.step .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--border-strong); flex: none; }
.step.done .dot { background: #b6b6ba; }
.step.active { color: var(--text-2); }
.step.active .dot { background: var(--text-2); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.25); } }

/* 思考区：推理模型先输出 reasoning_content，实时展示避免界面长时间空白 */
.thinking {
  display: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 9px; padding: 9px 12px;
}
.thinking.is-on { display: block; }
.thinking-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.3px; color: var(--text-2); font-weight: 500; line-height: 1.4;
}
.thinking-head .spinner { width: 11px; height: 11px; border-width: 1.6px; }
.thinking-head.clickable { cursor: pointer; }
.thinking-head.clickable:hover { color: var(--text); }
.thinking-time { margin-left: auto; font-family: var(--mono); font-size: 11.6px; color: var(--muted); font-weight: 400; }
.thinking-caret {
  width: 6px; height: 6px; flex: none; opacity: 0;
  border-right: 1.4px solid currentColor; border-bottom: 1.4px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px); transition: transform .16s, opacity .16s;
}
.thinking-body {
  margin-top: 8px; max-height: 128px; overflow-y: auto;
  font-size: 12.2px; line-height: 1.7; color: var(--muted);
  white-space: pre-wrap; word-break: break-word;
}
.thinking.is-done { background: transparent; border-color: var(--border); }
.thinking.is-done .thinking-head { color: var(--muted); }
.thinking.is-done .thinking-head .spinner { display: none; }
.thinking.is-done .thinking-caret { opacity: .55; }
.thinking.is-done .thinking-body { display: none; }
.thinking.is-done.is-open .thinking-body { display: block; }
.thinking.is-done.is-open .thinking-caret { opacity: .8; transform: rotate(-135deg) translate(-2px, -1px); }

/* 来源：中性浅灰标签 */
.sources { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.sources .lbl { font-size: 12px; color: var(--muted); }
.source-chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 260px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2);
  border-radius: 7px; padding: 4px 9px; font-size: 12.2px; cursor: pointer;
  transition: border-color .14s, color .14s, background .14s;
}
.source-chip:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface); }
.source-chip .n { font-weight: 600; color: var(--muted); }
.source-chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-chip.none { background: transparent; border-style: dashed; color: var(--muted); cursor: default; }

.msg-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg.user .msg-actions { justify-content: flex-end; }
.msg-actions button {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 7px; padding: 3px 9px; font-size: 12px; cursor: pointer;
  transition: border-color .14s, color .14s;
}
.msg-actions button:hover { color: var(--text); border-color: var(--border-strong); }
.cursor { display: inline-block; width: 2px; height: 15px; vertical-align: -2px; margin-left: 3px; background: var(--text); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.err-box { border: 1px solid #e8d2cf; background: #faf3f2; color: var(--danger); border-radius: 10px; padding: 10px 14px; font-size: 13.2px; }

/* 输入区 */
.composer { flex: none; padding: 8px 22px 22px; }
.composer-wrap { max-width: 780px; margin: 0 auto; }
.composer-box {
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 12px; padding: 9px 9px 9px 15px;
  transition: border-color .16s, box-shadow .16s;
}
.composer-box:focus-within { border-color: var(--text); box-shadow: 0 0 0 3px rgba(24, 24, 27, .06); }
.composer-box textarea {
  flex: 1; border: 0; outline: none; resize: none; background: transparent;
  max-height: 176px; min-height: 26px; padding: 5px 0; font-size: 14.2px; line-height: 1.6;
}
.composer-box textarea::placeholder { color: #a9a9ae; }
/* 发送按钮：近黑方形，去掉渐变与彩色投影 */
.send-btn {
  flex: none; width: 34px; height: 34px; border-radius: 8px; border: 0; cursor: pointer;
  display: grid; place-items: center; color: #fff;
  background: var(--ink);
  transition: background .14s, opacity .14s;
}
.send-btn:hover { background: var(--ink-hover); }
.send-btn:disabled { opacity: .3; cursor: not-allowed; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 4px 0; }
.status-tip { font-size: 12px; color: var(--muted); }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  padding: 8px 14px; font-size: 13.3px; font-weight: 500; transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: var(--ink-hover); }
.btn.ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); }
.btn.ghost:hover { border-color: var(--text-2); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { background: #97302a; }
.btn.block { width: 100%; }
.btn.tiny { padding: 4px 10px; font-size: 12px; border-radius: 7px; background: transparent; border-color: var(--border); color: var(--muted); }
.btn.tiny:hover { border-color: var(--border-strong); color: var(--text); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--text-2); padding: 6px; border-radius: 7px; line-height: 0; }
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }
.only-mobile { display: none; }

/* ===================== 知识库视图 ===================== */
.view-kb { background: var(--bg); }
.kb-head {
  flex: none; display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  padding: 26px 32px 18px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.kb-head h2 { font-size: 18px; font-weight: 600; letter-spacing: .01em; }
.kb-head p { margin-top: 5px; font-size: 13px; }
/* 我的空间统计：一行小字，不做卡片不做图表 */
.kb-stats { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 7px; font-size: 12px; color: var(--muted); }
.kb-stats b { color: var(--text-2); font-weight: 600; }
/* 配额行：贴近上限时降饱和提示，不用刺眼的红块 */
.kb-stats .quota { padding-left: 14px; border-left: 1px solid var(--border); }
.kb-stats .quota-near { color: var(--warn, #8a6a1f); }
.kb-stats .quota-full { color: var(--danger); }
.kb-stats .quota-full b, .kb-stats .quota-near b { color: inherit; }
.kb-actions { display: flex; gap: 8px; }
.kb-filters { flex: none; display: flex; align-items: center; gap: 12px; padding: 16px 32px 6px; flex-wrap: wrap; }
.search-box {
  display: flex; align-items: center; gap: 8px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 0 12px; height: 36px; width: 290px; max-width: 100%;
}
.search-box:focus-within { border-color: var(--text); box-shadow: 0 0 0 3px rgba(24, 24, 27, .06); }
.search-box input { border: 0; outline: none; background: transparent; flex: 1; font-size: 13.4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
/* 范围筛选（全部 / 我的 / 共享）与右侧分类筛选用细竖线分开，避免看成一排同级 chip */
#kbScope { padding-right: 12px; border-right: 1px solid var(--border); }
.chip {
  border: 1px solid var(--border); background: transparent; color: var(--muted);
  border-radius: 7px; padding: 5px 11px; font-size: 12.5px; cursor: pointer;
  transition: border-color .14s, color .14s, background .14s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text-2); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

.kb-list { flex: 1; overflow-y: auto; padding: 12px 32px 40px; display: flex; flex-direction: column; gap: 1px; }
/* 卡片改成「列表行」观感：去掉卡片阴影，靠分隔线组织 */
.kb-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 15px 17px; transition: border-color .16s, background .16s;
}
.kb-card:hover { border-color: var(--border-strong); background: var(--surface-2); }
.kb-card-top { display: flex; align-items: flex-start; gap: 10px; }
.kb-card h3 { font-size: 14.6px; font-weight: 600; flex: 1; min-width: 0; line-height: 1.5; }
.kb-cat {
  flex: none; font-size: 11.5px; font-weight: 500; padding: 3px 8px; border-radius: 5px;
  background: var(--bg-soft); color: var(--muted);
}
.kb-own { flex: none; font-size: 11.4px; padding: 3px 8px; border-radius: 5px; background: var(--bg-soft); color: var(--muted); }
.kb-own.mine { background: #eef4f0; color: var(--ok); }
.kb-body { margin-top: 8px; font-size: 13.3px; color: var(--muted); line-height: 1.75; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.kb-card-foot { margin-top: 12px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kb-tag { font-size: 11.6px; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 5px; padding: 2px 7px; }
.kb-time { font-size: 11.6px; color: var(--muted); margin-left: auto; }
/* 来源标记：这条记忆是怎么进来的（手动 / 粘贴 / 文件 / 网页） */
.kb-src { font-size: 11.5px; color: var(--muted); }
.kb-src-link { margin-top: 14px; font-size: 12.2px; color: var(--muted); word-break: break-all; line-height: 1.7; }
.kb-src-link a { color: var(--text-2); text-decoration: underline; text-underline-offset: 2px; }
/* 回收站列表：行式布局，左侧内容右侧操作 */
.trash-row { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
.trash-row:last-child { border-bottom: 0; }
.trash-main { flex: 1; min-width: 0; }
.trash-title { font-size: 13.6px; font-weight: 600; color: var(--text); line-height: 1.5; }
.trash-sub { font-size: 12.2px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trash-meta { flex: none; font-size: 11.6px; color: var(--muted); }
.trash-actions { flex: none; display: flex; gap: 6px; }

/* ===================== 管理概览（只有数字，不用彩色卡片） ===================== */
.adm-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.adm-card { background: var(--surface); padding: 13px 15px; }
.adm-num { font-size: 21px; font-weight: 600; color: var(--ink); line-height: 1.2; font-variant-numeric: tabular-nums; }
.adm-key { font-size: 12.6px; font-weight: 500; color: var(--text-2); margin-top: 4px; }
.adm-note { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.adm-sec { margin-top: 20px; }
.adm-sec-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .05em; margin-bottom: 10px; }
/* 分布行：标签 + 占比条 + 数量 */
.dist-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; font-size: 12.8px; color: var(--text-2); }
.dist-name { flex: none; width: 84px; }
.dist-bar { flex: 1; height: 5px; background: var(--bg-soft); border-radius: 3px; overflow: hidden; }
.dist-bar i { display: block; height: 100%; background: var(--ink); opacity: .82; }
.dist-num { flex: none; width: 48px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.adm-limits { display: flex; flex-wrap: wrap; gap: 8px; }
.adm-limit { display: inline-flex; align-items: center; gap: 6px; font-size: 12.2px; color: var(--text-2); border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; }
.adm-limit b { font-weight: 500; color: var(--muted); font-family: var(--font-mono, monospace); font-size: 11.6px; }
.adm-limit i { font-style: normal; font-size: 11px; color: var(--muted); background: var(--bg-soft); border-radius: 4px; padding: 1px 6px; }

/* ---- 管理弹窗页签 ---- */
.adm-tabs { display: flex; gap: 2px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.adm-tab {
  appearance: none; background: none; border: none; border-bottom: 2px solid transparent;
  padding: 8px 12px 9px; margin-bottom: -1px; font: inherit; font-size: 13.5px;
  color: var(--muted); cursor: pointer;
}
.adm-tab:hover { color: var(--text); }
.adm-tab.is-active { color: var(--text); border-bottom-color: var(--ink); font-weight: 600; }
.adm-sub { font-weight: 400; color: var(--muted); font-size: 12px; }

/* ---- 用户与权限 ---- */
.usr-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.usr-row {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px;
  background: var(--surface);
}
.usr-main { flex: 1 1 auto; min-width: 0; }
.usr-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.usr-mail { font-size: 13.6px; color: var(--text); font-weight: 500; word-break: break-all; }
.usr-badge {
  flex: none; font-size: 11px; padding: 1px 7px; border-radius: 5px;
  color: var(--muted); background: var(--bg-soft); border: 1px solid var(--border);
}
.usr-badge.on { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.usr-badge.self { color: var(--text-2); }
.usr-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 5px; font-size: 11.8px; color: var(--muted); }
.usr-actions { flex: none; }
.usr-actions .btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---- 授权操作审计 ---- */
.audit-list { display: flex; flex-direction: column; margin-top: 8px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.audit-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 12.6px; border-bottom: 1px solid var(--border); }
.audit-row:last-child { border-bottom: 0; }
.audit-act {
  flex: none; font-size: 11px; padding: 1px 7px; border-radius: 5px;
  border: 1px solid var(--border); color: var(--muted); background: var(--bg-soft);
}
/* 语义色只在这里出现，且保持低饱和：授权=中性偏实、取消=弱警示 */
.audit-act.is-on { color: var(--text); background: var(--surface); border-color: var(--border-strong); }
.audit-act.is-off { color: var(--danger); background: #f9f0ef; border-color: #ecd9d7; }
.audit-txt { flex: 1; min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-time { flex: none; color: var(--muted); font-size: 11.6px; }
/* 账号信息：用户区可点击主体 + 键值行 */
.uc-main { display: flex; align-items: center; gap: 8px; background: transparent; border: 0; padding: 0; cursor: pointer; min-width: 0; font-family: inherit; }
.acct-list { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.acct-row { display: flex; align-items: center; gap: 12px; padding: 10px 13px; border-bottom: 1px solid var(--border); font-size: 13px; }
.acct-row:last-child { border-bottom: 0; }
.acct-k { flex: none; width: 76px; color: var(--muted); font-size: 12.4px; }
.acct-v { flex: 1; min-width: 0; color: var(--text); font-family: var(--font-mono, monospace); font-size: 12.4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 时间线分组标题 */
.kb-group-head {
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  letter-spacing: .06em; padding: 18px 2px 7px;
}
.kb-card-actions { display: flex; gap: 6px; }
.empty-state { text-align: center; padding: 80px 20px; color: var(--muted); }
.empty-state h3 { font-size: 15px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }
.empty-state p { font-size: 13px; }

/* 空库时的起步引导。做成一块卡片而不是一行灰字：这是新用户唯一的
   可行动项，视觉上必须比周围的说明文字重。配色仍守白灰 + 近黑。 */
.starter-cta {
  margin: 26px auto 0; max-width: 460px; text-align: left;
  padding: 20px 22px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border-strong);
}
.starter-cta-head { font-size: 13.5px; font-weight: 600; color: var(--text); margin-bottom: 7px; }
.starter-cta p { font-size: 12.8px; line-height: 1.75; color: var(--muted); margin-bottom: 15px; }
.starter-cta .btn { width: 100%; justify-content: center; }
.starter-cta-note { margin-top: 11px; font-size: 12px; line-height: 1.65; color: var(--muted); }

/* ===================== 弹窗 / 提示 ===================== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(24, 24, 27, .32);
  backdrop-filter: blur(2px); z-index: 100;
  display: grid; place-items: center; padding: 20px;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%; max-width: 560px; max-height: 90dvh; display: flex; flex-direction: column;
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.02);
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px 12px; }
.modal-head h3 { font-size: 15.5px; font-weight: 600; flex: 1; }
.modal-head .sub { font-size: 12.4px; color: var(--muted); }
.modal-body { padding: 4px 22px 8px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 22px 20px; }

.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.6px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field .hint { font-size: 11.8px; color: var(--muted); margin-top: 5px; }
.input, .textarea, .select {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 9px 12px; font-size: 13.6px; outline: none; background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--text); box-shadow: 0 0 0 3px rgba(24, 24, 27, .06); }
.textarea { resize: vertical; min-height: 150px; line-height: 1.72; font-family: var(--font); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.otp-row { display: flex; gap: 9px; }
.otp-row .input { flex: 1; }

.seg { display: flex; gap: 3px; background: var(--bg-soft); padding: 3px; border-radius: 8px; margin-bottom: 16px; }
.seg button {
  flex: 1; border: 0; background: transparent; cursor: pointer; padding: 7px 0;
  border-radius: 6px; font-size: 13.2px; color: var(--muted); transition: background .15s, color .15s;
}
.seg button.is-active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }

.form-alert { border-radius: 8px; padding: 9px 12px; font-size: 12.8px; margin-bottom: 12px; display: none; }
.form-alert.show { display: block; }
.form-alert.error { background: #faf3f2; border: 1px solid #e8d2cf; color: var(--danger); }
.form-alert.ok { background: #f2f6f3; border: 1px solid #d6e3da; color: var(--ok); }
.form-alert.info { background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-2); }

.toast-root { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 9px; align-items: center; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; border-radius: 9px; padding: 10px 18px;
  font-size: 13.2px; box-shadow: var(--shadow-lg); animation: toastIn .2s ease; max-width: 82vw;
}
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

.spinner {
  width: 15px; height: 15px; border-radius: 50%; flex: none;
  border: 2px solid var(--border-strong); border-top-color: var(--text-2);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-row { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13px; padding: 4px 0; }

/* ===================== 响应式 ===================== */
@media (max-width: 960px) {
  .brand-text p { display: none; }
  .only-mobile { display: inline-flex; }
  .sidebar {
    position: fixed; top: 60px; bottom: 0; left: 0; z-index: 40;
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
  }
  .app.sb-open .sidebar { transform: translateX(0); }
  .app.sb-open .sidebar-mask { display: block; position: fixed; inset: 60px 0 0; background: rgba(24, 24, 27, .28); z-index: 35; }
  .kb-head { flex-direction: column; align-items: stretch; padding: 20px 18px 14px; }
  .kb-filters { padding: 14px 18px 6px; }
  .kb-list { padding: 12px 18px 32px; }
  .search-box { width: 100%; }
  .chat-inner { padding: 20px 14px 12px; }
  .composer { padding: 8px 14px 16px; }
  .modal-body { padding-inline: 16px; }
  .modal-head, .modal-foot { padding-inline: 16px; }
  .row-2 { grid-template-columns: 1fr; }
  .model-pick select { max-width: 96px; }
  /* 窄屏下把两段文案压短，避免顶栏被挤爆 */
  .mode-pick button { padding: 0 7px; font-size: 11.8px; }
}
/* 更窄时顶栏放不下"品牌名 + 标签页 + 策略开关 + 模型 + 账号"，只留图标。
   实测 760px：不隐藏品牌文字时 h1 与标签页会被挤成竖排。 */
@media (max-width: 840px) {
  .brand-text { display: none; }
}
@media (min-width: 961px) {
  .app.sb-open .sidebar-mask { display: none; }
}

/* ===================== 账号区域 & 链接按钮 ===================== */
.link-btn {
  border: 0; background: none; padding: 0; cursor: pointer;
  color: var(--text-2); font-size: 12.6px; text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--border-strong);
}
.link-btn:hover { color: var(--text); text-decoration-color: var(--text); }

.user-chip {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 8px; padding: 3px 3px 3px 3px; height: 34px;
}
.user-chip .av {
  width: 26px; height: 26px; border-radius: 6px; flex: none;
  display: grid; place-items: center; color: #fff;
  font-size: 11.5px; font-weight: 600;
  background: var(--ink);
}
.user-chip .nm {
  font-size: 12.6px; color: var(--text-2); max-width: 128px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip .out {
  border: 0; background: none; cursor: pointer; color: var(--muted);
  line-height: 0; padding: 4px; border-radius: 5px; margin-right: 3px;
}
.user-chip .out:hover { color: var(--text); background: var(--bg-soft); }

/* 窄屏下用户行竖排，避免邮箱与操作按钮互相挤 */
@media (max-width: 640px) {
  .usr-row { flex-direction: column; align-items: stretch; gap: 9px; }
  .usr-actions .btn { width: 100%; }
  .adm-tabs { margin-bottom: 13px; }
}

/* ===================== 手机端自适应 =====================
   顶栏一行塞不下「品牌 + 标签页 + 策略开关 + 模型 + 账号」：
   实测 390px 宽时 topbar-right 需要 392px，「记忆库优先」被截断、
   模型选择和登录按钮整块跑出屏幕外。改成两行：第一行品牌+标签页，
   第二行策略开关+模型+账号，各元素都能完整呈现。 */
@media (max-width: 640px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    padding: 0 12px;
    row-gap: 0;
  }
  /* 第一行：菜单 + 品牌 + 标签页，占满整行 */
  .topbar > .icon-btn,
  .topbar > .brand,
  .topbar > .tabs { flex: 0 0 auto; }
  .topbar > .tabs { margin-left: 2px; }
  .topbar > .brand { margin-right: auto; }
  .topbar .tab { padding: 0 10px; font-size: 13px; }

  /* 第二行：策略开关 + 模型 + 账号。用 order 挪到换行点之后，
     占满整行并两端对齐，不再跟第一行抢空间。
     360px 屏实测这行需要 424px，塞不下 —— 手机端把模型选择的
     图标容器去掉（只留下拉框本身）、间距收到 4px，压到 ~350px。 */
  .topbar-right {
    order: 10;
    flex: 1 1 100%;
    margin-left: 0;
    padding: 6px 0 8px;
    gap: 4px;
    justify-content: space-between;
    border-top: 1px solid var(--border);
  }
  .mode-pick { height: 32px; padding: 2px; }
  .mode-pick button { padding: 0 8px; font-size: 12px; height: 28px; }
  .model-pick { border: 0; background: transparent; padding: 0; height: 32px; }
  .model-pick > svg { display: none; }
  .model-pick select { max-width: 104px; font-size: 12.5px; height: 32px; }
  .user-area .btn { height: 32px; padding: 0 10px; font-size: 12.5px; }
  /* 登录后的用户胶囊：手机端不显示邮箱（第二行塞不下，截断也难看），
     只留头像 + 退出按钮。想看完整账号去「账号」弹窗。 */
  .user-chip .nm { display: none; }

  /* 侧栏抽屉与遮罩从屏幕顶端开始：topbar 变成两行后固定 60px 的旧锚点
     会让遮罩盖不住第二行。抽屉盖过 topbar 是抽屉的标准形态。 */
  .sidebar { top: 0; padding-top: 8px; }
  .app.sb-open .sidebar-mask { inset: 0; }

  /* 记忆库页操作按钮：四个按钮一行放不下，允许换行 */
  .kb-actions { flex-wrap: wrap; }
  .kb-actions .btn { flex: 0 0 auto; }

  /* 记忆库页改为整页滚动。原来 .kb-list 单独滚动，但手机上
     顶栏(82px) + 头部(约200px) + 筛选区(约100px) 吃掉大半屏，
     列表只剩 ~280px —— 矮屏机型一屏只能看到一条记忆，滑动手势
     也只在底部一小条生效。改成整个视图滚动：头部/筛选区随内容
     滚走，整屏都能滑动，一屏能看到 2~3 条。 */
  .view-kb.is-active { display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .view-kb .kb-list { overflow: visible; }
  .kb-head { padding: 14px 18px 12px; }
  .kb-filters { padding: 12px 18px 4px; }

  /* 欢迎页与正文留白收紧，把空间留给内容 */
  .welcome { padding-top: 26px; }
  .chat-inner { padding-top: 16px; }

  /* 输入框占位文案在窄屏下太长会被截断得很难看，缩短 */
  .composer textarea::placeholder { font-size: 12.5px; }

  /* 弹窗：mask 是 grid（place-items:center），item 的自动最小尺寸会被
     长内容（如回收站 .trash-sub 的 90 字 nowrap 预览）撑爆 —— 实测 375px
     手机上 wide 弹窗直接 720px 宽，「恢复/彻底删除」按钮全被推出屏幕右缘。
     把列轨道钉死为 minmax(0,1fr) + 弹窗 min-width:0，宽度过擂台回到
     mask 内边距之内；内容超出由 .modal-body 内部滚动承担（竖向一直正常）。
     只在 ≤640px 改轨道：桌面 auto 轨道让小弹窗按内容收缩的现状保持不变。 */
  .modal-mask { grid-template-columns: minmax(0, 1fr); }
  .modal { min-width: 0; }

  /* 回收站预览在手机上不再单行省略（一行只剩 ~130px 太短），
     改成最多两行截断，与 .kb-body 同款手法 */
  .trash-sub {
    white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  }
}

/* 极窄屏（老机型 320~360px）：第二行还差 ~35px，再压一档。
   策略开关文案改用更短的词（通过 data-short 属性由 CSS content 换不掉
   按钮文字，所以这里直接缩 padding + 字号 + 模型下拉宽度）。 */
@media (max-width: 359px) {
  .topbar .tab { padding: 0 8px; font-size: 12.5px; }
  .topbar-right { gap: 3px; }
  .mode-pick button { padding: 0 6px; font-size: 11.5px; }
  .model-pick select { max-width: 88px; font-size: 12px; }
  .user-area .btn { padding: 0 8px; font-size: 12px; }
}

.kb-lock-tip {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
  border-radius: 9px; padding: 10px 14px; font-size: 12.8px; margin-bottom: 12px;
}
.kb-lock-tip button {
  border: 0; background: none; color: var(--text); font-weight: 600;
  cursor: pointer; text-decoration: underline; text-underline-offset: 3px; font-size: 12.8px;
}
