:root, :root[data-theme="dark"] {
  --bg: #0d1117; --panel: #161b22; --panel2: #1c232c; --line: #262d36;
  --text: #e6edf3; --muted: #8b949e; --accent: #3b82f6; --accent2: #1f6feb;
  --ok: #3fb950; --warn: #d29922; --err: #f85149;
}
:root[data-theme="light"] {
  --bg: #f5f7fa; --panel: #fff; --panel2: #f0f3f7; --line: #dde3ea;
  --text: #1f2328; --muted: #636c76;
  --accent: #2f6fdd; --accent2: #1f5fc4;
  --ok: #1a7f37; --warn: #9a6700; --err: #cf222e;
}
/* 未手动指定主题时跟随系统 */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f5f7fa; --panel: #fff; --panel2: #f0f3f7; --line: #dde3ea;
    --text: #1f2328; --muted: #636c76;
    --accent: #2f6fdd; --accent2: #1f5fc4;
    --ok: #1a7f37; --warn: #9a6700; --err: #cf222e;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.55 system-ui, "Microsoft YaHei", "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.ok { color: var(--ok); } .warn { color: var(--warn); } .err { color: var(--err); }
/* 盈亏：红赢绿亏 */
.gain { color: var(--err); }
.loss { color: var(--ok); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, Consolas, monospace; }
/* 最新价后面的涨跌幅小字（策略监控 / 持仓列表共用） */
.quote-chg { font-size: 11px; margin-left: 2px; white-space: nowrap; }

/* ---------- 登录 ---------- */
.login-screen {
  min-height: 100%; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% 0%, rgba(59,130,246,.14), transparent 60%), var(--bg);
}
.login-card {
  width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 24px; box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card label { display: block; margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%; margin-top: 6px; padding: 9px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit;
}
.login-card button { width: 100%; margin-top: 18px; padding: 10px; }
.hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; }
.msg { font-size: 13px; min-height: 20px; margin-top: 10px; color: var(--err); }

