/* ====== 基础 ====== */
:root {
  --bg: #0b0e14;
  --bg2: #11151f;
  --card: #161b27;
  --card2: #1c2230;
  --border: #252c3d;
  --text: #d8dee9;
  --text2: #8a93a6;
  --text3: #5c6577;
  --green: #2ecc8f;
  --red: #f0506e;
  --yellow: #f5b85f;
  --blue: #5b8def;
  --purple: #9d7bef;
  --cyan: #41c7d4;
  --m1: #5b8def;
  --m2: #f5b85f;
  --m3: #9d7bef;
  --radius: 10px;
  --mono: "SF Mono", "JetBrains Mono", Consolas, monospace;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
a { color: inherit; text-decoration: none; }
b { font-weight: 600; }
.num { font-family: var(--mono); }
.sub-zero { font-size: 0.65em; vertical-align: -0.25em; }

/* ====== 登录 ====== */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 30% 20%, #16203a 0%, var(--bg) 60%);
}
.login-card {
  width: 340px; padding: 40px 36px; text-align: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,.5);
}
.login-logo { font-size: 48px; }
.login-card h1 { font-size: 20px; margin: 12px 0 4px; }
.login-sub { color: var(--text2); font-size: 12px; margin-bottom: 28px; }
.login-card input {
  width: 100%; padding: 11px 14px; margin-bottom: 14px;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 15px; text-align: center; letter-spacing: 4px; outline: none;
}
.login-card input:focus { border-color: var(--blue); }
.login-card button {
  width: 100%; padding: 11px; border: 0; border-radius: 8px;
  background: var(--blue); color: #fff; font-size: 15px; cursor: pointer;
}
.login-card button:hover { filter: brightness(1.1); }
.login-hint { margin-top: 16px; font-size: 11px; color: var(--text3); }

/* ====== 布局 ====== */
.app { display: flex; height: 100vh; }
.sidebar {
  width: 210px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--bg2); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 15px; }
