:root {
  --primary: #1677ff;
  --primary-hover: #0958d9;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --side: #0f172a;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; }
a { color: var(--primary); }
code { background: #eef2f7; padding: 1px 5px; border-radius: 5px; font-size: 12px; }

/* ---------- 登录 / 注册 ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-box {
  background: #fff; border-radius: 16px; padding: 30px; width: 100%; max-width: 400px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.1);
}
.auth-box h1 { font-size: 20px; margin-bottom: 4px; }
.auth-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.auth-tabs { display: flex; gap: 4px; background: #f1f5f9; border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.auth-tabs button {
  flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font-weight: 600;
  color: var(--muted); cursor: pointer; font-size: 13px;
}
.auth-tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.auth-links { margin-top: 10px; font-size: 13px; text-align: right; }
.fixed-table td, .fixed-table th { padding: 6px 8px; }
.recovery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.detail-table th { width: 110px; }
.form-err { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---------- 主布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex-shrink: 0; background: var(--side); color: #cbd5e1; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; color: #fff; font-weight: 700; font-size: 15px; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
}
.nav-group { padding: 10px 16px 4px; font-size: 11px; color: #64748b; letter-spacing: .5px; }
.nav-item {
  display: flex; justify-content: space-between; align-items: center; width: calc(100% - 16px); margin: 1px 8px;
  padding: 9px 12px; border: 0; border-radius: 8px; background: transparent; color: #cbd5e1; font-size: 13.5px;
  text-align: left; cursor: pointer; font-family: inherit;
}
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-dot { background: var(--amber); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.side-foot { margin-top: auto; padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side-user { color: #fff; font-weight: 600; font-size: 13px; word-break: break-all; }
.side-plan { color: #94a3b8; margin: 2px 0 10px; }

.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h2 { font-size: 20px; }
.page-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 6px; }
  .brand { padding: 8px 10px; }
  .nav-group { display: none; }
  #adminNav { display: contents; }
  .nav-item { width: auto; margin: 2px; padding: 7px 10px; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 6px 10px; display: flex; gap: 10px; align-items: center; }
  .side-plan { display: none; }
  .main { padding: 16px 12px 50px; }
}

/* ---------- 通用组件 ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px; margin-bottom: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 10px; }
.card-header h3 { font-size: 15px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.6; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.stat-card { background: var(--card); border-radius: 14px; padding: 16px; border: 1px solid var(--border); }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 800; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

.quota-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.quota-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.quota-top b { font-weight: 700; }
.bar { height: 8px; border-radius: 999px; background: #e9eef5; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); border-radius: 999px; }
.bar.warn > i { background: var(--amber); }
.bar.full > i { background: var(--red); }

.btn {
  border: 1px solid transparent; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 9px;
  font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; font-family: inherit; white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: #f8fafc; color: #334155; border-color: #cbd5e1; }
.btn.secondary:hover { background: #e2e8f0; }
.btn.green { background: var(--green); }
.btn.amber { background: var(--amber); }
.btn.red { background: var(--red); }
.btn.ghost { background: transparent; color: #cbd5e1; border-color: rgba(255,255,255,.2); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; margin-top: 16px; }
.btn-row { display: flex; gap: 5px; flex-wrap: wrap; }

input, select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #cbd5e1; border-radius: 9px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(22,119,255,.25); border-color: var(--primary); }
input[type="checkbox"] { width: 17px; height: 17px; }
textarea { min-height: 82px; resize: vertical; }
label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin: 12px 0 6px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; margin: 0; cursor: pointer; }
.w-auto { width: auto; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
@media (max-width: 680px) { .row, .row3 { grid-template-columns: 1fr; } }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.break { word-break: break-all; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 13px; color: var(--muted); flex-wrap: wrap; gap: 8px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge.green { background: #dcfce7; color: #166534; }
.badge.red { background: #fee2e2; color: #991b1b; }
.badge.amber { background: #fef3c7; color: #92400e; }
.badge.gray { background: #e2e8f0; color: #475569; }
.badge.blue { background: #dbeafe; color: #1d4ed8; }

.callout {
  background: #f8fafc; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; color: #334155; line-height: 1.65; margin: 12px 0;
}
.callout.warn { border-left-color: var(--amber); background: #fffbeb; }
.setup-choice .choice-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; align-items: flex-start; }
.setup-choice .choice { flex: 1; min-width: 220px; }
.setup-choice .choice .btn { margin-bottom: 6px; }
.setup-choice .qr-choice { display: flex; gap: 12px; flex: 2; min-width: 300px; }
.setup-choice .qr-choice img { width: 128px; height: 128px; border: 1px solid var(--border); border-radius: 10px; background: #fff; flex-shrink: 0; }
.tutorial-layer { position: fixed; inset: 0; z-index: 60; background: rgba(15, 23, 42, 0.25); display: flex; justify-content: flex-end; }
.tutorial-box { width: min(460px, 100%); height: 100%; background: #f1f5f9; display: flex; flex-direction: column; box-shadow: -12px 0 32px rgba(15, 23, 42, 0.25); animation: tutorial-in .18s ease-out; }
.tutorial-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: #fff; border-bottom: 1px solid var(--border); }
.tutorial-head .spacer { flex: 1; }
.tutorial-box iframe { flex: 1; width: 100%; border: 0; background: #f1f5f9; }
@keyframes tutorial-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.callout.danger { border-left-color: var(--red); background: #fef2f2; color: #7f1d1d; }
.callout .btn-row { margin-top: 8px; }
.health-note { font-size: 12px; margin-top: 3px; max-width: 260px; line-height: 1.5; }
.health-note.bad { color: #b91c1c; }
.health-note.warn { color: #b45309; }
.code-box {
  background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 10px; font-size: 12px; line-height: 1.7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}
.secret { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.plan-card { border: 1.5px solid var(--border); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; }
.plan-card.current { border-color: var(--primary); background: #f5f9ff; }
.plan-name { font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.plan-price { font-size: 22px; font-weight: 800; margin: 8px 0 2px; }
.plan-price small { font-size: 12px; font-weight: 500; color: var(--muted); }
.plan-card ul { margin: 10px 0 14px; padding-left: 18px; color: #334155; font-size: 13px; line-height: 1.8; flex: 1; }

.choice-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.choice-card { border: 1.5px solid var(--border); border-radius: 11px; padding: 12px 14px; cursor: pointer; background: #fff; }
.choice-card.selected { border-color: var(--primary); background: #eff6ff; }
.choice-title { font-weight: 700; font-size: 13.5px; }
.choice-desc { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- 弹窗与提示 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); display: none; align-items: center;
  justify-content: center; z-index: 50; padding: 16px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  padding: 22px; box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { font-size: 17px; }
.close-x { border: 0; background: transparent; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.qr-preview { max-width: 220px; border: 1px solid var(--border); border-radius: 12px; padding: 8px; background: #fff; display: block; margin: 10px auto; }
.qr-box { text-align: center; background: #f8fafc; border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.steps { margin: 8px 0 4px; padding-left: 20px; line-height: 1.75; font-size: 13px; color: #334155; }
.steps li { margin-bottom: 8px; }
.steps .secret { margin-top: 4px; }
.url-box { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; background: #f1f5f9; border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; word-break: break-all; flex: 1; min-width: 0; }
details.more { margin-top: 8px; font-size: 13px; color: #334155; }
details.more summary { cursor: pointer; color: var(--primary); font-weight: 600; }
details.more > div { margin-top: 6px; line-height: 1.7; }
.try-result { margin-top: 6px; font-size: 13px; min-height: 20px; }
.event-list { max-height: 190px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 4px 10px; font-size: 12px; }
.event-list > div { padding: 6px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 8px; }
.event-list > div:last-child { border-bottom: 0; }
.event-list time { color: var(--muted); white-space: nowrap; }
.log-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 12px; }

/* ---------- 按钮旁的确认 / 输入气泡 ---------- */
.pop-layer { position: fixed; inset: 0; z-index: 120; }
.pop-layer.center { background: rgba(15, 23, 42, 0.35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.pop {
  position: fixed; width: min(340px, calc(100vw - 24px)); background: #fff; border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; box-shadow: 0 14px 40px rgba(15, 23, 42, 0.22); font-size: 13px;
}
.pop-layer.center .pop { position: static; }
.pop::before {
  content: ''; position: absolute; left: var(--arrow-x, 50%); width: 10px; height: 10px; background: #fff;
  border: 1px solid var(--border); transform: translateX(-50%) rotate(45deg);
}
.pop.below::before { top: -6px; border-right: 0; border-bottom: 0; }
.pop.above::before { bottom: -6px; border-left: 0; border-top: 0; }
.pop-layer.center .pop::before { display: none; }
.pop-msg { line-height: 1.6; color: #1e293b; white-space: pre-line; word-break: break-word; }
.pop input { margin-top: 10px; }
.pop-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.toasts { position: fixed; bottom: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: #0f172a; color: #fff; padding: 11px 14px; border-radius: 10px; font-size: 13px; line-height: 1.5;
  box-shadow: 0 10px 28px rgba(15,23,42,.25); word-break: break-word;
}
.toast.ok { background: #166534; }
.toast.err { background: #b91c1c; }
.preview-frame { width: 100%; height: 320px; border: 1px solid #cbd5e1; border-radius: 10px; background: #f1f5f9; }

.preview-frame.tall { height: 560px; }
