/* 管理台共用样式：仪表盘式浅色工具风。
   颜色只有三个含义：运行/便宜（玉绿）、等待/高峰（赭黄）、失败（深红），
   加上一个交互色（深青）。除此之外全部是中性灰。 */
:root {
  --shell: #e9edf1;
  --panel: #ffffff;
  --sunk: #f2f5f7;            /* 面板内的下沉块（表头、空柱、轨道底） */
  --rule: #dbe1e7;
  --rule-strong: #c3cbd4;
  --ink: #16202b;
  --ink-2: #55616e;
  --accent: #145c6b;          /* 交互：链接、焦点、选中、主按钮 */
  --accent-soft: #e4eef1;
  --live: #0d6e52;            /* 运行中 / 错峰便宜时段 / 成功 */
  --live-soft: #e6f2ed;
  --hold: #8a5a12;            /* 暂停 / 高峰 / 等待 / 提醒 */
  --hold-soft: #f6efe2;
  --alarm: #ab2b22;           /* 失败 / 丢弃 */
  --alarm-soft: #f8ebea;
  --radius: 8px;
  --radius-sm: 6px;
  --control-h: 32px;
  --t-readout: 22px;
  --t-body: 13px;
  --t-meta: 12px;
}
* { box-sizing: border-box; }
/* 作者样式里的 button{display:inline-flex} 会盖掉 UA 的 [hidden]，这里兜住 */
[hidden] { display: none !important; }
/* 有无纵向滚动条不影响内容宽度：右侧那组按钮在各页保持同一位置 */
html { scrollbar-gutter: stable; }
body {
  margin: 0; background: var(--shell); color: var(--ink);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
h1 { font-size: 15px; margin: 0; font-weight: 600; }
h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; }
a { color: var(--accent); }
.muted { color: var(--ink-2); font-size: var(--t-meta); }
.note { color: var(--hold); font-size: var(--t-meta); }
.num, .tile .v, .tile .s, td.num, th.num { font-variant-numeric: tabular-nums; }
.spacer { margin-left: auto; }
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: nowrap; min-height: 56px;
  /* 左右内边距跟着 main 的 1400px 网格走，品牌与账户和卡片边缘对齐 */
  padding: 8px max(20px, calc((100% - 1400px) / 2 + 20px));
  background: var(--panel); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 10;
}
/* 顺序固定为 品牌 │ 导航 → 弹性空隙 → 账户，各页按钮 x 位置因此一致 */
.topbar .brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .brand::after { content: ''; width: 1px; height: 20px; margin-left: 8px; background: var(--rule); }
.topbar .brand h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .brand img { width: 18px; height: 18px; }
/* 导航：同一套圆角块的 hover 与选中，选中用淡青底 + 青色字，不做第二套下划线 */
nav.links { display: flex; align-items: center; gap: 4px; min-width: 0; }
nav.links a {
  display: inline-flex; align-items: center; gap: 6px; height: var(--control-h); padding: 0 12px;
  border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none;
  font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background-color .12s ease, color .12s ease;
}
nav.links a svg { width: 15px; height: 15px; }
nav.links a:hover { color: var(--ink); background: var(--sunk); }
nav.links a.active { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

/* 顶栏右侧：设置 + 账户菜单 */
.actions { display: flex; align-items: center; gap: 8px; }
.actions .userbox { position: relative; }
.actions button.ghost { border-color: var(--rule); color: var(--ink); font-weight: 500; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 220px; padding: 10px; background: var(--panel);
  border: 1px solid var(--rule); border-radius: var(--radius);
  box-shadow: 0 12px 28px rgba(16, 28, 38, .16);
}
.menu-title { margin: 0 0 8px; padding-bottom: 8px; border-bottom: 1px solid var(--rule); font-weight: 600; }
.menu .kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; font-size: 12px; margin-bottom: 10px; }
.menu .kv .k { color: var(--ink-2); white-space: nowrap; }
.menu .kv .v { overflow-wrap: anywhere; }
.menu-item {
  width: 100%; justify-content: flex-start; border-color: transparent; background: var(--sunk);
}
.menu-item:hover { background: var(--alarm-soft); border-color: #e3c4c1; color: var(--alarm); }

/* 按钮 */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--control-h); padding: 0 12px;
  border-radius: var(--radius); border: 1px solid var(--rule-strong); background: #fff;
  color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; text-decoration: none;
  /* 中文在 flex 行里会被逐字断行，控件文字一律不换行 */
  white-space: nowrap;
}
button:hover:not(:disabled), .btn:hover { background: var(--sunk); border-color: var(--rule-strong); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, .chip:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: #0f4a56; border-color: #0f4a56; }
button.warn { color: var(--hold); }
button.danger { color: var(--alarm); }
button.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
button.ghost:hover:not(:disabled) { background: var(--sunk); color: var(--ink); }
button svg, .btn svg { width: 15px; height: 15px; }
/* 表格里的文字按钮：不要方框按钮的外观，但保留键盘可聚焦 */
button.link {
  min-height: 0; padding: 0; border: 0; background: transparent;
  color: var(--accent); font-size: inherit; text-decoration: underline; text-underline-offset: 2px;
}
button.link:hover:not(:disabled) { background: transparent; color: #0f4a56; }

/* 布局 */
main { padding: 16px 20px 32px; display: grid; gap: 16px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px; }
/* 卡片标题行：标题在左、该卡片的操作在右 */
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.card-head #reason { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 24px; align-items: start; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.table-wrap { overflow-x: auto; }
/* min-width:0 才能让宽表格在自己的滚动容器里滚，而不是把整页撑开 */
main > *, .card, .split > * { min-width: 0; }

/* 徽标 */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; border: 1px solid var(--rule); background: var(--sunk);
  color: var(--ink-2); white-space: nowrap;
}
.pill.running, .pill.ok { color: var(--live); border-color: #bcded0; background: var(--live-soft); }
.pill.paused { color: var(--hold); border-color: #e3d3b3; background: var(--hold-soft); }
.pill.bad { color: var(--alarm); border-color: #e3c4c1; background: var(--alarm-soft); }

/* 读数块：面板内的下沉仪表块（不描边、不加阴影，避免卡片套卡片） */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.tile { background: var(--sunk); border-radius: var(--radius-sm); padding: 10px 12px; }
.tile .k { color: var(--ink-2); font-size: var(--t-meta); }
.tile .v { font-size: var(--t-readout); font-weight: 600; margin-top: 2px; line-height: 1.15; }
.tile .s { color: var(--ink-2); font-size: var(--t-meta); }
/* 轨道：进度与预算共用。带 10% 刻度，预计部分用虚纹，读的是量不是装饰 */
.rail { position: relative; height: 10px; border-radius: 999px; background: var(--sunk); overflow: hidden; margin: 10px 0 4px; }
.rail .done { position: absolute; inset: 0 auto 0 0; background: var(--accent); transition: width .3s ease; }
.rail::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to right, rgba(255, 255, 255, .45) 0 1px, transparent 1px 10%);
}
.rail.thin { height: 6px; margin: 8px 0 0; }
.rail.thin .done { background: var(--live); }
.rail.thin.warn .done { background: var(--hold); }
/* 进度卡里的两个运行目标：条数与字数各一条轨道，标签等宽对齐 */
.goal-k { color: var(--ink-2); font-size: var(--t-meta); min-width: 2.5em; }

/* 费用柱状图：固定 7 天，缺的补空柱 */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 132px; margin-top: 8px; border-bottom: 1px solid var(--rule); padding-bottom: 2px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; min-width: 28px; }
.chart .col i { width: 70%; background: #4c8693; border-radius: 4px 4px 0 0; transition: background .15s ease; }
.chart .col i[data-empty] { background: var(--rule-strong); }
.chart .col:hover i { background: var(--accent); }
.chart .col b { font-size: 11px; line-height: 16px; min-height: 16px; color: var(--ink-2); font-weight: 500; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 表格 */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--rule); font-size: 13px; vertical-align: top; }
/* 表头不换行：列宽挤压时中文会逐字断行，把表头行撑得高低不齐 */
th { color: var(--ink-2); font-weight: 500; font-size: 12px; background: var(--sunk); position: sticky; top: 0; white-space: nowrap; }
td.num, th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--sunk); }
.preview { color: var(--ink-2); max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.full { background: var(--sunk); white-space: pre-wrap; max-width: 900px; }
td.empty { color: var(--ink-2); text-align: center; padding: 20px 8px; }
.st-rejected { color: var(--alarm); }
.st-failed { color: var(--hold); }
.st-success { color: var(--live); }

/* 表单 */
label { font-size: 12px; color: var(--ink-2); display: block; margin-bottom: 3px; }
input[type=number], input[type=text], input[type=password], input[type=tel], select {
  width: 100%; min-height: var(--control-h); padding: 5px 8px;
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  font: inherit; font-variant-numeric: tabular-nums; background: #fff; color: var(--ink);
}
textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: #fff; color: var(--ink); resize: vertical;
}
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.fields .wide { grid-column: 1 / -1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; border: 1px solid var(--rule-strong); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; cursor: pointer; user-select: none; background: #fff; color: var(--ink-2);
  white-space: nowrap;
}
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.band { display: grid; grid-template-columns: 90px 160px 130px; gap: 8px; align-items: center; margin-bottom: 6px; }
.band-head { margin-bottom: 2px; font-size: 12px; }
.field-hint { margin: 12px 0 6px; }

