/* Reaper — design system. Tokens first; components consume only tokens. */
:root {
  color-scheme: dark;
  --bg: #15171b;
  --surface: #1b1e23;
  --raised: #23272e;
  --hover: #2a2f37;
  --line: #2c313a;
  --line-soft: #22262c;
  --text: #e7e9ed;
  --text-2: #a7aeb9;
  --muted: #727a86;
  --accent: #8f7cff;
  --accent-strong: #a597ff;
  --accent-ink: #120f26;
  --accent-soft: rgba(143, 124, 255, .14);
  --up: #26b47f;
  --up-soft: rgba(38, 180, 127, .14);
  --down: #ef5a6f;
  --down-soft: rgba(239, 90, 111, .14);
  --warn: #e3a33b;
  --warn-soft: rgba(227, 163, 59, .13);
  --info: #5aa9e6;
  --focus: #b8adff;

  --font-ui: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-num: "Bahnschrift", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --fs-xs: .77rem;  /* 11px at 14 */
  --fs-s: .857rem;  /* 12px */
  --fs-m: 1rem;     /* 14px */
  --fs-l: 1.143rem; /* 16px */
  --fs-xl: 1.43rem; /* 20px */
  --fs-xxl: 2rem;   /* 28px */

  --r-s: 4px; --r-m: 6px; --r-l: 10px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;
  --row: 28px; --control: 32px;
  --rail: 208px;
  --shadow: 0 12px 40px rgba(0, 0, 0, .45);
  --ease: cubic-bezier(.2, .7, .2, 1);
}
html { font-size: 14px; }
html[data-text="s"] { font-size: 13px; }
html[data-text="l"] { font-size: 15.5px; }
html[data-density="comfortable"] { --row: 34px; --control: 36px; }
html[data-contrast="high"] {
  --bg: #0d0e10; --surface: #131518; --raised: #1b1e22; --line: #4a525e; --line-soft: #343a43;
  --text: #ffffff; --text-2: #d3d8df; --muted: #a8b0bb; --accent: #a99bff; --up: #3ddc97; --down: #ff7387; --warn: #ffbf4d;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: var(--fs-m)/1.45 var(--font-ui); -webkit-font-smoothing: antialiased; min-height: 100vh; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.005em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-l); }
h3 { font-size: var(--fs-m); }
p { margin: 0 0 var(--sp-2); }
small { font-size: var(--fs-s); }
hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-4) 0; }
.num, .tabular { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.up { color: var(--up); }
.down { color: var(--down); }
.warn-text { color: var(--warn); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: var(--r-m); }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #3a404a; border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
* { scrollbar-color: #3a404a transparent; scrollbar-width: thin; }

.ico { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ico.l { width: 20px; height: 20px; }
.ico.fill { fill: currentColor; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface); padding: var(--sp-3) var(--sp-2); gap: 2px; overflow-y: auto; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; color: var(--text); font-weight: 700; letter-spacing: .06em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); }
.brand-mark .ico { stroke-width: 2.2; }
.brand small { display: block; font-weight: 500; letter-spacing: 0; color: var(--muted); font-size: var(--fs-xs); }
.nav-item { display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px; border-radius: var(--r-m); color: var(--text-2); border: 0; background: none; width: 100%; text-align: left; cursor: pointer; position: relative; }
.nav-item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -8px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-item .count { margin-left: auto; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: var(--fs-xs); text-align: center; font-weight: 700; }
.rail-group { margin-top: var(--sp-3); padding: 4px 10px; color: var(--muted); font-size: var(--fs-xs); }
.rail-foot { margin-top: auto; padding: var(--sp-3) 10px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); }

.topbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: var(--sp-3); height: 52px; padding: 0 var(--sp-4); background: color-mix(in srgb, var(--bg) 92%, transparent); border-bottom: 1px solid var(--line); }
.search-trigger { display: flex; align-items: center; gap: 8px; width: min(380px, 40vw); height: var(--control); padding: 0 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); color: var(--muted); cursor: pointer; }
.search-trigger:hover { border-color: #3c4350; color: var(--text-2); }
.search-trigger kbd { margin-left: auto; }
kbd { font: 600 var(--fs-xs) var(--font-ui); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; color: var(--text-2); background: var(--raised); }
.top-spacer { flex: 1; }
.conn { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); font-size: var(--fs-s); white-space: nowrap; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.conn-dot.live { background: var(--up); }
.conn-dot.offline { background: var(--down); }
.mode-switch { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-m); overflow: hidden; }
.mode-switch button { border: 0; background: none; padding: 0 10px; height: 28px; font-size: var(--fs-s); font-weight: 600; color: var(--muted); cursor: pointer; }
.mode-switch button[aria-pressed="true"].demo { background: var(--warn-soft); color: var(--warn); }
.mode-switch button.live[aria-pressed="false"] { text-decoration: line-through; text-decoration-color: var(--muted); }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: var(--control); height: var(--control); border: 1px solid transparent; border-radius: var(--r-m); background: none; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--accent-strong); background: var(--accent-soft); }
.icon-btn .badge { position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--down); color: #fff; font-size: 10px; font-weight: 700; line-height: 15px; }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--raised); color: var(--text); font-size: var(--fs-s); font-weight: 700; flex: none; }
.avatar[data-color="violet"] { background: #4d42a3; } .avatar[data-color="teal"] { background: #1f6e63; } .avatar[data-color="amber"] { background: #8a5e17; }
.avatar[data-color="rose"] { background: #8c2f45; } .avatar[data-color="sky"] { background: #24608e; } .avatar[data-color="lime"] { background: #4c6b1c; }

.main { min-width: 0; display: flex; flex-direction: column; }
.view { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.view-head p { margin: 2px 0 0; color: var(--muted); }
.statusbar { display: flex; gap: var(--sp-4); align-items: center; padding: 6px var(--sp-4); border-top: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); margin-top: auto; flex-wrap: wrap; }
.statusbar a { color: var(--text-2); }

.bottom-nav { display: none; }

/* ---------- Mode banner ---------- */
.demo-ribbon { display: flex; align-items: center; gap: 8px; padding: 6px var(--sp-4); background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid rgba(227, 163, 59, .25); font-size: var(--fs-s); }
.demo-ribbon b { letter-spacing: .04em; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 4px; font-size: var(--fs-xs); font-weight: 600; background: var(--raised); color: var(--text-2); white-space: nowrap; }
.tag.demo { background: var(--warn-soft); color: var(--warn); }
.tag.up { background: var(--up-soft); color: var(--up); }
.tag.down { background: var(--down-soft); color: var(--down); }
.tag.accent { background: var(--accent-soft); color: var(--accent-strong); }
.tag.stale { background: var(--warn-soft); color: var(--warn); }
.tag.off { color: var(--muted); }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); min-width: 0; }
.panel-head { display: flex; align-items: center; gap: var(--sp-2); min-height: 40px; padding: 0 var(--sp-3); border-bottom: 1px solid var(--line-soft); }
.panel-head h2, .panel-head h3 { font-size: var(--fs-m); }
.panel-head .grow { flex: 1; }
.panel-body { padding: var(--sp-3); }
.panel-foot { padding: var(--sp-2) var(--sp-3); border-top: 1px solid var(--line-soft); color: var(--muted); font-size: var(--fs-xs); display: flex; gap: var(--sp-2); justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: var(--sp-4); }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line-soft); border-radius: var(--r-l); overflow: hidden; border: 1px solid var(--line); }
.kpi { background: var(--surface); padding: var(--sp-3); min-width: 0; }
.kpi span { display: block; color: var(--muted); font-size: var(--fs-s); }
.kpi strong { display: block; font: 600 var(--fs-xl)/1.25 var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi small { color: var(--muted); }
.kpi.big strong { font-size: var(--fs-xxl); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--control); padding: 0 12px; border-radius: var(--r-m); border: 1px solid var(--line); background: var(--raised); color: var(--text); font-weight: 600; font-size: var(--fs-s); cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.buy { background: var(--up); border-color: var(--up); color: #04150e; }
.btn.sell { background: var(--down); border-color: var(--down); color: #1d0509; }
.btn.danger { color: var(--down); border-color: rgba(239, 90, 111, .4); background: transparent; }
.btn.danger:hover { background: var(--down-soft); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.small { height: 26px; padding: 0 8px; font-size: var(--fs-xs); }
.btn.block { width: 100%; }
.btn[aria-busy="true"] { position: relative; color: transparent !important; }
.btn[aria-busy="true"]::after { content: ""; position: absolute; width: 14px; height: 14px; border: 2px solid currentColor; border-color: var(--text) transparent var(--text) transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.btn.primary[aria-busy="true"]::after { border-color: var(--accent-ink) transparent var(--accent-ink) transparent; }
@keyframes spin { to { transform: rotate(360deg); } }
.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-m); flex-wrap: nowrap; }
.seg button { height: calc(var(--control) - 6px); padding: 0 9px; border: 0; border-radius: var(--r-s); background: none; color: var(--text-2); font-size: var(--fs-s); font-weight: 600; cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg.buy-sell button[data-side="BUY"][aria-pressed="true"] { background: var(--up); color: #04150e; box-shadow: none; }
.seg.buy-sell button[data-side="SELL"][aria-pressed="true"] { background: var(--down); color: #1d0509; box-shadow: none; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-soft); padding: 0 var(--sp-2); overflow-x: auto; scrollbar-width: none; }
.tabs button { height: 38px; padding: 0 10px; border: 0; background: none; color: var(--muted); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button:hover { color: var(--text-2); }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.chip { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid var(--line); background: none; color: var(--text-2); font-size: var(--fs-s); cursor: pointer; white-space: nowrap; }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .label { font-size: var(--fs-s); color: var(--text-2); font-weight: 600; }
.input, select.input, textarea.input { height: var(--control); width: 100%; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-m); color: var(--text); min-width: 0; }
textarea.input { height: auto; min-height: 90px; padding: 8px 10px; resize: vertical; }
.input:hover { border-color: #3c4350; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input[aria-invalid="true"] { border-color: var(--down); }
.input::placeholder { color: #5b626d; }
.affix { position: relative; display: flex; align-items: center; }
.affix .input { padding-right: 58px; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.affix .suffix { position: absolute; right: 10px; color: var(--muted); font-size: var(--fs-s); pointer-events: none; }
.affix .prefix { position: absolute; left: 10px; color: var(--muted); font-size: var(--fs-s); pointer-events: none; }
.affix .prefix + .input { padding-left: 64px; }
.hint { font-size: var(--fs-xs); color: var(--muted); }
.error { font-size: var(--fs-s); color: var(--down); min-height: 0; margin: 0; }
.error:empty { display: none; }
.form-error { padding: 8px 10px; border-radius: var(--r-m); background: var(--down-soft); color: var(--down); font-size: var(--fs-s); }
.form-error:empty { display: none; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-s); color: var(--text-2); }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-3); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; min-width: 0; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
table.data th { position: sticky; top: 0; z-index: 1; background: var(--surface); color: var(--muted); font-weight: 600; text-align: left; height: 32px; padding: 0 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.data th.r, table.data td.r { text-align: right; }
table.data th button.sort { border: 0; background: none; color: inherit; font: inherit; cursor: pointer; padding: 0; display: inline-flex; gap: 4px; align-items: center; }
table.data th button.sort:hover { color: var(--text); }
table.data th[aria-sort] button.sort { color: var(--text); }
table.data td { height: var(--row); padding: 0 10px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.data td.num, table.data td.r { font-family: var(--font-num); font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: rgba(255, 255, 255, .025); }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.selected { background: var(--accent-soft); }
.pair-cell { display: flex; align-items: center; gap: 8px; }
.pair-cell b { font-weight: 600; }
.pair-cell small { color: var(--muted); }
.coin-dot { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--raised); color: var(--text-2); font-size: 9.5px; font-weight: 700; flex: none; letter-spacing: -.02em; }
.star-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; display: inline-grid; }
.star-btn[aria-pressed="true"] { color: var(--warn); }
.star-btn[aria-pressed="true"] .ico { fill: currentColor; }
.empty { padding: var(--sp-5) var(--sp-4); text-align: center; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: 4px; }
.empty .btn { margin-top: var(--sp-3); }
.skeleton { display: block; height: 12px; border-radius: 4px; background: linear-gradient(90deg, var(--raised), var(--hover), var(--raised)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.flash-up { animation: flashUp .7s var(--ease); }
.flash-down { animation: flashDown .7s var(--ease); }
@keyframes flashUp { from { color: var(--up); } }
@keyframes flashDown { from { color: var(--down); } }
.pager { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); color: var(--muted); font-size: var(--fs-s); }

/* ---------- Dialogs, sheets, toasts ---------- */
dialog { padding: 0; border: 1px solid var(--line); border-radius: var(--r-l); background: var(--surface); color: var(--text); box-shadow: var(--shadow); width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.wide { width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(5, 6, 8, .65); }
dialog[open] { animation: pop .18s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } }
.dlg-head { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-soft); }
.dlg-head h2 { flex: 1; }
.dlg-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); overflow: auto; max-height: calc(100vh - 170px); }
.dlg-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line-soft); }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; background: var(--raised); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: var(--r-m); box-shadow: var(--shadow); animation: pop .2s var(--ease); font-size: var(--fs-s); }
.toast.ok { border-left-color: var(--up); }
.toast.err { border-left-color: var(--down); }
.toast.warn { border-left-color: var(--warn); }
.toast p { margin: 0; flex: 1; }
.toast b { display: block; }
.toast button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0; }
.callout { display: flex; gap: 10px; padding: 10px 12px; border-radius: var(--r-m); background: var(--raised); color: var(--text-2); font-size: var(--fs-s); border: 1px solid var(--line-soft); }
.callout.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(227, 163, 59, .25); }
.callout.err { background: var(--down-soft); color: var(--down); border-color: rgba(239, 90, 111, .3); }
.callout .ico { margin-top: 1px; }
.callout p { margin: 0; }

