/* Demo page chrome only.
 *
 * Everything inside a panel — the tables, the blotter rows, the watchlist, the
 * icon buttons, the P&L colours — is styled by the package's own
 * styles/trading-controls.css. This file styles the page around them and does
 * one thing to the controls themselves: it re-declares the --t-* tokens.
 *
 * That is the documented way to re-skin the package (styles/theme.css says so in
 * its own header: "a host with its own brand does NOT load this file — it
 * declares the same custom properties itself"). We still load theme.css, so any
 * token this file forgets keeps a working default, and we override the handful
 * that carry the look — pointing them at the palette of the sschart demo so the
 * two demo pages read as one family.
 *
 * The board itself is dockview-core. Its stylesheet paints from --dv-* custom
 * properties, so the dockview chrome is re-pointed at the same --t-* tokens
 * below — one theme attribute flips the page, the panels and the dock together.
 */

/* ---------------------------------------------------------------- palette */

:root {
    --t-bg: #0b0e11;
    --t-panel: #131820;
    --t-header: #131820;
    --t-hover: #1b2230;
    --t-border: #2a3546;

    --t-text: #c7d0dc;
    --t-text-dim: #6b7a8d;
    --t-text-bright: #ffffff;

    --t-accent: #4a9eff;
    --t-accent-hover: #3b8ae6;
    --t-accent-text: #ffffff;
    --t-accent-glow-soft: rgba(74, 158, 255, 0.14);

    --t-green: #26a69a;
    --t-red: #ef5350;
    --t-green-flash: rgba(38, 166, 154, 0.28);
    --t-red-flash: rgba(239, 83, 80, 0.28);

    --t-orange: #e8a33d;
    --t-warning: #e8a33d;

    /* One monospace stack for the whole page, numerals included — a trading
       terminal is read as columns of digits. No @font-face anywhere: these are
       local family names, and the stack ends at the generic `monospace`. */
    --t-font: 'IBM Plex Mono', 'JetBrains Mono', 'Cascadia Mono', 'Consolas', monospace;
    --t-mono: 'IBM Plex Mono', 'JetBrains Mono', 'Cascadia Mono', 'Consolas', monospace;
    --t-radius: 4px;
}

/* The package's theme.css keys its light scheme off the same attribute, so the
   toggle in the header drives both halves at once. */
:root[data-bs-theme="light"] {
    --t-bg: #eef1f6;
    --t-panel: #f4f6fa;
    --t-header: #ffffff;
    --t-hover: #e6ebf3;
    --t-border: #cbd5e1;

    --t-text: #2a3441;
    --t-text-dim: #67748a;
    --t-text-bright: #0b1220;

    --t-accent: #2f6fed;
    --t-accent-hover: #2559c9;
    --t-accent-text: #ffffff;
    --t-accent-glow-soft: rgba(47, 111, 237, 0.10);

    --t-green: #0f9d80;
    --t-red: #e03d4e;
    --t-green-flash: rgba(15, 157, 128, 0.22);
    --t-red-flash: rgba(224, 61, 78, 0.22);

    --t-orange: #b45309;
    --t-warning: #b45309;
}

/* ------------------------------------------------------------- page shell */

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }

body {
    background: var(--t-bg);
    color: var(--t-text);
    font: 13px/1.45 var(--t-font);
    font-variant-numeric: tabular-nums;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
}

.demo-header {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 14px;
    flex: none;
    background: var(--t-header);
    border-bottom: 1px solid var(--t-border);
}

.demo-header .brand { font-weight: 700; font-size: 14px; color: var(--t-text-bright); }
.demo-header .sub { color: var(--t-text-dim); font-size: 12px; font-weight: 400; }
.demo-header .spacer { flex: 1; }

.tbtn {
    background: transparent;
    color: var(--t-text);
    border: 1px solid var(--t-border);
    border-radius: 6px;
    padding: 5px 11px;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.tbtn:hover { border-color: var(--t-accent); color: var(--t-accent); }
.tbtn.on { background: var(--t-accent); color: var(--t-accent-text); border-color: var(--t-accent); }
.tbtn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--t-red); opacity: .4; }
.tbtn.on .dot { background: #fff; opacity: 1; animation: demoPulse 1s ease-in-out infinite; }
@keyframes demoPulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.5); opacity: .35; } }

.tbtn-sm { padding: 2px 9px; font-size: 11px; border-radius: 4px; }

/* -------------------------------------------------------------- dock host */

/* The terminal's own answer to a short window: the dock never squeezes below a
   usable board — the page scrolls instead. 70px = the header and the statusbar.
   Clipped, because the 'always' renderer parks the overlays of hidden tab
   panels just past the shell's bottom edge — without the clip that parking lot
   stretches the page by a whole dock of empty scroll. */