/* 设置页：分区导航 + provider 卡片 */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs a { font-size: 12px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--rule); background: #fff; color: var(--ink-2); text-decoration: none; }
.tabs a:hover { border-color: var(--accent); color: var(--accent); }
/* 选中态和顶栏导航同一套语言：淡青底 + 青字 + 加粗 */
.tabs a[aria-selected="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
section[data-section] { scroll-margin-top: 64px; }
.providers { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 12px; }
.provider { border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px; background: var(--sunk); }
.provider > .p-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.provider .p-head b { font-size: 13px; }
.provider .model { font-size: 12px; color: var(--ink-2); }
/* 只读摘要卡片：整张是按钮，点开模态窗口才有输入框 */
button.provider.summary {
  color: var(--ink); display: block; width: 100%; text-align: left; font: inherit;
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 12px; background: var(--sunk);
}
button.provider.summary:hover { border-color: var(--accent); background: var(--accent-soft); }
.provider.summary .p-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.provider.summary .p-head svg { width: 16px; height: 16px; color: var(--ink-2); }
.provider.summary .kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; font-size: 12px; }
.provider.summary .kv .k { color: var(--ink-2); white-space: nowrap; }
.provider.summary .kv .v { font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
/* 卡片自己的操作行：保存属于这张卡，不存在全页统一保存 */
.card-foot {
  display: flex; align-items: center; gap: 10px;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--rule);
}

