/* Trading terminal. Panels meet on one-pixel seams (the grid gap shows --line), no cards. Tokens only. */
body.is-terminal { background: var(--line); font-size: 14px; }
.term { min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; background: var(--line); gap: 1px; }
.num { letter-spacing: 0; font-weight: 500; }
.up { color: var(--profit); }
.down { color: var(--loss); }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.hint.up { color: var(--profit); }
.hint.down { color: var(--loss); }
.panel-h { font-family: var(--font-body); font-size: 13px; font-weight: 650; letter-spacing: 0.01em; }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; margin-left: 6px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-text); font-family: var(--font-mono); font-size: 11px; }
.hide-sm { display: none; }
@media (min-width: 760px) { .hide-sm { display: revert; } }
.button { min-height: 40px; padding: 8px 16px; font-size: 13px; }
.button-primary:hover { background: color-mix(in srgb, var(--accent-fill) 88%, var(--ink)); }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-text); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 0.2em; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
input, select { font: inherit; }

/* ── Head ── */
.term-head { display: flex; align-items: center; gap: 12px 20px; padding: 0 16px; min-height: 52px; background: var(--bg); flex-wrap: wrap; }
.brand-mark { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-family: var(--font-display); font-weight: 600; letter-spacing: 0.02em; min-height: 44px; }
.term-nav { display: flex; gap: 4px; }
.term-nav a { text-decoration: none; color: var(--muted-strong); font-size: 13px; font-weight: 600; padding: 12px 10px; border-radius: var(--radius-sm); }
.term-nav a:hover { color: var(--ink); background: var(--surface); }
.acct-switch select { min-height: 36px; background: var(--surface); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 4px 10px; font-size: 13px; max-width: 280px; }
.term-stats { display: flex; gap: 22px; margin-left: auto; }
.term-stats dt { font-size: 11px; color: var(--muted); }
.term-stats dd { font-size: 14px; }
@media (max-width: 759px) { .term-nav { order: 3; width: 100%; overflow-x: auto; } .term-stats { gap: 14px; } }

/* ── Grid ── */
.term-grid { display: grid; gap: 1px; background: var(--line); grid-template-columns: minmax(0, 1fr); grid-template-areas: "market" "chart" "order" "rules" "tables" "book"; }
.term-grid > * { background: var(--bg); min-width: 0; }
.market-head { grid-area: market; }
.area-chart { grid-area: chart; height: clamp(380px, 64svh, 620px); }
.area-book { grid-area: book; }
.area-order { grid-area: order; }
.area-rules { grid-area: rules; }
.area-tables { grid-area: tables; }
@media (min-width: 1024px) {
  .term-grid { grid-template-columns: minmax(0, 1fr) 328px; grid-template-rows: auto minmax(500px, calc(100dvh - 52px - 58px - 300px - 34px)) auto auto; grid-template-areas: "market order" "chart order" "tables rules" "book rules"; }
  .area-chart { height: auto; }
}
@media (min-width: 1360px) {
  .term-grid { grid-template-columns: minmax(0, 1fr) 272px 328px; grid-template-rows: auto minmax(520px, calc(100dvh - 52px - 58px - 300px - 34px)) minmax(300px, auto); grid-template-areas: "market market order" "chart book order" "tables tables rules"; }
}

/* ── Market head ── */
.market-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 28px; padding: 8px 16px; min-height: 58px; }
.symbol-btn { display: grid; grid-template-columns: auto auto; column-gap: 8px; align-items: center; text-align: left; background: none; border: 0; color: var(--ink); padding: 6px 8px; margin-left: -8px; border-radius: var(--radius-sm); min-height: 44px; }
.symbol-btn:hover { background: var(--surface); }
.symbol-btn strong { font-family: var(--font-display); font-weight: 600; font-size: 16px; }
.symbol-btn span { grid-column: 1; font-size: 11px; color: var(--muted); }
.symbol-btn svg { grid-column: 2; grid-row: 1 / 3; color: var(--muted); }
.mh-price { display: flex; align-items: baseline; gap: 10px; }
.mh-price strong { font-size: 22px; }
.mh-facts { display: flex; gap: 22px; }
.mh-facts dt { font-size: 11px; color: var(--muted); }
.mh-facts dd { font-size: 13px; }

