/* ============ TDesign 设计令牌 ============ */
:root {
  --td-brand-color: #0052D9;
  --td-brand-hover: #366EF4;
  --td-brand-active: #0034B5;
  --td-brand-light: #E7F0FF;
  --td-success: #00A870;
  --td-success-light: #E8F8F2;
  --td-warning: #ED7B2F;
  --td-warning-light: #FEF3E6;
  --td-error: #E34D59;
  --td-error-light: #FDECEE;
  --td-bg-page: #F3F3F3;
  --td-bg-card: #FFFFFF;
  --td-border: #DCDCDC;
  --td-border-light: #E7E7E7;
  --td-text-primary: rgba(0, 0, 0, .9);
  --td-text-secondary: rgba(0, 0, 0, .6);
  --td-text-placeholder: rgba(0, 0, 0, .4);
  --td-radius-sm: 3px;
  --td-radius-md: 6px;
  --td-radius-lg: 9px;
  --td-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .05);
  --td-font: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ============ Reset ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--td-font);
  font-size: 14px;
  color: var(--td-text-primary);
  background: var(--td-bg-page);
  -webkit-font-smoothing: antialiased;
}
a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
b { font-weight: 600; }

/* ============ 视图切换 ============ */
.view { display: none; }
.view.active { display: block; }

/* ============ 顶栏 ============ */
.topbar { display: none; }
.topbar.active {
  display: block;
  background: var(--td-bg-card);
  border-bottom: 1px solid var(--td-border-light);
  position: sticky; top: 0; z-index: 100;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 24px;
  height: 56px; display: flex; align-items: center; gap: 32px;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo {
  width: 30px; height: 30px; border-radius: var(--td-radius-md);
  background: var(--td-brand-color); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
}
.brand-name { font-size: 16px; font-weight: 600; }
.nav { display: flex; gap: 8px; margin-left: 8px; }
.nav-item {
  padding: 6px 14px; border-radius: var(--td-radius-sm);
  color: var(--td-text-secondary); font-size: 14px;
  transition: color .2s, background .2s;
}
.nav-item:hover { color: var(--td-text-primary); }
.nav-item.active { color: var(--td-brand-color); background: var(--td-brand-light); font-weight: 500; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--td-brand-light); color: var(--td-brand-color);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}
.username { color: var(--td-text-primary); font-size: 14px; }

/* ============ 页面容器 ============ */
.page { max-width: 1200px; margin: 0 auto; padding: 24px; }

/* ============ 卡片 ============ */
.td-card {
  background: var(--td-bg-card);
  border: 1px solid var(--td-border-light);
  border-radius: var(--td-radius-lg);
  box-shadow: var(--td-shadow);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px 20px;
  border-bottom: 1px solid var(--td-border-light);
}
.card-head-wrap { flex-wrap: wrap; }
.card-title { font-size: 16px; font-weight: 600; }
.card-tools { display: flex; align-items: center; gap: 8px; }