/* ---------- 布局 ---------- */
.app { display: grid; grid-template-columns: 208px 1fr; height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px;
}
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 6px 16px; }
/* 品牌 logo（替换原来的圆点） */
.brand-logo {
  width: 26px; height: 26px; flex: none;
  object-fit: contain;
  filter: drop-shadow(0 0 6px rgba(220, 38, 38, .28));
}
/* 登录页标题：logo + 标题 */
.login-title { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.login-title h1 { margin: 0; }
.login-logo { width: 34px; height: 34px; flex: none; object-fit: contain; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.brand-text { flex: 1; min-width: 0; }
.brand-name { font-weight: 650; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--muted); }
/* 图标小按钮（主题 / 退出）：图标严格居中。
   用 button.small.theme-toggle 提高特异性，覆盖后面的 button.small{ padding } */
button.small.theme-toggle {
  flex: none;
  width: 36px; height: 26px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px;
  font-size: 13px; line-height: 1;
  opacity: .85;
}
button.small.theme-toggle:hover { opacity: 1; }
button.small.theme-toggle svg { display: block; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a {
  padding: 9px 10px; border-radius: 8px; color: var(--muted);
  text-decoration: none; font-size: 13.5px;
  display: flex; align-items: center; gap: 9px;
}
nav a svg {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  opacity: .8;
}
nav a:hover { background: var(--panel2); color: var(--text); }
nav a:hover svg { opacity: 1; }
nav a.active { background: rgba(59,130,246,.16); color: var(--text); }
nav a.active svg { opacity: 1; stroke: var(--accent); }
/* 菜单分组分隔线 */
.nav-sep { height: 1px; background: var(--line); margin: 6px 10px; flex: 0 0 auto; }
.sidebar-foot {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between;
  gap: 6px; font-size: 12px; position: relative;   /* 用户菜单的定位父级 */
}
/* 左下角用户信息 = 用户菜单入口（点击弹出下拉菜单） */
.whoami-wrap {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  flex: 1 1 auto; padding: 4px 6px; border-radius: 8px;
  background: transparent; border: 0; color: inherit;
  font: inherit; cursor: pointer; text-align: left;
}
.whoami-wrap:hover, .whoami-wrap[aria-expanded="true"] { background: var(--panel2); }
.whoami-wrap:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.whoami-wrap svg {
  width: 14px; height: 14px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
  opacity: .7;
}
.whoami-wrap #whoami { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 用户下拉菜单：向上弹出，点外部 / Esc / 选完自动收起 */
.user-menu {
  position: absolute; left: 8px; bottom: calc(100% + 6px); z-index: 97;
  min-width: 150px; max-width: min(220px, 80vw);
  display: flex; flex-direction: column; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .45);
}
.user-menu button {
  display: block; width: 100%; text-align: left;
  padding: 8px 10px; min-height: 32px; font-size: 13px;
  background: transparent; border: 0; border-radius: 6px; color: var(--text);
}
.user-menu button:hover { background: var(--panel2); }
main { overflow: auto; padding: 22px 26px; }
h2 { font-size: 18px; margin: 0 0 4px; }
/* 带图标的页面标题：图标用主题色，与侧边栏菜单同一套线性图标 */
h2.page-title { display: flex; align-items: center; gap: 9px; }
h2.page-title svg {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: var(--accent); stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.page-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
h3 { font-size: 14.5px; margin: 24px 0 10px; }

/* ---------- 通用组件 ---------- */
button, select, input {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent2); }
button.ghost { background: transparent; }
button.small { padding: 4px 9px; font-size: 12px; }
button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
button:disabled { opacity: .5; cursor: not-allowed; }
input { min-width: 0; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 8px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 21px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .s { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 14px 0; }
.toolbar .spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: clip; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
/* 表头固定：sticky 相对最近的滚动容器（.scroll 或 main） */
thead th {
  position: sticky; top: 0; z-index: 3;
  font-size: 12px; color: var(--muted); font-weight: 600;
  background: var(--panel2);
  box-shadow: inset 0 -1px 0 var(--line);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(59,130,246,.06); }
tbody tr.clickable { cursor: pointer; }
/* 公共表格：表头可点排序 / Shift+点分组 */
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tr.group-row td {
  background: var(--panel2); font-weight: 600; font-size: 12px;
  color: var(--muted); letter-spacing: .02em;
}
/* 表格内的链接不要用浏览器默认蓝色 */
td a { color: var(--text); text-decoration: none; }
td a:hover { color: var(--accent); text-decoration: underline; }
.scroll { max-height: 520px; overflow: auto; border-radius: 10px; background: var(--panel); min-width: 0; max-width: 100%; }
.scroll table { border-radius: 0; border-left: 0; border-right: 0; border-top: 0; }
.scroll thead th { background: var(--panel2); }
/* 滚动时表头下沿与内容之间不留缝 */
.scroll thead th::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: var(--line);
}

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; border: 1px solid var(--line); }
.badge.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.badge.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: color-mix(in srgb, var(--warn) 10%, transparent); }
.badge.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); background: color-mix(in srgb, var(--err) 10%, transparent); }
.badge.dim { color: var(--muted); }
/* 多空语义色：多=红、空=绿（与国内行情习惯一致） */
.badge.long {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 45%, transparent);
  background: color-mix(in srgb, var(--err) 10%, transparent);
}
.badge.short {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
  background: color-mix(in srgb, var(--ok) 10%, transparent);
}

