/* ==========================================================================
   Mia 控制台设计系统
   - 双主题：:root[data-theme="dark"|"light"] 使用同一组变量名
   - 品牌主色：青碧（teal / cyan）。选它的理由：聊天界面是长时间停留的地方，
     青绿系蓝绿在深色底上不刺眼、不抢正文，也没有明显性别倾向
   - 纯 CSS 变量 + 组件类，无构建步骤
   ========================================================================== */

/* 与主题无关的令牌：动效曲线、圆角、焦点环。
   放在这里而不是两套主题里各写一份 —— 它们描述的是"怎么动"，不是"什么颜色"。 */
/* ==========================================================================
   设计系统 v3 —— 按参考稿（秒哒那份 Miai 控制台重设计）重做令牌层
   --------------------------------------------------------------------------
   参考稿的变量名和我们不同（`--ink/--line/--wash` vs 我们的 `--text/--border/--soft`），
   但它是一整套自洽的系统。**这里保留我们的变量名、换掉它们的值** ——
   全项目 CSS 都是消费变量写的，所以换值就等于换皮，一行页面 JS 都不用动。

   它比我们多出来的几样，一并补上：
     --bg-glow   顶部一层品牌色径向光晕（我们的页面底色原来是一块纯色）
     --tnum      数字用 Sora，等宽对齐；统计数字不用等宽字体时列会跳
     --brand-2   第二品牌色（青绿），渐变从"同色相明暗"变成"青→薄荷"的色相过渡
   ========================================================================== */

:root {
  /* ---------- 与主题无关的令牌（沿用参考稿的刻度） ---------- */
  /* 参考稿只用三档：18 / 12 / 9。我们原来是 18/13/9/6 四档，
     6px 那一档全项目只用在两个地方，收掉即可 —— 刻度越少越不容易走样。 */
  --r-xs: 9px;  --r-sm: 12px;  --r: 12px;  --r-lg: 18px;  --r-full: 999px;

  --dur-fast: .12s;
  --dur: .2s;
  --dur-slow: .3s;
  --ease: cubic-bezier(.22, .61, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.32, .64, 1);
  --ring: 0 0 0 3px var(--brand-ring);
  --blur: saturate(140%) blur(14px);

  /* 数字字体：统计值、耗时、计数用它，等宽才不会随数字跳动而抖。
     不再引用 Sora（那需要外链 Google/飞书字体）；系统等宽字体栈离线可用。 */
  --tnum: ui-monospace, 'SFMono-Regular', Menlo, Consolas, 'Cascadia Mono', monospace;

  /* 自定义背景（见 miai/theme/）。默认"没有图"，几个值由 JS 写进来。 */
  --bg-image: none;
  --bg-opacity: .25;
  --bg-blur: 0px;
  --bg-dim: .4;
  --surface-alpha: 100%;
}

/* ---------- 深色（参考稿的主场：深蓝黑，不是纯黑） ---------- */
:root[data-theme="dark"] {
  --bg: #0a141b;
  /* 顶部一层极淡的品牌色光晕。纯色底会让整页显得"平"，一层 12% 的径向渐变
     足够把视线引到左上（内容起始的地方），又不会干扰读数。 */
  --bg-glow: radial-gradient(1200px 520px at 18% -10%, rgba(46, 178, 205, .12), transparent 60%);

  /* 表面**比背景亮一档**：深色主题下靠明度分层，不靠边框 */
  --surface: #0f1d24;
  --surface-2: #0c1a21;      /* 比 surface 更靠近背景：表头、凹陷区 */
  --surface-3: #13242c;      /* 比 surface 更亮：悬停底、代码块 */
  --surface-hover: #16303a;
  /* 侧栏/顶栏和卡片用同一个表面色 —— 参考稿里"外壳也是面板"，
     靠 --bg 那一层灰把它们和内容区分开 */
  --bg-elev: #0f1d24;

  --border: #1b2d36;
  --border-strong: #2a424e;

  --text: #e6eef1;
  --text-dim: #9cb4be;
  --text-mute: #5f7c88;

  /* 品牌：青 → 薄荷。两端色相差约 25°，比"同色相明暗"更有生气，
     而 --brand-text 固定深色 —— 这条渐变够亮，白字上去只有 1.9:1。 */
  --brand: #3cc6df;
  --brand-2: #2fd0a6;
  --brand-strong: #8ee0ee;
  --brand-soft: rgba(60, 198, 223, .12);
  --brand-glow: rgba(60, 198, 223, .3);
  --brand-ring: rgba(60, 198, 223, .3);
  --brand-grad: linear-gradient(135deg, #2fb6cf, #27c69c);
  --brand-text: #04222b;

  --ok: #31c48d;      --ok-soft: rgba(49, 196, 141, .14);
  --warn: #e3a444;    --warn-soft: rgba(227, 164, 68, .14);
  --danger: #ef6a6a;  --danger-soft: rgba(239, 106, 106, .14);
  --info: #6a9aff;    --info-soft: rgba(106, 154, 255, .14);

  /* 两层阴影照参考稿：近处收紧边缘，远处给体积。深色下不加高光会糊成一片。 */
  --shadow: 0 20px 50px rgba(0, 0, 0, .5);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 26px rgba(0, 0, 0, .35);
  --scroll: rgba(255, 255, 255, .13);
  --card-hi: inset 0 1px 0 rgba(255, 255, 255, .04);
  --card-lift: inset 0 1px 0 rgba(255, 255, 255, .05), 0 20px 50px rgba(0, 0, 0, .5);
}

/* ---------- 浅色（冷白底，同样带一层品牌光晕） ---------- */
:root[data-theme="light"] {
  --bg: #eef2f4;
  --bg-glow: radial-gradient(1200px 520px at 18% -10%, rgba(11, 114, 133, .10), transparent 60%);

  --surface: #ffffff;
  --surface-2: #f6fafb;
  --surface-3: #eef4f6;
  --surface-hover: #eaf2f4;
  --bg-elev: #ffffff;

  --border: #e1e9ed;
  --border-strong: #ccd9df;

  --text: #0c1d24;
  --text-dim: #34505c;
  --text-mute: #7d98a3;

  --brand: #0b7285;
  --brand-2: #0f9d8f;
  --brand-strong: #08566a;
  --brand-soft: rgba(11, 114, 133, .10);
  --brand-glow: rgba(11, 114, 133, .22);
  --brand-ring: rgba(11, 114, 133, .22);
  --brand-grad: linear-gradient(135deg, #0b7285, #0f9d8f);
  --brand-text: #ffffff;

  --ok: #0e9f6e;      --ok-soft: rgba(14, 159, 110, .12);
  --warn: #b7791f;    --warn-soft: rgba(183, 121, 31, .14);
  --danger: #d64545;  --danger-soft: rgba(214, 69, 69, .12);
  --info: #2563eb;    --info-soft: rgba(37, 99, 235, .12);

  --shadow: 0 20px 50px rgba(12, 29, 36, .14);
  --shadow-sm: 0 1px 2px rgba(12, 29, 36, .05), 0 10px 26px rgba(12, 29, 36, .06);
  --scroll: rgba(12, 29, 36, .2);
  /* 浅色下高光是白叠加，压在白卡片上看不出来 —— 改成一道更实的描边 */
  --card-hi: inset 0 0 0 1px rgba(255, 255, 255, .7);
  --card-lift: 0 1px 2px rgba(12, 29, 36, .07), 0 20px 50px rgba(12, 29, 36, .16);
}



* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  /* 顶部一层品牌色径向光晕（参考稿的 --bg-glow）。纯色底会让整页显得平，
     一层 10% 的渐变把视线引到左上内容起始处，又不会干扰读数。
     写成两层：底下的 var(--bg) 仍然兜底。 */
  background: var(--bg-glow, none), var(--bg);
  color: var(--text);
  /* 系统字体栈：不下载任何外部字体，离线/内网与首次加载都不受网络影响。
     中文优先交给各平台自带的黑体（PingFang / 微软雅黑 / Noto），
     西文交给 Segoe UI / SF。 */
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---------- 自定义背景（覆盖全局） ----------
   用一张固定在视口上的伪元素，而不是给每个容器设 background-image：
   容器方案要在几十个组件上各写一遍 `background-attachment: fixed`，还必然漏掉几个。
   伪元素在 `z-index: -1`，所有内容自然压在它上面。

   `transform: scale(1.06)` 是给模糊留的余量 —— 高斯模糊会把边缘往外糊，
   不放大就会在四周露出一圈透明。 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: var(--bg-opacity);
  filter: blur(var(--bg-blur));
  transform: scale(1.06);
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease), filter var(--dur-slow) var(--ease);
}

/* 压一层底色：光靠透明度压不住花哨的图，正文会读不清。
   它和 `--bg-opacity` 是一对反作用力 —— 一个让图更明显、一个让字更清楚，
   所以两个都留给用户调。 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--bg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease);
}
:root[data-bg="on"] body::after { opacity: var(--bg-dim); }

/* 有背景图时把各处的不透明底色放掉，让图透上来。
   只调这几个"大面"—— 气泡、表格行这些小块保持不透明，否则整页都在飘，很难读。 */
:root[data-bg="on"] {
  --surface-alpha: 82%;
  /* 兜底底色：body 变透明之后，画布取的是**根元素**的背景。不给 html 这一层，
     画布就回落到浏览器默认的白色 —— 深色主题下一整页刷白，`body::before` 的图
     也被压在白底上，"图的不透明度"滑块随之失去意义。 */
  background: var(--bg);
}
:root[data-bg="on"] body { background: transparent; }
:root[data-bg="on"] .topnav,
:root[data-bg="on"] .subside {
  background: color-mix(in srgb, var(--bg-elev) var(--surface-alpha), transparent);
  backdrop-filter: var(--blur);
}
:root[data-bg="on"] .card {
  background: color-mix(in srgb, var(--surface) var(--surface-alpha), transparent);
  backdrop-filter: var(--blur);
}
:root[data-bg="on"] .chat-main { background: transparent; }
:root[data-bg="on"] .chat-head,
:root[data-bg="on"] .chat-input {
  background: color-mix(in srgb, var(--bg-elev) 72%, transparent);
  backdrop-filter: var(--blur);
}
:root[data-bg="on"] .chat-side {
  background: color-mix(in srgb, var(--bg-elev) var(--surface-alpha), transparent);
  backdrop-filter: var(--blur);
}
/* 登录页自己有整块品牌面板，不需要背景图透上来，免得两层图形打架 */
:root[data-bg="on"] .auth-card { backdrop-filter: var(--blur); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); background-clip: content-box; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre, .mono {
  font-family: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
}

/* ---------- 布局：顶栏一级导航 + 二级左栏 ----------

   **为什么改成两级**：15 个页面平铺在一条左栏里，找一个页面只能从上往下扫；
   分成 5 个一级之后，每个一级下面只有 2-5 项，扫一眼就定位完了。
   这是参考稿（秒哒那份 Miai 重设计）的结构：

       .app
         header.topnav              品牌 + 一级入口 + 搜索 + 身份
         .shell
           aside.subside            当前一级下的二级条目
           main.main
             header.page-head       主标题 + 一句说明
             .content#view          页面内容（自己滚）

   页头做成 **静态**（不跟着内容滚），和参考稿不同 —— 参考稿的页头会滚上去，
   但我们的页头挂着 `#pageTitle`，`updateTitle()` 和命令面板都依赖它一直在。
   而且控制台页面本来就长，主标题常驻省得反复滚回顶部确认自己在哪一页。 */

/* 高度用 dvh 而不是 vh：手机上地址栏收起/展开会改可视高度，vh 取的是「最大可能高度」，
   底部输入框会被顶到屏幕外。--app-h 由 app.js 从 visualViewport 写入，兜住
   iOS Safari / 微信这类「软键盘只缩 visual viewport」的浏览器（见 installViewportHeight）。 */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  height: var(--app-h, 100dvh);
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */

.topnav {
  flex: 0 0 62px;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  z-index: 20;
}
/* 内容从顶栏下面滑过去时，磨砂让「这一条浮在上面」看得出来。
   `color-mix` 在旧 WebView（微信内置）上没有，所以放进 @supports ——
   不支持时退回不透明，只少一层通透感，不会白屏。 */
@supports (background: color-mix(in srgb, red 50%, transparent)) {
  .topnav {
    background: color-mix(in srgb, var(--bg-elev) 80%, transparent);
    backdrop-filter: blur(14px) saturate(150%);
  }
}

.tnav-brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  width: 36px; height: 36px; flex: 0 0 36px;
  display: grid; place-items: center;
  border-radius: 11px;
  font-size: 17px; font-weight: 700;
  color: var(--brand-text);
  background: var(--brand-grad);
  box-shadow: 0 3px 10px var(--brand-glow);
}
.brand-name { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name b { font-size: 18px; font-weight: 700; letter-spacing: .4px; }
.brand-name span { font-size: 11px; color: var(--text-mute); letter-spacing: 2px; }

.tnav-div { width: 1px; height: 26px; flex: 0 0 1px; background: var(--border); margin: 0 2px; }

/* 一级导航。活动项用**渐变底 + 白字**（参考稿的做法）——
   它比"文字变色"更能说明"你现在在哪一层"。 */
.tnav { display: flex; align-items: center; gap: 4px; flex: 0 1 auto; min-width: 0; }
.tnav-item {
  display: flex; align-items: center; gap: 8px;
  height: 38px; padding: 0 14px;
  border-radius: 11px;
  color: var(--text-dim);
  font-size: 14px; font-weight: 500;
  white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background .16s, color .16s, box-shadow .16s;
}
.tnav-item svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--text-mute); transition: color .16s; }
.tnav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.tnav-item:hover svg { color: var(--brand); }
/* 活动项：**渐变底 + 白字**（参考稿的做法）。这里值得用最重的一种表达 ——
   顶栏只有 5 项，但它们代表 5 个大区，用户最常犯的错就是"以为自己在别的区"。
   浅色高亮在这个尺寸上一眼扫不出来，整块填色才行。 */
.tnav-item.active {
  background: var(--brand-grad);
  color: var(--brand-text);
  box-shadow: 0 6px 16px var(--brand-glow);
  font-weight: 600;
}
.tnav-item.active svg { color: var(--brand-text); }

