:root {
  color-scheme: dark;
  --bg: #0b0d0e;
  --panel: #111416;
  --panel-2: #171b1d;
  --line: #2b3134;
  --muted: #8e999d;
  --text: #eef2f0;
  --green: #24c78d;
  --red: #ff5a65;
  --yellow: #f3c84b;
  --cyan: #43bdd1;
  --orange: #ee8b47;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif; font-size: 14px; letter-spacing: 0; }
button, input { font: inherit; }
button { cursor: pointer; }

.topbar { height: 76px; display: grid; grid-template-columns: minmax(230px, 1fr) auto minmax(260px, 1fr); align-items: center; gap: 24px; padding: 0 24px; background: #0f1213; border-bottom: 1px solid var(--line); }
.instrument { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; background: var(--yellow); color: #17140a; font-weight: 900; border-radius: 4px; }
h1, h2, p { margin: 0; }
h1 { font-size: 18px; line-height: 1.2; font-weight: 700; }
.instrument-meta, .quote-detail { display: flex; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 4px; }
.mode-strip { display: flex; align-items: center; gap: 8px; }
.badge { min-height: 28px; display: inline-flex; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid var(--line); border-radius: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.badge.live { color: var(--green); border-color: #21533f; }
.badge.live i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; box-shadow: 0 0 9px currentColor; }
.badge.paper { color: var(--yellow); border-color: #5d5128; }
.badge.ready { color: var(--green); border-color: #21533f; }
.badge.blocked { color: var(--red); border-color: #5d2b30; }
.quote-block { text-align: right; min-width: 0; }
.mid-price { font-family: "Cascadia Mono", Consolas, monospace; font-size: 27px; font-weight: 700; font-variant-numeric: tabular-nums; }
.quote-detail { justify-content: flex-end; }

main { padding: 14px 16px 28px; }
.metric-band { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)) minmax(220px, 1.5fr); border: 1px solid var(--line); background: var(--panel); }
.metric { min-width: 0; padding: 12px 14px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric > span, .metric small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric strong { display: block; margin: 5px 0 3px; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.risk-summary { display: grid; grid-template-columns: 1fr minmax(360px, 1.35fr) 1fr; margin-top: 12px; border: 1px solid var(--line); background: var(--panel); }
.risk-side, .risk-alert { min-width: 0; min-height: 82px; padding: 12px 14px; border-right: 1px solid var(--line); }
.risk-side:last-child { border-right: 0; }
.risk-side > div { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.risk-side span, .risk-alert span, .risk-side small, .risk-alert small { color: var(--muted); font-size: 11px; }
.risk-side strong { font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.risk-side small, .risk-alert small { display: block; margin-top: 8px; line-height: 1.35; }
.short-risk strong { color: var(--green); }.long-risk strong { color: var(--red); }
.risk-alert { text-align: center; border-left: 3px solid #5c6467; }
.risk-alert strong { display: block; margin-top: 4px; font-size: 16px; }
.risk-alert.short_squeeze_upside { border-left-color: var(--green); }.risk-alert.short_squeeze_upside strong { color: var(--green); }
.risk-alert.long_liquidation_downside { border-left-color: var(--red); }.risk-alert.long_liquidation_downside strong { color: var(--red); }
.risk-alert.balanced_two_sided { border-left-color: var(--yellow); }.risk-alert.balanced_two_sided strong { color: var(--yellow); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 12px; margin-top: 12px; }
.visual-panel, .dom-panel, .ticket-panel, .zones-panel, .position-panel, .strategy-panel, .ledger-panel, .market-chart-panel, .sweep-panel { background: var(--panel); border: 1px solid var(--line); }
.section-head { height: 52px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.section-head.compact { height: 42px; }
.section-head h2 { font-size: 14px; font-weight: 700; }
.section-head p, .section-head > span { color: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 5px; align-items: center; color: var(--muted); font-size: 11px; }
.legend i { width: 17px; height: 7px; border-radius: 1px; }
.legend .l1 { background: #17343a; }.legend .l2 { background: #198b85; }.legend .l3 { background: #d1b142; }.legend .l4 { background: #f15b43; }
.canvas-wrap { position: relative; height: clamp(460px, 62vh, 700px); background: #090b0c; overflow: hidden; }
#heatmap-canvas { width: 100%; height: 100%; display: block; }
.canvas-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); background: rgba(9, 11, 12, .7); }
.canvas-empty.hidden { display: none; }
.stale-overlay { position: absolute; inset: 0; z-index: 3; display: grid; align-content: center; justify-items: center; gap: 8px; pointer-events: none; color: #ffb0b5; background: rgba(9, 11, 12, .64); border: 1px solid rgba(255,90,101,.35); }
.stale-overlay strong { font-size: 17px; }.stale-overlay span { color: #c58f93; font-size: 11px; }
.chart-tooltip { position: absolute; z-index: 4; min-width: 150px; padding: 8px 10px; pointer-events: none; color: var(--text); background: rgba(20, 24, 25, .96); border: 1px solid #465055; border-radius: 3px; box-shadow: 0 8px 24px rgba(0,0,0,.4); font: 11px/1.55 "Cascadia Mono", Consolas, monospace; white-space: nowrap; }
.chart-tooltip strong { color: var(--yellow); }

.market-chart-panel { margin-top: 12px; }
.chart-head { height: 54px; }
.ohlcv-strip { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 13px; color: var(--muted); font: 11px "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.ohlcv-strip strong { color: #dce2df; font-weight: 600; }
.ohlcv-strip .timeframe { padding: 4px 7px; color: var(--yellow); border: 1px solid #5d5128; border-radius: 3px; }
.candle-wrap { position: relative; height: 390px; background: #090b0c; overflow: hidden; }
#candle-canvas { width: 100%; height: 100%; display: block; }

.trade-column { display: grid; grid-template-rows: minmax(280px, 1fr) auto; gap: 12px; }
.dom-head, .dom-row { display: grid; grid-template-columns: 1fr 1.3fr 1fr; height: 24px; align-items: center; text-align: right; padding: 0 12px; font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; font-variant-numeric: tabular-nums; }
.dom-head { color: var(--muted); border-bottom: 1px solid var(--line); font-family: inherit; font-size: 10px; }
.dom-ladder { height: 282px; overflow: hidden; padding: 6px 0; }
.dom-row { position: relative; }
.dom-row .price { color: #d8dddd; }
.dom-row .bid { color: var(--green); }.dom-row .ask { color: var(--red); }
.dom-row.mid { height: 30px; margin: 3px 0; background: var(--panel-2); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--yellow); }
.depth-bar { position: absolute; top: 3px; bottom: 3px; opacity: .13; pointer-events: none; }
.depth-bar.bid { right: 66.66%; background: var(--green); }.depth-bar.ask { left: 66.66%; background: var(--red); }

.ticket-panel { padding-bottom: 12px; }
.ticket-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; padding: 12px; }
.ticket-fields label { color: var(--muted); font-size: 10px; }
.ticket-fields input { width: 100%; height: 34px; margin-top: 5px; padding: 0 8px; color: var(--text); background: #0d1011; border: 1px solid var(--line); border-radius: 3px; outline: none; }
.ticket-fields input:focus { border-color: var(--cyan); }
.order-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 12px; }
.order-actions button, .flatten { height: 40px; border: 0; border-radius: 3px; color: #07100c; font-weight: 800; }
.order-actions .buy { background: var(--green); }.order-actions .sell { background: var(--red); color: #170708; }
.flatten { width: calc(100% - 24px); margin: 8px 12px 10px; background: #d8dddd; }
button:disabled { opacity: .35; cursor: not-allowed; }
.cost-line { display: flex; justify-content: space-between; padding: 3px 12px; color: var(--muted); font-size: 11px; }
.cost-line strong { color: #cbd1ce; font-weight: 600; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, .8fr) minmax(280px, .8fr); gap: 12px; margin-top: 12px; }
.table-scroll { overflow-x: auto; }
.zones-panel .table-scroll { max-height: 520px; overflow-y: auto; }
.current-price-divider td { position: sticky; top: 32px; z-index: 1; height: 28px; color: var(--yellow); text-align: center !important; font-weight: 700; background: #202015; border-top: 1px solid #6f6029; border-bottom: 1px solid #6f6029; }
table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
th { height: 32px; padding: 0 12px; color: var(--muted); font-size: 10px; text-align: right; font-weight: 500; border-bottom: 1px solid var(--line); }
td { height: 34px; padding: 0 12px; text-align: right; border-bottom: 1px solid #202527; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
.empty-cell { text-align: center !important; color: var(--muted); }
.zone-long { color: var(--red); }.zone-short { color: var(--green); }
.position-empty { min-height: 128px; display: grid; place-items: center; color: var(--muted); }
.position-active { display: grid; grid-template-columns: 1fr 1fr; min-height: 128px; }
.position-active > div { padding: 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.position-active > div:nth-child(even) { border-right: 0; }
.position-active > div:nth-child(n+3) { border-bottom: 0; }
.position-active span, .position-active strong { display: block; }
.position-active span { color: var(--muted); font-size: 10px; }.position-active strong { margin-top: 7px; font-size: 14px; }
.hidden { display: none !important; }
.switch-row { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.switch-row span strong, .switch-row span small { display: block; }.switch-row span small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row > i { width: 38px; height: 21px; flex: 0 0 auto; border-radius: 11px; background: #343a3d; position: relative; transition: background .18s; }
.switch-row > i::after { content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; border-radius: 50%; background: #aeb6b3; transition: transform .18s; }
.switch-row input:checked + i { background: var(--green); }.switch-row input:checked + i::after { transform: translateX(17px); background: #07100c; }
.strategy-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.strategy-fields label { color: var(--muted); font-size: 10px; }
.strategy-fields input { width: 100%; height: 30px; margin-top: 5px; padding: 0 8px; color: var(--text); background: #0d1011; border: 1px solid var(--line); border-radius: 3px; }
.strategy-candidate { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; min-height: 50px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.strategy-candidate span { overflow-wrap: anywhere; }.strategy-candidate strong { color: var(--text); font-weight: 650; }
.gate-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px; }
.gate-list span { padding: 4px 6px; border: 1px solid #513037; color: #e89aa1; border-radius: 3px; font-size: 10px; }
.gate-list span.ok { border-color: #22543f; color: var(--green); }
.sweep-panel, .ledger-panel { margin-top: 12px; }
.sweep-scroll { max-height: 280px; overflow-y: auto; }
.positive { color: var(--green) !important; }.negative { color: var(--red) !important; }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(420px, calc(100vw - 40px)); padding: 12px 15px; background: #e4e9e6; color: #151817; border-radius: 4px; box-shadow: 0 8px 30px rgba(0,0,0,.35); transform: translateY(90px); opacity: 0; transition: .2s; z-index: 10; }
.toast.show { transform: translateY(0); opacity: 1; }.toast.error { background: #ff8f96; color: #190607; }

@media (max-width: 1050px) {
  .topbar { grid-template-columns: 1fr 1fr; height: auto; min-height: 76px; padding: 12px 16px; }
  .mode-strip { grid-column: 1 / -1; grid-row: 2; }
  .workspace { grid-template-columns: 1fr; }
  .trade-column { grid-template-columns: 1fr 1fr; grid-template-rows: none; }
  .detail-grid { grid-template-columns: 1fr 1fr; }.zones-panel { grid-column: 1 / -1; }
  .risk-summary { grid-template-columns: 1fr 1fr; }.risk-alert { grid-column: 1 / -1; grid-row: 2; border-top: 1px solid var(--line); }
}

@media (max-width: 680px) {
  .topbar { grid-template-columns: 1fr auto; gap: 10px; }
  .mode-strip { overflow-x: auto; }.badge { font-size: 10px; }
  main { padding: 8px; }
  .metric-band { grid-template-columns: repeat(2, 1fr); }.metric:nth-child(even) { border-right: 0; }.strategy-metric { grid-column: 1 / -1; }
  .workspace, .detail-grid { gap: 8px; margin-top: 8px; }
  .canvas-wrap { height: 430px; }
  .candle-wrap { height: 360px; }
  .chart-head { height: auto; min-height: 64px; align-items: flex-start; padding-top: 10px; padding-bottom: 10px; }
  .ohlcv-strip { gap: 7px 10px; }
  .trade-column, .detail-grid { grid-template-columns: 1fr; }.zones-panel { grid-column: auto; }
  .ticket-fields { grid-template-columns: 1fr 1fr 1fr; }
  .risk-summary { grid-template-columns: 1fr; }.risk-alert { grid-column: auto; grid-row: auto; }.risk-side, .risk-alert { border-right: 0; border-bottom: 1px solid var(--line); }
  .quote-detail { gap: 6px; }.mid-price { font-size: 22px; }
}
