/* QuantKing Web UI —— 对齐 New API 控制台视觉（Jinja2 零构建）
 * 设计参考：new-api theme.css 蓝主色 + Public Sans + 双主题 + 圆角卡片
 * 实现原因：只换展示层，保留 .panel/.metric 等旧类名兼容既有模板与 JS 动态 HTML
 */

/* ========== 设计令牌：浅色（new-api 默认语言） ========== */
:root, html.light {
  --radius: 1rem;
  --app-header-height: 3.25rem;
  --sidebar-width: 15rem;
  --sidebar-collapsed: 4rem;

  --background: #ffffff;
  --foreground: #171717;
  --card: #ffffff;
  --card-foreground: #171717;
  --popover: #ffffff;
  --muted: #f5f5f5;
  --muted-foreground: #737373;
  --border: #ebebeb;
  --input: #ebebeb;
  --ring: #3b82f6;

  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-foreground: #ffffff;
  --primary-soft: color-mix(in srgb, var(--primary) 12%, var(--background));

  --secondary: #f5f5f5;
  --secondary-foreground: #404040;

  --sidebar: #fafafa;
  --sidebar-foreground: #171717;
  --sidebar-accent: color-mix(in srgb, var(--primary) 12%, var(--background));
  --sidebar-accent-fg: #1d4ed8;
  --sidebar-border: #ebebeb;

  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.12);
  --destructive: #ef4444;
  --destructive-soft: rgba(239, 68, 68, 0.12);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --info: #0ea5e9;

  --profit: var(--success);
  --loss: var(--destructive);

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.04);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.06);
  --header-bg: color-mix(in srgb, var(--background) 88%, transparent);
  --log-bg: #f8fafc;
  --skeleton-base: #f0f0f0;
  --skeleton-hi: #fafafa;

  /* 兼容旧变量名（模板内联 style 仍引用） */
  --bg-primary: var(--background);
  --bg-secondary: var(--card);
  --bg-tertiary: var(--muted);
  --border-light: color-mix(in srgb, var(--border) 70%, var(--foreground));
  --text-primary: var(--foreground);
  --text-secondary: var(--muted-foreground);
  --text-muted: var(--muted-foreground);
  --accent-blue: var(--primary);
  --accent-cyan: var(--info);
  --accent-yellow: var(--warning);
  --accent-purple: #8b5cf6;
}

/* ========== 设计令牌：深色（OpenAI/new-api charcoal） ========== */
html.dark {
  --background: #1c1c1c;
  --foreground: #f5f5f5;
  --card: #262626;
  --card-foreground: #f5f5f5;
  --popover: #2a2a2a;
  --muted: #2e2e2e;
  --muted-foreground: #a3a3a3;
  --border: rgb(255 255 255 / 0.10);
  --input: rgb(255 255 255 / 0.14);
  --ring: #60a5fa;

  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-foreground: #ffffff;
  --primary-soft: color-mix(in srgb, var(--primary) 20%, var(--background));

  --secondary: #333333;
  --secondary-foreground: #e5e5e5;

  --sidebar: #171717;
  --sidebar-foreground: #f5f5f5;
  --sidebar-accent: color-mix(in srgb, var(--primary) 20%, var(--background));
  --sidebar-accent-fg: #93c5fd;
  --sidebar-border: rgb(255 255 255 / 0.10);

  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --destructive: #f87171;
  --destructive-soft: rgba(248, 113, 113, 0.14);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --info: #38bdf8;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.25);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 0.35);
  --header-bg: color-mix(in srgb, var(--background) 88%, transparent);
  --log-bg: #141414;
  --skeleton-base: #333;
  --skeleton-hi: #404040;

  --bg-primary: var(--background);
  --bg-secondary: var(--card);
  --bg-tertiary: var(--muted);
  --border-light: rgb(255 255 255 / 0.16);
  --text-primary: var(--foreground);
  --text-secondary: var(--muted-foreground);
  --text-muted: var(--muted-foreground);
  --accent-blue: var(--primary);
  --accent-cyan: var(--info);
  --accent-yellow: var(--warning);
  --profit: var(--success);
  --loss: var(--destructive);
}

/* ========== 基础 ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  background: var(--background);
  color: var(--foreground);
  /* 禁用 Google Fonts CDN：系统字体栈，离线/内网可访问 */
  font-family: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace; font-size: 0.9em; }
button:not(:disabled), [role="button"]:not(:disabled) { cursor: pointer; }
button:not(:disabled):active { transform: scale(0.98); }