/* ---------- Command palette ---------- */
#palette { width: min(640px, calc(100vw - 24px)); margin-top: 10vh; }
.pal-input { display: flex; align-items: center; gap: 10px; padding: 0 var(--sp-4); border-bottom: 1px solid var(--line); }
.pal-input input { flex: 1; height: 52px; border: 0; background: none; outline: none; font-size: var(--fs-l); }
.pal-list { max-height: min(60vh, 460px); overflow: auto; padding: 6px; }
.pal-group { padding: 8px 10px 4px; color: var(--muted); font-size: var(--fs-xs); }
.pal-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--r-m); background: none; text-align: left; cursor: pointer; color: var(--text); }
.pal-item[aria-selected="true"] { background: var(--accent-soft); }
.pal-item .meta { margin-left: auto; color: var(--muted); font-size: var(--fs-s); }

/* ---------- Trading terminal ---------- */
.terminal { --chart-col: 1fr; --side-col: 300px; --form-col: 300px; --bottom-h: 280px; display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--r-l); overflow: hidden; grid-template-columns: minmax(0, var(--chart-col)) 6px var(--side-col) var(--form-col); grid-template-rows: auto minmax(420px, 1fr) 6px var(--bottom-h); grid-template-areas: "head head head head" "chart split book form" "hsplit hsplit hsplit hsplit" "bottom bottom bottom bottom"; height: calc(100vh - 52px - 32px - 30px); min-height: 720px; }
.terminal > * { background: var(--surface); min-width: 0; min-height: 0; }
.t-head { grid-area: head; display: flex; align-items: center; gap: var(--sp-5); padding: 8px var(--sp-3); overflow-x: auto; scrollbar-width: none; }
.t-chart { grid-area: chart; display: flex; flex-direction: column; }
.t-side { grid-area: book; display: flex; flex-direction: column; gap: 1px; min-height: 0; background: var(--line); }
.t-book { display: flex; flex-direction: column; flex: 3 1 0; min-height: 0; background: var(--surface); }
.t-form { grid-area: form; overflow-y: auto; }
.t-bottom { grid-area: bottom; display: flex; flex-direction: column; }
.splitter { background: var(--line-soft); cursor: col-resize; position: relative; border: 0; padding: 0; }
.splitter:hover, .splitter:focus-visible { background: var(--accent); outline: none; }
.splitter.v { grid-area: split; }
.splitter.h { grid-area: hsplit; cursor: row-resize; }
.pair-switch { display: flex; align-items: center; gap: 8px; border: 0; background: none; padding: 4px 6px; border-radius: var(--r-m); cursor: pointer; }
.pair-switch:hover { background: var(--hover); }
.pair-switch b { font-size: var(--fs-l); }
.pair-switch span { color: var(--muted); }
.t-price { font: 600 var(--fs-xl)/1 var(--font-num); font-variant-numeric: tabular-nums; min-width: 9ch; }
.t-stat { display: flex; flex-direction: column; gap: 2px; white-space: nowrap; }
.t-stat span { color: var(--muted); font-size: var(--fs-xs); }
.t-stat strong { font: 500 var(--fs-s) var(--font-num); font-variant-numeric: tabular-nums; }
.chart-toolbar { display: flex; align-items: center; gap: 6px; padding: 6px var(--sp-2); border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.chart-toolbar .sep { width: 1px; height: 20px; background: var(--line); }
.chart-box { position: relative; flex: 1; min-height: 260px; touch-action: none; outline: none; }
.chart-box canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.chart-box:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.chart-legend { position: absolute; left: 8px; top: 6px; display: flex; gap: 10px; flex-wrap: wrap; font: var(--fs-xs) var(--font-num); font-variant-numeric: tabular-nums; color: var(--text-2); pointer-events: none; z-index: 2; padding-right: 80px; }
.chart-legend b { color: var(--muted); font-weight: 500; }
.chart-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); z-index: 3; text-align: center; padding: var(--sp-4); }
.chart-msg .btn { margin-top: var(--sp-2); }
.chart-foot { display: flex; justify-content: space-between; gap: var(--sp-2); padding: 4px var(--sp-2); border-top: 1px solid var(--line-soft); color: var(--muted); font-size: var(--fs-xs); }
.t-chart:fullscreen { background: var(--surface); }
.menu { position: relative; }
.menu-pop { position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 220px; padding: 6px; background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow); }
.menu-pop.right { left: auto; right: 0; }
.menu-pop .check { display: flex; padding: 6px 8px; border-radius: var(--r-s); }
.menu-pop .check:hover { background: var(--hover); }
.menu-pop .menu-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: 0; background: none; text-align: left; color: var(--text); border-radius: var(--r-s); cursor: pointer; font-size: var(--fs-s); }
.menu-pop .menu-item:hover { background: var(--hover); }
.menu-pop .menu-label { padding: 6px 8px 2px; color: var(--muted); font-size: var(--fs-xs); }

