/* dialogs：通用对话框底座 + 图片灯箱 + 账号登录/配置弹窗。
 * 文件预览弹窗（结构特殊、全屏化）在 files.css。 */

dialog {
  /* 改内边距时改这两个变量：表头靠它们铺满弹窗顶边，.dlg-body 靠左右值把滚动条拉到弹窗边缘 */
  --dlg-pad-y: 26px;
  --dlg-pad-x: 28px;
  /* 表头色带：「抬起」填充色压淡一些叠在面板上，各风格与自定义主题自动跟随；
   * 不用满色，关闭钮悬停用的就是满色 --panel-2，得留出差别 */
  --dlg-head-bg: color-mix(in srgb, var(--panel-2) 60%, transparent);
  background: var(--panel-solid);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: calc(10px * var(--radius-scale));
  padding: var(--dlg-pad-y) var(--dlg-pad-x);
  width: min(420px, 92vw);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto; /* 兜底：没分出 .dlg-body 的弹窗仍整体滚动 */
}
dialog::backdrop { background: var(--backdrop); }

/* 内容超高时只滚动正文：弹窗（或其中的 form）分成 .dlg-head / .dlg-body / .dlg-actions，
 * .dlg-body 以外的兄弟节点（标题、说明、底部按钮、状态行）都固定不动，由 .dlg-body 自己出滚动条。 */
dialog:has(> .dlg-body, > form > .dlg-body) { flex-direction: column; overflow: hidden; }
/* display 只能挂在 [open] 上：作者样式的 display 会盖过 UA 的 dialog:not([open]) { display: none }。
 * 方向与裁剪不能跟着 [open] 走：退场过渡里 display 由 allow-discrete 撑着 flex，[open] 一摘，
 * 方向就回到默认的 row，表头、正文、底栏横排挤成几列，弹窗看着先缩一下才淡出。 */
dialog[open]:has(> .dlg-body, > form > .dlg-body) { display: flex; }
dialog > form:has(> .dlg-body) { flex: 1 1 auto; min-height: 0; }
:is(dialog, dialog > form):has(> .dlg-body) > :not(.dlg-body) { flex: none; }
.dlg-body {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  /* 左右拉到弹窗边缘，滚动条贴边；上下各让 4px，焦点环不被裁。负外边距与内边距相互抵消，版面不变 */
  margin: -4px calc(-1 * var(--dlg-pad-x));
  padding: 4px var(--dlg-pad-x);
}
/* 块级排版里标题的下边距原本会和正文第一个元素的上边距合并；正文自成格式化上下文后不再合并，去掉后者 */
dialog > .dlg-body > :first-child { margin-top: 0; }
/* 同理，正文最后一个元素的下边距原本和底部按钮 6px 的上边距取较大值：在正文末尾放一个带同样上边距的
 * 空伪元素，让两者仍在正文里合并。只用于块级排版的正文，flex 正文里伪元素会多占一份间距 */
dialog > .dlg-body:has(+ .dlg-actions)::after { content: ""; display: block; margin-top: 6px; }
dialog > .dlg-body + .dlg-actions { margin-top: 0; }
/* form 里的正文沿用 form 的纵向间距（各弹窗的 form 间距不尽相同） */
dialog form > .dlg-body { display: flex; flex-direction: column; gap: inherit; }

/* 进出场：打开时从下方一点、略小处淡入，背板同时淡入；关闭反向淡出。
 * 进场靠 @starting-style，各浏览器都有。退场要让关掉的弹窗在顶层多留一个过渡时长
 * （overlay + display 的离散过渡），只有支持 overlay 的浏览器才开：不支持时弹窗一关
 * 就离开顶层，若还 display 着，会掉回文档流里原地闪一下。Safari、Firefox 因此关闭即消失。 */
dialog { --dlg-from: translateY(8px) scale(.97); }
dialog[open] { transition: opacity var(--dur) var(--ease-out), transform var(--dur) var(--ease-out); }
dialog[open]::backdrop { transition: opacity var(--dur) var(--ease-out); }
@starting-style {
  dialog[open] { opacity: 0; transform: var(--dlg-from); }
  dialog[open]::backdrop { opacity: 0; }
}
@supports (overlay: auto) {
  dialog, dialog::backdrop {
    transition: opacity var(--dur-fast) var(--ease-in), transform var(--dur-fast) var(--ease-in),
      overlay var(--dur-fast) allow-discrete, display var(--dur-fast) allow-discrete;
  }
  /* 退场途中已不是模态框，不能再挡住底下页面的点击 */
  dialog:not([open]) { opacity: 0; transform: var(--dlg-from); pointer-events: none; }
  dialog:not([open])::backdrop { opacity: 0; }
}
@media (max-width: 760px) { dialog { --dlg-from: translateY(24px); } }

