:root {
  --bg: #0b0f19;
  --bg-2: #111827;
  --panel: rgba(23, 30, 47, 0.86);
  --panel-2: #1a2233;
  --border: rgba(120, 140, 190, 0.16);
  --border-strong: rgba(120, 140, 190, 0.32);
  --text: #e8edf7;
  --text-dim: #93a1bd;
  --text-mute: #6b7a99;
  --primary: #6d5efc;
  --primary-2: #22d3ee;
  --success: #29d17f;
  --warn: #f5a524;
  --danger: #ff5f6d;
  --radius: 14px;
  --shadow: 0 18px 48px rgba(3, 8, 20, 0.55);
  font-synthesis: none;
}

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

body {
  min-height: 100vh;
  background:
    radial-gradient(900px 520px at 12% -8%, rgba(109, 94, 252, 0.22), transparent 62%),
    radial-gradient(760px 460px at 92% 4%, rgba(34, 211, 238, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-2); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: 14px; }

/* ---------------------------------------------------------------- 通用控件 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border: 1px solid var(--border-strong); border-radius: 10px;
  background: rgba(255, 255, 255, 0.03); color: var(--text);
  cursor: pointer; transition: all .16s ease; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); background: rgba(109, 94, 252, 0.14); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  border-color: transparent;
  background: linear-gradient(120deg, var(--primary), #8b7bff 55%, var(--primary-2));
  color: #fff; font-weight: 600;
  box-shadow: 0 10px 26px rgba(109, 94, 252, 0.34);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { border-color: rgba(255, 95, 109, .4); color: #ffb3b9; }
.btn-danger:hover { background: rgba(255, 95, 109, .14); border-color: var(--danger); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,.05); }

.input, .select, .textarea {
  width: 100%; padding: 10px 13px; border-radius: 10px;
  border: 1px solid var(--border); background: rgba(9, 13, 24, 0.75);
  color: var(--text); outline: none; transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.18);
}
.input::placeholder, .textarea::placeholder { color: var(--text-mute); }
.textarea { resize: vertical; min-height: 96px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.select { appearance: none; background-image: none; cursor: pointer; }
.select option { background: #151c2c; color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; color: var(--text-dim); font-weight: 500; }
.hint { font-size: 12px; color: var(--text-mute); line-height: 1.5; }

.tag {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid transparent; white-space: nowrap;
}
.tag-unused { background: rgba(34, 211, 238, .14); color: #7fe6f5; border-color: rgba(34,211,238,.3); }
.tag-used { background: rgba(41, 209, 127, .14); color: #6ce9ad; border-color: rgba(41,209,127,.3); }
.tag-redeeming { background: rgba(245, 165, 36, .16); color: #ffca72; border-color: rgba(245,165,36,.32); }
.tag-disabled { background: rgba(148, 163, 184, .14); color: #a9b6cd; border-color: rgba(148,163,184,.3); }
.tag-failed { background: rgba(255, 95, 109, .15); color: #ff9aa3; border-color: rgba(255,95,109,.32); }
.tag-success { background: rgba(41, 209, 127, .14); color: #6ce9ad; border-color: rgba(41,209,127,.3); }
.tag-pending { background: rgba(245, 165, 36, .16); color: #ffca72; border-color: rgba(245,165,36,.32); }

.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }

/* ---------------------------------------------------------------- 兑换页 */
.redeem-wrap { max-width: 760px; margin: 0 auto; padding: 52px 20px 72px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 26px rgba(109, 94, 252, .4); font-size: 22px;
}
.brand h1 { font-size: 21px; font-weight: 700; letter-spacing: .3px; }
.brand p { font-size: 12.5px; color: var(--text-mute); }

.card-box {
  margin-top: 26px; padding: 26px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--border);
  box-shadow: var(--shadow); backdrop-filter: blur(14px);
}
.notice {
  display: flex; gap: 10px; padding: 12px 14px; border-radius: 12px; margin-bottom: 20px;
  background: rgba(109, 94, 252, .1); border: 1px solid rgba(109, 94, 252, .25);
  color: #c9c3ff; font-size: 13px;
}
.redeem-input {
  width: 100%; padding: 15px 16px; border-radius: 12px; text-align: center;
  border: 1px solid var(--border-strong); background: rgba(9, 13, 24, .8);
  color: var(--text); font-size: 17px; letter-spacing: 2.5px; font-weight: 600;
  outline: none; text-transform: uppercase;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.redeem-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(109,94,252,.16); }
.btn-block { width: 100%; padding: 13px; font-size: 15px; margin-top: 14px; border-radius: 12px; }