/* ============ 按钮 ============ */
.td-btn {
  border: 1px solid transparent; border-radius: var(--td-radius-sm);
  height: 36px; padding: 0 16px; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .2s, border-color .2s, color .2s;
}
.td-btn-primary { background: var(--td-brand-color); color: #fff; }
.td-btn-primary:hover { background: var(--td-brand-hover); }
.td-btn-primary:active { background: var(--td-brand-active); }
.td-btn-outline { background: #fff; color: var(--td-text-primary); border-color: var(--td-border); }
.td-btn-outline:hover { border-color: var(--td-brand-color); color: var(--td-brand-color); }
.td-btn-text { background: transparent; color: var(--td-text-secondary); }
.td-btn-text:hover { color: var(--td-brand-color); }
.td-btn-block { width: 100%; }

/* ============ 输入框 ============ */
.td-input {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--td-border); border-radius: var(--td-radius-sm);
  background: #fff; padding: 0 12px; height: 36px;
  transition: border-color .2s, box-shadow .2s;
}
.td-input:focus-within { border-color: var(--td-brand-color); box-shadow: 0 0 0 2px var(--td-brand-light); }
.td-input input {
  border: none; outline: none; flex: 1; height: 100%;
  font-size: 14px; font-family: inherit; color: var(--td-text-primary);
  background: transparent; min-width: 0;
}
.td-input input::placeholder { color: var(--td-text-placeholder); }
.eye { border: none; background: transparent; color: var(--td-text-secondary); display: flex; padding: 2px; }
.eye:hover { color: var(--td-brand-color); }
.td-select {
  height: 36px; border: 1px solid var(--td-border); border-radius: var(--td-radius-sm);
  padding: 0 8px; font-size: 14px; font-family: inherit; color: var(--td-text-primary);
  background: #fff; outline: none;
}
.td-select:focus { border-color: var(--td-brand-color); }
.td-search { width: 200px; }

/* ============ 登录页 ============ */
.view-login { min-height: 100vh; }
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--td-bg-page);
}
.login-card {
  width: 400px; max-width: 100%;
  background: #fff; border: 1px solid var(--td-border-light);
  border-radius: var(--td-radius-lg); box-shadow: var(--td-shadow);
  padding: 36px 32px;
}
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.login-brand .brand-logo { width: 36px; height: 36px; font-size: 18px; }
.login-brand .brand-name { font-size: 20px; font-weight: 600; }
.login-sub { text-align: center; color: var(--td-text-secondary); font-size: 13px; margin-bottom: 28px; }
.form-field { margin-bottom: 18px; }
.form-field label { display: block; font-size: 14px; margin-bottom: 8px; color: var(--td-text-primary); }
.login-card .td-btn-block { margin-top: 8px; height: 40px; font-size: 15px; }
.login-hint { margin-top: 18px; text-align: center; color: var(--td-text-placeholder); font-size: 12px; }

