/* ─────────────────────────────────────────────
   组件：按钮 / 徽章 / 卡片内元素 / 表单 / 开关 / 弹窗
   颜色一律取 tokens.css 的语义变量，浅色 / 深色共用同一组声明，
   不在本文件里写死任何色值（必要的浅色 tint 用 color-mix 从令牌派生）。
   ───────────────────────────────────────────── */

/* ─── 按钮 ───
   基础 button 保留一层默认外观：账号行、代理表单等处由 JS 动态生成按钮，
   出厂样式能保证它们不会变成没有边框的裸文字。
   .btn 用于静态结构，样式更精细。
   填充与描边取 --control-* 一组：它们与承载面（--surface / --surface-2）分开，
   于是按钮在内容表面提亮之后依然立得住，不再需要靠压暗整块内容来衬托。 */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--control-border);
  border-radius: var(--r-md);
  background: var(--control-bg);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  box-shadow: var(--shadow-1);
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .08s ease;
}

button:hover:not(:disabled) { background: var(--control-hover); border-color: var(--control-border-hover); }
button:active:not(:disabled) { transform: translateY(.5px); }
button:disabled { opacity: .45; box-shadow: none; cursor: not-allowed; }

/* 主按钮：平铺主色 + 近白文字。前景从 --surface 向白提亮派生：浅色得到纯白，
   深色得到近白；直接用 --surface / --primary-fg 会在深色主题压出近黑或浅蓝，读不清。
   背景去掉原来的竖向渐变，改用平色 + --glow，与新体系「平色 + 品牌柔光」一致 */
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: color-mix(in srgb, var(--surface) 8%, white);
  font-weight: 600;
  box-shadow: var(--glow);
}

button.primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }

button.danger { color: var(--danger); border-color: var(--danger-bd); background: var(--danger-soft); }

/* 危险按钮 hover 不铺满实色：实色底 + 近白字在深色主题对比不足，
   改成「语义色 × 表面」加深底色，浅色变浅粉、深色变深红，两边都成立 */
button.danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 22%, var(--surface));
  border-color: var(--danger-bd);
}

button.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
button.ghost:hover:not(:disabled) { background: var(--control-hover); color: var(--text); border-color: transparent; }

/* 小号按钮按比例收一号圆角：26px 高配 12.8px 圆角会显得过圆。
   行内控件档（分页、卡片内操作）都落在这一档 */
button.sm { height: 26px; padding: 0 10px; font-size: 12px; border-radius: var(--r-sm); }
button.icon { width: 30px; padding: 0; }
button.icon.sm { width: 26px; }

/* ─── 徽章 ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 21px;
  padding: 1px 9px;
  border: 1px solid var(--control-border);
  border-radius: var(--r-pill);
  background: var(--control-bg);
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.badge.ok { background: var(--ok-soft); border-color: var(--ok-bd); color: var(--ok); }
.badge.warn { background: var(--warn-soft); border-color: var(--warn-bd); color: var(--warn); }
.badge.bad { background: var(--danger-soft); border-color: var(--danger-bd); color: var(--danger); }
.badge.brand { background: var(--primary-soft); border-color: var(--primary-bd); color: var(--primary-fg); }

/* 版本标签：固定配色，国内版附带签到入口 */
.badge.edition-cn { background: var(--cn-soft); border-color: var(--cn-bd); color: var(--cn); }
.badge.edition-intl { background: var(--intl-soft); border-color: var(--intl-bd); color: var(--intl); }

/* 行内状态标签：比徽章更方、更小 */
.badge.tag { min-height: 19px; padding: 0 8px; border-radius: var(--r-xs); font-size: 11px; }
.badge.tag.ok { background: var(--ok-soft); border-color: var(--ok-bd); color: var(--ok); }
.badge.tag.warn { background: var(--warn-soft); border-color: var(--warn-bd); color: var(--warn); }
/* 无状态占位（账号无任何状态可标时用的破折号），不要边框底色 */
.badge.tag.plain { padding: 0; border-color: transparent; background: transparent; color: var(--text-3); }

