:root {
  --bg: #0b0f14; --panel: #121821; --panel2: #18202b; --line: #233041; --text: #d6dde6; --muted: #8a97a6;
  --up: #26a69a; --down: #ef5350; --accent: #2b6cb0; --warn: #d69e2e;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 13px; }
button, input, select { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 4px 8px; }
button { cursor: pointer; } button:hover { border-color: #3b4d63; } button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); }
button.ghost { background: transparent; }
input:focus, select:focus { outline: 1px solid var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: #ff7b72; min-height: 1em; } .warn { color: var(--warn); font-size: 12px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 4px 0; } .row.end { justify-content: flex-end; }
label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
label.chk { flex-direction: row; align-items: center; gap: 4px; color: var(--text); }
.btn { display: inline-flex; align-items: center; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; background: var(--panel2); color: var(--text); cursor: pointer; }
.w4 { width: 4em; }

.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 10px; }
.card h2, .card h3 { margin: 0; }

#app { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; margin-right: 8px; }
.views { display: flex; gap: 2px; margin-right: auto; }
.views button { background: transparent; border-color: transparent; white-space: nowrap; }
.views button.active { border-color: var(--accent); background: rgba(43,108,176,.2); }
.status { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; } .dot.on { background: var(--up); } .dot.busy { background: var(--warn); }
.auto.on { background: #23614f; } .auto.off { background: #6e2a2a; }

.terminal { flex: 1; min-height: 0; display: grid; grid-template-columns: 296px 1fr; grid-template-rows: 1fr 260px auto; grid-template-areas: "watch center" "bottom bottom" "acct acct"; }
.watch { grid-area: watch; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.search { display: flex; gap: 4px; padding: 6px; } .search input { flex: 1; min-width: 0; }
.watch .qwrap { flex: 1; overflow: auto; min-height: 0; padding: 0 6px; }   /* 表格铺满面板宽度,与上方搜索栏左右对齐 */
.center { grid-area: center; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 8px; align-items: center; padding: 5px 8px; flex-wrap: wrap; border-bottom: 1px solid var(--line); }
.toolbar .sym { font-weight: 700; min-width: 70px; }
.tfs button { padding: 2px 7px; margin-right: 1px; } .tfs button.active { background: var(--accent); border-color: var(--accent); }
.chartWrap { flex: 1; min-height: 160px; position: relative; }
#chart { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.orderbar { display: flex; gap: 6px; align-items: flex-end; padding: 6px 8px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.orderbar input { width: 84px; }
button.sell { background: #8e2f2f; border-color: #8e2f2f; min-width: 120px; } button.buy { background: #23614f; border-color: #23614f; min-width: 120px; }
.bottom { grid-area: bottom; border-top: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 4px 6px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border-radius: 4px 4px 0 0; border-bottom: none; background: transparent; }
.tabs button.active { background: var(--panel2); border-color: var(--line); }
.tabbody { flex: 1; overflow: auto; padding: 6px; min-height: 0; }
.acct { grid-area: acct; padding: 5px 10px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); white-space: nowrap; overflow-x: auto; }
.acct b { color: var(--text); font-weight: 500; margin-right: 14px; }

table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.grid th { position: sticky; top: 0; background: var(--panel); color: var(--muted); font-weight: 500; text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 4px 6px; border-bottom: 1px solid #1a2330; white-space: nowrap; }
.grid tbody tr:hover { background: #17202b; } .grid tr.sel { background: #1d3550; }
.grid td.up, .up { color: var(--up); } .grid td.down, .down { color: var(--down); }
.grid td button { padding: 1px 6px; font-size: 12px; }

.ea { display: grid; grid-template-columns: 230px 1fr 300px; gap: 8px; }
.list { list-style: none; margin: 0; padding: 0; overflow: auto; }
.list li { padding: 5px 6px; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.list li:hover { background: #17202b; } .list li.sel { background: #1d3550; }
.list li .x { opacity: .6; } .list li .x:hover { opacity: 1; color: var(--down); }
#eaInfo { white-space: pre-wrap; margin: 0 0 6px; font-size: 12px; }
#eaInputs input { width: 100%; min-width: 80px; }
.logs { margin: 0; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; }

.tester { flex: 1; min-height: 0; display: grid; grid-template-columns: 430px 1fr; }
.tset { border-right: 1px solid var(--line); padding: 10px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.tset h4 { margin: 10px 0 2px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#tInputs input { width: 100%; min-width: 50px; } #tInputs td { padding: 2px 3px; }
.progress { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; } #tBar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.tres { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.report { margin: 0; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre; }
#tCurve { width: 100%; height: 100%; min-height: 300px; display: block; }

#toast { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 6px; z-index: 100; max-width: min(420px, calc(100vw - 32px)); }
#toast div { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 8px 12px; border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,.4); }
#toast div.bad { border-left-color: var(--down); }

/* 手机 / 窄屏 */
@media (max-width: 900px) {
  .terminal { display: flex; flex-direction: column; overflow: auto; }
  .watch { border-right: none; height: 230px; flex: none; }
  .center { flex: none; }
  .chartWrap { height: 340px; flex: none; }
  .bottom { height: 420px; flex: none; }   /* 固定高度,表格在面板内部滚动 */
  .acct { flex: none; }
  .ea { grid-template-columns: 1fr; }
  .tester { display: flex; flex-direction: column; overflow: auto; }
  .tset { border-right: none; }
  .tres { min-height: 500px; }
  header .brand { display: none; }
}

/* 权限 / 用户 */
.noperm { display: none !important; }
.seg { display: flex; gap: 0; } .seg button { flex: 1; border-radius: 0; } .seg button:first-child { border-radius: 4px 0 0 4px; } .seg button:last-child { border-radius: 0 4px 4px 0; }
.seg button.active { background: var(--accent); border-color: var(--accent); }
.okmsg { color: var(--up); min-height: 1em; }
.me { position: relative; }
.menu { position: absolute; right: 0; top: 110%; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; display: flex; flex-direction: column; z-index: 60; min-width: 120px; padding: 4px; }
.menu button { background: transparent; border: none; text-align: left; }
.menu button:hover { background: var(--panel2); }
.badge { display: inline-block; background: var(--down); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
textarea { font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; resize: vertical; }

/* AI 助手 */
.aiv { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px 1fr; }
.aiside { border-right: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.quick { display: flex; flex-wrap: wrap; gap: 4px; } .quick button { font-size: 12px; }
.aimain { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.aihead { padding: 8px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.aimsgs { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.aiempty { margin: auto; max-width: 420px; text-align: center; }
.msg { max-width: 900px; padding: 8px 12px; border-radius: 8px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: #1d3550; white-space: pre-wrap; }
.msg.assistant { background: var(--panel); border: 1px solid var(--line); }
.msg.error { background: #3a1d1d; color: #ffb4ab; } .msg.info { color: var(--muted); font-size: 12px; }
.msg pre { background: #0b0f14; padding: 8px; border-radius: 4px; overflow: auto; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; }
.msg code { font-family: ui-monospace, Menlo, Consolas, monospace; background: #0b0f14; padding: 0 3px; border-radius: 3px; }
.msg h3, .msg h4 { margin: 6px 0 2px; } .msg ul { margin: 4px 0; padding-left: 20px; } .msg p { margin: 4px 0; }
.tool { font-size: 12px; border: 1px dashed var(--line); border-radius: 6px; padding: 4px 8px; color: var(--muted); max-width: 900px; }
.tool summary { cursor: pointer; } .tool.err { border-color: var(--down); }
.tool pre { white-space: pre-wrap; max-height: 300px; overflow: auto; font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace; margin: 4px 0; color: var(--text); }
.aiinput { display: flex; gap: 8px; padding: 8px 12px; border-top: 1px solid var(--line); }
.aiinput textarea { flex: 1; min-height: 60px; } .aiinput .col { display: flex; flex-direction: column; gap: 6px; }

/* AI 交易 */
.aitv { flex: 1; min-height: 0; display: flex; }
.aitl { flex: 1; overflow: auto; padding: 10px; min-width: 0; }
.aitr { width: 400px; border-left: 1px solid var(--line); padding: 10px; overflow: auto; }
#stForm { display: flex; flex-direction: column; gap: 6px; }
.mode-auto { color: var(--down); } .mode-confirm { color: var(--warn); } .mode-suggest { color: var(--muted); }
#decList td:nth-child(3), #decList td:nth-child(4), #propList td:nth-child(4) { white-space: normal; min-width: 200px; }

/* 管理后台 */
.admin { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.admin .tabbody { padding: 10px; }
.prov { border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin-bottom: 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; align-items: end; }
.prov .wide { grid-column: 1 / -1; }
.aiglobal { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; align-items: end; max-width: 1000px; }
#admUsers select, #admUsers input { padding: 2px 4px; } #admUsers input { width: 110px; }

@media (max-width: 900px) {
  .aiv { display: flex; flex-direction: column; overflow: auto; }
  .aiside { border-right: none; flex: none; max-height: 260px; }
  .aimain { min-height: 520px; flex: none; height: 75vh; }
  .aitv { flex-direction: column; overflow: auto; }
  .aitr { width: auto; border-left: none; border-top: 1px solid var(--line); }
  .aitl { overflow: visible; }
  .aitl table, .admin .tabbody table { display: block; overflow-x: auto; }
  .views { width: 100%; overflow-x: auto; flex-wrap: nowrap; margin-right: 0; }
}

/* ---------- 右键菜单(MT5 风格) ---------- */
.ctx { position: fixed; z-index: 200; min-width: 190px; background: var(--panel); border: 1px solid #2c3b4f; border-radius: 6px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.55); user-select: none; }
.ctx .mi { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 4px; cursor: default; white-space: nowrap; position: relative; outline: none; }
.ctx .mi:hover, .ctx .mi:focus, .ctx .mi:has(> .ctx) { background: var(--accent); color: #fff; }
.ctx .mi.dis { opacity: .4; pointer-events: none; }
.ctx .mi.danger:not(:hover):not(:focus) .lb { color: #ff8a80; }
.ctx .ic { width: 16px; text-align: center; flex: none; font-size: 12px; }
.ctx .lb { flex: 1; }
.ctx .kb { color: var(--muted); font-size: 11px; margin-left: 16px; }
.ctx .mi:hover .kb, .ctx .mi:focus .kb { color: #dbe7f5; }
.ctx .sep { height: 1px; background: var(--line); margin: 4px 2px; }

/* ---------- 统一窗口 ---------- */
.card.dlg { padding: 0; gap: 0; max-width: 420px; max-height: calc(100vh - 32px); box-shadow: 0 12px 40px rgba(0,0,0,.6); }
.card.dlg.wide { max-width: 640px; } .card.dlg.xwide { max-width: 980px; }
.dlghead { display: flex; align-items: center; gap: 8px; padding: 7px 8px 7px 14px; background: var(--panel2); border-bottom: 1px solid var(--line); border-radius: 8px 8px 0 0; cursor: default; user-select: none; }
.dlghead b { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dlghead .x { background: transparent; border: none; color: var(--muted); padding: 2px 8px; }
.dlghead .x:hover { color: #fff; background: #8e2f2f; }
.dlgbody { padding: 14px; display: flex; flex-direction: column; gap: 10px; overflow: auto; min-height: 0; }
.dlgerr { padding: 0 14px; } .dlgerr:empty { display: none; }
.dlgfoot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlgfoot:empty { display: none; }
.dlgfoot button { min-width: 76px; }
.dlgmsg { margin: 0; white-space: pre-wrap; line-height: 1.6; }
button.danger { background: #8e2f2f; border-color: #8e2f2f; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; }
.srcview { margin: 0; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; white-space: pre; overflow: auto; max-height: 65vh; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 8px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; } .kv dt { color: var(--muted); } .kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* 新订单窗口 */
.ordq { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; text-align: center; }
.ordq div { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 4px; }
.ordq span { display: block; font-size: 12px; color: var(--muted); }
.ordq b { font-size: 22px; font-variant-numeric: tabular-nums; }
.ordq .bid b { color: var(--down); } .ordq .ask b { color: var(--up); }
.volrow { display: flex; gap: 4px; } .volrow input { flex: 1; min-width: 0; text-align: center; } .volrow button { width: 34px; padding: 4px 0; }
.dlgfoot .sell, .dlgfoot .buy { flex: 1; min-width: 0; }
.grid tbody tr { cursor: default; }
.eaprops td input, .eaprops td select { width: 100%; min-width: 90px; }
@media (max-width: 900px) { .dlgfoot button { flex: 1; } }
.grp { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px 10px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.grp legend { color: var(--muted); padding: 0 4px; font-size: 12px; }
.lab { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
