/* AI 网关中台 —— 移动端优先样式
 *
 * 设计取向：
 *   运维大概率在手机上瞄一眼，所以默认按手机布局写，桌面端只是加宽。
 *   信息密度优先：一屏能看到「余额 / 账号健康 / 并发 / 今日消耗」四个关键数。
 *   深色主题，和 wb2api 面板保持一致，切换时不刺眼。
 */

:root {
  --bg: #0f1115;
  --bg-soft: #15181e;
  --card: #1a1d23;
  --card-hi: #21252d;
  --line: #2a2f38;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --text-faint: #6b7482;

  --blue: #3b82f6;
  --green: #10b981;
  --red: #ef4444;
  --amber: #f59e0b;
  --purple: #8b5cf6;

  /* 语义色：深/浅两套主题各自覆盖，别在组件里写死颜色 */
  --nav-bg: rgba(21, 24, 30, 0.96);
  --topbar-bg: rgba(15, 17, 21, 0.92);
  --toast-bg: #262b34;
  --toast-fg: #eef2f7;
  --toast-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --danger-fg: #f87171;
  --btn-grad-a: #2563eb;
  --btn-grad-b: #7c3aed;
  --ring: rgba(255, 255, 255, 0.15);
  --glow: rgba(59, 130, 246, 0.1);
  --err-bg: #3a1d1f;
  --err-fg: #fca5a5;
  --err-line: rgba(239, 68, 68, 0.4);
  --ok-bg: #143029;
  --ok-fg: #6ee7b7;
  --ok-line: rgba(16, 185, 129, 0.4);
  --input-bg: var(--bg-soft);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-login: 0 18px 50px rgba(0, 0, 0, 0.45);
  --glow-a: rgba(59, 130, 246, 0.22);
  --glow-b: rgba(139, 92, 246, 0.2);

  --radius: 12px;
  --nav-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* 淡色主题：只覆盖颜色变量，组件样式完全复用。
   切换方式见 index.html / login.html 的 themeInit，以及设置页的「外观」。 */
:root[data-theme='light'] {
  --bg: #f4f6f9;
  --bg-soft: #ffffff;
  --card: #ffffff;
  --card-hi: #f0f3f7;
  --line: #e2e6ed;
  --text: #16191f;
  --text-dim: #4d5665;
  /* 浅底上次要文字必须压深，否则对比度只有 2.8，手机上基本看不清 */
  --text-faint: #6b7482;

  --blue: #2563eb;
  --green: #047857;
  --red: #dc2626;
  --amber: #b45309;
  --purple: #7c3aed;

  --nav-bg: rgba(255, 255, 255, 0.94);
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --toast-bg: #1f2733;
  --toast-fg: #f4f7fb;
  --toast-shadow: 0 10px 30px rgba(16, 24, 40, 0.18);
  --danger-fg: #b91c1c;
  --btn-grad-a: #2563eb;
  --btn-grad-b: #7c3aed;
  --ring: rgba(15, 23, 42, 0.12);
  --glow: rgba(37, 99, 235, 0.09);
  --err-bg: #fef2f2;
  --err-fg: #b91c1c;
  --err-line: rgba(220, 38, 38, 0.28);
  --ok-bg: #ecfdf5;
  --ok-fg: #047857;
  --ok-line: rgba(5, 150, 105, 0.28);
  --input-bg: #f7f9fc;
  --shadow-card: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-login: 0 14px 40px rgba(16, 24, 40, 0.1), 0 2px 6px rgba(16, 24, 40, 0.05);
  --glow-a: rgba(37, 99, 235, 0.14);
  --glow-b: rgba(124, 58, 237, 0.11);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 8px); }

/* ---------------------------------------------------------------- 顶栏 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  letter-spacing: 0.2px;
}

.topbar .status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
  flex-shrink: 0;
}
.topbar .status-dot.bad {
  background: var(--red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------------------------------------------------------------- 内容区 */

.page { padding: 14px; display: none; }
.page.active { display: block; }

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin: 20px 2px 10px;
}
.section-title:first-child { margin-top: 4px; }

/* ---------------------------------------------------------------- 关键指标 */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--blue);
  opacity: 0.8;
}
.kpi.green::after { background: var(--green); }
.kpi.amber::after { background: var(--amber); }
.kpi.red::after { background: var(--red); }
.kpi.purple::after { background: var(--purple); }