.dock-host {
    flex: none;
    height: max(880px, calc(100vh - 70px));
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* The --dv-* custom properties are how dockview's stylesheet takes its colours.
   They are declared on the shell element dockview creates — the one carrying
   its theme class — so the overrides must land on that same element, or the
   theme class's own values shadow them. Pointing them at the --t-* tokens is
   what makes one theme attribute flip the dock together with everything else. */
.dock-host .dv-shell {
    --dv-group-view-background-color: var(--t-panel);
    --dv-tabs-and-actions-container-background-color: var(--t-panel);
    --dv-activegroup-visiblepanel-tab-background-color: var(--t-panel);
    --dv-activegroup-hiddenpanel-tab-background-color: var(--t-panel);
    --dv-inactivegroup-visiblepanel-tab-background-color: var(--t-panel);
    --dv-inactivegroup-hiddenpanel-tab-background-color: var(--t-panel);
    --dv-activegroup-visiblepanel-tab-color: var(--t-text);
    --dv-activegroup-hiddenpanel-tab-color: var(--t-text-dim);
    --dv-inactivegroup-visiblepanel-tab-color: var(--t-text-dim);
    --dv-inactivegroup-hiddenpanel-tab-color: var(--t-text-dim);
    --dv-tabs-and-actions-container-height: 30px;
    --dv-tabs-and-actions-container-font-size: 11px;
    --dv-separator-border: var(--t-bg);
    --dv-background-color: var(--t-bg);
    --dv-paneview-active-outline-color: var(--t-accent);
    --dv-drag-over-background-color: var(--t-accent-glow-soft);
    --dv-drag-over-border-color: var(--t-accent);
    --dv-active-sash-color: var(--t-accent);
}

/* Each dockview panel's content element. It must fill the box dockview gives
   it, so the widgets' tables and canvases report a real size. */
.terminal-dock-panel {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    background: var(--t-panel);
}

.terminal-dock-panel > .terminal-panel {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    height: 100%;
}

/* The watchlist's scroll container. The blotters wrap their table in
   `.panel-body-content`, which the package sizes and scrolls; the watchlist
   wraps its own in `.watchlist-pane`, which the package leaves to the host —
   without a height on it the table simply overflows the panel. */
.watchlist-panel .watchlist-pane { flex: 1; min-height: 0; overflow-y: auto; }

/* ----------------------------------------------------------- dockview tab */

/* One row of chrome per panel: the dockview tab carries the title, the
   control's own header buttons (lifted into `.terminal-tab-actions` by the
   page) and the ×. The controls' markup is designed for exactly this — their
   `.panel-header` comments say so. */
.terminal-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 100%;
    padding: 0 6px 0 10px;
    min-width: 0;
}

.terminal-tab-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--t-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 0 1 auto;
    min-width: 0;
}

/* The slot grows to fill the space between title and close, contents
   right-aligned so lifted control rows sit flush with the ×. */
.terminal-tab-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
    overflow: hidden;
}

.terminal-tab-close {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--t-text-dim);
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    line-height: 1;
}

.terminal-tab-close:hover { background: var(--t-hover); color: var(--t-text); }

/* Inactive tabs in a multi-tab group dim their title; dockview marks them
   with .dv-inactive-tab, so we ride that. */
.dv-inactive-tab .terminal-tab-title { opacity: 0.55; }

/* A lone fullwidth tab overflows whenever its lifted controls fill the strip,
   and dockview answers with a "hidden tabs" dropdown that has nothing to show.
   Groups with real multiple tabs keep the dropdown. */
.dock-host .dv-single-tab .dv-tabs-overflow-dropdown-root { display: none; }

/* The lifted watchlist search row loses its in-panel band look inside a tab. */
.terminal-tab-actions .watchlist-search-row {
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    flex: 0 1 180px;
    min-width: 60px;
}

.terminal-tab-actions .watchlist-search-input { width: 100%; padding: 2px 8px; font-size: 11px; }

/* ------------------------------------------------------------------ mobile */

/* The board itself goes single-column on a phone (demo.js builds the stack and
   pins the dock's height); the chrome around it just has to wrap and shed the
   parts a narrow screen has no room for. */
@media (max-width: 768px) {
    .demo-header {
        flex-wrap: wrap;
        height: auto;
        min-height: 44px;
        padding: 6px 10px;
        row-gap: 6px;
    }

    .demo-header .sub { display: none; }
    .tbtn { padding: 4px 8px; font-size: 11px; }

    .demo-statusbar { grid-template-columns: 1fr auto; }
    .demo-statusbar .status-left { display: none; }
}