/* 顶栏右侧：搜索 + 身份 + 操作 */
.topnav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

/* 图标按钮（顶栏用）。比 .icon-btn 大一档：顶栏是"手容易点到"的地方。 */
.top-icon {
  width: 36px; height: 36px; flex: 0 0 36px;
  display: grid; place-items: center;
  border: none; border-radius: 10px;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.top-icon:hover { background: var(--surface-hover); color: var(--text); }
.top-icon svg { width: 19px; height: 19px; }

/* 身份卡。头像用 32px 圆角方块（不是圆形）—— 和 .brand-mark 同一套形状语言。 */
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 10px 4px 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  max-width: 200px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.user-chip:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.user-chip .who-txt { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-chip .who-name {
  font-size: 12.5px; font-weight: 600; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip .who-role { font-size: 10.5px; color: var(--text-mute); }

.who-avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: 9px; object-fit: cover;
  border: 1px solid var(--border);
}
.who-avatar.fallback {
  display: grid; place-items: center;
  font-size: 14px; font-weight: 700; color: var(--brand-text);
  background: var(--brand-grad);
  border-color: transparent;
}

.mobile-nav-btn { display: none; }

/* ---------- 二级左栏 ---------- */

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

.subside {
  width: 224px;
  flex: 0 0 224px;
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  overflow: hidden;
  /* 收起时收宽度（不是 display:none）—— 宽度过渡才有"抽屉滑回去"的感觉。
     `flex-basis` 要一起改，否则 flex 布局还按 224 分配空间，主区不会跟着变宽。 */
  transition: width var(--dur-slow) var(--ease), flex-basis var(--dur-slow) var(--ease);
}
.subside.collapsed { width: 0; flex-basis: 0; border-right: none; }

.subside-top { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; }
.st-ico {
  width: 32px; height: 32px; flex: 0 0 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  color: var(--brand);
  background: var(--brand-soft);
}
.st-ico svg { width: 17px; height: 17px; }
.st-name { font-size: 14px; font-weight: 600; line-height: 1.25; }
.st-sub { font-size: 11px; color: var(--text-mute); margin-top: 1px; }

.subside-nav { flex: 1; overflow-y: auto; padding: 0 12px 16px; }

/* 二级条目。**活动指示条放在条目外侧**（left:-12px 正好落在 .subside-nav
   的 12px 内边距上）—— 贴着文字那一侧会显得挤。 */
.ss-item {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin: 1px 0;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 13.5px;
  cursor: pointer; user-select: none;
  transition: background .15s, color .15s;
}
.ss-item svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--text-mute); transition: color .15s; }
.ss-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.ss-item:hover svg { color: var(--brand); }
.ss-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.ss-item.active svg { color: var(--brand); }
.ss-item.active::before {
  content: ""; position: absolute; left: -12px; top: 50%;
  width: 3px; height: 18px; margin-top: -9px;
  border-radius: 3px;
  background: var(--brand-grad);
}

.subside-foot {
  padding: 11px 18px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-mute);
}

/* ---------- 主区 ---------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* 页头：主标题 + 一句说明。 */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 0;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0;
  font-size: 22px; font-weight: 700;
  letter-spacing: .2px; line-height: 1.2;
}
/* 副标题：12.5px、--text-mute、贴主标题 2px。
   它占页面标题区一半的信息量 —— 光有大标题，用户还是不知道这页能干什么。 */
.page-head .page-sub {
  font-size: 12.5px; color: var(--text-mute);
  margin-top: 2px; line-height: 1.3;
}
.page-head .page-actions { display: flex; align-items: center; gap: 8px; }

/* `display:flex` 不是为了好看，是为了让 `.fill-col` 能用 —— 页面里需要"自己滚"的
   区域（日志、聊天）不能靠 `calc(100vh - 94px)` 那种算法：那个 94 是"顶栏 + 内边距"
   两个数相加，而卡片本身就挂在那圈内边距里，减出来会比可视区高 40px。
   改成 flex 之后，`flex:1; min-height:0` 由布局算，加不加内边距都对。
   普通页面挂进来的根 div 在列向 flex 里表现得和一个块级元素一样（撑满宽、高由内容定），
   所以这一条对它们没有视觉影响。

   注意 `padding-top: 0`：上边距由 .page-head 负责。若这里再给一份，
   无页头的整屏页面（聊天）顶部会多出一段空白。 */
.content { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 20px 32px; display: flex; flex-direction: column; }
.content.no-pad { padding: 0; overflow: hidden; }

/* 整屏页面（聊天）自己占满高度，页头让位 —— 它的标题区在页面内部已经有了，
   再挂一份只是白占 60px。用 `:has()` 是为了让这条规则**自己跟着**
   `#view.no-pad` 走，不用在 main.js 里再同步一个类（两份状态迟早对不上）。
   不支持 `:has()` 的浏览器只是页头多留一行，功能不受影响。 */
.main:has(#view.no-pad) .page-head { display: none; }

/* 15 个页面都靠这条动画进入。放在外壳里而不是各页里，
   是为了"切页有反馈"这件事只有一处实现。 */
.content > *:not(.chat-layout) { animation: pageIn var(--dur) var(--ease); }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .content > *, .subside { animation: none; transition: none; }
}

/* ---------- 移动端 ---------- */
/* 窄屏：一级导航收进抽屉，二级左栏不占位（页面本身在手机上就是全宽） */

@media (max-width: 900px) {
  .topnav { flex-basis: 58px; height: 58px; gap: 8px; padding: 0 12px; }
  .tnav, .tnav-div, .subside, .subside-toggle { display: none; }
  .mobile-nav-btn { display: grid; }
  .brand-name span { display: none; }
  .page-head { padding: 14px 12px 0; }
  .page-head h1 { font-size: 19px; }
  .content { padding: 12px 12px 28px; }
}

/* 顶栏在 900-1180px 之间比较挤：搜索框先收成图标。
   （900px 以下由上面的断点接手，那时整个 .tnav 都没了。） */
@media (max-width: 1180px) {
  .search-trigger { width: 42px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger .kbd { display: none; }
}

/* ---------- 抽屉（窄屏的一级+二级导航） ---------- */

.mnav {
  position: fixed; inset: 0 auto 0 0;
  z-index: 60;
  width: min(320px, 86vw);
  display: flex; flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform var(--dur-slow) var(--ease);
}
.mnav.open { transform: none; }
.mnav-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.mnav-body { flex: 1; overflow-y: auto; padding: 4px 12px 20px; }
.mnav-group {
  padding: 16px 8px 6px;
  font-size: 11px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-mute);
}
.mnav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; margin: 1px 0;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 13.5px;
  cursor: pointer; user-select: none;
}
.mnav-item svg { width: 18px; height: 18px; flex: 0 0 18px; color: var(--text-mute); }
.mnav-item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.mnav-item:hover svg { color: var(--brand); }
.mnav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 500; }
.mnav-item.active svg { color: var(--brand); }
.mnav-mask {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(10, 20, 27, .45);
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur) var(--ease);
}
.mnav-mask.open { opacity: 1; pointer-events: auto; }
@media (min-width: 901px) { .mnav, .mnav-mask { display: none; } }


/* ---------- 卡片 ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--card-hi), var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
/* 网格里由 `gap` 负责间距，这条上边距必须让位。不让的话，除第一张外的卡片都会被
   顶下去 16px，而网格行高是统一的 —— 于是它们看起来比第一张矮一截
   （实测 148.77px vs 132.77px，表现为"版本框大小和其他不一致"）。
   特异性 3 个类 > 上面的 2 个类，能盖住它。 */
/* 相邻卡片的外边距在**网格里**是有害的：网格项被拉伸到行高后，`margin-top`
   会把它压矮那么多、并整体下移 —— 表现是"第一张比别的高一截"。
   这条原来只覆盖 `.grid`，新增的 `.stat-grid` / `.quick-grid` 都漏了。 */
:is(.grid, .grid-2) > .card + .card { margin-top: 0; }
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card-head .sub { font-size: 12px; color: var(--text-mute); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 10px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* 指标卡样式见下方 `.card.stat` 一节；这里只留进度条本体 */
.meter { height: 6px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--brand-strong), var(--brand)); transition: width .4s; }

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px;
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s, transform .08s;
}
/* 悬停底色必须排除 .primary / .danger。
   本规则的特异性是 5 个类，而 `.btn.primary` 只有 2 个 —— 不排除的话，
   鼠标一移到主按钮上，渐变背景就被换成浅色底，而 color 仍是白色，
   按钮直接"消失"（白字白底）。danger 同理。 */
.btn:not(.primary):not(.danger):hover:not(:disabled) {
  background: var(--surface-hover); border-color: var(--border-strong);
}
.btn:hover:not(:disabled) { text-decoration: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand-grad); color: var(--brand-text); border-color: transparent; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: var(--danger-soft); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- 表单 ---------- */

.field { margin-bottom: 14px; }
.field > label { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--text-dim); }
.field .hint { margin-top: 4px; font-size: 11.5px; color: var(--text-mute); }
.field .err { margin-top: 4px; font-size: 12px; color: var(--danger); }

input[type=text], input[type=password], input[type=number], input[type=email],
select, textarea {
  width: 100%;
  padding: 8px 11px;
  font-family: inherit; font-size: 13.5px; color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
input::placeholder, textarea::placeholder { color: var(--text-mute); }
input:disabled, select:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
textarea { resize: vertical; min-height: 90px; line-height: 1.55; }
textarea.code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; min-height: 320px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: auto; }

.switch { position: relative; display: inline-block; width: 38px; height: 21px; flex: 0 0 38px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--surface-hover); border: 1px solid var(--border);
  border-radius: 999px; transition: background .2s;
}
.switch .track::before {
  content: ""; position: absolute; left: 2px; top: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--text-mute); transition: transform .2s, background .2s;
}
.switch input:checked + .track { background: var(--brand-soft); border-color: var(--brand); }
.switch input:checked + .track::before { transform: translateX(17px); background: var(--brand); }
.switch input:disabled + .track { opacity: .5; cursor: not-allowed; }

/* ---------- 表格 ---------- */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: 11.5px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-mute); white-space: nowrap; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.actions { text-align: right; white-space: nowrap; }
table.data td.actions .btn { margin-left: 4px; }
table.data td.wrap { white-space: normal; word-break: break-word; max-width: 380px; }

/* ---------- 徽标 ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-hover); color: var(--text-dim);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: 0 0 7px; }

.tag {
  display: inline-block; padding: 1px 7px; margin: 2px 3px 2px 0;
  border-radius: 6px; font-size: 11.5px;
  background: var(--surface-hover); color: var(--text-dim);
}

/* ---------- 杂项 ---------- */

.empty {
  padding: 44px 20px; text-align: center; color: var(--text-mute);
}


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

.loading-row { display: flex; align-items: center; gap: 9px; padding: 26px; justify-content: center; color: var(--text-mute); }

