/* ════════════════════════════════════════════════════════════
   私有AI量化对冲系统 · Web 前端暗色主题
   底色 #0a0e1a / 卡片 #0f1729 / 涨 #26a69a / 跌 #ef5350
   对齐现有 TUI 审美：深蓝黑底、绿涨红跌、信息密度优先
   ════════════════════════════════════════════════════════════ */

:root {
  --bg: #0a0e1a;
  --bg-card: #0f1729;
  --bg-card-hover: #16213a;
  --bg-input: #0c1322;
  --border: #1e2a45;
  --border-light: #2a3a5c;
  --text: #d6deeb;
  --text-dim: #6b7a99;
  --text-bright: #f0f4ff;
  --up: #26a69a;
  --down: #ef5350;
  --flat: #8a94ad;
  --accent: #4f7cff;
  --accent-dim: #2c4380;
  --yellow: #e2b93d;
  --gold: #f0c040;
  /* 状态色板 */
  --status-active-bg:  #1a4d3a;
  --status-active-fg:  #d4f5e9;
  --status-standby-bg: #1a2c5e;
  --status-standby-fg: #c3d6ff;
  --status-retired-bg: #1e2030;
  --status-retired-fg: #8a94ad;
  --status-shadow-bg:  #1a2c5e;
  --status-shadow-fg:  #c3d6ff;
  /* 市场类型色板：现货=青色 合约=橙色 */
  --spot-bg:    rgba(77, 208, 225, 0.14);
  --spot-fg:    #4dd0e1;
  --spot-bdr:   rgba(77, 208, 225, 0.4);
  --futures-bg: rgba(255, 138, 65, 0.14);
  --futures-fg: #ff8a41;
  --futures-bdr:rgba(255, 138, 65, 0.4);
  --topbar-h: 52px;
  --sidebar-w: 168px;
  --radius: 8px;
  --font-mono: "SF Mono", "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: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  /* 流式字号：小屏(≤1023px) 12px / 中屏(1024-1599px) 13px / 大屏(≥1600px) 15px */
  font-size: 12px;
  line-height: 1.5;
}

@media (min-width: 1024px) {
  html, body { font-size: 13px; }
}

@media (min-width: 1600px) {
  html, body { font-size: 15px; }
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ───────────────────── 顶栏 ───────────────────── */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  z-index: 100;
}

.brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand-logo { color: var(--accent); font-size: 18px; }
.brand-name { font-size: 15px; font-weight: 600; color: var(--text-bright); white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-dim); white-space: nowrap; }

.topbar-right { display: flex; align-items: center; gap: 16px; }

.symbol-indicator {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-mono);
}
.symbol-label { font-size: 11px; color: var(--text-dim); }
.symbol-value { font-size: 13px; color: var(--accent); font-weight: 600; }

.account-switch {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.account-btn {
  padding: 5px 16px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.account-btn:hover { color: var(--text); }
.account-btn.active {
  background: var(--accent-dim);
  color: var(--text-bright);
  font-weight: 600;
}

.conn-status { display: flex; align-items: center; gap: 6px; }
.conn-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
}
.conn-dot.on { background: var(--up); box-shadow: 0 0 6px var(--up); }
.conn-dot.off { background: var(--down); box-shadow: 0 0 6px var(--down); }
.conn-text { font-size: 12px; color: var(--text-dim); }

/* ───────────────────── 布局：侧栏 + 主区 ───────────────────── */

.layout { display: flex; padding-top: var(--topbar-h); min-height: 100vh; }

.sidebar {
  position: fixed;
  top: var(--topbar-h); bottom: 0; left: 0;
  width: var(--sidebar-w);
  padding: 12px 8px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  z-index: 90;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-card-hover); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--text-bright);
  font-weight: 600;
}
.nav-icon { width: 18px; text-align: center; font-size: 14px; opacity: 0.85; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 18px 22px 40px;
  min-width: 0;
}

/* ───────────────────── 页面通用 ───────────────────── */