/* ========== App Shell（顶栏 + 侧栏 + 内容，对齐 AuthenticatedLayout） ========== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--background);
}
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* 顶栏 */
.app-header {
  height: var(--app-header-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  z-index: 40;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.header-brand {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--foreground); text-decoration: none; font-weight: 700; font-size: 15px;
  padding: 4px 6px; border-radius: 10px;
}
.header-brand:hover { background: var(--muted); text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(145deg, var(--primary), #1d4ed8);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800;
}
.header-divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.page-title { font-size: 15px; font-weight: 650; color: var(--foreground); white-space: nowrap; }
.header-metrics {
  display: flex; gap: 6px; flex: 1; min-width: 0; overflow: hidden; justify-content: center;
}
/* 内层 chips 排布容器（base.html 中 .header-metrics 包了一层 .top-chips）
   实现原因：div 默认是块级元素，若不给 flex，会被外层 flex 容器当成单个子项、
   内部 chips 退化成块内左对齐堆积——这正是「PC 顶栏资产区位置不对、不横排」的根因；
   显式 flex 后 chips 才能横向一行排列，并由外层 justify-content:center 居中 */
.top-chips {
  display: flex;
  gap: 6px;
  align-items: stretch;
  flex-wrap: nowrap;   /* 单行横排，超出交给外层 hidden 裁切 */
  min-width: 0;
}
.top-chip, .qk-chip {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 10px;
  min-width: 88px;
  box-shadow: var(--shadow-sm);
}
.top-chip span, .qk-chip span {
  display: block; color: var(--muted-foreground); font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .03em;
}
.top-chip b, .qk-chip b {
  display: block;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: var(--foreground);
}
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.mode-badge {
  padding: 4px 10px; border-radius: 999px; font-weight: 650; font-size: 11px;
  background: var(--warning-soft); color: var(--warning); border: 1px solid transparent;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.clock {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  color: var(--muted-foreground); font-size: 12px; font-variant-numeric: tabular-nums;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  border: 1px solid var(--border); background: var(--card); color: var(--foreground);
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
}
.icon-btn:hover { background: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; flex-shrink: 0; }

/* 侧栏 */
.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column;
  transition: width .18s ease, flex-basis .18s ease;
  overflow: hidden;
}
.app-shell.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed);
  flex-basis: var(--sidebar-collapsed);
}
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed .nav-group-title,
.app-shell.sidebar-collapsed .side-status-text,
.app-shell.sidebar-collapsed .brand-text-side { display: none; }
.app-shell.sidebar-collapsed .nav-item { justify-content: center; padding: 10px; }

.side-nav {
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 14px;
  flex: 1; overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group-title {
  font-size: 11px; font-weight: 650; color: var(--muted-foreground);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 4px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted-foreground); text-decoration: none;
  padding: 9px 12px; border-radius: 10px;
  font-weight: 550; transition: background .12s, color .12s;
}
.nav-item:hover { color: var(--foreground); background: color-mix(in srgb, var(--foreground) 4%, transparent); text-decoration: none; }
.nav-item.active {
  color: var(--sidebar-accent-fg);
  background: var(--sidebar-accent);
  font-weight: 650;
}
.nav-item .nav-ico {
  width: 18px; height: 18px; flex: 0 0 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-item .nav-ico svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75; }
.nav-item.mini { padding: 8px 12px; font-size: 13px; }
.side-bottom {
  padding: 10px; border-top: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; gap: 4px;
}
.status-line {
  color: var(--muted-foreground); font-size: 12px;
  padding: 8px 10px; display: flex; align-items: center; gap: 8px;
}
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.online { background: var(--success); box-shadow: 0 0 8px color-mix(in srgb, var(--success) 60%, transparent); }
.status-dot.offline { background: var(--destructive); }

/* 主内容区 */
.main-shell {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--background);
}
.container {
  flex: 1; overflow-y: auto; padding: 20px 22px 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ========== 卡片 / 面板（.panel 兼容） ========== */
.panel, .card, .qk-card {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 0.9);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s ease, box-shadow .15s ease;
}
@media (min-width: 641px) {
  .panel:hover, .card:hover, .qk-card:hover {
    box-shadow: var(--shadow-md);
  }
}
.panel h2, .card h2, .qk-card h2,
.panel h3, .card h3 {
  font-size: 15px; font-weight: 650; margin-bottom: 12px; color: var(--foreground);
}
.panel-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.panel-title h2 { margin: 0; }
.page-header { margin-bottom: 16px; }
.page-header h2 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.page-header .muted { font-size: 13px; }

