:root {
  --bg: #0d1117;
  --bg-soft: #151b23;
  --panel: #161c24;
  --panel-2: #1b232d;
  --line: #232c38;
  --line-soft: #1d2530;
  --text: #e6edf3;
  --text-dim: #8b97a6;
  --text-mute: #5d6875;
  --accent: #2f81f7;
  --accent-soft: rgba(47, 129, 247, 0.12);
  --up: #f0554d;      /* 涨：红 */
  --down: #2ea86b;    /* 跌：绿 */
  --warn: #d29922;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f7fa;
    --bg-soft: #ffffff;
    --panel: #ffffff;
    --panel-2: #f8fafc;
    --line: #e3e8ef;
    --line-soft: #eef2f7;
    --text: #1a2230;
    --text-dim: #5c6b7f;
    --text-mute: #8a97a8;
    --accent-soft: rgba(47, 129, 247, 0.1);
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { max-width: 1480px; margin: 0 auto; padding: 0 24px 48px; }

/* ---------------- 顶栏 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 16px 0;
  margin-bottom: 20px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-soft);
}

.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #2f81f7, #6f4ef2);
  color: #fff; font-weight: 700; font-size: 17px;
  display: grid; place-items: center;
}
.brand-text h1 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--text-mute); }

.topbar-controls { display: flex; align-items: flex-end; gap: 18px; flex: 1; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 11px; color: var(--text-mute); font-weight: 500; }

.select, .input {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.select { min-width: 210px; cursor: pointer; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.search { width: 200px; }

.segmented {
  display: inline-flex;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  background: transparent;
  border: 0;
  color: var(--text-dim);
  font-size: 12.5px;
  font-family: inherit;
  padding: 5px 11px;
  border-radius: 5px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--accent); color: #fff; font-weight: 500; }
.segmented.small button { font-size: 12px; padding: 4px 9px; }

.date-custom { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-mute); }

.mode-badge {
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 20px;
  background: rgba(210, 153, 34, .14);
  color: var(--warn);
  border: 1px solid rgba(210, 153, 34, .3);
  white-space: nowrap;
}
.mode-badge.live {
  background: rgba(46, 168, 107, .12);
  color: var(--down);
  border-color: rgba(46, 168, 107, .3);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 7px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--text-mute); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; }
.btn-icon { padding: 7px 9px; }
.btn.full { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------------- 提示 ---------------- */
.banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.7;
}
.banner strong { color: var(--text); }
.banner-icon {
  flex-shrink: 0;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--warn); color: #1a1a1a;
  font-weight: 700; font-size: 11px;
  display: grid; place-items: center;
  margin-top: 2px;
}
.banner-body { flex: 1; }
.banner-close {
  background: none; border: 0; color: var(--text-mute);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 2px;
}
.banner-close:hover { color: var(--text); }