.page-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.page-title { font-size: 18px; font-weight: 600; color: var(--text-bright); }
.page-meta { font-size: 12px; color: var(--text-dim); }

.page-loading {
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.page-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 60px 20px;
  text-align: center;
}
.page-error-icon { font-size: 36px; color: var(--yellow); }
.page-error-title { font-size: 16px; font-weight: 600; color: var(--text-bright); }
.page-error-detail { font-size: 12px; color: var(--text-dim); max-width: 480px; word-break: break-all; }

.error-banner {
  margin-bottom: 12px;
  padding: 8px 14px;
  background: rgba(239, 83, 80, 0.12);
  border: 1px solid rgba(239, 83, 80, 0.4);
  border-radius: var(--radius);
  color: #ff8a87;
  font-size: 12px;
}
.hidden { display: none !important; }

.empty-hint {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.btn {
  padding: 6px 18px;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--accent); }

.dim { color: var(--text-dim); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* ───────────────────── 卡片 ───────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 12px;
  letter-spacing: 0.5px;
}

.cards-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.cards-row .card { margin-bottom: 0; }

/* 账户卡片 */
.account-card { position: relative; }
.account-card.account-active { border-color: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent-dim); }

.equity-big {
  font-family: var(--font-mono);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-bright);
}
.equity-big.up { color: var(--up); }
.equity-big.down { color: var(--down); }

.return-line { font-size: 14px; font-weight: 600; margin: 2px 0 12px; }

.metric-row { display: flex; gap: 24px; flex-wrap: wrap; margin-bottom: 10px; }
.metric { display: flex; flex-direction: column; gap: 1px; }
.metric-label { font-size: 11px; color: var(--text-dim); }
.metric-value { font-family: var(--font-mono); font-size: 14px; color: var(--text); }

.util-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
}
.util-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* ───────────────────── 徽章 ───────────────────── */