/* ── Menus and pickers ── */
.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 200px; display: grid; padding: 6px; background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); }
.menu > button { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 6px 10px 6px 30px; position: relative; background: none; border: 0; color: var(--ink); border-radius: 4px; text-align: left; font-size: 13px; }
.menu > button svg { position: absolute; left: 8px; color: var(--accent); }
.menu > button:hover { background: var(--surface); }
.menu-wide { min-width: 280px; }
.check-row { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.check-row:hover { background: var(--surface); }
.check-row input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--accent-fill); }
.check-row span { display: grid; gap: 2px; font-size: 13px; }
.check-row small { color: var(--muted); font-size: 11px; }
.picker { width: min(92vw, 360px); padding: 8px; }
.picker-search { display: flex; align-items: center; gap: 8px; padding: 0 10px; margin-bottom: 6px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted); }
.picker-search input { flex: 1; min-height: 40px; background: none; border: 0; color: var(--ink); outline: none; }
.picker-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.picker ul { max-height: 360px; overflow-y: auto; display: grid; }
.picker li button { display: grid; grid-template-columns: minmax(0, 1fr) auto 76px; gap: 12px; align-items: center; width: 100%; min-height: 48px; padding: 6px 10px; background: none; border: 0; color: var(--ink); text-align: left; border-radius: 4px; font-size: 13px; }
.picker li button:hover, .picker li button[aria-current="true"] { background: var(--surface); }
.picker li button span:first-child { display: grid; }
.picker li small { color: var(--muted); font-size: 11px; }
.picker .num { text-align: right; }

