:root {
  --bg: #0b0e14;
  --bg-elevated: #111622;
  --card: #151b28;
  --card-hover: #1a2233;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #eaecef;
  --text-dim: #848e9c;
  --text-muted: #5e6673;
  --gold: #f0b90b;
  --gold-soft: rgba(240, 185, 11, 0.14);
  --green: #0ecb81;
  --green-soft: rgba(14, 203, 129, 0.14);
  --red: #f6465d;
  --red-soft: rgba(246, 70, 93, 0.14);
  --blue: #3b82f6;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.num, .kpi-value, .data-table td, .kline-readout { font-variant-numeric: tabular-nums; }
.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }
.muted { color: var(--text-dim); }

/* 登录页 */
.login-backdrop {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, rgba(240, 185, 11, 0.09), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(14, 203, 129, 0.07), transparent 45%),
              var(--bg);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 32px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}

.login-brand h1 { font-size: 20px; font-weight: 700; letter-spacing: 0.2px; }
.login-brand p { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f0b90b, #d99b00);
  color: #0b0e14;
  font-weight: 900;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(240, 185, 11, 0.3);
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .input-sm {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus, .input-sm:focus { border-color: var(--gold); }
.input-sm { width: 190px; padding: 6px 10px; font-size: 12px; }

.login-error {
  background: var(--red-soft);
  border: 1px solid rgba(246, 70, 93, 0.35);
  color: #ff8b9b;
  font-size: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

/* 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text);
  background: transparent;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--gold); color: #0b0e14; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline { border-color: var(--border-strong); background: rgba(255, 255, 255, 0.03); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.22); }
.btn-ghost { color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.btn-danger-outline { border-color: rgba(246, 70, 93, 0.45); color: #ff7a8c; background: var(--red-soft); }
.btn-danger-outline:hover { background: var(--red); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* 主布局 */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 22px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.sidebar-brand .brand-logo { width: 36px; height: 36px; font-size: 17px; border-radius: 10px; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--gold); margin-top: 1px; }

.nav-menu { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.nav-item.active {
  background: var(--gold-soft);
  color: var(--gold);
  font-weight: 600;
}
.nav-icon { font-size: 15px; width: 18px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
}
.nav-item.active .nav-badge { background: var(--gold); color: #0b0e14; font-weight: 700; }

.sidebar-footer { padding-top: 14px; border-top: 1px solid var(--border); }
.strategy-pill {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.pill-label { font-size: 11px; color: var(--text-muted); }
.pill-val { font-size: 13px; font-weight: 600; color: var(--text); margin-top: 2px; word-break: break-all; }
.pill-meta { font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* 主内容区 */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left, .topbar-actions { display: flex; align-items: center; gap: 12px; }
.topbar-meta { font-size: 12.5px; color: var(--text-dim); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.status-pill.running { background: var(--green-soft); border-color: rgba(14, 203, 129, 0.35); color: var(--green); }
.status-pill.running .status-dot { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 2s infinite; }
.status-pill.paused { background: var(--gold-soft); border-color: rgba(240, 185, 11, 0.35); color: var(--gold); }
.status-pill.paused .status-dot { background: var(--gold); }
.status-pill.stopped { background: var(--red-soft); border-color: rgba(246, 70, 93, 0.35); color: var(--red); }
.status-pill.stopped .status-dot { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.85); }
}

.content {
  padding: 22px 24px 36px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
}

.tab-panel { display: none; flex-direction: column; gap: 18px; }
.tab-panel.active { display: flex; }

/* KPI 卡片 */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
}
.kpi-card:hover { border-color: var(--border-strong); }
.kpi-card.accent-gold::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
}
.kpi-label { font-size: 12px; color: var(--text-dim); }
.kpi-value { font-size: 26px; font-weight: 700; margin: 8px 0 6px; letter-spacing: -0.3px; }
.kpi-sub { font-size: 12px; color: var(--text-dim); }

/* 通用卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { font-size: 12px; color: var(--text-dim); margin-left: 8px; }

.two-col {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 18px;
}

/* 当前持仓卡片 */
.open-trades-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.trade-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.trade-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.trade-pair { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}
.badge-long { background: var(--green-soft); color: var(--green); }
.badge-short { background: var(--red-soft); color: var(--red); }
.badge-lev { background: var(--gold-soft); color: var(--gold); }
.badge-tag { background: rgba(255, 255, 255, 0.06); color: var(--text-dim); font-weight: 500; }

.trade-pnl { text-align: right; }
.trade-pnl-pct { font-size: 19px; font-weight: 700; }
.trade-pnl-abs { font-size: 12px; margin-top: 1px; }

.trade-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  padding: 10px;
}
.tm-label { font-size: 11px; color: var(--text-muted); }
.tm-val { font-size: 13px; font-weight: 600; margin-top: 2px; font-family: var(--font-mono); }

.sl-bar-wrap { display: flex; flex-direction: column; gap: 4px; }
.sl-bar-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); }
.sl-bar-track {
  height: 6px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  position: relative;
}
.sl-bar-fill { height: 100%; border-radius: 99px; transition: width 0.3s; }

.trade-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* 表格 */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

/* 币对排行 */
.perf-list { display: flex; flex-direction: column; gap: 10px; }
.perf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.perf-pair { font-weight: 600; font-size: 13.5px; }
.perf-count { font-size: 11.5px; color: var(--text-dim); }
.perf-val { font-weight: 700; font-family: var(--font-mono); text-align: right; }

/* 图表容器 */
.chart-box { height: 260px; position: relative; }
.kline-box { height: 470px; position: relative; }
.chart-box canvas, .kline-box canvas { width: 100%; height: 100%; display: block; }

.chart-toolbar { align-items: center; }
.pair-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pair-pill {
  padding: 5px 12px;
  border-radius: 99px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.pair-pill:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.25); }
.pair-pill.active { background: var(--gold); color: #0b0e14; border-color: var(--gold); }

.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-dim); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.gold { background: var(--gold); }
.dot.blue { background: var(--blue); }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }

.kline-readout {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  padding: 6px 10px;
  background: var(--bg-elevated);
  border-radius: 8px;
  margin-bottom: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

/* 白名单与锁定 */
.whitelist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.wl-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color 0.15s;
}
.wl-item:hover { border-color: var(--gold); }
.locks-list { display: flex; flex-direction: column; gap: 8px; }
.lock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
}

/* 日志终端 */
.log-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.checkbox-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); cursor: pointer; }
.logs-terminal {
  background: #080a0f;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  height: 540px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}
.log-line { padding: 2px 0; border-bottom: 1px solid rgba(255, 255, 255, 0.02); word-break: break-all; }
.log-ts { color: var(--text-muted); margin-right: 8px; }
.log-lvl { display: inline-block; width: 64px; font-weight: 700; margin-right: 6px; }
.log-INFO .log-lvl { color: #60a5fa; }
.log-WARNING .log-lvl { color: var(--gold); }
.log-WARNING { background: rgba(240, 185, 11, 0.05); }
.log-ERROR .log-lvl, .log-CRITICAL .log-lvl { color: var(--red); }
.log-ERROR, .log-CRITICAL { background: rgba(246, 70, 93, 0.09); }

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 28px 16px;
  font-size: 13px;
  grid-column: 1 / -1;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #1d2536;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar-brand { border-bottom: none; margin-bottom: 0; padding: 0; }
  .nav-menu { flex-direction: row; overflow-x: auto; }
  .sidebar-footer { display: none; }
}