.status-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.badge-sep { width: 1px; height: 16px; background: var(--border-light); margin: 0 4px; }
.badge-label { font-size: 12px; color: var(--text-dim); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-green  { background: rgba(38, 166, 154, 0.15); color: var(--up); border: 1px solid rgba(38, 166, 154, 0.4); }
.badge-red    { background: rgba(239, 83, 80, 0.15); color: var(--down); border: 1px solid rgba(239, 83, 80, 0.4); }
.badge-yellow { background: rgba(226, 185, 61, 0.15); color: var(--yellow); border: 1px solid rgba(226, 185, 61, 0.4); }
.badge-blue   { background: rgba(79, 124, 255, 0.15); color: var(--accent); border: 1px solid rgba(79, 124, 255, 0.4); }
.badge-gray   { background: rgba(138, 148, 173, 0.12); color: var(--flat); border: 1px solid rgba(138, 148, 173, 0.35); }

/* 袖徽章（持仓分组着色） */
.sleeve-badge {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 600;
}
.sleeve-ai     { background: rgba(171, 130, 255, 0.15); color: #ab82ff; border: 1px solid rgba(171, 130, 255, 0.4); }
.sleeve-mech   { background: rgba(79, 124, 255, 0.15); color: var(--accent); border: 1px solid rgba(79, 124, 255, 0.4); }
.sleeve-shadow { background: rgba(138, 148, 173, 0.12); color: var(--flat); border: 1px solid rgba(138, 148, 173, 0.35); }
.sleeve-none   { background: rgba(138, 148, 173, 0.08); color: var(--text-dim); border: 1px solid var(--border); }
.sleeve-x0 { background: rgba(38, 166, 154, 0.13); color: var(--up); border: 1px solid rgba(38, 166, 154, 0.35); }
.sleeve-x1 { background: rgba(226, 185, 61, 0.13); color: var(--yellow); border: 1px solid rgba(226, 185, 61, 0.35); }
.sleeve-x2 { background: rgba(255, 138, 101, 0.13); color: #ff8a65; border: 1px solid rgba(255, 138, 101, 0.35); }
.sleeve-x3 { background: rgba(77, 208, 225, 0.13); color: #4dd0e1; border: 1px solid rgba(77, 208, 225, 0.35); }

/* 等级徽章（机会池） */
.grade-badge {
  display: inline-block;
  min-width: 26px;
  text-align: center;
  padding: 1px 8px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
}
.grade-s { background: rgba(240, 192, 64, 0.18); color: var(--gold); border: 1px solid rgba(240, 192, 64, 0.5); }
.grade-a { background: rgba(38, 166, 154, 0.15); color: var(--up); border: 1px solid rgba(38, 166, 154, 0.4); }
.grade-b { background: rgba(79, 124, 255, 0.15); color: var(--accent); border: 1px solid rgba(79, 124, 255, 0.4); }
.grade-c { background: rgba(138, 148, 173, 0.12); color: var(--flat); border: 1px solid rgba(138, 148, 173, 0.35); }
.grade-d { background: rgba(239, 83, 80, 0.15); color: var(--down); border: 1px solid rgba(239, 83, 80, 0.4); }

/* ───────────────────── 数据表格 ───────────────────── */

.table-scroll { overflow: auto; max-height: 420px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  z-index: 1;
}
.data-table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table tbody tr:hover { background: var(--bg-card-hover); }
.data-table .num { text-align: right; font-family: var(--font-mono); }
.data-table .sym { font-family: var(--font-mono); font-weight: 600; color: var(--text-bright); }

/* ───────────────────── 机会池专属 ───────────────────── */

.pool-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.pool-hint { font-size: 12px; }

.search-input {
  flex: 0 1 280px;
  padding: 7px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); }

.pool-scroll { max-height: calc(100vh - 280px); min-height: 320px; }

.pool-row { cursor: pointer; }
.pool-row.row-selected {
  background: rgba(79, 124, 255, 0.1);
  box-shadow: inset 3px 0 0 var(--accent);
}

.held-dot {
  color: var(--gold);
  margin-left: 5px;
  font-size: 10px;
  vertical-align: middle;
}

.judgement {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  padding: 9px 20px;
  background: var(--bg-card-hover);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  color: var(--text-bright);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ───────────────────── 报告页（reports.js：回测中心/复盘/因子/情报/任务） ───────────────────── */

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

.badge.green { background: rgba(38, 166, 154, 0.15); color: var(--up); border: 1px solid rgba(38, 166, 154, 0.4); }
.badge.red   { background: rgba(239, 83, 80, 0.15); color: var(--down); border: 1px solid rgba(239, 83, 80, 0.4); }
.badge.blue  { background: rgba(79, 124, 255, 0.15); color: var(--accent); border: 1px solid rgba(79, 124, 255, 0.4); }
.badge:not(.green):not(.red):not(.blue):not([class*="badge-"]) {
  background: rgba(138, 148, 173, 0.12);
  color: var(--flat);
  border: 1px solid rgba(138, 148, 173, 0.35);
}

.page { min-width: 0; }
.sub-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin: 4px 0 8px;
  letter-spacing: 0.5px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.card-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.card-header .card-title { margin-bottom: 0; }
.card-subtitle { font-size: 12px; color: var(--text-dim); }
.card-body { min-width: 0; }

.table-wrap { overflow: auto; max-height: 480px; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
  z-index: 1;
}
.table thead th.sortable { cursor: pointer; user-select: none; }
.table thead th.sortable:hover { color: var(--text); }
.table tbody td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--bg-card-hover); }
.table tbody tr.row-hit { box-shadow: inset 3px 0 0 var(--up); }
.table tbody tr.row-miss { box-shadow: inset 3px 0 0 var(--down); }

.placeholder {
  padding: 24px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.placeholder.error { color: var(--down); }

.champion-line {
  margin-top: 12px;
  padding: 8px 12px;
  background: rgba(240, 192, 64, 0.08);
  border: 1px solid rgba(240, 192, 64, 0.35);
  border-radius: var(--radius);
  font-size: 13px;
}

.summary-flex {
  display: flex;
  align-items: center;
  gap: 32px;
  flex-wrap: wrap;
}
.big-number-block { display: flex; flex-direction: column; gap: 2px; }
.big-number {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 700;
  color: var(--text-bright);
}
.big-number.green { color: var(--up); }
.big-number.red { color: var(--down); }
.summary-stats { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 7px;
  font-size: 12px;
}
.bar-label {
  flex: 0 0 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}
.bar-track {
  flex: 1;
  height: 10px;
  background: var(--bg-input);
  border-radius: 5px;
  overflow: hidden;
}
.bar-fill { height: 100%; background: var(--accent); border-radius: 5px; transition: width 0.3s; }
.bar-fill.red { background: var(--down); opacity: 0.75; }
.bar-fill.green { background: var(--up); opacity: 0.75; }
.bar-count { flex: 0 0 36px; text-align: right; font-family: var(--font-mono); }

.footnote { margin-top: 4px; font-size: 12px; }

.dot { font-size: 10px; vertical-align: middle; }
.dot.green { color: var(--up); }
.dot.red { color: var(--down); }
.dot.blue { color: var(--accent); }
.dot.gray { color: var(--flat); }
.dot.yellow { color: var(--yellow); }

/* 任务页（需求6）：运行中绿色脉冲点 + 最近失败行底色 */
@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}
.dot.pulse { animation: dot-pulse 1.2s ease-in-out infinite; }
.table tbody tr.row-failed td { background: rgba(239, 83, 80, 0.07); }

/* 因子资产库（需求4）：族分组头行可点折叠 */
.fam-row td {
  background: rgba(79, 124, 255, 0.07);
  cursor: pointer;
  user-select: none;
}
.fam-row:hover td { background: rgba(79, 124, 255, 0.13); }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ───────────────────── 响应式（iPad / 窄屏） ───────────────────── */

@media (max-width: 1024px) {
  :root { --sidebar-w: 56px; }
  .nav-label { display: none; }
  .nav-item { justify-content: center; padding: 11px 0; }
  .nav-icon { width: auto; font-size: 17px; }
  .brand-sub { display: none; }
  .main { padding: 14px 14px 32px; }
}

@media (max-width: 820px) {
  .cards-row { grid-template-columns: 1fr; }
  .symbol-indicator { display: none; }
  .equity-big { font-size: 26px; }
  .topbar { padding: 0 10px; }
  .topbar-right { gap: 8px; }
  .judgement { max-width: 160px; }
}

/* ═══════════════════════════════════════════════════════
   TUI 综合仪表盘（dashboard.js）
   ═══════════════════════════════════════════════════════ */

/* 主网格：左栏 260px | 中栏 K线 flex | 右栏盘口 220px */
.db-layout {
  display: grid;
  grid-template-columns: 260px 1fr 220px;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "left mid right"
    "bottom bottom bottom";
  gap: 10px;
  height: calc(100vh - var(--topbar-h) - 36px);
  min-height: 560px;
}

.db-col-left   { grid-area: left;   display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.db-col-mid    { grid-area: mid;    display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 10px; }
.db-col-right  { grid-area: right;  display: flex; flex-direction: column; gap: 6px; padding: 10px; overflow-y: auto; min-width: 0; }
.db-col-bottom { grid-area: bottom; display: grid; grid-template-columns: 1fr 240px; gap: 10px; max-height: 200px; }

/* 左栏：账户卡 */
.db-acct-card  { flex: 0 0 auto; padding: 12px; margin-bottom: 0; }
.db-acct-title { font-size: 13px; font-weight: 600; color: var(--text-dim); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: baseline; }
.db-acct-updated { font-size: 11px; }
.db-acct-equity { font-family: var(--font-mono); font-size: 28px; font-weight: 700; color: var(--text-bright); }
.db-acct-equity.up { color: var(--up); }
.db-acct-equity.down { color: var(--down); }
.db-acct-ret { font-size: 13px; font-weight: 600; margin: 2px 0 10px; }
.db-acct-empty { padding: 16px 0; color: var(--text-dim); font-size: 12px; }
.db-metrics { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.db-metric { display: flex; flex-direction: column; gap: 1px; }
.db-metric-label { font-size: 10px; color: var(--text-dim); }
.db-metric-value { font-family: var(--font-mono); font-size: 13px; color: var(--text); }

/* 左栏：徽章条 */
.db-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.db-badge-sep { width: 1px; height: 16px; background: var(--border-light); margin: 0 2px; align-self: center; }

/* 左栏：持仓卡 */
.db-pos-card { flex: 1 1 0; overflow: hidden; display: flex; flex-direction: column; padding: 10px; margin-bottom: 0; }
.db-pos-card .card-title { margin-bottom: 8px; }
.db-pos-scroll { flex: 1; overflow-y: auto; }
.db-pos-scroll .data-table { font-size: 12px; }
.db-pos-scroll .data-table thead th { font-size: 10px; padding: 5px 8px; }
.db-pos-scroll .data-table tbody td { padding: 5px 8px; }
.db-pos-row { cursor: pointer; transition: background 0.12s; }
.db-pos-row:hover { background: var(--bg-card-hover); }
.db-empty { padding: 12px; text-align: center; color: var(--text-dim); font-size: 12px; }

/* 中栏：K线工具栏 */
.db-kl-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  flex-shrink: 0;
}
.db-kl-symbol {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 12px;
  min-width: 140px;
}
.db-kl-ivs { display: flex; gap: 4px; }
.db-kl-iv {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
}
.db-kl-iv.active {
  background: var(--up);
  color: #0a0e1a;
  border-color: var(--up);
  font-weight: 600;
}
.db-kl-legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--text-dim);
  flex: 1;
  min-width: 0;
}
.db-kl-legend b   { font-weight: 600; color: var(--text); }
.db-kl-legend .up { color: var(--up); }
.db-kl-legend .down { color: var(--down); }
.db-kl-sym { color: var(--text-bright); font-weight: 700; }

.db-kl-chart { flex: 1; min-height: 0; }
.db-kl-error {
  font-size: 11px;
  color: var(--down);
  padding: 4px 0;
  flex-shrink: 0;
}

/* 右栏：盘口 */
.db-ob-header { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
.db-ob-mid { font-size: 20px; font-weight: 700; font-family: var(--font-mono); color: var(--text-bright); }
.db-ob-mid.up   { color: var(--up); }
.db-ob-mid.down { color: var(--down); }
.db-ob-spread { font-size: 11px; }

.db-ob-press { flex-shrink: 0; }
.db-ob-press-track {
  height: 8px;
  border-radius: 4px;
  background: rgba(239, 83, 80, 0.25);
  overflow: hidden;
  margin-bottom: 3px;
}
.db-ob-press-fill { height: 100%; background: var(--up); opacity: 0.65; transition: width 0.3s; }
.db-ob-press-label { font-size: 11px; }

.db-ob-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; flex-shrink: 0; }
.db-ob-col-head { font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.db-ob-col-head.up   { color: var(--up); }
.db-ob-col-head.down { color: var(--down); }

.db-ob-row {
  position: relative;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 4px;
  font-size: 11px;
  padding: 2px 4px;
  font-family: var(--font-mono);
  line-height: 1.6;
}
.db-ob-bar {
  position: absolute;
  top: 1px; bottom: 1px;
  width: 0;
  border-radius: 2px;
  transition: width 0.2s;
}
.db-ob-bids .db-ob-bar { left: 0; background: rgba(38, 166, 154, 0.2); }
.db-ob-asks .db-ob-bar { right: 0; background: rgba(239, 83, 80, 0.2); }
.db-ob-bids .db-ob-price { color: var(--up); font-weight: 600; }
.db-ob-asks .db-ob-price { color: var(--down); font-weight: 600; }
.db-ob-price, .db-ob-qty { position: relative; z-index: 1; }
.db-ob-qty { text-align: right; color: var(--text-dim); }

.db-ob-flow { flex: 1; min-height: 0; overflow-y: auto; }
.db-ob-flow-title { font-size: 11px; margin-bottom: 4px; }
.db-ob-flow-row { display: grid; grid-template-columns: auto auto auto auto auto auto auto auto; gap: 4px; font-size: 11px; align-items: center; }
.db-ob-src { font-size: 10px; flex-shrink: 0; }

/* 底栏 */
.db-trades-card { margin-bottom: 0; overflow: hidden; display: flex; flex-direction: column; padding: 10px; }
.db-trades-card .card-title { margin-bottom: 6px; flex-shrink: 0; }
#db-trades { flex: 1; overflow-y: auto; }
#db-trades .data-table { font-size: 12px; }
#db-trades .data-table thead th,
#db-trades .data-table tbody td { padding: 5px 8px; }

.db-tasks-mini { margin-bottom: 0; padding: 10px; overflow: hidden; }
.db-tasks-mini .card-title { margin-bottom: 6px; }
.db-task-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 6px;
  font-size: 11px;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.db-task-row:last-child { border-bottom: none; }
.db-task-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.db-task-ts { color: var(--text-dim); white-space: nowrap; }

/* ── 响应式：iPad 竖屏（≤1024px） ── */
@media (max-width: 1024px) {
  .db-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "left right"
      "mid mid"
      "bottom bottom";
    height: auto;
    min-height: 0;
  }
  .db-col-mid { height: 340px; }
  .db-col-bottom { grid-template-columns: 1fr; max-height: none; }
  .db-tasks-mini { display: none; }
}

/* ── 响应式：手机（≤640px） ── */
@media (max-width: 640px) {
  .db-layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      "left"
      "mid"
      "right"
      "bottom";
  }
  .db-col-right { max-height: 320px; }
}