.result {
  margin-top: 22px; padding: 20px; border-radius: 16px; display: none;
  border: 1px solid var(--border-strong); background: rgba(9, 13, 24, .6);
}
.result.show { display: block; animation: fade .28s ease; }
.result.ok { border-color: rgba(41, 209, 127, .4); background: rgba(41, 209, 127, .07); }
.result.err { border-color: rgba(255, 95, 109, .4); background: rgba(255, 95, 109, .07); }
.result.warn { border-color: rgba(245, 165, 36, .4); background: rgba(245, 165, 36, .07); }
.result-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.secret-box {
  margin-top: 12px; padding: 15px; border-radius: 12px; word-break: break-all;
  background: rgba(0, 0, 0, .38); border: 1px dashed var(--border-strong);
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.75;
  white-space: pre-wrap; color: #b8f5d8;
}
.result-meta { margin-top: 10px; font-size: 12.5px; color: var(--text-mute); }
.copy-row { display: flex; gap: 10px; margin-top: 12px; }

/* 一条龙兑换流程面板（填 Session / 确认账号 / 进度） */
.flow-slot {
  margin-top: 18px; padding: 18px; border-radius: 16px; display: none;
  border: 1px solid rgba(109, 94, 252, .38); background: rgba(109, 94, 252, .06);
  animation: fade .28s ease;
}
.flow-title { font-size: 15px; font-weight: 700; margin-bottom: 10px; }
.flow-title.ok { color: #4ee2a3; }
.flow-label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--text-dim); }
.flow-textarea {
  width: 100%; min-height: 132px; padding: 12px 14px; border-radius: 12px; resize: vertical;
  border: 1px solid var(--border-strong); background: rgba(9, 13, 24, .8);
  color: var(--text); font-size: 13px; line-height: 1.6; outline: none;
  font-family: ui-monospace, Menlo, Consolas, monospace; box-sizing: border-box;
}
.flow-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(109,94,252,.16); }
.flow-link { display: inline-block; margin-top: 10px; font-size: 12.5px; color: #9d92ff; text-decoration: none; }
.flow-link:hover { text-decoration: underline; }
.flow-email {
  margin: 4px 0 14px; font-size: 15px; font-weight: 600; color: #b8f5d8;
  word-break: break-all;
}
.flow-facts { margin: 0 0 4px; padding: 0; font-size: 13px; }
.flow-facts > div {
  display: flex; justify-content: space-between; gap: 12px; padding: 9px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, .07);
}
.flow-facts > div:last-child { border-bottom: none; }
.flow-facts dt { color: var(--text-mute); flex-shrink: 0; }
.flow-facts dd { margin: 0; text-align: right; word-break: break-all; }
.flow-block {
  margin-top: 14px; padding: 11px 13px; border-radius: 10px; font-size: 13px;
  background: rgba(255, 95, 109, .1); border: 1px solid rgba(255, 95, 109, .32); color: #ffb3ba;
}
.flow-actions { display: flex; gap: 10px; margin-top: 16px; }
.flow-actions .btn { flex: 1; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.foot { margin-top: 26px; text-align: center; font-size: 12px; color: var(--text-mute); }
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  padding: 11px 20px; border-radius: 12px; background: rgba(20, 26, 42, .96);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all .24s ease;
  /* 必须高于 .login-mask(400) 和 .modal-mask(200)，否则登录页/弹窗里弹出的提示
     会被整屏遮罩盖住，看起来就是「点了没反应」 */
  z-index: 900;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- 后台 */
.admin-shell { display: none; min-height: 100vh; }
.admin-shell.active { display: flex; }
.side {
  width: 218px; flex-shrink: 0; padding: 20px 14px; border-right: 1px solid var(--border);
  background: rgba(10, 14, 25, .72); backdrop-filter: blur(12px);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.side-brand .brand-logo { width: 34px; height: 34px; font-size: 17px; border-radius: 10px; }
.side-brand span { font-size: 15px; font-weight: 700; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text-dim); cursor: pointer; margin-bottom: 3px; font-size: 13.5px;
  transition: all .15s ease; user-select: none;
}
.nav-item:hover { background: rgba(255, 255, 255, .045); color: var(--text); }
.nav-item.active {
  background: linear-gradient(100deg, rgba(109, 94, 252, .28), rgba(34, 211, 238, .12));
  color: #fff; font-weight: 600;
}
.side-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }

.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h2 { font-size: 19px; font-weight: 700; }
.page-head .sub { font-size: 12.5px; color: var(--text-mute); margin-top: 2px; }

.panel { padding: 20px; border-radius: var(--radius); background: var(--panel);
  border: 1px solid var(--border); box-shadow: var(--shadow); margin-bottom: 18px; }