/* --------------------------------------------------------------- statusbar */

.demo-statusbar {
    flex: none;
    height: 26px;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 14px;
    padding: 0 12px;
    background: var(--t-header);
    border-top: 1px solid var(--t-border);
    font-size: 11px;
    color: var(--t-text-dim);
}

.status-left, .status-right { white-space: nowrap; }

/* Filled by the primary watchlist through `ticker.publish` — page chrome the
   control reports into rather than draws. */
.ticker {
    display: flex;
    gap: 18px;
    align-items: center;
    height: 100%;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
    white-space: nowrap;
    font-size: 11px;
}

.ticker::-webkit-scrollbar { display: none; }
.ticker .tk-empty { color: var(--t-text-dim); }
.ticker .tk { display: inline-flex; gap: 6px; align-items: baseline; }
.ticker .tk-sym { color: var(--t-text-dim); font-weight: 600; }
.ticker .tk-px { color: var(--t-text-bright); }
.ticker .tk-chg.up { color: var(--t-green); }
.ticker .tk-chg.down { color: var(--t-red); }

/* ------------------------------------------------------------------- chart */

/* The SSChart canvases live here; the page tells the chart its size from a
   ResizeObserver, so the wrap only has to honestly fill the panel. */
.chart-wrap {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    position: relative;
}

/* ---------------------------------------------------------------- host log */

/* The port-traffic log is a dockview panel like everything else; its Clear
   button and caption ride in `.hostlog-actions`, which the page lifts into the
   panel's tab exactly as it lifts the controls' headers. */
.hostlog-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
}

.hostlog-note {
    font-size: 11px;
    color: var(--t-text-dim);
    text-transform: none;
    letter-spacing: normal;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Four tabs share that strip — the caption would crowd the ones beside it, so
   it only shows while its panel is the active one. */
.dv-inactive-tab .hostlog-note { display: none; }

.log {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 12px 8px;
    font-size: 11px;
}

.log-line { padding: 1px 0; color: var(--t-text-dim); white-space: pre-wrap; }
.log-line .t { color: var(--t-border); margin-right: 8px; }
.log-line .k { color: var(--t-accent); }
.log-line.data { color: var(--t-text); }
.log-line.act { color: var(--t-text-bright); }
.log-line.up { color: var(--t-green); }
.log-line.down { color: var(--t-red); }
.log-line.warn { color: var(--t-warning); }

/* ------------------------------------------------------------------- icons */

/* The controls emit Bootstrap Icons markup (`<i class="bi bi-x">`) and leave the
   icon font to the host — see dom.ts `makeIcon`. This page loads no web font, so
   it answers with plain Unicode glyphs instead. Presentation only: the buttons
   themselves come from the package and are wired to its own listeners. */
.bi { font-style: normal; line-height: 1; }
.bi::before { display: inline-block; }
.bi-x::before { content: '\2715'; }
.bi-x-circle::before { content: '\2297'; font-size: 13px; }
.bi-arrow-clockwise::before { content: '\21BB'; font-size: 13px; }
.bi-arrow-left-right::before { content: '\21C4'; font-size: 13px; }
.bi-file-earmark-spreadsheet::before { content: '\2913'; font-size: 13px; }
.bi-question-circle::before { content: '?'; font-weight: 700; }
.bi-plus-lg::before { content: '\FF0B'; }
.bi-distribute-horizontal::before { content: '\2551'; }
.bi-table::before { content: '\2261'; }
.bi-arrow-down-up::before { content: '\21C5'; }
.bi-graph-up::before { content: '\2197'; }
.bi-window-plus::before { content: '\229E'; }
.bi-list-ul::before { content: '\2630'; }
.bi-circle-fill::before { content: '\25CF'; font-size: 9px; }

/* ------------------------------------------------------- instrument picker */

/* What `trading.pickInstrument` puts on screen. It is page chrome, not part of
   any control: the order book asks for an instrument and this is the host's
   answer, so it is styled here rather than in the package. */
.picker {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    z-index: 50;
}

.picker-sheet {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 280px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 10px;
    background: var(--t-panel);
    border: 1px solid var(--t-border);
    border-radius: var(--t-radius);
}

.picker-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--t-text-dim);
    padding-bottom: 6px;
}

.picker-option {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--t-radius);
    color: var(--t-text);
    font-family: var(--t-font);
    font-size: 12px;
    text-align: left;
    padding: 5px 8px;
    cursor: pointer;
}

.picker-option:hover {
    background: var(--t-hover);
    border-color: var(--t-border);
    color: var(--t-text-bright);
}

.picker-dismiss { margin-top: 8px; align-self: flex-end; }
