:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e9ebef;
  --line-soft: #f1f3f6;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #9099a8;
  --brand: #fe2c55;
  --brand-soft: #fff1f4;
  --up: #e8294a;
  --down: #0e9f6e;
  --gold: #f5a623;
  --silver: #9aa5b1;
  --bronze: #c9825b;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 8px 24px -12px rgba(16, 24, 40, 0.12);
}

* { box-sizing: border-box; }

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

h1, h2, h3, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ------------------------------- 顶栏 ------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 28px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-text { min-width: 0; }

.logo {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(135deg, #fe2c55 0%, #ff5f7e 55%, #25f4ee 140%);
  box-shadow: 0 6px 16px -6px rgba(254, 44, 85, 0.7);
}

.brand-text h1 {
  font-size: 16.5px; font-weight: 700; letter-spacing: -0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-text p { font-size: 12px; color: var(--muted); margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.conn {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-2);
  padding: 6px 11px; border-radius: 999px;
  background: #f6f7f9; border: 1px solid var(--line);
}
.pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); flex: 0 0 auto;
}
.conn.on .pulse { background: var(--down); box-shadow: 0 0 0 0 rgba(14, 159, 110, 0.5); animation: pulse 2s infinite; }
.conn.busy .pulse { background: var(--gold); animation: pulse 1.2s infinite; }
.conn.off .pulse { background: var(--brand); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(14, 159, 110, 0.45); }
  70% { box-shadow: 0 0 0 7px rgba(14, 159, 110, 0); }
  100% { box-shadow: 0 0 0 0 rgba(14, 159, 110, 0); }
}

