:root {
  --bg: #060608;
  --surface: #0e0e12;
  --inset: #0a0a0d;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.11);
  --text: #ededf2;
  --dim: #8b8b96;
  --dimmer: #55555e;
  --accent: #8b93ff;
  --green: #3ecf8e;
  --amber: #f5b53f;
  --red: #f4647e;
  --mono: "SF Mono", "Cascadia Code", Consolas, "JetBrains Mono", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum";
}
::selection { background: rgba(139, 147, 255, 0.25); }

/* 顶部氛围光 */
body::before {
  content: ""; position: fixed; inset: 0 0 auto 0; height: 460px; pointer-events: none;
  background:
    radial-gradient(ellipse 50% 90% at 50% -10%, rgba(139, 147, 255, 0.07), transparent 70%),
    radial-gradient(ellipse 30% 60% at 85% 0%, rgba(62, 207, 142, 0.04), transparent 70%);
}

/* ---------- 顶栏(毛玻璃吸附) ---------- */
header {
  position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  background: rgba(6, 6, 8, 0.72);
  border-bottom: 1px solid var(--border);
}
.header-in {
  max-width: 1180px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px 28px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { display: block; }
.brand .name { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.brand .tag { font-size: 11.5px; color: var(--dimmer); margin-top: 1px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.conn-status {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; font-size: 12px; color: var(--dim);
  background: rgba(255, 255, 255, 0.025);
}
.conn-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--amber); transition: background 0.3s; }
.conn-status.live { color: #9ee8c6; border-color: rgba(62, 207, 142, 0.22); background: rgba(62, 207, 142, 0.06); }
.conn-status.live .dot { background: var(--green); box-shadow: 0 0 7px rgba(62, 207, 142, 0.8); animation: breathe 2.4s ease-in-out infinite; }
.conn-status.down { color: #f5c78e; border-color: rgba(245, 181, 63, 0.22); background: rgba(245, 181, 63, 0.06); }
@keyframes breathe { 50% { opacity: 0.45; } }
.uptime {
  border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 12px; font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.02em; color: var(--dim);
  background: rgba(255, 255, 255, 0.025);
}

main {
  position: relative; max-width: 1180px; margin: 0 auto;
  padding: 22px 28px 64px;
  display: flex; flex-direction: column; gap: 14px;
}

/* ---------- KPI ---------- */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px 20px 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035), 0 8px 24px rgba(0, 0, 0, 0.25);
  transition: border-color 0.15s, transform 0.15s;
}
.kpi-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.kpi-label { font-size: 12px; color: var(--dim); margin-bottom: 12px; }
.kpi-value {
  font-size: 30px; font-weight: 620; letter-spacing: -0.03em;
  line-height: 1.05; font-variant-numeric: tabular-nums;
}
.kpi-value.accent { color: var(--accent); }
.kpi-foot { font-size: 11.5px; color: var(--dimmer); margin-top: 10px; font-family: var(--mono); letter-spacing: 0.01em; }

/* ---------- 面板 ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035), 0 8px 24px rgba(0, 0, 0, 0.25);
}
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 22px 0;
}
.panel-title { font-size: 13.5px; font-weight: 600; letter-spacing: 0.005em; }
.panel-sub { font-size: 12px; color: var(--dimmer); margin-top: 3px; }
.panel-body { padding: 16px 22px 22px; }

.range-switch {
  display: flex; gap: 2px; padding: 2px;
  background: var(--inset);
  border: 1px solid var(--border); border-radius: 9px;
}
.range-switch button {
  background: transparent; border: none; color: var(--dimmer);
  border-radius: 7px; padding: 4px 13px; font-size: 12px; cursor: pointer;
  font-family: var(--mono); transition: color 0.12s, background 0.12s;
}
.range-switch button:hover { color: var(--dim); }
.range-switch button.active { background: rgba(255, 255, 255, 0.08); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); }

#chart { width: 100%; height: 240px; display: block; margin-top: 6px; cursor: crosshair; }
.chart-legend { display: flex; gap: 22px; margin-top: 12px; font-size: 12px; color: var(--dim); }
.chart-legend span { display: flex; align-items: center; gap: 7px; }
.chart-legend .sw { width: 8px; height: 8px; border-radius: 2.5px; }
.chart-legend .sw.cache { border-radius: 50%; }
.sw.in { background: linear-gradient(180deg, #a4abff, #7982f0); }
.sw.out { background: linear-gradient(180deg, #5ee8b1, #2fae7c); }
.sw.cache { background: var(--amber); }

/* ---------- 密钥池 ---------- */
.upstream-block { margin-bottom: 22px; }
.upstream-block:last-child { margin-bottom: 0; }
.upstream-sessions {
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
  background: rgba(255, 255, 255, 0.02); white-space: nowrap;
}

.key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(430px, 1fr)); gap: 12px; }
.key-card {
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--inset);
  padding: 16px 18px 14px;
  transition: border-color 0.15s;
}
.key-card:hover { border-color: var(--border-strong); }
.key-card.cooling { opacity: 0.6; }