/* Order book */
.book-head, .book-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 0 var(--sp-2); font-size: var(--fs-xs); }
.book-head { height: 26px; align-items: center; color: var(--muted); border-bottom: 1px solid var(--line-soft); }
.book-head span:not(:first-child), .book-row span:not(:first-child) { text-align: right; }
.book-side { flex: 1; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.book-side.asks { justify-content: flex-end; }
.book-row { position: relative; height: 19px; align-items: center; font-family: var(--font-num); font-variant-numeric: tabular-nums; cursor: pointer; border: 0; background: none; color: var(--text-2); width: 100%; text-align: left; }
.book-row:hover { background: var(--hover); }
.book-row .depth { position: absolute; top: 1px; bottom: 1px; right: 0; opacity: .16; pointer-events: none; transform-origin: right; }
.book-row.bid .depth { background: var(--up); }
.book-row.ask .depth { background: var(--down); }
.book-row.bid span:first-child { color: var(--up); }
.book-row.ask span:first-child { color: var(--down); }
.book-row span { position: relative; }
.book-mid { display: flex; align-items: baseline; gap: 8px; padding: 6px var(--sp-2); border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.book-mid strong { font: 600 var(--fs-l) var(--font-num); font-variant-numeric: tabular-nums; }
.book-mid small { color: var(--muted); margin-left: auto; font-family: var(--font-num); }
.book-tools { display: flex; align-items: center; gap: 6px; padding: 6px var(--sp-2); }
.book-tools select { height: 26px; width: auto; padding: 0 6px; font-size: var(--fs-xs); }
.trades-list { overflow-y: auto; flex: 1; min-height: 0; }
.trade-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; height: 19px; align-items: center; padding: 0 var(--sp-2); font: var(--fs-xs) var(--font-num); font-variant-numeric: tabular-nums; }
.trade-row span:not(:first-child) { text-align: right; color: var(--text-2); }
.depth-canvas { width: 100%; height: 100%; display: block; }

/* Order form */
.order-form { padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-3); }
.order-form .seg { width: 100%; }
.order-form .seg button { flex: 1; }
.pct-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.pct-row button { height: 24px; border: 1px solid var(--line); background: var(--bg); color: var(--text-2); border-radius: var(--r-s); font-size: var(--fs-xs); cursor: pointer; }
.pct-row button:hover { border-color: var(--accent); color: var(--text); }
.summary { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: var(--fs-xs); color: var(--muted); }
.summary dd { margin: 0; text-align: right; color: var(--text-2); font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.summary dt { white-space: nowrap; }
.avail { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--muted); }
.avail strong { color: var(--text-2); font: 500 var(--fs-xs) var(--font-num); }
.adv { border-top: 1px solid var(--line-soft); padding-top: var(--sp-2); }
.adv summary { cursor: pointer; color: var(--text-2); font-size: var(--fs-s); }
.live-lock { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }

