:root {
  --bg: #0b0f14;
  --surface: #121821;
  --surface-2: #171f2a;
  --line: #26303d;
  --text: #eef2f6;
  --muted: #8f9baa;
  --green: #56d39b;
  --green-dim: #183d31;
  --amber: #f3bd62;
  --red: #ff756f;
  --blue: #70a5ff;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); }
button, input { font: inherit; }
select { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 76px; padding: 0 4vw; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); background: rgba(11, 15, 20, .95); position: sticky; top: 0; z-index: 10;
}
.brand, .topbar-actions, .key-row, .status-strip, .scope-bar, .panel-head { display: flex; align-items: center; }
.brand { gap: 14px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center; border: 1px solid #3b4b60;
  color: var(--green); font: 700 13px var(--mono); letter-spacing: -.04em;
}
h1, h2, p { margin: 0; }
h1 { font-size: 18px; letter-spacing: .01em; }
h2 { font-size: 17px; font-weight: 650; }
.eyebrow { margin-bottom: 4px; color: var(--muted); font: 600 10px var(--mono); letter-spacing: .14em; }
.topbar-actions { gap: 10px; }
.mode-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 11px; color: var(--green);
  border: 1px solid #285744; background: var(--green-dim); font-size: 12px; font-weight: 650;
}
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(86,211,155,.11); }
.button { min-height: 38px; padding: 0 15px; border: 1px solid transparent; color: var(--text); background: none; }
.button.primary { color: #07120e; background: var(--green); font-weight: 700; }
.button.secondary { border-color: var(--line); background: var(--surface); }
.button.quiet { color: var(--muted); }
.button:hover, .text-button:hover { filter: brightness(1.12); }
.button:focus-visible, .text-button:focus-visible, input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.shell { width: min(1480px, 92vw); margin: 34px auto 56px; }
.login-panel {
  width: min(760px, 100%); margin: 10vh auto; padding: 30px; display: grid; grid-template-columns: 1fr 1.2fr;
  gap: 36px; border: 1px solid var(--line); border-top: 3px solid var(--green); background: var(--surface);
}
.login-copy p:last-child { margin-top: 14px; color: var(--muted); line-height: 1.7; font-size: 13px; }
.key-form label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.key-row { gap: 8px; }
input {
  min-width: 0; flex: 1; height: 42px; padding: 0 12px; border: 1px solid #354254; color: var(--text);
  background: #0d1218; font-family: var(--mono); font-size: 13px;
}
.form-error { min-height: 20px; margin-top: 8px; color: var(--red); font-size: 12px; }
.dashboard { display: grid; gap: 16px; }
.status-strip {
  min-height: 46px; padding: 0 16px; justify-content: space-between; gap: 16px; border: 1px solid var(--line); background: var(--surface);
  font-size: 12px;
}
.status-strip > div { display: flex; align-items: center; gap: 10px; }
.status-strip p { color: var(--muted); }
.scope-bar {
  min-height: 68px; padding: 10px 16px; justify-content: space-between; gap: 24px;
  border: 1px solid var(--line); border-left: 3px solid var(--blue); background: var(--surface);
}
.scope-copy { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 10px; }
.scope-copy .eyebrow { grid-column: 1 / -1; }
.scope-copy strong { font-size: 13px; }
.scope-copy span { color: var(--muted); font-size: 11px; }
.scope-select { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.scope-select select {
  min-width: 280px; height: 38px; padding: 0 32px 0 11px; border: 1px solid #354254;
  color: var(--text); background: #0d1218; font-family: var(--mono); font-size: 12px;
}
.currency-scope select { min-width: 100px; }
.separator { margin: 0 7px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.pulse.warning { background: var(--amber); }
.pulse.error { background: var(--red); }
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.metric-card { min-height: 128px; padding: 18px; border: 1px solid var(--line); background: var(--surface); }
.metric-card p { color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; margin: 15px 0 7px; font: 650 25px var(--mono); }
.metric-card span { color: var(--muted); font-size: 11px; }
.grid-two { display: grid; grid-template-columns: minmax(360px, .8fr) minmax(560px, 1.2fr); gap: 16px; }
.lower-grid { grid-template-columns: 1fr 1fr; }
.panel { min-width: 0; border: 1px solid var(--line); background: var(--surface); }
.panel-head { min-height: 68px; padding: 0 18px; justify-content: space-between; border-bottom: 1px solid var(--line); }
.history-head { gap: 20px; }
.history-controls { display: flex; align-items: center; gap: 4px; }
.range-button { min-height: 32px; padding: 0 10px; border: 1px solid transparent; color: var(--muted); background: none; font-size: 11px; }
.range-button:hover { color: var(--text); background: var(--surface-2); }
.range-button.active { color: var(--green); border-color: #285744; background: var(--green-dim); }
.history-grid { display: grid; grid-template-columns: 1fr 1fr; }
.chart-card { min-width: 0; padding: 18px; }
.chart-card + .chart-card { border-left: 1px solid var(--line); }
.chart-title-row { min-height: 48px; display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.chart-title-row h3 { margin: 0 0 5px; font-size: 13px; font-weight: 650; }
.chart-title-row p { color: var(--muted); font-size: 10px; }
.chart-legend { display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 10px; }
.chart-legend span { white-space: nowrap; }
.chart-legend strong { margin-left: 4px; color: var(--text); font-family: var(--mono); font-size: 11px; }
.legend-line { display: inline-block; width: 14px; height: 2px; margin-right: 5px; vertical-align: middle; }
.legend-line.balance { background: var(--blue); }
.legend-line.equity { background: var(--green); }
.symbol-control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; }
.symbol-control select { height: 32px; min-width: 110px; padding: 0 26px 0 9px; border: 1px solid var(--line); color: var(--text); background: #0d1218; }
.chart-stage { position: relative; min-height: 270px; margin-top: 8px; }
.history-chart { display: block; width: 100%; height: 270px; overflow: visible; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.chart-grid-line { stroke: #25303c; stroke-width: 1; }
.chart-zero-line { stroke: #526174; stroke-width: 1; stroke-dasharray: 4 4; }
.chart-axis-label { fill: #758293; font: 10px var(--mono); }
.chart-series { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-end-dot { stroke: var(--surface); stroke-width: 2; vector-effect: non-scaling-stroke; }
.symbol-chart-foot { display: flex; justify-content: flex-end; gap: 20px; color: var(--muted); font-size: 10px; }
.symbol-chart-foot strong { margin-left: 5px; color: var(--text); font-family: var(--mono); font-size: 12px; }
.text-button { padding: 8px 0; border: 0; color: var(--blue); background: none; font-size: 12px; }
.caption { color: var(--muted); font-size: 11px; }
.table-scroll-hint { display: none; padding: 8px 14px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 10px; }
.account-list { display: grid; gap: 1px; background: var(--line); }
.account-card { padding: 18px; background: var(--surface); }
.account-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 18px; }
.account-identity { display: grid; gap: 5px; }
.account-id { font: 650 14px var(--mono); }
.account-terminal { color: var(--muted); font: 10px var(--mono); }
.currency { color: var(--muted); font: 11px var(--mono); }
.account-values { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px 20px; }
.account-values span { display: block; color: var(--muted); font-size: 11px; }
.account-values strong { display: block; margin-top: 5px; font: 600 18px var(--mono); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
.orders-table { min-width: 1800px; }
th { padding: 11px 14px; color: var(--muted); background: #0f151d; font-size: 10px; font-weight: 600; letter-spacing: .05em; text-align: left; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid var(--line); white-space: nowrap; font-family: var(--mono); }
tbody tr:first-child td { border-top: 0; }
.state { display: inline-flex; align-items: center; gap: 6px; font-family: inherit; }
.state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.state.good { color: var(--green); }.state.good::before { background: var(--green); }
.state.bad { color: var(--red); }.state.bad::before { background: var(--red); }
.state.warn { color: var(--amber); }.state.warn::before { background: var(--amber); }
.side-buy { color: var(--green); }.side-sell { color: var(--red); }
.profit-positive { color: var(--green); font-weight: 650; }
.profit-negative { color: var(--red); font-weight: 650; }
.quote-rise { animation: quote-rise 950ms ease-out; }
.quote-fall { animation: quote-fall 950ms ease-out; }
@keyframes quote-rise {
  0% { color: #c8ffe6; background: rgba(35, 179, 116, .52); box-shadow: inset 3px 0 var(--green); }
  100% { background: transparent; box-shadow: inset 0 0 transparent; }
}
@keyframes quote-fall {
  0% { color: #ffe0de; background: rgba(220, 68, 68, .48); box-shadow: inset 3px 0 var(--red); }
  100% { background: transparent; box-shadow: inset 0 0 transparent; }
}
.empty { padding: 30px 18px !important; color: var(--muted); text-align: center; font-family: inherit; }
.integrity-list { padding: 8px 18px 18px; }
.integrity-item { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.integrity-item:last-child { border-bottom: 0; }
.integrity-item span:last-child { color: var(--muted); font-family: var(--mono); }
.event-list { margin: 0; padding: 8px 18px 18px; list-style: none; }
.event-item { display: grid; grid-template-columns: 90px 1fr auto; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.event-item time, .event-item span:last-child { color: var(--muted); font-family: var(--mono); }
.error-banner { position: fixed; right: 22px; bottom: 22px; max-width: 460px; padding: 14px 18px; color: #ffd6d4; border: 1px solid #7b3535; background: #321b1d; font-size: 12px; }
footer { padding: 24px; color: #637080; border-top: 1px solid var(--line); text-align: center; font-size: 11px; }

@media (max-width: 1000px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .grid-two, .lower-grid { grid-template-columns: 1fr; }
  .history-grid { grid-template-columns: 1fr; }
  .chart-card + .chart-card { border-left: 0; border-top: 1px solid var(--line); }
  .table-scroll-hint { display: block; }
}
@media (max-width: 650px) {
  .topbar { height: auto; min-height: 76px; padding: 12px 4vw; }
  .topbar-actions { gap: 4px; }.mode-badge { display: none; }
  .button { padding: 0 10px; }.shell { width: 94vw; margin-top: 18px; }
  .login-panel { margin: 5vh auto; padding: 22px; grid-template-columns: 1fr; gap: 24px; }
  .key-row { align-items: stretch; flex-direction: column; }
  .metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric-card { min-height: 112px; padding: 14px; }.metric-card strong { font-size: 20px; }
  .status-strip { padding: 12px; align-items: flex-start; flex-direction: column; }
  .status-strip p { margin-left: 18px; }.separator, .status-strip p span:last-child { display: none; }
  .scope-bar { padding: 12px; align-items: stretch; flex-direction: column; gap: 12px; }
  .scope-select { align-items: stretch; flex-direction: column; gap: 6px; }
  .scope-select select { width: 100%; min-width: 0; }
  .history-head { padding: 12px; align-items: flex-start; flex-direction: column; }
  .history-controls { width: 100%; overflow-x: auto; }
  .range-button { flex: 1; white-space: nowrap; }
  .chart-card { padding: 14px 10px; }
  .chart-title-row { align-items: flex-start; flex-direction: column; }
  .chart-legend { width: 100%; justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  .quote-rise, .quote-fall { animation-duration: 1ms; }
}