.divider { height: 1px; background: var(--border); margin: 14px 0; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 160px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.muted { color: var(--text-mute); }
.dim { color: var(--text-dim); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.right { text-align: right; }
.mt0 { margin-top: 0; } .mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb0 { margin-bottom: 0; }

pre.code-block {
  margin: 0; padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-x: auto; line-height: 1.5;
  color: var(--text-dim);
}

/* ---------- 标签页 ---------- */

/* 页签统一到 `.tabbar` 的视觉（旧页面用 .tabs/.tab，新列表页用 tabs() 的 .tabbar）。
   两套 DOM 保留，但下划线、hover、选中色只有一份定义。 */
.tabs {
  display: flex; align-items: center; gap: var(--sp-1);
  padding: 0 var(--sp-4); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center;
  padding: 10px 10px 11px; margin: 0;
  font-size: 13px; color: var(--text-dim);
  border: 0; border-bottom: 2px solid transparent;
  background: none; cursor: pointer; user-select: none;
}
.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab.active { color: var(--brand); border-bottom-color: transparent; font-weight: 600; }
.tab.active::after {
  content: ""; position: absolute; left: 6px; right: 6px; bottom: -1px;
  height: 2px; background: var(--brand); border-radius: 2px 2px 0 0;
}

/* ---------- 弹层 ---------- */

.modal-mask {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(10, 8, 14, .55);
  backdrop-filter: blur(3px);
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }

.modal {
  width: 100%; max-width: 560px; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  box-shadow: var(--shadow);
  animation: pop .18s cubic-bezier(.2, .9, .3, 1.3);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; padding: 16px 18px 10px; }
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-head .spacer { flex: 1; }
.modal-body { padding: 6px 18px 4px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px 16px; }
.icon-btn {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: none; border-radius: 8px; background: transparent;
  color: var(--text-mute); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 120; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.toast {
  min-width: 240px; max-width: 420px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--brand);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: slide .2s ease;
}
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

/* ---------- 登录页 ---------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  /* 登录页是**唯一**可以铺大面积品牌色的地方（控制台里其它地方都得克制，
     否则长时间看会累）。两层径向渐变 + 一层点阵网格，全部 CSS 生成：
     不引图片，离线/内网照样是完整的。 */
  background:
    radial-gradient(820px 480px at 8% 2%, var(--brand-glow), transparent 62%),
    radial-gradient(680px 440px at 96% 98%, var(--brand-glow), transparent 60%),
    var(--bg);
  position: relative;
  overflow: hidden;
}
/* 点阵网格：给纯色底一点"材质"。四周用遮罩淡出，免得在边缘切出一条硬线。 */
.auth-wrap::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(currentColor 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--border-strong);
  opacity: .55;
  -webkit-mask-image: radial-gradient(72% 62% at 50% 42%, #000 10%, transparent 80%);
  mask-image: radial-gradient(72% 62% at 50% 42%, #000 10%, transparent 80%);
}
.auth-split { position: relative; z-index: 1; }
.auth-card {
  width: 100%; max-width: 400px;
  padding: 34px 30px 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.auth-card .logo {
  width: 50px; height: 50px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 15px; font-size: 24px; color: var(--brand-text);
  background: var(--brand-grad);
}
.auth-card h1 { margin: 0 0 6px; font-size: 20px; text-align: center; }
.auth-card .sub { margin: 0 0 22px; font-size: 13px; color: var(--text-mute); text-align: center; }

/* 左右分栏：左侧品牌区 + 右侧表单。窄屏时品牌区收起，退回单卡片。 */
.auth-split {
  width: 100%; max-width: 940px;
  display: grid; grid-template-columns: 1.05fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-brand {
  position: relative;
  padding: 44px 40px;
  /* 用调色板自己的渐变。原先这里**写死**了青碧色（`linear-gradient(155deg,#0e7490,#0b4a5c)`），
     结果是：用户在设置里换成樱花、抹茶、柠檬，登录页毫无变化 —— 而登录页恰恰是
     唯一有大面积品牌色的地方，也是看到的第一屏。 */
  background: var(--brand-grad);
  /* 文字固定白色，**不跟 --brand-text** —— 因为下面压了一层黑（见 ::before），
     底色一定是深的。--brand-text 在深色主题下是深色，压黑之后会彻底看不清。 */
  color: #fff;
}
/* 压暗一层。调色板的渐变是给**按钮**那种小面积调的，原样铺满一屏（登录页左半屏
   600×400）会变成一整块高饱和色，在深色控制台里非常吵。
   压的是黑而不是 --bg：--bg 在浅色主题下是接近白的，压完白字就没对比度了。 */
.auth-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .38);
  pointer-events: none;
}
.auth-brand::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(420px 260px at 85% 15%, rgba(255,255,255,.14), transparent 70%);
  pointer-events: none;
}
.auth-brand > * { position: relative; z-index: 1; }
.auth-brand .logo {
  width: 46px; height: 46px; margin: 0 0 20px;
  display: grid; place-items: center;
  border-radius: 14px; font-size: 22px; font-weight: 700;
  background: rgba(255,255,255,.18);
  border: 1px solid rgba(255,255,255,.28);
}
.auth-brand h1 { margin: 0 0 10px; font-size: 24px; }
.auth-brand p { margin: 0 0 22px; font-size: 13.5px; line-height: 1.7; opacity: .9; }
.auth-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.auth-points li {
  position: relative; padding-left: 22px;
  font-size: 13px; opacity: .95;
}
.auth-points li::before {
  content: "✓"; position: absolute; left: 0; top: 0;
  font-size: 12px; opacity: .85;
}
.auth-panel { display: grid; place-items: center; padding: 34px 30px; }
.auth-panel .auth-card {
  width: 100%; max-width: 380px;
  padding: 0; border: 0; border-radius: 0; box-shadow: none; background: transparent;
}
.auth-panel .auth-card .logo { display: none; }

.auth-title { margin: 0 0 6px; font-size: 20px; text-align: center; }
.auth-alt {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 13px;
}
.auth-alt a { color: var(--brand); text-decoration: none; font-weight: 600; }
.auth-alt a:hover { text-decoration: underline; }
.auth-done { text-align: center; padding: 12px 0; }
.auth-done .big {
  width: 54px; height: 54px; margin: 0 auto 14px;
  display: grid; place-items: center;
  border-radius: 50%; font-size: 26px; color: var(--brand-text);
  background: var(--brand-grad);
}
.auth-done h2 { margin: 0 0 8px; font-size: 18px; }
.auth-done p { margin: 0 0 20px; }
.field.ok > div, .field.ok { color: var(--ok, #2f855a); font-size: 12.5px; }

/* 窄屏：分栏塌成上下两段，品牌区收成一条窄头图（保留 logo，砍掉卖点列表） */
@media (max-width: 760px) {
  .auth-split { grid-template-columns: 1fr; max-width: 420px; }
  .auth-brand { padding: 24px 26px; }
  .auth-brand .logo { margin-bottom: 12px; }
  .auth-brand h1 { font-size: 19px; margin-bottom: 6px; }
  .auth-brand p { margin: 0; font-size: 12.5px; }
  .auth-points { display: none; }
  .auth-panel { padding: 24px 22px 28px; }
}

/* ---------- 日志 / 追踪 ---------- */

.log-list { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12.5px; line-height: 1.65; }
.log-line { display: flex; gap: 10px; padding: 3px 18px; border-bottom: 1px solid var(--border); }
.log-line:hover { background: var(--surface-2); }
.log-line .t { color: var(--text-mute); flex: 0 0 76px; }
.log-line .lv { flex: 0 0 62px; font-weight: 600; }
.log-line .tag { flex: 0 0 120px; color: var(--brand); background: none; padding: 0; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-line .msg { flex: 1; white-space: pre-wrap; word-break: break-word; color: var(--text-dim); }
.lv-DEBUG { color: var(--text-mute); }
.lv-INFO { color: var(--info); }
.lv-SUCCESS { color: var(--ok); }
.lv-WARNING { color: var(--warn); }
.lv-ERROR, .lv-CRITICAL { color: var(--danger); }

/* ---------- 聊天 ---------- */

.chat-layout { display: flex; height: 100%; min-height: 0; }
.chat-side {
  width: 232px; flex: 0 0 232px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
}
.chat-side .side-head { padding: 12px; border-bottom: 1px solid var(--border); }
.chat-sessions { flex: 1; overflow-y: auto; padding: 8px; }
.sess {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; margin-bottom: 3px;
  border-radius: 9px; cursor: pointer; font-size: 13px;
  color: var(--text-dim);
}
.sess:hover { background: var(--surface-hover); }
.sess.active { background: var(--brand-soft); color: var(--text); font-weight: 600; }
.sess .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess .del { opacity: 0; font-size: 14px; color: var(--text-mute); }
.sess:hover .del { opacity: 1; }
.sess .del:hover { color: var(--danger); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
}
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px 20px; }
.msg { display: flex; margin-bottom: 14px; }
.msg.user { justify-content: flex-end; }
/* 机器人消息有两块内容（身份头 + 气泡）。默认的 flex row 会把它们并排放，
   气泡被挤成"每行两个字"。必须改成纵向堆叠。 */
.msg.bot { flex-direction: column; align-items: flex-start; }
.msg.bot > div:last-child { max-width: 100%; }
/* 宽度上限挂在 .msg 的**直接子元素**上，而不是 .bubble 上。
   .msg 的宽度是确定的（整行），百分比能正常解析；而 .bubble 的包裹层
   （那个 position:relative 的 div，用来放「复制」按钮）是按内容收缩的，
   百分比参照它就成了循环依赖 —— 浏览器只能按百分比把气泡压扁，
   表现就是中文每行只放得下两个字。 */
.msg > div { max-width: min(660px, 78%); }
.bubble {
  max-width: 100%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px; line-height: 1.65;
  word-break: break-word;
  background: var(--surface);
  border: 1px solid var(--border);
}
.msg.user .bubble { background: var(--brand-grad); color: var(--brand-text); border-color: transparent; }

/* 表情图：贴在文字里时跟行高走，别把行撑开；不加边框 —— 它是"贴纸"不是内容图。
   单独发一条时气泡里只有它，`display:block` 之下会自然居中偏左，看着像一张贴纸。 */
.emoji-img {
  width: 88px; height: 88px;
  object-fit: contain;
  vertical-align: middle;
  border: 0;
  border-radius: 6px;
}
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  margin: 8px 0; padding: 10px 12px;
  background: var(--bg); border-radius: 9px; overflow-x: auto;
  border: 1px solid var(--border);
}
.msg.user .bubble pre { background: color-mix(in srgb, currentColor 14%, transparent); border-color: transparent; }
.bubble code { background: var(--surface-hover); padding: 1px 5px; border-radius: 5px; }
.bubble pre code { background: none; padding: 0; }
/* 复制按钮：绝对定位在气泡内侧右上角，悬停消息时浮现（JS 里它是 .bubble 的兄弟节点） */
.msg > div[style*="position:relative"] { position: relative; }
.msg .copy {
  position: absolute; top: 5px; right: 9px; z-index: 2;
  padding: 1px 6px; border-radius: 6px;
  font-size: 11px; cursor: pointer; color: var(--text-mute);
  background: var(--surface-hover);
  opacity: 0; transition: opacity .15s;
}
.msg.bot:hover .copy { opacity: 1; }
.msg .copy:hover { color: var(--brand); }

/* ---- 消息级操作（FR-CH-04）：复制/引用/编辑/重新生成/删除 ---- */
.msg { position: relative; }
.msg .acts {
  display: flex; gap: 2px; margin-top: 4px;
  opacity: 0; transition: opacity .15s;
}
.msg.user .acts { justify-content: flex-end; }
.msg:not(.user) .acts { justify-content: flex-start; }
.msg:hover .acts, .msg .acts:focus-within { opacity: 1; }
/* 操作条里的按钮改成静态排布 —— 上面那条 .msg .copy 是绝对定位的单按钮老样式 */
.msg .acts .copy { position: static; top: auto; right: auto; opacity: 1; }
.msg .acts .copy.danger:hover { color: var(--danger); }
/* 触屏没有 hover：常驻显示，否则手机上永远点不到 */
@media (hover: none) {
  .msg .acts { opacity: 1; }
}

/* 引用块与"已编辑"标记 */
.bubble .quote {
  display: flex; gap: 6px; align-items: baseline;
  padding: 5px 9px; margin-bottom: 7px;
  border-left: 3px solid var(--brand); border-radius: 4px;
  background: var(--surface-hover); font-size: 12px; cursor: pointer;
}
/* 引用条用 currentColor 的透明度：气泡文字在深色主题里是深色、浅色主题里是白色，
   写死白色会在其中一套主题里消失 */
.msg.user .bubble .quote { background: color-mix(in srgb, currentColor 12%, transparent); border-left-color: color-mix(in srgb, currentColor 55%, transparent); }
.bubble .quote-who { color: var(--text-mute); flex: 0 0 auto; }
.msg.user .bubble .quote-who, .msg.user .bubble .quote-txt { color: color-mix(in srgb, currentColor 82%, transparent); }
.bubble .quote-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bubble .edited { font-size: 11px; color: var(--text-mute); margin-left: 6px; }
.msg.user .bubble .edited { color: color-mix(in srgb, currentColor 72%, transparent); }

/* 跳转到被引用的消息时闪一下，否则用户不知道跳到哪了 */
.msg.flash .bubble { box-shadow: 0 0 0 2px var(--brand); transition: box-shadow .2s; }

/* 引用栏（输入框上方） */
.reply-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; margin-bottom: 8px;
  border-left: 3px solid var(--brand); border-radius: 6px;
  background: var(--surface-hover); font-size: 12px;
}
.reply-bar .reply-body { flex: 1; min-width: 0; display: flex; gap: 6px; align-items: baseline; }
.reply-bar .reply-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* @ 工作流提示 */
.mention-menu {
  max-height: 220px; overflow-y: auto; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
}
.mention-item { padding: 7px 11px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.mention-item:hover { background: var(--surface-hover); }

/* 工作流调用状态条（FR-CH-15） */
.wf-status {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 10px; margin-bottom: 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-hover); font-size: 12px;
}
/* 本轮用到的 Skill（FR-CH-09） */
.skill-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: -6px 0 12px; }

/* 会话重命名/归档（FR-CH-02） */
.sess .del { opacity: .55; }
.sess.archived { opacity: .6; }
.sess.archived .txt { text-decoration: line-through; }
.sess-archived-toggle {
  padding: 8px 10px; font-size: 12px; color: var(--text-mute);
  cursor: pointer; border-top: 1px solid var(--border);
}
.sess-archived-toggle:hover { color: var(--brand); }

.caret { display: inline-block; width: 7px; height: 14px; background: var(--brand); vertical-align: -2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* 「正在思考」：等待首个 token 期间的状态，避免只看到一个空气泡 */
.thinking { color: var(--text-mute); font-size: 13px; display: inline-flex; align-items: center; gap: 3px; }
.thinking i {
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor; display: inline-block;
  animation: think-bounce 1.2s infinite ease-in-out;
}
.thinking i:nth-child(2) { animation-delay: .15s; }
.thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes think-bounce { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ---------- 工作流画布 ---------- */

.canvas-wrap { display: flex; height: calc(100vh - 150px); min-height: 520px; }
.canvas-palette {
  width: 240px; flex: 0 0 240px; padding: 12px; overflow-y: auto;
  border-right: 1px solid var(--border); background: var(--bg-elev);
}
.canvas-panel {
  width: 290px; flex: 0 0 290px; padding: 12px; overflow-y: auto;
  border-left: 1px solid var(--border); background: var(--bg-elev);
}
.pal-group { margin: 10px 0 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-mute); }
.pal-item {
  padding: 6px 9px; margin-bottom: 3px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; font-size: 12.5px;
}
.pal-item:hover { background: var(--surface-hover); border-color: var(--border); }
.pal-list { max-height: none; }

.canvas-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.canvas-toolbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--bg-elev);
}
.canvas-toolbar .spacer { flex: 1; }

.canvas-viewport {
  position: relative; flex: 1; overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(var(--border-strong) 1px, transparent 1px);
  background-size: 22px 22px;
  cursor: grab;
}
.canvas-viewport:active { cursor: grabbing; }

.canvas-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.canvas-wires { position: absolute; left: 0; top: 0; overflow: visible; width: 1px; height: 1px; pointer-events: none; }
.wire { fill: none; stroke: var(--brand); stroke-width: 2; pointer-events: stroke; cursor: pointer; }
.wire:hover { stroke: var(--danger); stroke-width: 3; }
.wire-temp { fill: none; stroke: var(--brand); stroke-width: 2; stroke-dasharray: 5 4; }
.wire-temp.bad { stroke: var(--danger); }

.wf-node {
  position: absolute; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
  box-shadow: var(--shadow-sm); user-select: none; font-size: 12px;
}
.wf-node.sel { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft), var(--shadow-sm); }
.wf-node .hd {
  padding: 7px 9px; border-bottom: 1px solid var(--border);
  border-radius: 9px 9px 0 0; cursor: move;
  background: linear-gradient(180deg, var(--surface-2), transparent);
}
.wf-node .hd .nm { font-weight: 600; font-size: 12.5px; }
.wf-node .hd .tp { color: var(--text-mute); font-size: 11px; }
.wf-node .bd { padding: 4px 0; }
.wf-node .ports { display: flex; align-items: flex-start; }
.wf-node .side { flex: 1; min-width: 0; }
.wf-node .mid { width: 6px; }
.wf-node .prow { height: 22px; display: flex; align-items: center; }