/* Status chips for orders */
.st { font-size: var(--fs-xs); font-weight: 600; }
.st.NEW, .st.PENDING_TRIGGER { color: var(--info); }
.st.PARTIALLY_FILLED { color: var(--warn); }
.st.FILLED { color: var(--up); }
.st.CANCELED, .st.EXPIRED { color: var(--muted); }
.st.REJECTED { color: var(--down); }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { position: relative; padding-left: 18px; font-size: var(--fs-s); }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.timeline li:not(:last-child)::after { content: ""; position: absolute; left: 6px; top: 15px; bottom: -12px; width: 1px; background: var(--line); }
.timeline time { color: var(--muted); font-size: var(--fs-xs); display: block; }

/* Allocation bar */
.alloc { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--raised); gap: 2px; }
.alloc span { display: block; height: 100%; min-width: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--fs-s); color: var(--text-2); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.sw-0 { background: #8f7cff; } .sw-1 { background: #4cc2d6; } .sw-2 { background: #e3a33b; } .sw-3 { background: #db6fb0; } .sw-4 { background: #7bbf5a; } .sw-5 { background: #6c7a92; }
.mini-chart { width: 100%; height: 180px; display: block; }

/* Calendar */
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.calendar .dow { color: var(--muted); font-size: var(--fs-xs); text-align: center; }
.calendar .day { min-height: 54px; padding: 4px 6px; border-radius: var(--r-s); background: var(--bg); border: 1px solid var(--line-soft); font-size: var(--fs-xs); display: flex; flex-direction: column; justify-content: space-between; }
.calendar .day.pos { background: var(--up-soft); }
.calendar .day.neg { background: var(--down-soft); }
.calendar .day b { color: var(--muted); font-weight: 500; }
.calendar .day span { font-family: var(--font-num); font-variant-numeric: tabular-nums; text-align: right; }

/* Account */
.settings-list { display: flex; flex-direction: column; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); padding: var(--sp-3) 0; border-bottom: 1px solid var(--line-soft); flex-wrap: wrap; }
.setting:last-child { border-bottom: 0; }
.setting > div:first-child { max-width: 60ch; }
.setting p { margin: 2px 0 0; color: var(--muted); font-size: var(--fs-s); }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; font: 600 var(--fs-m) var(--font-num); padding: var(--sp-3); background: var(--bg); border-radius: var(--r-m); border: 1px dashed var(--line); }
.secret { font: 600 var(--fs-m) var(--font-num); letter-spacing: .08em; word-break: break-all; padding: var(--sp-2); background: var(--bg); border-radius: var(--r-m); border: 1px solid var(--line); user-select: all; }
.lock-screen { position: fixed; inset: 0; z-index: 300; background: var(--bg); display: grid; place-items: center; padding: var(--sp-4); }
.lock-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: var(--sp-3); }