.notice {
  background: rgba(210, 153, 34, .1);
  border: 1px solid rgba(210, 153, 34, .25);
  color: var(--warn);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* ---------------- 指标卡 ---------------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 10px;
  overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.metric-card:hover { border-color: var(--text-mute); transform: translateY(-1px); }

.metric-label { font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 5px; }
.metric-label .hint {
  font-size: 10px; color: var(--text-mute);
  border: 1px solid var(--line); border-radius: 3px; padding: 0 3px; cursor: help;
}
.metric-value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -.5px;
  margin: 6px 0 2px;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: 3px;
}
.metric-value .unit { font-size: 13px; font-weight: 400; color: var(--text-mute); }
.metric-foot { display: flex; align-items: center; gap: 8px; font-size: 11.5px; }
.delta { font-weight: 500; display: inline-flex; align-items: center; gap: 2px; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.delta.flat { color: var(--text-mute); }
.metric-prev { color: var(--text-mute); }

.metric-spark { position: absolute; right: 0; bottom: 0; width: 92px; height: 34px; opacity: .55; }

/* ---------------- 面板 ---------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line-soft);
  flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-sub { margin: 3px 0 0; font-size: 11.5px; color: var(--text-mute); }
.panel-tools { display: flex; align-items: center; gap: 8px; }

.chart { width: 100%; height: 320px; padding: 8px 4px 4px; }

/* ---------------- 表格 ---------------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table thead th {
  position: sticky; top: 0;
  background: var(--panel-2);
  color: var(--text-dim);
  font-weight: 500;
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 11.5px;
}
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text); }
.data-table th.active-sort { color: var(--accent); }
.data-table th.active-sort::after { content: " ↓"; font-size: 10px; }
.data-table th.active-sort.asc::after { content: " ↑"; }
.col-rank { width: 34px; }

.data-table tbody td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-soft);
  color: var(--text);
}
.data-table tbody tr { cursor: pointer; transition: background .1s; }
.data-table tbody tr:hover { background: var(--panel-2); }
.data-table tbody tr.expanded { background: var(--panel-2); }
.data-table tbody tr.top-row .cell-name { color: var(--accent); font-weight: 500; }

.cell-name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-id { font-size: 10.5px; color: var(--text-mute); margin-left: 6px; }

.share-cell { display: flex; align-items: center; gap: 7px; justify-content: flex-end; }
.share-bar { width: 48px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.share-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.rank-badge {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border-radius: 4px;
  font-size: 10.5px; color: var(--text-mute);
  background: var(--panel-2); border: 1px solid var(--line);
}
tr.top-row .rank-badge { border-color: var(--accent); color: var(--accent); }

.data-table tfoot td {
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.data-table tfoot b { color: var(--text); }

.drill-row td { padding: 0 !important; background: var(--bg-soft); }
.drill-box { padding: 12px 16px 4px; }
.drill-title { font-size: 11.5px; color: var(--text-mute); margin-bottom: 6px; }
.drill-chart { height: 130px; width: 100%; }

.empty-row td {
  text-align: center; padding: 40px 12px !important;
  color: var(--text-mute); cursor: default;
}

.skeleton-row td { padding: 11px 12px !important; }
.sk {
  height: 10px; border-radius: 4px;
  background: linear-gradient(90deg, var(--line-soft) 25%, var(--line) 50%, var(--line-soft) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.page-foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  font-size: 11px; color: var(--text-mute);
  padding: 4px 2px;
}

/* ---------------- 抽屉 ---------------- */
.drawer-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
  z-index: 40; backdrop-filter: blur(2px);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 460px; max-width: 94vw;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  z-index: 50;
  display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, .35);
  animation: slideIn .2s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: .6; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.drawer-head h2 { margin: 0; font-size: 15px; }
.drawer-body { padding: 16px 20px 40px; overflow-y: auto; }

.cfg-block { padding: 14px 0; border-bottom: 1px solid var(--line-soft); }
.cfg-block:last-child { border-bottom: 0; }
.cfg-block h3 { margin: 0 0 8px; font-size: 12.5px; font-weight: 600; color: var(--text); }
.cfg-block .muted { font-size: 11.5px; color: var(--text-mute); line-height: 1.65; margin: 0 0 8px; }
.cfg-block .input.full { width: 100%; margin-bottom: 6px; }

.kv-list { margin: 0 0 8px; font-size: 12px; }
.kv-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.kv-list dt { color: var(--text-mute); }
.kv-list dd { margin: 0; color: var(--text); text-align: right; word-break: break-all; }
.kv-list dd.good { color: var(--down); }
.kv-list dd.bad { color: var(--up); }

.steps { margin: 0; padding-left: 18px; font-size: 11.5px; color: var(--text-dim); line-height: 1.85; }
.steps li { margin-bottom: 3px; }

.log-box {
  max-height: 160px; overflow-y: auto;
  font-family: "SF Mono", ui-monospace, monospace;
  font-size: 10.5px; line-height: 1.6;
  color: var(--text-mute);
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: 7px; padding: 8px 10px;
  white-space: pre-wrap;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line);
  color: var(--text); font-size: 12.5px;
  padding: 10px 18px; border-radius: 8px;
  box-shadow: var(--shadow); z-index: 100;
  animation: toastIn .18s ease-out;
}
.toast.err { border-color: rgba(240, 85, 77, .5); color: var(--up); }
.toast.ok { border-color: rgba(46, 168, 107, .5); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; }
}
@media (max-width: 720px) {
  .app { padding: 0 14px 32px; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-value { font-size: 22px; }
  .select { min-width: 160px; }
  .input.search { width: 130px; }
  .chart { height: 260px; }
}