dialog h2 { margin: 0 0 16px; font-size: 16px; }
dialog form { display: flex; flex-direction: column; gap: 14px; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
dialog input[type="text"], dialog input[type="number"], dialog input[type="password"],
dialog select, dialog .select-trigger, dialog textarea { width: 100%; }
dialog textarea { resize: vertical; }
.dlg-git-connections { width: min(720px, 94vw); }
.dlg-git-connections p { overflow-wrap: anywhere; white-space: pre-line; }
.dlg-git-connections input { width: 100%; }
.dlg-git-connections input[type="checkbox"] { width: auto; }
.dlg-git-connections pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 240px; overflow-y: auto; font-size: 12px; }
.git-connection-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.git-connection-row { padding: 14px 0; border-bottom: 1px solid var(--line); }
/* Git 操作进度：标题行（操作 · 阶段 + 百分比）、进度条、字节与速率 + 取消钮。
 * 挂在弹窗正文下方，正文滚动时它不动；「操作记录」里的活动操作也用这一块。 */
.git-operation-progress {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px 12px;
  margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line);
}
[data-active] > .git-operation-progress:first-child { margin-top: 0; }
.git-operation-progress > p { margin: 0; font-size: 13px; color: var(--text); overflow-wrap: anywhere; white-space: normal; }
.git-op-pct { font-size: 12px; color: var(--muted); }
.git-operation-progress > .progress { grid-column: 1 / -1; }
.git-op-meta { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.git-operation-progress > button { justify-self: end; }

/* 并排两列（主机+端口、用户名+密码）：窄屏落回单列 */
.dlg-row { display: flex; gap: 12px; }
.dlg-row > label { flex: 1; min-width: 0; }
.dlg-row > label.dlg-narrow { flex: 0 0 108px; }
@media (max-width: 480px) {
  .dlg-row { flex-direction: column; }
  .dlg-row > label.dlg-narrow { flex: 1; }
}

/* ---- 安装技能弹窗：本地上传 / 官方市场两个来源 ---- */
.dlg-skill { width: min(760px, 94vw); }
.skill-src-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px;
}
.skill-target { color: var(--muted); font-size: 12px; }
.skill-target b { color: var(--text); font-weight: 600; }

.skill-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; width: 100%; min-height: 168px; padding: 20px; text-align: center;
  border: 1px dashed var(--line); border-radius: calc(10px * var(--radius-scale));
  background: transparent; color: var(--text); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.skill-drop:hover, .skill-drop.over { border-color: var(--accent); background: var(--panel-2); }
.skill-drop-main { font-size: 14px; }
.skill-drop-hint { color: var(--muted); font-size: 12px; line-height: 1.7; }

.market-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.market-bar input[type="search"] { flex: 1; min-width: 0; }
.market-bar :is(select, .select-trigger) { flex: 0 0 132px; }
.market-list {
  height: min(48vh, 420px); overflow-y: auto;
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
}
.market-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.market-row:last-child { border-bottom: none; }
.market-row:hover { background: var(--panel-2); }
.market-info { flex: 1; min-width: 0; }
.market-name { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.market-name b { font-size: 13px; }
.market-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: calc(5px * var(--radius-scale)); padding: 1px 6px; }
.market-tag.has-skills { color: var(--diff-add); border-color: color-mix(in srgb, var(--diff-add) 45%, transparent); }
.market-desc {
  margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.market-foot { margin: 10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.7; }
.market-empty { padding: 28px 12px; text-align: center; color: var(--muted); font-size: 13px; }

@media (max-width: 560px) {
  .market-bar { flex-wrap: wrap; }
  .market-bar :is(select, .select-trigger) { flex: 1; }
}

/* ---- 弹窗统一头部：标题居左，✕ 关闭钮固定右上角（全部弹窗共用） ---- */
.dlg-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  margin: 0 0 16px;
}
/* 弹窗里的表头是一条贴边色带，和正文区分开（Git 管理页里的页内表头不受影响） */
:is(dialog, dialog > form) > .dlg-head {
  margin: calc(-1 * var(--dlg-pad-y)) calc(-1 * var(--dlg-pad-x)) 18px;
  padding: 18px var(--dlg-pad-x) 16px;
  background: var(--dlg-head-bg);
  border-bottom: 1px solid var(--line);
}
dialog > form > .dlg-head { margin-bottom: 4px; } /* 再加上 form 自带的 gap */
.dlg-head h2 { margin: 0; }
/* 标题下带一行说明时，两者一起留在色带里 */
.dlg-title-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.dlg-desc { margin: 0; }
.dlg-title-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
/* 弹窗里的「?」：说明框在图标下方居中，免得撑出弹窗 */
.dlg-help .help-tip { left: 50%; transform: translateX(-50%); width: min(320px, 80vw); font-weight: 400; }
.dlg-x {
  flex: none;
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  margin: -6px -10px 0 0; /* 视觉贴向弹窗右上角 */
  background: transparent; border: none; border-radius: calc(7px * var(--radius-scale));
  color: var(--muted); font-size: 14px; line-height: 1;
}
.dlg-x:hover { color: var(--text); background: var(--panel-2); }
.dlg-x:disabled { opacity: 0.4; cursor: not-allowed; }
.dlg-x:disabled:hover { color: var(--muted); background: transparent; }
.skill-drop > .ui-icon { width: 28px; height: 28px; color: var(--muted); margin-bottom: 4px; }