.port { display: flex; align-items: center; gap: 5px; height: 22px; cursor: crosshair; max-width: 100%; }
.port.in { padding-left: 4px; }
.port.out { padding-right: 4px; flex-direction: row-reverse; }
.port .dot {
  width: 9px; height: 9px; border-radius: 50%; flex: 0 0 9px;
  background: var(--surface-2); border: 2px solid var(--brand);
}
.port.out .dot { background: var(--brand); }
.port:hover .dot { transform: scale(1.25); }
.port .plabel { font-size: 11px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1100px) {
  .canvas-wrap { flex-direction: column; height: auto; }
  .canvas-palette { width: auto; flex: none; max-height: 180px; border-right: none; border-bottom: 1px solid var(--border); }
  .canvas-panel { width: auto; flex: none; max-height: 260px; border-left: none; border-top: 1px solid var(--border); }
  .canvas-viewport { height: 460px; flex: none; }
}

/* 历史恢复时的骨架，避免内容跳动 */
.msg-skeleton { display: flex; margin-bottom: 14px; }
.msg-skeleton .bar {
  height: 42px; border-radius: 14px; background: var(--surface-2);
  animation: sk-pulse 1.4s ease-in-out infinite;
}
@keyframes sk-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }

/* 附件相关 */
.attach-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 0 8px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); font-size: 12px; max-width: 240px;
}
.attach-chip img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.attach-chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .rm { cursor: pointer; color: var(--text-mute); }
.attach-chip .rm:hover { color: var(--danger); }
.attach-chip.uploading { opacity: .6; }
.chat-drop-active { outline: 2px dashed var(--brand); outline-offset: -6px; }
.bubble .attach-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.bubble .attach-thumbs img { max-width: 180px; max-height: 180px; border-radius: 8px; cursor: zoom-in; display: block; }


/* ---------- 响应式 ---------- */

/* 会话列表的「抽屉」按钮：宽屏不显示，窄屏才出现（见下） */
.chat-head .side-toggle { display: none; }
/* 窄屏抽屉遮罩：定位放在基础规则里，只由媒体查询切换可见性 */
.chat-backdrop {
  display: none;
  position: absolute; inset: 0; z-index: 25;
  background: rgba(0, 0, 0, .35);
}

@media (max-width: 900px) {
  /* 只收窄，绝不占满 —— 之前写成 flex-basis:100% 会把聊天主区压成 0 宽，
     中文于是逐字换行（用户看到的「单字竖排」）。 */
  .chat-side { width: 180px; flex-basis: 180px; }
}

@media (max-width: 640px) {
  /* 更窄时把会话列表改成浮层抽屉，主区独占整宽 */
  .chat-layout { position: relative; }
  .chat-side {
    position: absolute; left: 0; top: 0; bottom: 0; z-index: 30;
    width: 250px; flex-basis: 250px;
    transform: translateX(-101%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .chat-layout.show-side .chat-side { transform: translateX(0); }
  .chat-layout.show-side .chat-backdrop { display: block; }
  .chat-head .side-toggle { display: inline-flex; }
}

/* ==========================================================================
   多用户界面：身份、用户管理、只读聊天、细节打磨
   ========================================================================== */

/* ---------- 顶栏身份 ---------- */

/* 头像的尺寸/圆角由外壳的 `.who-avatar` 统一（32px 圆角方块）。
   这里只留一条：设置页把它当普通头像用时，不该被 flex 压扁。 */

/* ---------- 小头像（用户列表 / 详情） ---------- */

.mini-avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%; object-fit: cover;
  border: 1px solid var(--border);
}
.mini-avatar.fallback {
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--brand-text);
  background: var(--brand-grad);
  border-color: transparent;
}
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell-txt { display: flex; align-items: center; gap: 6px; min-width: 0; }

/* ---------- 详情页小件 ---------- */

