:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --sub: #6e6e73;
  --muted: #86868b;
  --line: rgba(0, 0, 0, .08);
  --field: #f2f2f4;
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, .1);
  --ok: #1f9d55;
  --ok-bg: rgba(48, 209, 88, .14);
  --bad: #e02424;
  --bad-bg: rgba(255, 59, 48, .13);
  --warn: #b25000;
  --warn-bg: rgba(255, 149, 0, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 12px 32px rgba(0, 0, 0, .06);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --sub: #a1a1a6;
    --muted: #86868b;
    --line: rgba(255, 255, 255, .1);
    --field: #2c2c2e;
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, .16);
    --ok: #30d158;
    --ok-bg: rgba(48, 209, 88, .15);
    --bad: #ff453a;
    --bad-bg: rgba(255, 69, 58, .15);
    --warn: #ff9f0a;
    --warn-bg: rgba(255, 159, 10, .15);
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
        "Helvetica Neue", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
button, a, .switch, .chip { touch-action: manipulation; }
button { -webkit-user-select: none; user-select: none; }
[hidden] { display: none !important; }

/* 顶栏 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; min-width: 0; }
.brand svg { width: 19px; height: 19px; fill: var(--text); flex: none; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--sub); flex: none; }
.recharge-tip {
  flex: 1; min-width: 0; text-align: center;
  font-size: 12px; color: var(--sub);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.balance { background: var(--accent-soft); color: var(--accent); padding: 5px 11px; border-radius: 100px; font-weight: 600; white-space: nowrap; }
.balance b { font-size: 14px; font-variant-numeric: tabular-nums; }
.uname { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkbtn {
  border: 0; background: none; color: var(--accent); font-size: 13px; cursor: pointer;
  padding: 9px 5px; min-height: 38px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.linkbtn.muted { color: var(--muted); }
.linkbtn:active { opacity: .55; }

/* 布局 */
.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 20px 16px 64px; }
.seg {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 18px;
  background: var(--field); border-radius: 12px;
}
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--sub);
  padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 500; cursor: pointer;
}
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.fl { display: block; font-size: 13px; font-weight: 600; color: var(--sub); margin: 0 0 7px 2px; }
.fl:not(:first-child) { margin-top: 18px; }
select, input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; height: 48px; padding: 0 14px;
  border: 1px solid transparent; border-radius: 12px;
  background: var(--field); color: var(--text);
  font-size: 16px; outline: none;
  transition: border-color .15s, background .15s;
}
textarea { height: auto; padding: 12px 14px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8'><path d='M1 1l5 5 5-5' stroke='%2386868b' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>"); background-repeat: no-repeat; background-position: right 15px center; padding-right: 38px; }
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.svc-desc { margin: 8px 2px 0; font-size: 13px; color: var(--muted); min-height: 18px; }
.row { display: flex; gap: 10px; }
.row > input { flex: 1; min-width: 0; }
button.primary {
  height: 48px; padding: 0 22px; border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  cursor: pointer; flex: none; transition: opacity .15s, transform .1s;
}
button.primary:active:not(:disabled) { transform: scale(.98); }
button.primary:disabled { opacity: .55; cursor: default; }
button.ghost {
  height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--text); font-size: 14px; cursor: pointer;
}
button.ghost:active { background: var(--field); }
button.ghost:hover { background: var(--field); }
button.danger { color: var(--bad); border-color: var(--bad-bg); }
button.btn-md { height: 44px; padding: 0 18px; font-size: 14px; }
.price-line { margin: 12px 2px 0; font-size: 13px; color: var(--muted); }
.price-line b { color: var(--text); font-weight: 600; }

