:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel-2: #1a2331;
  --line: #243044;
  --text: #e6edf7;
  --muted: #8296b0;
  --green: #26c281;
  --red: #e5544b;
  --accent: #3d8bfd;
  --amber: #f0a92e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

/* =============================================================== header */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 10px 18px;
  background: linear-gradient(90deg, #101827, #16233a);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { font-size: 16px; font-weight: 700; letter-spacing: 2px; margin-right: 4px; }

/* ================================================================ layout */
.layout {
  display: grid;
  gap: 12px;
  padding: 12px 18px 24px;
  /* 第一行（行情 / K线 / 订单簿 / 交易窗口）的高度，比组件自然高度高约 50% */
  --top-row-height: 537px;
  /* 第二行（监控与研究窗口）至少与最高的导航页等高：
     高度定下来后，实时推送的日志、风控表格、量化面板都能用满窗口，
     切换导航页时窗口高度也不再跳动。 */
  --ops-row-height: 563px;
  grid-template-columns: minmax(200px, 0.8fr) minmax(340px, 1.35fr) minmax(220px, 0.95fr) minmax(290px, 1.15fr);
  grid-template-rows: minmax(var(--top-row-height), auto) minmax(var(--ops-row-height), auto);
  grid-template-areas:
    "markets chart  book  trade"
    "ops     ops    ops   ops";
  align-items: stretch;
  position: relative;
}

.area-markets { grid-area: markets; }
.area-chart { grid-area: chart; }
.area-book { grid-area: book; }
/* 下单 / 持仓 / 挂单 / 账户详情 / 模拟盘 —— 同一窗口的五个导航页 */
.area-trade { grid-area: trade; }
/* 实时推送 / 风控 / 量化交易 —— 同一窗口的三个导航页 */
.area-ops { grid-area: ops; }

@media (max-width: 1400px) {
  .layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
    grid-template-areas:
      "chart   chart"
      "markets book"
      "trade   trade"
      "ops     ops";
  }
}

@media (max-width: 820px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-template-areas:
      "chart" "markets" "book"
      "trade" "ops";
  }
}

/* ====================================================== column resizer */
/* 分隔条：绝对定位在列间距正中，拖动时由 splitter.js 改写列宽比例。
   显示与否完全交给 CSS（.layout.resizable + 断点），JS 只负责定位。 */
.col-resizer {
  position: absolute;
  display: none;
  width: 12px;
  cursor: col-resize;
  z-index: 5;
  touch-action: none;
}
.layout.resizable .col-resizer { display: block; }
.col-resizer::after {
  content: '';
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 5px;
  width: 2px;
  border-radius: 2px;
  background: var(--line);
  opacity: .55;
  transition: background .15s, opacity .15s;
}
.col-resizer:hover::after,
.col-resizer.dragging::after {
  background: var(--accent);
  opacity: 1;
  top: 0;
  bottom: 0;
}
@media (max-width: 1400px) {
  .layout.resizable .col-resizer { display: none; }
}