/* 指标卡网格（回测/诊断结果区） */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
/* 回测「信号」横条：长策略名横向一行，避免竖卡占半屏 */
.bt-signal-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--muted);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 12px;
  margin-bottom: 12px;
}
.bt-signal-bar .label {
  color: var(--muted-foreground);
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex: 0 0 auto;
}
.bt-signal-bar .value {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 14px;
  font-weight: 600;
  color: var(--foreground);
  line-height: 1.45;
  flex: 1 1 200px;
  word-break: break-word;
}

/* 网格 */
.grid { display: grid; gap: 12px; }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-4, .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }
}
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .panel, .row > .card { flex: 1; min-width: 280px; }

/* 指标卡（.metric 兼容 + .qk-stat） */
.metric, .qk-stat {
  background: var(--muted);
  border: 1px solid var(--border);
  padding: 14px 14px 12px;
  border-radius: 12px;
  position: relative;
  overflow: hidden;
}
.metric .label, .qk-stat .label, .data-label {
  color: var(--muted-foreground);
  font-size: 11px; font-weight: 650;
  text-transform: uppercase; letter-spacing: .04em;
}
.metric .value, .qk-stat .value {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 22px; font-weight: 750; margin-top: 6px;
  font-variant-numeric: tabular-nums;
  color: var(--foreground);
  line-height: 1.2;
}
.metric .sub, .qk-stat .sub {
  color: var(--muted-foreground); font-size: 12px; margin-top: 4px; line-height: 1.45;
}

/* 统计条（new-api LogStatCards 风格） */
.qk-stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--card);
  margin-bottom: 16px;
}
.qk-stat-row > .metric,
.qk-stat-row > .qk-stat {
  border: none; border-radius: 0; background: transparent;
  border-right: 1px solid var(--border);
}
.qk-stat-row > :last-child { border-right: none; }

/* 表格 */
table, .qk-table { width: 100%; border-collapse: collapse; }
/* 表格横向滚动容器（窄窗口防溢出） */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 720px; }
th, td {
  padding: 10px 12px; text-align: left;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
th {
  color: var(--muted-foreground); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  background: color-mix(in srgb, var(--foreground) 2.5%, var(--background));
}
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: color-mix(in srgb, var(--foreground) 3%, transparent); }
td.mono, .mono {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
}

/* 表单控件 */
input, select, textarea {
  background: var(--background);
  border: 1px solid var(--input);
  color: var(--foreground);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
label { color: var(--muted-foreground); font-size: 13px; }

/* 按钮 */
button, .qk-btn {
  background: var(--primary);
  color: var(--primary-foreground);
  border: 1px solid transparent;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 650;
  font-family: inherit;
  transition: background .12s, opacity .12s, transform .1s;
}
button:hover, .qk-btn:hover { background: var(--primary-hover); }
button:disabled, .qk-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.secondary, .qk-btn.ghost, .qk-btn.secondary {
  background: var(--secondary);
  color: var(--secondary-foreground);
  border: 1px solid var(--border);
}
button.secondary:hover, .qk-btn.ghost:hover, .qk-btn.secondary:hover {
  background: var(--muted);
}
button.danger, .qk-btn.danger {
  background: var(--destructive);
  color: #fff;
}
.form-inline {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 14px;
}

/* Badge */
.badge, .qk-badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700;
}
.badge.ok, .qk-badge.ok { background: var(--success-soft); color: var(--success); }
.badge.fail, .qk-badge.fail { background: var(--destructive-soft); color: var(--destructive); }
.badge.warn, .qk-badge.warn { background: var(--warning-soft); color: var(--warning); }