/* 供应商弹窗：按「调度 / API Key / 单价」分组，高峰赭黄、错峰玉绿（沿用全局配色语义） */
/* 选择器要盖住后面的 .dialog 宽度，所以带 .dialog 一起写 */
.dialog.provider-dialog { width: min(600px, calc(100vw - 32px)); }
.p-group { margin-bottom: 16px; }
.p-group:last-of-type { margin-bottom: 0; }
.p-group-head { margin: 0 0 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.p-group-head .muted { font-weight: 400; }
/* 窄屏下这一小句整体换行，不从中间断开 */
#provider-sub { min-width: 0; }
#provider-sub span { white-space: nowrap; }
.hint { display: block; margin-top: 4px; font-size: 12px; color: var(--ink-2); }
.p-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.p-status .pill { flex: none; }
.p-status .muted { min-width: 0; overflow-wrap: anywhere; }
.p-prices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.p-price-head { display: flex; align-items: center; gap: 6px; margin: 0 0 6px; font-size: 12px; font-weight: 600; }
.p-price-head svg { width: 14px; height: 14px; }
.p-price.peak .p-price-head { color: var(--hold); }
.p-price.off .p-price-head { color: var(--live); }
.p-price .fields { grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 560px) { .p-prices { grid-template-columns: 1fr; } }

/* 登录页 */
.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
/* 宽度只由视口和 max-width 决定；高度钉死，切换「手机验证码 / 口令」时窗口不跳动 */
.login {
  width: 100%; min-width: 0; max-width: 380px; height: 428px; margin: auto;
  /* 不放竖向滚动条：内容本来就装得下（差 2px 以内靠这条兜底，且不显示轨道）；
     窗口太矮时交给页面滚动，卡片自己不变形 */
  overflow-y: auto; scrollbar-width: none;
  background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 24px;
  display: flex; flex-direction: column;
}
.login::-webkit-scrollbar { width: 0; height: 0; }
.login .logo { flex: none; width: 48px; height: 48px; margin-bottom: 14px; }
.login form, .login .tabs, .btn-row, .btn-row input { min-width: 0; }
.login h1 { font-size: 17px; margin-bottom: 4px; }
.login .sub { color: var(--ink-2); font-size: 12px; margin: 0 0 16px; }
/* 表单撑满卡片，提交按钮钉在表单底部：两种登录方式下「登录」按钮位置一致，
   口令方式字段少，多出来的空间自然变成按钮上方的留白 */
.login form { flex: 1 1 auto; display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.login form button[type=submit] { margin-top: auto; }
.login .btn-row { display: flex; gap: 8px; }
.login .btn-row input { flex: 1 1 auto; }
.login .btn-row button { flex: 0 0 auto; }
.login button.primary { min-height: 36px; }
/* 固定高度的提示位：报错文字长短不会顶动上面的按钮（超长时该行自己滚） */
.error {
  color: var(--alarm); font-size: 12px; margin: 0;
  height: 34px; max-height: 34px; overflow-y: auto; scrollbar-width: none;
}
.error::-webkit-scrollbar { width: 0; height: 0; }
/* 拼图验证：原生 dialog，自带焦点陷阱与 Esc 关闭 */
.dialog {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow-y: auto;
  padding: 16px; border: 1px solid var(--rule); border-radius: var(--radius);
  background: var(--panel); color: var(--ink);
  box-shadow: 0 14px 36px rgba(16, 28, 38, .18);
}
.dialog::backdrop { background: rgba(24, 32, 44, .38); }
/* 弹窗容器自己接焦点（避免一打开就给"关闭"画环），容器不用再画一圈 */
.dialog:focus, .dialog:focus-visible { outline: none; }
.dialog .dlg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.dialog .dlg-head b { font-size: 15px; }
/* 文本详情：一屏看完"为什么被丢" + 全文 + 元信息，正文区自己滚，弹窗不撑破视口 */
.text-dialog { width: min(760px, calc(100vw - 32px)); }
.text-dialog .text-tags { display: flex; gap: 6px; }
.text-why {
  margin: 0 0 12px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--alarm-soft); color: var(--alarm); font-size: 12px; overflow-wrap: anywhere;
}
.text-why.paused { background: var(--hold-soft); color: var(--hold); }
.text-block { margin-bottom: 12px; border: 1px solid var(--rule); border-radius: var(--radius-sm); overflow: hidden; }
.text-block-head {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  background: var(--sunk); border-bottom: 1px solid var(--rule); font-size: 12px;
}
.text-block pre {
  margin: 0; padding: 10px; max-height: 42vh; overflow: auto;
  font: inherit; font-size: 13px; line-height: 1.7;
  white-space: pre-wrap; overflow-wrap: anywhere; user-select: text;
}
.text-meta {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px;
  margin: 0; font-size: 12px;
}
.text-meta dt { color: var(--ink-2); white-space: nowrap; }
.text-meta dd { margin: 0; overflow-wrap: anywhere; }
.dialog .dlg-foot {
  /* 窄屏下按钮会换行（不能只靠 no-wrap，弹窗横向滚动会把提示文字裁掉） */
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--rule);
}
.captcha-dialog {
  width: min(360px, calc(100vw - 32px));
}
.captcha-dialog .dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.captcha-dialog .dlg-head button { min-height: 28px; padding: 0 10px; font-size: 12px; }
/* 拇指直径来自接口下发的 --thumb；轨道与拼图图片等宽，行程 = 宽 - 拇指 → 拇指 1px == 拼图块 1px */
.captcha-dialog #captcha-slider {
  -webkit-appearance: none; appearance: none;
  height: 22px; margin: 10px 0 4px; padding: 0; background: transparent;
}
.captcha-dialog #captcha-slider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 999px; background: var(--rule);
}
.captcha-dialog #captcha-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb, 18px); height: var(--thumb, 18px);
  margin-top: calc(var(--thumb, 18px) / -3);
  border-radius: 50%; background: var(--accent); border: 0; cursor: grab;
}
.captcha-dialog #captcha-slider:disabled::-webkit-slider-thumb { background: var(--rule-strong); cursor: default; }
.captcha-dialog #captcha-slider::-moz-range-track { height: 6px; border-radius: 999px; background: var(--rule); }
.captcha-dialog #captcha-slider::-moz-range-thumb {
  width: var(--thumb, 18px); height: var(--thumb, 18px);
  border: 0; border-radius: 50%; background: var(--accent);
}
.captcha-dialog #captcha-slider:disabled::-moz-range-thumb { background: var(--rule-strong); }
.captcha-body { min-width: 0; }
.captcha-stage { position: relative; width: 320px; max-width: 100%; height: 160px; overflow: hidden; border-radius: var(--radius-sm); background: var(--sunk); }
.captcha-stage img.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; user-select: none; }
.captcha-stage img.piece { position: absolute; width: 90px; height: 90px; pointer-events: none; user-select: none; z-index: 2; }

@media (max-width: 860px) {
  main { padding: 12px 12px 32px; }
  /* 窄屏两行：第一行 品牌（可截断）+ 账户，第二行导航三等分。用 grid 定死，宽度再窄也不乱换行 */
  .topbar {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: center; gap: 8px 12px; min-height: 0; padding: 8px 12px;
  }
  .topbar .brand { grid-area: 1 / 1; min-width: 0; }
  .topbar .brand::after { display: none; }
  .topbar .spacer { display: none; }
  .actions { grid-area: 1 / 2; }
  nav.links { grid-area: 2 / 1 / 3 / 3; gap: 2px; }
  /* 三个等分格变窄，图标+文字要缩进得下（320px 下每格 92px） */
  nav.links a { flex: 1; justify-content: center; padding: 0 8px; gap: 4px; }
  .split { grid-template-columns: 1fr; gap: 16px; }
}