.countdown { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.countdown b { color: var(--text-2); font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 13px;
  border-radius: 9px; border: 1px solid transparent;
  font-size: 13px; font-weight: 500;
  text-decoration: none; color: var(--text-2);
  background: #fff;
  transition: all 0.16s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 4px 12px -6px rgba(254, 44, 85, 0.8); }
.btn-primary:hover { background: #e62248; }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover { background: #fafbfc; border-color: #d9dde3; }
.badge {
  min-width: 18px; height: 18px; padding: 0 5px;
  display: inline-grid; place-items: center;
  border-radius: 999px; background: var(--brand-soft);
  color: var(--brand); font-size: 11px; font-weight: 700;
}

main { max-width: 1360px; margin: 0 auto; padding: 22px 28px 40px; }

/* ------------------------------- KPI ------------------------------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; letter-spacing: 0.2px; }
.kpi-value {
  margin-top: 8px;
  font-size: 27px; font-weight: 700;
  letter-spacing: -0.8px;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: baseline; gap: 5px;
  line-height: 1.15;
}
.kpi-value.accent { color: var(--brand); }
.kpi-value.name { font-size: 19px; letter-spacing: -0.3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unit { font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.kpi-foot { margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.kpi-foot b { color: var(--text-2); font-weight: 600; }

/* ------------------------------ 工具栏 ------------------------------ */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-bottom: 12px; flex-wrap: wrap;
}
.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  height: 31px; padding: 0 13px;
  border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--text-2);
  font-size: 12.5px; font-weight: 500;
  transition: all 0.15s ease;
}
.chip:hover { border-color: #d5d9e0; }
.chip.active { background: #111827; border-color: #111827; color: #fff; }

.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.search {
  display: flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 11px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  color: var(--muted);
  transition: border-color 0.15s ease;
}
.search:focus-within { border-color: #c9ced8; }
.search input {
  border: 0; outline: 0; background: transparent;
  font-size: 13px; color: var(--text); width: 190px;
}
select {
  height: 34px; padding: 0 9px;
  border-radius: 9px; border: 1px solid var(--line);
  background: #fff; color: var(--text-2); font-size: 13px;
  outline: none;
}

/* ------------------------------- 榜单 ------------------------------- */
.board {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board-head, .row {
  display: grid;
  grid-template-columns: 46px minmax(200px, 1fr) 92px 108px 96px 108px 54px;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
}

.board-head {
  height: 40px;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
  background: #fbfcfd;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.3px;
}
.c-online, .c-delta, .c-total { text-align: right; }
.c-trend { text-align: center; }
.c-act { text-align: right; }

.rows { min-height: 120px; }

.row {
  height: 66px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 0.12s ease;
  cursor: pointer;
  animation: rowIn 0.28s ease both;
}
@keyframes rowIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #fcfcfd; }
.row.offline { opacity: 0.62; }

.rank {
  font-size: 15px; font-weight: 700;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 8px;
}
.rank.r1 { background: linear-gradient(135deg, #ffd76e, #f5a623); color: #fff; box-shadow: 0 3px 8px -3px rgba(245, 166, 35, 0.9); }
.rank.r2 { background: linear-gradient(135deg, #cfd6df, #9aa5b1); color: #fff; }
.rank.r3 { background: linear-gradient(135deg, #e0a582, #c9825b); color: #fff; }

.anchor { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  object-fit: cover; flex: 0 0 auto;
  background: #eef0f3;
  border: 1px solid var(--line);
}
.anchor-meta { min-width: 0; }
.anchor-name {
  font-size: 13.5px; font-weight: 600;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.anchor-title {
  font-size: 11.5px; color: var(--muted);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
.tag {
  flex: 0 0 auto;
  font-size: 10px; font-weight: 600;
  padding: 1px 5px; border-radius: 4px;
  background: var(--brand-soft); color: var(--brand);
}
.tag.new { background: #eefbf3; color: var(--down); }
.tag.kw { background: #eef2ff; color: #4c6ef5; }
.tag.off { background: #f3f4f6; color: var(--muted); }

.total {
  text-align: right;
  font-size: 12.5px; color: var(--text-2);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

.online {
  text-align: right;
  font-size: 19px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
}
.online small { font-size: 11px; font-weight: 500; color: var(--muted); margin-left: 2px; letter-spacing: 0; }

.delta {
  text-align: right;
  font-size: 12.5px; font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: flex; align-items: center; justify-content: flex-end; gap: 3px;
}
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--muted); font-weight: 500; }

.spark { display: block; margin: 0 auto; }

.act { display: flex; justify-content: flex-end; gap: 4px; }
.icon-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 7px; border: 1px solid transparent;
  background: transparent; color: var(--muted);
  font-size: 13px; line-height: 1;
  transition: all 0.14s ease;
}
.icon-btn:hover { background: #f4f5f7; color: var(--text); }
.icon-btn.starred { color: var(--gold); }

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

.foot {
  display: flex; justify-content: space-between; gap: 16px;
  margin-top: 14px; padding: 0 4px;
  font-size: 11.5px; color: var(--muted);
  flex-wrap: wrap;
}
.foot b { color: var(--text-2); }
.foot code {
  background: #eceef2; padding: 1px 4px; border-radius: 4px;
  font-size: 10.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.err { color: var(--brand); max-width: 60%; text-align: right; }

/* ------------------------------ 抽屉 ------------------------------ */
.drawer-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(17, 24, 39, 0.28);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  backdrop-filter: blur(2px);
}
.drawer-mask.show { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 50;
  width: 400px; max-width: 92vw;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px -30px rgba(16, 24, 40, 0.3);
  transform: translateX(102%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex; flex-direction: column;
  padding: 20px 20px 28px;
  overflow-y: auto;
}
.drawer.show { transform: none; }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.drawer-head h2 { font-size: 16px; font-weight: 700; }
.drawer-desc { font-size: 12px; color: var(--muted); line-height: 1.6; margin-bottom: 14px; }

.add-box { display: flex; gap: 7px; align-items: flex-start; }
.add-box input {
  flex: 1; height: 36px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; outline: none;
}
.add-box textarea {
  flex: 1; padding: 8px 11px;
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 13px; outline: none; resize: vertical;
  min-height: 38px; max-height: 120px;
  font-family: inherit; line-height: 1.5;
}
.add-box input:focus, .add-box textarea:focus { border-color: #c9ced8; }
.add-box .btn { height: 36px; }

.kw-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.kw-item {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 6px 4px 10px;
  border-radius: 999px;
  background: #eef2ff; border: 1px solid #dbe3ff; color: #4c6ef5;
  font-size: 12px; font-weight: 500;
}
.kw-item .kw-del {
  width: 16px; height: 16px; border: 0; border-radius: 50%;
  background: rgba(76, 110, 245, 0.12); color: #4c6ef5;
  font-size: 11px; line-height: 1; padding: 0;
  display: grid; place-items: center;
}
.kw-item .kw-del:hover { background: rgba(76, 110, 245, 0.24); }

.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #dfe3e8; border-radius: 999px; transition: background 0.2s ease;
}
.slider::before {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; transition: transform 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}
.switch input:checked + .slider { background: var(--brand); }
.switch input:checked + .slider::before { transform: translateX(16px); }

.btn-sm { height: 30px; font-size: 12px; padding: 0 10px; margin-top: 10px; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 7px; line-height: 1.5; }
.hint.ok { color: var(--down); }
.hint.bad { color: var(--brand); }

.watch-list { margin-top: 16px; display: flex; flex-direction: column; gap: 6px; }
.watch-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  border: 1px solid var(--line-soft); background: #fcfcfd;
}
.watch-item img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: #eef0f3; }
.watch-item .wi-meta { flex: 1; min-width: 0; }
.watch-item .wi-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.watch-item .wi-sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.watch-item .wi-sub.live { color: var(--up); font-weight: 600; }

.drawer-section { margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--line); }
.drawer-section h3 { font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.row-setting {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 7px 0; font-size: 12.5px; color: var(--text-2);
}

/* 详情 */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.detail-head img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; }
.detail-name { font-size: 15px; font-weight: 700; }
.detail-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.metric-note {
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--text-2);
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 16px;
}
.detail-stat {
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
}
.detail-stat .l { font-size: 11px; color: var(--muted); }
.detail-stat .v { font-size: 19px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; }
.chart-wrap { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.chart-wrap h4 { font-size: 12px; color: var(--muted); font-weight: 500; margin-bottom: 8px; }
canvas { display: block; }
.detail-link { margin-top: 16px; display: inline-flex; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 30px; z-index: 80;
  transform: translate(-50%, 16px);
  background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 10px;
  font-size: 13px; opacity: 0; pointer-events: none;
  transition: all 0.22s ease;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------ 响应式 ------------------------------ */
@media (max-width: 980px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .board-head, .row { grid-template-columns: 40px minmax(150px, 1fr) 100px 92px 48px; }
  .c-total, .c-trend, .total, .spark { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 14px; gap: 10px; flex-wrap: wrap; }
  .brand { flex: 0 0 100%; width: 100%; }
  .brand-text h1 { font-size: 15.5px; }
  .brand-text p { display: none; }
  .topbar-right { flex: 0 0 100%; width: 100%; justify-content: space-between; gap: 8px; flex-wrap: nowrap; }
  .countdown { display: none; }
  .conn { flex: 0 0 auto; }
  .btn { height: 32px; padding: 0 11px; font-size: 12.5px; }

  main { padding: 16px 12px 30px; }
  .kpis { gap: 10px; margin-bottom: 14px; }
  .kpi { padding: 13px 14px; }
  .kpi-value { font-size: 22px; }
  .kpi-value.name { font-size: 16px; }

  .toolbar { gap: 10px; }
  .chips { width: 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: 0 0 auto; }
  .tools { width: 100%; }
  .search { flex: 1; }
  .search input { width: 100%; }
  .tools select { flex: 0 0 auto; }
  .tools .btn { flex: 0 0 auto; }

  .board-head, .row { grid-template-columns: 34px minmax(110px, 1fr) 78px 42px; padding: 0 10px; gap: 8px; }
  .c-delta, .delta { display: none; }
  .online { font-size: 16px; }
  .anchor-title { font-size: 11px; }
  .row { height: 62px; }
  .avatar { width: 34px; height: 34px; }
}