/* Knowledge base */
.article { max-width: 72ch; }
.article h3 { margin: var(--sp-4) 0 var(--sp-2); }
.article p, .article li { color: var(--text-2); }
.article ol, .article ul { padding-left: 1.2em; }
.kb-item { border-bottom: 1px solid var(--line-soft); }
.kb-item summary { padding: 10px 0; cursor: pointer; font-weight: 600; }
.kb-item summary::marker { color: var(--muted); }
.kb-item div { padding: 0 0 12px; color: var(--text-2); }
.term { border-bottom: 1px dotted var(--muted); cursor: help; }

/* Onboarding coach */
.coach { position: fixed; right: 16px; bottom: 16px; z-index: 150; width: min(340px, calc(100vw - 32px)); padding: var(--sp-4); background: var(--raised); border: 1px solid var(--accent); border-radius: var(--r-l); box-shadow: var(--shadow); }
.coach h3 { margin-bottom: 6px; }
.coach p { color: var(--text-2); font-size: var(--fs-s); }
.coach .steps { color: var(--muted); font-size: var(--fs-xs); }

/* ---------- Responsive ---------- */
@media (max-width: 1440px) { .terminal { --side-col: 270px; --form-col: 280px; } }
@media (max-width: 1279px) {
  :root { --rail: 60px; }
  .rail .label, .rail .rail-group, .rail .brand small, .rail .brand-text, .rail-foot { display: none; }
  .rail .nav-item { justify-content: center; padding: 0; }
  .rail .nav-item .count { position: absolute; top: 2px; right: 4px; margin: 0; }
  .brand { justify-content: center; padding: 6px 0 14px; }
  .terminal { grid-template-columns: minmax(0, 1fr) var(--form-col); grid-template-rows: auto minmax(380px, 52vh) 300px auto; grid-template-areas: "head head" "chart chart" "book form" "bottom bottom"; height: auto; min-height: 0; }
  .splitter { display: none; }
  .t-bottom { min-height: 320px; }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 899px) {
  .grid.two, .grid.three { grid-template-columns: minmax(0, 1fr); }
  .search-trigger { width: auto; }
  .search-trigger .label, .search-trigger kbd { display: none; }
}
@media (max-width: 759px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
  .topbar { padding: 0 var(--sp-3); gap: var(--sp-2); }
  .topbar .conn .conn-label { display: none; }
  .view { padding: var(--sp-3) var(--sp-3) 84px; }
  .statusbar { padding-bottom: 76px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; height: 60px; padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--line); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 10.5px; border: 0; background: none; text-decoration: none; }
  .bottom-nav [aria-current="page"] { color: var(--accent-strong); }
  .bottom-nav .ico { width: 20px; height: 20px; }
  .terminal { display: flex; flex-direction: column; height: auto; min-height: 0; border-radius: var(--r-m); }
  .t-head { gap: var(--sp-3); flex-wrap: wrap; }
  .t-head .t-stat.opt { display: none; }
  .mobile-tabs { display: flex !important; }
  .terminal[data-mtab] .t-chart, .terminal[data-mtab] .t-book, .terminal[data-mtab] .t-bottom { display: none; }
  .terminal[data-mtab="chart"] .t-chart { display: flex; height: 62vh; }
  .terminal[data-mtab="book"] .t-book { display: flex; height: 64vh; }
  .terminal[data-mtab="orders"] .t-bottom { display: flex; min-height: 50vh; }
  .t-form { display: none; }
  .mobile-trade-bar { display: grid !important; }
  .kpi strong { font-size: var(--fs-l); }
  .kpi.big strong { font-size: var(--fs-xl); }
  dialog.sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: var(--r-l) var(--r-l) 0 0; max-height: 92vh; }
  dialog.sheet[open] { animation: sheet .22s var(--ease); }
  .hide-m { display: none !important; }
  table.data td, table.data th { padding: 0 8px; }
  .toasts { bottom: 72px; }
  .coach { bottom: 72px; }
}
@keyframes sheet { from { transform: translateY(30px); opacity: .4; } }
.mobile-tabs { display: none; }
.mobile-trade-bar { display: none; position: fixed; left: 0; right: 0; bottom: 60px; z-index: 39; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 12px; background: var(--surface); border-top: 1px solid var(--line); }
.mobile-trade-bar .btn { height: 42px; font-size: var(--fs-m); }
@media (min-width: 2200px) { html { font-size: 15px; } .terminal { --side-col: 340px; --form-col: 340px; } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }
html[data-motion="reduce"] *, html[data-motion="reduce"] *::before, html[data-motion="reduce"] *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
@media (forced-colors: active) { .btn, .seg button, .chip, .tag { border: 1px solid ButtonText; } .book-row .depth { forced-color-adjust: none; } }
@media print { .rail, .topbar, .bottom-nav, .statusbar { display: none; } }
.statusbar .grow { flex: 1; }

