/* vtest UI —— 暗色专业终端风格
 * 断点：
 *   ≥1180px   桌面：侧边栏固定展开（可收成图标栏）
 *   700–1179  折叠屏内屏 / 平板：68px 图标栏常驻，展开时以抽屉覆盖
 *   <700      手机：侧边栏为抽屉
 */
:root {
  --bg: #090c12;
  --side: #0c1018;
  --panel: #0f141c;
  --raised: #151b26;
  --hover: #1a2230;
  --line: #1a212d;
  --line2: #263041;
  --text: #dce3ee;
  --muted: #7a869b;
  --faint: #4c586c;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, .15);
  --accent-line: rgba(76, 141, 255, .55);
  --up: #f85149;      /* 涨：红 */
  --down: #3fb950;    /* 跌：绿 */
  --warn: #e3b341;
  --radius: 10px;
  --ctl-h: 34px;
  --rail: 68px;
  --side-full: 268px;
  --top-h: 52px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: "HarmonyOS Sans SC", "MiSans", "vivo Sans", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, "SF Mono", Menlo, monospace;
}
@media (pointer: coarse) { :root { --ctl-h: 42px; } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); font-variant-numeric: tabular-nums; -webkit-text-size-adjust: 100%; }
html, body { overflow: hidden; overscroll-behavior: none; }
h1, h2 { margin: 0; font-weight: 600; }
button { font: inherit; color: inherit; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: #29323f transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #29323f; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.pos { color: var(--up); } .neg { color: var(--down); }
.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.ic.big { width: 40px; height: 40px; stroke-width: 1.4; color: var(--faint); }

/* ------------------------------------------------------------------ 基础控件 ------ */
select, input:not([type=checkbox]):not([type=range]), .btn {
  height: var(--ctl-h); background: #0b0f16; color: var(--text); border: 1px solid var(--line2); border-radius: 8px; padding: 0 10px; font: inherit; min-width: 0;
}
select { padding-right: 6px; }
input[type=number] { appearance: textfield; -moz-appearance: textfield; }
select:focus, input:focus, .btn:focus-visible, .nav-item:focus-visible, .sym:focus-visible, .icon-btn:focus-visible {
  outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 14px; background: var(--raised); cursor: pointer; white-space: nowrap; user-select: none;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--hover); border-color: #34415a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn .ic { width: 16px; height: 16px; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
@media (pointer: coarse) { .btn.sm { height: 34px; } }
.btn.icon { padding: 0; width: var(--ctl-h); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #3f7fee; }
.btn.danger { background: transparent; border-color: #5b2227; color: #ff7b72; }
.btn.danger:hover { background: #2a1215; border-color: var(--up); }
.btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* chip：label > input[checkbox] + span */
.chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; display: inline-flex; cursor: pointer; user-select: none; }
.chip input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.chip span {
  display: inline-flex; align-items: center; height: calc(var(--ctl-h) - 4px); padding: 0 12px; border-radius: 999px; border: 1px solid var(--line2);
  background: #0b0f16; color: var(--muted); transition: all .15s; white-space: nowrap;
}
.chip:hover span { color: var(--text); border-color: #34415a; }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent-line); color: #cfe0ff; }
.chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* 开关 */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; min-height: var(--ctl-h); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 36px; height: 20px; border-radius: 999px; background: #232c3b; position: relative; transition: background .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #aab4c5; transition: transform .15s, background .15s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }

.inline-sel { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
input[type=range] { accent-color: var(--accent); height: 28px; }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }

/* ------------------------------------------------------------------ 外壳 ------ */
#app { height: 100dvh; --cm: var(--side-full); }
#content { height: 100%; margin-left: var(--cm); display: flex; flex-direction: column; min-width: 0; transition: margin-left .2s ease; padding-right: var(--sar); }
main { flex: 1; min-height: 0; position: relative; }
.tab { display: none; height: 100%; min-height: 0; }
.tab.active { display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; gap: 12px; height: calc(var(--top-h) + var(--sat)); padding: var(--sat) 14px 0 16px; flex: none;
  background: linear-gradient(180deg, #0e131b, #0b1017); border-bottom: 1px solid var(--line);
}
#topbar h1 { font-size: 16px; letter-spacing: .3px; white-space: nowrap; }
#menuBtn { display: none; margin-left: -8px; }
.ctx-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; max-width: 58%; padding: 0 10px 0 12px; border-radius: 999px;
  background: var(--raised); border: 1px solid var(--line2); cursor: pointer; color: var(--text); min-width: 0;
}
.ctx-chip:hover { background: var(--hover); }
.ctx-chip .ic { width: 16px; height: 16px; color: var(--muted); }
.ctx-main { display: inline-flex; align-items: baseline; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; }
.ctx-main b { font-weight: 600; }
.ctx-main .nm { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 11px; font-style: normal; padding: 1px 7px; border-radius: 999px; background: var(--accent-soft); color: #9ec1ff; }

/* ------------------------------------------------------------------ 侧边栏 ------ */
#side {
  position: fixed; inset: 0 auto 0 0; width: var(--rail); z-index: 40; display: flex; flex-direction: column; overflow: hidden;
  padding: var(--sat) 0 var(--sab) var(--sal); background: var(--side); border-right: 1px solid var(--line);
  transition: width .2s ease, transform .22s ease;
}
#app.full #side { width: var(--side-full); }
#scrim { position: fixed; inset: 0; z-index: 30; background: rgba(3, 6, 10, .6); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .2s; }
#app.overlay #scrim { opacity: 1; pointer-events: auto; }
#app.overlay #side { box-shadow: 14px 0 40px rgba(0, 0, 0, .55); }

.side-brand { display: flex; align-items: center; gap: 12px; height: var(--top-h); padding: 0 17px; flex: none; }
.logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: linear-gradient(135deg, #2f6bff, #7b4dff); box-shadow: 0 4px 14px rgba(76, 100, 255, .35); }
.logo svg { width: 20px; height: 20px; fill: rgba(255, 255, 255, .22); stroke: #fff; stroke-width: 1.6; stroke-linecap: round; }
.brand-txt { display: flex; flex-direction: column; line-height: 1.2; white-space: nowrap; }
.brand-txt b { font-size: 16px; letter-spacing: .5px; }
.brand-txt small { color: var(--muted); font-size: 11px; }

.side-nav { display: flex; flex-direction: column; gap: 4px; padding: 8px 12px 4px; flex: none; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; height: 46px; padding: 0 12px; border: 0; border-radius: 10px;
  background: transparent; color: var(--muted); cursor: pointer; text-align: left; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: #fff; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 11px; bottom: 11px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-item.active .ic { color: var(--accent); }
.nav-item .lbl { display: flex; flex-direction: column; line-height: 1.25; font-size: 14px; white-space: nowrap; }
.nav-item .lbl small { font-size: 11px; color: var(--faint); }
.nav-item.active .lbl small { color: #7da6e8; }

.rail-pick { display: none; margin: 6px 12px 0; height: 46px; border: 1px dashed var(--line2); border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; place-items: center; }
.rail-pick:hover { color: var(--text); border-color: #3a475f; background: var(--hover); }

.side-panel { display: none; flex-direction: column; min-height: 0; flex: 1; margin: 10px 0 0; padding: 12px 12px 0; border-top: 1px solid var(--line); gap: 10px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; padding: 0 6px; font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--faint); font-weight: 600; min-height: 28px; }
.panel-title .count { letter-spacing: 0; text-transform: none; font-weight: 400; }

.seg { display: flex; gap: 2px; padding: 3px; background: #090d13; border: 1px solid var(--line); border-radius: 10px; flex: none; }
.seg button { flex: 1; min-width: 0; height: 30px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12.5px; white-space: nowrap; padding: 0 4px; }
@media (pointer: coarse) { .seg button { height: 36px; } }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--raised); color: #fff; box-shadow: 0 1px 0 rgba(255, 255, 255, .05) inset, 0 1px 3px rgba(0, 0, 0, .4); }

.search { position: relative; display: block; flex: none; }
.search > .ic { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; margin-top: -8px; color: var(--faint); pointer-events: none; }
.search input { width: 100%; padding-left: 34px; padding-right: 34px; border-radius: 10px; }
.search input::-webkit-search-cancel-button { display: none; }
.search .clear { position: absolute; right: 4px; top: 50%; margin-top: -15px; width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.search .clear .ic { width: 14px; height: 14px; }

.list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px 12px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.list .empty-note { padding: 18px 8px; color: var(--faint); text-align: center; }

.sym, .item {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 1px solid transparent; border-radius: 9px;
  background: transparent; color: var(--text); text-align: left; cursor: pointer; min-height: 48px; transition: background .12s;
}
.sym:hover, .item:hover { background: var(--hover); }
.sym.active, .item.active { background: var(--accent-soft); border-color: rgba(76, 141, 255, .28); }
.sym:disabled { opacity: .35; cursor: not-allowed; }
.sym-main, .item-main { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.sym-main b, .item-main b { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sym-main small, .item-main small { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sym .mk { font-size: 10px; color: var(--muted); border: 1px solid var(--line2); border-radius: 4px; padding: 0 4px; margin-left: 6px; font-weight: 400; }
.cov { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; flex: none; }
.cov i { width: 3px; height: 100%; border-radius: 1px; background: #232c3a; }
.cov i.on { background: #4ea36a; }
.cov.part i.on { background: var(--warn); }

.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px 10px 18px; margin-top: auto; border-top: 1px solid var(--line); flex: none; }
.status { display: inline-flex; align-items: center; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--down); box-shadow: 0 0 0 3px rgba(63, 185, 80, .16); flex: none; }
#sideToggle .ic { transition: transform .2s; }
#app.full #sideToggle .ic { transform: rotate(180deg); }

/* 侧边栏：窄栏（图标栏）*/
#app:not(.full) .brand-txt, #app:not(.full) .nav-item .lbl, #app:not(.full) .side-panel, #app:not(.full) .status { display: none; }
#app:not(.full) .side-brand { padding: 0; justify-content: center; }
#app:not(.full) .side-nav { padding: 8px 10px 4px; }
#app:not(.full) .nav-item { justify-content: center; padding: 0; }
#app:not(.full) .nav-item.active::before { left: -10px; }
#app:not(.full) .rail-pick { display: grid; margin-left: 10px; margin-right: 10px; }
#app:not(.full) .side-foot { justify-content: center; padding: 8px 0 10px; }
/* 展开时：只显示当前页面相关的面板 */
#app.full #panelSym { display: flex; }
#app.full #panelInst { display: none; }
body[data-tab="bt"] #app.full #panelSym { display: none; }
body[data-tab="bt"] #app.full #panelInst { display: flex; }
body[data-tab="bt"] .ctx-chip .ctx-main .nm:empty { display: none; }
body[data-tab="ind"] #app.full #panelSym, body[data-tab="stg"] #app.full #panelSym { display: none; }
body[data-tab="ind"] #app.full #panelLib, body[data-tab="stg"] #app.full #panelLib { display: flex; }
.ctx-chip .ctx-main .nm:empty { display: none; }

/* 断点：侧边栏与内容区的关系 */
@media (min-width: 1180px) {
  #app { --cm: var(--side-full); }
  #app:not(.full) { --cm: var(--rail); }
}
@media (min-width: 700px) and (max-width: 1179.98px) {
  #app { --cm: var(--rail); }
}
@media (max-width: 699.98px) {
  #app { --cm: 0px; }
  #side { width: min(86vw, 320px); }
  #app.full #side { width: min(86vw, 320px); }
  #app:not(.full) #side { transform: translateX(-100%); box-shadow: none; }
  #menuBtn { display: inline-grid; }
  #topbar { padding-left: 12px; }
  #topbar h1 { font-size: 15px; }
  .ctx-chip { max-width: 62%; }
  #topHint { display: none; }
}

/* ------------------------------------------------------------------ 通用面板 ------ */
.panel, .card-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.card-box { min-width: 0; min-height: 0; overflow: hidden; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 8px 14px; flex: none; }
.legend { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; color: var(--muted); font-size: 12px; }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.lg i { width: 14px; height: 3px; border-radius: 2px; }
.lg i.dash { height: 0; background: none; border-top: 2px dashed var(--c); }

/* ------------------------------------------------------------------ 行情总览 ------ */
#grid6 {
  flex: 1; min-height: 0; display: grid; gap: 8px; padding: 0 12px 12px; overflow-y: auto;
  grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(2, minmax(220px, 1fr));
}
#grid6 > div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); min-height: 0; min-width: 0; overflow: hidden; touch-action: none; }
@media (max-width: 1179.98px) {
  /* 折叠屏内屏近似方形：2 列 × 3 行 */
  #grid6 { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(210px, 1fr)); }
}
@media (max-width: 699.98px) {
  #grid6 { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-rows: 280px; padding: 0 10px calc(12px + var(--sab)); }
  #grid6 > div { touch-action: pan-y; }   /* 手机单列：竖滑翻页，横滑才是图表平移 */
  .hide-sm { display: none; }
}

/* ------------------------------------------------------------------ 弹层 / 抽屉 ------ */
.pop-wrap { position: relative; display: inline-flex; }
.pop-menu {
  position: absolute; z-index: 20; display: none; flex-direction: column; gap: 12px; padding: 14px; min-width: 220px;
  background: #121926; border: 1px solid var(--line2); border-radius: 12px; box-shadow: 0 18px 50px rgba(0, 0, 0, .6);
}
.pop-menu.open { display: flex; }
.pop-menu.up { bottom: calc(100% + 10px); right: 0; }
.pop-menu.down { top: calc(100% + 6px); left: 12px; right: 12px; max-width: 620px; }
.pop-menu label { display: flex; align-items: center; justify-content: space-between; gap: 14px; color: var(--muted); }
.pop-menu select { min-width: 110px; }
.pop-sec { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; }
.pop-hint { margin-top: -2px; }
[data-pop].on { background: var(--accent-soft); border-color: var(--accent-line); color: #cfe0ff; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.badge:empty { display: none; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.scroll-x { overflow-x: auto; flex-wrap: nowrap !important; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.scroll-x .chip { flex: none; }

/* ------------------------------------------------------------------ 回放控制条（固定高度，贴在图表下方）------ */
.dock { flex: none; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px 6px; background: #101620; border-top: 1px solid var(--accent-line); }
.dock.hidden { display: none !important; }
.dock-row { display: flex; align-items: center; gap: 8px; min-width: 0; height: var(--ctl-h); }
.dock-row.meta { height: 20px; gap: 12px; font-size: 12px; color: var(--muted); }
.dock .btn.play { min-width: 66px; }
.dock input[type=range] { flex: 1; min-width: 60px; height: 30px; }
.rb-time { flex: none; white-space: nowrap; font-size: 12px; color: var(--text); }
.replay-status { flex: 1; min-width: 0; display: flex; gap: 6px; overflow: hidden; white-space: nowrap; font-size: 12px; text-align: left; }
.replay-status .tag { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; padding: 1px 9px; border-radius: 6px; background: #1b2332; border: 1px solid var(--line2); color: var(--text); }
.replay-status .hold { color: var(--warn); }
#lrEnter.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ------------------------------------------------------------------ 指标实验室 ------ */
#tab-lab { position: relative; overflow: hidden; }
.lab-bar { position: relative; display: flex; align-items: center; gap: 8px; padding: 6px 12px; flex: none; }
.lab-bar #labPeriods { flex: 1; min-width: 0; padding: 2px 0; }
.lab-bar .btn { flex: none; }
.g-label { width: 34px; flex: none; font-size: 11px; letter-spacing: 1px; color: var(--faint); font-weight: 600; }
.inline-sel { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }

/* 图表区撑满剩余高度，不再整页滚动 */
#labCharts { display: grid; flex: 1; min-height: 0; touch-action: none; }
#labCharts > .cell { min-height: 0; min-width: 0; touch-action: none; }
#labCharts.multi { gap: 8px; padding: 0 12px 8px; }
#labCharts.multi > .cell { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
#labCharts:not(.multi) { padding: 0 6px; }
/* 状态行：单行定高，文字变化不会改变图表尺寸 */
#labInfo { flex: none; height: 26px; line-height: 26px; padding: 0 14px; margin-bottom: var(--sab); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lrBar:not(.hidden) ~ #labInfo { display: none; }
#lrBar { margin: 0 12px calc(8px + var(--sab)); border: 1px solid var(--accent-line); border-radius: var(--radius); }
@media (max-width: 699.98px) { .lab-bar .btn:not(.icon) { padding: 0 10px; } #lrEnter { font-size: 0; gap: 0; width: var(--ctl-h); padding: 0; } #lrEnter .ic { width: 18px; height: 18px; } }

/* ------------------------------------------------------------------ 策略回测：K 线为主 ------ */
#tab-bt { position: relative; overflow: hidden; }
.empty { margin: auto; max-width: 340px; padding: 32px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.empty b { font-size: 16px; }
.empty p { margin: 0 0 8px; }
#btEmptyPick { display: none; }
@media (max-width: 1179.98px) { #btEmptyPick { display: inline-flex; } }

/* 整体固定在一屏内：顶部信息 → 主图（弹性撑满）→ 底部结果区。屏幕过矮时才出现滚动 */
#btWork { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 8px; padding: 6px 12px calc(10px + var(--sab)); overflow-y: auto; }
#btWork > * { flex: none; }
.bt-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-width: 0; }
.bt-title { min-width: 0; flex: 1; }
.bt-title h2 { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bt-actions { display: flex; gap: 8px; flex: none; }
#instReplay.replay-wait { opacity: .55; border-style: dashed; }

/* 绩效指标：单行横向滑动，不占多行高度 */
#btCards { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
#btCards::-webkit-scrollbar { display: none; }
#btCards:empty { display: none; }
.card { flex: 1 0 auto; min-width: 88px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 12px; }
.card b { display: block; font-size: 15px; font-weight: 600; line-height: 1.3; }
.card span { color: var(--muted); font-size: 11px; white-space: nowrap; }

.chart-card { flex: 1 1 0 !important; min-height: 280px; display: flex; flex-direction: column; }
#btChart { flex: 1; min-height: 0; touch-action: none; }
.chart-card .dock { border-radius: 0; }

.bt-lower { display: flex; flex-direction: column; flex: none; }
.lower-tabs { display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.lower-tabs::-webkit-scrollbar { display: none; }
.lower-tabs > * { flex: none; }
.lower-tabs > .spacer { flex: 1 0 0; }
.lower-tabs > button:not(.icon-btn) { height: 32px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; white-space: nowrap; }
@media (pointer: coarse) { .lower-tabs > button:not(.icon-btn) { height: 38px; } }
.lower-tabs > button.on { background: var(--raised); color: #fff; }
.lower-tabs .icon-btn { width: 32px; height: 32px; }
.lower-tabs .icon-btn .ic { transition: transform .2s; }
.bt-lower.collapsed .lower-tabs .icon-btn .ic { transform: rotate(180deg); }
.bt-lower.collapsed .lower-tabs { border-bottom: 0; }
.bt-lower.collapsed .lower-body { display: none; }
.lower-body { height: clamp(150px, 24vh, 250px); position: relative; }
.bt-lower.replaying .lower-body { height: clamp(118px, 17vh, 170px); }   /* 回放时变矮，K 线仍是主视角 */
tbody tr.holding { background: rgba(227, 179, 65, .08); }
tbody tr.holding td:last-child { color: var(--warn); }
tbody tr.none { cursor: default; }
.lower-tabs > button .muted { font-size: 11.5px; }
.lpane { display: none; position: absolute; inset: 0; }
.lpane.on { display: block; }
#btEquity { height: 100%; touch-action: none; }
.scroll { overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { position: sticky; top: 0; background: #131a25; color: var(--muted); font-weight: 500; z-index: 1; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
@media (max-width: 699.98px) { .bt-actions .btn:not(#instRun) { padding: 0 10px; } }
@media (max-height: 760px) { .lower-body { height: 130px; } }

/* 实例参数抽屉 */
#sheetScrim, .sheet-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(3, 6, 10, .55); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .2s; }
#sheetScrim.open, .sheet-scrim.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; width: min(460px, 94vw); display: flex; flex-direction: column;
  padding: var(--sat) var(--sar) var(--sab) 0; background: var(--panel); border-left: 1px solid var(--line2); box-shadow: -18px 0 50px rgba(0, 0, 0, .55);
  transform: translateX(105%); visibility: hidden; transition: transform .22s ease, visibility 0s .22s;
}
.sheet.open { transform: none; visibility: visible; transition: transform .22s ease; }
.sheet-head { display: flex; align-items: center; height: var(--top-h); padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); flex: none; font-size: 15px; }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.sheet-foot { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); flex: none; background: #0d121a; }
.sub-title { margin-top: 6px; font-size: 11px; letter-spacing: 1.2px; color: var(--faint); font-weight: 600; text-transform: uppercase; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.form-grid:empty { display: none; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; min-width: 0; }
.form-grid label input:not([type=checkbox]), .form-grid label select { width: 100%; color: var(--text); font-size: 13px; }
.form-grid label.check, .form-grid label:has(> input[type=checkbox]) {
  flex-direction: row; align-items: center; justify-content: space-between; padding: 0 12px; height: var(--ctl-h); margin-top: auto; border: 1px solid var(--line2); border-radius: 8px; background: #0b0f16;
}
.form-grid label.check { grid-column: 1 / -1; }
@media (max-width: 420px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* ------------------------------------------------------------------ 指标管理 / 策略管理 ------ */
#tab-lib { position: relative; overflow: hidden; }
.lib-page { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 8px 12px calc(12px + var(--sab)); overflow-y: auto; }
.lib-page > * { flex: none; }
.lib-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lib-page .sub-title.pad { margin: 0; padding: 11px 12px 0; }

/* 状态标签 */
.st { display: inline-flex; align-items: center; gap: 6px; flex: none; height: 22px; padding: 0 9px; border-radius: 999px; border: 1px solid var(--line2); background: #1b2332; color: var(--muted); font-size: 11.5px; font-style: normal; white-space: nowrap; }
.st.ok { color: #7ee2a0; border-color: rgba(63, 185, 80, .35); background: rgba(63, 185, 80, .08); }
.st.warn { color: var(--warn); border-color: rgba(227, 179, 65, .35); background: rgba(227, 179, 65, .08); }
.st.err { color: #ff8f88; border-color: rgba(248, 81, 73, .4); background: rgba(248, 81, 73, .08); }
.st.run { color: #9ec1ff; border-color: var(--accent-line); background: var(--accent-soft); }
.st.run::before, .mini.run { animation: blink 1.2s ease-in-out infinite; }
.st.run::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
@keyframes blink { 50% { opacity: .25; } }
.mini { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--warn); }
.mini.run { background: var(--accent); }
.mini.err { background: var(--up); }
.dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(227, 179, 65, .16); }
.dot.off { background: var(--faint); box-shadow: none; }
.warn-text { color: var(--warn); }

.notice { padding: 9px 12px; border-radius: 8px; border: 1px solid rgba(227, 179, 65, .35); background: rgba(227, 179, 65, .08); color: #e9cf8b; font-size: 12.5px; overflow-wrap: anywhere; }
.notice.err { border-color: rgba(248, 81, 73, .4); background: rgba(248, 81, 73, .08); color: #ff9c95; }

/* 总览：文件列表 */
a.btn { text-decoration: none; }
a.btn:not([href]) { opacity: .55; cursor: default; }
.lib-rows, .tasks { display: flex; flex-direction: column; }
.lib-rows .empty-note, .tasks .empty-note { padding: 18px 12px; color: var(--faint); text-align: center; }
.lib-row {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr) 124px 108px; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 9px 14px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; cursor: pointer; transition: background .12s;
}
.lib-row:last-child { border-bottom: 0; }
.lib-row:hover { background: var(--hover); }
.lib-row:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft) inset; }
.lib-row > .st { justify-self: end; }
.lr-main { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.lr-main b { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-main small { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lr-codes { display: flex; flex-wrap: wrap; gap: 4px 6px; min-width: 0; }
.lr-meta { color: var(--muted); font-size: 11.5px; line-height: 1.4; text-align: right; white-space: nowrap; }
.code-chip { display: inline-block; max-width: 100%; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line2); background: #0b0f16; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.code-chip code, .def-head code { margin-right: 6px; color: #9ec1ff; font-family: var(--mono); }
.lib-sep, .list-sep { font-size: 11px; letter-spacing: 1px; color: var(--faint); font-weight: 600; }
.lib-sep { padding: 9px 14px 7px; background: #0c1119; border-bottom: 1px solid var(--line); }
.list-sep { padding: 12px 10px 4px; }
@media (max-width: 699.98px) {
  .lib-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; }
  .lr-codes { grid-column: 1 / -1; order: 3; }
  .lr-codes:empty, .lr-meta { display: none; }
  #libConsole span { display: none; }
}

/* Agent 任务 */
.task { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task-main { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.task-main b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-main small { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 详情：宽屏左栏（提交 Agent / 任务 / 登记信息）+ 右侧源码，各自滚动；窄屏上下排，整页滚动 */
.lib-page > .lib-cols { flex: 1 1 0; min-height: 0; display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 10px; }
.lib-col { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; }
.lib-col > * { flex: none; }
.agent-box { display: flex; flex-direction: column; gap: 10px; }
form.agent-box { padding: 12px; }
.agent-box .sub-title { margin: 0; }
#agentTitle { text-transform: none; }
textarea { width: 100%; min-height: 96px; resize: vertical; padding: 9px 10px; border: 1px solid var(--line2); border-radius: 8px; background: #0b0f16; color: var(--text); font: inherit; line-height: 1.5; }
textarea:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea::placeholder, input::placeholder { color: var(--faint); }
.pass-row { display: flex; align-items: center; gap: 10px; }
.pass-row .agent-pass { flex: 1; }
.remember { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; cursor: pointer; }
.agent-foot { display: flex; align-items: center; gap: 10px; }
.agent-foot .agent-hint { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 12px; }
.field input, .field textarea { color: var(--text); font-size: 13px; }
.suffix-input { display: flex; align-items: center; gap: 8px; }
.suffix-input input { flex: 1; font-family: var(--mono); }
.suffix-input em { font-style: normal; color: var(--faint); font-family: var(--mono); }

.defs { display: flex; flex-direction: column; gap: 14px; padding: 8px 12px 12px; }
.def-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.def-head code { margin: 0; font-size: 13px; }
.def p { margin: 4px 0 0; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px 12px; margin: 8px 0 0; font-size: 12px; }
.kv dt { color: var(--faint); white-space: nowrap; }
.kv dd { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; min-width: 0; color: var(--muted); }
.kv code, .prow code { padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line2); background: #0b0f16; color: var(--text); font-family: var(--mono); font-size: 11.5px; }
.prow { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 10px; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 12px; }
.prow code { margin-right: 6px; }

.code-box { display: flex; flex-direction: column; min-height: 0; }
.code-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; padding: 9px 14px; border-bottom: 1px solid var(--line); flex: none; }
.code { flex: 1; min-height: 0; margin: 0; padding: 8px 0; overflow: auto; overscroll-behavior: contain; counter-reset: ln; tab-size: 4; font: 12.5px/1.6 var(--mono); color: #c9d4e3; }
.code .l { counter-increment: ln; }
.code .l::before { content: counter(ln); position: sticky; left: 0; display: inline-block; width: 50px; margin-right: 12px; padding-right: 10px; border-right: 1px solid var(--line); background: var(--panel); color: var(--faint); text-align: right; user-select: none; }
.code i { font-style: normal; }
.t-c { color: #62718a; }
.t-s { color: #9ecb8a; }
.t-k { color: #7fb0ff; }
.t-d { color: var(--warn); }
.t-n { color: #e0a36a; }
@media (max-width: 899.98px) {
  .lib-page > .lib-cols { flex: none; display: flex; flex-direction: column; }
  .lib-col { display: contents; }
  .lib-cols > *, .lib-col > * { order: 3; }
  #agentForm { order: 1; }
  .revs-box { order: 2; }
  .lib-cols > .code-box { order: 2; }
  .code { max-height: 70vh; }
  .code-box { scroll-margin-top: 8px; }
  .code.diff .dl { white-space: pre-wrap; overflow-wrap: anywhere; }
}

/* 版本 / 修订历史 */
.revs { display: flex; flex-direction: column; }
.revs .empty-note { padding: 14px 12px; color: var(--faint); text-align: center; font-size: 12.5px; }
.rev-row { display: flex; align-items: center; gap: 10px; width: 100%; min-width: 0; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; cursor: pointer; transition: background .12s; }
.rev-row:last-child { border-bottom: 0; }
.rev-row:hover { background: var(--hover); }
.rev-row.active { background: var(--accent-soft); box-shadow: 3px 0 0 var(--accent) inset; }
.rev-row:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft) inset; }
.rev-row code { margin-right: 7px; color: #9ec1ff; font-family: var(--mono); font-size: 12px; }
.rev-box { display: flex; flex-direction: column; gap: 9px; padding: 11px 12px 12px; border-top: 1px solid var(--line2); background: #0c1119; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; height: 26px; padding: 0 9px; border-radius: 7px; border: 1px solid var(--line2); background: #0b0f16; color: var(--text); font: 12px var(--mono); cursor: pointer; white-space: nowrap; overflow: hidden; }
.file-chip:hover { border-color: #34415a; }
.file-chip.on { border-color: var(--accent-line); background: var(--accent-soft); }
.file-chip b { font: 600 11px var(--font); color: var(--warn); }
.file-chip i, #codeMeta i { font-style: normal; }
.rev-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.rev-actions .spacer { flex: 1; }
.notice.ok { border-color: rgba(63, 185, 80, .35); background: rgba(63, 185, 80, .08); color: #9be3b0; white-space: pre-wrap; }
.rev-box .notice.err { white-space: pre-wrap; max-height: 220px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.code-chip.draft { color: var(--warn); border-color: rgba(227, 179, 65, .35); background: rgba(227, 179, 65, .06); }
.code-head { align-items: center; }
.code-head .seg { padding: 2px; }
.code-head .seg button { height: 26px; padding: 0 12px; flex: none; }
.code.diff { padding: 8px 0; }
.code .dl { display: inline-block; min-width: 100%; padding: 0 14px; }
.code .dl.add { background: rgba(63, 185, 80, .13); color: #aee9bf; }
.code .dl.del { background: rgba(248, 81, 73, .13); color: #ffb3ad; }
.code .dl.hunk { color: #7fb0ff; background: rgba(76, 141, 255, .08); }
.code .dl.file { color: var(--faint); }

/* 版本下拉框（指标实验室顶栏） */
.rev-sel { flex: none; min-width: 0; }
.rev-sel select { max-width: 230px; }
.rev-sel.on select { border-color: rgba(227, 179, 65, .55); color: var(--warn); }
@media (max-width: 699.98px) { .rev-sel > span { display: none; } .rev-sel select { max-width: 118px; } }

/* 回测记录 */
.run-info:empty { display: none; }
.run-info b { margin-right: 6px; font-weight: 600; color: var(--text); }
.run-info b.warn-text { color: var(--warn); }
th.tl, td.tl { text-align: left; }
td.params { max-width: 320px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
#runTable tr.cur { background: var(--accent-soft); box-shadow: 3px 0 0 var(--accent) inset; }
#runTable .icon-btn { width: 24px; height: 24px; }
#runTable .icon-btn .ic { width: 14px; height: 14px; }
#runTable .icon-btn:hover { color: #ff7b72; }

/* ------------------------------------------------------------------ 登录 ------ */
/* 盖住整个页面（抽屉 60 之上、Toast 99 之下）；顶栏右侧的用户名按钮点了退出登录 */
.login { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px; background: var(--bg); overflow-y: auto; }
.login-box { width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px 24px 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-box .btn { height: 40px; margin-top: 4px; }
.login-box .muted { text-align: center; }
.user-btn { max-width: 40%; color: var(--muted); }
.user-btn .ic { width: 14px; height: 14px; }

/* ------------------------------------------------------------------ Toast ------ */
/* 只盖在顶部标题栏范围内（不挡周期 / 时间栏、图表、底部工具栏）；多条消息叠放，最新的在上 */
#toasts { position: fixed; right: calc(10px + var(--sar)); top: calc(var(--sat) + 4px); width: min(560px, calc(100vw - 20px)); height: calc(var(--top-h) - 8px); z-index: 99; pointer-events: none; }
.toast { position: absolute; inset: 0; display: flex; align-items: center; background: #1a2130; border: 1px solid var(--line2); border-left: 4px solid var(--accent); padding: 0 12px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); transition: opacity .4s; pointer-events: auto; overflow: hidden; font-size: 13px; line-height: 17px; }
.toast > span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.toast.err { border-left-color: var(--up); }
.toast.ok { border-left-color: var(--down); }
.toast b { margin-right: 8px; }
@media (max-width: 699.98px) { #toasts { left: 10px; right: 10px; width: auto; } }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
