:root {
  --bg: #0b0e14; --panel: #121722; --panel2: #171d2b; --line: #232b3d; --text: #d7dce8; --muted: #7d879c;
  --accent: #4c8dff; --buy: #1fbf75; --sell: #ff4d5e; --warn: #ffb020; --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--sans); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 11px; } .r { text-align: right; }
.err { color: var(--sell); min-height: 1em; }
code { font-family: var(--mono); font-size: 11px; color: #9fb7ff; }
input, select, button { font: inherit; color: inherit; }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; outline: none; }
input:focus, select:focus { border-color: var(--accent); }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { border-color: #5a2630; color: #ff8792; }
.btn.ghost { background: none; }
.btn.buy { background: var(--buy); border-color: var(--buy); color: #04140c; font-weight: 700; }
.btn.sell { background: var(--sell); border-color: var(--sell); color: #1a0306; font-weight: 700; }
.btn.big { padding: 12px; font-size: 15px; width: 100%; }
.btn:disabled { opacity: .5; cursor: wait; }

/* login */
.overlay { position: fixed; inset: 0; background: rgba(5,7,12,.85); display: grid; place-items: center; z-index: 50; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 20px; min-width: 320px; }
.login-card { display: grid; gap: 12px; width: 340px; }
.brand { font-weight: 700; letter-spacing: .5px; display: flex; align-items: center; gap: 8px; }
.brand.big { font-size: 26px; }
.logo { color: var(--accent); }

/* topbar */
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: var(--panel); height: 52px; }
.hud { display: flex; gap: 16px; flex: 1; min-width: 0; overflow: hidden; }
/* narrower screens: Margin and Level step aside (they are in Toolbox → Trade and the Dashboard) so Balance/Equity/P/L/Free stay readable */
@media (max-width: 1600px) { .hud-opt { display: none !important; } }
.hud-item { display: flex; flex-direction: column; min-width: 70px; flex: 0 0 auto; }
.hud-item label { font-size: 10px; text-transform: uppercase; color: var(--muted); letter-spacing: .6px; }
.hud-item > span { font-family: var(--mono); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; display: block; }
.status { display: flex; gap: 6px; align-items: center; }
.pill { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); letter-spacing: .5px; }
.pill.ok { color: var(--buy); border-color: #1d5a3f; background: #0f2a1e; }
.pill.bad { color: var(--sell); border-color: #5a2630; background: #2a0f14; }
.pill.warn { color: var(--warn); border-color: #5a4520; background: #2a200f; }

/* grid */
.grid { display: grid; height: calc(100vh - 52px); gap: 6px; padding: 6px;
  grid-template-columns: 330px 1fr 280px; grid-template-rows: 1fr 300px;
  grid-template-areas: "mw chart ticket" "dock dock dock"; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.panel-h { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 12px; min-height: 36px; }
.mw { grid-area: mw; } .chartp { grid-area: chart; } .ticket { grid-area: ticket; } .dock { grid-area: dock; }
.inline-in { width: 110px; margin-left: auto; padding: 3px 6px; font-weight: 400; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.tbl th { position: sticky; top: 0; background: var(--panel); text-align: left; font-family: var(--sans); font-weight: 600; color: var(--muted); font-size: 11px; padding: 5px 8px; border-bottom: 1px solid var(--line); }
.tbl th.r { text-align: right; }
.tbl td { padding: 4px 8px; border-bottom: 1px solid #1a2030; white-space: nowrap; }
.tbl tbody tr:hover { background: var(--panel2); }
.mw .tbl { display: block; overflow-y: auto; }
.mw tbody tr { cursor: pointer; }
.mw tr.sel { background: #18233a; }
.up { color: var(--buy); } .down { color: var(--sell); }
.flash-up { animation: fu .6s; } .flash-down { animation: fd .6s; }
@keyframes fu { from { background: rgba(31,191,117,.35); } } @keyframes fd { from { background: rgba(255,77,94,.35); } }
.mini { display: inline-flex; gap: 2px; }
.mw .tbl td:last-child { padding-right: 6px; }
.mini button { font-size: 10px; padding: 1px 5px; border-radius: 4px; border: none; cursor: pointer; font-weight: 700; }
.mini .b { background: var(--buy); color: #04140c; } .mini .s { background: var(--sell); color: #1a0306; }
.x { background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 4px; cursor: pointer; padding: 1px 6px; }
.x:hover { color: var(--sell); border-color: var(--sell); }

/* chart */
#chart { flex: 1; min-height: 0; position: relative; }
.chart-info { position: absolute; margin: 44px 0 0 14px; font-family: var(--mono); font-size: 12px; color: var(--muted); pointer-events: none; z-index: 3; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { background: none; border: none; color: var(--muted); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; white-space: nowrap; }
.tabs button.on { background: var(--panel2); color: var(--text); }
.tabs button b { font-weight: 600; color: var(--accent); }
.tabs .close { margin-left: 6px; opacity: .5; } .tabs .close:hover { opacity: 1; color: var(--sell); }
.tfs { display: flex; gap: 1px; margin-left: auto; }
.tfs button { background: none; border: none; color: var(--muted); font-size: 11px; padding: 3px 6px; cursor: pointer; border-radius: 4px; font-family: var(--mono); }
.tfs button.on { color: var(--accent); background: var(--panel2); }

/* ticket */
.form { display: grid; gap: 8px; padding: 10px; }
.form label { display: grid; gap: 3px; font-size: 11px; color: var(--muted); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.risk { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.quote-big { display: grid; grid-template-columns: 1fr 1fr; text-align: center; font-family: var(--mono); font-size: 18px; font-weight: 700; padding: 6px 0; }
.bid { color: var(--sell); } .ask { color: var(--buy); }

/* dock */
.tab-body { flex: 1; min-height: 0; overflow: auto; position: relative; }
.toolbar { display: flex; gap: 6px; padding: 6px 8px; align-items: center; }
.toolbar select { width: auto; }
.console { font-family: var(--mono); font-size: 12px; padding: 8px 12px; height: calc(100% - 58px); overflow-y: auto; white-space: pre-wrap; }
.console .in { color: var(--accent); } .console .ok { color: var(--text); } .console .er { color: var(--sell); } .console .sys { color: var(--muted); }
.con-in { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-top: 1px solid var(--line); }
.con-in input { border: none; background: none; font-family: var(--mono); padding: 8px 0; }
.prompt { white-space: nowrap; color: var(--accent); font-family: var(--mono); font-weight: 700; }
.hint { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 2px 12px 4px; min-height: 18px; }
.log { margin: 0; padding: 8px 12px; font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; color: #b5bdd0; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 8px 12px; }
.cols h4 { margin: 6px 0; font-size: 12px; display: flex; gap: 8px; align-items: center; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 14px; font-family: var(--mono); font-size: 12px; }
.kv .k { color: var(--muted); }
.inline-form { display: flex; gap: 6px; margin-top: 8px; }
#shot { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #000; min-height: 100px; }

/* toasts */
#toasts { position: fixed; right: 14px; bottom: 14px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 8px; max-width: 380px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: tin .2s; }
.toast.ok { border-left-color: var(--buy); } .toast.er { border-left-color: var(--sell); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; grid-template-rows: 220px 380px auto 420px; height: auto;
    grid-template-areas: "mw" "chart" "ticket" "dock"; }
  .hud { display: none; }
  .cols { grid-template-columns: 1fr; }
}

/* ======================= view switch ======================= */
.views { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.views button { background: none; border: none; color: var(--muted); padding: 4px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; }
.views button.on { background: var(--panel2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

/* ======================= dashboard ======================= */
/* chart tokens (dataviz reference palette, dark steps): one series hue, diverging blue<->red with gray midpoint,
   reserved status colors that always ship with an icon + label */
.dash {
  --s1: #3987e5; --pos: #3987e5; --neg: #e66767; --mid: #383835;
  --good: #0ca30c; --warning: #fab219; --critical: #d03b3b;
  --ink2: #c3c2b7; --grid: #1f2636; --axis: #383835;
  height: calc(100vh - 52px); overflow-y: auto; padding: 10px 12px 24px;
}
.dash-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.dash-bar .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { background: var(--panel); border: none; border-right: 1px solid var(--line); color: var(--muted); padding: 5px 12px; cursor: pointer; font-size: 12px; }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--panel2); color: var(--text); font-weight: 700; }
.dash-notice { background: #2a200f; border: 1px solid #5a4520; color: #f3d9a4; border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: 12px; }

.kpis { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; position: relative; }
.kpi label { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi svg { display: block; margin-top: 6px; width: 100%; height: 26px; }

.dgrid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px; }
.dcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; min-width: 0; position: relative; }
.dcard > header { display: flex; align-items: baseline; gap: 10px; padding: 9px 12px 6px; }
.dcard h3 { margin: 0; font-size: 12.5px; font-weight: 650; }
.c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; }
.tview { margin-left: auto; background: none; border: 1px solid var(--line); color: var(--muted); border-radius: 5px; font-size: 11px; padding: 1px 8px; cursor: pointer; }
.tview:hover, .tview.on { color: var(--text); border-color: var(--accent); }
.dchart { height: 260px; margin: 0 6px 8px; position: relative; }
.dchart.short { height: 200px; }
.dtable { max-height: 260px; overflow: auto; margin: 0 6px 8px; }
.empty { position: absolute; inset: 40px 0 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; pointer-events: none; }
.scroll { max-height: 250px; overflow: auto; }

/* horizontal diverging bars (P/L by symbol, exposure) */
.hbars { display: grid; gap: 4px; padding: 4px 12px 12px; }
.hbar { display: grid; grid-template-columns: 74px 1fr 76px; align-items: center; gap: 8px; font-size: 12px; min-height: 22px; cursor: default; }
.hbar .name { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; }
.hbar .val { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.hbar .track { position: relative; height: 14px; }
.hbar .track::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.hbar .fill { position: absolute; top: 2px; height: 10px; }
.hbar .fill.pos { left: 50%; background: var(--pos); border-radius: 0 4px 4px 0; }
.hbar .fill.neg { right: 50%; background: var(--neg); border-radius: 4px 0 0 4px; }
.hbar:hover .fill { filter: brightness(1.2); }
.hbars .none { color: var(--muted); font-size: 12px; padding: 18px 0; text-align: center; }

/* account health */
.health { display: grid; gap: 10px; padding: 4px 12px 12px; }
.meter label { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.meter label b { color: var(--text); font-family: var(--mono); font-weight: 600; }
.meter .bar { height: 8px; border-radius: 4px; background: var(--mid); overflow: hidden; display: flex; gap: 2px; }
.meter .bar i { display: block; height: 100%; background: var(--s1); border-radius: 4px; }
.meter .bar i.alt { background: var(--neg); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.status-chip { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 11px; color: var(--muted); }
.status-chip b { display: flex; align-items: center; gap: 5px; color: var(--text); font-size: 12px; margin-top: 2px; }
.status-chip .ic { width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10px; font-weight: 800; color: #fff; flex: none; }
.ic.good { background: var(--good); } .ic.warning { background: var(--warning); color: #0b0b0b; } .ic.critical { background: var(--critical); }

.perf { padding: 2px 12px 12px; gap: 5px 12px; }
.perf span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; }

/* market movers */
.movers { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; padding: 4px 12px 12px; }
.mover { border-radius: 8px; padding: 8px 10px; cursor: pointer; color: #fff; border: 1px solid rgba(255,255,255,.08); transition: transform .1s; }
.mover:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.35); }
.mover .sym { font-weight: 700; font-size: 12px; font-family: var(--mono); }
.mover .chg { font-size: 16px; font-weight: 700; }
.mover .px { font-size: 11px; opacity: .85; font-family: var(--mono); }
.mover svg { width: 100%; height: 22px; display: block; margin-top: 4px; }
.mover.err { background: var(--panel2); color: var(--muted); cursor: default; }

/* P/L by hour heatmap */
.hours { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; padding: 4px 12px 6px; }
.hours div { aspect-ratio: 1.6; border-radius: 4px; display: grid; place-items: center; font-size: 10px; font-family: var(--mono); color: rgba(255,255,255,.75); background: var(--mid); cursor: default; }
.hours div:hover { outline: 1px solid #fff; }
.legend-div { display: flex; align-items: center; gap: 6px; padding: 0 12px 12px; font-size: 10.5px; color: var(--muted); }
.legend-div .ramp { flex: 1; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--neg), var(--mid), var(--pos)); }

/* sparks */
.sparks { display: grid; gap: 8px; padding: 4px 12px 12px; }
.spark { display: grid; grid-template-columns: 96px 1fr 72px; align-items: center; gap: 8px; font-size: 11.5px; }
.spark .lbl { color: var(--muted); }
.spark .now { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.spark svg { width: 100%; height: 28px; display: block; }

/* activity feed */
.feed { list-style: none; margin: 0; padding: 0 12px 12px; max-height: 250px; overflow: auto; font-size: 12px; }
.feed li { display: grid; grid-template-columns: 62px 1fr; gap: 8px; padding: 4px 0; border-bottom: 1px solid #1a2030; }
.feed time { color: var(--muted); font-family: var(--mono); font-size: 11px; }
.feed .k { font-weight: 700; margin-right: 6px; font-size: 10px; letter-spacing: .5px; color: var(--ink2); }

/* shared tooltip */
.dtip { position: fixed; z-index: 70; pointer-events: none; background: #0f131c; border: 1px solid #2c3550; border-radius: 8px; padding: 7px 10px; font-size: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.5); max-width: 260px; }
.dtip b { display: block; margin-bottom: 2px; }
.dtip .row { display: flex; justify-content: space-between; gap: 14px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dtip .row span:first-child { color: var(--muted); font-family: var(--sans); }

@media (max-width: 1300px) {
  .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .c3, .c4, .c5 { grid-column: span 6; } .c6, .c8 { grid-column: span 12; }
}
@media (max-width: 760px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dgrid > * { grid-column: span 12 !important; }
  .dash { padding: 8px 16px 20px; height: auto; }
  .views button { padding: 4px 8px; }
}
@media (forced-colors: active) { .hbar .fill, .meter .bar i { forced-color-adjust: none; border: 1px solid CanvasText; } }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; gap: 8px; padding: 8px 16px; }
  .status { flex-wrap: wrap; }
  .grid { height: auto; }
}
/* the account label may shrink (ellipsis, full text on hover); money figures keep their width */
.hud-item:first-child { flex: 0 1 230px; min-width: 110px; overflow: hidden; }
.hud-item:first-child > span { max-width: 100%; }