.kpi .label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.kpi .value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.kpi .value small {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: 0;
  margin-left: 3px;
}
.kpi .sub {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 5px;
}
.kpi .sub.warn { color: var(--amber); }
.kpi .sub.bad { color: var(--red); }

/* ---------------------------------------------------------------- 卡片 */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-card);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.card-head .t {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
}
.card-head .badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--card-hi);
  color: var(--text-dim);
  border: 1px solid var(--line);
}
.badge.ok { color: var(--green); border-color: rgba(16,185,129,.3); background: rgba(16,185,129,.1); }
.badge.bad { color: var(--red); border-color: rgba(239,68,68,.3); background: rgba(239,68,68,.1); }
.badge.warn { color: var(--amber); border-color: rgba(245,158,11,.3); background: rgba(245,158,11,.1); }

/* ---------------------------------------------------------------- 账号卡 */

.acct {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.acct.off { opacity: 0.55; }

.acct-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.acct-name {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.acct-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.acct-stat .k {
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 2px;
}
.acct-stat .v {
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* 余额进度条：直观看出还剩多少 */
.bar {
  height: 5px;
  border-radius: 3px;
  background: var(--card-hi);
  overflow: hidden;
  margin-top: 6px;
}
.bar > i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background: var(--green);
  transition: width 0.4s ease;
}
.bar > i.warn { background: var(--amber); }
.bar > i.bad { background: var(--red); }

/* ---------------------------------------------------------------- 操作按钮 */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button, .btn {
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card-hi);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
  white-space: nowrap;
}
button:active { transform: scale(0.97); }
button:hover:not(:disabled) { background: #282d36; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #2f74e0; }
button.danger { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.35); color: var(--danger-fg); }
button.danger:hover:not(:disabled) { background: rgba(239,68,68,.2); }
button.ok { background: rgba(16,185,129,.12); border-color: rgba(16,185,129,.35); color: #34d399; }
button.ghost { background: transparent; }
button.sm { padding: 6px 10px; font-size: 12px; }

/* ---------------------------------------------------------------- 表格 */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -14px;
  padding: 0 14px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
th {
  text-align: left;
  font-weight: 600;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td {
  padding: 8px;
  border-bottom: 1px solid rgba(42,47,56,.5);
  white-space: nowrap;
}
tr:last-child td { border-bottom: none; }
tr.fail td { color: var(--danger-fg); }

/* ---------------------------------------------------------------- 表单 */

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field .hint,
.hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-top: 5px;
  line-height: 1.45;
}

/* 分段控件（外观：深色 / 淡色） */
.seg {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.seg button {
  flex: 1;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.on {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  font: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); }
input::placeholder { color: var(--text-faint); }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid rgba(42,47,56,.6);
}
.switch-row:last-child { border-bottom: none; }
.switch-row .lbl { flex: 1; font-size: 13.5px; }
.switch-row .desc { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }

.switch {
  position: relative;
  width: 44px; height: 26px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute;
  inset: 0;
  background: var(--card-hi);
  border: 1px solid var(--line);
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.switch span::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 3px; top: 3px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.2s, background 0.2s;
}
.switch input:checked + span { background: rgba(59,130,246,.25); border-color: var(--blue); }
.switch input:checked + span::before { transform: translateX(18px); background: var(--blue); }

/* ---------------------------------------------------------------- 底部导航 */

.nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--nav-bg);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--nav-h);
  color: var(--text-faint);
  text-decoration: none;
  font-size: 10.5px;
  transition: color 0.15s;
}
.nav a.active { color: var(--blue); }
.nav a svg { width: 21px; height: 21px; stroke-width: 1.9; }

/* ---------------------------------------------------------------- 提示 */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  border: 1px solid var(--line);
  box-shadow: var(--toast-shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 100;
  max-width: calc(100vw - 40px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--err-bg); border-color: var(--err-line); color: var(--err-fg); }
#toast.ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-fg); }

/* ---------------------------------------------------------------- 登录页 */

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + var(--safe-b));
  position: relative;
  overflow: hidden;
}

