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

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 26px 28px;
  width: min(420px, 92vw);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
}
dialog::backdrop { background: var(--backdrop); }
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); }

/* 并排两列（主机+端口、用户名+密码）：窄屏落回单列 */
.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: 10px;
  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: 8px;
}
.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: 5px; padding: 1px 6px; }
.market-tag.has-skills { color: #3fb950; border-color: color-mix(in srgb, #3fb950 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;
}
dialog form .dlg-head { margin: 0; } /* form 自带 gap，避免双份间距 */
.dlg-head h2 { margin: 0; }
.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: 7px;
  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(--amber); 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: 8px;
  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[open] { display: flex; flex-direction: column; }
.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: 50%;
  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: 8px;
  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: 8px; 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: 8px;
  background: var(--panel-2);
}
.auth-model-chip {
  font-size: 11px; padding: 3px 8px; border-radius: 999px;
  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-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: 8px;
  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: 7px;
  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(--amber); }
.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; }

/* 窄屏：流水行的时间/类型/金额/余额四项都是定宽，加起来约 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: 8px;
  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);
  border: 1px solid var(--line); border-radius: 8px;
  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: 4px;
  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: 5px;
  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(--amber);
  border: 1px solid var(--amber-dim); border-radius: 4px;
  padding: 1px 6px;
}

.au-body { 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(--amber); }
.au-row-pct.full { color: var(--red); }

.au-track {
  height: 6px; margin-top: 6px;
  background: var(--panel-2);
  border-radius: 3px; overflow: hidden;
}
.au-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.25s ease;
}
.au-fill.warn { background: var(--amber); }
.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-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: 6px; }
.reasoning-dialog fieldset > div { display: grid; gap: 8px; }
.reasoning-dialog .field-hint { margin: 0; }