/* 结果 */
#resultBox { scroll-margin-top: 78px; }
.result { margin-top: 16px; scroll-margin-top: 84px; animation: rise .3s cubic-bezier(.22,.61,.36,1); }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.result-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.result-head .ico {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--ok-bg); color: var(--ok);
}
.result-head .ico svg { width: 21px; height: 21px; fill: currentColor; }
.result-head .ico.bad { background: var(--bad-bg); color: var(--bad); }
.result-head .ico.warn { background: var(--warn-bg); color: var(--warn); }
.result-title { font-size: 18px; font-weight: 650; letter-spacing: -.01em; word-break: break-word; }
.result-sub { font-size: 13px; color: var(--sub); margin-top: 1px; overflow-wrap: break-word; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 11px; border-radius: 100px; font-size: 12px; font-weight: 600;
  background: var(--field); color: var(--sub);
}
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.kv { border-top: 1px solid var(--line); }
.kv .item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.kv .item:last-child { border-bottom: 0; }
.kv .k { font-size: 13px; color: var(--sub); flex: none; min-width: 74px; }
.kv .v { font-size: 14px; font-weight: 500; text-align: right; min-width: 0; word-break: break-word; font-variant-numeric: tabular-nums; }
.kv .v .mini { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.kv .v .mini.ok { background: var(--ok-bg); color: var(--ok); }
.kv .v .mini.bad { background: var(--bad-bg); color: var(--bad); }
.kv .v .mini.warn { background: var(--warn-bg); color: var(--warn); }
.kv .v .mini.neutral { background: var(--field); color: var(--sub); }
.group { margin-top: 6px; }
.group > .gtitle {
  padding: 14px 0 8px; font-size: 13px; font-weight: 650; color: var(--sub);
  letter-spacing: .02em; border-top: 1px solid var(--line);
}
.group:first-of-type > .gtitle { border-top: 0; padding-top: 0; }
.foot-note { margin: 12px 2px 0; font-size: 12px; color: var(--muted); }
.notice-act {
  margin-top: 14px; height: 40px; padding: 0 18px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer;
}
.notice-act:active { opacity: .72; }

/* 记录 */
.records .rec {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 13px 15px; margin-bottom: 9px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.rec-main { flex: 1; min-width: 0; }
.rec-t { font-size: 14px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rec-s { font-size: 12px; color: var(--muted); margin-top: 2px; font-variant-numeric: tabular-nums; }
.rec-r { text-align: right; flex: none; }
.rec-p { font-size: 13px; font-weight: 600; color: var(--sub); font-variant-numeric: tabular-nums; }
.rec-d { font-size: 11px; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; color: var(--muted); font-size: 14px; padding: 40px 0; }

/* 登录 */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 26px; }
.auth-brand svg { width: 34px; height: 34px; fill: var(--text); }
.auth-brand h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--field); border-radius: 11px; margin-bottom: 18px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px 0; border-radius: 8px; font-size: 14px; color: var(--sub); cursor: pointer; }
.tabs button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.form-field { margin-bottom: 13px; }
.btn-block { width: 100%; height: 48px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer; margin-top: 6px; }
.btn-block:disabled { opacity: .6; }
.form-msg { min-height: 18px; font-size: 13px; color: var(--bad); margin: -4px 2px 8px; }

/* 提示 */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px);
  background: rgba(28, 28, 30, .94); color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 100px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 后台 */