/* ============ 统计卡片 ============ */
.stat-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; margin-bottom: 16px;
}
.stat-card { padding: 20px; }
.stat-label { font-size: 13px; color: var(--td-text-secondary); margin-bottom: 10px; }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-value-sm { font-size: 24px; }
.stat-meta { margin-top: 8px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.tag-up { color: var(--td-success); font-size: 12px; }
.tag-down { color: var(--td-brand-color); font-size: 12px; }
.muted { color: var(--td-text-placeholder); font-size: 12px; }
.progress { height: 6px; border-radius: 3px; background: var(--td-brand-light); overflow: hidden; margin-top: 12px; }
.progress-bar { height: 100%; background: var(--td-brand-color); border-radius: 3px; transition: width .3s; }
.progress-bar.warn { background: var(--td-warning); }
.progress-bar.danger { background: var(--td-error); }

/* ============ 图表卡片 ============ */
.chart-card { margin-bottom: 16px; }
.chart-legend { display: flex; gap: 16px; padding: 12px 20px 0; }
.lg { font-size: 12px; color: var(--td-text-secondary); display: inline-flex; align-items: center; gap: 6px; }
.lg::before { content: ""; width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.lg-down::before { background: var(--td-brand-color); }
.lg-up::before { background: var(--td-success); }
.chart-box { padding: 16px 20px 20px; height: 300px; position: relative; }

/* ============ 表格 ============ */
.table-card { margin-bottom: 16px; }
.td-table-wrap { overflow-x: auto; }
.td-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.td-table th, .td-table td { padding: 12px 20px; text-align: left; white-space: nowrap; }
.td-table thead th {
  color: var(--td-text-secondary); font-weight: 500; font-size: 13px;
  border-bottom: 1px solid var(--td-border-light); background: #FAFAFA;
}
.td-table tbody tr { border-bottom: 1px solid var(--td-border-light); }
.td-table tbody tr:last-child { border-bottom: none; }
.td-table tbody tr:hover { background: var(--td-brand-light); }
.td-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.td-table th.num { text-align: right; }

/* 排行 */
.rank-table td { padding: 14px 20px; }
.rank-medal { font-size: 18px; }
.rank-index {
  display: inline-flex; width: 24px; height: 24px; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--td-bg-page); color: var(--td-text-secondary); font-size: 13px;
}
.rank-user { display: flex; align-items: center; gap: 10px; }
.rank-user .avatar { width: 30px; height: 30px; }
.rank-email { color: var(--td-text-placeholder); font-size: 12px; margin-left: 4px; }
.trend-up { color: var(--td-success); }
.trend-down { color: var(--td-error); }

/* 排行：可点击排序表头 + 当前排序列高亮 */
th.sortable { cursor: pointer; user-select: none; transition: color .15s; }
th.sortable:hover { color: var(--td-brand-color); }
th.sortable.active { color: var(--td-brand-color); }
th.sortable.active::after { content: ' ↓'; font-weight: 700; }
td.col-active { background: rgba(0, 82, 217, .045); font-weight: 600; }
.col-act { width: 72px; text-align: center; }
/* 备注（别名）编辑 */
.alias-edit {
  border: 1px solid var(--td-border); background: #fff; color: var(--td-text-secondary);
  border-radius: var(--td-radius-sm); padding: 3px 9px; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.alias-edit:hover { border-color: var(--td-brand-color); color: var(--td-brand-color); }
.rank-alias-tag {
  font-size: 11px; color: var(--td-brand-color); border: 1px solid var(--td-border);
  border-radius: 4px; padding: 0 4px; margin-left: 4px; background: #fff;
}
/* 备注弹窗 */
.modal-foot-split { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.alias-btns { display: inline-flex; gap: 8px; }
.alias-tip { font-size: 12px; margin: 8px 0 12px; }
.alias-input { width: 100%; }
.alias-input input { width: 100%; }
.empty { padding: 48px; text-align: center; color: var(--td-text-placeholder); }
.pager { display: flex; gap: 6px; justify-content: center; padding: 16px; }
.pager-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--td-border); border-radius: var(--td-radius-sm);
  background: #fff; color: var(--td-text-primary); font-size: 13px;
}
.pager-btn:hover { border-color: var(--td-brand-color); color: var(--td-brand-color); }
.pager-btn.active { background: var(--td-brand-color); border-color: var(--td-brand-color); color: #fff; }

/* ============ Tabs ============ */
.tabs { display: inline-flex; background: #f3f3f3; border-radius: var(--td-radius-sm); padding: 3px; gap: 2px; }
.tab {
  border: none; background: transparent; padding: 5px 14px; font-size: 13px;
  color: var(--td-text-secondary); border-radius: var(--td-radius-sm); transition: all .2s;
}
.tab:hover { color: var(--td-text-primary); }
.tab.active { background: #fff; color: var(--td-brand-color); font-weight: 500; box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* ============ 实时流量 + 趋势（左右分栏） ============ */
.traffic-split {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px;
}
.card-meta { font-size: 12px; color: var(--td-text-placeholder); }
.realtime-card { display: flex; flex-direction: column; }
.realtime-body { display: flex; gap: 16px; padding: 20px; }
.realtime-chart-box { flex: 1; min-height: 140px; padding: 0 20px 12px; display: flex; }
.realtime-chart-box canvas { width: 100% !important; height: 100% !important; }
.realtime-metric { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.rt-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--td-text-secondary); }
.rt-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.rt-dot.up { background: var(--td-success); }
.rt-dot.down { background: var(--td-brand-color); }
.rt-value { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.rt-value.up { color: var(--td-success); }
.rt-value.down { color: var(--td-brand-color); }
.realtime-peak { padding: 0 20px 18px; font-size: 12px; color: var(--td-text-placeholder); }

/* ============ 日历（使用明细） ============ */
.cal-nav { display: inline-flex; align-items: center; gap: 8px; }
.cal-btn {
  width: 30px; height: 30px; border-radius: var(--td-radius-sm);
  border: 1px solid var(--td-border); background: #fff; color: var(--td-text-primary);
  font-size: 16px; line-height: 1; display: inline-flex; align-items: center; justify-content: center;
}
.cal-btn:hover { border-color: var(--td-brand-color); color: var(--td-brand-color); }
.cal-title { min-width: 96px; text-align: center; font-size: 14px; font-weight: 500; }
.calendar { padding: 16px 20px; }
.cal-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; margin-bottom: 8px; }
.cal-weekdays span { text-align: center; font-size: 13px; color: var(--td-text-secondary); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.cal-cell {
  border: 1px solid var(--td-border-light); border-radius: var(--td-radius-md);
  padding: 8px; min-height: 66px; background: #fff;
  display: flex; flex-direction: column; gap: 4px;
}
.cal-cell.empty { background: transparent; border: none; }
.cal-cell.today { border-color: var(--td-brand-color); box-shadow: 0 0 0 2px var(--td-brand-light); }
.cal-day { font-size: 13px; font-weight: 500; color: var(--td-text-primary); }
.cal-traffic { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cal-cell.zero .cal-traffic { font-weight: 400; }
.cal-footer {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 20px; border-top: 1px solid var(--td-border-light);
}
.cal-total { font-size: 14px; color: var(--td-text-primary); }
.cal-total b { font-size: 16px; color: var(--td-brand-color); font-variant-numeric: tabular-nums; }
.cal-legend { display: flex; gap: 14px; flex-wrap: wrap; }
.lg-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--td-text-secondary); }
.lg-dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ============ 响应式（移动端） ============ */
@media (max-width: 768px) {
  .topbar-inner { padding: 0 16px; gap: 12px; }
  .brand-name { display: inline; font-size: 15px; }
  .nav { margin-left: 0; }
  .username { display: none; }
  .page { padding: 16px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  /* 第 5 张卡片（服务器总剩余）在移动端跨两列填满 */
  .stat-card:last-child { grid-column: span 2; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 22px; }
  .stat-value-sm { font-size: 20px; }

  /* 实时流量 + 趋势：移动端上下堆叠 */
  .traffic-split { grid-template-columns: 1fr; gap: 12px; }
  .realtime-body { padding: 16px; }
  .realtime-chart-box { flex: none; height: 160px; padding: 0 16px 10px; }
  .rt-value { font-size: 24px; }

  .chart-box { height: 240px; padding: 12px 12px 16px; }
  .card-head { padding: 14px 16px; }
  .td-search { width: 100%; flex: 1; }

  /* 明细表在移动端保持横向滚动，但压缩内边距 */
  .td-table th, .td-table td { padding: 12px 16px; }

  /* 日历在移动端压缩间距 */
  .calendar { padding: 12px; }
  .cal-weekdays { gap: 4px; }
  .cal-grid { gap: 4px; }
  .cal-cell { min-height: 52px; padding: 6px; }
  .cal-day { font-size: 12px; }
  .cal-traffic { font-size: 11px; }
  .cal-footer { flex-direction: column; align-items: flex-start; gap: 10px; padding: 12px 16px; }
  .cal-legend { gap: 10px; }

  .login-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
  .nav-item { padding: 5px 10px; font-size: 13px; }
  .td-btn-text { display: none; } /* 移动端用头像下拉代替，此处隐藏退出文字 */
}

/* ============ 左侧悬浮标签 ============ */
.float-lottery {
  display: none;
  position: fixed;
  left: 0; top: 50%; transform: translateY(-50%);
  z-index: 200;
  flex-direction: column; align-items: center; gap: 8px;
  padding: 18px 10px;
  background: linear-gradient(160deg, #3E7BFA 0%, #0052D9 100%);
  color: #fff;
  border: none;
  border-radius: 0 var(--td-radius-lg) var(--td-radius-lg) 0;
  box-shadow: 2px 0 12px rgba(0, 82, 217, .28);
  transition: padding-left .2s, box-shadow .2s;
  font-size: 14px; font-weight: 600;
}
.float-lottery.active { display: flex; }
.float-lottery:hover { padding-left: 16px; box-shadow: 3px 0 18px rgba(0, 82, 217, .4); }
.fl-icon { font-size: 17px; line-height: 1; }
.fl-text { writing-mode: vertical-rl; letter-spacing: 3px; }

/* ============ 抽奖页 ============ */
.lottery-body {
  display: grid; grid-template-columns: 400px 1fr; gap: 24px;
  padding: 24px 20px; align-items: start;
}
.wheel-col { display: flex; justify-content: center; }
.wheel-area { position: relative; width: 360px; height: 360px; }
.wheel-rotor {
  width: 100%; height: 100%;
  transition: transform 4s cubic-bezier(.17, .67, .16, 1);
  will-change: transform;
}
.wheel-rotor canvas { width: 100%; height: 100%; display: block; }
.wheel-pointer {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  z-index: 3; width: 0; height: 0;
  border-left: 15px solid transparent;
  border-right: 15px solid transparent;
  border-top: 30px solid var(--td-error);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .2));
}
.spin-btn {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  z-index: 4;
  width: 92px; height: 92px; border-radius: 50%;
  background: var(--td-brand-color); color: #fff;
  border: 5px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 82, 217, .35);
  font-size: 16px; font-weight: 600; line-height: 1.25;
  transition: transform .15s, background .2s;
}
.spin-btn:hover:not(:disabled) { background: var(--td-brand-hover); transform: translate(-50%, -50%) scale(1.05); }
.spin-btn:active:not(:disabled) { transform: translate(-50%, -50%) scale(.96); }
.spin-btn:disabled { background: #C9CDD4; box-shadow: none; cursor: not-allowed; }

.lottery-side { display: flex; flex-direction: column; gap: 16px; }
.lottery-side .stat-card { padding: 20px; }
.record-list { list-style: none; max-height: 220px; overflow-y: auto; }
.record-list li {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--td-border-light);
}
.record-list li:last-child { border-bottom: none; }
.record-name { font-weight: 500; }
.record-time { color: var(--td-text-placeholder); font-size: 12px; }
.record-badge {
  display: inline-block; padding: 2px 10px; border-radius: 10px;
  font-size: 12px; font-weight: 600;
}
.record-win { background: var(--td-success-light); color: var(--td-success); }
.record-lose { background: var(--td-bg-page); color: var(--td-text-placeholder); }

/* ============ 管理页 ============ */
.prize-input {
  width: 110px; height: 34px; padding: 0 10px;
  border: 1px solid var(--td-border); border-radius: var(--td-radius-sm);
  font-size: 14px; font-family: inherit; color: var(--td-text-primary);
  font-variant-numeric: tabular-nums;
}
.prize-input:focus { outline: none; border-color: var(--td-brand-color); box-shadow: 0 0 0 2px var(--td-brand-light); }
.prize-dot {
  display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  margin-right: 8px; vertical-align: -1px;
  border: 1px solid rgba(0, 0, 0, .1);
}
.prize-bar-wrap { width: 220px; height: 8px; background: var(--td-bg-page); border-radius: 4px; overflow: hidden; }
.prize-bar { height: 100%; border-radius: 4px; transition: width .25s; }
.prize-total { display: flex; align-items: center; gap: 10px; padding: 18px 20px; border-top: 1px solid var(--td-border-light); }
.prize-total b { font-size: 16px; color: var(--td-brand-color); font-variant-numeric: tabular-nums; }
.prize-total b.error { color: var(--td-error); }
.prize-warn { color: var(--td-text-placeholder); font-size: 12px; }
.prize-warn.error { color: var(--td-error); }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal-mask[hidden] { display: none; }
.modal {
  width: 320px; max-width: 100%;
  background: #fff; border-radius: var(--td-radius-lg);
  box-shadow: 0 8px 40px rgba(0, 0, 0, .18);
  overflow: hidden;
  animation: modal-in .22s ease-out;
}
@keyframes modal-in {
  from { transform: translateY(12px) scale(.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.modal-body { padding: 32px 24px 24px; text-align: center; }
.result-icon { font-size: 44px; line-height: 1; margin-bottom: 14px; }
.result-title { font-size: 18px; font-weight: 600; margin-bottom: 10px; }
.result-prize {
  font-size: 36px; font-weight: 700; color: var(--td-brand-color);
  margin-bottom: 10px; font-variant-numeric: tabular-nums;
}
.result-prize.lose { font-size: 26px; color: var(--td-text-placeholder); font-weight: 600; }
.result-tip { color: var(--td-text-secondary); font-size: 13px; }
.modal-foot { padding: 0 24px 24px; }

/* ============ 抽奖 / 管理 响应式 ============ */
@media (max-width: 900px) {
  .lottery-body { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .float-lottery { padding: 14px 8px; font-size: 13px; letter-spacing: 2px; }
  .wheel-area { width: 300px; height: 300px; }
  .spin-btn { width: 78px; height: 78px; font-size: 14px; }
  .lottery-body { padding: 16px; gap: 16px; }
  .prize-bar-wrap { width: 120px; }
  .record-list li, .prize-total { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 420px) {
  .wheel-area { width: 270px; height: 270px; }
  .spin-btn { width: 70px; height: 70px; font-size: 13px; }
}