.key-top { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.key-label { font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.key-upstream {
  font-family: var(--mono); font-size: 11px; color: var(--dimmer);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.key-side { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.key-badge { display: flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 500; white-space: nowrap; }
.key-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; }
.key-badge.ok { color: var(--green); }
.key-badge.ok::before { background: var(--green); box-shadow: 0 0 6px rgba(62, 207, 142, 0.7); }
.key-badge.down { color: var(--red); }
.key-badge.down::before { background: var(--red); box-shadow: 0 0 6px rgba(244, 100, 126, 0.7); }

.key-stats { display: flex; gap: 8px; margin-bottom: 13px; }
.ks {
  flex: 1; position: relative; overflow: hidden;
  padding: 9px 12px 10px;
  border: 1px solid var(--border); border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.005));
  transition: border-color 0.15s;
}
.ks:hover { border-color: var(--border-strong); }
/* 顶部彩色亮线,随指标主题色变化 */
.ks::after {
  content: ""; position: absolute; top: 0; left: 12px; right: 12px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--kc, var(--accent)), transparent);
  opacity: 0.6;
}
.ks .k {
  display: flex; align-items: center; gap: 6px;
  font-size: 10.5px; color: var(--dimmer); letter-spacing: 0.04em; margin-bottom: 4px;
}
.ks .k::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--kc, var(--accent));
  box-shadow: 0 0 6px var(--kc, var(--accent));
}
.ks .v {
  font-family: var(--mono); font-size: 15px; font-weight: 650;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  color: color-mix(in srgb, var(--kc, var(--accent)) 25%, var(--text));
}
.ks.a-green { --kc: var(--green); }
.ks.a-blue { --kc: var(--accent); }
.ks.a-violet { --kc: #b48bff; }
.ks.a-amber { --kc: var(--amber); }
.ks.a-red { --kc: var(--red); }

.quota-bar-row { margin-top: 9px; }
.quota-bar-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; color: var(--dim); margin-bottom: 5px;
}
.quota-bar-label .r { font-family: var(--mono); font-size: 10.5px; color: var(--dimmer); }
.quota-bar { height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.055); overflow: hidden; }
.quota-bar > i {
  display: block; height: 100%; border-radius: 99px;
  background: linear-gradient(90deg, #6d76e8, var(--accent));
  transition: width 0.5s ease;
}
.quota-bar.warn > i { background: linear-gradient(90deg, #d99a2b, var(--amber)); }
.quota-bar.danger > i { background: linear-gradient(90deg, #e04a64, var(--red)); }

.account-row { margin-top: 13px; padding-top: 12px; border-top: 1px dashed rgba(255, 255, 255, 0.07); }
.account-row.error {
  color: var(--amber); font-size: 12px; border-top: 1px dashed rgba(255, 255, 255, 0.07);
  display: flex; align-items: center; gap: 10px;
}
.account-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.account-meta span {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 3px 8px; background: rgba(255, 255, 255, 0.02);
}
.account-login-btn {
  background: rgba(245, 181, 63, 0.08); border: 1px solid rgba(245, 181, 63, 0.3);
  color: var(--amber); border-radius: 7px; padding: 3px 11px;
  font-size: 11px; cursor: pointer;
}
.account-login-btn:hover { background: rgba(245, 181, 63, 0.15); }

/* ---------- API 密钥发放 ---------- */
.hidden { display: none !important; }
.ak-issue { display: flex; align-items: center; gap: 8px; }
.ak-issue input {
  background: var(--inset); border: 1px solid var(--border);
  border-radius: 9px; padding: 6px 12px; color: var(--text);
  font-size: 12.5px; outline: none; width: 200px;
  transition: border-color 0.14s;
}
.ak-issue input:focus { border-color: rgba(139, 147, 255, 0.5); }
.ak-new {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid rgba(62, 207, 142, 0.3); background: rgba(62, 207, 142, 0.06);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 14px;
  font-size: 12.5px; color: #9ee8c6;
}
.ak-new code {
  font-family: var(--mono); font-size: 12px; color: var(--text);
  user-select: all; word-break: break-all;
}
.ak-hint {
  border: 1px solid rgba(245, 181, 63, 0.3); background: rgba(245, 181, 63, 0.06);
  color: var(--amber); border-radius: 10px; padding: 9px 14px;
  font-size: 12px; margin-bottom: 14px;
}
.ak-table { margin-top: 2px; }
.ak-mono { font-family: var(--mono); font-size: 12px; }

/* ---------- 日志 ---------- */
.log-wrap { overflow-x: auto; max-height: 400px; overflow-y: auto; margin: 4px -22px -22px; padding: 0 22px 10px; }
.log-table { width: 100%; border-collapse: collapse; }
.log-table th {
  text-align: left; color: var(--dimmer); font-weight: 500; font-size: 11px; letter-spacing: 0.03em;
  padding: 10px 14px 8px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.log-table td {
  padding: 9px 14px; border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  font-size: 12.5px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.log-table tbody tr { transition: background 0.1s; }
.log-table tbody tr:hover td { background: rgba(255, 255, 255, 0.022); }
.log-table tbody tr:last-child td { border-bottom: none; }
.log-table tr.flash { animation: flash 0.8s ease-out; }
@keyframes flash { from { background: rgba(139, 147, 255, 0.1); } to { background: transparent; } }
.st {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 6px;
}
.st::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.st.ok { color: var(--green); background: rgba(62, 207, 142, 0.09); }
.st.err { color: var(--red); background: rgba(244, 100, 126, 0.09); }
.st.warn { color: var(--amber); background: rgba(245, 181, 63, 0.09); }
.cell-dim { color: var(--dimmer); }
.cell-cache { color: var(--amber); }

/* ---------- 按钮 ---------- */
.ghost-btn {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; padding: 6px 14px;
  font-size: 12.5px; font-weight: 500; cursor: pointer;
  transition: background 0.14s, border-color 0.14s;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.09); border-color: var(--border-strong); }
.icon-btn {
  background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border);
  color: var(--dim); border-radius: 7px; padding: 3px 11px;
  font-size: 11.5px; cursor: pointer; white-space: nowrap;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.09); border-color: var(--border-strong); }
.primary-btn {
  background: var(--accent); border: none; border-radius: 9px; padding: 7px 18px;
  color: #0b0c16; font-weight: 650; cursor: pointer; font-size: 13px;
  transition: filter 0.14s;
}
.primary-btn:hover { filter: brightness(1.1); }
.danger-btn {
  background: transparent; border: 1px solid rgba(244, 100, 126, 0.35);
  color: var(--red); border-radius: 9px; padding: 7px 14px;
  font-size: 12px; cursor: pointer; transition: background 0.14s;
}
.danger-btn:hover { background: rgba(244, 100, 126, 0.09); }

/* ---------- 登录 / 弹窗 ---------- */
.login-mask {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(3, 3, 5, 0.8); backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
}
.login-mask.hidden { display: none; }
.login-box {
  width: 340px; padding: 34px 32px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 24px 64px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-box .brand-mark { display: flex; justify-content: center; }
.login-title { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
.login-desc { font-size: 12px; color: var(--dim); }
.login-box input {
  background: var(--inset); border: 1px solid var(--border);
  border-radius: 9px; padding: 10px 14px; color: var(--text);
  font-family: var(--mono); font-size: 13px; outline: none; text-align: center;
  transition: border-color 0.14s;
}
.login-box input:focus { border-color: rgba(139, 147, 255, 0.5); }
.login-box button {
  background: var(--accent); border: none; border-radius: 9px; padding: 10px;
  color: #0b0c16; font-weight: 650; cursor: pointer; font-size: 14px;
  transition: filter 0.14s;
}
.login-box button:hover { filter: brightness(1.1); }
.login-error { color: var(--red); font-size: 12px; min-height: 14px; }

.kimi-link {
  color: var(--accent); font-family: var(--mono); font-size: 12px;
  word-break: break-all; text-decoration: none;
}
.kimi-link:hover { text-decoration: underline; }
.kimi-code {
  font-family: var(--mono); font-size: 28px; font-weight: 700;
  letter-spacing: 6px; color: var(--accent);
  padding: 8px 0;
}

/* ---------- 上游配置编辑器 ---------- */
.cfg-box {
  width: 640px; max-width: calc(100vw - 32px); max-height: calc(100vh - 60px);
  padding: 26px 28px; border-radius: 16px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 24px 64px rgba(0, 0, 0, 0.5);
  display: flex; flex-direction: column; gap: 14px;
}
.cfg-title { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.cfg-form { display: flex; flex-direction: column; gap: 12px; }
.cfg-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cfg-row label { font-size: 12px; color: var(--dim); white-space: nowrap; }
.cfg-row .grow, .cfg-key-row .grow { flex: 1; min-width: 160px; }
.cfg-box input, .cfg-box select {
  background: var(--inset); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; color: var(--text);
  font-family: var(--mono); font-size: 12px; outline: none;
  transition: border-color 0.14s;
}
.cfg-box input:focus, .cfg-box select:focus { border-color: rgba(139, 147, 255, 0.5); }
.cfg-box input:disabled { opacity: 0.5; }
.cfg-box input[type="number"] { width: 110px; }
.cfg-box input[type="checkbox"] { width: auto; accent-color: var(--accent); }

.cfg-section {
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 10px;
  background: rgba(255, 255, 255, 0.012);
}
.cfg-check { font-size: 13px; display: flex; align-items: center; gap: 8px; cursor: pointer; white-space: nowrap; }
.cfg-hint { font-weight: 400; color: var(--dimmer); font-size: 11px; margin-left: 8px; }
.cfg-device { font-family: var(--mono); font-size: 11px; color: var(--dimmer); }
.cfg-section-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600;
}
.cfg-key-row {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--inset);
}
.k-line { display: flex; align-items: center; gap: 8px; }
.k-line .k-label { width: 90px; }
.k-aq { color: var(--dim); }
.k-aq .cfg-check { font-size: 12px; }
.k-aq .k-aq-login { margin-left: auto; }
.key-card .account-row { margin-top: 10px; margin-bottom: 0; }

.cfg-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- 滚动条 ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(255, 255, 255, 0.1) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.16); }
::-webkit-scrollbar-corner { background: transparent; }

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .header-in, main { padding-left: 16px; padding-right: 16px; }
}

.nav-link { color: var(--dim); text-decoration: none; font-size: 12.5px; }
.nav-link:hover { color: var(--text); }