.chart { width: 100%; height: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.chart.small { height: 260px; }

.empty { padding: 40px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 6px; margin: 18px 0 12px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 8px 12px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.form-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin: 12px 0; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-row label input, .form-row label select { min-width: 150px; }

/* AI 接口设置弹窗：窄一些，输入框整行铺满 */
.ai-field {
  display: flex; flex-direction: column; gap: 4px;
  margin: 12px 0; font-size: 12px; color: var(--muted);
}
.ai-field input { width: 100%; min-width: 0; margin-top: 2px; }

.toast {
  position: fixed; left: 50%; top: 40%; transform: translate(-50%, -50%);
  z-index: 300; display: flex; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 26px; font-size: 14.5px; font-weight: 500;
  box-shadow: 0 18px 56px rgba(0, 0, 0, .5);
  max-width: min(520px, 86vw); text-align: left; pointer-events: none;
  animation: toast-in .16s ease-out;
}
.toast .toast-icon { font-size: 17px; font-weight: 700; line-height: 1; }
.toast.ok { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.toast.ok .toast-icon { color: var(--ok); }
.toast.err { border-color: color-mix(in srgb, var(--err) 55%, var(--line)); }
.toast.err .toast-icon { color: var(--err); }
.toast:not(.ok):not(.err) .toast-icon { color: var(--accent); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, -46%) scale(.96); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; align-items: start; }
/* 策略监控：左列表更宽，右 K 线稍窄 */
.split.strategy-split { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .split, .split.strategy-split { grid-template-columns: minmax(0, 1fr); } }

/* 自适应宽度：左侧表格按内容定宽，右侧图表吃掉剩余空间 */
.split-flex { display: flex; gap: 16px; align-items: stretch; margin-top: 18px; }
.split-flex > .fit { flex: 0 1 auto; min-width: 320px; max-width: 58%; display: flex; flex-direction: column; }
/* 策略监控右列：K 线 + 覆盖在图内的说明浮层，不占额外高度 → 与左侧顶底严格对齐 */
.split-flex > .grow.kline-col { position: relative; }
.kline-caption {
  position: absolute; left: 10px; bottom: 6px;
  font-size: 12px; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  padding: 2px 7px; border-radius: 6px;
  max-width: calc(100% - 24px);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.split-flex > .grow { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; }
.split-flex .fit table { width: auto; }
.split-flex .fit .scroll { max-height: 560px; }
.split-flex > .fit > .scroll,
.split-flex > .grow > .scroll { flex: 1 1 auto; }
.chart.sync-height { height: 560px; }
@media (max-width: 1100px) {
  .split-flex { flex-direction: column; }
  .split-flex > .fit { max-width: none; min-width: 0; width: 100%; }
  .chart.sync-height { height: 340px; }
}

/* 账号详情：当前持仓 / 持仓K线+手工交易 两列（权益曲线已改为弹窗） */
.trade-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1.3fr) minmax(0, 0.95fr);
  gap: 16px; align-items: start; margin-top: 18px;
}
.trade-grid.two-col {
  grid-template-columns: minmax(0, 2.2fr) minmax(0, 1fr);
}
.trade-col { min-width: 0; display: flex; flex-direction: column; }
/* 手工交易列下方的 K 线：自动填充剩余高度，底边与左侧持仓列表对齐 */
.trade-col .chart.fill { flex: 1 1 auto; min-height: 200px; }
/* 持仓列表固定高度，与左侧权益曲线图表等高等高（不含列表下方的按钮行） */
.trade-col .scroll { height: 500px; max-height: 500px; }
.manual-panel { display: flex; flex-direction: column; gap: 8px; }
.manual-panel select { width: 100%; }
/* 合约 + 手数同一行 */
.manual-row-top { display: flex; gap: 6px; align-items: center; }
.manual-row-top select { flex: 1 1 auto; min-width: 0; }
.qty-wrap { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.qty-wrap input { width: 58px; flex: 0 0 58px; }
.qty-unit { font-size: 12.5px; color: var(--muted); }
.manual-row-inline { display: flex; gap: 6px; }
.manual-row-inline .trade-btn { flex: 1 1 0; min-width: 0; }
.manual-panel [data-act="liquidate"] { width: 100%; }
@media (max-width: 1200px) {
  .trade-grid { grid-template-columns: minmax(0, 1fr); }
  .trade-grid.two-col { grid-template-columns: minmax(0, 1fr); }
}

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 10px 0 4px; }
.kv { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.kv .k { font-size: 11.5px; color: var(--muted); }
.kv .v { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
/* 带操作按钮的指标卡：按钮固定在右侧，不会被文字覆盖 */
.kv.kv-action {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 8px;
}
.kv.kv-action > .k { grid-column: 1; grid-row: 1; }
.kv.kv-action > .v { grid-column: 1; grid-row: 2; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.kv.kv-action > button { grid-column: 2; grid-row: 1 / span 2; align-self: center; white-space: nowrap; font-size: 11.5px; padding: 4px 8px; }
@media (max-width: 1100px) {
  /* 窄屏时出入金按钮换到下方，避免挤扁数值 */
  .kv.kv-action { grid-template-columns: 1fr; }
  .kv.kv-action > .v { grid-column: 1; grid-row: 2; }
  .kv.kv-action > button { grid-column: 1; grid-row: 3; align-self: start; justify-self: start; }
}

/* ---------- 策略管理 ---------- */
.strategy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; }
.strategy-card { display: flex; flex-direction: column; gap: 8px; }
.strategy-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.strategy-name { font-size: 15px; font-weight: 650; }
/* 详情卡片名称行：名称 + 所属/共享徽章同一行，窄屏自动换行 */
.strategy-name-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; }
.strategy-name-line .strategy-name { min-width: 0; overflow-wrap: anywhere; }
/* 策略管理左列：比通用 fit 宽一点，让「所属 / 操作」列在桌面上不用横向滚动 */
@media (min-width: 1101px) {
  .split-flex > .fit.strategy-list-col { max-width: 64%; }
}
.switch-line { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); cursor: pointer; white-space: nowrap; }

/* ---------- 账号设置 ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 10px 0; }
.variety-picker { display: flex; flex-wrap: wrap; gap: 6px; max-height: 220px; overflow: auto;
                  border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--panel); }
.variety-picker label { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px;
                        padding: 4px 9px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; }
.variety-picker label:hover { border-color: var(--accent); }
.variety-picker input { margin: 0; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 100; padding: 20px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .52); backdrop-filter: blur(2px);
}
.modal {
  width: min(760px, 100%); max-height: 86vh;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
}
.modal-body { padding: 16px 18px; overflow: auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--line);
}
.modal-foot .muted { margin-right: auto; }

/* ---------- 状态点 / 名单着色 ---------- */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
       margin-right: 6px; vertical-align: middle; }
