:root {
  --bg: #eef1f8;
  --card-bg: #ffffff;
  --text: #1a2033;
  --text-muted: #6b7280;
  --border: #e8eaf1;
  --accent: #e11d48;
  --accent-2: #f97316;
  --accent-soft: #fde8ea;
  --primary: #3457d5;
  --primary-2: #6d5bd0;
  --primary-soft: #ebefff;
  --warn: #f59e0b;
  --warn-soft: #fef3e0;
  --good: #0ea472;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 8px 24px rgba(30, 41, 82, 0.07);
  --shadow-hover: 0 4px 8px rgba(20, 24, 40, 0.06), 0 14px 32px rgba(30, 41, 82, 0.10);
}

* { box-sizing: border-box; }

/* 类选择器里的 display 会盖掉 hidden 属性自带的 display:none，
   这里统一兜底，否则"后台管理"按钮等元素对无权限用户也会显示出来 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1000px 480px at 12% -8%, rgba(52, 87, 213, 0.10), transparent 60%),
    radial-gradient(900px 460px at 100% 0%, rgba(225, 29, 72, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 24px 56px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  background: linear-gradient(120deg, #1b234b 0%, #2c3374 45%, #7c2748 100%);
  border-radius: 20px;
  padding: 26px 30px;
  box-shadow: 0 12px 32px rgba(27, 35, 75, 0.28);
  position: relative;
  overflow: hidden;
}
.topbar::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(520px 220px at 92% 0%, rgba(255, 255, 255, 0.14), transparent 60%);
  pointer-events: none;
}
.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: #ffd9de;
  margin-bottom: 8px;
  text-transform: uppercase;
}
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #ff5470;
  box-shadow: 0 0 0 0 rgba(255, 84, 112, 0.6);
  animation: livepulse 1.8s infinite;
}
@keyframes livepulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 84, 112, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(255, 84, 112, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 84, 112, 0); }
}
.topbar h1 {
  font-size: 24px;
  margin: 0 0 8px;
  letter-spacing: 0.2px;
  color: #ffffff;
  font-weight: 700;
}
.subtitle {
  color: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  position: relative;
  z-index: 1;
}
.topbar-actions { display: flex; gap: 10px; position: relative; z-index: 1; }

.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); }
.btn-primary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(4px);
  font-weight: 600;
}
.btn-primary:hover { background: rgba(255, 255, 255, 0.24); color: #fff; border-color: rgba(255,255,255,.5); }
.btn:disabled { opacity: .6; cursor: default; transform: none; }

/* ---------- KPI ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 980px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: box-shadow .18s ease, transform .18s ease;
  border: 1px solid rgba(255,255,255,0.6);
}
.kpi-card:hover { box-shadow: var(--shadow-hover); transform: translateY(-2px); }
.kpi-icon {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  background: var(--primary-soft);
}
.kpi-card.accent .kpi-icon { background: var(--accent-soft); }
.kpi-body { flex: 1; min-width: 0; }
.kpi-label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.kpi-value { font-size: 25px; font-weight: 800; line-height: 1.1; letter-spacing: -0.2px; }
.kpi-sub { font-size: 12px; margin-top: 7px; color: var(--text-muted); }
.kpi-sub.up { color: var(--accent); font-weight: 600; }
.kpi-sub.down { color: var(--good); font-weight: 600; }
.kpi-card.accent .kpi-value { color: var(--accent); }

/* ---------- Card / Layout ---------- */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px;
  margin-bottom: 20px;
  border: 1px solid rgba(255,255,255,0.6);
}
.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: #212842;
  flex-wrap: wrap;
}
.card-icon { font-size: 16px; }
.card-title-sub {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.card-title-row .card-title { margin-bottom: 0; }

.charts-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
}
@media (max-width: 980px) { .charts-grid { grid-template-columns: 1fr; } }

