/* LiteChat API 控制台 —— v2.7.0
   设计取向：中性、克制。不用渐变/发光/彩色图标底，主按钮用近黑（深色模式近白），
   蓝色只用于链接与可点击强调。 */

:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --bg-sink: #f4f5f7;
  --text: #1a1d21;
  --text-2: #40454d;
  --muted: #757b85;
  --line: #e6e8eb;
  --line-2: #eff1f3;
  --ink: #1a1d21;          /* 主按钮底色 */
  --ink-fg: #ffffff;       /* 主按钮文字 */
  --link: #2f6fed;
  --ok: #157f3c;
  --warn: #9a6100;
  --err: #c0362c;
  --code-bg: #14161a;
  --code-fg: #e7e9ee;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1113;
    --bg-soft: #141719;
    --bg-sink: #1a1d20;
    --text: #e8eaed;
    --text-2: #c2c7cd;
    --muted: #8b929b;
    --line: #262a2e;
    --line-2: #1e2225;
    --ink: #e8eaed;
    --ink-fg: #14171a;
    --link: #7aa2ff;
    --ok: #4ec27a;
    --warn: #d8a33a;
    --err: #f0736a;
    --code-bg: #0a0b0d;
    --code-fg: #e7e9ee;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

code, pre, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }

.sb {
  width: 228px;
  flex: 0 0 228px;
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sb-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 18px 18px 14px;
  font-weight: 650;
  letter-spacing: -.01em;
  color: var(--text);
  font-size: 15px;
}
.sb-brand img { width: 22px; height: 22px; border-radius: 6px; display: block; }
.sb-brand a { color: inherit; }

.sb-nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; }

.sb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
}
.sb-item:hover { background: var(--bg-sink); text-decoration: none; }
.sb-item.active { background: var(--bg-sink); color: var(--text); font-weight: 600; }
.sb-item svg { width: 17px; height: 17px; flex: 0 0 17px; fill: currentColor; opacity: .8; }
.sb-item.active svg { opacity: 1; }
.sb-item .claw { width: 17px; height: 17px; flex: 0 0 17px; object-fit: contain; }

.sb-foot {
  margin-top: auto;
  padding: 14px 18px 18px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line-2);
}
.sb-foot a { color: var(--muted); }
.sb-foot a:hover { color: var(--text); }

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

.topbar {
  height: 56px;
  flex: 0 0 56px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 12px;
}
.topbar h1 { font-size: 14px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
.topbar .spacer { flex: 1 1 auto; }
.topbar .who { font-size: 13px; color: var(--muted); }

.content { padding: 26px 28px 64px; max-width: 1000px; width: 100%; }

/* ---------- 通用块 ---------- */
.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.card-h {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-2);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-h h2 { font-size: 13.5px; font-weight: 600; margin: 0; }
.card-h .spacer { flex: 1 1 auto; }
.card-b { padding: 18px; }
.card-b.tight { padding: 0; }

.page-lede { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.grid { display: grid; gap: 14px; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--bg);
}
.stat .k { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .v { font-size: 20px; font-weight: 620; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .u { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 3px; }

/* ---------- 表格 ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 18px; text-align: left; border-bottom: 1px solid var(--line-2); }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; }
td { color: var(--text-2); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--text); }
.strike { text-decoration: line-through; opacity: .45; margin-right: 6px; }
.strong { font-weight: 650; color: var(--text); }

.badge {
  display: inline-block;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 32%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 32%, transparent); }
.badge.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 32%, transparent); }

/* ---------- 表单 ---------- */
.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }

.input, .select, textarea.input {
  width: 100%;
  padding: 8px 11px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  font-family: inherit;
  transition: border-color .15s;
}
.input:focus, .select:focus { border-color: var(--muted); }
.input[readonly] { background: var(--bg-sink); color: var(--muted); }
.select { appearance: none; cursor: pointer; padding-right: 30px;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23757b85' stroke-width='2' stroke-linecap='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 15px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; min-width: 150px; }
.row > .btn { flex: 0 0 auto; min-width: 0; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--bg-sink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--ink-fg); }
.btn-primary:hover { opacity: .88; background: var(--ink); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 7px; }
.btn-danger { color: var(--err); }
.btn-danger:hover { background: color-mix(in srgb, var(--err) 8%, transparent); }

/* ---------- 代码块 ---------- */
.code-wrap { position: relative; }
pre.code {
  margin: 0;
  padding: 16px 18px;
  background: var(--code-bg);
  color: var(--code-fg);
  border-radius: var(--radius);
  font-size: 12.5px;
  line-height: 1.75;
  overflow-x: auto;
  white-space: pre;
}
.code-copy { position: absolute; top: 10px; right: 10px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 0 0 14px; }
.tab {
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
}
.tab:hover { background: var(--bg-sink); color: var(--text-2); }
.tab.active { background: var(--bg-sink); color: var(--text); font-weight: 600; }

/* ---------- Key 列表 ---------- */
.keyline {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line-2);
  flex-wrap: wrap;
}
.keyline:last-child { border-bottom: none; }
.keyline .kn { font-weight: 550; color: var(--text); }
.keyline .km { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; color: var(--muted); background: var(--bg-sink);
  border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; }
.keyline .meta { font-size: 12px; color: var(--muted); }
.keyline .spacer { flex: 1 1 auto; }

