:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2635;
  --muted: #7b8698;
  --line: #e4e8f0;
  --primary: #2f6df6;
  --ok: #16a34a;
  --warn: #f59e0b;
  --danger: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

h1 { font-size: 18px; margin: 0 0 18px; }
h2 { font-size: 15px; margin: 0 0 14px; }

a { color: var(--primary); text-decoration: none; }

/* ---------- 布局 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px; height: 58px;
  background: #fff; border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; font-size: 15px; display: flex; align-items: center; gap: 12px; }
.top-balance {
  font-size: 13px; font-weight: 500; color: #2f6df6;
  background: #eef4ff; border: 1px solid #dbe6ff;
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}
.top-balance b { font-weight: 700; font-variant-numeric: tabular-nums; }
.top-right { display: flex; align-items: center; gap: 10px; }

.wrap { max-width: 1180px; margin: 22px auto 60px; padding: 0 18px; }
.wrap.narrow { max-width: 560px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.card.login { width: 100%; max-width: 380px; margin: 0; }

/* ---------- 表单 ---------- */
label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
input {
  display: block; width: 100%; margin-top: 6px;
  padding: 9px 11px; font-size: 14px; color: var(--text);
  background: #fff;
  border: 1px solid var(--line); border-radius: 8px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,109,246,.13);
}
input.mini { width: 78px; display: inline-block; margin: 0 4px 0 0; padding: 5px 8px; font-size: 13px; }

