/* Phase 1 theme tokens and chart-first layout. The retained TAPE components use base.css. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #131722; --panel: #131722; --raised: #1E222D; --hover: #2A2E39;
  --border: #2A2E39; --divider: #2A2E39; --text: #D1D4DC; --muted: #9598A1;
  --blue: #5B8AFF; --selected: #24344F;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #FFFFFF; --panel: #FFFFFF; --raised: #FFFFFF; --hover: #F0F3FA;
  --border: #E0E3EB; --divider: #E0E3EB; --text: #131722; --muted: #5D606B;
  --blue: #2962FF; --selected: #E3EBFF;
}
html, body, #root { margin: 0; width: 100%; height: 100%; background: var(--bg); color: var(--text); }
.terminal { height: 100dvh; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; font-variant-numeric: tabular-nums; }
.topbar { height: 40px; background: var(--panel); }
.topbar .wordmark { width: auto; padding: 0 10px; gap: 5px; color: var(--blue); }
.topbar > select[aria-label="Market"] { max-width: 126px; min-width: 52px; height: 30px; padding: 0 5px; border-color: var(--border); }
.mode-switch button { color: var(--muted); }
.mode-switch button.active, .mode-switch button:hover, .chart-footer button[aria-pressed="true"] { color: var(--blue); background: var(--selected); }
.chart-credit { color: var(--muted); white-space: nowrap; }
.local-feed-badge { border-radius: 3px; padding: 2px 6px; font-weight: 650; border: 1px solid var(--border); }
.local-feed-badge.live { color: var(--green); background: #08998118; }
.local-feed-badge.delayed { color: #F2B34C; background: #F2B34C18; }
.local-feed-badge.simulated { color: var(--blue); background: var(--selected); }
.local-feed-name, .local-feed-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.local-feed-detail { color: var(--muted); font-size: 11px; }
.local-form { display: grid; gap: 12px; padding: 12px 0; max-width: 100%; }
.local-form label:not(.check-row) { display: grid; gap: 6px; }
.local-form input:not([type="checkbox"]), .local-form select { padding: 7px 9px; width: 100%; border-color: var(--border); }
.local-form p { color: var(--muted); line-height: 1.5; margin: 0; }
.local-form button { justify-self: start; }
.local-loading { padding: 26px; }
:root[data-theme="light"] .mode-switch,
:root[data-theme="light"] .tool-divider,
:root[data-theme="light"] .order-ticket input,
:root[data-theme="light"] .order-ticket select { border-color: var(--border); }
:root[data-theme="light"] .chart-symbol-dot, :root[data-theme="light"] .symbol-monogram { background: var(--hover); color: var(--text); }
:root[data-theme="light"] .chart-footer button, :root[data-theme="light"] .source-link, :root[data-theme="light"] .replay-badge { color: var(--blue); }
:root[data-theme="light"] .local-feed-badge.delayed { color: #805400; }
:root[data-theme="light"] .watch-row { border-color: var(--divider); }
:root[data-theme="light"] .error-inline { color: #B02033; }
@media (max-width: 900px) {
  .workspace.dock-open .right-sidebar { display: flex; position: fixed; z-index: 22; right: 42px; top: 84px; bottom: 22px; width: min(320px, calc(100vw - 84px)); box-shadow: -8px 0 24px #0003; }
  .workspace.dock-open:has(.order-ticket) .right-sidebar { visibility: hidden; }
  .order-ticket { width: min(310px, calc(100vw - 50px)); }
  .topbar { overflow-x: auto; scrollbar-width: none; }
  .topbar > * { flex-shrink: 0; }
  .topbar .wordmark b { display: none; }
  .chart-type { display: flex; }
  .live-toolbar { padding-left: 8px; gap: 5px; }
  .live-toolbar button { white-space: nowrap; }
  .local-feed-detail { display: none; }
  .chart-footer { overflow-x: auto; }
}
@media (max-width: 600px) {
  .topbar { height: 44px; }
  .topbar .tool-button, .topbar .icon { min-height: 38px; }
  .topbar > select[aria-label="Market"] { max-width: 62px; }
  .topbar .toolbar-label span { display: none; }
  .local-feed-name { font-size: 10px; }
  .local-feed-badge { font-size: 11px; }
  .chart-credit { font-size: 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Phase 2 chart studies and object controls. */
