/* ============ Design Tokens ============ */
:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --bg-soft: #f0f2f5;
  --bg-dark: #0e1116;
  --bg-dark-2: #161b22;
  --border: #e3e6ea;
  --border-strong: #d3d8de;
  --text: #1a1d21;
  --text-2: #5a6472;
  --text-3: #8b94a1;
  --brand: #2f6bff;
  --brand-hover: #2158e0;
  --brand-soft: #eaf0ff;
  --ok: #12a06a;
  --ok-soft: #e6f7f0;
  --warn: #d98200;
  --warn-soft: #fdf4e3;
  --err: #d93a3a;
  --err-soft: #fdecec;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 4px 16px rgba(16, 24, 40, .08);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .14);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
pre {
  background: var(--bg-dark); color: #d8dee9; padding: 16px 18px; border-radius: var(--radius);
  overflow-x: auto; margin: 0; line-height: 1.65; max-width: 100%;
}
pre code { color: inherit; white-space: pre; }
/* 防止 grid 子项被内容撑破 */
.grid > *, .card, .card-body, .stack > * { min-width: 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ============ Layout ============ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--bg-dark); color: #aeb8c6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand {
  padding: 20px 20px 18px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.07); color: #fff; font-weight: 700; font-size: 15px;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; flex: 0 0 30px;
  background: linear-gradient(135deg, #4d86ff, #2f6bff 55%, #1b4fd1);
  display: grid; place-items: center; font-size: 15px; color: #fff; font-weight: 800;
}
.nav { padding: 12px 10px; flex: 1; overflow-y: auto; }
.nav-group { margin: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #5f6b7c; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: #aeb8c6; font-size: 13.5px; font-weight: 500; margin-bottom: 2px; text-decoration: none;
  transition: background .12s, color .12s;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a .ico { width: 16px; height: 16px; flex: 0 0 16px; opacity: .9; }
/* 触摸设备上提高点击反馈与命中高度 */
@media (hover: none) {
  .nav a { padding: 12px; }
  .nav a:active { background: rgba(255,255,255,.13); }
  .btn:active, .fb-seg-btn:active { opacity: .82; }
}
.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; }

/* 移动端抽屉：汉堡、关闭、遮罩默认隐藏（900px 断点内再打开） */
.menu-btn { display: none; font-size: 19px; }
.side-close {
  display: none; width: 30px; height: 30px; flex: 0 0 30px; border: none; cursor: pointer;
  border-radius: 7px; background: rgba(255,255,255,.08); color: #aeb8c6;
  font-size: 13px; line-height: 1; font-family: inherit;
}
.side-close:hover { background: rgba(255,255,255,.16); color: #fff; }
.scrim {
  position: fixed; inset: 0; background: rgba(9, 13, 20, .48); z-index: 59;
  opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s;
  -webkit-tap-highlight-color: transparent;
}
.scrim.show { opacity: 1; visibility: visible; }
body.drawer-open { overflow: hidden; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--bg-elev); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 26px; position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }

/* 用户胶囊 */
.uc-avatar {
  width: 29px; height: 29px; flex: 0 0 29px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.uc-text { line-height: 1.25; min-width: 0; text-align: left; }
.uc-name {
  font-size: 13px; font-weight: 600; max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.content { padding: 26px; max-width: 1280px; width: 100%; }

/* ============ Components ============ */
.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px 22px; }
.card-head {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card-head h3 { font-size: 14.5px; }
.card-body { padding: 20px 22px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack > * + * { margin-top: 14px; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.bold { font-weight: 650; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.w-full { width: 100%; }
.flex-1 { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 15px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); font-size: 13.5px; font-weight: 550;
  cursor: pointer; transition: all .12s; white-space: nowrap; font-family: inherit;
}
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn-danger { color: var(--err); border-color: #f0c8c8; background: #fff; }
.btn-danger:hover { background: var(--err-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 7px; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 14.5px; border-radius: 10px; }
.btn-block { width: 100%; }

label.field { display: block; margin-bottom: 14px; }
label.field > .lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
label.field > .hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong);
  border-radius: 8px; font-size: 13.5px; font-family: inherit; background: #fff; color: var(--text);
  transition: border-color .12s, box-shadow .12s; outline: none;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47,107,255,.12); }
input:disabled, select:disabled { background: var(--bg-soft); color: var(--text-3); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238b94a1' d='M6 8.5 1.5 4h9z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.table-wrap { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-3); font-weight: 650;
  background: var(--bg-soft); border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: 6px; font-size: 11.5px; font-weight: 600; background: var(--bg-soft); color: var(--text-2);
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge-mute { background: var(--bg-soft); color: var(--text-3); }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---- 上游通道列表（模型管理） ---- */
.up-list { display: flex; flex-direction: column; gap: 8px; }
.up-item {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 10px; background: #fff; transition: border-color .14s, box-shadow .14s;
}
.up-item:hover { border-color: var(--border-strong); box-shadow: 0 1px 4px rgba(16,24,40,.06); }
.up-item.is-off { background: var(--bg-soft); opacity: .72; }
.up-pri {
  flex: 0 0 auto; min-width: 34px; height: 24px; padding: 0 7px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; background: var(--brand-soft); color: var(--brand);
  font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.up-main { flex: 1 1 auto; min-width: 0; }
.up-url {
  font-size: 12.5px; color: var(--text); font-weight: 550;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.up-meta {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-top: 4px; font-size: 11.5px; color: var(--text-3);
}
.up-tag {
  background: var(--bg-soft); border-radius: 5px; padding: 1px 6px;
  color: var(--text-2); font-size: 11px;
}
.up-sep { opacity: .45; }
.up-weight { font-variant-numeric: tabular-nums; }
.up-state { font-weight: 600; }
.up-state.on { color: var(--ok); }
.up-state.off { color: var(--text-3); }
.up-side { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; }

.stat { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.stat .k { font-size: 12px; color: var(--text-2); font-weight: 550; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.alert { padding: 12px 15px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.alert-err { background: var(--err-soft); color: #a32c2c; border-color: #f3d0d0; }
.alert-ok { background: var(--ok-soft); color: #0b7d52; border-color: #c8ecdc; }
.alert-warn { background: var(--warn-soft); color: #90560a; border-color: #f4e0bb; }
.alert-info { background: var(--brand-soft); color: #1e4bc4; border-color: #d3e0ff; }

.key-box {
  display: flex; align-items: center; gap: 8px; background: var(--bg-dark); color: #e6edf3;
  padding: 10px 12px; border-radius: 8px; font-family: var(--mono); font-size: 12.5px; word-break: break-all;
}
.key-box .val { flex: 1; min-width: 0; }

.copy-btn {
  border: 1px solid rgba(255,255,255,.18); background: rgba(255,255,255,.06); color: #cbd5e1;
  border-radius: 6px; height: 26px; padding: 0 9px; font-size: 11.5px; cursor: pointer; font-family: inherit;
}
.copy-btn:hover { background: rgba(255,255,255,.14); color: #fff; }

/* 列表里的 Key 展示：浅色行内块，不复用弹窗的暗色 .key-box */
.key-inline {
  display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap;
  max-width: 100%;
}
.key-val {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  background: var(--bg-soft); border-radius: 6px; padding: 3px 8px;
  /* 明文很长，必须允许在任意位置折行，否则会被表格单元格裁掉 */
  word-break: break-all; white-space: normal; line-height: 1.5;
}
/* 明文态：反色强调，让人一眼看出「现在屏幕上就是真 Key」 */
.key-val.key-plain {
  color: var(--text); background: var(--warn-soft); border: 1px solid #f3d8ae;
}
.key-note {
  font-size: 11px; color: var(--muted); background: var(--bg-soft);
  border-radius: 6px; padding: 2px 7px; white-space: nowrap;
}

/* Modal */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 20, 28, .62); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 1000; padding: 20px; animation: fadein .12s ease; overflow-y: auto;
}
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--bg-elev); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  animation: pop .16s cubic-bezier(.2,.9,.3,1.2); overflow: hidden;
}
.modal-body { padding: 22px; overflow-y: auto; flex: 1; min-height: 0; }
.modal .key-box { max-width: 100%; }
.modal .key-box .val { overflow-wrap: anywhere; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0 } to { transform: none; opacity: 1 } }
.modal.modal-lg { max-width: 800px; }
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.icon-btn {
  width: 30px; height: 30px; border-radius: 7px; border: none; background: transparent; cursor: pointer;
  color: var(--text-3); font-size: 18px; line-height: 1; display: grid; place-items: center; font-family: inherit;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs button {
  border: none; background: transparent; padding: 10px 14px; font-size: 13.5px; font-weight: 600;
  color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: inherit;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Toast */
#toasts { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 240px; max-width: 380px; background: var(--bg-dark-2); color: #e6edf3;
  padding: 11px 15px; border-radius: 9px; font-size: 13px; box-shadow: var(--shadow-lg);
  animation: slidein .18s ease; border-left: 3px solid var(--brand);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
@keyframes slidein { from { transform: translateX(16px); opacity: 0 } to { transform: none; opacity: 1 } }

/* Empty */
.empty { text-align: center; padding: 44px 20px; color: var(--text-3); }
.empty .big { font-size: 30px; margin-bottom: 10px; opacity: .5; }

/* Skeleton */
.skeleton { background: linear-gradient(90deg, var(--bg-soft) 25%, #e8ebef 50%, var(--bg-soft) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0 } }

/* Progress */
.progress { height: 6px; background: var(--bg-soft); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }

/* Switch */
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 38px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cfd5dd; border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(16px); }

/* ============ Auth pages ============ */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1fr minmax(440px, 520px); }

.auth-left {
  background: #0b0e13; color: #cfd8e3; padding: 52px 60px; display: flex; flex-direction: column;
  justify-content: space-between; position: relative; overflow: hidden;
}
.auth-left::before {
  content: ''; position: absolute; width: 760px; height: 760px; border-radius: 50%;
  background: radial-gradient(circle, rgba(47,107,255,.26), transparent 62%);
  right: -280px; top: -240px;
}
.auth-left::after {
  content: ''; position: absolute; width: 520px; height: 520px; border-radius: 50%;
  background: radial-gradient(circle, rgba(120,80,255,.16), transparent 65%);
  left: -180px; bottom: -220px;
}
.auth-left .promo { position: relative; z-index: 1; }
.auth-left .promo h1 {
  font-size: 40px; line-height: 1.22; margin-bottom: 20px; color: #fff;
  letter-spacing: -.025em; font-weight: 700;
}
.auth-left .promo h1 em { font-style: normal; color: #6f9dff; }
.auth-left .promo p { font-size: 15px; color: #93a1b3; max-width: 430px; line-height: 1.75; }

.auth-feats { display: grid; gap: 20px; margin-top: 44px; position: relative; z-index: 1; }
.auth-feat { display: flex; gap: 14px; align-items: flex-start; }
.auth-feat .fi {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 10px; font-size: 16px;
  background: rgba(47,107,255,.15); border: 1px solid rgba(96,140,255,.22);
  display: grid; place-items: center;
}
.auth-feat .ft { font-weight: 650; color: #fff; font-size: 14px; margin-bottom: 2px; }
.auth-feat .fd { font-size: 12.5px; color: #7f8c9d; line-height: 1.6; }

.auth-right {
  background: var(--bg-elev); display: flex; align-items: center; justify-content: center;
  padding: 48px 56px; border-left: 1px solid var(--border);
}
.auth-form { width: 100%; max-width: 360px; }

/* 分段切换 */
.auth-tabs {
  display: flex; gap: 0; background: var(--bg-soft); padding: 4px; border-radius: 10px;
  margin-bottom: 30px;
}
.auth-tabs button {
  flex: 1; height: 38px; border: none; background: transparent; border-radius: 7px;
  font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer;
  font-family: inherit; transition: all .16s;
}
.auth-tabs button:hover { color: var(--text); }
.auth-tabs button.active {
  background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(16,24,40,.10);
}

.auth-form h1 { font-size: 25px; margin-bottom: 7px; letter-spacing: -.02em; }
.auth-form .sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 28px; line-height: 1.6; }

/* 表单字段强化 */
.auth-form label.field { margin-bottom: 18px; }
.auth-form label.field > .lbl {
  font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; display: block;
}
.auth-form input[type=tel], .auth-form input[type=password], .auth-form input[type=text] {
  height: 46px; padding: 0 15px; font-size: 14.5px; border-radius: 10px;
  border: 1.5px solid var(--border-strong); transition: all .15s;
}
.auth-form input:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3.5px rgba(47,107,255,.13);
}
.auth-form .btn-lg { height: 48px; border-radius: 10px; font-size: 15px; margin-top: 8px; }

.auth-switch { margin-top: 22px; font-size: 13px; color: var(--text-2); text-align: center; }
.auth-switch a { font-weight: 600; }

/* 注册赠送提示 */
.bonus-note {
  display: flex; align-items: center; gap: 8px; padding: 10px 13px; border-radius: 9px;
  background: var(--ok-soft); border: 1px solid #c9ecdd; color: #0b7d52;
  font-size: 12.5px; font-weight: 550; margin-bottom: 18px;
}

@media (max-width: 900px) {
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-left { display: none; }
  .auth-right { padding: 40px 28px; border-left: none; min-height: 100dvh; align-items: flex-start; }
  .auth-form { max-width: 420px; margin: 0 auto; }

  /* 侧边栏改为抽屉 */
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100dvh; width: 252px; flex-basis: 252px;
    transform: translateX(-100%); transition: transform .22s cubic-bezier(.4,0,.2,1);
    z-index: 60; will-change: transform; box-shadow: none;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .menu-btn { display: grid; }
  .side-close { display: grid; }

  .content { padding: 16px; max-width: 100%; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .topbar { padding: 0 14px; height: 56px; }
  .topbar-right { gap: 8px; min-width: 0; }
  .topbar-right .btn-sm { padding: 0 9px; font-size: 12px; }
  #balance-chip .badge { height: 24px; font-size: 11.5px; padding: 0 7px; }
}
body { overflow-x: hidden; }

/* Code sample group */
.code-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.code-tabs button {
  border: 1px solid var(--border-strong); background: #fff; padding: 5px 12px; border-radius: 7px;
  font-size: 12.5px; cursor: pointer; font-family: inherit; color: var(--text-2); font-weight: 550;
}
.code-tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* Model catalog card */
.model-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  display: flex; flex-direction: column; gap: 12px; transition: border-color .14s, box-shadow .14s;
}
.model-card:hover { border-color: #c8d3e6; box-shadow: var(--shadow); }
.model-card .mc-name { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--brand); word-break: break-all; }
.model-card .mc-title { font-weight: 650; font-size: 15px; }
.price-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; }
.price-row .pv { font-variant-numeric: tabular-nums; font-weight: 600; }

.upstream-row {
  border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; background: #fcfdfe; margin-bottom: 10px;
}
.upstream-row .ur-grid { display: grid; grid-template-columns: 2.2fr 1.4fr 1.6fr 64px 70px; gap: 10px; align-items: end; }

.scroll-y { overflow-y: auto; }

/* ============ 调用记录卡片（仅手机显示） ============ */
.log-cards { display: none; }
.log-card {
  padding: 12px 13px; border-bottom: 1px solid var(--border);
}
.log-card:last-child { border-bottom: none; }
.lc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lc-model {
  font-size: 12.5px; font-weight: 600; color: var(--brand);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.lc-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 5px; font-size: 11px; color: var(--text-3);
}
.lc-time { font-variant-numeric: tabular-nums; }
.lc-tag { background: var(--bg-soft); border-radius: 4px; padding: 0 5px; font-size: 10.5px; }
.lc-stats {
  display: flex; align-items: center; gap: 6px 14px; flex-wrap: wrap;
  margin-top: 7px; font-size: 11.5px; color: var(--text-2);
}
.lc-stats b { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.lc-lat { margin-left: auto; color: var(--text-3); font-variant-numeric: tabular-nums; }
.lc-url {
  margin-top: 6px; font-size: 11px; color: var(--text-2);
  word-break: break-all; line-height: 1.5;
}
/* 卡片内的操作按钮组 */
.lc-actions {
  display: flex; gap: 8px; margin-top: 9px;
}
.lc-actions .btn { flex: 1 1 0; height: 30px; font-size: 12px; }

/* 模型勾选卡片 */
.model-pick {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 9px; background: #fff; transition: all .13s;
}
.model-pick:hover { border-color: #c8d3e6; background: #fbfcfe; }
.model-pick:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.model-pick input[type=checkbox] {
  width: 16px; height: 16px; margin: 2px 0 0; flex: 0 0 16px; accent-color: var(--brand); cursor: pointer;
}
.model-pick .mp-body { min-width: 0; flex: 1; }
.model-pick .mp-name { font-weight: 650; font-size: 13.5px; }
.model-pick .mp-id { font-size: 11.5px; color: var(--text-3); word-break: break-all; margin-top: 1px; }
.model-pick .mp-price { margin-top: 4px; }

/* ============ 筛选栏 ============ */
.filter-bar {
  padding: 12px 22px; border-bottom: 1px solid var(--border); background: #fbfcfd;
  display: flex; flex-direction: column; gap: 9px;
}
.filter-bar .fb-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.fb-seg {
  display: inline-flex; background: var(--bg-soft); padding: 3px; border-radius: 9px; gap: 2px;
  flex-wrap: wrap; flex: 0 0 auto;
}
.fb-seg-btn {
  border: none; background: transparent; height: 28px; padding: 0 12px; border-radius: 7px;
  font-size: 12.5px; font-weight: 550; color: var(--text-2); cursor: pointer;
  font-family: inherit; transition: all .13s; white-space: nowrap;
}
.fb-seg-btn:hover { color: var(--text); background: rgba(255,255,255,.7); }
.fb-seg-btn.active { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(16,24,40,.10); font-weight: 650; }
.fb-dates { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
/* 属性选择器优先级高于 class，这里必须显式压过全局 input 规则 */
.filter-bar input[type=date] {
  height: 30px; padding: 0 8px; font-size: 12.5px; border-radius: 7px;
  width: 132px; flex: 0 0 132px;
}
.filter-bar input.fb-search {
  width: 200px; flex: 0 0 200px; height: 30px; font-size: 12.5px; border-radius: 7px; padding: 0 11px;
}
.filter-bar select.fb-select {
  width: auto; flex: 0 0 auto; min-width: 148px; max-width: 220px;
  height: 30px; font-size: 12.5px; border-radius: 7px; padding: 0 28px 0 11px;
}
.filter-bar .fb-spacer { flex: 1 1 auto; min-width: 0; }
.filter-bar .fb-reset {
  height: 30px; padding: 0 13px; font-size: 12.5px; border-radius: 7px; flex: 0 0 auto;
}
.fb-summary {
  display: flex; gap: 10px 18px; padding: 10px 22px; background: var(--brand-soft);
  border-bottom: 1px solid #d8e3ff; font-size: 12.5px; flex-wrap: wrap;
}
.fb-summary b { font-variant-numeric: tabular-nums; }

/* ============ 充值档位卡片 ============ */
.tier-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
}
.tier-card {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 16px 14px 13px;
  background: var(--bg-elev);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  text-align: left;
  transition: border-color .15s, box-shadow .15s, transform .12s;
  overflow: visible;
}
.tier-card:hover:not(:disabled) { border-color: var(--brand); transform: translateY(-1px); }
.tier-card.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.tier-card:disabled { opacity: .5; cursor: not-allowed; }

.tier-price {
  font-size: 21px; font-weight: 700; letter-spacing: -.02em;
  color: var(--brand); font-variant-numeric: tabular-nums;
}
.tier-points {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums;
}
.tier-bonus {
  font-size: 11.5px; color: #e2622b; font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.tier-bonus-none { color: var(--muted); font-weight: 400; }

/* 角标：绝对定位到卡片右上角，允许溢出 */
.tier-ribbon {
  position: absolute; top: -9px; right: 8px;
  padding: 2px 9px;
  font-size: 10.5px; font-weight: 600; line-height: 1.5;
  color: #fff;
  background: linear-gradient(135deg, #ff8a4c, #f2622e);
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(242, 98, 46, .3);
}
.tier-ribbon-plain {
  background: var(--brand);
  box-shadow: 0 2px 6px rgba(47, 107, 255, .28);
}

/* ============ 手机适配（640 / 480 / 380 三档） ============ */
@media (max-width: 640px) {
  body { font-size: 13.5px; }
  .content { padding: 12px; overflow-x: hidden; }
  /* 卡片裁掉溢出的表格滚动区，避免整页横滑 */
  .card { overflow: hidden; }

  /* 顶栏：标题可截断，右侧按钮不被挤爆 */
  .topbar { height: 52px; padding: 0 12px; }
  .topbar-title { font-size: 14px; }
  .topbar-right { gap: 6px; }
  /* 窄屏把「管理后台」收进头像菜单，给标题腾地方 */
  #admin-entry { display: none; }
  .topbar-right > .btn-sm { height: 30px; padding: 0 9px; font-size: 12px; }
  #balance-chip .badge { height: 26px; font-size: 11.5px; }
  #user-menu { padding: 0 7px; height: 32px; }
  .uc-text { display: none; }
  .uc-avatar { width: 24px; height: 24px; flex-basis: 24px; font-size: 11px; }
  #user-drop { width: 176px !important; }

  /* 统计卡：两列，数值缩小 */
  .grid { gap: 10px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat { padding: 13px 14px; border-radius: 9px; }
  .stat .k { font-size: 11.5px; }
  .stat .v { font-size: 21px; }
  .stat .s { font-size: 11px; }

  /* 卡片头：标题和操作同一行，过长则右侧操作下移 */
  .card-head { padding: 12px 13px; flex-wrap: nowrap; gap: 8px; align-items: center; }
  .card-head > div { min-width: 0; flex: 1 1 auto; }
  .card-head > .btn, .card-head > .btn-sm, .card-head > a.btn { flex: 0 0 auto; margin-left: auto; }
  .card-head > span.tiny { flex: 0 0 auto; white-space: nowrap; }
  /* 右侧按钮组/操作区不参与压缩，否则会被裁掉 */
  .card-head > .row, .card-head > .row.nowrap { flex: 0 0 auto; margin-left: auto; }
  .card-head > .row > .btn, .card-head > .row > .btn-sm { flex: 0 0 auto; }
  .card-head h3 { font-size: 14px; }
  /* 模型 ID 徽章过长时截断，别把卡片撑破 */
  .card-head .badge.mono {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; display: inline-block; line-height: 20px;
  }
  .card-body { padding: 14px; }
  .card-pad { padding: 14px; }

  /* 表格：横向滚动 + 首列吸附，避免整页被撑破 */
  .table-wrap {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    /* 右侧渐隐提示"还有更多列"，用 background-attachment:local 让它随内容滚动 */
    background:
      linear-gradient(to right, var(--bg-elev) 30%, rgba(255,255,255,0)) left center / 28px 100% no-repeat local,
      linear-gradient(to left, var(--bg-elev) 30%, rgba(255,255,255,0)) right center / 28px 100% no-repeat local,
      radial-gradient(farthest-side at 0 50%, rgba(16,24,40,.14), transparent) left center / 12px 100% no-repeat scroll,
      radial-gradient(farthest-side at 100% 50%, rgba(16,24,40,.14), transparent) right center / 12px 100% no-repeat scroll;
  }
  .table-wrap table { min-width: 460px; }
  .table-wrap thead th, .table-wrap tbody td {
    padding: 8px 9px; font-size: 12px; white-space: nowrap;
  }
  .table-wrap thead th:first-child, .table-wrap tbody td:first-child {
    position: sticky; left: 0; z-index: 2;
    background: var(--bg-elev); box-shadow: 1px 0 0 var(--border);
  }
  .table-wrap thead th:first-child { background: var(--bg-soft); }
  .table-wrap thead th { font-size: 10.5px; letter-spacing: .02em; }
  .table-wrap .mono, .table-wrap .tiny { font-size: 11px; }
  .table-wrap .badge { height: 19px; padding: 0 6px; font-size: 10.5px; }
  /* 无 field 包裹的简单两列信息表（账号设置等）不强制最小宽 */
  table.small, .card-body > table { min-width: 0; }
  table.small tbody td, .card-body > table tbody td {
    padding: 8px 0; font-size: 12.5px; white-space: normal;
  }
  .card-body > table tbody td:first-child { padding-right: 12px; }

  /* 弹窗：贴边全宽，底部按钮铺满 */
  .modal-mask { padding: 10px; align-items: flex-start; }
  .modal {
    max-width: 100%; max-height: calc(100dvh - 20px); border-radius: 13px;
    margin: auto 0;
  }
  .modal.modal-lg { max-width: 100%; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; height: 40px; }

  /* 表单控件：16px 防止 iOS 聚焦自动放大 */
  input[type=text], input[type=email], input[type=password], input[type=number],
  input[type=search], input[type=tel], select, textarea {
    font-size: 16px; height: 40px;
  }
  textarea { height: auto; }
  .auth-form input[type=tel], .auth-form input[type=password],
  .auth-form input[type=text] { height: 44px; font-size: 16px; }
  .auth-form h1 { font-size: 22px; }
  .auth-form .sub { margin-bottom: 22px; }
  .auth-tabs { margin-bottom: 22px; }

  /* 按钮触摸目标 */
  .btn { height: 38px; padding: 0 14px; font-size: 13.5px; }
  .btn-sm { height: 32px; padding: 0 10px; }
  .icon-btn { width: 36px; height: 36px; }

  /* 筛选栏：分段按钮一行塞不下就横滚 */
  .filter-bar { padding: 10px 12px; gap: 8px; }
  .filter-bar .fb-row { gap: 8px; flex-wrap: wrap; }
  .fb-seg {
    width: 100%; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .fb-seg::-webkit-scrollbar { display: none; }
  .fb-seg-btn { flex: 0 0 auto; padding: 0 11px; height: 30px; font-size: 12.5px; }
  .filter-bar input.fb-search { width: auto; flex: 1 1 120px; min-width: 0; height: 34px; padding: 0 10px; }
  .filter-bar select.fb-select { flex: 1 1 110px; min-width: 0; max-width: none; width: auto; height: 34px; }
  .filter-bar .fb-reset { height: 34px; flex: 0 0 auto; padding: 0 12px; }
  .filter-bar .fb-spacer { display: none; }
  .filter-bar input[type=date] { width: 100%; flex: 1 1 120px; height: 34px; }
  .fb-dates { width: 100%; flex-wrap: wrap; }
  .fb-summary { padding: 9px 12px; gap: 10px 16px; }

  /* 调用记录 / 测试结果：手机上用卡片替代表格 */
  .log-cards { display: block; }
  /* 与卡片同级的表格（同一父容器内）直接隐藏，避免两套内容并存 */
  .log-cards ~ .table-wrap, .table-wrap:has(+ .log-cards) { display: none; }

  /* 上游通道卡片：主信息换行 */
  .up-item { flex-wrap: wrap; gap: 9px; padding: 10px 11px; }
  .up-main { flex-basis: 100%; order: 3; }
  .up-side { margin-left: auto; }
  .up-url { white-space: normal; word-break: break-all; }

  /* key 展示框换行 */
  .key-box { padding: 9px 10px; font-size: 11.5px; }

  /* toast 顶部铺满，但避开 topbar */
  #toasts { top: 60px; left: 10px; right: 10px; }
  .toast { min-width: 0; max-width: none; width: 100%; font-size: 12.5px; padding: 10px 12px; }

  pre { padding: 13px 14px; font-size: 11.5px; border-radius: 9px; }
  .empty { padding: 34px 16px; }
  h1 { font-size: 21px; }
  h2 { font-size: 17px; }
}

@media (max-width: 480px) {
  .content { padding: 10px; }
  /* 统计卡：保持两列，但压缩成紧凑版（4 个指标一屏可见） */
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 11px 12px; }
  .stat .k { font-size: 11px; }
  .stat .v { font-size: 18px; }
  .stat .s { font-size: 10.5px; }
  .card-head .btn, .card-head .btn-sm { flex: 0 0 auto; }
  .up-pri { min-width: 30px; height: 22px; font-size: 11px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .auth-right { padding: 30px 18px; }
  /* 顶栏再挤一点 */
  #balance-chip .badge { padding: 0 6px; font-size: 11px; }
  .uc-avatar { width: 22px; height: 22px; flex-basis: 22px; font-size: 10px; }
}

@media (max-width: 380px) {
  .content { padding: 9px; }
  .topbar { height: 50px; }
  .topbar-title { font-size: 13px; }
  .card-head, .card-body, .card-pad { padding-left: 11px; padding-right: 11px; }
  /* 极窄屏：标题允许换行，操作区仍然贴右且不被压缩 */
  .card-head { flex-wrap: wrap; }
  .card-head > .btn, .card-head > .btn-sm, .card-head > a.btn,
  .card-head > .row, .card-head > span.tiny { margin-left: auto; }
  .card-head h3 { font-size: 13.5px; }
  .fb-seg-btn { padding: 0 9px; font-size: 12px; }
  .btn { padding: 0 11px; }
  .stat .v { font-size: 18px; }
  .grid { gap: 8px; }
}

/* 横屏矮屏（如手机横放）：弹窗不超高 */
@media (max-height: 460px) and (orientation: landscape) {
  .modal-mask { padding: 6px; }
  .modal { max-height: calc(100dvh - 12px); }
  .sidebar { width: 230px; }
}