.empty { padding: 30px 18px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- 弹窗 ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 18, 22, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 14px; width: 100%; max-width: 460px;
  box-shadow: 0 12px 40px rgba(16, 24, 40, .18);
  max-height: 88vh; overflow: auto;
}
.modal-h { padding: 16px 18px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; }
.modal-h h3 { margin: 0; font-size: 14px; font-weight: 620; }
.modal-b { padding: 18px; }
.modal-f { padding: 14px 18px; border-top: 1px solid var(--line-2);
  display: flex; justify-content: flex-end; gap: 10px; }

/* 一次性密钥展示 */
.reveal {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-sink);
  padding: 14px;
}
.reveal .v {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 8px 0 10px;
}
.notice {
  font-size: 12.5px;
  color: var(--warn);
  background: color-mix(in srgb, var(--warn) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 24%, transparent);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 14px;
}

/* ---------- 快速接入 ---------- */
.quick-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; }
.preview-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-sink);
  overflow: hidden;
  height: 620px;
}
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.sw-list { display: flex; flex-direction: column; gap: 6px; }
.sw {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 9px; cursor: pointer; background: var(--bg);
  font-size: 13px; color: var(--text-2); text-align: left; font-family: inherit;
}
.sw:hover { background: var(--bg-sink); }
.sw.active { border-color: var(--text); color: var(--text); font-weight: 600; }
.sw .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); flex: 0 0 6px; }
.sw.active .dot { background: var(--text); }
.sw .sub { font-size: 11.5px; color: var(--muted); font-weight: 400; display: block; margin-top: 1px; }

/* ---------- 文档 ---------- */
.doc-h { font-size: 12.5px; color: var(--muted); margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--text-2); }
.kv dd code { background: var(--bg-sink); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 5px; font-size: 12.5px; }

.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: var(--ink); color: var(--ink-fg);
  padding: 8px 16px; border-radius: 999px; font-size: 12.5px;
  z-index: 99; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sb { width: auto; flex: none; height: auto; position: static; border-right: none;
        border-bottom: 1px solid var(--line); }
  .sb-nav { flex-direction: row; overflow-x: auto; padding: 0 10px 10px; }
  .sb-item { width: auto; white-space: nowrap; }
  .sb-foot { display: none; }
  .content { padding: 18px 16px 48px; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: 1fr; }
  .preview-frame { height: 520px; }
}

/* ---------- 优化（上游排队） v2.7.2 ---------- */
.opt-hero { display: flex; align-items: center; gap: 14px; }
.opt-ico {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px;
  background: var(--bg-sink); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.opt-ico svg { width: 22px; height: 22px; }
.opt-hero h2 { margin: 0; font-size: 15px; font-weight: 620; letter-spacing: -.01em; }
.opt-hero p { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }

.switch { position: relative; width: 46px; height: 26px; flex: 0 0 46px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--line); transition: background .18s;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .18s;
}
.switch input:checked + .track { background: var(--ink); }
.switch input:checked + .track + .knob { transform: translateX(20px); }
.switch input:disabled + .track { opacity: .5; }

/* ================= v2.8.1：Token 卡 / 用量趋势图 / 充值 ================= */

/* 四格统计（原来只有 .grid-3 / .grid-2） */
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Token 卡：大数字 22px + 1px 分隔线 + 三行明细 */
.tok-card .card-b { padding: 22px 22px 20px; }
.tok-head { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.tok-title { font-size: 13px; font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.tok-total {
  font-size: 22px; font-weight: 680; line-height: 1.2; letter-spacing: -.02em;
  color: var(--text); font-variant-numeric: tabular-nums;
}
.tok-hr { height: 1px; background: var(--line); margin: 14px 0 12px; }
.tok-sub { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.tok-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; }
.tok-k { font-size: 12px; color: var(--muted); }
.tok-v { font-size: 14px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* 双图：一行两张，16:9（用 padding-top 而不是 aspect-ratio，老浏览器兼容） */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin: 0 0 18px; }
.chart-grid > .card { margin: 0; min-width: 0; }
.chart-box { position: relative; width: 100%; padding-top: 56.25%; height: 0; }
.chart-inner { position: absolute; inset: 0; }
.chart-empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 13px;
}

/* 充值面额 */
.amt-row { display: flex; flex-wrap: wrap; gap: 8px; }
.amt {
  padding: 9px 16px; font: inherit; font-size: 13px; font-weight: 600;
  color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.amt:hover { background: var(--bg-sink); }
.amt.active { border-color: var(--ink); background: var(--bg-sink); }
.amt-custom { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.amt-input { width: 110px; }
.amt-hint { font-size: 12px; color: var(--muted); }
.pay-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.pay-msg { margin-top: 12px; font-size: 12.5px; color: var(--muted); min-height: 18px; word-break: break-all; }
.pay-msg.ok { color: var(--ok); }
.pay-msg.warn { color: var(--warn); }
.pay-msg.err { color: var(--err); }

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
}

/* ================= v2.8.5：故障自动切换（路由链） ================= */
.fo-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 16px 0 0; }
.fo-pill {
  font-size: 12.5px; font-weight: 600; color: var(--text);
  background: var(--bg-sink); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; white-space: nowrap;
}
.fo-arrow { color: var(--muted); font-size: 12px; }
.fo-note { margin-top: 14px; font-size: 12.5px; color: var(--muted); line-height: 1.95; }
/* v2.9.4: 永不停止 —— 模型多选 chip */
.ns-models { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.ns-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--bg-sink); border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; cursor: pointer; user-select: none;
  transition: color .15s, border-color .15s, background .15s;
}
.ns-chip:hover { color: var(--text); }
.ns-chip.on { color: var(--text); border-color: var(--text); background: color-mix(in srgb, var(--text) 6%, var(--bg-sink)); }
.ns-chip input { margin: 0; accent-color: var(--text); }