.sec-title {
  margin: 0 0 12px; font-size: 12px; font-weight: 700;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-mute);
}
.kv {
  display: flex; gap: 12px; padding: 7px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.kv:last-child { border-bottom: 0; }
.kv .k { flex: 0 0 96px; color: var(--text-mute); }
.kv .v { color: var(--text); word-break: break-all; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; }

/* ---------- 只读聊天记录（管理员查看用户会话） ---------- */

.readonly-chat { display: flex; flex-direction: column; gap: 12px; padding: 4px; }
.ro-msg { display: flex; flex-direction: column; gap: 4px; max-width: 78%; }
.ro-msg.user { align-self: flex-end; align-items: flex-end; }
.ro-msg.bot { align-self: flex-start; }
.ro-role { font-size: 11px; color: var(--text-mute); }
.ro-bubble {
  padding: 9px 13px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 13px; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.ro-msg.user .ro-bubble {
  background: var(--brand-grad);
  color: var(--brand-text); border-color: transparent;
}
.ro-text { white-space: pre-wrap; }

/* ---------- 细节打磨 ---------- */

/* 卡片：hover 时轻微抬升，提示"可点/可交互" */
.card { transition: box-shadow .18s ease, transform .18s ease; }
.stat { transition: transform .18s ease, border-color .18s ease; }
.stat:hover { transform: translateY(-2px); border-color: var(--border-strong); }

/* 表格：斑马纹 + 行悬停 + 粘性表头 */
table.data thead th { position: sticky; top: 0; z-index: 1; background: var(--surface-2); }
/* 斑马纹已去掉：现代表格靠行高 + 悬停高亮 + 分隔线区分，交替底色只会显脏 */
table.data tbody tr:hover { background: var(--surface-hover); }

/* 表单：统一焦点环，键盘可达 */
input, select, textarea { transition: border-color .15s, box-shadow .15s; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
/* 链接与按钮的键盘焦点 */
a:focus-visible, .btn:focus-visible, .ss-item:focus-visible,
.tnav-item:focus-visible, .mnav-item:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px;
}

/* 空状态加一点存在感 */
.empty { padding: 40px 20px; text-align: center; color: var(--text-mute); }

/* 空状态插画（app.js 的 emptyArt 生成，颜色在这里给） */
.empty-art { display: block; margin: 0 auto 12px; }
.empty-art .ea-halo { fill: var(--brand-soft); }
.empty-art .ea-back { fill: var(--surface-2); stroke: var(--border); stroke-width: 1.4; }
.empty-art .ea-front { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.6; }
.empty-art .ea-line { stroke: var(--brand); stroke-width: 2.4; stroke-linecap: round; }
.empty > div:first-of-type { color: var(--text-dim); font-size: 13.5px; }


/* 分区标题与列表项入场（克制：一次 160ms） */
@keyframes fadeUp { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg, .ro-msg, .sess { animation: fadeUp .16s ease both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 900px) {
  .user-chip .who-txt { display: none; }
  .user-chip { padding: 3px; border-color: transparent; background: transparent; }
}

/* ---------- 聊天：助手身份与消息头 ---------- */

.msg-head {
  display: flex; align-items: center; gap: 7px;
  margin-bottom: 5px; padding-left: 2px;
}
.msg-head .mini-avatar { width: 22px; height: 22px; flex: 0 0 22px; font-size: 11px; }
.msg-name { font-size: 12px; color: var(--text-mute); font-weight: 500; }

/* 只读字段要有明确的视觉区分，否则用户会一直点它想改 */
input:disabled, input[readonly], textarea[readonly] {
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: not-allowed;
}
textarea[readonly] { opacity: .92; }
.sess .badge { flex: 0 0 auto; }

/* ---------- 角色共享对话框 ---------- */

.share-list {
  max-height: 240px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 6px;
}
.share-user {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border-radius: 8px;
  font-size: 13px; cursor: pointer;
}
.share-user:hover { background: var(--surface-hover); }
.share-user.granted { cursor: default; opacity: .85; }
.share-user .share-name { font-weight: 500; }
.share-user .spacer { flex: 1; }
.share-user input[type="checkbox"] { flex: 0 0 auto; }

/* ==========================================================================
   聊天界面打磨
   ========================================================================== */

/* ---------- 顶部工具条 ---------- */

.chat-head {
  background: var(--bg-elev);
  gap: 8px;
  min-height: 52px;
}
.chat-head .chat-title {
  font-weight: 600; font-size: 14px;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* 选择器统一收敛成"胶囊"样式，别让原生下拉那么抢眼 */
.chat-head select {
  height: 30px; padding: 0 8px;
  font-size: 12.5px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.chat-head select:focus-visible { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }

/* ---------- 消息区 ---------- */

.msg { margin-bottom: 16px; }
.bubble { border-radius: 16px; box-shadow: var(--shadow-sm); }
.msg.bot .bubble { background: var(--surface); }
/* 用户气泡右下角收一点，形成"从右边发出"的指向感 */
.msg.user .bubble { border-bottom-right-radius: 5px; box-shadow: none; }
.msg.bot .bubble { border-bottom-left-radius: 5px; }
.msg-head { margin-bottom: 6px; }
.msg-name { font-weight: 500; }

/* 时间戳（JS 可选注入），弱化显示 */
.msg-time { font-size: 10.5px; color: var(--text-mute); margin-left: 6px; }

/* ---------- 输入区 ---------- */

.chat-input {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.chat-input textarea {
  min-height: 40px; max-height: 180px;
  padding: 10px 13px;
  border-radius: 12px;
  line-height: 1.55;
  resize: none;
}

/* 附件按钮做成方块，和发送按钮对齐 */
.chat-input .attach-btn {
  width: 40px; height: 40px; flex: 0 0 40px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; padding: 0;
}

/* ---------- 会话列表 ---------- */

.chat-sessions { padding: 10px; }
.sess {
  padding: 9px 11px; margin-bottom: 4px;
  border-radius: 10px;
  transition: background .15s, color .15s;
}
.sess.active {
  background: var(--brand-soft);
  box-shadow: inset 2px 0 0 var(--brand);
}

/* ---------- 只读/二次确认 ---------- */

.chat-backdrop { backdrop-filter: blur(1px); }

/* ---------- 可搜索下拉（app.js 的 searchSelect） ---------- */

.combo { position: relative; }
.combo > input { width: 100%; }
.combo.disabled > input { opacity: .6; cursor: not-allowed; }
.combo-panel {
  display: none;
  position: absolute; z-index: 40; top: calc(100% + 4px); left: 0;
  min-width: 100%; max-height: 280px; overflow-y: auto;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.combo.open .combo-panel { display: block; }
.combo-group {
  padding: 7px 8px 3px;
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--text-mute);
}
.combo-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 7px;
  font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.combo-item.active { background: var(--surface-hover); }
.combo-item.selected { color: var(--brand); font-weight: 600; }
.combo-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.combo-hint { flex: 0 0 auto; }
.combo-empty { padding: 8px; }
.badge.cap { padding: 0 5px; font-size: 11px; }

/* ==========================================================================
   移动端 / 触摸适配
   - 断点沿用既有约定：760 = 分栏塌陷（同 .auth-split），640 = 手机（同聊天抽屉）
   - 触摸能力用 @media (hover: none) 判定，不按宽度猜设备
   - 一条硬规矩：凡是要在断点下改变的值，都必须来自类，不能留在行内 style ——
     媒体查询命中不了行内 style（唯一的例外是 flex-basis 能盖掉行内 width）
   ========================================================================== */

/* ---------- 视口高度与基础 ---------- */

html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }

/* 复制按钮的定位基准。原来是 `.msg > div[style*="position:relative"]` 这种依赖 JS
   行内字符串的属性选择器，改个行内写法就静默失效，换成显式类名。 */
.msg-body { position: relative; }

/* 模型/角色选择器：宽屏是一组紧凑的胶囊，窄屏整组换行（见下面的 640 媒体查询）。
   min-width:0 不能省：`.chat-pickers` 在窄屏是 flex-basis:100% 的弹性项，它的
   `min-width:auto` 会解析成内容最小宽度（实测 398px，比 390 的视口还宽）→ 横向溢出。 */
.chat-pickers { display: flex; align-items: center; gap: 8px; min-width: 0; }

/* 桌面宽度。这两个值原来写在 chat.js 的行内 style 上（170/180px），
   而行内值同样会参与上面的 min-content 计算，所以一并收编到这里。
   注：原本那个 180px 一直被 `.chat-head select{max-width:170px}` 压成 170，此处照实写 170。 */

/* ---------- 角色页左右分栏 ---------- */
/* 这几个值原来写在 roles.js 的行内 style 上，媒体查询打不到，收编成类 */
.roles-split { display: flex; gap: 16px; align-items: flex-start; }
.roles-list { width: 260px; flex: 0 0 260px; max-height: 60vh; overflow-y: auto; }
.roles-editor { flex: 1; min-width: 0; }
.roles-editor textarea.code { min-height: 380px; }
.roles-back { display: none; }

@media (max-width: 760px) {
  /* 复制按钮：从「浮在气泡右上角、压住第一行正文」改成「气泡下方右对齐」 */
  .msg .copy {
    position: static; display: block; width: fit-content;
    margin: 4px 0 0 auto; padding: 2px 0; background: transparent;
  }

  /* 标题栏按钮多时换行，别被 nowrap 的按钮/徽标撑破 */
  .card-head { flex-wrap: wrap; row-gap: 8px; }

  /* 弹窗按可视高度居中：软键盘弹起时底部按钮不会被盖住 */
  .modal-mask { bottom: auto; height: var(--app-h, 100vh); }
  .toast-wrap { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); align-items: stretch; }
  .toast { min-width: 0; max-width: none; }

  /* 角色页：列表 ⇄ 编辑器 主从切换（class 由 roles.js 切；宽屏下这些规则不生效） */
  .roles-split { display: block; }
  .roles-list { width: auto; flex: none; max-height: none; overflow: visible; }
  .roles-split .roles-editor { display: none; }
  .roles-split.show-editor .roles-list { display: none; }
  .roles-split.show-editor .roles-editor { display: block; }
  .roles-editor textarea.code { min-height: 240px; }
  .roles-back { display: inline-flex; }
}

@media (max-width: 640px) {
  .content { padding: 12px 12px 28px; }

  /* 聊天顶栏折成两行：① ☰会话 / 标题 / 管理   ② 模型 + 角色 各占一半。
     order:10 必须给 —— 否则「管理」按钮会被挤到第三行，头部从两行变三行。 */
        /* flex-basis:0 + min-width:0 才能让 select 缩到比最长 option 还窄 ——
     否则长模型名会把整个页面撑出横向滚动。选择器要写成两个类（0-2-0），
     才盖得过上面那条 `.chat-pickers .sel-model` 的宽度。 */
  .chat-pickers .sel-model, .chat-pickers .sel-prompt {
    width: auto; flex: 1 1 0; min-width: 0; max-width: none;
  }

        /* 窄屏放不下「📎 + 输入框 + 发送」一行，按钮会换行 —— 既然换行了就占满整行，
     否则留一个半宽按钮悬在左边更难看，顺带把点击区做到最大 */
  .chat-input .stack { flex: 1 1 100%; }
  .chat-input .stack .btn { width: 100%; }
  .chat-input .tip { display: none; }        /* 「Shift+Enter / 拖入」在手机上是误导 */
  .chat-input textarea { max-height: 120px; }
  .hide-sm { display: none; }

  /* iOS 聚焦字号 < 16px 的输入框会自动放大整页。选择器要写到与被覆盖规则同级
     或更高特异性（现有规则是 `.chat-head select`（0-1-1）这种）。 */
  input[type=text], input[type=password], input[type=number], input[type=email],
  select, textarea,
  .chat-head select, .chat-input textarea, .roles-editor textarea.code { font-size: 16px; }
  .chat-head select { height: 34px; }

  /* 触摸目标放大一档 */
  .btn { padding: 9px 15px; }
  .btn.sm { padding: 6px 11px; }
}

/* ---------- 触摸设备：没有 hover，就不能「悬停才出现」 ---------- */
/* 修的是两个真问题：手机上一个会话都删不掉（✕ 永远 opacity:0）、消息复制按钮点不到 */
@media (hover: none), (hover: on-demand) {
  .sess .del, .msg .copy { opacity: 1; }
  .sess .del {
    width: 32px; height: 32px; flex: 0 0 32px;
    display: grid; place-items: center;
    margin: -6px -6px -6px 0; border-radius: 8px;
  }
  /* 用按压反馈替代悬停反馈 */
  .sess:active, .ss-item:active, .tnav-item:active, .mnav-item:active,
  .tab:active, .share-user:active { background: var(--surface-hover); }
  .btn, .sess, .ss-item, .tnav-item, .mnav-item, .tab { touch-action: manipulation; }
}

/* ============ 工作项看板（PRD FR-WK-04） ============ */
.board {
  display: flex; gap: 12px; padding: 14px 16px;
  overflow-x: auto; align-items: flex-start;
}
.board-col {
  flex: 1 1 0; min-width: 200px;
  background: var(--surface-hover); border-radius: 10px; padding: 8px;
}
.board-col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px 10px; font-size: 13px;
}
.board-col-body { display: flex; flex-direction: column; gap: 8px; }
.board-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; cursor: pointer; font-size: 13px;
}
.board-card:hover { border-color: var(--brand); }

/* 窄屏：看板竖排，横向滚动在手机上很难用 */
@media (max-width: 700px) {
  .board { flex-direction: column; overflow-x: visible; }
  .board-col { width: 100%; }
}

/* ==========================================================================
   视觉与动效
   --------------------------------------------------------------------------
   一条纪律：**动效只用来表达状态变化**（出现了、被选中了、正在处理），
   不用来"显得活泼"。所以这里的动画都很短（.12~.34s）、幅度很小（2~6px），
   并且统一受 `prefers-reduced-motion` 管辖 —— 前庭敏感的用户关掉系统动效之后，
   这里不该还有东西在晃。
   ========================================================================== */

@keyframes fadeUp   { from { opacity: 0; transform: translateY(6px); }  to { opacity: 1; transform: none; } }
@keyframes fadeIn   { from { opacity: 0; }                                to { opacity: 1; } }
@keyframes popIn    { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes slideInR { from { opacity: 0; transform: translateX(14px); }   to { opacity: 1; transform: none; } }
@keyframes shimmer  { from { background-position: -200% 0; }              to { background-position: 200% 0; } }
@keyframes bounce   { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-3px); opacity: 1; } }
@keyframes blink    { 50% { opacity: 0; } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes pulseRing{ 0% { box-shadow: 0 0 0 0 var(--brand-glow); } 100% { box-shadow: 0 0 0 8px transparent; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- 组件动效 ---------- */

.card {
  border-radius: var(--r);
  animation: fadeUp var(--dur-slow) var(--ease) both;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
/* 同一屏里多张卡片时错开一点点，看起来是"依次落位"而不是"整块闪一下"。
   只排前 6 张 —— 再多就会被感知成"页面加载很慢"。 */
.card:nth-of-type(2) { animation-delay: .03s; }
.card:nth-of-type(3) { animation-delay: .06s; }
.card:nth-of-type(4) { animation-delay: .09s; }
.card:nth-of-type(5) { animation-delay: .12s; }
.card:nth-of-type(6) { animation-delay: .15s; }

/* 卡片悬停只提边框、不提阴影：整屏卡片一起浮起来会像页面在抖 */
.card:hover { border-color: var(--border-strong); }

.btn {
  border-radius: var(--r-sm);
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(0) scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary {
  background: var(--brand-grad);
  border-color: transparent;
  box-shadow: 0 2px 8px var(--brand-glow);
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 6px 18px var(--brand-glow); }

/* 键盘焦点环：`:focus-visible` 而不是 `:focus` —— 鼠标点一下也画出蓝框很吵 */
.btn:focus-visible, .ss-item:focus-visible, .tab:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* 品牌方块/头像的底色统一走 --brand-grad，**不要**自己拼
   `linear-gradient(var(--brand), var(--brand-strong))`：那个方向是"亮→暗"，
   而 palettes.py 明确说了 grad 两端明度刻意接近，就是为了配 `--brand-text`。
   自己拼一份会让文字色和底色对不上。这一条由外壳的 .brand-mark/.who-avatar 承担。 */

.tab { border-radius: var(--r-sm) var(--r-sm) 0 0; transition: color var(--dur) var(--ease); }
.tab::after { transition: transform var(--dur) var(--ease); }

.badge { border-radius: var(--r-full); }
.stat .value { font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.meter > i, .meter > div { transition: width var(--dur-slow) var(--ease); }

/* 图标统一在方块里居中。竖排文字基线对齐对 SVG 不生效，居中会歪半像素。 */
.stat-ico, .ico, .icon-btn {
  display: inline-grid; place-items: center;
  vertical-align: -2px;
}
.stat-ico { color: var(--brand); margin-right: 2px; }
.stat .label .stat-ico { opacity: .9; }

/* 表格：表头吸顶 + 行悬停。长表格滚动时不知道自己在哪一列，是很常见的体验问题。 */
.data thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-2);
  backdrop-filter: var(--blur);
}
.data tbody tr { transition: background var(--dur-fast) var(--ease); }
.data tbody tr:hover { background: var(--surface-hover); }

/* 表格精修：统一行高 + 操作列降噪 + 信息层级。
   起因是工作流列表：描述列有的折两行、有的一行，行高参差，扫读时没有节奏；
   操作列每行四五个带框按钮、删除还是实心红底，整列几乎只剩边框。
   做法是把次要操作降到 ghost（悬停才显形）、描述截断成一行（全文进 title）——
   **交互一个没变**，只是把视觉噪音收掉。 */
.data td { height: 44px; }
/* 描述列：一行截断。整段折行会让每行高度都不一样，长列表很难扫。 */
.data td .clamp1 {
  display: block; max-width: 34ch;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* 名称比描述重一档，主次才分得出来 */
.data td .cell-name { font-weight: 500; }
/* 分组列：同一个分组重复十几行时，实心药丸会连成一条色带，比名称还抢眼。
   改成描边式 —— 信息还在，但不跟内容争视线。 */
.data td .badge.group {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-mute);
}

/* 次要操作默认隐形，悬停才浮出来 —— 一屏十几行时差别很大 */
.data td .btn.ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.data td .btn.ghost:hover:not(:disabled) {
  border-color: var(--border); background: var(--surface-hover); color: var(--text);
}
/* 删除：不再常驻红底，但仍然保留危险色的语义 —— 悬停时红框红字 */
.data td .btn.danger.ghost { border-color: transparent; background: transparent; color: var(--text-mute); }
.data td .btn.danger.ghost:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
  background: var(--danger-soft); color: var(--danger);
}

.modal { animation: popIn var(--dur) var(--ease-spring) both; border-radius: var(--r-lg); }
.modal-mask { animation: fadeIn var(--dur) var(--ease) both; backdrop-filter: var(--blur); }
.toast { animation: slideInR var(--dur) var(--ease-spring) both; border-radius: var(--r-sm); }

input, select, textarea { border-radius: var(--r-sm); transition: border-color var(--dur) var(--ease); }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--border-strong); }

/* 加载态统一成流光条：静态骨架屏容易被误认成"加载完了但是空的" */
.msg-skeleton .bar, .skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 37%, var(--surface-2) 63%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.spin { animation: spin .9s linear infinite; display: inline-block; }

/* ---------- 聊天界面（重点） ----------
   聊天页和其他页不一样：它是**长时间停留**的界面，所以这里的手感比别处更值得抠 ——
   气泡的圆角、头像的克制、消息之间该松还是该紧，看久了差别很明显。 */

.chat-main { background: var(--bg); }
.chat-head {
  background: color-mix(in srgb, var(--bg-elev) 82%, transparent);
  backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--border);
}
.chat-side { background: var(--bg-elev); border-right: 1px solid var(--border); }
/* 左右留白比别处宽一点：气泡贴着边缘看久了很累，而且圆角会被视口切掉半个 */

/* 消息进入：轻微上浮。幅度刻意只有 4px —— 大位移在长列表里滚动时很晕。 */
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg { animation: msgIn var(--dur) var(--ease) both; }

/* 连续同一个人的消息收紧间距：整段对话读起来是一个"话轮"而不是一堆碎片。
   头像只在该轮第一条出现（JS 侧没区分，所以这里用相邻选择器把重复的藏起来） */
.msg.bot + .msg.bot .msg-head { display: none; }
.msg.bot + .msg.bot { margin-top: -6px; }
.msg.user + .msg.user { margin-top: -6px; }

.bubble {
  border-radius: var(--r) var(--r) var(--r) 4px;
  line-height: 1.62;
  transition: box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.msg.bot .bubble { background: var(--surface-2); border: 1px solid var(--border); }
.msg.bot:hover .bubble { border-color: var(--border-strong); }

/* 自己的消息：右下角收一个小角，方向感来自形状而不是颜色 */
.msg.user .bubble {
  border-radius: var(--r) var(--r) 4px var(--r);
  background: var(--brand-grad);
  box-shadow: 0 2px 10px var(--brand-glow);
}

/* ---------- 聊天页重构（参考 ChatGPT） ----------
   三处关键差异，目标是让**长回答读起来像文章**，而不是泡在一个个气泡里：
   1. 内容列限宽居中；2. 助手消息去气泡；3. 用户气泡柔和化。
   功能一个没动：引用 / 重新生成 / 编辑 / 删除 / 附件 / @ 工作流 都在原处。

   ⚠ 这一段**必须排在上面那组 .bubble 规则之后**：本文件是"后写者胜"，
   放前面的话同特异性会被盖掉 —— 踩过：padding 生效了、背景却没变，
   查了一阵才发现是顺序，不是选择器写错。 */


/* 消息列 768px 居中 —— 中文正文约 40 字/行；全宽时一行能到 150+ 字符，
   眼睛回行时找不到行首。挂在 .msg 上而不是加包裹层：每个 .msg 各自居中，
   列自然对齐，不必动 chat.js 里那几处 mount。 */
.chat-msgs > .msg {
  max-width: 768px;
  margin-left: auto; margin-right: auto;
  margin-bottom: 20px;
}

/* 助手消息去气泡：正文直接落在背景上。代码块 / 引用块各自仍有底色框，
   所以"哪段是代码"一眼可辨 —— 去掉的只是包着整段回答的那圈边框。 */
.msg.bot .bubble {
  background: transparent;
  border: 0;
  padding: 0;
  border-radius: 0;
  box-shadow: none;
}
.msg.bot .bubble .quote { background: var(--surface-hover); }
.msg.bot:hover .bubble { border-color: transparent; }   /* 上面有 :hover 提亮边框，一并取消 */

/* 用户消息：品牌渐变 → 淡品牌底 + 细品牌边框。
   引用条 / "已编辑"标记用的是 currentColor，文字色改回 --text 后会自动适配。 */
.msg.user .bubble {
  background: var(--brand-soft);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--brand) 26%, transparent);
  box-shadow: none;
}

/* 输入区与消息列同宽居中 —— 输入框和正文左右对齐，视线不用横跳 */
.chat-input > * { max-width: 768px; margin-left: auto; margin-right: auto; }

/* 输入区做成一个整体卡片（参考 ChatGPT）：去掉 textarea 自己的边框，
   让 附件 / 输入 / 发送 看起来属于**同一个控件**。当前 DOM 是 `.chat-input-card`。 */
.chat-input textarea {
  border: 0; background: transparent; box-shadow: none;
  padding: 9px 4px; min-height: 40px;
}
.chat-input textarea:focus { outline: none; }
/* 胶囊里按钮不需要自己的边框，否则又变回"三个独立件" */
.chat-input .attach-btn { border-color: transparent; background: transparent; color: var(--text-dim); }
.chat-input .attach-btn:hover { background: var(--surface-hover); color: var(--text); }

/* 标题栏的选择器降到 ghost：它们是"偶尔改一下"的东西，
   常驻边框会跟会话标题抢注意力（参考 ChatGPT 的模型名只占一行小字）。 */