/* 弹窗内勾选行：通用 dialog label 是纵向布局，勾选框必须与文字同行 */
dialog label.check {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
  cursor: pointer;
}
dialog label.check input { margin: 0; flex: none; }
.field-hint { font-size: 12px; color: var(--muted); opacity: 0.85; line-height: 1.6; }
.radio-row { display: flex; gap: 18px; }
.radio { flex-direction: row !important; align-items: center; color: var(--text); }

/* Agent 类型选择卡：官方图标 + 名称，选中项亮出品牌色描边与浅底 */
.agent-row { display: flex; gap: 10px; }
.agent-opt {
  position: relative;
  flex: 1;
  flex-direction: row !important; align-items: center; justify-content: center;
  gap: 8px;
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  padding: 11px 10px;
  color: var(--muted); font-size: 13.5px;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.agent-opt input { position: absolute; opacity: 0; pointer-events: none; }
.agent-opt .agent-ico { opacity: 0.55; transition: opacity 0.15s ease; }
.agent-opt:hover { border-color: var(--muted); }
.agent-opt:has(input:checked) {
  color: var(--text);
  border-color: color-mix(in srgb, var(--brand) 55%, transparent);
  background: color-mix(in srgb, var(--brand) 10%, transparent);
}
.agent-opt:has(input:checked) .agent-ico { opacity: 1; }
.agent-opt:has(input:focus-visible) { outline: 2px solid var(--amber); outline-offset: 1px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---- 图片灯箱：固定窗口大小，图片等比缩放完整展示，不出现滚动条。
   通用 dialog 规则会把 width 锁成 420px，这里必须显式覆盖 ---- */
.dlg-img {
  background: transparent; border: none; padding: 0;
  width: min(1280px, 92vw);
  height: min(86vh, 960px);
  max-width: 92vw; max-height: 86vh;
  overflow: hidden;
}
.dlg-img { flex-direction: column; } /* 方向不挂 [open]，原因见上方 .dlg-body 规则 */
.dlg-img[open] { display: flex; }
.dlg-img { --dlg-from: scale(.94); } /* 灯箱是从缩略图「放大」出来的，不做上移 */
.dlg-img::backdrop { background: var(--backdrop-strong); }
.dlg-img img {
  flex: 1; min-height: 0;
  width: 100%;
  object-fit: contain;
  cursor: zoom-out;
}
.lb-bar {
  flex: none;
  display: flex; justify-content: center; align-items: center; gap: 12px;
  padding: 10px 2px 0;
  color: var(--muted); font-size: 12px;
}
.lb-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 灯箱 ✕：悬浮在图片右上角。灯箱背板两个主题下都是深色，
 * 所以这枚钮固定深底浅字，不跟随主题。 */
.lb-x {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; margin: 0;
  background: var(--overlay-chip); border-radius: var(--radius-round);
  color: #dfe3ea; font-size: 15px;
}
.lb-x:hover { background: rgba(6, 8, 12, 0.88); color: #fff; }

/* ---- 账号登录 / 配置对话框 ---- */
.dlg-auth { width: min(580px, 94vw); }
.auth-body { display: flex; flex-direction: column; gap: 12px; }
.auth-hint { margin: 0; font-size: 12px; line-height: 1.7; color: var(--muted); }
.auth-linkrow {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  padding: 8px 10px; background: var(--panel-2);
  min-width: 0;
}
.auth-link {
  flex: 1; min-width: 0;
  font-size: 11px; color: var(--amber); text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.auth-link:hover { text-decoration: underline; }
.dlg-auth input[type="text"], .dlg-auth input[type="password"] { width: 100%; }
.auth-msg { margin: 10px 0 0; font-size: 12px; color: var(--green); }
.auth-msg.err { color: var(--red); }
.auth-modes {
  display: flex; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale)); overflow: hidden;
}
.auth-modes .seg {
  flex: 1; padding: 8px 0; font-size: 12px;
  background: var(--panel); color: var(--muted); border: 0; cursor: pointer;
}
.auth-modes .seg + .seg { border-left: 1px solid var(--line); }
.auth-modes .seg.active { background: var(--panel-2); color: var(--text); font-weight: 600; }
.auth-keyrow { display: flex; gap: 8px; align-items: center; }
.auth-keyrow :is(select, .select-trigger) { flex: 1; min-width: 0; }
.auth-models {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 180px; overflow-y: auto;
  padding: 10px; border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  background: var(--panel-2);
}
.auth-model-chip {
  font-size: 11px; padding: 3px 8px; border-radius: var(--radius-pill);
  border: 1px solid var(--line); background: var(--panel);
  color: var(--text); cursor: pointer;
}
.auth-model-chip:hover { border-color: var(--amber); }
.auth-model-chip.in { color: var(--muted); border-style: dashed; cursor: default; }
.auth-model-chip.in:hover { border-color: var(--line); }

/* ---- 账号可用模型：勾选 + 每个模型的思考强度 + 默认模型 ---- */
.dlg-model-price { width: min(460px, 94vw); }
.dlg-model-price form { gap: 12px; }
.dlg-model-price .field-hint { margin: 0; }
.mp-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.mp-grid input { width: 100%; }
.mp-catalog { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale)); }
.mp-catalog .field-hint { flex: 1; min-width: 200px; }
.dlg-acct-models { width: min(760px, 94vw); }
.dlg-acct-models form { gap: 12px; }
.dlg-acct-models .field-hint { margin: 0; }
.am-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.am-bar input[type="search"] { flex: 1; min-width: 140px; width: auto; }
.am-bar label.check { flex: none; color: var(--text); }
.am-status { white-space: pre-line; }
/* 模型表：列定义在列表上，表头和各行用 subgrid 共用同一组列，
 * 列宽按最长的内容定，换语言或文字长短不一时各行照样对齐。 */