select {
  display: block; width: 100%; margin-top: 6px;
  padding: 9px 11px; font-size: 14px; color: var(--text);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  font-family: inherit;
}
select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 109, 246, .13);
}
select.mini { width: auto; display: inline-block; margin: 0 4px 0 0; padding: 5px 8px; font-size: 13px; }

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0 16px; align-items: end;
}
.grid-form button { margin-bottom: 14px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  padding: 8px 16px; font-size: 14px; font-family: inherit;
  color: var(--text); background: #eef1f7;
  border: 1px solid transparent; border-radius: 8px;
  cursor: pointer; white-space: nowrap;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.ok      { background: var(--ok); color: #fff; }
.btn.warn    { background: var(--warn); color: #fff; }
.btn.danger  { background: var(--danger); color: #fff; }
.btn.ghost   { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.block   { display: block; width: 100%; }
.btn.big     { padding: 12px 22px; font-size: 15px; }
.btn.mini    { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; filter: none; }

/* ---------- 统计卡 ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 18px;
}
.stat .k { display: block; font-size: 12px; color: var(--muted); }
.stat .v { display: block; font-size: 22px; font-weight: 600; margin-top: 4px; }

/* ---------- 表格 ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: 12px; background: #fafbfe; white-space: nowrap; }
tbody tr:hover { background: #fafbfe; }
td.money { font-variant-numeric: tabular-nums; }
td.op-col, th.op-col { min-width: 380px; }
form.inline { display: flex; align-items: center; gap: 4px; margin: 3px 0; flex-wrap: wrap; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }

/* ---------- 徽标 / 提示 ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 500;
}
.st-idle  { background: #eceff4; color: #64748b; }
.st-run   { background: #dcfce7; color: #15803d; }
.st-pause { background: #fef3c7; color: #b45309; }
.st-low   { background: #fee2e2; color: #b91c1c; }

.alert {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px;
}
.alert.ok  { background: #dcfce7; color: #166534; }
.alert.err { background: #fee2e2; color: #991b1b; }
.alert.hidden { display: none; }

.muted { color: var(--muted); font-size: 13px; }
.hint  { font-size: 12px; color: var(--muted); margin: 12px 0 0; }
.hint code { background: #eef1f7; padding: 1px 5px; border-radius: 4px; }

/* ---------- 用户计费面板 ---------- */
.meter { text-align: center; padding: 26px 22px 22px; }
.meter-head { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 20px; }

.balance {
  font-size: 46px; font-weight: 700; line-height: 1.1;
  font-variant-numeric: tabular-nums; letter-spacing: -.5px;
}
.balance .cur { font-size: 24px; font-weight: 500; margin-right: 4px; color: var(--muted); }
.balance-sub, .timer-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.timer {
  margin-top: 20px; font-size: 26px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.meter.running .timer { color: var(--ok); }
.meter.paused  .timer { color: var(--warn); }

.facts {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; margin: 22px 0;
}
.facts > div { background: #fff; padding: 11px 12px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { margin: 3px 0 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- 卡密充值 ---------- */
.redeem-row { display: flex; gap: 10px; }
.redeem-row input {
  flex: 1; margin-top: 0;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  letter-spacing: 1px; text-transform: uppercase;
}

/* ---------- 操作结果动态提示 ---------- */
.toast-wrap {
  position: fixed; top: 70px; right: 18px; z-index: 999;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(360px, 86vw); pointer-events: none;
}
.toast {
  padding: 10px 14px; font-size: 13px; line-height: 1.5;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(19, 32, 58, .12);
  animation: toast-in .22s ease-out;
}
.toast.ok  { background: #ecfdf3; border-color: #bbf7d0; color: #166534; }
.toast.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.toast.out { opacity: 0; transform: translateY(-6px); transition: opacity .28s, transform .28s; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- 操作记录面板 ---------- */
.log-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.log-head h2 { margin: 0; }
.log-tools { display: flex; align-items: center; gap: 10px; }
.log-stat {
  font-size: 12px; color: var(--muted);
  background: #f4f6fa; border: 1px solid var(--line);
  padding: 2px 10px; border-radius: 999px;
}
.log-stat b { font-variant-numeric: tabular-nums; }
.log-stat.ok  { color: #15803d; background: #f0fdf4; border-color: #dcfce7; }
.log-stat.err { color: #b91c1c; background: #fef2f2; border-color: #fee2e2; }

.log-list {
  list-style: none; margin: 0; padding: 0;
  max-height: 280px; overflow-y: auto; overscroll-behavior: contain;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fbfcfe;
}
.log-list::-webkit-scrollbar { width: 8px; }
.log-list::-webkit-scrollbar-thumb { background: #d8dfea; border-radius: 8px; }

.log-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 12px; font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.log-item:last-child { border-bottom: none; }
.log-time {
  flex: 0 0 auto; padding-top: 1px;
  font-size: 12px; color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}
.log-text { flex: 1; word-break: break-word; }
.log-dot {
  flex: 0 0 auto; width: 8px; height: 8px; margin-top: 6px;
  border-radius: 50%; background: #94a3b8;
}
.log-item.ok   .log-dot { background: var(--ok);       box-shadow: 0 0 0 3px rgba(22, 163, 74, .15); }
.log-item.err  .log-dot { background: var(--danger);   box-shadow: 0 0 0 3px rgba(220, 38, 38, .15); }
.log-item.info .log-dot { background: var(--primary);  box-shadow: 0 0 0 3px rgba(47, 109, 246, .15); }
.log-item.ok   .log-text { color: #14532d; }
.log-item.err  .log-text { color: #7f1d1d; }
.log-item.in { animation: log-in .26s ease-out; }

@keyframes log-in {
  from { opacity: 0; transform: translateY(-6px); background: #eaf1ff; }
  to   { opacity: 1; transform: translateY(0); background: transparent; }
}

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

/* ---------- 网络状态 ---------- */
.net-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: #f4f6fa; border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.net-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: #94a3b8; flex: 0 0 auto;
}
.net-pill.good, .net-badge.good { color: #15803d; background: #f0fdf4; border-color: #dcfce7; }
.net-pill.fair, .net-badge.fair { color: #b45309; background: #fffbeb; border-color: #fef3c7; }
.net-pill.poor, .net-badge.poor { color: #b91c1c; background: #fef2f2; border-color: #fee2e2; }
.net-pill.offline, .net-badge.offline { color: #64748b; background: #eceff4; border-color: #e4e8f0; }

.net-pill.good .net-dot   { background: var(--ok);     box-shadow: 0 0 0 3px rgba(22, 163, 74, .18); }
.net-pill.fair .net-dot   { background: var(--warn);   box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.net-pill.poor .net-dot   { background: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, .18); }
.net-badge.good .net-dot  { background: var(--ok); }
.net-badge.fair .net-dot  { background: var(--warn); }
.net-badge.poor .net-dot  { background: var(--danger); }

.net-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px;
}
.net-head h2 { margin: 0; }
.net-tools { display: flex; align-items: center; gap: 8px; }
.app-state { font-size: 11px; color: #94a3b8; white-space: nowrap; }
.app-state.bad { color: #b91c1c; font-weight: 600; }
.net-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: #f4f6fa; border: 1px solid var(--line); color: var(--muted);
}

.net-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; margin-bottom: 14px;
}
.net-metric { background: #fff; padding: 10px 12px; }
.net-metric .k { display: block; font-size: 12px; color: var(--muted); }
.net-metric .v {
  display: block; margin-top: 2px; font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.net-bars {
  display: flex; align-items: flex-end; gap: 2px; height: 56px;
  padding: 6px 8px; background: #fbfcfe;
  border: 1px solid var(--line); border-radius: 10px;
}
.net-bars i {
  flex: 1; min-height: 3px; border-radius: 2px; background: #cbd5e1;
  transition: height .2s ease;
}
.net-bars i.good { background: var(--ok); }
.net-bars i.fair { background: var(--warn); }
.net-bars i.poor { background: var(--danger); }

@media (max-width: 560px) {
  .balance { font-size: 38px; }
  .actions .btn { flex: 1 1 44%; }
  .redeem-row { flex-direction: column; }
  .top-balance { font-size: 12px; padding: 2px 8px; }
  .toast-wrap { top: auto; bottom: 16px; left: 12px; right: 12px; max-width: none; }
  .log-head { flex-wrap: wrap; }
  .log-list { max-height: 240px; }
  .net-pill { font-size: 11px; padding: 2px 8px; }
  .brand { gap: 8px; }
}

/* ---------- 充值战绩 ---------- */
.redeem-stats {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 12px;
}
.rs {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: #f4f6fa; border: 1px solid var(--line); color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.rs b { display: inline-block; font-weight: 700; }
.rs.ok    { color: #15803d; background: #f0fdf4; border-color: #dcfce7; }
.rs.err   { color: #b91c1c; background: #fef2f2; border-color: #fee2e2; }
.rs b.bump { animation: count-bump .5s ease-out; }

@keyframes count-bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.9); }
  100% { transform: scale(1); }
}

/* ---------- 特效层 ---------- */
.fx-aura, .fx-particles, .fx-layer {
  position: fixed; inset: 0; pointer-events: none;
}
.fx-aura      { z-index: 1; opacity: 0; transition: opacity .6s ease; }
.fx-particles { z-index: 2; overflow: hidden; }
.fx-layer     { z-index: 900; }

/* 计费中：整屏背景光晕 + 上下扫描光带 */
.fx-aura {
  background:
    radial-gradient(60% 45% at 50% 0%,   rgba(47, 109, 246, .12), transparent 70%),
    radial-gradient(60% 45% at 50% 100%, rgba(16, 185, 129, .12), transparent 70%);
}
body.billing-on .fx-aura { opacity: 1; animation: aura-breathe 5s ease-in-out infinite; }
.fx-aura::before, .fx-aura::after {
  content: ''; position: absolute; left: 0; right: 0; height: 160px; opacity: 0;
  background: linear-gradient(90deg, transparent, rgba(47, 109, 246, .18), rgba(16, 185, 129, .18), transparent);
}
body.billing-on .fx-aura::before { top: 0;    animation: aura-scan 6s linear infinite; }
body.billing-on .fx-aura::after  { bottom: 0; animation: aura-scan 6s linear infinite reverse; }

@keyframes aura-breathe {
  0%, 100% { opacity: .5; }
  50%      { opacity: 1; }
}
@keyframes aura-scan {
  0%   { opacity: 0; transform: translateX(-60%); }
  50%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(60%); }
}

/* 计费中：漂浮光点 */
.fx-particles i {
  position: absolute; bottom: -20px; border-radius: 50%;
  background: radial-gradient(circle, rgba(96, 165, 250, .95), rgba(96, 165, 250, 0));
  animation-name: particle-rise;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes particle-rise {
  0%   { transform: translateY(0) scale(.6);      opacity: 0; }
  15%  { opacity: .9; }
  100% { transform: translateY(-105vh) scale(1.1); opacity: 0; }
}

/* 计费中：余额脉冲、卡片辉光、顶栏光带 */
body.billing-on #balance { animation: balance-glow 2s ease-in-out infinite; }
@keyframes balance-glow {
  0%, 100% { text-shadow: 0 0 0 rgba(22, 163, 74, 0); }
  50%      { text-shadow: 0 0 18px rgba(22, 163, 74, .55); }
}

body.billing-on .meter { animation: meter-pulse 2.6s ease-in-out infinite; }
@keyframes meter-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(22, 163, 74, .20), 0 0 20px rgba(22, 163, 74, .12); }
  50%      { box-shadow: 0 0 0 1px rgba(22, 163, 74, .45), 0 0 34px rgba(22, 163, 74, .28); }
}

body.billing-on .topbar {
  background-image: linear-gradient(90deg, transparent, rgba(47, 109, 246, .18), rgba(16, 185, 129, .18), transparent);
  background-size: 200% 100%;
  animation: topbar-flow 4s linear infinite;
}
@keyframes topbar-flow {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 充值成功 / 失败爆发特效 */
.fx-burst {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
}
.fx-burst.ok  { color: var(--ok); }
.fx-burst.err { color: var(--danger); }

.fx-ring {
  position: absolute; width: 60px; height: 60px; border-radius: 50%;
  border: 2px solid currentColor; opacity: .9;
  animation: ring-out .9s ease-out forwards;
}
.fx-ring.d2 { animation-delay: .12s; }
@keyframes ring-out {
  0%   { transform: scale(.3); opacity: .95; }
  100% { transform: scale(7);  opacity: 0; }
}

.fx-text {
  position: relative; z-index: 1; white-space: nowrap;
  font-size: 22px; font-weight: 700;
  padding: 10px 20px; border-radius: 12px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 10px 30px rgba(19, 32, 58, .18);
  animation: text-pop 1.6s ease-out forwards;
}
.fx-burst.ok  .fx-text { color: #15803d; border: 2px solid #bbf7d0; }
.fx-burst.err .fx-text {
  color: #b91c1c; border: 2px solid #fecaca;
  animation: text-pop 1.6s ease-out forwards, text-shake .5s ease-in-out .1s;
}
@keyframes text-pop {
  0%   { transform: scale(.6) translateY(10px);  opacity: 0; }
  25%  { transform: scale(1.08) translateY(0);   opacity: 1; }
  70%  { transform: scale(1);                    opacity: 1; }
  100% { transform: scale(1) translateY(-14px);  opacity: 0; }
}
@keyframes text-shake {
  0%, 100% { margin-left: 0; }
  20%      { margin-left: -10px; }
  40%      { margin-left: 8px; }
  60%      { margin-left: -6px; }
  80%      { margin-left: 4px; }
}

.fx-spark {
  position: absolute; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  animation: spark-out 1s ease-out forwards;
}
@keyframes spark-out {
  0%   { transform: translate(0, 0) scale(1);                       opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(.2);      opacity: 0; }
}

/* 充值失败：屏幕红光闪烁 */
body.fx-shake::after {
  content: ''; position: fixed; inset: 0; z-index: 950; pointer-events: none;
  box-shadow: inset 0 0 120px rgba(220, 38, 38, .5);
  animation: red-flash .7s ease-out;
}
@keyframes red-flash {
  0%   { opacity: 1; }
  100% { opacity: 0; }
}

/* 尊重系统的「减少动态效果」设置 */
@media (prefers-reduced-motion: reduce) {
  body.billing-on .fx-aura,
  body.billing-on .fx-aura::before,
  body.billing-on .fx-aura::after,
  body.billing-on #balance,
  body.billing-on .meter,
  body.billing-on .topbar,
  .fx-particles i,
  .fx-ring, .fx-text, .fx-spark, body.fx-shake::after {
    animation: none !important;
  }
}