/* ─── 指标块（.field-grid / .field 沿用既有类名） ─── */
.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 10px;
}

.field {
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}

.field .label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--text-3);
  font-size: 11.5px;
}

.field .value {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-all;
}

.field .value.mono { font-family: var(--font-mono); font-size: 12.5px; font-weight: 500; }
.field .value .sub { color: var(--text-3); font-size: 11.5px; font-weight: 400; }
.field code { font-family: var(--font-mono); font-size: 12.5px; }

/* 复制小按钮 */
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: var(--r-xs);
  background: transparent;
  box-shadow: none;
  color: var(--text-3);
  font-size: 12px;
}

.copy-btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border); color: var(--primary); }
.copy-btn.done { color: var(--ok); }

/* ─── 说明 / 提示 ─── */
.detail { color: var(--text-2); font-size: 12px; line-height: 1.65; }

.hint {
  color: var(--text-2);
  font-size: 11.5px;
  line-height: 1.7;
}

.hint code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  background: var(--surface-3);
}

.hint strong, .detail strong { color: var(--text); }

/* 提示条 */
.banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--info-bd);
  border-radius: var(--r-md);
  background: var(--info-soft);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.65;
}

.banner .ico { flex: 0 0 auto; color: var(--info); font-size: 13px; line-height: 1.5; }
.banner.warn { border-color: var(--warn-bd); background: var(--warn-soft); }
.banner.warn .ico { color: var(--warn); }
.banner.danger { border-color: var(--danger-bd); background: var(--danger-soft); }
.banner.danger .ico { color: var(--danger); }
.banner strong { color: var(--text); }

/* ─── 空状态 ─── */
.empty {
  padding: 30px 16px;
  color: var(--text-3);
  font-size: 12.5px;
  text-align: center;
}

/* ─── 加载指示 ─── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -2px;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── 轻提示 ─── */
#toast {
  position: fixed;
  top: 16px;
  left: 50%;
  z-index: 40;
  display: none;
  max-width: 76vw;
  padding: 10px 16px;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  color: var(--text);
  font-size: 12.5px;
}

#toast.ok { border-color: var(--ok-bd); color: var(--ok); }
#toast.err { border-color: var(--danger-bd); color: var(--danger); }

/* ─── 表单控件 ─── */
input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="time"],
select,
textarea {
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--control-border);
  border-radius: var(--r-md);
  background: var(--control-bg);
  color: var(--text);
  font-size: 12.5px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input[type="text"], input[type="password"], input[type="search"], input[type="number"] { flex: 1 1 auto; }

textarea {
  height: auto;
  min-height: 104px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  resize: vertical;
}

input::placeholder, textarea::placeholder { color: var(--text-3); }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { border-color: var(--control-border-hover); }

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: var(--ring);
}

input:disabled, select:disabled, textarea:disabled { background: var(--surface-3); color: var(--text-3); }

select {
  padding-right: 26px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

input[type="time"] { font-family: var(--font-mono); }
input[type="number"] { max-width: 130px; }

/* 表单行 */
.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.field-row > label { color: var(--text-2); font-size: 12.5px; white-space: nowrap; }

/* 输入框 + 前后缀（affix 的左偏移与 input 自身 10px 内边距对齐） */
.input-affix { position: relative; display: flex; align-items: center; flex: 1 1 auto; }
.input-affix .affix { position: absolute; left: 10px; color: var(--text-3); font-size: 12px; pointer-events: none; }
.input-affix input { padding-left: 28px; }

/* ─── 单选卡片（账号版本 / 代理模式） ─── */
.edition-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.edition-option:hover { border-color: var(--border-strong); background: var(--surface-3); }
.edition-option input { accent-color: var(--primary); margin: 0; }

.edition-option:has(input:checked) {
  border-color: var(--primary-bd);
  background: var(--primary-soft);
  color: var(--primary-fg);
  font-weight: 600;
}

/* ─── 复选 / 单选 ─── */
.check, .radio {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}

.check input, .radio input { accent-color: var(--primary); width: 14px; height: 14px; margin: 0; cursor: pointer; }

/* ─── 开关 ─── */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-2);
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
}