/* 文字色 */
.muted { color: var(--muted-foreground); }
.green { color: var(--profit) !important; }
.red { color: var(--loss) !important; }
.yellow { color: var(--warning) !important; }
.blue { color: var(--primary) !important; }
.orange { color: #e67e22 !important; }
.purple { color: #9b59b6 !important; }

/* 图表 / 日志 / Tab */
.chart-wrap { position: relative; height: 320px; }

/* 回测权益曲线专业布局：主图更高 + 回撤子图 + 摘要条 */
.equity-panel .panel-title { margin-bottom: 10px; }
.equity-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 8px;
  margin: 0 0 14px;
  padding: 10px 12px;
  background: var(--bg-secondary, var(--card));
  border: 1px solid var(--border);
  border-radius: 10px;
}
.equity-stat-cell .label {
  font-size: 11px;
  color: var(--muted-foreground);
  margin-bottom: 2px;
  font-weight: 500;
}
.equity-stat-cell .value {
  font-size: 13px;
  font-weight: 600;
  color: var(--foreground);
  line-height: 1.25;
}
.chart-wrap.equity-main-wrap {
  height: 420px;
  margin-bottom: 4px;
}
.equity-dd-head {
  font-size: 12px;
  font-weight: 600;
  margin: 10px 0 6px;
  letter-spacing: 0.02em;
}
.chart-wrap.equity-dd-wrap {
  height: 160px;
}
@media (max-width: 768px) {
  .chart-wrap.equity-main-wrap { height: 300px; }
  .chart-wrap.equity-dd-wrap { height: 130px; }
  .equity-stats { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}
.log, .qk-log {
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  max-height: 360px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: var(--foreground);
}
.tabbar, .qk-tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tabbar button, .qk-tabs button {
  background: transparent; color: var(--muted-foreground);
  border: none; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 10px 14px; font-weight: 600;
}
.tabbar button:hover, .qk-tabs button:hover { color: var(--foreground); background: transparent; }
.tabbar button.active, .qk-tabs button.active {
  color: var(--foreground); border-bottom-color: var(--primary); background: transparent;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 骨架屏 */
.qk-skeleton {
  background: linear-gradient(90deg, var(--skeleton-base) 0%, var(--skeleton-base) 33%, var(--skeleton-hi) 50%, var(--skeleton-base) 67%, var(--skeleton-base) 100%);
  background-size: 300% 100%;
  animation: skeleton-shimmer 1.8s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: -100% 50%; }
}

/* 登录页 */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, color-mix(in srgb, var(--primary) 18%, transparent), transparent),
    var(--background);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius));
  padding: 32px 28px;
  box-shadow: var(--shadow-md);
}
.login-card .brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  font-size: 22px; font-weight: 750; color: var(--foreground); margin-bottom: 4px;
}
.login-card .brand-mark { width: 36px; height: 36px; font-size: 16px; border-radius: 10px; }
.login-card .login-sub {
  text-align: center; color: var(--muted-foreground); font-size: 13px; margin-bottom: 22px;
}
.login-card input { width: 100%; margin-bottom: 12px; padding: 10px 12px; }
.login-card button[type="submit"] { width: 100%; padding: 10px; margin-top: 4px; }
.login-theme {
  position: fixed; top: 16px; right: 16px;
}