.drawing-toolbar { min-height: 0; overflow-y: auto; scrollbar-width: none; }
.drawing-toolbar .tool-button { flex-shrink: 0; }
.drawing-toolbar .choice-trigger { min-height: 33px; }
.drawing-overlay { left: 0; top: 0; z-index: 3; }
.drawing-overlay .drawing-input { pointer-events: all; cursor: crosshair; touch-action: none; }
.drawing-overlay .interactive > :not(.drawing-handle), .drawing-overlay .interactive :is(line,polygon,rect,ellipse,text) { pointer-events: visiblePainted; cursor: move; touch-action: none; }
.drawing-overlay .drawing-handle { pointer-events: all; cursor: grab; touch-action: none; }
.drawing-overlay .locked :is(line,polygon,rect,ellipse,text,circle) { cursor: default; }
.drawing-overlay .locked .drawing-handle { pointer-events: none; }
.drawing-overlay text { pointer-events: none; }
.drawing-overlay .interactive text { pointer-events: all; }
.chart-study-key { display: flex; flex-wrap: wrap; gap: 4px; position: absolute; top: 65px; left: 8px; max-width: calc(100% - 85px); z-index: 4; pointer-events: none; }
.chart-study-key button { pointer-events: auto; font-size: 11px; padding: 2px 5px; border: 1px solid var(--border); border-radius: 4px; background: var(--panel); }
.study-panel { display: grid; grid-template-columns: minmax(170px,1fr) minmax(190px,1.05fr); min-height: 260px; }
.study-library, .study-editor { padding: 12px; min-width: 0; }
.study-library { border-right: 1px solid var(--border); }
.study-library input, .study-editor > label select { width: 100%; padding: 7px 8px; }
.study-list { display: grid; max-height: min(42dvh,355px); overflow-y: auto; margin-top: 8px; }
.study-list button { text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid var(--border); }
.study-list small, .tree-object-name small { color: var(--muted); display: block; font-size: 11px; margin-top: 3px; }
.study-editor > label { display: grid; gap: 6px; }
.study-editor .settings-tabs { padding: 0; margin: 8px 0; }
.study-editor .settings-tabs button { padding: 7px; }
.study-fields { display: grid; gap: 9px; align-content: start; }
.study-fields label:not(.check-row), .plot-settings { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.study-fields input[type=number] { width: 68px; }
.study-fields input:not([type=checkbox]), .study-fields select { min-height: 28px; }
.plot-settings label { justify-content: flex-start !important; }
.study-edit-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.study-edit-actions button { border: 1px solid var(--border); padding: 5px; border-radius: 4px; }
.drawing-tree { position: fixed; z-index: 24; top: 72px; right: 48px; bottom: 28px; width: min(316px,calc(100vw - 90px)); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 8px 22px #0004; }
.drawing-tree > header { padding: 10px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.drawing-tree > .check-row { margin: 7px 10px; }
.drawing-tree-list { overflow-y: auto; }
.tree-group, .tree-object { width: 100%; border-bottom: 1px solid var(--border); text-align: left; padding: 7px 9px; }
.tree-group { color: var(--muted); }
.tree-object.selected { background: var(--selected); }
.tree-object-name { text-align: left; overflow-wrap: anywhere; width: 100%; }
.tree-actions { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.tree-actions button, .drawing-selection button { padding: 4px 6px; border: 1px solid var(--border); border-radius: 4px; }
.drawing-selection { position: fixed; top: 77px; right: 54px; z-index: 18; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 5px; background: var(--panel); border: 1px solid var(--border); border-radius: 5px; max-width: calc(100vw - 100px); }
@media(max-width:600px) {
 .study-panel { grid-template-columns: 1fr; }
 .study-library { border-right: 0; border-bottom: 1px solid var(--border); }
 .study-list { max-height: 118px; }
 .study-editor .settings-tabs button { min-height: 34px; }
 .drawing-tree { right: 40px; }
 .chart-study-key { top: 58px; }
}
.study-templates { padding: 8px 12px; border-top: 1px solid var(--border); }
.study-templates summary { cursor: pointer; }
.study-templates > div { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.study-templates input, .study-templates select, .study-templates button { padding: 5px 7px; border: 1px solid var(--border); border-radius: 4px; }
.study-scroll { min-height: 0; overflow-y: auto; }
.study-scroll + footer { flex-shrink: 0; }

/* Phase 3 paper order and depth views. */
.ticket-market { display:flex; justify-content:space-between; align-items:center; gap:6px; font-variant-numeric:tabular-nums; }
.ticket-market small { display:block; color:var(--muted); }
.ticket-source { padding:3px 6px; color:var(--blue); background:var(--selected); border-radius:4px; font-size:11px; }
.order-ticket .order-types button { white-space:normal; min-height:34px; line-height:1.1; }
.ticket-explanation { min-height:32px; line-height:1.35; }
.ticket-margin-link { color:var(--blue); padding-left:5px; text-decoration:underline; }
.paper-form { min-height:0; overflow:auto; }
.paper-form + footer { flex-shrink:0; }
.margin-banner { padding:5px 10px; color:var(--text); background:#e7933828; border-bottom:1px solid var(--border); font-size:12px; }
.depth-panel { min-height:0; overflow:auto; padding:12px 15px; }
.depth-panel p { line-height:1.45; margin:0 0 10px; }
.depth-badge { background:var(--selected); color:var(--blue); padding:3px 6px; border-radius:4px; }
.depth-panel table { width:100%; text-align:center; border-collapse:collapse; font-variant-numeric:tabular-nums; }
.depth-panel td,.depth-panel th { padding:3px 5px; border-bottom:1px solid var(--border); width:33.33%; }
.depth-panel button { width:100%; min-height:25px; padding:2px 4px; border-radius:3px; }
.depth-panel button:hover,.depth-panel button:focus-visible { background:var(--selected); }
.depth-size { display:block; padding:2px 4px; border-radius:2px; }
.depth-size.bid { background:#08998128; margin-left:auto; }
.depth-size.ask { background:#f2364528; }
.depth-mid { background:var(--hover); }
.right-toolrail { min-height:0; overflow-y:auto; scrollbar-width:none; }
.right-toolrail > button { flex-shrink:0; }

/* Phase 4 market discovery and local alerts. */
.market-tool { min-height:0; overflow:auto; padding:12px 14px; }
.market-filters { display:grid; grid-template-columns:repeat(auto-fit,minmax(145px,1fr)); gap:8px; margin:10px 0; }
.market-filters label { min-width:0; display:grid; gap:4px; font-size:12px; }
.market-filters :is(input,select) { min-width:0; width:100%; min-height:34px; padding:5px 6px; border:1px solid var(--border); border-radius:4px; }
.market-summary,.market-tabs,.market-source-links,.market-pagination { display:flex; flex-wrap:wrap; align-items:center; gap:6px; }
.market-summary,.market-pagination { justify-content:space-between; }
.market-summary button,.market-tabs button,.market-source-links :is(button,a),.market-pagination button,.market-secondary {
 border:1px solid var(--border); border-radius:4px; padding:6px 8px; min-height:31px;
}
.market-tabs [aria-pressed=true] { color:var(--blue); background:var(--selected); }
.market-source-links a,.market-release-list a,.market-ticker { color:var(--blue); }
.market-source-links { margin:8px 0; }
.market-table { overflow:auto; }
.market-table table { width:100%; border-collapse:collapse; font-variant-numeric:tabular-nums; }
.market-table td,.market-table th { padding:6px 7px; border-bottom:1px solid var(--border); text-align:left; }
.market-table th { white-space:nowrap; }
.market-table small { display:block; min-width:80px; color:var(--muted); font-size:10px; }
.market-ticker { font-weight:650; }
.market-pagination { margin-top:10px; font-size:12px; }
.market-heatmap { display:grid; grid-template-columns:repeat(auto-fit,minmax(100px,1fr)); gap:5px; }
.market-heatmap button { display:grid; text-align:left; gap:2px; padding:8px; min-height:70px; border:1px solid var(--border); border-radius:4px; }
.market-heatmap small { font-size:10px; color:var(--muted); }
.market-release-list article { display:grid; gap:3px; padding:8px 0; border-bottom:1px solid var(--border); }
.market-release-list time,.market-release-list small { color:var(--muted); font-size:11px; }
.watch-sort { display:flex; align-items:center; gap:5px; padding:3px 8px; border-bottom:1px solid var(--border); font-size:12px; }
.watch-sort label { display:flex; gap:5px; align-items:center; }
.watch-sort select,.watch-sort button { border:1px solid var(--border); border-radius:4px; padding:3px 6px; }
.price-alerts { min-width:max-content; }
.price-alerts .market-summary,.price-alerts>.modal-note { padding:5px 8px; }
@media(max-width:600px) {
 .market-filters { grid-template-columns:repeat(2,minmax(0,1fr)); }
 .market-heatmap { grid-template-columns:repeat(3,minmax(0,1fr)); }
 .market-tool { padding:8px; }
}

/* Phase 5 Pine editor and local strategy results. */
.pine-studio { display:grid; gap:8px; }
.pine-studio :is(h3,p,figure) { margin:0; }
.pine-example { display:flex; flex-wrap:wrap; align-items:center; gap:8px; }
.pine-example select { border:1px solid var(--border); padding:5px 7px; border-radius:4px; }
.pine-studio textarea { width:100%; min-height:230px; resize:vertical; color:var(--text); background:var(--bg);
 border:1px solid var(--border); border-radius:5px; padding:9px; font:13px/1.55 ui-monospace,Consolas,monospace; tab-size:4; white-space:pre; }
.pine-diagnostic { padding:7px; background:#f236451f; border:1px solid #f2364570; border-radius:4px; }
.pine-diagnostic button { text-decoration:underline; margin-right:4px; }
.pine-footer { flex-wrap:wrap; }
.pine-tester { display:grid; gap:8px; min-width:0; }
.pine-tester .performance { display:grid; grid-template-columns:repeat(auto-fit,minmax(128px,1fr)); }
.pine-equity { padding:6px; color:var(--blue); border:1px solid var(--border); border-radius:4px; }
.pine-equity figcaption { color:var(--muted); }
.pine-equity svg { display:block; width:100%; height:100px; }

/* Phase 6 Replay workspace. The primary chart retains the full trading surface. */
.chart-board { grid-area:1/2; min-width:0; min-height:0; display:grid; gap:1px; background:var(--border); }
.chart-board > .chart-section { grid-area:auto; background:var(--bg); }
.chart-board.single { grid-template:minmax(0,1fr)/minmax(0,1fr); }
.chart-board.split { grid-template:minmax(0,1fr)/repeat(2,minmax(0,1fr)); }
.chart-board.stack { grid-template:repeat(2,minmax(0,1fr))/minmax(0,1fr); }
.chart-board.quad { grid-template:repeat(2,minmax(0,1fr))/repeat(2,minmax(0,1fr)); }
.replay-comparison { display:flex; flex-direction:column; min-height:0; min-width:0; background:var(--bg); }
.replay-comparison > header { display:flex; align-items:center; flex-wrap:wrap; gap:7px; padding:4px 8px; border-bottom:1px solid var(--border); font-size:11px; }
.replay-comparison > header span { color:var(--muted); }
.replay-comparison > header button { margin-left:auto; color:var(--blue); padding:4px; }
.replay-comparison-chart { position:relative; min-height:0; flex:1; }
.replay-comparison-canvas { position:absolute; inset:0; }
.replay-comparison-chart p { position:absolute; inset:40% 8px auto; text-align:center; color:var(--muted); pointer-events:none; }
.replay-layout-form { display:grid; gap:10px; }
.replay-layout-form h3,.replay-layout-form p { margin:0; }
.replay-layout-picker { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:7px; }
.replay-layout-picker button { display:grid; justify-items:center; align-items:center; gap:4px; min-height:58px; padding:4px; border:1px solid var(--border); border-radius:5px; }
.replay-layout-picker [aria-pressed=true] { background:var(--selected); border-color:var(--blue); }
.layout-thumbnail { width:34px; height:22px; display:grid; grid-template:1fr/1fr; gap:2px; }
.layout-thumbnail.split { grid-template:1fr/1fr 1fr; }
.layout-thumbnail.stack { grid-template:1fr 1fr/1fr; }
.layout-thumbnail.quad { grid-template:1fr 1fr/1fr 1fr; }
.layout-thumbnail i { border:1px solid var(--muted); border-radius:2px; }
.replay-layout-sync { display:flex; flex-wrap:wrap; gap:8px 12px; }
.replay-layout-sync label { display:flex; align-items:center; gap:5px; }
.replay-layout-sync select { border:1px solid var(--border); border-radius:4px; padding:3px; }
.replay-slot { margin:0; border:1px solid var(--border); padding:8px; border-radius:5px; }
.replay-slot legend { color:var(--muted); }
.replay-layout-presets { display:grid; gap:6px; }
@media(max-width:850px) {
 .chart-board:not(.single) { grid-template:none; grid-template-columns:minmax(0,1fr); grid-auto-rows:minmax(240px,1fr); overflow:auto; }
}
@media(max-width:530px) {
 .replay-layout-picker { grid-template-columns:repeat(2,minmax(0,1fr)); }
}

/* Phase 7 crypto directory */
.crypto-explorer .market-filters{display:flex;align-items:end;gap:.65rem;flex-wrap:wrap}
.crypto-explorer .market-filters label{display:flex;align-items:center;gap:.4rem;flex-wrap:wrap}
.crypto-explorer .market-filters input{width:9rem}
.crypto-table{max-height:48vh;overflow:auto;margin:.65rem 0}
.crypto-table table{min-width:850px;width:100%;border-collapse:collapse;font-size:12px}
.crypto-table th,.crypto-table td{text-align:left;padding:.5rem;white-space:nowrap;border-bottom:1px solid var(--line,#303540)}
.crypto-table th{position:sticky;top:0;background:var(--panel,#1e222d);z-index:1}
.crypto-table small{display:block;max-width:27rem;white-space:normal;overflow-wrap:anywhere;opacity:.75}
.crypto-wrap{overflow-wrap:anywhere}
.local-feed-badge.cached,.local-feed-badge.unavailable{color:#e7ab53}
.instrument-results .instrument-row{content-visibility:auto;contain-intrinsic-block-size:auto 48px}

/* Chart-side technical analysis */
.pattern-panel{position:absolute;z-index:7;top:96px;right:76px;width:min(298px,calc(100% - 90px));color:#e4eaf3;background:#131c29f7;border:1px solid #334157;border-radius:10px;box-shadow:0 10px 30px #0005;font-size:12px;overflow:hidden}
.chart-section{position:relative}
.pattern-panel header{display:flex;align-items:center;gap:9px;padding:9px 10px;border-bottom:1px solid #263449}
.pattern-panel header>div{flex:1;min-width:0}
.pattern-panel header strong{display:block;font-size:13px;letter-spacing:.01em}
.pattern-panel header small,.pattern-summary small,.pattern-empty,.pattern-evidence{color:#a5b2c5}
.pattern-icon{display:grid;place-items:center;width:28px;height:28px;background:#233249;border-radius:7px;color:#9fc5fd}
.pattern-panel button,.pattern-panel select{color:inherit;border:1px solid #344357;background:#1a2637;border-radius:5px;padding:4px 6px}
.pattern-panel button:hover{background:#293a53}
.pattern-panel button:focus-visible,.pattern-panel select:focus-visible{outline:2px solid #8bb7f5;outline-offset:1px}
.pattern-panel header button{display:grid;place-items:center;background:transparent;border-color:transparent}
.pattern-content{padding:10px;max-height:min(440px,57vh);overflow:auto}
.pattern-controls,.pattern-options,.pattern-heading,.pattern-meter{display:flex;justify-content:space-between;align-items:center;gap:7px}
.pattern-controls label,.pattern-options label{display:flex;align-items:center;gap:5px}
.pattern-options{margin:8px 0;color:#b7c4d5}
.pattern-options button{display:inline-flex;align-items:center;gap:4px}
.pattern-list{display:grid;gap:4px;max-height:78px;overflow:auto}
.pattern-list button{display:flex;justify-content:space-between;text-align:left}
.pattern-list button[aria-pressed=true]{border-color:#678ab7;background:#24344b}
.pattern-summary{--tone:#e4b66e;border-top:1px solid #2d3b51;margin-top:8px;padding-top:8px}
.pattern-summary.bull{--tone:#62d5b5}.pattern-summary.bear{--tone:#f798a1}
.pattern-heading h3{font-size:14px;margin:3px 0 6px}
.pattern-signal{color:var(--tone);background:#1d2a3b;border-radius:4px;padding:4px 5px;font-size:10px;font-weight:700;white-space:nowrap}
.pattern-meter strong{color:var(--tone);font-variant-numeric:tabular-nums}
.pattern-summary progress{display:block;width:100%;height:5px;margin:5px 0 9px;accent-color:var(--tone)}
.pattern-levels{display:grid;grid-template-columns:repeat(3,1fr);margin:0;background:#182436;border-radius:5px;padding:7px;gap:4px}
.pattern-levels dt{font-size:10px;color:#a5b2c5}.pattern-levels dd{margin:2px 0 0;font-variant-numeric:tabular-nums;font-weight:600}
.pattern-summary p,.pattern-empty{margin:7px 0;line-height:1.4}
.pattern-evidence small{display:block;margin:3px 0}
.pattern-panel .pattern-reset{color:#a5b2c5;border-color:transparent;background:transparent}
@media(max-width:700px){
 .pattern-panel{top:auto;bottom:30px;right:8px;left:8px;width:auto;max-width:400px;margin-inline:auto}
 .pattern-content{max-height:33vh}
}