.admin-body { background: var(--bg); }
.admin-layout { display: flex; min-height: 100vh; }
.side {
  width: 210px; flex: none; padding: 22px 14px; border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side .brand { margin: 0 8px 24px; }
.side nav { display: flex; flex-direction: column; gap: 3px; }
.side nav button {
  border: 0; background: transparent; color: var(--sub); text-align: left;
  padding: 10px 12px; border-radius: 9px; font-size: 14px; cursor: pointer;
}
.side nav button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.admin-main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.admin-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.admin-title .at-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.admin-title h2 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.admin-title .at-right { display: none; align-items: center; gap: 2px; flex: none; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.stat .s-k { font-size: 12px; color: var(--muted); }
.stat .s-v { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 4px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { height: 40px; flex: 1; min-width: 180px; }
.toolbar button { height: 40px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.neutral { background: var(--field); color: var(--sub); }
input.price-input { width: 90px; height: 34px; padding: 0 10px; font-size: 14px; }
.switch { position: relative; width: 42px; height: 24px; border-radius: 100px; background: var(--field); border: 0; cursor: pointer; transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(18px); }
.vis { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.vis-t { font-size: 12px; color: var(--muted); white-space: nowrap; }
table.tbl tr.tr-hidden .svc-name { color: var(--muted); }
table.tbl tr.tr-hidden .vis-t { color: var(--warn); font-weight: 600; }
.settings-form { max-width: 460px; }
.settings-form .card { padding: 20px; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.hint { font-size: 12px; color: var(--muted); margin: 7px 2px 0; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 18px;
  padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  animation: rise .22s ease;
}
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal p { margin: 0 0 16px; font-size: 13px; color: var(--sub); }
.modal .actions { display: flex; gap: 10px; margin-top: 18px; }
.modal .actions .primary { flex: 1; }
.modal .actions .ghost { flex: 1; height: 48px; }
.quick { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.quick button { padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--field); color: var(--text); font-size: 13px; cursor: pointer; min-height: 38px; }
.quick button:active { transform: scale(.97); }

/* ---------- 平板：后台侧栏改为底部标签栏 ---------- */
@media (max-width: 860px) {
  .admin-layout { display: block; }
  .side {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: auto; height: auto; display: block; z-index: 40;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line); border-bottom: 0;
    background: var(--card);
    background: color-mix(in srgb, var(--card) 90%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    overflow: visible;
  }
  .side .brand, .side .side-foot { display: none; }
  .side nav { flex-direction: row; gap: 2px; }
  .side nav button {
    flex: 1 1 0; text-align: center; padding: 9px 2px; min-height: 46px;
    font-size: 12.5px; border-radius: 10px;
  }
  .side nav button:active { background: var(--field); }
  .admin-main { padding: 0 14px calc(82px + env(safe-area-inset-bottom)); }
  .admin-title {
    position: sticky; top: 0; z-index: 30; margin: 0 -14px 16px;
    padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--line);
  }
  .admin-title h2 { font-size: 18px; }
  .admin-title .at-right { display: flex; }
  .admin-title .linkbtn { font-size: 13px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .s-v { font-size: 21px; }
  .settings-form { max-width: none; }
}
@media (min-width: 861px) {
  .side-foot { position: absolute; bottom: 18px; left: 14px; right: 14px; font-size: 12px; color: var(--muted); }
}
@media (min-width: 861px) and (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 手机 ---------- */
@media (max-width: 640px) {
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 14px 8px; gap: 8px; flex-wrap: wrap; row-gap: 2px; }
  .brand { font-size: 16px; gap: 6px; }
  .brand span { max-width: 9em; }
  .recharge-tip { order: 3; flex: 0 0 100%; text-align: center; font-size: 12px; }
  .userbox { gap: 2px; }
  .uname { display: none; }
  .balance { padding: 6px 10px; }
  .wrap { padding: 14px 14px calc(40px + env(safe-area-inset-bottom)); }
  .seg { margin-bottom: 14px; }
  .seg button { min-height: 40px; }
  .card { padding: 18px 16px; border-radius: 16px; }
  .toast { bottom: calc(22px + env(safe-area-inset-bottom)); padding: 12px 18px; max-width: calc(100vw - 40px); }
  .auth-wrap {
    min-height: 100vh; min-height: 100dvh;
    padding: calc(28px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  }
  .auth-brand { margin-bottom: 20px; }
  .auth-brand h1 { font-size: 22px; }
  .btn-block, button.primary { min-height: 50px; }

  /* 后台数据表 → 卡片列表 */
  .panel { padding: 0; border: 0; background: transparent; border-radius: 0; overflow: visible; }
  table.tbl { display: block; font-size: 13px; }
  table.tbl thead { display: none; }
  table.tbl tbody { display: block; }
  table.tbl tr {
    display: block; background: var(--card); border: 1px solid var(--line);
    border-radius: 14px; padding: 4px 14px; margin-bottom: 9px;
  }
  table.tbl td {
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
    padding: 9px 0; border-bottom: 1px solid var(--line);
    white-space: normal; text-align: right; word-break: break-word;
  }
  table.tbl td:last-child { border-bottom: 0; }
  table.tbl td::before {
    content: attr(data-label); flex: none; text-align: left;
    font-size: 12px; font-weight: 600; color: var(--muted);
  }
  table.tbl td.empty { justify-content: center; padding: 30px 0; color: var(--muted); }
  table.tbl td.empty::before { display: none; }
  table.tbl td .linkbtn {
    margin-left: 6px; padding: 8px 12px; border-radius: 9px;
    background: var(--field); font-size: 13px; min-height: 36px;
  }
  input.price-input { width: 108px; height: 40px; font-size: 16px; }
  /* 手机上隐藏信息量低的两列，卡片更紧凑 */
  table.tbl td[data-label="ID"],
  table.tbl td[data-label="注册时间"] { display: none; }
  .toolbar { gap: 8px; }
  .toolbar input { flex: 1 1 100%; min-width: 0; height: 44px; }
  .toolbar button { flex: 1; height: 44px; }
  .hint { font-size: 12.5px; }

  /* 弹窗改为底部弹出，避免键盘遮挡 */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none; width: 100%; border-radius: 20px 20px 0 0;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
    max-height: 88vh; overflow-y: auto;
    animation: sheet .24s cubic-bezier(.22,.61,.36,1);
  }
  @keyframes sheet { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
  .modal .actions { margin-top: 16px; }
  .quick button { flex: 1 1 0; min-height: 42px; }
  .settings-actions button { flex: 1; }
}

/* ---------- 小屏手机 ---------- */
@media (max-width: 420px) {
  .row { flex-direction: column; }
  .row > button.primary { width: 100%; }
  .kv .item { gap: 12px; }
  .kv .k { min-width: 66px; }
  .rec { padding: 12px 13px; }
  .stat-grid { gap: 8px; }
  .stat .s-v { font-size: 19px; }
  .admin-title { padding-left: 12px; padding-right: 12px; margin-left: -14px; margin-right: -14px; }
}