.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.switch .track {
  position: relative;
  flex: 0 0 auto;
  width: 36px;
  height: 21px;
  border-radius: var(--r-pill);
  background: var(--border-strong);
  transition: background .18s ease;
}

/* 滑块近白（同样从 --surface 向白提亮派生）：轨道浅色是浅灰、深色是深灰，
   两种主题下滑块都要比轨道亮才立得住。阴影改用 --shadow-1，不另造投影 */
.switch .track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 8%, white);
  box-shadow: var(--shadow-1);
  transition: transform .18s cubic-bezier(.3, 1.4, .6, 1);
}

.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(15px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }
.switch input:disabled + .track { opacity: .5; }

/* 开关卡片：整行可点，附说明 */
.switch-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}

.switch-card .switch { color: var(--text); font-weight: 500; }
.switch-card .desc { color: var(--text-3); font-size: 11.5px; }
.switch-card.stack { flex-direction: column; align-items: stretch; gap: 10px; }

/* 带 time 控件的 .switch：内部不是开关，要覆盖上面的隐藏处理 */
.switch-time { gap: 9px; cursor: default; }

.switch-time input[type="time"] {
  position: static;
  width: auto;
  height: 28px;
  opacity: 1;
  pointer-events: auto;
}

/* 分段控件（账号页筛选）：槽取 --control-* 一组，与按钮同源 ——
   它现在坐在内容表面上，需要靠自身填充而不是反衬底色来立住。 */
.seg {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--control-border);
  border-radius: var(--r-md);
  background: var(--control-bg);
}

/* 分段项嵌在 .seg 里，圆角要按「外圆角 - 内边距」收一号，
   否则 24px 的项配上控制件的 12.8px 会比容器还圆，接缝处露出毛边 */
.seg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 24px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  box-shadow: none;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}

/* 未选中项用中性叠加：深色叠白、浅色叠黑，同一行声明两边都成立 */
.seg-item:hover:not(:disabled) { background: var(--nav-hover); color: var(--text); }

/* 选中项走品牌浅底，与导航选中态、单选卡片保持一致 */
.seg-item.active {
  background: var(--primary-soft);
  color: var(--primary-fg);
  font-weight: 600;
}

.seg-item .seg-count {
  min-width: 16px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  opacity: 1;
}

.seg-item.active .seg-count { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary-fg); }

/* 计数为 0 的分段弱化，减少视觉噪音 */
.seg-item.zero:not(.active) { opacity: .45; }
.seg-item:disabled { cursor: not-allowed; opacity: .4; }
.seg-item.active:disabled { opacity: .7; }