.chat-pickers select, .chat-pickers input {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.chat-pickers select:hover, .chat-pickers input:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

/* 会话项改成两行：标题 + 相对时间。
   原来只有一行截断的预览 —— 几条会话开头都是"你好…"时完全分不出谁是谁。 */
.sess-body { flex: 1; min-width: 0; }
.sess-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess-when { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.sess.active .sess-when { color: var(--text-dim); }

/* 空态抬高：新会话时先看到一句问候，而不是一条贴在顶部的细线 */
.chat-msgs .empty { padding-top: 16vh; }

/* 宽屏也能收起会话列表（参考 ChatGPT 的侧栏折叠）。
   窄屏那套是"抽屉"（≤640px 由 .show-side 推出来），这套是"折叠" ——
   用媒体查询把两者隔开，于是 JS 可以无脑同时 toggle 两个类，由 CSS 决定谁生效。 */
@media (min-width: 641px) {
  .chat-head .side-toggle { display: inline-flex; }
  .chat-layout.side-hidden .chat-side { display: none; }
}

.mini-avatar {
  box-shadow: 0 0 0 1px var(--border), 0 2px 6px rgba(0, 0, 0, .18);
  transition: transform var(--dur) var(--ease-spring);
}
.msg-head:hover .mini-avatar { transform: scale(1.08); }
.mini-avatar.fallback {
  background: var(--brand-grad);        /* 同上：别自己拼方向相反的渐变 */
  font-weight: 600;
}

.msg-name { letter-spacing: .2px; }

/* 「正在思考」：三个点依次起伏。比转圈更能表达"在生成文字"这件事。
   老浏览器不认识 `:nth-child` 的 delay 也无所谓，静态三点同样能读懂。 */
.thinking { display: inline-flex; align-items: center; gap: 4px; color: var(--text-mute); font-size: 13px; }
.thinking i {
  width: 4px; height: 4px; border-radius: 50%;
  background: currentColor; display: inline-block;
  animation: bounce 1.25s var(--ease) infinite;
}
.thinking i:nth-child(2) { animation-delay: .16s; }
.thinking i:nth-child(3) { animation-delay: .32s; }

/* 流式输出的光标 */
.caret {
  display: inline-block; width: 2px; height: 1em; margin-left: 2px;
  vertical-align: text-bottom; border-radius: 1px;
  background: var(--brand); animation: blink 1s step-end infinite;
}

/* 输入区：聚焦时整块边框亮起来而不是只亮输入框 —— 这块区域是"会话的一部分" */
.chat-input {
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: var(--blur);
  border-top: 1px solid var(--border);
  transition: border-color var(--dur) var(--ease);
}
.chat-input textarea {
  border-radius: var(--r);
  resize: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.chat-input textarea:focus { border-color: var(--brand); box-shadow: var(--ring); }

.chat-backdrop { backdrop-filter: var(--blur); animation: fadeIn var(--dur) var(--ease) both; }
.chat-drop-active { border-radius: var(--r); animation: fadeIn var(--dur-fast) var(--ease) both; }
.bubble .attach-thumbs img { border-radius: var(--r-sm); transition: transform var(--dur) var(--ease-spring); }
.bubble .attach-thumbs img:hover { transform: scale(1.03); }

/* 会话列表项 */
.sess { border-radius: var(--r-sm); transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.sess.active { background: var(--brand-soft); }
.sess.active::before { content: none; }

/* 空状态：给一个会呼吸的圆点，让"这里现在没东西"看起来是正常状态而不是加载失败 */
/* `.big` 在全站基础层里是 `display: block`（占满整行），而这里给它 `border-radius: 50%`
   加脉冲 box-shadow —— 圆角和阴影是算在"整行宽 × 一行高"上的，于是本该贴着「◌」
   字形的一圈光环被拉成横贯全屏的扁椭圆（聊天页空态上尤其明显）。
   改成按内容收缩，光环才贴着那个字形；`.empty` 是 `text-align: center`，
   inline-block 依然居中。 */


/* 顶部进度条：页面切换时的一条细线。比转圈不打扰，又不至于让人以为没反应。 */
.route-progress {
  position: fixed; top: 0; left: 0; height: 2px; width: 0;
  background: linear-gradient(90deg, var(--brand), var(--info));
  z-index: 9999; opacity: 0;
  /* 不吃点击：盖在页面顶部的一条细线不该拦截任何鼠标事件 */
  pointer-events: none;
  transition: width var(--dur-slow) var(--ease), opacity var(--dur) var(--ease);
}
.route-progress.on { opacity: 1; width: 70%; }
.route-progress.done { width: 100%; opacity: 0; }

/* 工作项看板卡片 */
.board-card { border-radius: var(--r-sm); transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.board-card:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.board-col { border-radius: var(--r); }

/* 插件市场的卡片 */
.plugin-card .card-body { padding: 14px 16px; }
.plugin-card { animation: fadeUp var(--dur-slow) var(--ease) both; }

.row.wrap { flex-wrap: wrap; }

/* ==========================================================================
   外观设置（设置页 → 外观）
   ========================================================================== */

.palette-grid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
}
.palette-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
}
.palette-chip:hover { border-color: var(--border-strong); transform: translateY(-1px); }
/* 选中态用**边框 + 背景**而不是只换文字色：色块本身颜色各异，
   光靠文字变色，在一屏马卡龙里根本看不出哪个被选中了 */
.palette-chip.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--ring);
}
/* 色块画成"左深右浅"的小渐变，正好对应按钮和气泡的观感 */
.palette-dot {
  width: 18px; height: 18px; flex: 0 0 18px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14), 0 1px 3px rgba(0, 0, 0, .18);
}
.palette-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-check { color: var(--brand); font-weight: 700; }

/* 配色预览：两条气泡，用真实的 --brand-grad，所见即所得 */
.appearance-preview { margin-top: 14px; }
.appearance-preview-inner {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
}
.ap-bubble {
  max-width: 70%; padding: 8px 12px; font-size: 13px;
  border-radius: var(--r) var(--r) var(--r) 4px;
}
.ap-bubble.bot { background: var(--surface); border: 1px solid var(--border); align-self: flex-start; }
.ap-bubble.user {
  background: var(--brand-grad); color: var(--brand-text);
  border-radius: var(--r) var(--r) 4px var(--r);
  align-self: flex-end;
  box-shadow: 0 2px 10px var(--brand-glow);
}

/* 滑块行：标签固定宽度，滑块占满，数值右对齐 —— 三行对齐后一眼能横向比较 */
.slider-row {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 10px;
}
.slider-row label { flex: 0 0 76px; font-size: 12.5px; color: var(--text-dim); }
.slider-row input[type="range"] { flex: 1; min-width: 120px; }
.slider-row > span:last-child { flex: 0 0 56px; text-align: right; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  height: 4px; border-radius: 2px;
  background: var(--surface-hover);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--brand);
  border: 2px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .3);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--surface);
  cursor: pointer;
}

/* ==========================================================================
   设计系统 v2 —— 现代 SaaS 视觉
   --------------------------------------------------------------------------
   这一节是**新增**的，不是又一层覆盖：里面的类名都是新的（.tabbar / .bulk-bar /
   .row-actions / .kv / .input-sm / .data.dense …），老页面不引用就完全不受影响。
   老选择器的修订直接改在原处，不在这里再覆盖一遍 —— 那正是这个文件变得难维护的原因
   （三节追加式覆盖层，9 个选择器被定义两三次，同一个 padding 改过四遍）。

   视觉上的四个决定：
     1. 行高收到 40px（原来 ~44px+），一屏能多看四五条
     2. 边框降一档、靠留白分层，少用重描边
     3. 行内操作默认淡出，悬停整行才显出来 —— 一列实心按钮比什么都吵
     4. 圆角只用令牌，不再写字面量（原来有 60+ 处字面量、11 种取值）
   ========================================================================== */

:root {
  /* 间距刻度。**以前完全没有** —— 229 处行内 style 里大半是在补这个。
     用 4 的倍数，跟主流设计系统对齐。 */
  --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;  --sp-4: 16px;
  --sp-5: 20px;  --sp-6: 24px;  --sp-8: 32px;  --sp-10: 40px;

  /* 表格与控件的固定高度，避免每个页面各写一个 px */
  --h-row: 40px;
  --h-row-dense: 32px;
  --h-ctl: 32px;
  --h-ctl-sm: 28px;
}

/* ---------- 筛选标签条 ---------- */

.tabbar {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }

.tabbar-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 10px 11px;
  border: 0;
  background: none;
  color: var(--text-dim);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  border-radius: var(--r-xs) var(--r-xs) 0 0;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.tabbar-item:hover { color: var(--text); background: var(--surface-hover); }
.tabbar-item.active { color: var(--brand); font-weight: 600; }
/* 选中下划线：压在 .tabbar 的 border-bottom 上，所以要比它低 1px */
.tabbar-item.active::after {
  content: "";
  position: absolute;
  left: 6px; right: 6px; bottom: -1px;
  height: 2px;
  background: var(--brand);
  border-radius: 2px 2px 0 0;
}
.tabbar-count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-mute);
  font-size: 11px;
  font-weight: 600;
  line-height: 17px;
  text-align: center;
}
.tabbar-item.active .tabbar-count { background: var(--brand-soft); color: var(--brand); }

/* ---------- 批量操作条 ---------- */
/* 默认 height:0 收起来而不是 display:none —— 后者会让下面的表格在选中时跳一下 */

.table-block { display: block; }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: 0;
  padding: 0 var(--sp-4);
  overflow: hidden;
  background: var(--brand-soft);
  border-bottom: 1px solid transparent;
  opacity: 0;
  transition: height var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.bulk-bar.show {
  height: 46px;
  opacity: 1;
  border-bottom-color: var(--border);
}
.bulk-count { font-size: 13px; font-weight: 600; color: var(--brand); }

/* ---------- 行内操作 ---------- */

.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  opacity: .32;
  transition: opacity var(--dur-fast) var(--ease);
}
tr:hover .row-actions,
tr:focus-within .row-actions { opacity: 1; }
/* 触摸设备没有 hover，常驻显示（否则这些按钮等于不存在） */
@media (hover: none), (hover: on-demand) {
  .row-actions { opacity: 1; }
}

.icon-btn.sm {
  width: var(--h-ctl-sm);
  height: var(--h-ctl-sm);
  border-radius: var(--r-xs);
}
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- 表格：紧凑模式与勾选列 ---------- */

table.data.dense td { height: var(--h-row-dense); }
table.data.dense th { padding: 6px 12px; }

table.data th.pick,
table.data td.pick {
  width: 36px;
  padding-right: 0;
  text-align: center;
}

/* 原生勾选框统一成品牌色，免得每页各写一遍 accent-color */
input[type="checkbox"].row-check {
  width: 15px;
  height: 15px;
  accent-color: var(--brand);
  cursor: pointer;
  vertical-align: middle;
}

table.data tr.clickable { cursor: pointer; }
table.data tr.clickable:hover td { background: var(--surface-hover); }

/* 名称列：主标题 + 次要 id 的固定排版（原来只有工作流列表有，现在全站统一） */
.cell-main { display: block; font-weight: 600; color: var(--text); }
.cell-sub {
  display: block;
  font-size: 12px;
  color: var(--text-mute);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* ---------- 键值表 ---------- */

.kv { display: block; }
.kv-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-4);
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.kv-row:last-child { border-bottom: 0; }
.kv-k {
  flex: 0 0 132px;
  color: var(--text-mute);
  font-size: 13px;
}
.kv-v { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- 小号控件 ---------- */
/* 原来筛选框的宽度全是行内 px（150/90/130/200…），窄屏下媒体查询打不到 */

.input-sm {
  height: var(--h-ctl-sm);
  padding: 0 var(--sp-2);
  font-size: 13px;
  /* 小尺寸输入框要配小圆角：这条只有 28px 高，用全局那份 12px 圆角
     两端会完全圆掉，变成一颗「扁椭圆」，和旁边 10px 圆角的按钮不是一套语言。 */
  border-radius: var(--r-xs);
}
select.input-sm { padding-right: 4px; }

/* 宽度档位 */
.w-80 { width: 80px; }
.w-120 { width: 120px; }
.w-160 { width: 160px; }
.w-220 { width: 220px; }
.w-auto { width: auto; }

/* ---------- 工具栏（卡片头上方的一行筛选） ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4);
}
.toolbar .spacer { flex: 1; }

/* ---------- 卡片头：改成一栏紧凑排版 ---------- */

.card-head {
  min-height: 52px;
  padding: 0 var(--sp-4);
}
.card-head h2 {
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 9px;
}
/* 卡片头里的图标用品牌色（参考稿 .card-head h3 svg 就是这个处理）——
   一排卡片扫过去，图标是第一个能区分它们的锚点 */
.card-head h2 svg { width: 17px; height: 17px; color: var(--brand); }
/* 标题与副标题**不许被挤断行**。card-head 是个会 wrap 的 flex 行，
   右边的筛选控件一多（调用追踪页有 5 个），标题就被压成"LLM / 调用 / 追踪"
   三行 —— 一个 15px 的标题占掉三行，整张卡的头就废了。
   宁可让筛选控件换到下一行（flex-wrap 本来就会做这件事）。 */
.card-head > div:first-child { flex: 0 0 auto; min-width: 0; }
.card-head h2 { white-space: nowrap; }
.card-head .sub { white-space: nowrap; }
/* 卡片头里的小标签（勾选框的文字说明等）同理：两个字横着断成两行是最没道理的排版 */
.card-head label { white-space: nowrap; }

/* ---------- 指标卡 ---------- */
/* **全站唯一结构**：图标色块 → 大数字（可带单位）→ 标签 → 注脚。
   dashboard 以前的 richStat 与这里的 statCard 是两套 DOM/两套字号，
   现在合并到 app.js:statCard 一份实现，`.stat-card` 这一套类名已删除。 */

.card.stat {
  /* 列向 flex + 注脚 margin-top:auto：一排卡片的底边对齐 */
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
}
.card.stat .stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.card.stat .stat-ico {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand);
}
.card.stat .stat-ico svg { width: 19px; height: 19px; }
.card.stat.t-info .stat-ico { color: var(--info); background: var(--info-soft); }
.card.stat.t-ok .stat-ico { color: var(--ok); background: var(--ok-soft); }
.card.stat.t-warn .stat-ico { color: var(--warn); background: var(--warn-soft); }
.card.stat .stat-value {
  font-family: var(--tnum);        /* 统计数字等宽：轮询刷新时数字跳变不会让整列抖 */
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.card.stat .stat-value small {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-mute);
  margin-left: 4px;
}
.card.stat .stat-value.warn { color: var(--warn); }
.card.stat .stat-value.ok { color: var(--ok); }
.card.stat .stat-value.danger { color: var(--danger); }
.card.stat .stat-label { font-size: 12.5px; color: var(--text-mute); margin-top: 8px; }
.card.stat .stat-hint {
  font-size: 11.5px; color: var(--text-mute);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: auto; padding-top: 8px;       /* 推到卡片底部，与邻居对齐 */
}
.card.stat .meter { margin-top: 8px; }
.card.stat.clickable {
  cursor: pointer;
  transition: border-color var(--dur) var(--ease), transform var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.card.stat.clickable:hover {
  border-color: var(--border-strong); transform: translateY(-2px);
  box-shadow: var(--shadow-sm, 0 6px 18px rgba(0, 0, 0, .08));
}

/* ---------- 文本语义色 ---------- */
/* `.warn` / `.ok` / `.danger` 原先只作为 `.badge.*` 存在，写 `class:"small warn"`
   完全没有效果 —— 用户管理页那个「待审核」的数字就没变过色。 */

.warn { color: var(--warn); }
.ok { color: var(--ok); }
.danger { color: var(--danger); }

/* ---------- 页面级布局 ---------- */
/* 用 flex 撑满而不是 calc(100vh - 94px)：那个 94 是两个魔法数相加，
   而挂在内边距容器里算法根本不对（chat.js 的注释记过这个坑）。 */

.fill-col {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
/* 卡片里的滚动区：撑满剩余高度、自己滚。日志页的列表用这个。 */
.fill-col > .scroll-y { flex: 1; min-height: 0; overflow-y: auto; }

/* ---------- 两栏网格 ---------- */
/* `.grid-2` 这个名字被日志页用过但从来没定义过，静默退化成了竖排。 */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-4);
}
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* 并排的卡片**不要互相拉齐高度** —— 快捷入口只有 6 行、系统信息有 6 行但行高不同，
   拉齐的结果是矮的那张底下一大片空白。 */