/* ───────────────────── 总账户汇总条（overview.js / dashboard.js） ───────────────────── */

.total-summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  padding: 10px 16px;
  margin-bottom: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  align-items: center;
}
.total-summary-item { display: flex; flex-direction: column; gap: 2px; }
.total-summary-label { font-size: 11px; color: var(--text-dim); }
.total-summary-value { font-size: 16px; font-weight: 700; font-family: var(--font-mono); color: var(--text-bright); }
.total-summary-desc { font-size: 13px; font-family: var(--font-mono); }

/* dashboard 内嵌总条 */
.db-total-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: rgba(79, 124, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.db-total-item { display: flex; align-items: center; gap: 5px; }
.db-total-sleeve { opacity: 0.8; }

/* ───────────────────── 复盘/因子/情报额外区块 ───────────────────── */

/* 生命周期网格 */
.lifecycle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
  padding: 4px 0;
}
.lc-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.lc-item .muted { font-size: 11px; }

/* 条形分布图 */
.bar-row {
  display: grid;
  grid-template-columns: 160px 1fr 36px;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.bar-label {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.bar-track {
  height: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 6px;
  opacity: 0.75;
}
.bar-fill.red { background: var(--down); }
.bar-fill.green { background: var(--up); }
.bar-count { font-size: 11px; color: var(--text-dim); text-align: right; font-family: var(--font-mono); }

/* 机会池可排序列 */
.sortable-col { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable-col:hover { color: var(--accent); }

/* ═══════════════════════════════════════════════════════
   机会池 TUI 联动布局（pool.js）
   左侧列表 + 右侧 K线/盘口，原地联动不跳页
   ═══════════════════════════════════════════════════════ */

.pool-tui-layout {
  display: grid;
  grid-template-columns: minmax(360px, 45%) 1fr;
  gap: 10px;
  height: calc(100vh - var(--topbar-h) - 80px);
  min-height: 560px;
}

/* 左侧：列表面板 */
.pool-tui-left {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  min-height: 0;
}

.pool-list-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  min-height: 0;
}

/* 右侧：K线 + 盘口，垂直叠放 */
.pool-tui-right {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

/* K线面板 */
.pool-kl-panel {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px;
  overflow: hidden;
}

.pool-kl-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.pool-kl-sym {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text-bright);
  flex-shrink: 0;
}

.pool-kl-ivs {
  display: flex;
  gap: 4px;
}

.pool-enter-btn {
  margin-left: auto;
  padding: 4px 12px;
  font-size: 12px;
  flex-shrink: 0;
}

.pool-kl-chart {
  flex: 1;
  min-height: 0;
  position: relative;
}

/* 盘口面板 */
.pool-ob-panel {
  flex: 0 0 auto;
  max-height: 320px;
  overflow-y: auto;
  padding: 10px;
}

/* 响应式：窄屏右侧下移堆叠 */
@media (max-width: 1024px) {
  .pool-tui-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  .pool-tui-left {
    max-height: 40vh;
    min-height: 240px;
  }
  .pool-kl-panel {
    height: 320px;
    flex: none;
  }
  .pool-ob-panel {
    max-height: 280px;
  }
}

/* ═══════════════════════════════════════════════════════
   全站实时动态化：数值变化闪烁（TUI 感的关键）
   patchDOM 增量更新时给变化的叶子节点加一次性动画：
   涨→绿闪 / 跌→红闪 / 非数值变化→中性微闪
   ═══════════════════════════════════════════════════════ */

@keyframes flash-up {
  0%   { background-color: rgba(38, 166, 154, 0.38); }
  100% { background-color: transparent; }
}
@keyframes flash-down {
  0%   { background-color: rgba(239, 83, 80, 0.38); }
  100% { background-color: transparent; }
}
@keyframes flash-flat {
  0%   { background-color: rgba(110, 130, 170, 0.22); }
  100% { background-color: transparent; }
}
.flash-up   { animation: flash-up   0.9s ease-out; border-radius: 2px; }
.flash-down { animation: flash-down 0.9s ease-out; border-radius: 2px; }
.flash-flat { animation: flash-flat 0.9s ease-out; border-radius: 2px; }

/* 用户偏好减弱动效时禁用闪烁 */
@media (prefers-reduced-motion: reduce) {
  .flash-up, .flash-down, .flash-flat { animation: none; }
}

/* ═══════════════ 资金页（account.js） ═══════════════ */

.acct-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1100px) { .acct-grid { grid-template-columns: 1fr; } }

.acct-col { min-width: 0; }
.acct-updated { font-size: 11px; font-weight: 400; }

/* 资金卡：每信息点独立行 */
.acct-summary-list { display: flex; flex-direction: column; }
.acct-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 6px 2px;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.acct-summary-row:last-child { border-bottom: none; }
.acct-summary-label { color: var(--text-dim); font-size: 12px; }
.acct-summary-value { font-family: var(--font-mono); font-size: 14px; }
.acct-equity-row .acct-summary-value { font-size: 19px; font-weight: 700; }

/* 持仓/成交行可点击 */
.acct-pos-row, .acct-trade-row { cursor: pointer; }

.acct-table-scroll { overflow-x: auto; }
.acct-model-id {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* 历史成交分页条 */
.acct-pager {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  padding: 8px 2px 0;
  font-size: 12px;
  color: var(--text-dim);
}
.acct-pager .btn { padding: 2px 10px; font-size: 12px; }
.acct-pager .btn:disabled { opacity: 0.4; cursor: default; }

/* ═══════════════ 资金页统一排版修复 ═══════════════ */

/* 两列等宽卡片：现货/合约各一列，列内4卡片垂直对齐 */
.acct-grid {
  align-items: start;
}
.acct-col .card {
  /* 等宽：同一列所有卡片100%撑满列宽 */
  width: 100%;
  box-sizing: border-box;
}
/* 表格列宽一致：数字列右对齐+固定宽度 */
.acct-col .data-table th,
.acct-col .data-table td {
  padding: 7px 10px;
}
/* 资金卡数据行间距网格化 */
.acct-summary-row {
  padding: 7px 4px;
  gap: 16px;
}

/* ═══════════════ 策略状态/类型胶囊徽章 ═══════════════ */

/* 胶囊基础：比普通 badge 更圆更填充感 */
.badge-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.6;
}

/* 现役：绿底白字 */
.badge-status-active {
  background: var(--status-active-bg);
  color: var(--status-active-fg);
  border-color: rgba(38, 166, 154, 0.5);
}
/* 候补：蓝底浅蓝字 */
.badge-status-standby {
  background: var(--status-standby-bg);
  color: var(--status-standby-fg);
  border-color: rgba(79, 124, 255, 0.4);
}
/* 退役：暗灰 */
.badge-status-retired {
  background: var(--status-retired-bg);
  color: var(--status-retired-fg);
  border-color: rgba(138, 148, 173, 0.3);
}
/* 影子：蓝 */
.badge-status-shadow {
  background: var(--status-shadow-bg);
  color: var(--status-shadow-fg);
  border-color: rgba(79, 124, 255, 0.4);
}

/* 现货胶囊：青色 */
.badge-spot-type {
  background: var(--spot-bg);
  color: var(--spot-fg);
  border-color: var(--spot-bdr);
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--spot-bdr);
  line-height: 1.6;
}
/* 合约胶囊：橙色 */
.badge-futures-type {
  background: var(--futures-bg);
  color: var(--futures-fg);
  border-color: var(--futures-bdr);
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--futures-bdr);
  line-height: 1.6;
}