/* 背景光晕：两团模糊色块，别太重，否则刺眼 */
.login-wrap::before,
.login-wrap::after {
  content: '';
  position: fixed;
  border-radius: 50%;
  filter: blur(72px);
  pointer-events: none;
  z-index: 0;
}
.login-wrap::before {
  width: 420px; height: 420px;
  top: -170px; left: -130px;
  background: radial-gradient(circle, var(--glow-a), transparent 70%);
}
.login-wrap::after {
  width: 380px; height: 380px;
  bottom: -160px; right: -120px;
  background: radial-gradient(circle, var(--glow-b), transparent 70%);
}

.login-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
}

.login-box .logo { text-align: center; margin-bottom: 22px; }
.login-box .logo .ico {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 22px rgba(59, 130, 246, 0.3);
}
.login-box .logo h1 {
  font-size: 20px;
  margin: 0 0 5px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.login-box .logo p { font-size: 12.5px; color: var(--text-faint); margin: 0; }

/* 登录表单卡片 */
.login-box form.card {
  padding: 22px 20px;
  border-radius: 16px;
  box-shadow: var(--shadow-login);
}
.login-box .field { margin-bottom: 14px; }
.login-box .field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.login-box input[type='text'],
.login-box input[type='password'] {
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 10px;
}

/* 密码可见切换 */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-faint);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  line-height: 0;
}
.pw-toggle:hover { color: var(--text); background: var(--card-hi); }

.login-box .btn-login {
  width: 100%;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border: none;
  border-radius: 11px;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, var(--btn-grad-a), var(--btn-grad-b));
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.28);
  transition: transform 0.12s, box-shadow 0.18s, opacity 0.15s;
}
.login-box .btn-login:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 9px 24px rgba(59, 130, 246, 0.34);
}
.login-box .btn-login:active:not(:disabled) { transform: translateY(0); }
.login-box .btn-login:disabled { opacity: 0.6; cursor: default; }

/* 错误条 */
.login-err {
  display: none;
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 12.5px;
  line-height: 1.45;
  background: var(--err-bg);
  color: var(--err-fg);
  border: 1px solid var(--err-line);
}
.login-err.show { display: block; }

/* 右上角外观切换 */
.theme-fab {
  position: fixed;
  top: 14px; right: 14px;
  z-index: 5;
  width: 38px; height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--card);
  color: var(--text-dim);
  cursor: pointer;
  box-shadow: var(--shadow-card);
  transition: color 0.15s, border-color 0.15s;
}
.theme-fab:hover { color: var(--text); border-color: var(--blue); }

/* ---------------------------------------------------------------- 空态 / 加载 */

.empty {
  text-align: center;
  padding: 36px 20px;
  color: var(--text-faint);
  font-size: 13px;
}
.empty svg { width: 36px; height: 36px; opacity: 0.35; margin-bottom: 10px; }

.loading {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid var(--ring);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--card) 25%, var(--card-hi) 50%, var(--card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 8px;
  height: 60px;
  margin-bottom: 10px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------------------------------------------------------------- 工具类 */

.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.tiny { font-size: 11.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.mt8 { margin-top: 8px; }
.mt12 { margin-top: 12px; }
.mb0 { margin-bottom: 0; }
.green { color: var(--green); }
.red { color: var(--red); }
.amber { color: var(--amber); }
.blue { color: var(--blue); }
.hidden { display: none !important; }

/* ---------------------------------------------------------------- 桌面端 */

@media (min-width: 768px) {
  body { padding-bottom: 0; padding-left: 200px; }

  /* 登录页没有侧边栏。原先这里同时给 body 和 .login-wrap 各加了 200px 左内边距，
     登录框被顶到右边 400px，这就是"登录页是乱的"的原因。
     给 body 加 login-page 类来清掉为导航预留的偏移。 */
  body.login-page { padding-left: 0; }

  .nav {
    left: 0; top: 0; bottom: 0; right: auto;
    width: 200px;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--line);
    padding: 16px 0;
    background: var(--bg-soft);
  }
  .nav a {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    height: 46px;
    padding: 0 20px;
    font-size: 13.5px;
  }
  .nav a.active { background: var(--glow); }

  #toast { bottom: 24px; }

  .page { max-width: 1080px; margin: 0 auto; padding: 18px 24px; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
  .topbar { padding-left: 24px; padding-right: 24px; }
}