/* ================================================================ panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  min-height: 26px;
}

.panel-title {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.spacer { flex: 1 1 auto; }

/* ============================================================== tabbed */
.tab-nav { gap: 4px; padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 4px 11px;
  font-size: 12.5px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab-btn:hover:not(:disabled) { color: var(--text); border-color: var(--line); }
.tab-btn.active {
  color: var(--text);
  background: rgba(61, 139, 253, .14);
  border-color: var(--accent);
  font-weight: 600;
}

.tab-badge {
  font-size: 10px;
  line-height: 1.5;
  padding: 0 5px;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}
.tab-btn.active .tab-badge { border-color: var(--accent); color: var(--accent); }

.tab-pane[hidden] { display: none; }
/* 导航页撑满窗口高度，内部组件才能用满可用空间（否则 pane 是内容高度，flex 填满无效）。
   注意这里用 flex-basis:auto：行的固有高度要由“最高的那个导航页内容”决定，
   若用 basis:0，行高会塌成 0（内容被裁掉）。内部列表再用 basis:0 就不会反过来撑高行。 */
.tabbed > .tab-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.tab-pane {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.tab-pane > .panel { flex: 1 1 auto; min-height: 0; }
/* 导航页内的组件不再重复画边框、背景与面板标题，避免「窗中窗」 */
.tab-pane > .panel {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
}
.tab-pane .panel-title { display: none; }

/* ================================================================ modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 9vh 16px 24px;
  background: rgba(5, 9, 16, .62);
}
.modal-backdrop[hidden] { display: none; }
body.modal-open { overflow: hidden; }

.modal {
  width: min(560px, 100%);
  max-height: 80vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px 16px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .55);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal-head { display: flex; align-items: center; gap: 8px; }
.modal-title { margin: 0; font-size: 14px; letter-spacing: .5px; }
.modal-body { display: flex; flex-direction: column; gap: 10px; }
.modal-sub {
  margin: 4px 0 0;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.modal-note { font-size: 11.5px; color: var(--muted); line-height: 1.55; }
.modal-actions { display: flex; gap: 8px; align-items: center; }
.modal-actions > button { flex: 0 0 auto; }

/* 弹窗内的选项导航页 */
.connect-tabs { border: 0; padding: 0; background: transparent; }
.connect-tabs .tab-nav { margin-bottom: 8px; }
.connect-tabs .tab-body { display: flex; flex-direction: column; gap: 9px; }
.connect-pane { display: flex; flex-direction: column; gap: 9px; }

/* 浏览器钱包（EIP-1193 插件）选择卡片 */
.wallet-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.wallet-card {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 11px; font: inherit; font-size: 12.5px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.wallet-card:hover { border-color: var(--accent); }
.wallet-card.active { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.wallet-card .wallet-icon { font-size: 15px; line-height: 1; }
.wallet-card .wallet-name { white-space: nowrap; }

/* 登录步骤指示器：等待 / 进行中 / 完成 / 失败 */
.wallet-steps { display: flex; flex-direction: column; gap: 4px; margin: 0; padding-left: 18px; font-size: 11.5px; color: var(--muted); }
.wallet-steps li { line-height: 1.5; }
.wallet-steps li[data-state="active"] { color: var(--accent); font-weight: 600; }
.wallet-steps li[data-state="done"] { color: var(--green); }
.wallet-steps li[data-state="bad"] { color: var(--red); }
.wallet-steps li[data-state="done"]::marker { content: '✓ '; }
.wallet-steps li[data-state="bad"]::marker { content: '✕ '; }
.wallet-steps li[data-state="active"]::marker { content: '▸ '; }

.scroll { overflow: auto; }
.scroll-y-260 { max-height: 260px; overflow: auto; }
.scroll-y-300 { max-height: 300px; overflow: auto; }
.scroll-y-220 { max-height: 220px; overflow: auto; }

/* 填满面板剩余高度：面板变高时直接用起来，内容超出才出现滚动条。
   flex-basis 用 0（而非 auto）——否则内容的固有高度会反过来把所在的行撑大，
   例如日志/列表越长行越高，页面无限变长。 */
.fill-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow: auto;
}

/* 行数不多但面板很高时（如行情列表），让表格撑满高度、行均分剩余空间，
   而不是把数据挤在顶部留一大块空白。内容超出时表格自然恢复纵向滚动。 */
.fill-scroll > .fill-rows { height: 100%; }

@media (max-width: 1400px) {
  .scroll-y-260, .scroll-y-300, .scroll-y-220 { max-height: 320px; }
}

/* ============================================================== controls */
input, select, button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 8px;
  font: inherit;
  outline: none;
}

input:focus, select:focus { border-color: var(--accent); }
button { cursor: pointer; transition: .15s; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.buy { background: rgba(38, 194, 129, .15); border-color: var(--green); color: var(--green); font-weight: 600; }
button.sell { background: rgba(229, 84, 75, .15); border-color: var(--red); color: var(--red); font-weight: 600; }
button.chip { background: transparent; color: var(--muted); padding: 3px 9px; font-size: 12px; }
button.chip.active { background: var(--panel-2); color: var(--accent); border-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 2px; }
.field > span { font-size: 10px; color: var(--muted); white-space: nowrap; }
.field > input, .field > select { width: 100%; padding: 4px 7px; font-size: 12.5px; }

.form-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.form-row > label { color: var(--muted); min-width: 52px; font-size: 12px; }
.form-row > input, .form-row > select { flex: 1 1 auto; min-width: 0; }

/* ================================================================= table */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th {
  text-align: right; color: var(--muted); font-weight: 500;
  padding: 3px 5px; font-size: 11px; position: sticky; top: 0;
  background: var(--panel); z-index: 1;
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
td { text-align: right; padding: 3px 5px; font-size: 12.5px; white-space: nowrap; }
tbody tr { border-bottom: 1px solid rgba(36, 48, 68, .45); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
tbody tr.selected { background: rgba(61, 139, 253, .12); }
tbody tr[data-symbol] { cursor: pointer; }
.empty { color: var(--muted); font-size: 12px; padding: 10px 4px; text-align: center; }

/* ================================================================== misc */
.green { color: var(--green); }
.red { color: var(--red); }
.amber { color: var(--amber); }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "Cascadia Mono", monospace; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 9px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { border-color: var(--green); color: var(--green); }
.pill.warn { border-color: var(--amber); color: var(--amber); }
.pill.bad { border-color: var(--red); color: var(--red); }

.kv { display: flex; justify-content: space-between; padding: 2px 0; font-size: 12.5px; }
.kv > span:first-child { color: var(--muted); }
.bar { height: 4px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin: 4px 0 8px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--amber), var(--red)); }

/* ================================================================= chart */
/* `height: 0` + `flex: 1`：由 flex 决定高度，避免 canvas 的固有尺寸
   （draw 时会按 devicePixelRatio 放大后写回 width/height 属性）反过来
   把面板撑大，形成「越画越高」的布局反馈循环。 */
.chart-canvas {
  width: 100%;
  height: 0;
  flex: 1 1 auto;
  min-height: 300px;
  display: block;
  cursor: crosshair;
}
.chart-price { font-size: 15px; font-weight: 600; }
.intervals { display: flex; gap: 3px; }

/* pushes the following block to the bottom of a flex panel */
.push-bottom { margin-top: auto; }

/* ============================================================= simulator */
.switch { position: relative; display: inline-block; width: 42px; height: 22px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; background: #2a3548;
  border: 1px solid var(--line); border-radius: 999px; transition: .2s; cursor: pointer;
}
.switch span::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 2px; top: 2px;
  background: #93a3ba; border-radius: 50%; transition: .2s;
}
.switch input:checked + span { background: rgba(240, 169, 46, .25); border-color: var(--amber); }
.switch input:checked + span::before { transform: translateX(20px); background: var(--amber); }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(78px, 1fr)); gap: 8px; }
.area-simulator .panel-head button[data-toggle] { min-width: 84px; }
.area-simulator.busy .panel-head button { opacity: .65; }