.panel-title { font-size: 14.5px; font-weight: 700; margin-bottom: 16px; display: flex;
  align-items: center; justify-content: space-between; gap: 10px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; border-radius: var(--radius); background: var(--panel);
  border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat .k { font-size: 12.5px; color: var(--text-dim); }
.stat .v { font-size: 25px; font-weight: 700; margin-top: 5px; letter-spacing: -.5px; }
.stat .v small { font-size: 12px; color: var(--text-mute); font-weight: 500; margin-left: 5px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 16px; }

.table-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 11px 13px; background: rgba(255, 255, 255, .035);
  color: var(--text-dim); font-weight: 600; font-size: 12.5px; white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 10px 13px; border-bottom: 1px solid rgba(120, 140, 190, .08); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, .022); }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.empty { padding: 44px 20px; text-align: center; color: var(--text-mute); font-size: 13px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.pager-info { font-size: 12.5px; color: var(--text-mute); }

.toolbar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; min-width: 130px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(4, 7, 15, .74); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-mask.show { display: flex; }
.modal {
  width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; padding: 24px;
  border-radius: 18px; background: #141b2b; border: 1px solid var(--border-strong);
  box-shadow: 0 30px 70px rgba(0, 0, 0, .6); animation: fade .22s ease;
}
.modal.wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border); }
.close-x { background: none; border: none; color: var(--text-mute); font-size: 20px; cursor: pointer; line-height: 1; }
.close-x:hover { color: var(--text); }

.login-mask {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 400;
  background: radial-gradient(700px 420px at 50% 0%, rgba(109, 94, 252, .2), transparent 65%), var(--bg);
}
.login-box { width: min(384px, 92vw); padding: 30px; border-radius: 20px; background: var(--panel);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow); }
.login-box h2 { font-size: 18px; margin-bottom: 4px; }
.login-box .sub { font-size: 12.5px; color: var(--text-mute); margin-bottom: 22px; }

/* Cloudflare Turnstile 控件：固定高度避免验证通过后登录按钮跳动 */
.turnstile-box { display: flex; justify-content: center; align-items: center; min-height: 65px; }
.hint-danger { color: var(--danger); margin-top: 8px; line-height: 1.6; }

/* 登录失败提示：贴在登录框内部，避免被整屏遮罩挡住 */
.login-error {
  margin: 2px 0 14px; padding: 9px 12px; border-radius: 10px; font-size: 13px;
  color: var(--danger); background: rgba(255, 88, 88, .1);
  border: 1px solid rgba(255, 88, 88, .35); line-height: 1.5;
  word-break: break-word; animation: shake .3s ease;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.code-pill {
  display: inline-block; padding: 3px 9px; border-radius: 7px; background: rgba(0, 0, 0, .35);
  border: 1px solid var(--border); font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
}
/* 兑换记录「发货内容」：完整展示，超长自动换行 + 限高可滚动，点击复制 */
.code-content {
  max-width: 340px; max-height: 110px; overflow: auto;
  white-space: pre-wrap; word-break: break-all;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.55;
  padding: 6px 9px; border-radius: 8px; cursor: copy;
  background: rgba(0, 0, 0, .35); border: 1px solid var(--border);
}
.code-content:hover { border-color: var(--border-strong); }
/* 兑换记录「兑换核验」：上游 CDK + 核验状态 + 核验按钮 */
.verify-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.verify-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.batch-list { max-height: 260px; overflow-y: auto; padding: 14px; border-radius: 12px;
  background: rgba(0, 0, 0, .3); border: 1px solid var(--border); margin-top: 14px;
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.9;
  white-space: pre-wrap; word-break: break-all; }
.upstream-picker { max-height: 380px; overflow-y: auto; border-radius: 12px; border: 1px solid var(--border); }
.picker-row { display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-bottom: 1px solid rgba(120, 140, 190, .08); cursor: pointer; user-select: none; }
.picker-row:hover { background: rgba(109, 94, 252, .1); }
.picker-row:has(input:disabled) { cursor: not-allowed; opacity: .55; }
.picker-row:has(input:disabled):hover { background: transparent; }
.picker-row .p-name { font-weight: 600; font-size: 13.5px; }
.picker-row .p-meta { font-size: 12px; color: var(--text-mute); margin-top: 2px; }

input[type="checkbox"] {
  width: 15px; height: 15px; flex-shrink: 0; margin: 0;
  accent-color: var(--primary); cursor: pointer;
}
input[type="checkbox"]:disabled { cursor: not-allowed; opacity: .5; }

.pick-all-row {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; margin-bottom: 10px;
  border-radius: 10px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, .025);
  cursor: pointer; user-select: none; font-size: 13px; color: var(--text-dim);
}
.pick-all-row:hover { border-color: var(--border-strong); color: var(--text); }
.pick-all-row .hint { margin-left: auto; }

.pick-toggle {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 12.5px; color: var(--text-mute); cursor: pointer; user-select: none;
}
.pick-toggle:hover { color: var(--text); }
.pick-toggle input { accent-color: var(--primary); cursor: pointer; }

/* 卡密选中操作条 */
.sel-bar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  margin-bottom: 12px; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 11px; background: rgba(255, 255, 255, .02);
}

@media (max-width: 760px) {
  .admin-shell.active { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; display: flex; gap: 6px; overflow-x: auto; padding: 12px; }
  .side-brand { display: none; }
  .side-foot { display: none; }
  .nav-item { margin-bottom: 0; white-space: nowrap; }
  .main { padding: 18px 14px 50px; }
}