/* 左右两张卡片等高，让图表撑满剩余空间而不是在卡片底部留出大片空白 */
.charts-grid > .card {
  display: flex;
  flex-direction: column;
  margin-bottom: 0;
}
.charts-grid > .card > .chart { flex: 1 1 auto; }
.charts-grid { margin-bottom: 20px; }

.chart { width: 100%; height: 320px; min-height: 320px; }
.chart-large { height: 380px; }

/* ---------- Tabs / Filters ---------- */
.tabs { display: flex; gap: 8px; flex: none; }
.tabs.small .tab { padding: 5px 14px; font-size: 12px; }
.tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.tab:hover { border-color: var(--primary); color: var(--primary); }
.tab.active {
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  color: #fff;
  border-color: transparent;
  font-weight: 600;
  box-shadow: 0 4px 10px rgba(52, 87, 213, 0.28);
}

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.input, .select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  background: #fbfbfe;
  color: var(--text);
  transition: border-color .15s ease;
}
.input:focus, .select:focus { border-color: var(--primary); outline: none; background: #fff; }
.input { width: 220px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  background: #fafbfe;
}
thead th:first-child { border-radius: 8px 0 0 0; }
thead th:last-child { border-radius: 0 8px 0 0; }
tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:nth-child(even) { background: #fbfcfe; }
tbody tr:hover { background: var(--primary-soft); }
.rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
}
.rank.top1 { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.title-cell { max-width: 360px; }
.title-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}
.title-link:hover { color: var(--primary); text-decoration: underline; }
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--primary);
  white-space: nowrap;
}
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.muted { color: var(--text-muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.growth-up { color: var(--accent); font-weight: 600; }
.empty-row td { text-align: center; color: var(--text-muted); padding: 30px; }

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.pagination button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all .15s ease;
}
.pagination button:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: default; }

.footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 12px;
  padding-top: 12px;
}

/* ---------- 登录页 ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card {
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: 0 12px 40px rgba(27, 35, 75, 0.16);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.6);
}
.auth-brand {
  background: linear-gradient(120deg, #1b234b 0%, #2c3374 45%, #7c2748 100%);
  padding: 26px 30px 24px;
  color: #fff;
}
.auth-brand h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: .2px; }
.auth-brand-sub {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}
.auth-form { padding: 26px 30px 30px; }
.auth-form-title {
  font-size: 15px;
  font-weight: 700;
  color: #212842;
  margin-bottom: 18px;
}
.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}
.field-input { width: 100%; padding: 10px 12px; font-size: 14px; }
.auth-error {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 14px;
}
.auth-submit {
  width: 100%;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 2px;
  color: #fff;
  border-color: transparent;
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  box-shadow: 0 6px 16px rgba(52, 87, 213, 0.28);
}
.auth-submit:hover:not(:disabled) {
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(52, 87, 213, 0.34);
}
.auth-tip {
  margin-top: 16px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- 后台管理 ---------- */
.topbar-admin { background: linear-gradient(120deg, #16203f 0%, #263169 50%, #2f5670 100%); }
.topbar-actions { align-items: center; flex-wrap: wrap; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.user-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.28);
  white-space: nowrap;
}
.btn-solid {
  background: linear-gradient(120deg, var(--primary), var(--primary-2));
  color: #fff;
  border-color: transparent;
  font-weight: 600;
}
.btn-solid:hover { color: #fff; border-color: transparent; }

.new-user-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 14px;
  margin-bottom: 16px;
  background: #f7f9ff;
  border: 1px dashed #ccd6f6;
  border-radius: var(--radius-sm);
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.status-on { color: var(--good); font-weight: 600; }
.status-off { color: var(--text-muted); font-weight: 600; }
.row-actions { white-space: nowrap; }
.link-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 6px;
}
.link-btn:hover:not(:disabled) { background: var(--primary-soft); }
.link-btn.danger { color: var(--accent); }
.link-btn.danger:hover:not(:disabled) { background: var(--accent-soft); }
.link-btn:disabled { color: #c3c7d4; cursor: default; }
.ua-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