.am-list {
  display: grid; align-content: start;
  /* 名字列至少留出一块，空间不够时先截断强度（完整内容在悬停提示里） */
  grid-template-columns: minmax(min(13em, 32%), 1fr) minmax(0, max-content) max-content max-content;
  column-gap: 14px;
  max-height: min(48vh, 440px); overflow-y: auto;
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  background: var(--panel-solid);
}
.am-list:empty { display: none; }
.am-head, .am-row {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: subgrid;
  align-items: center; row-gap: 4px;
  padding: 7px 12px;
}
.am-head {
  position: sticky; top: 0; z-index: 1;
  padding-block: 6px;
  background: var(--panel-solid); border-bottom: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
/* 表头文字与按钮里的图标左缘对齐（.btn-sm 的左内边距） */
.am-h-effort, .am-h-delegation { padding-left: 10px; }
.am-h-default { justify-self: center; }
.am-row { border-bottom: 1px solid var(--line-soft); }
.am-row:last-child { border-bottom: 0; }
.am-row.off .am-name, .am-row.off .am-effort, .am-row.off .am-delegation, .am-row.off .am-default { opacity: 0.55; }
dialog label.am-pick { min-width: 0; color: var(--text); }
.am-name { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.am-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.am-label, .am-id { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.am-id { font-size: 11px; color: var(--muted); }
.am-tag {
  flex: none;
  font-size: 11px; line-height: 1.5; padding: 0 7px; border-radius: var(--radius-pill);
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.am-tag[hidden] { display: none; }
.am-effort, .am-delegation {
  justify-self: start; justify-content: flex-start; max-width: 100%; min-width: 0;
  font-size: 12px; overflow: hidden; white-space: nowrap; color: var(--muted);
}
.am-effort .action-label, .am-delegation .action-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.am-effort.on { color: var(--text); }
dialog label.am-default { justify-self: center; gap: 6px; font-size: 12px; white-space: nowrap; }
.am-default-text { display: none; }
.am-empty { grid-column: 1 / -1; padding: 12px; }
.am-add { display: flex; gap: 8px; }
.am-add input { flex: 1; min-width: 0; }
/* 窄屏：去掉表头，每行两层——名字与默认在上，强度与跑腿在下（强度自带前缀） */
@media (max-width: 560px) {
  .am-list { display: flex; flex-direction: column; }
  .am-head { display: none; }
  .am-row { grid-template-columns: minmax(0, 1fr) auto; column-gap: 8px; padding: 8px 10px; }
  .am-row > .am-pick { grid-column: 1; grid-row: 1; }
  .am-row > .am-default { grid-column: 2; grid-row: 1; justify-self: end; }
  .am-row > .am-effort { grid-column: 1; grid-row: 2; margin-left: 16px; }
  .am-row > .am-delegation { grid-column: 2; grid-row: 2; justify-self: end; }
  .am-effort .action-label::before { content: attr(data-k); }
  .am-default-text { display: inline; }
}

/* ---- 额度管理弹窗 ---- */
.dlg-quota { width: min(560px, 94vw); }
.q-body { display: flex; flex-direction: column; gap: 18px; }

.q-balance {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: calc(8px * var(--radius-scale));
  padding: 12px 14px;
}
.q-bal-main { display: flex; align-items: baseline; gap: 10px; }
.q-bal-label { font-size: 12.5px; color: var(--muted); }
.q-bal-num { font-size: 22px; font-weight: 600; color: var(--text); }
/* 余额为零或负：这个用户已经停在门外了。 */
.q-bal-num.neg { color: var(--red); }
.q-bal-sub { margin-top: 4px; font-size: 11.5px; color: var(--muted); }

.q-block-title { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.q-modes { display: flex; flex-direction: column; gap: 6px; }
.q-mode {
  flex-direction: row !important; align-items: baseline; gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line); border-radius: calc(7px * var(--radius-scale));
  color: var(--text); font-size: 13px; cursor: pointer;
}
.q-mode:hover { border-color: var(--muted); }
.q-mode:has(input:checked) {
  border-color: var(--amber-dim);
  background: color-mix(in srgb, var(--amber) 8%, transparent);
}
.q-mode input { margin: 0; flex: none; }
.q-mode .q-mode-name { flex: none; font-weight: 500; }
.q-mode .q-mode-desc { font-size: 11.5px; color: var(--muted); }
.q-block .field-hint { margin: 8px 0 0; }

.q-grant { display: flex; gap: 8px; flex-wrap: wrap; }
.q-grant input { flex: 1; min-width: 130px; width: auto; }
.q-grant .btn { flex: none; }

.q-ledger { display: flex; flex-direction: column; max-height: 210px; overflow-y: auto; }
.q-led-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 5px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.q-led-row:last-child { border-bottom: none; }
.q-led-ts { flex: none; color: var(--muted); font-size: 11px; }
.q-led-reason { flex: none; font-size: 11px; color: var(--muted); }
.q-led-reason.grant { color: var(--green); }
.q-led-reason.adjust { color: var(--warn); }
.q-led-delta { flex: none; min-width: 82px; text-align: right; }
.q-led-delta.in { color: var(--green); }
.q-led-delta.out { color: var(--text); }
.q-led-after { flex: none; color: var(--muted); font-size: 11px; }
.q-led-note {
  min-width: 0; flex: 1; text-align: right;
  color: var(--muted); font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.q-empty { color: var(--muted); font-size: 12.5px; padding: 6px 2px; }
.q-ledger-skeleton { display: flex; flex-direction: column; }

/* 窄屏：流水行的时间/类型/金额/余额四项都是定宽，加起来约 283px，而 320px 手机上
   弹窗里能用的宽度只有 264px 左右——四项自己就撑破了，备注再怎么省略也没用。
   把备注放到第二行，金额靠右浮，其余三项挤在第一行。 */
@media (max-width: 760px) {
  .q-led-row { flex-wrap: wrap; gap: 6px 8px; }
  .q-led-delta { min-width: 0; margin-left: auto; }
  .q-led-note { flex-basis: 100%; text-align: left; }
}

/* ---- 账号弹窗里的出口代理选择器（proxies.ts 的 mountProxyPicker） ----
   代理多起来之后（一个账号池挂几十个出口是常态）原生 <select> 既翻不动也看
   不出哪个是通的，所以自绘：触发器 + 搜索框 + 每行带一个探测按钮。 */
.proxy-pick { position: relative; }
.pp-trigger {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  color: var(--text);
  font-size: 13px;
  padding: 9px 11px;
}
.pp-trigger:hover { border-color: var(--muted); }
.pp-trigger.open { border-color: var(--accent); }
.pp-label {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pp-label.none { color: var(--muted); }
.pp-caret { flex: none; color: var(--muted); font-size: 11px; }

.pp-menu {
  position: absolute; z-index: 5;
  left: 0; right: 0; top: calc(100% + 6px);
  background: var(--panel-solid);
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.pp-search { padding: 8px; border-bottom: 1px solid var(--line); }
.pp-search input { width: 100%; font-size: 13px; }
.pp-list { max-height: 240px; overflow-y: auto; }
.pp-opt {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
}
.pp-opt:last-child { border-bottom: none; }
.pp-opt:hover { background: var(--panel-2); }
.pp-opt.on { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.pp-opt.off { opacity: 0.55; }
.pp-opt-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pp-opt-body b { font-size: 13px; font-weight: 600; color: var(--text); }
.pp-opt-body span {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pp-probe {
  flex: none;
  font-family: var(--mono); font-size: 11px;
  border: 1px solid var(--line); border-radius: calc(4px * var(--radius-scale));
  padding: 1px 6px;
}
.pp-probe.good { color: var(--green); border-color: var(--green-line); }
.pp-probe.bad { color: var(--red); border-color: var(--red-line); }
.pp-test {
  flex: none;
  background: none; border: 1px solid var(--line); border-radius: calc(5px * var(--radius-scale));
  color: var(--muted); font-size: 11.5px;
  padding: 2px 8px;
}
.pp-test:hover { color: var(--text); border-color: var(--accent); }
.pp-check { flex: none; color: var(--accent); font-size: 13px; }

/* ---- 账号额度弹窗（Claude 订阅的 5 小时 / 周窗口） ---- */
.dlg-ausage { width: min(400px, 94vw); }

.au-acct {
  display: flex; align-items: baseline; gap: 8px;
  margin-bottom: 16px;
}
.au-name { font-size: 13.5px; color: var(--text); }
.au-plan {
  flex: none;
  font-size: 11px; color: var(--text);
  border: 1px solid var(--line); border-radius: calc(4px * var(--radius-scale));
  padding: 1px 6px;
}

.au-body, .au-body-skeleton { display: flex; flex-direction: column; gap: 14px; }

.au-row-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.au-row-label { font-size: 13px; color: var(--text); }
.au-row-pct { font-size: 13px; font-weight: 600; color: var(--text); }
/* 八成起转琥珀、满格转红：颜色是这个弹窗唯一要传达的判断。 */
.au-row-pct.warn { color: var(--warn); }
.au-row-pct.full { color: var(--red); }

.au-track {
  height: 6px; margin-top: 6px;
  background: var(--panel-2);
  border-radius: calc(3px * var(--radius-scale)); overflow: hidden;
}
.au-fill {
  height: 100%;
  background: var(--green);
  border-radius: calc(3px * var(--radius-scale));
  transition: width 0.25s ease;
}
.au-fill.warn { background: var(--warn); }
.au-fill.full { background: var(--red); }

.au-row-sub { margin-top: 5px; font-size: 11.5px; color: var(--muted); }

.au-msg { font-size: 12.5px; color: var(--muted); padding: 8px 0; }
.au-msg.err { color: var(--red); }

.au-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 18px;
}
.au-fetched { font-size: 11px; color: var(--muted); }

/* Account creation and authentication share one calm, responsive form. */
.acct-fields { border: 0; padding: 0; margin: 0 0 20px; min-width: 0; }
.acct-fields:disabled { opacity: .65; pointer-events: none; }
.acct-field-label { display: block; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.acct-basics { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.acct-basics > * { min-width: 0; }
.acct-basics label { margin: 0; }
.acct-advanced { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
#acct-users-row { margin-top: 16px; }

/* ---- 用户多选（user-picker.ts）：账号使用范围、智能决策的「指定用户」 ----
 * 弹窗和设置页共用，所以选择器都挂在 .user-picker 下，盖过通用的 dialog label 纵向布局。
 * 这些元素自己设了 display，hidden 属性要显式补回 display: none。 */
.up-field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.up-field[hidden] { display: none; }
.up-field > .up-label, .up-field > .acct-field-label { margin: 0; font-size: 12.5px; color: var(--muted); }
.user-picker { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.user-picker [hidden] { display: none !important; }
.up-bar { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; }
.user-picker .up-search { flex: 1 1 180px; min-width: 0; width: auto; padding-block: 6px; font-size: 13px; }
.user-picker label.up-all { flex: none; color: var(--text); }
.up-count { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.up-list {
  display: flex; flex-direction: column;
  max-height: min(40vh, 272px); overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale));
  background: var(--panel-solid);
}
.user-picker .up-row {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  min-height: 38px; margin: 0; padding: 6px 12px;
  font-size: 13px; color: var(--text); cursor: pointer;
}
/* 分隔线只画在「前面还有可见行」的行上：筛选藏掉若干行后不会多出一道 */
.user-picker .up-row:not([hidden]) ~ .up-row:not([hidden]) { border-top: 1px solid var(--line-soft); }
.user-picker .up-row:hover:not(.up-admin, .up-missing) { background: var(--panel-2); }
.user-picker input[type="checkbox"] { width: auto; margin: 0; flex: none; }
.user-picker :is(.up-admin, .up-missing) { cursor: default; color: var(--muted); }
.up-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-tag {
  flex: none; margin-left: auto;
  font-size: 11px; line-height: 1.5; padding: 0 7px; border-radius: var(--radius-pill);
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.up-missing .up-tag { color: var(--warn); border-color: var(--warn-line); }
.up-status { margin: 0; padding: 10px 12px; font-size: 12.5px; color: var(--muted); }
.up-list > .btn { align-self: flex-start; margin: 0 12px 10px; }
.up-note { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.user-picker .up-error:empty { display: none; }
.acct-advanced summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.acct-advanced label { margin-top: 12px; }
.dlg-auth .auth-body > label { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.dlg-auth input[type="url"] { width: 100%; }
.dlg-auth .auth-modes .seg { transition: background .15s, color .15s; }
.dlg-auth .auth-link { font-size: 13px; }
#auth-gen { align-self: flex-start; }
#auth-finish { align-self: flex-end; }
@media (max-width: 540px) {
  .acct-basics { grid-template-columns: 1fr; gap: 12px; }
  .auth-keyrow { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) { .dlg-auth .auth-modes .seg { transition: none; } }

/* 模型能力编辑：沿用统一弹窗与勾选控件。 */
.reasoning-dialog fieldset { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: calc(6px * var(--radius-scale)); }
.reasoning-dialog fieldset > div { display: grid; gap: 8px; }
.reasoning-dialog .field-hint { margin: 0; }

/* Environment checks stay readable in a narrow dialog; status is text as well as color. */
.diagnostics-dialog { width: min(660px, 94vw); }
.diagnostic-checks { list-style: none; padding: 0; margin: 16px 0; }
.diagnostic-checks li { border-top: 1px solid var(--line); padding: 12px 0; }
.diagnostic-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.diagnostic-heading [data-state] { flex-shrink: 0; font-size: 12px; color: var(--muted); }
.diagnostic-heading [data-state="passed"] { color: var(--green); }
.diagnostic-heading [data-state="failed"] { color: var(--red); }
.diagnostic-checks p { margin: 6px 0 0; font-size: 13px; }
.diagnostic-reference, .diagnostics-dialog p { overflow-wrap: anywhere; }
.diagnostics-dialog .dlg-actions { flex-wrap: wrap; }
@media (max-width: 600px) { .diagnostics-dialog { --dlg-pad-y: 18px; --dlg-pad-x: 18px; } }

/* 界面主题（themes.ts）：三组列表——我的主题、全站主题、内置风格。每行左边色卡，
 * 中间名称与「基于哪个风格 · 作者 · 说明」，右边「使用」与导出/删除图标按钮。 */
.dlg-themes { width: min(620px, 94vw); }
.themes-status { margin: 0 0 12px; padding: 8px 10px; font-size: 12.5px; line-height: 1.6; border-radius: calc(6px * var(--radius-scale)); overflow-wrap: anywhere; }
.themes-status.ok { color: var(--green); background: color-mix(in srgb, var(--green) 10%, transparent); }
.themes-status.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.themes-status.error { color: var(--red); background: color-mix(in srgb, var(--red) 10%, transparent); }
.themes-body { display: flex; flex-direction: column; gap: 18px; }
.themes-section-head { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.themes-section-head h3 { margin: 0; font-size: 13.5px; }
.themes-section-head .btn { margin-left: auto; }
.themes-count { font-size: 11.5px; color: var(--muted); }
.themes-section-hint { margin: 2px 0 8px; font-size: 12px; color: var(--muted); }
/* 按圆角裁剪：选中行的底色是直角块，不裁剪就会在首尾两行的圆角处溢出边框 */
.themes-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: calc(8px * var(--radius-scale)); overflow: hidden; }
.themes-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 10px; }
.themes-row + .themes-row { border-top: 1px solid var(--line-soft); }
.themes-row.active { background: color-mix(in srgb, var(--amber) 8%, transparent); }
.themes-swatch { width: 26px; height: 26px; border-radius: calc(6px * var(--radius-scale)); }
.themes-row-text { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.themes-row-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.themes-row-meta { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.themes-row-actions { display: flex; flex: none; align-items: center; gap: 6px; }
.themes-use:disabled { opacity: 1; color: var(--amber); }
.themes-empty { padding: 14px 12px; font-size: 12.5px; color: var(--muted); }
/* 窄屏仍是一行：名称与说明省略，按钮挨紧，不让每行因换行变成两倍高 */
@media (max-width: 480px) {
  .themes-row { gap: 10px; padding: 8px; }
  .themes-row-actions { gap: 2px; }
  .themes-swatch { width: 22px; height: 22px; }
}

/* 主题编辑器（theme-editor.ts）：贴右侧的全高面板，窄屏改成底部抽屉。
 * 背板透明且不磨砂（压过各风格给 dialog::backdrop 加的遮罩）：改动是实时写在整页上的，
 * 面板旁边露出来的页面就是预览，压暗或模糊了就看不准。 */
.dlg-theme-editor {
  inset: 0 0 0 auto; margin: 0 0 0 auto; padding: 0;
  width: min(460px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh;
  border-width: 0 0 0 1px; border-radius: 0; overflow: hidden;
  box-shadow: var(--shadow-lg);
  --dlg-from: translateX(24px);
}
.dlg-theme-editor { flex-direction: column; } /* 方向不挂 [open]：退场时 display 仍是 flex */
.dlg-theme-editor[open] { display: flex; }
:root[data-skin] dialog.dlg-theme-editor::backdrop { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.dlg-theme-editor .dlg-head { flex: none; margin: 0; padding: 18px 20px 12px; }
.te-body { display: flex; flex: 1; flex-direction: column; gap: 14px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 20px; }
.dlg-theme-editor > .themes-status { flex: none; margin: 0 20px 10px; }
.te-ai-fallback { flex: none; margin: 0 20px 10px; width: auto; font-size: 11.5px; resize: none; }
.te-actions { display: flex; flex: none; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.te-actions #te-ai { margin-right: auto; }

/* 样张：按钮、输入框、状态色、文字层级、代码块、终端，都直接取令牌 */
.te-specimen { display: flex; flex: none; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: calc(10px * var(--radius-scale)); background: var(--panel); }
.te-spec-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.te-spec-field { flex: 1; min-width: 96px; padding: 5px 10px; border: 1px solid var(--line); border-radius: calc(6px * var(--radius-scale)); background: var(--field); color: var(--muted); font-size: 12.5px; }
.te-chip { padding: 2px 9px; border: 1px solid; border-radius: var(--radius-pill); font-size: 11.5px; }
.te-chip.ok { color: var(--green); border-color: var(--green-line); }
.te-chip.warn { color: var(--warn); border-color: var(--warn-line); }
.te-chip.err { color: var(--red); border-color: var(--red-line); }
.te-spec-text { margin: 0; color: var(--text); font-size: 13px; }
.te-spec-muted { color: var(--muted); }
.te-spec-amber { color: var(--amber); }
.te-spec-code { margin: 0; padding: 8px 10px; overflow-x: auto; border: 1px solid var(--code-line); border-radius: calc(6px * var(--radius-scale)); background: var(--code-bg); color: var(--text); font: 12px/1.55 var(--mono); white-space: pre; }
.te-spec-code .kw { color: var(--syntax-keyword); }
.te-spec-code .fn { color: var(--syntax-function); }
.te-spec-term { padding: 8px 10px; border-radius: calc(6px * var(--radius-scale)); background: var(--term-bg); color: var(--term-fg); font: 12px/1.55 var(--mono); }
.te-spec-term .sel { background: var(--term-sel); }
.te-spec-term .cursor { display: inline-block; width: .6em; height: 1.15em; margin-left: 3px; vertical-align: text-bottom; background: var(--term-cursor); }

.te-fields { display: flex; flex: none; flex-direction: column; gap: 10px; }
.te-switches { display: flex; flex: none; flex-wrap: wrap; justify-content: space-between; gap: 8px; }
.te-panel { display: flex; flex: none; flex-direction: column; }
.te-panel[hidden] { display: none; }
.te-group h3 { margin: 12px 0 2px; color: var(--muted); font-size: 12px; font-weight: 600; }
.te-group:first-child h3 { margin-top: 0; }

/* 一行一个令牌：取色块 | 名称与令牌名 | 取值 | 恢复。没改过的取值留空，占位符显示继承来的值 */
.te-token { display: grid; grid-template-areas: "color label value reset"; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 46%) auto; align-items: center; gap: 8px; padding: 5px 0; }
.te-token + .te-token { border-top: 1px solid var(--line-soft); }
.te-color { grid-area: color; width: 28px; height: 28px; padding: 2px; border: 1px solid var(--line); border-radius: calc(6px * var(--radius-scale)); background: var(--field); cursor: pointer; }
.te-color[hidden] { display: block; visibility: hidden; }
dialog .te-token-text { grid-area: label; display: flex; flex-direction: column; gap: 1px; min-width: 0; color: var(--text); font-size: 12.5px; }
.te-token-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.te-token.set .te-token-name::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 6px; vertical-align: middle; border-radius: 50%; background: var(--amber); }
.te-token-text code { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
dialog input.te-value { grid-area: value; min-width: 0; padding: 5px 8px; font-size: 12px; }
.te-reset { grid-area: reset; }
.te-scale { grid-template-areas: "label value reset"; grid-template-columns: minmax(0, 1fr) minmax(0, 46%) 40px; }
.te-scale input[type="range"] { grid-area: value; width: 100%; accent-color: var(--accent); }
.te-scale-value { grid-area: reset; color: var(--muted); font-size: 12px; text-align: right; }
#te-json { min-height: 340px; font-size: 12px; line-height: 1.5; white-space: pre; }

@media (max-width: 760px) {
  .dlg-theme-editor {
    inset: auto 0 0 0; margin: auto 0 0 0;
    width: 100vw; height: 68dvh; max-height: 68dvh;
    border-width: 1px 0 0;
    border-radius: calc(14px * var(--radius-scale)) calc(14px * var(--radius-scale)) 0 0;
    --dlg-from: translateY(24px);
  }
  .dlg-theme-editor .dlg-head { padding: 14px 16px 10px; }
  .te-body { padding: 12px 16px; }
  .te-actions { padding: 10px 16px 14px; }
  .te-token { grid-template-areas: "color label reset" ". value value"; grid-template-columns: 28px minmax(0, 1fr) auto; row-gap: 4px; }
  .te-scale { grid-template-areas: "label reset" "value value"; grid-template-columns: minmax(0, 1fr) 40px; }
}
