:root {
  --bg: #080b10;
  --bg-soft: #0e141c;
  --card: #121a24;
  --card-2: #16202c;
  --line: #1f2b39;
  --text: #e8eef7;
  --muted: #7f8ea3;
  --accent: #2ee6b0;
  --accent-2: #4c8dff;
  --danger: #ff5d6c;
  --warn: #ffb020;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #12313a 0%, transparent 60%),
              radial-gradient(900px 500px at -10% 10%, #1a2340 0%, transparent 55%),
              var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  min-height: 100vh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; line-height: 1.6; margin: 6px 0 14px; }
.msg { min-height: 18px; font-size: 12px; color: var(--muted); margin: 8px 0 0; word-break: break-all; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--accent); }

/* ---------- 登录 ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: linear-gradient(180deg, rgba(22,32,44,.96), rgba(14,20,28,.96));
  border: 1px solid var(--line); border-radius: 22px; padding: 32px 24px;
  box-shadow: 0 30px 80px rgba(0,0,0,.55);
}
.logo-mark {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #06121a;
  font-weight: 800; font-size: 26px; margin-bottom: 18px;
}
.login-card h1 { font-size: 22px; margin: 0 0 6px; letter-spacing: .5px; }
.login-card p { margin: 0 0 22px; }

/* ---------- 布局 ---------- */
#app { max-width: 1080px; margin: 0 auto; padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 90px); }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font-size: 15px; cursor: pointer;
}
.icon-btn:active { transform: scale(.95); }