.dot.ok { background: var(--ok); box-shadow: 0 0 6px color-mix(in srgb, var(--ok) 60%, transparent); }
.dot.warn { background: var(--warn); }
.dot.dim { background: var(--muted); }

.variety-picker label.picked-white {
  border-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 12%, transparent);
}
.variety-picker label.picked-black {
  border-color: var(--err);
  background: color-mix(in srgb, var(--err) 12%, transparent);
}

/* ---------- 成交记录弹窗：成交/按品种盈亏各占一半 ---------- */
.modal-body.split-half {
  display: flex; flex-direction: column; gap: 12px;
  height: 84vh; padding: 10px 14px;
}
.half-block { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.half-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.half-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.half-body .scroll { max-height: none; flex: 1 1 auto; min-height: 0; }
.pager-bar {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; padding: 6px 0 2px; font-size: 12.5px; flex: 0 0 auto;
}
.pager-bar button { min-width: 72px; }
.pager-size { display: flex; align-items: center; gap: 4px; }
.pager-size select { width: auto; padding: 3px 6px; font-size: 12px; }

/* ---------- 策略执行进度 ---------- */
.run-progress-wrap { margin: -2px 0 12px; }
.run-progress-wrap.hidden { display: none; }
.run-progress {
  height: 6px; background: var(--line); border-radius: 3px; overflow: hidden;
}
.run-progress-bar {
  height: 100%; width: 0; background: var(--accent);
  transition: width .25s ease;
}
.run-progress-text { font-size: 12px; color: var(--muted); margin-top: 5px; }

/* ---------- 手工交易 ---------- */
.trade-btn { min-width: 54px; font-weight: 650; }
.trade-btn.long {
  color: var(--err);
  border-color: color-mix(in srgb, var(--err) 45%, var(--line));
}
.trade-btn.long:hover { background: color-mix(in srgb, var(--err) 14%, transparent); }
.trade-btn.short {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
}
.trade-btn.short:hover { background: color-mix(in srgb, var(--ok) 14%, transparent); }
.trade-btn.close { color: var(--text); }
.trade-btn.reverse {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 45%, var(--line));
}
.trade-btn:disabled { opacity: .38; cursor: not-allowed; }
/* 持仓表列比较多（14 列），收紧内边距让一屏能看全 */
#positionsTable { font-size: 12.5px; }
#positionsTable th, #positionsTable td { padding: 6px 7px; white-space: nowrap; }