.brand-icon { font-size: 22px; }
.nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 2px; border-radius: 8px;
  color: var(--text2); font-size: 13.5px;
}
.nav a i { font-style: normal; font-size: 16px; width: 20px; text-align: center; }
.nav a:hover { background: var(--card); color: var(--text); }
.nav a.active { background: var(--card2); color: var(--text); box-shadow: inset 2px 0 0 var(--blue); }
.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text2); }
.ws-status { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.logout-btn {
  width: 100%; padding: 7px; background: none; border: 1px solid var(--border);
  border-radius: 6px; color: var(--text2); cursor: pointer; font-size: 12px;
}
.logout-btn:hover { color: var(--red); border-color: var(--red); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  height: 54px; padding: 0 20px; flex-shrink: 0;
  background: var(--bg2); border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 16px; font-size: 12.5px; color: var(--text2); }
.bnb-rate b { color: var(--yellow); font-family: var(--mono); }
.sys-status { display: flex; align-items: center; gap: 6px; }
.clock { font-family: var(--mono); }
.content { flex: 1; overflow-y: auto; padding: 20px; }

/* ====== 通用组件 ====== */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot-green { background: var(--green); }
.dot-red { background: var(--red); }
.dot-yellow { background: var(--yellow); }
.dot-gray { background: var(--text3); }
.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge-sim { background: rgba(245,184,95,.15); color: var(--yellow); border: 1px solid rgba(245,184,95,.35); }
.badge-m1 { background: rgba(91,141,239,.15); color: var(--m1); }
.badge-m2 { background: rgba(245,184,95,.15); color: var(--m2); }
.badge-m3 { background: rgba(157,123,239,.15); color: var(--m3); }
.badge-green { background: rgba(46,204,143,.15); color: var(--green); }
.badge-red { background: rgba(240,80,110,.15); color: var(--red); }
.badge-gray { background: rgba(138,147,166,.15); color: var(--text2); }
.badge-yellow { background: rgba(245,184,95,.15); color: var(--yellow); }
.badge-blue { background: rgba(91,141,239,.15); color: var(--blue); }
.badge-cyan { background: rgba(65,199,212,.15); color: var(--cyan); }

.up { color: var(--green); }
.down { color: var(--red); }
.muted { color: var(--text2); }
.dim { color: var(--text3); }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card-title .more { margin-left: auto; font-size: 12px; color: var(--text2); font-weight: 400; cursor: pointer; }
.card-title .more:hover { color: var(--blue); }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g6 { grid-template-columns: repeat(6, 1fr); }
.span2 { grid-column: span 2; }

/* KPI */
.kpi { padding: 14px 16px; }
.kpi .k-label { font-size: 12px; color: var(--text2); }
.kpi .k-value { font-size: 22px; font-weight: 700; font-family: var(--mono); margin: 2px 0; }
.kpi .k-sub { font-size: 11.5px; color: var(--text3); }

/* 表格 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 10px; white-space: nowrap;
  color: var(--text3); font-weight: 500; font-size: 12px;
  border-bottom: 1px solid var(--border);
}
td { padding: 9px 10px; border-bottom: 1px solid rgba(37,44,61,.5); white-space: nowrap; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(91,141,239,.04); }
tr.clickable { cursor: pointer; }
.ta-r { text-align: right; }
td.ta-r, th.ta-r { text-align: right; }

/* 筛选条 */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.filter-bar .spacer { flex: 1; }
.chip {
  padding: 5px 12px; border-radius: 6px; cursor: pointer; user-select: none;
  background: var(--card); border: 1px solid var(--border); color: var(--text2); font-size: 12.5px;
}
.chip:hover { color: var(--text); }
.chip.active { background: rgba(91,141,239,.15); border-color: var(--blue); color: var(--blue); }
.search-input {
  padding: 6px 12px; background: var(--card); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 12.5px; outline: none; width: 200px;
}
.search-input:focus { border-color: var(--blue); }
select.chip { appearance: none; }

/* 展开行 */
.expand-row td { background: var(--bg2); padding: 12px 16px; white-space: normal; }
.checks-table { font-size: 12px; }
.checks-table td { padding: 5px 10px; font-family: var(--mono); }
.check-pass { color: var(--green); }
.check-fail { color: var(--red); }

/* 钱包卡 */
.wallet-card { position: relative; overflow: hidden; }
.wallet-card .w-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.wallet-card .w-name { font-weight: 600; }
.wallet-card .w-balance { font-size: 24px; font-weight: 700; font-family: var(--mono); }
.wallet-card .w-pnl { font-size: 13px; font-family: var(--mono); margin-bottom: 6px; }
.wallet-card .w-stats { display: flex; gap: 16px; font-size: 11.5px; color: var(--text2); }
.wallet-card .w-spark { position: absolute; right: 0; bottom: 0; width: 45%; height: 56px; opacity: .9; }

/* 漏斗 */
.funnel-row { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; font-size: 12.5px; }
.funnel-row .f-mod { width: 64px; flex-shrink: 0; }
.funnel-steps { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.f-step { background: var(--card2); border-radius: 6px; padding: 4px 10px; text-align: center; }
.f-step b { display: block; font-family: var(--mono); font-size: 15px; }
.f-step span { font-size: 10.5px; color: var(--text3); }
.f-arrow { color: var(--text3); }

/* 时间线 */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: -23px; top: 4px; width: 12px; height: 12px;
  border-radius: 50%; border: 2px solid var(--bg2); background: var(--text3);
}
.tl-dot.green { background: var(--green); } .tl-dot.red { background: var(--red); }
.tl-dot.blue { background: var(--blue); } .tl-dot.yellow { background: var(--yellow); }
.tl-time { font-size: 11px; color: var(--text3); font-family: var(--mono); }
.tl-title { font-weight: 600; font-size: 13px; margin: 1px 0 3px; }
.tl-body { font-size: 12px; color: var(--text2); }

/* 抽屉 */
.drawer-mask { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 560px; max-width: 95vw; z-index: 61;
  background: var(--bg2); border-left: 1px solid var(--border);
  box-shadow: -16px 0 48px rgba(0,0,0,.45);
  display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head {
  display: flex; align-items: center; gap: 10px; padding: 16px 20px;
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 15px;
}
.drawer-close { margin-left: auto; background: none; border: 0; color: var(--text2); font-size: 20px; cursor: pointer; }
.drawer-close:hover { color: var(--text); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }

/* 评分 */
.dims-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dim-item { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
.dim-item .d-name { font-size: 11px; color: var(--text2); }
.dim-item .d-row { display: flex; align-items: baseline; justify-content: space-between; }
.dim-item .d-score { font-family: var(--mono); font-weight: 700; font-size: 16px; }
.dim-item .d-raw { font-family: var(--mono); font-size: 11px; color: var(--text3); }
.score-bar { height: 4px; border-radius: 2px; background: var(--card2); margin-top: 5px; overflow: hidden; }
.score-bar i { display: block; height: 100%; border-radius: 2px; background: var(--blue); }

/* 进度条 */
.hbar { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.hbar .bar { flex: 1; height: 6px; border-radius: 3px; background: var(--card2); overflow: hidden; }
.hbar .bar i { display: block; height: 100%; border-radius: 3px; }

/* 配置 */
.cfg-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.cfg-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.cfg-field label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.cfg-field label .cfg-desc { color: var(--text3); }
.cfg-field input, .cfg-field select {
  width: 100%; padding: 7px 10px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text); font-size: 13px; font-family: var(--mono); outline: none;
}
.cfg-field input:focus { border-color: var(--blue); }
.cfg-field input[disabled] { opacity: .5; cursor: not-allowed; }
.cfg-actions { margin-top: 16px; display: flex; gap: 10px; align-items: center; }
.btn {
  padding: 8px 18px; border: 0; border-radius: 7px; cursor: pointer; font-size: 13px;
  background: var(--blue); color: #fff;
}
.btn:hover { filter: brightness(1.1); }
.btn-ghost { background: none; border: 1px solid var(--border); color: var(--text2); }
.cfg-meta { font-size: 11.5px; color: var(--text3); margin-left: auto; }
.seg-table input { width: 90px; padding: 4px 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 5px; color: var(--text); font-family: var(--mono); font-size: 12px; }
.mini-btn { padding: 3px 10px; font-size: 11.5px; background: none; border: 1px solid var(--border); border-radius: 5px; color: var(--text2); cursor: pointer; }
.mini-btn:hover { color: var(--blue); border-color: var(--blue); }
.cfg-error { color: var(--red); font-size: 12px; }
.rule-block { background: var(--bg2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.rule-block .r-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; font-size: 13px; }
.rule-params { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; font-family: var(--mono); color: var(--text2); }
.rule-params span { background: var(--card); padding: 2px 8px; border-radius: 5px; }

/* 健康 */
.hp-card { display: flex; flex-direction: column; gap: 4px; }
.hp-card .hp-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.hp-card .hp-sub { font-size: 11.5px; color: var(--text3); font-family: var(--mono); }

/* 日志 */
.log-detail { background: var(--bg); border-radius: 6px; padding: 10px 12px; font-family: var(--mono); font-size: 11.5px; color: var(--text2); overflow-x: auto; white-space: pre; }

/* Toast */
.toast-wrap { position: fixed; top: 64px; right: 20px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 16px; background: var(--card2); border: 1px solid var(--border);
  border-left: 3px solid var(--green); border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: toast-in .2s ease-out;
}
.toast.warn { border-left-color: var(--yellow); }
.toast.error { border-left-color: var(--red); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { none; opacity: 1; } }

/* 图表容器 */
.chart { width: 100%; }
.chart-280 { height: 280px; }
.chart-200 { height: 200px; }
.chart-160 { height: 160px; }

/* 空态 */
.empty { padding: 40px; text-align: center; color: var(--text3); font-size: 13px; }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ====== 响应式 ====== */
@media (max-width: 1100px) {
  .g4, .g6 { grid-template-columns: repeat(2, 1fr); }
  .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 70;
    transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; box-shadow: 16px 0 48px rgba(0,0,0,.5); }
  .menu-btn { display: block; }
  .content { padding: 12px; }
  .g2, .g4, .g6 { grid-template-columns: 1fr 1fr; }
  .span2 { grid-column: span 2; }
  .kpi .k-value { font-size: 18px; }
  .hide-sm { display: none; }
  .drawer { width: 100vw; max-width: 100vw; }
  .dims-grid { grid-template-columns: 1fr; }
}