.endpoint-bar {
  background: linear-gradient(135deg, rgba(46,230,176,.10), rgba(76,141,255,.10));
  border: 1px solid rgba(46,230,176,.28); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 16px;
}
.endpoint-label { font-size: 11px; color: var(--muted); letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.endpoint-row { display: flex; align-items: center; gap: 10px; }
.endpoint-row code {
  flex: 1; font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; color: var(--accent);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.tabs {
  display: flex; gap: 4px; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 14px; padding: 4px; margin-bottom: 18px; position: sticky; top: 0; z-index: 5;
  backdrop-filter: blur(12px);
}
.tab {
  flex: 1; padding: 9px 0; border: 0; border-radius: 10px; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer;
}
.tab.active { background: var(--card-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.tab-panel { display: none; animation: fade .18s ease; }
.tab-panel.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 12px; }
.section-head h2 { font-size: 15px; margin: 0; font-weight: 650; }
.head-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- 卡片 / 列表 ---------- */
.list { display: grid; gap: 10px; }
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-soft));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title { display: flex; align-items: center; gap: 8px; font-weight: 650; min-width: 0; }
.card-title span.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-pill { font-size: 10px; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.status-pill.on { color: var(--accent); border-color: rgba(46,230,176,.4); background: rgba(46,230,176,.08); }
.status-pill.off { color: var(--danger); border-color: rgba(255,93,108,.35); background: rgba(255,93,108,.08); }
.card-url { font-family: monospace; font-size: 11.5px; color: var(--muted); margin: 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 11px; color: var(--muted); background: var(--card-2); border: 1px solid var(--line); padding: 3px 8px; border-radius: 8px; }
.chip.accent { color: var(--accent); border-color: rgba(46,230,176,.3); }
.card-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- 按钮 ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #35c9a0); color: #04140f; border: 0; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(255,93,108,.35); background: rgba(255,93,108,.07); }
.btn.sm { padding: 8px 12px; font-size: 12.5px; border-radius: 10px; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.mini-btn {
  border: 1px solid var(--line); background: var(--card-2); color: var(--accent);
  font-size: 12px; padding: 6px 10px; border-radius: 9px; cursor: pointer; white-space: nowrap;
}

/* ---------- 表单 ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea, textarea, select {
  width: 100%; background: #0a1018; border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 12px; font-size: 14px; font-family: inherit; outline: none;
}
.field input:focus, textarea:focus, select:focus { border-color: rgba(46,230,176,.55); box-shadow: 0 0 0 3px rgba(46,230,176,.08); }
.field.checkbox { display: flex; align-items: center; gap: 8px; }
.field.checkbox input { width: auto; }
.price-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.price-row .field { margin-bottom: 10px; }
.select-sm { width: auto; padding: 7px 10px; font-size: 12px; border-radius: 9px; }
.model-add { display: flex; gap: 8px; margin-bottom: 10px; }
.model-add input {
  flex: 1; background: #0a1018; border: 1px solid var(--line); color: var(--text);
  border-radius: 11px; padding: 10px 12px; font-size: 13px; font-family: inherit; outline: none;
}
.model-add input:focus { border-color: rgba(46,230,176,.55); }
.compat-row { margin-top: 8px; }
.compat-row code { font-size: 11px; color: var(--muted); }
.compat-tag {
  font-size: 10px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 6px; white-space: nowrap;
}

/* 开关 */
.switch { position: relative; display: inline-block; width: 44px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #26313f; border-radius: 999px; transition: .2s; }
.switch i::after {
  content: ""; position: absolute; width: 19px; height: 19px; border-radius: 50%;
  background: #aab6c6; top: 3px; left: 3px; transition: .2s;
}
.switch input:checked + i { background: rgba(46,230,176,.35); }
.switch input:checked + i::after { transform: translateX(19px); background: var(--accent); }

/* ---------- 模型 ---------- */
.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.model-card {
  border: 1px solid var(--line); background: var(--card); border-radius: 13px; padding: 12px;
  cursor: pointer; transition: border-color .15s ease, transform .08s ease; position: relative; overflow: hidden;
}
.model-card:active { transform: scale(.98); }
.model-card .m-name { font-size: 13px; font-weight: 600; word-break: break-all; line-height: 1.35; }
.model-card .m-sub { font-size: 11px; color: var(--muted); margin-top: 6px; }
.model-card .m-badge { position: absolute; top: 8px; right: 8px; font-size: 10px; color: var(--muted); }
.model-card.ok { border-color: rgba(46,230,176,.55); }
.model-card.ok .m-sub { color: var(--accent); }
.model-card.fail { border-color: rgba(255,93,108,.5); }
.model-card.fail .m-sub { color: var(--danger); }
.model-card.testing { opacity: .65; }

.model-picker { display: flex; flex-wrap: wrap; gap: 7px; max-height: 260px; overflow: auto; padding: 2px; }
.model-chip {
  font-size: 12px; padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); cursor: pointer; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-chip.on { border-color: rgba(46,230,176,.55); color: var(--accent); background: rgba(46,230,176,.09); }
.model-chip.limit { opacity: .35; pointer-events: none; }
.alias-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.alias-row .alias-real {
  flex: 0 0 46%; font-size: 12px; color: var(--muted); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.alias-row input { flex: 1; min-width: 0; }
.up-picks { display: flex; flex-wrap: wrap; gap: 8px; }
.up-pick {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; background: var(--card);
  cursor: pointer; max-width: 100%;
}
.up-pick input { width: auto; margin: 0; }
.picker-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.inject-box {
  border: 1px solid var(--line); border-radius: 13px; padding: 12px; margin: 14px 0;
  background: rgba(76,141,255,.05);
}
.inject-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-weight: 600; font-size: 13px; }
.inject-box textarea { background: #080d14; }

/* ---------- 密钥 ---------- */
.balance-bar { height: 6px; border-radius: 99px; background: #1c2836; margin-top: 10px; overflow: hidden; }
.balance-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.key-token {
  font-family: monospace; font-size: 11.5px; color: var(--muted); background: #080d14;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px; word-break: break-all; margin-top: 9px;
}
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 20px; margin-top: 4px; }
.stat span { font-size: 11px; color: var(--muted); }
.log-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid rgba(31,43,57,.6); font-size: 12px; }
.log-row:last-child { border-bottom: 0; }
.log-row .l-main { min-width: 0; }
.log-row .l-model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-row .l-sub { color: var(--muted); font-size: 11px; margin-top: 3px; }
.log-row .l-cost { color: var(--accent); white-space: nowrap; }

/* ---------- 抽屉 / 弹窗 ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .22s ease; z-index: 40;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(420px, 92vw);
  background: var(--bg-soft); border-left: 1px solid var(--line); z-index: 50;
  transform: translateX(102%); transition: transform .26s cubic-bezier(.3,.8,.3,1);
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { font-size: 16px; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-foot { padding: 14px 16px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line); }

.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(0,0,0,.6); }
.modal-card {
  width: 100%; max-width: 380px; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 18px; padding: 20px; max-height: 86vh; overflow-y: auto;
}
.modal-card h3 { margin: 0 0 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn { flex: 1; }

.fab {
  position: fixed; right: 18px; bottom: calc(22px + var(--safe-bottom)); width: 54px; height: 54px;
  border-radius: 50%; border: 0; font-size: 26px; font-weight: 300; color: #04140f;
  background: linear-gradient(135deg, var(--accent), #35c9a0);
  box-shadow: 0 12px 28px rgba(46,230,176,.28); cursor: pointer; z-index: 30;
}
.fab:active { transform: scale(.94); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translate(-50%, 20px);
  background: #16202c; border: 1px solid var(--line); color: var(--text); padding: 10px 16px;
  border-radius: 12px; font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 70;
  max-width: 86vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; font-size: 13px; line-height: 1.8; }

@media (min-width: 720px) {
  #app { padding-bottom: 60px; }
  #channelList { grid-template-columns: 1fr 1fr; }
  #keyList { grid-template-columns: 1fr 1fr; }
}