/* 总览页：总权益 / 总净值 曲线并排 */
.dash-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 6px;
}
.dash-charts .chart { height: 260px; }
@media (max-width: 900px) {
  .dash-charts { grid-template-columns: 1fr; }
}

/* 定时任务卡片 */
.sched-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.sched-card { display: flex; flex-direction: column; align-items: flex-start; }

/* 数据管理只读模式（普通用户）：tab 可切换，其余控件不可操作 */
.readonly-banner {
  display: flex; align-items: center; gap: 8px;
  margin: 0 0 14px; padding: 9px 12px;
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  border-radius: 8px; font-size: 12.5px;
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  color: var(--text);
}
.readonly-mode #dataTabs button { pointer-events: auto; opacity: 1; }
.readonly-mode button:not(#dataTabs button),
.readonly-mode select,
.readonly-mode input:not(#symbolFilter) {
  pointer-events: none !important;
  opacity: .5;
  cursor: not-allowed;
}

/* 数据管理：行情源分「历史 / 实时」两组并排 */
.source-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}
.source-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: color-mix(in srgb, var(--panel2) 50%, transparent);
}
.source-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 600;
}

/* 回测参数对比组 */
.param-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: color-mix(in srgb, var(--panel2) 60%, transparent);
}
.param-group-label {
  min-width: 200px;
  max-width: 280px;
}
.param-group .form-row { margin-bottom: 8px; }

/* 回测：多策略选择器（网格对齐、紧凑、名称完整换行显示） */
.strategy-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 4px 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel2) 40%, transparent);
  /* 作为 flex/表单子项时允许收缩，否则 grid 的 min-content 会把容器顶宽（移动端溢出） */
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
.strategy-picker .switch-line { margin: 0; }
/* 多选里的 label 是行内选项，不能被 .form-row label 的「纵向表单标签」布局影响 */
.form-row .strategy-picker label,
.strategy-picker label {
  display: inline-flex; flex-direction: row; align-items: center;
  flex: 0 0 auto; width: auto;
}
.form-row .strategy-picker .strategy-pick-item {
  display: flex; align-items: flex-start; gap: 6px;
  width: 100%; min-width: 0; flex: initial;
  margin: 0; padding: 4px 6px; border-radius: 6px;
  font-size: 12.5px; line-height: 1.45;
  color: var(--text); cursor: pointer; white-space: normal;
}
.strategy-pick-item:hover { background: var(--panel2); }
.strategy-pick-item.muted { color: var(--muted); }
/* 覆盖移动端 `.form-row label input { width:100% }`，否则 checkbox 会被撑满整项 */
.form-row .strategy-picker .strategy-pick-item input[type="checkbox"] {
  width: 16px; min-width: 16px; max-width: 16px; flex: none; margin: 0; margin-top: 2px;
}
/* 名称完整显示：允许换行、不截断 */
.strategy-pick-item .pick-name {
  flex: 1 1 auto; min-width: 0;
  white-space: normal; word-break: break-word; overflow: visible;
  text-overflow: clip;
}
.strategy-pick-item .badge { flex: none; margin-top: 1px; }
.strategy-pick-item input[type="checkbox"] { flex: none; margin: 0; }
@media (max-width: 900px) {
  .strategy-picker { grid-template-columns: minmax(0, 1fr); }
}