.grid.cols-2 { align-items: start; }

/* ==========================================================================
   聊天界面 v2 —— 参考通义千问那类对话产品的排布
   --------------------------------------------------------------------------
   **这一节取代上面所有零散的 `.chat-*` / `.msg` / `.bubble` 规则**（原来那些散在
   6 个追加层里：`.chat-input` 定义过 5 次、`.chat-msgs` 5 次、`.chat-head` 4 次、
   `.bubble` 3 次）。这里按「一个组件只写一次」重排，以后改聊天只改这一节。

   三处结构性变化：
     1. **模型 / 角色选择从顶栏搬进输入框**。它们和「这一次要发什么」是同一件事，
        放顶栏会让人以为是全局设置 —— 千问、ChatGPT 也都是放在输入框旁边的。
     2. **输入框变成一张卡片**：文本域在上，底部一行放选择器 + 附件 + 发送。
        发送键做成圆形图标，但**保留「发送」两个字的可访问名**。
     3. **侧栏折叠统一成「整条收起」**（原来宽屏收成图标条、窄屏是抽屉，两套行为）。
   ========================================================================== */

/* 视觉隐藏、但保留给读屏与测试用的文字。**不能写 display:none** ——
   那样 `has-text()` 找不到，读屏也读不到。 */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 布局 ---------- */

.chat-layout { display: flex; height: 100%; min-height: 0; position: relative; }

.chat-side {
  width: 264px;
  flex: 0 0 264px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
}

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

/* ---------- 侧栏 ---------- */

.chat-side .side-head { padding: 12px; flex: 0 0 auto; }
.chat-side .side-head .btn { width: 100%; justify-content: center; gap: 6px; }

.chat-sessions { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; }

.sess {
  position: relative;
  display: block;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}
.sess:hover { background: var(--surface-hover); }
.sess.active { background: var(--brand-soft); }
.sess-title {
  display: block;
  font-size: 13.5px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 28px;          /* 给右上角的删除键留位，长标题不会压到它 */
}
.sess.active .sess-title { color: var(--brand); font-weight: 600; }
.sess-when { display: block; font-size: 11.5px; color: var(--text-mute); margin-top: 1px; }
.sess .del {
  position: absolute;
  top: 6px; right: 6px;
  width: 26px; height: 26px;    /* 触摸目标下限是 24px；原来 22 差一点点 */
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-xs);
  background: none; color: var(--text-mute);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease);
}
.sess:hover .del { opacity: 1; }
.sess .del:hover { background: var(--danger-soft); color: var(--danger); }
/* 触摸设备没有 hover —— 不常驻显示的话，会话删除键在手机上等于不存在
   （重写这一节时漏掉过这条，被 e2e 的触摸可达性探针抓出来了）。 */
@media (hover: none), (hover: on-demand) {
  .sess .del { opacity: 1; }
}

/* ---------- 顶栏：只留开关 + 标题 + 右侧动作 ---------- */
/* 选择器搬走之后这里空出来了，正好按千问那样做成一条**细**顶栏 */

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  height: 54px;
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.chat-head .side-toggle { display: inline-flex; }
.chat-title {
  font-size: 14.5px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 消息区 ---------- */

.chat-msgs {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px var(--sp-4) 8px;
  scroll-behavior: smooth;
  scroll-padding-bottom: 24px;
}
/* 居中消息列。**用 margin auto 而不是给容器定宽** —— 容器保持全宽，
   引用块、代码、表格都能撑满；只有每条消息自己收在 768px 里。 */
.chat-msgs > .msg { max-width: 768px; margin-left: auto; margin-right: auto; }
.chat-msgs .empty { padding-top: 14vh; }

.msg { display: flex; gap: 10px; margin-bottom: 18px; animation: msgIn var(--dur) var(--ease) both; }
/* `.msg-head` 与 `.msg-body` 是**兄弟**（见 chat.js 的 bubble()），不是父子 ——
   所以头像自成一列，正文占剩下的宽度。 */
.msg > .msg-body { flex: 1; min-width: 0; }
.msg-head { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 3px; width: 40px; }
.msg-name {
  font-size: 10.5px;
  color: var(--text-mute);
  max-width: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg.user .msg-head { display: none; }

/* 引用块 */
.bubble .quote {
  display: flex;
  gap: 6px;
  align-items: baseline;
  margin-bottom: 7px;
  padding: 5px 9px;
  border-left: 3px solid var(--brand);
  border-radius: 4px;
  background: var(--surface-2);
  font-size: 12.5px;
  cursor: pointer;
}
.bubble .quote-who { color: var(--text-mute); flex: 0 0 auto; }
.bubble .quote-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.user .bubble .quote { background: rgba(0, 0, 0, .18); border-left-color: currentColor; }
.msg.user .bubble .quote-who,
.msg.user .bubble .quote-txt { color: inherit; opacity: .86; }
.bubble .edited { font-size: 11px; color: var(--text-mute); margin-left: 6px; }
.msg.user .bubble .edited { color: inherit; opacity: .7; }

/* 复制/引用/编辑 这些文字按钮：调小、去掉边框感，别和正文抢注意力 */
.msg .acts .copy {
  font-size: 11.5px;
  color: var(--text-mute);
  padding: 1px 6px;
  border-radius: var(--r-xs);
  cursor: pointer;
}
.msg .acts .copy:hover { color: var(--brand); background: var(--brand-soft); }
.msg .acts .copy.danger:hover { color: var(--danger); background: var(--danger-soft); }

/* 助手气泡**没有背景**（千问 / ChatGPT 的做法）：一整片色块在长对话里很吵，
   而且会和代码块、表格打架。用留白和对齐区分角色就够了。 */
.msg.bot .bubble {
  background: none;
  border: 0;
  padding: 0;
  box-shadow: none;
}
/* 用户气泡保留品牌色：一眼分清「谁说的」是聊天界面最基本的要求 */
.msg.user { flex-direction: row-reverse; }
.msg.user .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  /* `inline-block` + `max-width`：气泡按内容宽度收缩。
     用默认的块级的话，"11" 会撑成横贯整行的一条长条 —— 短消息看着像出了错。 */
  display: inline-block;
  max-width: min(78%, 620px);
  text-align: left;
  background: var(--brand-grad);
  color: var(--brand-text);
  border: 0;
  border-radius: var(--r-lg);
  box-shadow: none;
  padding: 9px 14px;
}
.msg.user .acts { justify-content: flex-end; }
.msg.user .msg-head { justify-content: flex-end; }

.bubble {
  font-size: 14.5px;
  line-height: 1.72;
  overflow-wrap: anywhere;
}
.msg.bot .bubble { color: var(--text); }
.bubble p { margin: 0 0 10px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble code { background: var(--surface-hover); padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.bubble pre code { background: none; padding: 0; }
.msg.user .bubble pre { background: rgba(0, 0, 0, .18); border-color: transparent; }

/* 消息级操作：悬停才显出来 */
.msg .acts { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity var(--dur-fast) var(--ease); }
.msg:hover .acts, .msg .acts:focus-within { opacity: 1; }
@media (hover: none) { .msg .acts { opacity: 1; } }

/* ---------- 输入区：一张卡片 ---------- */

.chat-input { flex: 0 0 auto; padding: 6px var(--sp-4) 10px; }

.chat-input-card {
  max-width: 768px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 10px 12px 8px;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.chat-input-card:focus-within { border-color: var(--brand); box-shadow: var(--ring); }

.chat-input-card textarea {
  width: 100%;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 14.5px;
  line-height: 1.6;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 180px;
  padding: 0;
}
.chat-input-card textarea::placeholder { color: var(--text-mute); }

/* 卡片底部那一行：选择器在左，发送在右 */
.chat-input-bar { display: flex; align-items: center; gap: var(--sp-2); margin-top: 6px; }

/* 选择器做成小药丸。默认下拉框的尺寸和「输入框的一部分」这个身份不搭。 */
.pick-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  max-width: 190px;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.pick-pill:hover { border-color: var(--border-strong); color: var(--text); }
.pick-pill:focus-within { border-color: var(--brand); box-shadow: var(--ring); }
.pick-pill select,
.pick-pill input {
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  outline: none;
  max-width: 150px;
  padding: 0;
  cursor: pointer;
  appearance: none;
}
/* 药丸里的下拉**不要**再画一层边框 —— 上面 `.chat-pickers select` 那条老规则还在，
   不压掉它，药丸里就会多出一个框。 */
.pick-pill select:focus,
.pick-pill select:hover,
.pick-pill input:focus { outline: none; box-shadow: none; border: 0; }
/* 桌面端模型选择用的是 `searchSelect`（可搜索 + 按来源分组 + 能力徽标），
   它自带 `.combo > input` 那层外观 —— 不压掉，药丸里会套一个输入框。 */
.pick-pill .combo { flex: 1; min-width: 0; }
.pick-pill .combo > input {
  border: 0; background: none; height: auto; padding: 0;
  box-shadow: none; font-size: 12.5px; color: inherit;
}
.pick-pill .combo-panel { font-size: 13px; }

/* 发送键：圆形图标。里面的「发送」两个字是 `.sr-only` 的 ——
   e2e 用 `has-text("发送")` 找它、读屏也靠它，所以字必须留在 DOM 里。 */
.send-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  border-radius: var(--r-full);
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}
.chat-input-bar .stop-btn { height: 30px; border-radius: var(--r-full); font-size: 12.5px; padding: 0 12px; }

.chat-input .tip {
  max-width: 768px;
  margin: 6px auto 0;
  font-size: 11.5px;
  color: var(--text-mute);
  text-align: center;
}

/* 附件条 / 引用条 / 错误条也收进同一条 768px 列宽 */
.chat-input .attach-bar,
.chat-input .reply-bar,
.chat-input .mention-menu { max-width: 768px; margin-left: auto; margin-right: auto; }
.chat-main > .attach-bar,
.chat-main > .card { max-width: 768px; margin-left: auto; margin-right: auto; }

/* ---------- 侧栏折叠 ---------- */
/* 宽屏：`side-hidden` = 侧栏整个不占位，主区铺满。
   窄屏：`show-side` = 抽屉推出来，配一层遮罩。 */

@media (min-width: 641px) {
  .chat-layout.side-hidden .chat-side { display: none; }
  .chat-backdrop { display: none !important; }
}

@media (max-width: 640px) {
  .chat-layout { position: relative; }
  .chat-side {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 30;
    /* 控制台左侧还有一条 60px 的导航图标条，抽屉再占 82vw 就整屏吃满了 ——
       留出一指宽能看到下面的内容，也是"点遮罩能关掉"这个交互的前提。 */
    width: min(300px, 74vw);
    max-width: calc(100vw - 76px);
    transform: translateX(-102%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow);
  }
  .chat-layout.show-side .chat-side { transform: translateX(0); }
  .chat-layout.show-side .chat-backdrop { display: block; }
  .chat-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 20;
    background: rgba(0, 0, 0, .34);
    backdrop-filter: blur(1px);
  }
  .chat-msgs { padding: 14px 12px 6px; }
  .chat-input { padding: 4px 10px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .chat-input .tip { display: none; }   /* 「Shift+Enter / 拖入」在手机上是误导 */
  /* 16px 防 iOS 聚焦时页面被放大 */
  .chat-input-card textarea { max-height: 120px; font-size: 16px; }
  .pick-pill { max-width: 130px; }
  .pick-pill select, .pick-pill input { max-width: 96px; }
  /* 手机上药丸 + 附件 + 发送并排会挤，让内容换行、发送键靠右 */
  .chat-input-bar { flex-wrap: wrap; }
  .chat-input-bar .send-btn { margin-left: auto; }
}

/* 附件键：和选择器药丸同样的尺寸与边界感，不然是个"悬空的加号" */
.chat-input-bar .attach-btn {
  width: 30px;
  height: 30px;
  min-width: 30px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--text-dim);
}
.chat-input-bar .attach-btn:hover { border-color: var(--border-strong); color: var(--text); }

/* ==========================================================================
   命令面板（参考稿的 .palette / .search-trigger）
   --------------------------------------------------------------------------
   控制台有 15 个页面、几十条工作流和角色，光靠侧栏点两下才能到某一页。
   命令面板把"页面 / 角色 / 模型 / 工作流 / Skill"收到一个输入框后面 ——
   `Ctrl/Cmd+K` 唤起，打字即时过滤，回车直达。

   JS 在 app.js 的 installPalette()；这里只管外观。
   ========================================================================== */

/* 顶栏那个触发按钮。窄屏收成一个纯图标按钮（参考稿也是这么处理的）。 */
.search-trigger {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 240px;
  max-width: 34vw;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-mute);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.search-trigger:hover { border-color: var(--border-strong); color: var(--text-dim); }
.search-trigger svg { width: 16px; height: 16px; flex: 0 0 16px; }
.search-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-trigger .kbd {
  margin-left: auto;
  /* **不能被压扁**：`margin-left:auto` 之外还要 flex:0 0 auto —— 否则占位文案一长，
     flex 就会先压缩这个"最不重要的"子项，快捷键提示被截成 "ctrl…"（踩过）。 */
  flex: 0 0 auto;
  font-family: var(--tnum);
  font-size: 11px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 7px;
  color: var(--text-dim);
}
@media (max-width: 900px) {
  .search-trigger { width: 42px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger .kbd { display: none; }
}

/* ---------- 面板本体 ---------- */

.palette-mask {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 27, .5);
  backdrop-filter: blur(3px);
  z-index: 80;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s var(--ease);
}
.palette-mask.open { opacity: 1; pointer-events: auto; }

.palette {
  position: fixed;
  top: 12vh;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  width: min(600px, 92vw);
  z-index: 81;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .18s var(--ease), transform .18s var(--ease), visibility .18s;
}
.palette.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.palette-input {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.palette-input svg { width: 18px; height: 18px; color: var(--text-mute); flex: 0 0 18px; }
.palette-input input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
}
.palette-input input::placeholder { color: var(--text-mute); }

.palette-list { max-height: 46vh; overflow-y: auto; padding: 8px; }

.pal-group {
  padding: 8px 12px 4px;
  font-size: 11px;
  color: var(--text-mute);
  letter-spacing: 1.2px;
}

.pal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s var(--ease);
}
.pal-item:hover, .pal-item.sel { background: var(--surface-hover); }
.pal-item .pi {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--brand);
  background: var(--brand-soft);
}
.pal-item .pi svg { width: 16px; height: 16px; }
.pal-item .pt { font-size: 13.5px; font-weight: 500; }
.pal-item .ps {
  font-size: 12px;
  color: var(--text-mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pal-item .gk {
  margin-left: auto;
  font-family: var(--tnum);
  font-size: 11px;
  color: var(--text-mute);
  flex: 0 0 auto;
}

.palette-empty { padding: 28px 16px; text-align: center; color: var(--text-mute); font-size: 13px; }

.palette-foot {
  padding: 9px 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-mute);
  display: flex;
  gap: 14px;
  align-items: center;
}
.palette-foot .kbd {
  font-family: var(--tnum);
  font-size: 10.5px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 5px;
  color: var(--text-dim);
}

/* ==========================================================================
   首页的学习区（learn.js）
   --------------------------------------------------------------------------
   关卡式工作流教程。形式参考 n8n 的入门课程：短说明 + 一个立刻要做的动作。
   放在首页（而不是新开一页）是因为新用户第一眼就落在仪表盘上 ——
   教程藏进侧栏第二层，等于没有。
   ========================================================================== */

.learn-card { margin-bottom: var(--sp-4); }

.learn-head {
  cursor: pointer;
  user-select: none;
  min-height: 56px;
}
.learn-head h2 { gap: 9px; }
.learn-count {
  font-family: var(--tnum);
  font-size: 12.5px;
  color: var(--text-dim);
  flex: 0 0 auto;
}
.learn-bar {
  width: 96px;
  height: 5px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  overflow: hidden;
  flex: 0 0 auto;
}
.learn-bar > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: var(--r-full);
  background: var(--brand-grad);
  transition: width var(--dur-slow) var(--ease);
}
.learn-chev {
  color: var(--text-mute);
  font-size: 12px;
  flex: 0 0 auto;
  transition: transform var(--dur) var(--ease);
}
.learn-chev.up { transform: rotate(-90deg); }