/* ---------- Views: shared additions ---------- */
.t-tape { display: flex; flex-direction: column; flex: 2 1 0; min-height: 150px; background: var(--surface); }
.grow-1 { flex: 1 1 260px; }
.input.auto { width: auto; }
.input-icon { position: relative; }
.input-icon .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 32px; }
.sort-ind { font-size: 9px; color: var(--accent-strong); }
.coin-dot.big { width: 40px; height: 40px; font-size: 12px; }
.dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 16px; margin: 0 0 var(--sp-3); font-size: var(--fs-s); }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.kpis.flat { border: 0; border-radius: 0; }
.mini-chart.small { height: 140px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.list li:last-child { border-bottom: 0; }
.list li p { margin: 2px 0 0; color: var(--text-2); font-size: var(--fs-s); }
.list li .muted { margin-left: 8px; font-size: var(--fs-xs); }
.list li.unread b::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--accent); vertical-align: 1px; }
.list.inbox li { padding: 10px var(--sp-3); }
.list.inbox li .btn { margin-top: 6px; margin-right: 6px; }
.group-title { padding: var(--sp-3) var(--sp-3) var(--sp-1); font-size: var(--fs-s); color: var(--text-2); }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { display: grid; grid-template-columns: 90px minmax(0, 1fr) 110px; align-items: center; gap: 10px; font-size: var(--fs-s); }
.bars li b { text-align: right; font-weight: 600; }
.bar { display: block; height: 8px; border-radius: 4px; background: var(--raised); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; }
.bar.up i { background: var(--up); } .bar.down i { background: var(--down); }
.switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.reorder { list-style: none; margin: 0; padding: 0; min-width: 260px; }
.reorder li { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.reorder li span { flex: 1; }
.narrow { max-width: 560px; }
.avatar.large { width: 44px; height: 44px; font-size: var(--fs-l); }
.chip input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip:has(input:checked) { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.chip:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.chip .avatar { width: 14px; height: 14px; margin-right: 6px; }
fieldset.field { border: 0; padding: 0; margin: 0; }
tr.warn-row td { color: var(--warn); }
.thread { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: flex; flex-direction: column; gap: 10px; }
.thread li { padding: 10px 12px; border-radius: var(--r-m); background: var(--raised); border: 1px solid var(--line-soft); }
.thread li.staff { border-color: var(--accent); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0 0; }
button.link { border: 0; background: none; padding: 0; color: var(--accent-strong); text-decoration: underline; cursor: pointer; font: inherit; }
.keys td:first-child { width: 1%; white-space: nowrap; }
.row.center { justify-content: center; }
code { font-family: var(--font-num); font-size: .95em; }
.filters .field[hidden] { display: none; }
@media (max-width: 1279px) { .t-side .t-book { flex-basis: 0; } }
@media (max-width: 759px) {
  table.data .opt { display: none; }
  .t-side { display: contents; }
  .t-side .t-book, .t-side .t-tape { flex: none; }
  .t-tape { display: none; }
  .terminal[data-mtab="book"] .t-tape { display: flex; height: 40vh; }
  .terminal[data-mtab="book"] .t-book { height: 52vh; }
  .bars li { grid-template-columns: 70px minmax(0, 1fr) 90px; }
  .view-head .row { width: 100%; }
}