/* 回测：每个策略的参数区（多策略交叉对比） */
.strategy-param-section {
  margin-bottom: 14px;
  padding-left: 10px;
  border-left: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.strategy-param-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.strategy-param-title .mono { font-weight: 400; font-size: 11.5px; }

/* 表格选中行高亮（持仓、回测交易等所有可点击表格共用） */
tbody tr.selected td {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
tbody tr.selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
/* 回测：「逐笔交易」容器只负责定高，滚动交给内部的表格容器，避免双层滚动条 */
#btTradeTable { height: 460px; }
#btTradeTable .scroll { height: 100%; max-height: 100%; }

/* ---------- 交易日历 ---------- */
.calendar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 12px; }
.cal-month { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.cal-month h4 { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; margin-bottom: 4px;
            font-size: 10px; color: var(--muted); text-align: center; }
.cal-cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-cell { aspect-ratio: 1; display: grid; place-items: center; font-size: 11px;
            border-radius: 4px; color: var(--muted); }
.cal-cell.open { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); }
.cal-cell.today { outline: 1px solid var(--accent); }

/* ============================================================ 移动端抽屉菜单 / 行情芯片 */
/* 悬浮 ☰ 按钮与遮罩：桌面端隐藏，≤900px 由媒体查询打开 */
.nav-toggle {
  display: none; position: fixed; left: 14px;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 95; width: 48px; height: 48px; padding: 0; border-radius: 50%;
  align-items: center; justify-content: center;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .42);
}
.nav-toggle:hover { border-color: var(--accent); }
.nav-toggle svg {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.nav-mask { display: none; position: fixed; inset: 0; z-index: 91; background: rgba(0, 0, 0, .52); }
body.nav-open .nav-mask { display: block; }

/* 全局行情状态芯片：纯展示（不挡点击），接口不可用时由 JS 隐藏 */
.quote-chip {
  position: fixed; right: 16px; top: 12px; z-index: 70;
  display: inline-flex; align-items: center; gap: 6px;
  max-width: calc(100vw - 32px); padding: 4px 10px; border-radius: 99px;
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line); pointer-events: none;
}
.quote-chip .dot { margin-right: 0; }

/* 总览「实时行情」小卡片 */
.quote-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.quote-mini {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; min-width: 0;
}
.quote-mini .k {
  font-size: 11.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.quote-mini .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 1px; }
.quote-mini .s { font-size: 11.5px; font-variant-numeric: tabular-nums; }

/* 手工交易面板：最新价 / 涨跌幅 / 实时-收盘角标 */
.manual-quote {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: color-mix(in srgb, var(--panel2) 55%, transparent);
  font-size: 12.5px; color: var(--muted);
}
.manual-quote .price { font-size: 17px; font-weight: 650; color: var(--text); font-variant-numeric: tabular-nums; }
.manual-quote .chg { font-size: 12.5px; font-variant-numeric: tabular-nums; }
.manual-quote .badge { margin-left: auto; }