/* ========== K 线（币安风格专业终端） ========== */
.bn-kline { display: flex; flex-direction: column; gap: 0; margin: -4px 0 0; }
.bn-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap; padding: 4px 0 12px;
  border-bottom: 1px solid var(--border);
}
.bn-header-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.bn-symbol-select {
  font-size: 16px; font-weight: 750; padding: 8px 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  color: var(--foreground); cursor: pointer;
}
.bn-price-block { display: flex; flex-direction: column; gap: 2px; }
.bn-last-price {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 28px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1;
  color: var(--foreground);
}
.bn-last-price.up { color: #0ecb81; }
.bn-last-price.down { color: #f6465d; }
.bn-last-change {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 14px; font-weight: 700;
}
.bn-last-change.up { color: #0ecb81; }
.bn-last-change.down { color: #f6465d; }
.bn-stats {
  display: flex; flex-wrap: wrap; gap: 18px 28px; align-items: flex-start;
}
.bn-stat { display: flex; flex-direction: column; gap: 2px; min-width: 72px; }
.bn-stat-l {
  font-size: 11px; color: var(--muted-foreground); font-weight: 600;
  letter-spacing: .02em;
}
.bn-stat-v {
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-size: 13px; font-weight: 650; color: var(--foreground);
  font-variant-numeric: tabular-nums;
}
.bn-stat-v.up { color: #0ecb81; }
.bn-stat-v.down { color: #f6465d; }

.bn-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 0 6px; flex-wrap: wrap;
}
.bn-toolbar-left, .bn-toolbar-right {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.bn-ma-toggles { display: flex; gap: 10px; align-items: center; margin-left: 4px; }
.bn-ma-lab {
  font-size: 12px; font-weight: 650; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; user-select: none;
}
.bn-ma-lab input { accent-color: currentColor; }
.bn-ma-lab.ma7 { color: #f0b90b; }
.bn-ma-lab.ma25 { color: #c744f5; }
.bn-ma-lab.ma99 { color: #0ecb81; }
.bn-tool-btn {
  background: var(--muted); border: 1px solid var(--border); color: var(--muted-foreground);
  padding: 5px 10px; border-radius: 6px; font-size: 12px; font-weight: 650; cursor: pointer;
}
.bn-tool-btn:hover { color: var(--foreground); border-color: var(--primary); }

/* 十字光标信息条 */
.bn-ohlc {
  display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: baseline;
  padding: 6px 2px 8px;
  font-size: 12px;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border);
  min-height: 28px;
}
.bn-ohlc-time { color: var(--muted-foreground); font-weight: 600; margin-right: 4px; }
.bn-ohlc-item { display: inline-flex; gap: 4px; align-items: baseline; }
.bn-ohlc-item i {
  font-style: normal; color: var(--muted-foreground); font-size: 11px; font-weight: 600;
}
.bn-ohlc-item b { font-weight: 700; color: var(--foreground); }
.bn-ohlc-ma { margin-left: auto; display: flex; gap: 10px; font-size: 11px; font-weight: 650; }

.kline-intervals { display: flex; gap: 4px; flex-wrap: wrap; }
.kline-tf {
  background: transparent; border: none; color: var(--muted-foreground);
  padding: 6px 10px; border-radius: 4px; font-size: 13px; font-weight: 650;
  transition: all .12s; cursor: pointer;
}
.kline-tf:hover { color: var(--foreground); background: var(--muted); }
.kline-tf.active { color: #f0b90b; background: transparent; font-weight: 750; }
.kline-tf.disabled { opacity: .35; cursor: not-allowed; }
.kline-hist-info {
  font-size: 11px; max-width: min(240px, 36vw);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--text-muted, #888);
}
.kline-loading { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--warning); }
.kline-loading-dot {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warning); animation: kline-pulse 1s infinite;
}
@keyframes kline-pulse { 0%,100%{ opacity:.4 } 50%{ opacity:1 } }

/* 主区三栏：左订单簿保持窄档；右「最新成交」加宽（四列数字需空间）| 中 K线 */
.bn-main {
  display: grid;
  /* 订单簿 230–250 不动；成交从 ~160 提到 ~210–230 */
  grid-template-columns: minmax(230px, 250px) 1fr minmax(210px, 230px);
  gap: 8px;
  align-items: stretch;
  min-height: 0;
}
.bn-col {
  display: flex; flex-direction: column;
  height: calc(100vh - 270px); min-height: 520px;
  min-width: 0;
}
.bn-col-chart { min-width: 0; }
.kline-chart-wrap, .bn-chart-wrap {
  position: relative; width: 100%;
  flex: 1;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  background: var(--card);
  touch-action: none;
}
html.dark .bn-chart-wrap { background: #161a1e; border-color: rgba(255,255,255,0.06); }
.kline-chart { width: 100%; height: 100%; }
.kline-no-data {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; color: var(--muted-foreground);
}

.bn-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex; flex-direction: column;
  min-height: 0;
  flex: 1;
  height: 100%;
}
html.dark .bn-panel { background: #161a1e; border-color: rgba(255,255,255,0.06); }
/* 左右栏面板占满列高，订单簿/成交各自可滚看更多 */
.bn-orderbook, .bn-trades { flex: 1; min-height: 0; }
.bn-panel-hd {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; font-size: 13px; font-weight: 700;
  border-bottom: 1px solid var(--border); color: var(--foreground);
  flex-shrink: 0;
  gap: 8px;
  white-space: nowrap; /* 禁止「订单簿 / 精度 / 价差」顶栏换行 */
  overflow: hidden;
}
.bn-panel-hd > span:first-child { flex-shrink: 0; }
.ob-hd-right {
  display: flex; align-items: center; gap: 8px;
  min-width: 0; flex: 1; justify-content: flex-end;
  white-space: nowrap;
}
.ob-tick {
  font-size: 11px; font-weight: 650; padding: 2px 6px;
  background: var(--muted); border: 1px solid var(--border); border-radius: 4px;
  color: var(--foreground); cursor: pointer;
  flex-shrink: 0;
}
.bn-panel-sub {
  font-size: 11px; font-weight: 600; color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}
/* 四列：价格 | 数量 | 累计 | 总额(U) —— 币安信息密度 */
.ob-head {
  display: grid; grid-template-columns: 1.15fr 0.9fr 0.9fr 0.95fr;
  gap: 2px; padding: 3px 8px; font-size: 10px; color: var(--muted-foreground); font-weight: 600;
  flex-shrink: 0;
}
.tr-head {
  display: grid; grid-template-columns: 1.15fr 0.9fr 0.9fr 0.95fr;
  gap: 2px; padding: 3px 8px; font-size: 10px; color: var(--muted-foreground); font-weight: 600;
  flex-shrink: 0;
}
/* 币安式：无滚动条；卖区底对齐 mid、买区顶对齐 mid；只画能铺满的 N 档 */
.ob-asks, .ob-bids {
  flex: 1 1 0;
  min-height: 60px;
  overflow: hidden; /* 无滚动条 */
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums; font-size: 11px;
  display: flex;
  flex-direction: column;
}
/* 卖：行贴底部（最优卖紧贴中间价） */
.ob-asks { justify-content: flex-end; }
/* 买：行贴顶部（最优买紧贴中间价） */
.ob-bids { justify-content: flex-start; }
.ob-row {
  position: relative; display: grid; grid-template-columns: 1.15fr 0.9fr 0.9fr 0.95fr;
  gap: 2px; padding: 0 8px;
  height: 18px; line-height: 18px;
  flex: 0 0 18px;
  box-sizing: border-box;
}
.ob-row:hover { background: rgba(127,127,127,0.08); }
.ob-row .ob-bg {
  position: absolute; top: 0; bottom: 0; right: 0;
  opacity: .16; pointer-events: none; z-index: 0;
}
.ob-row.ask .ob-bg { background: #f6465d; }
.ob-row.bid .ob-bg { background: #0ecb81; }
.ob-row > span { position: relative; z-index: 1; }
.ob-row.ask .ob-p { color: #f6465d; font-weight: 700; }
.ob-row.bid .ob-p { color: #0ecb81; font-weight: 700; }
.ob-q, .ob-c, .ob-cq, .tr-q, .tr-t { color: var(--muted-foreground); text-align: right; }
.ob-p, .tr-p { text-align: left; }
.ob-mid {
  padding: 5px 8px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 1px; flex-shrink: 0;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  background: color-mix(in srgb, var(--muted) 40%, transparent);
}
.ob-mid-price { font-size: 15px; font-weight: 750; color: var(--foreground); }
.ob-mid-bbo { font-size: 10px; color: var(--muted-foreground); }
.ob-empty { padding: 10px; text-align: center; font-size: 12px; }
/* 底部：加宽后单行横排 — 买 | 深度比 | 卖，不再叠行 */
.ob-foot {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  color: var(--muted-foreground);
  box-sizing: border-box;
  white-space: nowrap;
}
.ob-foot-sums {
  display: contents; /* 子项直接参与 foot 横排：买 / 比 / 卖 */
}
#ob-sum-bid, #ob-sum-ask {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.2;
  flex-shrink: 0;
}
#ob-sum-bid { text-align: left; color: #0ecb81; order: 1; }
.ob-ratio { order: 2; flex: 1; min-width: 72px; max-width: 120px; }
#ob-sum-ask { text-align: right; color: #f6465d; order: 3; }
.ob-foot b {
  font-weight: 700;
  color: inherit;
  font-size: 12px;
}
.ob-foot em {
  font-style: normal;
  font-size: 10px;
  opacity: 0.85;
  color: var(--muted-foreground);
}
.ob-ratio {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  min-width: 0;
}
.ob-ratio-bar {
  display: flex; width: 100%; height: 5px; border-radius: 2px; overflow: hidden;
  background: rgba(127,127,127,0.15);
}
.ob-ratio-bid { background: #0ecb81; height: 100%; }
.ob-ratio-ask { background: #f6465d; height: 100%; }
.ob-ratio-txt {
  font-size: 10px; text-align: center; white-space: nowrap;
  color: var(--muted-foreground);
}

/* 成交：按高度固定 N 笔，无滚动条 */
.tr-body {
  flex: 1; min-height: 0;
  overflow: hidden;
  font-family: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, monospace;
  font-variant-numeric: tabular-nums; font-size: 11px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.tr-row {
  display: grid; grid-template-columns: 1.15fr 0.9fr 0.9fr 0.95fr;
  gap: 2px; padding: 0 8px;
  height: 18px; line-height: 18px;
  flex: 0 0 18px;
  box-sizing: border-box;
}
.tr-row:hover { background: rgba(127,127,127,0.08); }
.tr-row.buy .tr-p { color: #0ecb81; font-weight: 700; }
.tr-row.sell .tr-p { color: #f6465d; font-weight: 700; }
.tr-qv { color: var(--muted-foreground); text-align: right; }

@media (min-width: 1400px) {
  .bn-main {
    /* 订单簿仍略增；成交再宽一点 */
    grid-template-columns: minmax(240px, 255px) 1fr minmax(220px, 240px);
  }
}
@media (max-width: 1200px) {
  .bn-main {
    grid-template-columns: minmax(220px, 235px) 1fr minmax(195px, 215px);
  }
}
@media (max-width: 1000px) {
  /* 窄屏：上 K 线，下订单簿|成交 */
  .bn-main {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(360px, 48vh) minmax(320px, 42vh);
  }
  .bn-col-chart { grid-column: 1 / -1; height: auto; min-height: 360px; }
  .bn-col-ob, .bn-col-tr { height: auto; min-height: 300px; }
  .kline-chart-wrap, .bn-chart-wrap { min-height: 360px; }
}
@media (max-width: 900px) {
  .bn-last-price { font-size: 22px; }
  .bn-stats { gap: 12px 16px; }
  .bn-ohlc-ma { margin-left: 0; width: 100%; }
}
@media (max-width: 640px) {
  .bn-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  .bn-col-chart, .bn-col-ob, .bn-col-tr {
    height: auto; min-height: 280px;
  }
  .bn-col-chart { min-height: 360px; }

  /* —— 手机深度适配：单列堆叠后给列显式高度，避免塌缩或无限撑高 ——
     实现原因：面板是 flex 子项（flex-basis:0%），在高度 auto 的父列里 height 属性
     会被内容撑开（成交列表渲染 60 笔 ≈1259px）——必须把高度定在【列】上，
     面板靠 flex 填满；K 线图优先占屏，订单簿/成交各分固定比例 */
  .bn-col-ob { min-height: 320px; height: 42vh; }   /* 订单簿列 42% 视口高 */
  .bn-col-tr { min-height: 260px; height: 34vh; }   /* 成交列 34% 视口高 */
  /* 面板内部恢复滚动（桌面是「无滚动条铺满」，手机堆叠时必须可滚才看得到全部档位） */
  .bn-orderbook .ob-asks,
  .bn-orderbook .ob-bids { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .bn-trades .tr-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* 顶栏统计换行收紧：24h 高/低/量/额 两列网格排布 */
  .bn-header { gap: 10px; padding-bottom: 8px; }
  .bn-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 10px;
    width: 100%;
  }
  .bn-stat { min-width: 0; }
  .bn-last-price { font-size: 20px; }
  .bn-symbol-select { font-size: 14px; padding: 6px 8px; }

  /* OHLC 十字光标条：字段多，允许两行且隐藏次要项防挤压 */
  .bn-ohlc { gap: 4px 10px; font-size: 11px; padding: 4px 2px 6px; min-height: 0; }
  .bn-ohlc-ma { margin-left: 0; width: 100%; }

  /* 工具条：周期按钮触控放大 + MA 开关换行 */
  .bn-toolbar { padding: 8px 0 4px; gap: 8px; }
  .kline-tf { padding: 9px 10px; font-size: 13px; }   /* 触控目标 ≥38px */
  .bn-tool-btn { padding: 8px 12px; }
  .bn-ma-toggles { gap: 12px; flex-wrap: wrap; }
  .bn-ma-lab input { width: 16px; height: 16px; }      /* 复选框触控放大 */

  /* 盘口行高微增（18→20px）提升可读性，行数由 JS 按容器高度自适应重算 */
  .ob-row, .tr-row { height: 20px; line-height: 20px; flex-basis: 20px; }
}

/* 策略卡选中态 */
.strategy-card {
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  background: var(--card);
}
.strategy-card:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)) !important; }
.strategy-card.selected {
  border-color: var(--primary) !important;
  background: var(--primary-soft) !important;
}

/* 响应式 */
@media (max-width: 1200px) {
  .top-chip.lg { display: none; }
  .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .qk-stat-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .qk-stat-row > .metric, .qk-stat-row > .qk-stat {
    border-bottom: 1px solid var(--border);
  }
}
@media (max-width: 1100px) {
  .grid-5, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .top-chip.md { display: none; }
}

/* ========== 手机适配（≤860px 抽屉侧栏 + 紧凑顶栏） ========== */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: var(--app-header-height); bottom: 0;
    z-index: 50; transform: translateX(-100%);
    box-shadow: var(--shadow-md);
    transition: transform .2s ease;
  }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-collapsed .sidebar { width: var(--sidebar-width); flex-basis: var(--sidebar-width); }
  .app-shell.sidebar-collapsed .nav-label,
  .app-shell.sidebar-collapsed .nav-group-title,
  .app-shell.sidebar-collapsed .side-status-text { display: initial; }
  .sidebar-backdrop {
    display: none; position: fixed; inset: 0; top: var(--app-header-height);
    background: rgb(0 0 0 / 0.4); z-index: 45;
  }
  .app-shell.sidebar-open .sidebar-backdrop { display: block; }
  /* 页面标题隐藏（省空间），品牌名保留（用户需知道当前系统） */
  .page-title { display: none; }
  .header-divider { display: none; }
  /* 手机端顶栏自动精简：仅保留 今日盈亏/累计增值，隐藏 4 个资产类 chip 与模式徽标
     实现原因：PC 需完整资产/浮盈/可用信息，手机宽度不足按 860px 断点自动隐藏 .pc-only 控件（资产/多仓浮盈/空仓浮盈/可用），
     顶栏本身保持显示（height 不变），仅内容精简；侧栏/遮罩保持 top: var(--app-header-height) 默认值无需覆盖 */
  .top-chip.pc-only { display: none !important; }
  #top-short-pnl-chip.pc-only { display: none !important; }
  #top-mode, #top-clock { display: none; }
  /* 手机端剩余 2 个 chip 紧凑化：防止挤高顶栏超出 3.25rem 固定高度 + 防止数值百分比横向溢出框
     实现原因：①手机仅留 2 chip 时若保留 PC 的 min-width:88px + padding:4px 10px + 12.5px 字号，内容过长会导致 chip 换行/增高进而撑高 .app-header，
     收紧为 min-width:0 + 小 padding + 小字号，保证单行高度≤顶栏高度，不撑开；
     ②数值“+1,234.56U +12.34%”在 ≤860px 时 11px 会横向溢出 chip 边框（bSW119 > bCW81），遂将标题 span 降至 8px、数值 b 降至 8.5px（比 11px 小 2.5px 满足“字体调小”），
     并让 chip flex:1 1 0 均分 + overflow:hidden，b 改为 white-space:normal 允许在空格处自动换行（金额与百分比可分两行），彻底杜绝横向溢出框；
     换行后 chip 高约 29→39px 仍 < 52px 顶栏高度，不撑高；极窄屏靠 480px 断点再降一档，仍保持不溢出 */
  .top-chips { gap: 4px; }
  .top-chip { min-width: 0; padding: 3px 6px; flex: 1 1 0; overflow: hidden; display: flex; flex-direction: column; justify-content: center; gap: 1px; }
  .top-chip span { font-size: 8px; line-height: 1.15; }
  .top-chip b { font-size: 8.5px; line-height: 1.2; white-space: normal; overflow-wrap: anywhere; word-break: break-word; overflow: hidden; display: block; max-width: 100%; }

  .grid-5, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .row > .panel, .row > .card { min-width: 100%; }  /* row 双卡在手机改纵向堆叠 */
  .qk-stat-row { grid-template-columns: 1fr; }
  .container { padding: 12px 12px 20px; }
}

/* ========== 手机深度适配（≤640px：小屏手机） ========== */
@media (max-width: 640px) {
  /* 表格兜底：所有表格可横向滚动，禁止撑破容器
     实现原因：live/trade/paper 多张宽表未包 .table-scroll，窄屏溢出页面 */
  .panel table:not(#strategy-info-body),
  .card table,
  #checks-table,
  #lvo-table,
  #coverage-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* 触控目标 ≥40px：按钮/输入/下拉加高（44px 是 iOS HIG 推荐值） */
  button, .qk-btn { padding: 10px 14px; font-size: 13.5px; min-height: 38px; }
  input, select, textarea { padding: 9px 10px; font-size: 15px; }  /* 15px 防 iOS 聚焦自动放大 */

  /* 卡片与指标卡收紧内边距，信息密度更高 */
  .panel, .card, .qk-card { padding: 14px 12px; border-radius: 12px; }
  .metric, .qk-stat { padding: 12px 10px; border-radius: 10px; }
  .metric .value, .qk-stat .value { font-size: 19px; }  /* 大数字防溢出换行 */
  .qk-stat-row > .metric .value, .qk-stat-row > .qk-stat .value { font-size: 17px; }

  /* 表单控件全宽化：固定 px 宽的输入框在小屏自适应 */
  .form-inline input,
  .form-inline select { max-width: 100%; }
  .form-inline label { flex-shrink: 1; min-width: 0; }
  /* datetime-local 固定 180px 内联宽度 → 小屏放开自适应 */
  input[type="datetime-local"] { width: 100% !important; }

  /* tab 切换按钮均分整行，触控更稳 */
  .tabbar, .qk-tabs { gap: 2px; margin-bottom: 12px; }
  .tabbar button, .qk-tabs button { flex: 1 1 0; padding: 10px 6px; text-align: center; white-space: nowrap; }

  /* 指标网格回退单列（覆盖中间断点） */
  .metrics { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }

  /* 日志字号微调 + 高度收窄（手机竖屏可视空间有限） */
  .log, .qk-log { font-size: 11.5px; max-height: 300px; padding: 10px; }

  /* 登录页卡片贴边 */
  .login-card { padding: 24px 20px; }

  /* toast 提示改为左右贴边（窄屏右下角易被遮挡） */
  #trade-toast {
    left: 12px !important;
    right: 12px !important;
    bottom: 16px !important;
    max-width: none !important;
  }
}

/* ========== 手机超窄屏（≤480px） ========== */
@media (max-width: 480px) {
  .brand-text-side { display: none; }
}