/* ── Chart ── */
.chart-shell { height: 100%; display: flex; flex-direction: column; background: var(--surface); }
.chart-shell.is-full { position: fixed; inset: 0; z-index: 100; }
.chart-bar { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-bottom: 1px solid var(--line); min-height: 44px; overflow-x: auto; scrollbar-width: none; }
.chart-bar::-webkit-scrollbar { display: none; }
.chart-bar .menu-wrap { flex: none; }
.bar-gap { flex: 1; }
.seg { display: inline-flex; flex: none; padding: 2px; border-radius: var(--radius-sm); background: var(--bg); }
.seg button { min-width: 38px; min-height: 32px; padding: 0 8px; background: none; border: 0; color: var(--muted-strong); font-family: var(--font-mono); font-size: 12px; border-radius: 4px; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.tool-btn { display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; padding: 0; background: none; border: 0; border-radius: var(--radius-sm); color: var(--muted-strong); }
.tool-btn.wide { display: inline-flex; gap: 6px; width: auto; padding: 0 10px; font-size: 13px; }
.tool-btn.text { width: auto; padding: 0 10px; font-family: var(--font-mono); font-size: 12px; }
.tool-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.tool-btn[aria-pressed="true"], .tool-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-text); }
.chart-body { flex: 1; display: flex; min-height: 0; }
.draw-bar { display: flex; flex-direction: column; gap: 2px; padding: 6px 4px; border-right: 1px solid var(--line); overflow-y: auto; scrollbar-width: none; }
.draw-sep { height: 1px; margin: 4px 6px; background: var(--line-strong); }
.chart-canvas { position: relative; flex: 1; min-width: 0; }
.chart-canvas.is-drawing { cursor: crosshair; }
.chart-box { position: absolute; inset: 0; }
.chart-box:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.legend { position: absolute; top: 8px; left: 10px; z-index: 3; pointer-events: none; display: grid; gap: 4px; font-size: 12px; }
.legend-title { display: flex; gap: 10px; align-items: baseline; }
.legend-title strong { font-family: var(--font-display); font-weight: 600; font-size: 13px; }
.legend-title span { color: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.legend-ohlc { display: flex; flex-wrap: wrap; gap: 2px 12px; font-family: var(--font-mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.legend-ohlc i { font-style: normal; color: var(--muted); margin-right: 4px; }
.chart-noscript { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }
@media (max-width: 759px) {
  .chart-body { flex-direction: column; }
  .draw-bar { flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; padding: 2px 6px; }
  .draw-sep { width: 1px; height: auto; margin: 6px 4px; }
  .legend-ohlc span:nth-child(n + 5) { display: none; }
}
@media (pointer: coarse) { .tool-btn { width: 44px; height: 44px; } .seg button { min-height: 40px; min-width: 44px; } }

/* ── Book and tape ── */
.book { display: flex; flex-direction: column; height: 100%; font-size: 12px; }
.tabs-mini { display: flex; gap: 2px; padding: 3px; background: var(--surface); border-radius: var(--radius-sm); }
.tabs-mini button { flex: 1; min-height: 34px; padding: 0 10px; background: none; border: 0; border-radius: 4px; color: var(--muted-strong); font-size: 13px; font-weight: 600; white-space: nowrap; }
.tabs-mini button:hover { color: var(--ink); }
.tabs-mini button[aria-checked="true"], .tabs-mini button[aria-selected="true"] { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.tabs-flat { background: none; border-bottom: 1px solid var(--line); border-radius: 0; padding: 0 8px; gap: 4px; }
.tabs-flat button { flex: none; border-radius: 0; min-height: 40px; }
.tabs-flat button[aria-selected="true"] { background: none; box-shadow: inset 0 -2px 0 var(--accent); }
.book-head, .book-side button, .tape li { display: grid; grid-template-columns: 1.1fr 1fr 1fr; gap: 6px; padding: 0 12px; }
.book-head { padding-block: 8px 4px; color: var(--muted); font-size: 11px; }
.book-head span:not(:first-child), .book-side span:not(:first-child), .tape span:not(:first-child) { text-align: right; }
.book-side button { position: relative; width: 100%; min-height: 21px; align-items: center; background: none; border: 0; color: var(--ink); font-family: var(--font-mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.book-side button:hover { background: var(--surface); }
.book-side span { position: relative; z-index: 1; }
.depth { position: absolute; right: 0; top: 1px; bottom: 1px; }
.depth.ask { background: var(--loss-soft); }
.depth.bid { background: var(--profit-soft); }
.book-mid { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 12px; border-block: 1px solid var(--line); }
.book-mid strong { font-size: 16px; }
.book-mid span { color: var(--muted); font-size: 11px; }
.tape { font-family: var(--font-mono); font-size: 11.5px; }
.tape li { min-height: 21px; align-items: center; }
.tape li span:last-child { color: var(--muted); }

/* ── Order panel ── */
.order-panel { padding: 14px 16px 18px; }
.order-panel form { display: grid; gap: 14px; }
.side-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.side-switch button { display: grid; gap: 2px; min-height: 52px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font-weight: 650; font-size: 15px; }
.side-switch small { font-size: 11px; font-weight: 500; color: var(--muted); }
.side-switch .buy[aria-checked="true"] { background: var(--profit); border-color: var(--profit); color: var(--on-profit); }
.side-switch .sell[aria-checked="true"] { background: var(--loss); border-color: var(--loss); color: var(--on-loss); }
.side-switch button[aria-checked="true"] small { color: inherit; opacity: 0.85; }
.o-field { display: grid; gap: 6px; }
.o-field > label, .label-row label { font-size: 12px; font-weight: 600; color: var(--muted-strong); }
.label-row { display: flex; justify-content: space-between; align-items: center; }
.unit-toggle { display: inline-flex; gap: 2px; padding: 2px; background: var(--surface); border-radius: 4px; }
.unit-toggle button { min-height: 28px; padding: 0 8px; background: none; border: 0; border-radius: 3px; color: var(--muted); font-family: var(--font-mono); font-size: 11px; }
.unit-toggle button[aria-checked="true"] { background: var(--surface-2); color: var(--ink); }
.input-unit { display: flex; align-items: center; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.input-unit:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.input-unit input, .bracket-grid input, .bracket-form input { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; background: none; border: 0; color: var(--ink); font-family: var(--font-mono); font-size: 14px; outline: none; }
.bracket-grid input, .bracket-form input { background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); }
.bracket-grid input:focus-visible, .bracket-form input:focus-visible { border-color: var(--accent); }
.unit { padding: 0 12px; color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.unit-btn { margin-right: 4px; min-height: 34px; padding: 0 10px; background: var(--surface-2); border: 0; border-radius: 4px; color: var(--muted-strong); font-size: 12px; }
.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.presets button { min-height: 32px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; color: var(--muted-strong); font-family: var(--font-mono); font-size: 12px; }
.presets button:hover { border-color: var(--line-strong); color: var(--ink); }
.check-line { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 13px; color: var(--muted-strong); cursor: pointer; }
.check-line input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent-fill); }
.bracket-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.order-sum { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; }
.order-sum > div { display: flex; justify-content: space-between; gap: 12px; }
.order-sum dt { color: var(--muted); }
.order-sum dd { text-align: right; }
.order-sum .warn dd { color: var(--loss); }
.form-warn { font-size: 12px; color: var(--ink); background: var(--loss-soft); border-left: 3px solid var(--loss); padding: 8px 10px; border-radius: 4px; }
.submit { display: grid; gap: 2px; min-height: 54px; border: 0; border-radius: var(--radius-sm); font-weight: 700; font-size: 15px; }
.submit small { font-size: 11px; font-weight: 500; opacity: 0.85; }
.submit.buy { background: var(--profit); color: var(--on-profit); }
.submit.sell { background: var(--loss); color: var(--on-loss); }
.submit:hover:not(:disabled) { filter: brightness(1.06); }
.form-error { min-height: 1em; font-size: 12px; color: var(--loss); }
.order-locked { display: grid; gap: 10px; margin-top: 12px; }
.order-locked .actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ── Rules panel ── */
.rules { padding: 14px 16px 18px; display: grid; gap: 14px; align-content: start; }
.rules-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.chip { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; padding: 3px 8px; border-radius: 4px; background: var(--surface-2); color: var(--muted-strong); }
.chip-active { color: var(--accent-text); background: var(--accent-soft); }
.chip-passed { color: var(--profit); background: var(--profit-soft); }
.chip-failed { color: var(--loss); background: var(--loss-soft); }
.equity-line { display: grid; gap: 2px; }
.equity-line .label { font-size: 11px; }
.equity-line strong { font-size: 24px; }
.equity-line span.num { font-size: 13px; }
.rule-rows { display: grid; gap: 14px; }
.rule-rows li { display: grid; gap: 6px; }
.rule-top { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; }
.rule-top .num { color: var(--muted-strong); font-size: 12px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 3px; transition: width 400ms ease; }
.meter-gold span { background: var(--gold); }
.meter-loss span { background: var(--loss); }
.meter-accent span { background: var(--accent); }
.days { display: flex; gap: 6px; }
.days span { flex: 1; height: 6px; border-radius: 3px; background: var(--surface-2); }
.days span.on { background: var(--profit); }
.rules-preview { display: grid; }
.rules-preview li { display: flex; justify-content: space-between; padding-block: 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.verdict { display: grid; gap: 8px; padding: 12px; border-radius: var(--radius-sm); justify-items: start; font-size: 13px; }
.verdict-passed { background: var(--profit-soft); border-left: 3px solid var(--profit); }
.verdict-failed { background: var(--loss-soft); border-left: 3px solid var(--loss); }
.button-quiet { border-color: var(--line-strong); }

/* ── Tables ── */
.tables { display: flex; flex-direction: column; min-height: 260px; }
.table-scroll { overflow: auto; flex: 1; max-height: 340px; }
.grid-table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 720px; }
.grid-table th { position: sticky; top: 0; background: var(--bg); text-align: left; font-weight: 500; font-size: 11px; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
.grid-table td.num, .grid-table .r { text-align: right; }
.grid-table small { display: block; font-size: 11px; color: inherit; opacity: 0.85; }
.grid-table tbody tr:hover { background: var(--surface); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions button { min-height: 32px; padding: 0 10px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); font-size: 12px; }
.row-actions button:hover:not(:disabled) { border-color: var(--muted); }
.row-actions .danger:hover:not(:disabled) { border-color: var(--loss); color: var(--loss); }
@media (pointer: coarse) { .row-actions button, .presets button { min-height: 44px; } }
.edit-row td { background: var(--surface); }
.bracket-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 6px 0; }
.bracket-form label { display: grid; gap: 4px; font-size: 11px; color: var(--muted); }
.empty-row { padding: 24px 16px; color: var(--muted); font-size: 13px; }

/* ── Toast and foot ── */
.toast { position: fixed; right: 16px; bottom: 16px; z-index: 60; max-width: min(92vw, 420px); display: none; }
.toast-ok, .toast-err { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line-strong); border-left-width: 3px; border-radius: var(--radius-sm); box-shadow: var(--shadow-pop); font-size: 13px; }
.toast-ok { border-left-color: var(--profit); }
.toast-err { border-left-color: var(--loss); }
.toast button { flex: none; display: grid; place-items: center; width: 28px; height: 28px; background: none; border: 0; color: var(--muted); border-radius: 4px; }
.term-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; padding: 8px 16px; background: var(--bg); color: var(--muted); font-size: 11px; }
.term-foot a { color: var(--muted-strong); }
.skip-link:focus { z-index: 200; }

.rules-model + .rules-model { margin-top: 14px; }
.rules-model .label { font-size: 11px; color: var(--muted-strong); }
.rules-terms { display: grid; margin-top: 4px; }
.rules-terms > div { display: flex; justify-content: space-between; gap: 12px; padding-block: 8px; border-bottom: 1px solid var(--line); font-size: 12px; }
.rules-terms dt { color: var(--muted); }
.rules-terms dd { text-align: right; }