/* 策略管理列表：行尾操作列（开关不触发选中） */
td.ops { white-space: nowrap; }
td.ops .ops { display: flex; align-items: center; gap: 10px; }
/* 行尾开关：小字标签在上、勾选框在下（11px muted），触摸区 ≥28px */
.ops-switch {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-width: 34px; min-height: 30px;
  cursor: pointer; user-select: none;
}
.ops-label { display: block; font-size: 11px; line-height: 1.1; color: var(--muted); }
.ops-switch input[type="checkbox"] { width: 16px; height: 16px; margin: 0; flex: none; }
td.ops .switch-line { display: inline-flex; align-items: center; margin-right: 10px; vertical-align: middle; }
td.ops .switch-line input, .switch-line input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }
td.ops button { min-height: 28px; flex: none; }
.strategy-row-lock { margin-left: 4px; }

/* ---------- 开盘执行（T+1）待执行提示条 / 执行设置 ---------- */
.executor-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 0 0 14px; padding: 8px 12px; min-width: 0;
  border: 1px solid var(--line); border-left: 3px solid var(--warn);
  border-radius: 10px; background: color-mix(in srgb, var(--warn) 8%, var(--panel));
  font-size: 13px;
}
.executor-bar.active {
  border-left-color: var(--ok);
  background: color-mix(in srgb, var(--ok) 8%, var(--panel));
}
.executor-bar-text { min-width: 0; overflow-wrap: anywhere; }
.executor-bar .muted { font-size: 12px; }
/* 待执行条目的口径说明小问号（hover 显示说明） */
.executor-bar-help {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  border: 1px solid var(--line); font-size: 10px; line-height: 1;
  color: var(--muted); cursor: help; user-select: none;
}
.exec-settings { min-width: 0; }
@media (max-width: 900px) {
  .executor-bar { font-size: 12.5px; padding: 8px 10px; gap: 6px; }
  .executor-bar .muted { font-size: 11.5px; }
}