/* ═══════════════ 回测中心布局（手动回测+日志面板） ═══════════════ */

/* 表单行：紧凑单行排列 */
.bt-form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 0 8px;
}

/* 日志面板：主体高度，等宽字体，强视觉存在感 */
.bt-log-wrap {
  margin-top: 10px;
}
.bt-log {
  display: block;
  background: #05070f;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  /* 占页面约 60% 高度 */
  min-height: 55vh;
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: clamp(11px, 0.75vw + 0.4rem, 13px);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
  /* 绿色光晕：TUI 终端感 */
  box-shadow: inset 0 0 30px rgba(38, 166, 154, 0.03);
}
/* 日志内容着色（前端关键词映射） */
.bt-log-ok    { color: var(--up); }
.bt-log-err   { color: var(--down); }
.bt-log-warn  { color: var(--yellow); }
.bt-log-info  { color: var(--accent); }

/* ═══════════════ 响应式流式补强 ═══════════════ */

/* 表格小屏横向滚动，不挤压 */
.table-wrap, .table-scroll, .acct-table-scroll {
  overflow-x: auto;
}
.table-wrap table,
.table-scroll table,
.acct-table-scroll table {
  min-width: 480px;
}

/* 大屏升字号 */
@media (min-width: 1600px) {
  .page-title   { font-size: clamp(18px, 1.25vw, 22px); }
  .card-title   { font-size: clamp(13px, 0.9vw, 15px); }
  .data-table, .table { font-size: clamp(13px, 0.85vw, 15px); }
  .metric-value, .db-metric-value { font-size: clamp(13px, 0.9vw, 15px); }
}

/* 小屏降字号，主要区域横向滚动而非挤压 */
@media (max-width: 900px) {
  .main { padding: 12px 10px 28px; }
  .cards-row { grid-template-columns: 1fr; }
  .acct-grid  { grid-template-columns: 1fr; }
  .bt-form-row { flex-direction: column; align-items: flex-start; }
  .bt-log { min-height: 40vh; }
  .db-layout {
    grid-template-columns: 1fr;
    grid-template-areas: "left" "mid" "right" "bottom";
    height: auto;
  }
}