/* ================================================================== feed */
.feed-status { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--red); display: inline-block; margin-right: 5px; }
.dot.on { background: var(--green); box-shadow: 0 0 6px var(--green); }

.feed-list {
  flex: 1 1 0;
  min-height: 140px;
  overflow: auto;
  background: #0a0e15;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 11.5px;
}

.feed-item { display: flex; gap: 7px; padding: 1px 0; white-space: pre-wrap; word-break: break-all; }
.feed-time { color: #55657d; flex: 0 0 auto; }
.feed-tag { flex: 0 0 auto; padding: 0 5px; border-radius: 4px; font-size: 10.5px; border: 1px solid var(--line); color: var(--muted); }
.feed-tag.market { border-color: #2a4a7a; color: #6ea8fe; }
.feed-tag.user { border-color: #6a5320; color: var(--amber); }
.feed-body { flex: 1 1 auto; color: #9fb0c7; }
.feed-body.ok { color: var(--green); }
.feed-body.bad { color: var(--red); }

/* ================================================================= quant */
.quant-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1.15fr) minmax(320px, 1fr) minmax(300px, 1fr);
  gap: 14px;
  align-items: start;
}

@media (max-width: 1400px) {
  .quant-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 820px) {
  .quant-grid { grid-template-columns: 1fr; }
}

.quant-col { min-width: 0; display: flex; flex-direction: column; }
.sub-title { font-size: 12px; margin: 0 0 6px; color: var(--muted); letter-spacing: .5px; }

.strategy-list { max-height: 168px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }

.strategy-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  cursor: pointer;
  background: var(--panel-2);
  transition: .15s;
}
.strategy-item:hover { border-color: var(--accent); }
.strategy-item.active { border-color: var(--accent); background: rgba(61, 139, 253, .12); }
.strategy-head { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.strategy-desc { font-size: 11px; line-height: 1.45; margin-top: 2px; max-height: 46px; overflow: auto; }

.param-form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 190px; overflow: auto; }
.param { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.param > span { font-size: 10px; color: var(--muted); white-space: nowrap; }
.param > input, .param > textarea {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 5px; padding: 3px 6px; font: inherit; font-size: 12px; outline: none; resize: vertical;
}
.param > input:focus, .param > textarea:focus { border-color: var(--accent); }
.param.wide { grid-column: 1 / -1; }
.param.wide > textarea { font-family: Consolas, monospace; font-size: 11px; }

.quant-log {
  margin: 8px 0 0;
  height: 132px;
  overflow: auto;
  background: #0a0e15;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 11px;
  color: #9fb0c7;
  white-space: pre-wrap;
  word-break: break-all;
}

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 6px; }
.metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 7px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.metric > span { font-size: 10px; color: var(--muted); }
.metric > strong { font-size: 12.5px; }

.equity-canvas { width: 100%; height: 128px; display: block; margin-top: 8px; }
.nowrap { white-space: nowrap; }

/* ============================================================= risk center */
.risk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.risk-pane {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px 9px;
  background: var(--panel-2);
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}
.risk-pane > header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}
.risk-pane > header .spacer { flex: 1 1 auto; }
.risk-pane h4 {
  margin: 2px 0 0;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}