.learn-wrap { padding: 4px var(--sp-4) var(--sp-4); }

.learn-level { padding: 14px 0; border-top: 1px solid var(--border); }
.learn-level:first-child { border-top: 0; }
.learn-level.done .learn-lv-head { opacity: .62; }

.learn-lv-head { display: flex; align-items: baseline; gap: 10px; }
.learn-lv-t { font-size: 14px; font-weight: 600; }
.learn-lv-n {
  font-family: var(--tnum);
  font-size: 11.5px;
  color: var(--text-mute);
}
.learn-lv-sub { font-size: 12.5px; color: var(--text-mute); margin: 3px 0 10px; }

.learn-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background var(--dur-fast) var(--ease);
}
.learn-step:hover { background: var(--surface-hover); }
.learn-step.done .learn-step-t { color: var(--text-mute); text-decoration: line-through; }
.learn-step.done .learn-step-txt { opacity: .6; }

/* 勾选框：**必须够大好点**，而且要在触摸设备上也能看到（它是这页唯一的交互） */
.learn-tick {
  width: 20px; height: 20px;
  flex: 0 0 20px;
  margin-top: 1px;
  border: 1.5px solid var(--border-strong);
  border-radius: 6px;
  display: grid;
  place-items: center;
  color: var(--brand-text);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.learn-tick:hover { border-color: var(--brand); }
.learn-tick.on { background: var(--brand-grad); border-color: transparent; }

.learn-step-txt { flex: 1; min-width: 0; }
.learn-step-t { font-size: 13.5px; font-weight: 500; }
.learn-step-d { font-size: 12.5px; color: var(--text-mute); margin-top: 1px; line-height: 1.6; }

/* 「去做」按钮默认淡一点：15 个步骤每行一个实心按钮会吵得没法读 */
.learn-go { flex: 0 0 auto; opacity: .55; transition: opacity var(--dur-fast) var(--ease); }
.learn-step:hover .learn-go, .learn-go:focus-visible { opacity: 1; }
@media (hover: none) { .learn-go { opacity: 1; } }

.learn-src {
  padding: 10px var(--sp-4) 14px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-mute);
  line-height: 1.7;
}
.learn-src a { color: var(--brand); }

@media (max-width: 640px) {
  /* 手机上"说明 + 按钮"并排会把说明挤成一条窄缝，改成两行 */
  .learn-step { flex-wrap: wrap; }
  .learn-step-txt { flex: 1 1 calc(100% - 30px); }
  .learn-go { margin-left: 30px; }
  .learn-bar { width: 56px; }
  .learn-head h2 { font-size: 14px; }
}


/* ---------- Agent 工具速览（learn.js 的 toolCard） ---------- */

.tool-grid {
  display: grid;
  gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
}
@media (max-width: 760px) { .tool-grid { grid-template-columns: 1fr; } }

.tool-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface-2);
  transition: border-color var(--dur-fast) var(--ease);
}
.tool-item:hover { border-color: var(--border-strong); }

.tool-head { display: flex; align-items: center; gap: 8px; }
.tool-ico {
  width: 28px; height: 28px;
  flex: 0 0 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  color: var(--brand);
  background: var(--brand-soft);
}
.tool-ico svg { width: 16px; height: 16px; }
.tool-name { font-size: 14px; font-weight: 600; }
.tool-head .badge { margin-left: auto; }

.tool-what { font-size: 12.5px; line-height: 1.65; color: var(--text-dim); }

/* 「在本控制台」这一栏是这块内容的主体 —— 用左侧品牌色条把它和小字说明分开，
   否则整段都是灰字，读者会跳过。 */
.tool-here {
  display: flex;
  gap: 8px;
  padding: 9px 10px;
  border-left: 3px solid var(--brand);
  border-radius: 4px;
  background: var(--surface);
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--text);
}
.tool-here-tag {
  flex: 0 0 auto;
  color: var(--brand);
  font-weight: 600;
}

.tool-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 4px;
}
.tool-src {
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-mute);
  text-decoration: none;
}
.tool-src:hover { color: var(--brand); text-decoration: underline; }


/* ===== 对话界面美化（对齐参考稿） ===== */
/* 消息区背景：极淡的品牌径向光晕，避免大面积死白 */
.chat-main {
  background:
    radial-gradient(900px 420px at 72% -12%, var(--brand-soft), transparent 62%),
    var(--bg);
}
/* 空态欢迎语：插画放大、标题加重 */
.chat-msgs .empty { padding-top: 12vh; }
.chat-msgs .empty .empty-art { transform: scale(1.18); }
.chat-msgs .empty > div:first-of-type {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-top: 6px;
}
/* 输入卡：悬浮柔投影，圆角更饱满 */
.chat-input-card {
  border-radius: 18px;
  box-shadow: 0 10px 30px -14px rgba(11, 114, 133, .28), var(--shadow-sm);
}
.chat-input-card:focus-within {
  box-shadow: 0 14px 36px -14px rgba(11, 114, 133, .38), var(--ring);
}
/* 发送键：品牌渐变 + 投影 */
.chat-input-bar .send-btn {
  background: var(--brand-grad);
  border: 0;
  color: #fff;
  box-shadow: 0 4px 12px -4px rgba(11, 114, 133, .55);
}
.chat-input-bar .send-btn:hover { filter: brightness(1.07); transform: translateY(-1px); }
.chat-input-bar .send-btn:active { transform: translateY(0); }
/* 会话项：选中态左侧竖条 */
.sess { border-radius: 10px; padding: 9px 11px; }
.sess.active { box-shadow: inset 2.5px 0 0 var(--brand); }


/* ===== 工作流画布美化 ===== */
.canvas-viewport {
  background-color: var(--bg);
  background-image: radial-gradient(var(--border-strong) 1px, transparent 1.2px);
  background-size: 24px 24px;
}
/* 节点卡片：更圆润、悬浮感 */
.wf-node {
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  box-shadow: 0 4px 14px -8px rgba(15, 40, 50, .18);
  transition: box-shadow .15s ease, border-color .15s ease;
}
.wf-node:hover { box-shadow: 0 8px 22px -10px rgba(15, 40, 50, .28); }
.wf-node.sel {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px var(--brand-soft), 0 8px 22px -10px rgba(11,114,133,.3);
}
.wf-node .hd { background: linear-gradient(180deg, var(--surface-2), var(--surface)); }
/* 端口圆点：品牌色更明显 */
.port .dot { border-width: 2px; }
/* 缩放/适配视图按钮聚成一组 */
.canvas-main .toolbar-row .btn,
.canvas-viewport ~ .btn { border-radius: 9px; }


/* 登录页底部公开站入口 */
.auth-pub { margin-top: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; justify-content: center; font-size: 13px; }
.auth-pub-link { color: var(--brand); text-decoration: none; }
.auth-pub-link:hover { text-decoration: underline; }


/* 聊天气泡美化（参考豆包）：助手消息无气泡纯文字，用户消息柔和圆角 */
.msg{margin-bottom:18px}
.msg .bubble{border-radius:4px 18px 18px 18px;box-shadow:none;background:transparent;border:0}
.msg.user .bubble{border-radius:18px 4px 18px 18px;background:var(--brand-grad);color:var(--brand-text);box-shadow:0 6px 16px -8px rgba(11,114,133,.4)}



/* 聊天页打磨：会话项 hover + 输入框悬浮卡片 + 头像 */
.sess{transition:background .15s, transform .15s}
.sess:hover{background:var(--surface-hover)}
.chat-input{padding-bottom:16px}
.chat-input textarea{border:0;background:transparent}
.mini-avatar.fallback{background:var(--brand-grad);color:var(--brand-text)}


/* 手机端聊天输入框安全区 */
@supports(padding-bottom:env(safe-area-inset-bottom)){
  .chat-input{padding-bottom:calc(14px + env(safe-area-inset-bottom))}
}


/* 聊天选择器下拉：限宽 + 长名截断 */
.combo-panel{max-width:320px;max-height:320px;overflow-y:auto}
.combo-item{display:flex;align-items:center;gap:8px;padding:8px 12px}
.combo-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
.chat-pickers select{max-width:160px;text-overflow:ellipsis}


/* 下拉面板美化 */
.combo-panel{border-radius:14px;box-shadow:0 16px 40px -16px rgba(15,40,50,.25);border:1px solid var(--border);padding:6px;max-height:340px}
.combo-item{padding:9px 10px;font-size:13px;border-radius:9px;transition:background .12s}
.combo-item:hover{background:var(--brand-wash)}
.combo-item.active{background:var(--brand-soft)}
.combo-item.selected{color:var(--brand);font-weight:600}
.combo-item.selected::before{content:'✓';margin-right:2px;color:var(--brand);font-weight:700}
.combo-group{padding:8px 10px 4px;font-size:10.5px}
.combo-panel::-webkit-scrollbar{width:8px}
.combo-panel::-webkit-scrollbar-thumb{background:var(--border);border-radius:4px}


/* 选择器触发器胶囊 */
.pick-pill{display:inline-flex;align-items:center;gap:4px;padding:5px 12px;border-radius:999px;background:var(--surface);border:1px solid var(--border);font-size:12.5px;color:var(--text-dim);cursor:pointer;transition:all .15s;max-width:150px}
.pick-pill:hover{border-color:var(--brand);color:var(--brand)}
.pick-pill select{border:0;background:none;max-width:110px;overflow:hidden;text-overflow:ellipsis;cursor:pointer}
/* 模型下拉：面板宽度对齐触发器、不局促 */
.pick-pill .combo-panel{min-width:220px;width:max-content;max-width:280px}