/* 工具条：一行收住筛选与主操作 */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.toolbar .group { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.toolbar .group > .label { color: var(--text-3); font-size: 11.5px; white-space: nowrap; }
.toolbar .actions { margin-left: auto; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.toolbar .divider { width: 1px; height: 18px; background: var(--border); flex: 0 0 auto; }

/* 窄窗口（≤1120px）：三段筛选与主操作同行会挤，让操作独占一行靠右 */
@media (max-width: 1120px) {
  .toolbar .actions { flex-basis: 100%; margin-left: 0; }
}

/* 提供商筛选下拉：它决定列表里显示哪些家的账号，
   比同排普通下拉重一档，边框取强调色而不是用字重硬顶 */
.model-select {
  max-width: 200px;
  height: 30px;
  border-color: var(--border-strong);
  background-color: var(--surface);
  font-weight: 600;
}

/* ─── 进度条 ─── */
.progress {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.progress > .bar {
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width .3s ease;
}

/* ─── 弹窗 ─── */
/* 遮罩要「两个主题都压暗背景」，但令牌里没有这样的颜色：--text、--bg、--surface
   都随主题翻转，拿它们当蒙层会在深色模式刷出一层白雾。所以按 tokens.css 里
   浅色 tint 同款手法派生，只把基底换成黑，深浅两模式的方向就一致了。 */
.modal-mask {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: color-mix(in srgb, black 46%, transparent);
  backdrop-filter: blur(3px);
}

.modal-mask.open { display: flex; animation: mask-in .16s ease; }

@keyframes mask-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  display: flex;
  flex-direction: column;
  width: min(620px, 100%);
  max-height: 100%;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  overflow: hidden;
  animation: modal-in .2s cubic-bezier(.2, .9, .3, 1);
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--hairline);
}

.modal-head h2 { flex: 1 1 auto; font-size: 14.5px; font-weight: 650; }

/* 关闭按钮是透明底图标钮，圆角沿用 button 的 --r-md */
.modal-head > button {
  width: 28px;
  height: 28px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: var(--text-3);
}

.modal-head > button:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 20px;
  overflow-y: auto;
}

.modal-section {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}

.modal-section h3 { font-size: 12.5px; font-weight: 650; }
.modal-section p { color: var(--text-2); font-size: 12px; line-height: 1.65; }

.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 20px;
  border-top: 1px solid var(--hairline);
  background: var(--surface-2);
}

.modal-foot .spacer { flex: 1 1 auto; }

/* 说明性小字（弹窗内） */
.modal .detail { color: var(--text-3); font-size: 11.5px; }

/* ─── 表格列宽拖动把手 ───
   四张表的表头右缘共用这一枚把手（账号表由 accounts-columns.js 委托，
   模型管理 / 网关 Key / 请求日志由 table-columns.js 委托）：
   常驻一枚 1px 竖线标出可拖的列边界（实时调列宽不必先悬停摸索），
   按住时变主色加粗。
   靠绝对定位挂在宿主单元格上，所以宿主必须是定位元素 —— 三张 table 表的
   表头是 position: sticky（本来就是），请求日志的表头格也单独声明了 relative。
   right: -4px 让竖线正好压住列边界；代价是最后一列不能插把手（钉在表格右缘
   会顶出滚动容器），这一条由各自的脚本负责（请求日志是网格布局、整行填满
   不滚动，末列照插）。

   竖线不随宿主撑满、改定高 20px 垂直居中：四张表的宿主高度参差 —— 账号表
   th 行高 32px（眼睛按钮撑起行盒），32 − 上下各 6px 恰是 20px；模型/网关
   th 上下内边距各多 1px；请求日志的宿主格只有一行字高（~17px），按撑满算
   只剩几像素。定高才保证四条分隔线一样长，20px 即以账号页为准。 */
.col-grip {
  position: absolute;
  top: 0;
  right: -4px;
  width: 9px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}

.col-grip::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 50%;
  height: 20px;
  transform: translateY(-50%);
  width: 1px;
  background: var(--border-strong);
}

.col-grip.active::after { left: 3.5px; width: 2px; background: var(--primary); }

/* 拖动中：全局换光标并禁用选中（拖过文本会触发原生的拖选，把手就「断」了） */
body.col-resizing { cursor: col-resize; user-select: none; }

/* 表格列设置（浮层与列对齐）在 css/table-col-settings.css ——
   它必须排在页面样式之后（要盖过各表写死的默认对齐），所以独立成一层，
   与 select.css / tooltip.css 同一编排。 */

/* ─── 页面级分段布局辅助 ─── */
/* 端点卡片（网关页 / 设置页） */
.endpoint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.endpoint {
  min-width: 0;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.endpoint .k { color: var(--text-3); font-size: 11.5px; }

.endpoint .v {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.endpoint .v .url {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

.endpoint.accent { background: var(--primary-soft); border-color: var(--primary-bd); }