/* ---------- 总览·定时调度（管理员） ---------- */
.sched-overview-card {
  min-width: 0;
  align-items: stretch;   /* 覆盖 .sched-card 的 flex-start，让进度条铺满卡片 */
}
.sched-ov-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; min-width: 0;
}
.sched-ov-head .k { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.sched-overview-card .s { min-width: 0; overflow-wrap: anywhere; }
.sched-ov-progress { margin: 2px 0 0; }
.sched-history {
  margin-top: 6px; font-size: 11px; line-height: 1.55; color: var(--muted);
  min-width: 0; overflow-wrap: anywhere;
}
.sched-history-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 数据管理·行情源 ---------- */
.quote-sources-card { min-width: 0; }
.source-list {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px; margin-top: 10px;
}
.source-item {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  min-width: 0; font-size: 12.5px;
}
.source-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.source-head .muted { font-size: 11.5px; }
.source-item .muted { font-size: 11.5px; overflow-wrap: anywhere; }
.dot.err { background: var(--err); }
@media (max-width: 900px) {
  .source-list { grid-template-columns: minmax(0, 1fr); }
  .sched-history-line { white-space: normal; }
}

/* ============================================================ 移动端 */
@media (max-width: 900px) {
  /* 兜底：任何页面都不出现横向滚动（真正的溢出仍按 G1 逐页修） */
  html, body { max-width: 100%; overflow-x: hidden; }
  .app { grid-template-columns: minmax(0, 1fr); height: auto; min-height: 100vh; align-content: start; }
  .app > main { min-width: 0; }
  main { padding: 12px 12px calc(86px + env(safe-area-inset-bottom, 0px)); overflow: visible; min-width: 0; }
  #view { min-width: 0; }

  /* 侧栏改为抽屉：默认移出视口，body.nav-open 时滑入 */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 93;
    width: min(78vw, 300px); height: 100%;
    /* 底部留出悬浮 ☰/✕ 按钮的空间，展开时按钮不会被用户名挡住 */
    padding: 14px 12px calc(82px + env(safe-area-inset-bottom, 0px));
    flex-direction: column; align-items: stretch; gap: 0;
    overflow-y: auto; overflow-x: hidden;
    border-right: 1px solid var(--line); border-bottom: 0;
    background: var(--panel);
    transform: translateX(-104%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    box-shadow: 0 0 60px rgba(0, 0, 0, .45);
  }
  body.nav-open .sidebar { transform: none; visibility: visible; transition: transform .22s ease; }
  body.nav-open { overflow: hidden; }
  .nav-toggle { display: inline-flex; }
  .nav-mask { display: none; }
  body.nav-open .nav-mask { display: block; }
  .quote-chip { top: auto; right: 12px; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); font-size: 11px; }

  .brand { padding: 2px 4px 14px; }
  .brand-sub { display: none; }
  nav { flex-direction: column; gap: 2px; flex: 0 0 auto; overflow: visible; }
  nav a { padding: 11px 10px; font-size: 14.5px; white-space: nowrap; min-height: 42px; }
  .nav-sep { width: auto; height: 1px; margin: 6px 10px; }
  .sidebar-foot {
    margin-top: auto; flex-shrink: 0; gap: 8px;
    padding-top: 12px; border-top: 1px solid var(--line);
  }
  #whoami { display: inline; }

  h2 { font-size: 16px; }
  .page-sub { font-size: 12.5px; margin-bottom: 12px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 10px 12px; min-width: 0; }
  .card .v { font-size: 17px; }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kv { padding: 8px 10px; min-width: 0; }
  .kv .v { font-size: 14px; }
  .strategy-grid, .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .split { grid-template-columns: minmax(0, 1fr); }
  .dash-charts { grid-template-columns: minmax(0, 1fr); }
  .form-row { gap: 8px; }
  .form-row label { flex: 1 1 100%; min-width: 0; }
  .form-row label input, .form-row label select { min-width: 0; width: 100%; }
  .param-group-label { min-width: 0; max-width: 100%; width: 100%; }
  .chart { height: 300px; }
  .chart.small { height: 240px; }
  .chart.sync-height { height: 300px; }
  .modal { width: 100%; max-height: 92vh; }
  .modal-mask { padding: 10px; }
  .modal-head, .modal-body, .modal-foot { padding: 12px 14px; }
  .scroll { max-height: 60vh; min-width: 0; max-width: 100%; }
  table { font-size: 12.5px; }
  th, td { padding: 6px 8px; }
  .variety-picker { max-height: 180px; }
  .login-card { width: 100%; padding: 22px 18px; }
  .toast {
    left: 50%; right: auto; top: auto; transform: translateX(-50%);
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    max-width: calc(100vw - 24px); padding: 12px 16px;
  }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tabs button { white-space: nowrap; }
  .toolbar { gap: 8px; }
  /* 长选项文字（如数据源名称）会把 select 的 min-content 顶宽，必须允许收缩 */
  .toolbar select, .toolbar input, .form-row select { min-width: 0; max-width: 100%; }
  select, input[type="text"], input[type="number"], input[type="date"] { max-width: 100%; }
  .calendar-grid { grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr)); }
  .quote-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quote-mini { padding: 7px 9px; }
  /* 手工交易：合约独占一行，手数 + 四个按钮一行，清仓独占一行 */
  .manual-row-top { flex-wrap: wrap; }
  .manual-row-top select { flex: 1 1 100%; width: 100%; }
  .manual-row-top .qty-wrap { flex: 1 1 auto; }
  .manual-row-top #manualMargin { flex: 0 0 auto; }
  .manual-row-inline .trade-btn { min-height: 38px; }
  .manual-panel [data-act="liquidate"] { min-height: 38px; }
  .trade-btn { min-height: 38px; }
  /* 触摸友好：按钮最小高度 32px、开关行可点区域 ≥ 36px */
  button { min-height: 32px; }
  .switch-line { min-height: 36px; }
  td.ops .switch-line { min-height: 36px; }
  .strategy-picker .switch-line { min-height: 36px; }
}