.risk-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.risk-table th {
  text-align: left;
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
  padding: 2px 4px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.risk-table td { padding: 3px 4px; border-bottom: 1px solid rgba(255, 255, 255, .04); }
.risk-table tr:last-child td { border-bottom: 0; }
.risk-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.risk-table tr.level-warning { background: rgba(240, 169, 46, .08); }
.risk-table tr.level-critical { background: rgba(239, 83, 80, .12); }
.risk-scroll { max-height: 168px; overflow: auto; }
.risk-alerts { display: flex; flex-direction: column; gap: 4px; max-height: 150px; overflow: auto; }
.risk-alert {
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
  line-height: 1.35;
}
.risk-alert.info { border-left-color: var(--accent); }
.risk-alert.warning { border-left-color: var(--amber); }
.risk-alert.critical { border-left-color: var(--red); }
.risk-alert .risk-alert-head { display: flex; gap: 6px; color: var(--muted); font-size: 10px; }
.risk-wallet {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11.5px;
}
.risk-wallet-head { display: flex; align-items: center; gap: 6px; }
.risk-wallet-head .spacer { flex: 1 1 auto; }
.risk-wallet .addr { font-family: ui-monospace, monospace; font-size: 10.5px; color: var(--muted); word-break: break-all; }
.risk-note { font-size: 10.5px; color: var(--muted); line-height: 1.4; }
.risk-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.risk-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 9px; }
