:root {
  --bg: #f5f6fb;
  --card: #ffffff;
  --text: #1b1e2b;
  --muted: #767d92;
  --line: #e9ebf3;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0ff;
  --ok: #0f9d58;
  --ok-soft: #e8f8ef;
  --warn: #d97706;
  --danger: #e11d48;
  --radius: 18px;
  --shadow: 0 12px 32px -16px rgba(24, 28, 48, 0.28);
}

* { box-sizing: border-box; }

/* .btn 等用了 display:inline-flex，会盖掉 [hidden] 的默认 display:none */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.6;
}

/* 背景柔光 */
body::before,
body::after {
  content: "";
  position: fixed;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.5;
  pointer-events: none;
  z-index: 0;
}
body::before { top: -220px; left: -160px; background: #c7d2fe; }
body::after { bottom: -260px; right: -180px; background: #ddd6fe; }

a { color: var(--primary); }

/* ---------------- 顶部栏 ---------------- */
.topbar {
  position: relative;
  z-index: 2;
  max-width: 1040px;
  margin: 0 auto;
  padding: 26px 24px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
}

.brand .logo {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2, #7c3aed));
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 800;
  box-shadow: 0 6px 14px -6px rgba(79, 70, 229, 0.9);
}

.brand small {
  display: block;
  font-weight: 500;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.4px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--muted);
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
}

/* ---------------- 布局 ---------------- */
main {
  position: relative;
  z-index: 1;
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 24px 72px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card h3 {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 650;
}

.card .sub {
  margin: 0 0 18px;
  font-size: 12.5px;
  color: var(--muted);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
}

.mt-20 { margin-top: 20px; }

/* ---------------- 登录 / 注册 ---------------- */
.auth-shell {
  max-width: 430px;
  margin: 6vh auto 0;
}

.auth-card { padding: 30px 28px 26px; }

.tabs {
  display: flex;
  gap: 6px;
  background: #f2f3f9;
  padding: 5px;
  border-radius: 12px;
  margin-bottom: 24px;
}

.tab {
  flex: 1;
  border: 0;
  background: transparent;
  padding: 9px 0;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s ease;
}

.tab.active {
  background: #fff;
  color: var(--text);
  box-shadow: 0 2px 8px rgba(24, 28, 48, 0.09);
}

.field { margin-bottom: 15px; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: #4a5065;
  margin-bottom: 7px;
}

input[type="text"],
input[type="tel"],
input[type="password"] {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fbfbfe;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

input::placeholder { color: #a8aebe; }

input:focus {
  outline: none;
  border-color: #b9b8f7;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 20px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.18s, background 0.18s, opacity 0.18s;
}

.btn:hover { background: #fafafd; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #6d5ce8);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 10px 22px -12px rgba(79, 70, 229, 1);
}

.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), #5b4bd6); }

.btn-block { width: 100%; }

.btn-ghost {
  height: 32px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover { color: var(--danger); background: #fff1f4; }

.hint {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.7;
}

.hint.error { color: var(--danger); }

.form-msg {
  margin: 14px 0 0;
  font-size: 12.5px;
  padding: 9px 12px;
  border-radius: 10px;
  display: none;
}

.form-msg.show { display: block; }
.form-msg.error { background: #fff1f4; color: var(--danger); }
.form-msg.success { background: var(--ok-soft); color: var(--ok); }

/* ---------------- 会员卡 ---------------- */
.member-card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 26px;
  color: #fff;
  background: linear-gradient(135deg, #2b2f45, #3d3f5c);
  box-shadow: 0 18px 38px -22px rgba(28, 31, 55, 0.9);
  min-height: 186px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: background 0.4s ease;
}

.member-card.active {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #a855f7 100%);
  box-shadow: 0 20px 42px -20px rgba(99, 74, 226, 0.85);
}

.member-card::after {
  content: "";
  position: absolute;
  right: -70px;
  top: -90px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.09);
}

.member-card::before {
  content: "";
  position: absolute;
  right: 40px;
  bottom: -110px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
}

.mc-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.8;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: none;
  background: rgba(255, 255, 255, 0.16);
  backdrop-filter: blur(4px);
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c9cbe0;
}

.pill.on { background: rgba(255, 255, 255, 0.22); }
.pill.on::before { background: #7dfab2; box-shadow: 0 0 8px #7dfab2; }

.mc-main {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
}

.mc-days { display: flex; align-items: baseline; gap: 8px; }

.mc-days b {
  font-size: 44px;
  line-height: 1;
  font-weight: 750;
  letter-spacing: -1px;
}

.mc-days span { font-size: 13px; opacity: 0.75; }

.mc-info {
  text-align: right;
  font-size: 12px;
  line-height: 1.9;
  opacity: 0.9;
}

.mc-info span { opacity: 0.68; margin-right: 8px; }
.mc-info b { font-weight: 600; }

/* ---------------- 状态小格 ---------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 14px;
}

.stat {
  background: #f8f9fd;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 14px;
}

.stat span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 3px;
}

.stat b { font-size: 17px; font-weight: 700; }

/* ---------------- 兑换 ---------------- */
.redeem-row { display: flex; gap: 10px; }
.redeem-row input { flex: 1; height: 46px; letter-spacing: 1px; text-transform: uppercase; }
.redeem-row .btn { height: 46px; white-space: nowrap; }

.redeem-result {
  margin-top: 14px;
  padding: 13px 15px;
  border-radius: 12px;
  background: var(--ok-soft);
  color: #0b7a45;
  font-size: 13px;
  display: none;
  animation: pop 0.25s ease;
}

.redeem-result.show { display: block; }

@keyframes pop {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: none; }
}

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; margin: 0 -6px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 560px;
}

th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 12px 10px;
  border-bottom: 1px solid #f2f3f9;
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfbfe; }

.tag {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: #f1f2f8;
  color: var(--muted);
}

.tag.ok { background: var(--ok-soft); color: #0b7a45; }
.tag.warn { background: #fff5e6; color: var(--warn); }
.tag.primary { background: var(--primary-soft); color: var(--primary); }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; letter-spacing: 0.4px; }

.empty {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 34px 0;
}

.code-like {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #f4f5fb;
  border: 1px dashed #d8daea;
  border-radius: 8px;
  padding: 3px 8px;
}

/* ---------------- 后台：小按钮 / 密码 / 兑换码 ---------------- */
.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
  border-radius: 9px;
}

.btn-plain { background: #f7f8fd; color: var(--muted); }
.btn-plain:hover { background: #eef0f8; color: var(--text); }

.btn-mini {
  height: 26px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--primary);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-mini:hover { background: var(--primary-soft); border-color: #d5d3fb; }

.card h3 .tag { margin-left: 8px; vertical-align: 2px; font-weight: 600; }

/* 密码列：默认固定 8 个星号，点「显示」才换成明文 */
.pwd {
  display: inline-block;
  min-width: 76px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 2px;
  color: var(--muted);
  font-size: 13px;
}

.pwd.shown { letter-spacing: 0.4px; color: var(--text); }
.pwd-cell .btn-mini { margin-left: 6px; }

.code-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.code-toolbar .grow { flex: 1; }

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.check input,
.code-check {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
}

.col-check { width: 32px; }
.tbl-codes { min-width: 460px; }

td.row-actions .btn-mini + .btn-mini { margin-left: 6px; }

/* ---------------- Toast ---------------- */
#toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 20px);
  background: rgba(27, 30, 43, 0.94);
  color: #fff;
  font-size: 13px;
  padding: 11px 18px;
  border-radius: 11px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  z-index: 99;
  max-width: 86vw;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #b3173c; }
#toast.ok { background: #0b7a45; }

/* ---------------- 后台页 ---------------- */
.admin-shell { max-width: 1080px; margin: 0 auto; padding: 0 24px 72px; position: relative; z-index: 1; }

.admin-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.key-row { display: flex; gap: 10px; align-items: center; }
.key-row input { width: 220px; height: 40px; }

/* 后台两个标签：用户管理 / 兑换码管理 */
.admin-tabs {
  display: inline-flex;
  gap: 5px;
  background: #f2f3f9;
  padding: 5px;
  border-radius: 13px;
  margin-bottom: 20px;
}

.admin-tabs .tab {
  flex: none;
  padding: 8px 22px;
  font-size: 13px;
}

.admin-panel { animation: panelIn 0.18s ease; }

/* 用户列表：按会员状态筛选 */
.seg {
  display: inline-flex;
  gap: 4px;
  background: #f2f3f9;
  padding: 4px;
  border-radius: 11px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 6px 13px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}

.seg-btn:hover { color: var(--text); }

.seg-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 2px 8px rgba(24, 28, 48, 0.09);
}

.seg-num {
  font-style: normal;
  font-size: 11px;
  font-weight: 700;
  min-width: 19px;
  padding: 1px 5px;
  border-radius: 20px;
  background: rgba(24, 28, 48, 0.06);
  color: var(--muted);
  text-align: center;
}

.seg-btn.active .seg-num { background: var(--primary-soft); color: var(--primary); }

/* 用户搜索框 */
.search-input {
  height: 34px;
  width: 172px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.search-input::placeholder { color: #a8aebf; }

.search-input:focus {
  border-color: #c7c9f2;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* 修改密码弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(24, 28, 48, 0.42);
  animation: fadeIn 0.16s ease;
}

.modal-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border-radius: 16px;
  padding: 22px 22px 18px;
  box-shadow: 0 24px 60px -18px rgba(24, 28, 48, 0.4);
  animation: modalIn 0.18s ease;
}

.modal-card h3 { margin: 0 0 4px; font-size: 16px; }
.modal-card .sub { margin: 0 0 16px; color: var(--muted); font-size: 12.5px; }

.pwd-row { display: flex; gap: 8px; }
.pwd-row input { flex: 1; min-width: 0; height: 40px; }
.pwd-row .btn { white-space: nowrap; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes panelIn {
  from { opacity: 0; transform: translateY(-3px); }
  to { opacity: 1; transform: none; }
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.summary .card { padding: 18px 20px; }
.summary .card span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.summary .card b { font-size: 24px; font-weight: 750; letter-spacing: -0.5px; }

.code-output {
  margin-top: 14px;
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  background: #fafaff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.code-output.show { display: grid; }
.code-output code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 9px;
  text-align: center;
  letter-spacing: 0.6px;
}

@media (max-width: 820px) {
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 12px 16px 60px; }
  .topbar { padding: 18px 16px 4px; }
  .auth-shell { margin-top: 3vh; }
  .mc-main { flex-direction: column; align-items: flex-start; gap: 12px; }
  .mc-info { text-align: left; }
  .stats { grid-template-columns: 1fr 1fr; }
  .admin-shell { padding: 0 16px 60px; }
  .admin-tabs { display: flex; width: 100%; }
  .admin-tabs .tab { flex: 1; padding: 8px 0; }
  .seg { display: flex; width: 100%; }
  .seg-btn { flex: 1; justify-content: center; padding: 6px 4px; }
  .search-input { width: 100%; }
}
