:root {
  --bg: #131722;
  --panel: #1e222d;
  --panel-2: #262b38;
  --border: #2a2e39;
  --border-2: #363a45;
  --text: #d1d4dc;
  --text-strong: #f0f3fa;
  --muted: #787b86;
  --accent: #2962ff;
  --accent-hover: #1e53e5;
  --up: #089981;
  --down: #f23645;
  --warn: #f7a600;
  --font: -apple-system, BlinkMacSystemFont, "Trebuchet MS", Roboto, Ubuntu, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.flex { flex: 1; }
.muted { color: var(--muted); }

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- top bar ---------- */
#topbar { height: 40px; flex: none; display: flex; align-items: center; gap: 2px; padding: 0 6px; border-bottom: 1px solid var(--border); background: var(--bg); user-select: none; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.tb-btn { height: 30px; display: inline-flex; align-items: center; gap: 6px; padding: 0 8px; background: none; border: 0; border-radius: 4px; cursor: pointer; color: var(--text); white-space: nowrap; }
.tb-btn:hover { background: var(--border); }
.tb-btn svg { width: 18px; height: 18px; flex: none; }
.tb-btn.icon { padding: 0 6px; }
.tb-btn.sym { font-weight: 600; color: var(--text-strong); font-size: 14px; }
.tf-group { display: flex; gap: 1px; }
.tf-btn { height: 30px; min-width: 32px; padding: 0 6px; background: none; border: 0; border-radius: 4px; cursor: pointer; color: var(--text); }
.tf-btn:hover { background: var(--border); }
.tf-btn.active { color: var(--accent); background: rgba(41, 98, 255, .12); }
.tb-select { height: 28px; background: var(--bg); border: 1px solid transparent; border-radius: 4px; padding: 0 4px; cursor: pointer; }
.tb-select:hover { background: var(--border); }
.tb-select option { background: var(--panel); }
#replay-ctl { display: flex; align-items: center; gap: 4px; margin-left: 6px; padding-left: 6px; border-left: 1px solid var(--border); }
#rp-progress { font-size: 12px; min-width: 120px; }

.badge { display: flex; align-items: center; gap: 7px; padding: 4px 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--border-2); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; cursor: default; }
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.badge.live .dot { background: var(--up); box-shadow: 0 0 6px var(--up); animation: pulse 1.6s infinite; }
.badge.sim .dot { background: var(--warn); }
.badge.replay .dot { background: #ab47bc; }
.badge.off .dot { background: var(--down); }
@keyframes pulse { 50% { opacity: .45; } }

/* ---------- layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }
#lefttools { width: 48px; flex: none; border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding-top: 6px; gap: 2px; background: var(--bg); }
.tool { width: 38px; height: 38px; border: 0; background: none; border-radius: 4px; color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.tool svg { width: 28px; height: 28px; }
.tool:hover { background: var(--border); }
.tool.active { color: var(--accent); background: rgba(41, 98, 255, .12); }
.tool-sep { width: 28px; height: 1px; background: var(--border); margin: 4px 0; }
#center { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chart-wrap { flex: 1; position: relative; min-height: 120px; }
#chart { position: absolute; inset: 0; }
#chart.drawing { cursor: crosshair; }
#overlays { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.loading { position: absolute; left: 50%; top: 45%; transform: translate(-50%, -50%); padding: 10px 16px; background: var(--panel); border: 1px solid var(--border-2); border-radius: 6px; color: var(--muted); z-index: 5; }

/* ---------- legend ---------- */
#legend { position: absolute; left: 0; top: 0; right: 0; pointer-events: none; z-index: 4; }
.pane-legend { position: absolute; left: 8px; max-width: calc(100% - 90px); display: flex; flex-direction: column; gap: 2px; font-size: 12px; text-shadow: 0 0 2px #131722, 0 0 3px #131722, 0 0 5px #131722; }
.lg-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; height: 20px; }
.lg-main { font-size: 13px; }
.lg-title { color: var(--text-strong); font-weight: 600; }
.lg-sub { color: var(--muted); }
.lg-val { font-variant-numeric: tabular-nums; }
.lg-ohlc b { color: var(--muted); font-weight: 400; margin-right: 2px; }
.lg-ind { pointer-events: auto; padding: 0 4px 0 2px; border-radius: 3px; border: 1px solid transparent; }
.lg-ind:hover { background: rgba(19, 23, 34, .85); border-color: var(--border-2); }
.lg-ind .lg-btns { display: none; gap: 2px; }
.lg-ind:hover .lg-btns { display: flex; }
.lg-ind.off .lg-name, .lg-ind.off .lg-val { opacity: .45; }
.lg-btn { width: 20px; height: 18px; border: 0; background: none; color: var(--text); cursor: pointer; border-radius: 3px; display: inline-flex; align-items: center; justify-content: center; padding: 0; font-size: 12px; }
.lg-btn:hover { background: var(--border-2); }
.lg-err { color: var(--down); }
.lg-fold-row { height: 22px; }
.lg-fold { pointer-events: auto; display: inline-flex; align-items: center; gap: 3px; height: 20px; min-width: 22px; padding: 0 5px; border: 1px solid var(--border-2); border-radius: 4px; background: rgba(19, 23, 34, .75); color: var(--text); cursor: pointer; font-size: 12px; font-variant-numeric: tabular-nums; text-shadow: none; }
.lg-fold:hover { background: var(--border-2); color: var(--text-strong); }
.lg-fold svg { width: 12px; height: 12px; flex: none; }
.lg-warn { color: var(--warn); cursor: help; }
.lg-src { font-size: 10px; padding: 0 5px; border-radius: 3px; background: var(--panel-2); color: var(--muted); letter-spacing: .3px; }
.lg-src.live { color: #fff; background: var(--up); }
.lg-src.sim { color: #131722; background: var(--warn); }
.lg-src.replay { color: #fff; background: #ab47bc; }

/* ---------- pine tables ---------- */
.pine-table { position: absolute; border-collapse: collapse; font-size: 12px; pointer-events: auto; }
.pine-table td { padding: 2px 6px; white-space: pre; }

/* ---------- editor ---------- */
#editor-panel { height: 300px; flex: none; display: flex; flex-direction: column; border-top: 1px solid var(--border); position: relative; background: var(--bg); }
#editor-resize { position: absolute; top: -3px; left: 0; right: 0; height: 6px; cursor: ns-resize; z-index: 3; }
.ed-head { display: flex; align-items: center; gap: 6px; padding: 5px 8px; border-bottom: 1px solid var(--border); }
#ed-name { width: 220px; background: var(--panel); border: 1px solid var(--border-2); border-radius: 4px; padding: 4px 8px; }
.ed-btn { height: 28px; padding: 0 10px; border: 1px solid var(--border-2); background: var(--panel); border-radius: 4px; cursor: pointer; display: inline-flex; align-items: center; }
.ed-btn:hover { background: var(--border-2); }
.ed-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ed-btn.primary:hover { background: var(--accent-hover); }
.ed-btn.icon { border: 0; background: none; }
.ed-body { flex: 1; display: flex; min-height: 0; font: 13px/19px var(--mono); }
#ed-gutter { width: 46px; flex: none; text-align: right; padding: 6px 8px 6px 0; color: #4c525e; overflow: hidden; user-select: none; white-space: pre; }
#ed-gutter .err { color: var(--down); font-weight: 700; }
#ed-scroll { flex: 1; position: relative; overflow: hidden; }
#ed-highlight, #ed-text { position: absolute; inset: 0; margin: 0; padding: 6px 10px; font: inherit; white-space: pre; tab-size: 4; overflow: auto; }
#ed-highlight { pointer-events: none; color: var(--text); }
#ed-text { background: transparent; color: transparent; caret-color: #fff; border: 0; outline: 0; resize: none; z-index: 1; }
#ed-text::selection { background: rgba(41, 98, 255, .35); color: transparent; }
.tk-kw { color: #f06292; } .tk-ty { color: #4dd0e1; } .tk-str { color: #a5d6a7; } .tk-num { color: #ffb74d; }
.tk-com { color: #6a7385; font-style: italic; } .tk-ns { color: #90caf9; } .tk-fn { color: #ce93d8; } .tk-col { color: #fff59d; }
.tk-errline { background: rgba(242, 54, 69, .15); display: inline-block; width: 100%; }
#ed-console { height: 74px; flex: none; overflow: auto; border-top: 1px solid var(--border); padding: 4px 10px; font: 12px/18px var(--mono); }
#ed-console .c-err { color: var(--down); } #ed-console .c-warn { color: var(--warn); } #ed-console .c-ok { color: var(--up); } #ed-console .c-log { color: var(--muted); }

/* ---------- modals ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; z-index: 50; }
.modal { width: 560px; max-width: 94vw; max-height: 80vh; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border-2); border-radius: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5); }
.modal header { display: flex; align-items: center; padding: 14px 18px 10px; font-size: 16px; font-weight: 600; color: var(--text-strong); }
.modal header .x { margin-left: auto; background: none; border: 0; cursor: pointer; font-size: 18px; color: var(--muted); }
.modal .body { padding: 0 18px 14px; overflow: auto; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border-2); }
.modal .search { width: 100%; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; margin-bottom: 10px; }
.list-h { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin: 10px 0 4px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.list-item:hover { background: var(--border-2); }
.list-item .right { margin-left: auto; color: var(--muted); font-size: 12px; display: flex; gap: 10px; align-items: center; }
.list-item .del { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 3px; }
.list-item .del:hover { color: var(--down); background: var(--bg); }
/* Indicators dialog, laid out like TradingView's */
.modal.ind-dialog { height: min(560px, 80vh); }
.ind-body { display: flex; flex-direction: column; min-height: 0; flex: 1; padding-bottom: 0; overflow: hidden; }
.ind-cols { display: flex; flex: 1; min-height: 0; border-top: 1px solid var(--border-2); margin: 0 -18px; }
.ind-nav { width: 180px; flex: none; padding: 8px 8px 12px; border-right: 1px solid var(--border-2); overflow: auto; }
.ind-nav-h { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin: 10px 10px 4px; }
.ind-nav-item { display: flex; align-items: center; padding: 7px 10px; border-radius: 4px; cursor: pointer; }
.ind-nav-item:hover { background: var(--border-2); }
.ind-nav-item.active { background: var(--accent); color: #fff; }
.ind-nav-item .n { margin-left: auto; font-size: 12px; opacity: .7; }
.ind-list { flex: 1; overflow: auto; padding: 6px 8px 14px; }
.ind-list .list-h { margin: 10px 10px 4px; }
.ind-list .list-item .when { min-width: 70px; text-align: right; }
.ind-list .list-item .del { visibility: hidden; }
.ind-list .list-item:hover .del { visibility: visible; }
.ind-list .list-item.added { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.ind-list .added-tag { color: var(--accent); font-weight: 600; }
.ind-empty { padding: 14px 10px; font-size: 13px; }
.btn { height: 32px; padding: 0 16px; border-radius: 4px; border: 1px solid var(--border-2); background: var(--panel-2); cursor: pointer; }
.btn:hover { background: var(--border-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--border-2); margin: 0 18px 12px; }
.tab { padding: 6px 0; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.active { color: var(--text-strong); border-color: var(--text-strong); }
/* indicator settings, laid out like TradingView's */
.modal.set-dialog { height: min(640px, 86vh); }
.set-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.set-wrap .tabs { flex: none; }
.set-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 16px; }
.in-grid { display: grid; grid-template-columns: minmax(140px, 40%) 1fr; gap: 9px 12px; align-items: center; }
.in-grp { grid-column: 1 / -1; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border-2); }
.in-grid > .in-grp:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.in-lead { color: var(--text); min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.in-lead.chk, .in-ctl .chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.in-ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.in-sub { color: var(--text); margin-left: 6px; }
.in-grid input[type=number], .in-grid input[type=text], .in-grid select, .in-grid textarea { background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; padding: 5px 8px; min-width: 0; color: var(--text); }
.in-grid input[type=number] { width: 76px; }
.in-grid input[type=text] { width: 150px; }
.in-grid select { max-width: 200px; }
.in-grid input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.modal footer .btn.left { margin-right: auto; }
.in-grid .tip { color: var(--muted); cursor: help; font-size: 13px; }
.in-grid .sess { display: inline-flex; align-items: center; gap: 6px; }
.in-grid input.sess-t { background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; padding: 4px 6px; color: var(--text); color-scheme: dark; width: 116px; }
.in-grid .color-btn { width: 28px; height: 24px; padding: 3px; }
.form-grid { display: grid; grid-template-columns: 170px 1fr; gap: 8px 12px; align-items: center; }
.form-grid .grp { grid-column: 1 / -1; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .6px; margin-top: 8px; }
.form-grid label { color: var(--text); }
.form-grid .ctl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.form-grid input[type=number], .form-grid input[type=text], .form-grid select, .form-grid textarea, .field { background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; padding: 5px 8px; min-width: 0; }
.form-grid input[type=number] { width: 110px; }
.form-grid input[type=text], .form-grid select { width: 220px; }
.form-grid input[type=color] { width: 34px; height: 26px; padding: 0; border: 1px solid var(--border-2); background: none; border-radius: 4px; }
.form-grid .tip { color: var(--muted); cursor: help; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 4px 12px; font-size: 12px; }
.kv span:nth-child(odd) { color: var(--muted); }
code.inline { font-family: var(--mono); font-size: 12px; background: var(--bg); padding: 1px 5px; border-radius: 3px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { min-width: 260px; max-width: 420px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border-2); border-left: 3px solid var(--accent); border-radius: 6px; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); animation: slide .2s ease-out; }
.toast.alert { border-left-color: var(--warn); }
.toast.error { border-left-color: var(--down); }
.toast .t-title { font-weight: 600; color: var(--text-strong); margin-bottom: 2px; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } }

/* ======================= TradingView-style drawing UI ======================= */
#lefttools { width: 52px; gap: 0; padding-top: 4px; overflow-y: auto; overflow-x: visible; scrollbar-width: none; }
#lefttools::-webkit-scrollbar { display: none; }
.tool-wrap { position: relative; width: 52px; display: flex; justify-content: center; }
.tool-wrap .tool { width: 40px; height: 36px; }
.tool { color: #b2b5be; }
.tool:hover { color: var(--text-strong); }
.tool.active, .tool.on { color: var(--accent); }
.tool.toggle.on { background: rgba(41, 98, 255, .14); }
.tool.toggle.strong { box-shadow: inset 0 0 0 1px rgba(41, 98, 255, .55); }
.tool-more { position: absolute; right: 0; top: 0; height: 36px; width: 10px; border: 0; background: none; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s; padding: 0; }
.tool-wrap:hover .tool-more { opacity: 1; }
.tool-more:hover { color: var(--text-strong); }
.tool-sep { width: 32px; margin: 5px 0; }
#chart[data-cursor="arrow"], #chart[data-cursor="arrow"] * { cursor: default !important; }
#chart[data-cursor="dot"], #chart[data-cursor="dot"] * { cursor: none !important; }
#chart[data-cursor="eraser"] { cursor: not-allowed; }
#chart.drawing, #chart.drawing * { cursor: crosshair !important; }

/* popups: menus, flyouts, colour picker */
.popup { position: fixed; z-index: 200; background: #1e222d; border: 1px solid var(--border-2); border-radius: 6px; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); padding: 6px 0; min-width: 160px; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 14px 6px 10px; border: 0; background: none; color: var(--text); cursor: pointer; text-align: left; white-space: nowrap; font-size: 13px; }
.menu-item:hover { background: #2a2e39; }
.menu-item.on { color: var(--accent); }
.mi-ico { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; flex: none; }
.mi-ico svg { width: 28px; height: 28px; }
.mi-label { flex: 1; }
.mi-hint { color: var(--muted); font-size: 12px; margin-left: 16px; }
.menu-sep { height: 1px; background: var(--border-2); margin: 5px 0; }
.popup.flyout { min-width: 230px; }

.cp { padding: 10px; min-width: 0; }
.cp-grid { display: grid; grid-template-columns: repeat(10, 20px); gap: 3px; }
.cp-sw { width: 20px; height: 20px; border-radius: 3px; border: 1px solid rgba(255, 255, 255, .08); cursor: pointer; padding: 0; }
.cp-sw:hover { transform: scale(1.12); }
.cp-sw.on { box-shadow: 0 0 0 2px #131722, 0 0 0 3px var(--accent); }
.cp-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.cp-custom { width: 26px; height: 22px; border: 1px solid var(--border-2); border-radius: 3px; background: none; padding: 0; cursor: pointer; }
.cp-alpha { flex: 1; accent-color: var(--accent); }
.cp-pct { width: 36px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }

/* floating toolbar for the selected drawing */
.float-tb { position: absolute; z-index: 6; display: flex; align-items: center; gap: 1px; padding: 3px; background: #1e222d; border: 1px solid var(--border-2); border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, .4); user-select: none; }
.ft-grip { width: 16px; height: 30px; color: var(--muted); cursor: grab; display: flex; align-items: center; justify-content: center; }
.ft-grip svg { width: 22px; height: 22px; }
.ft-btn { height: 32px; min-width: 32px; padding: 0 4px; border: 0; background: none; color: var(--text); border-radius: 4px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; position: relative; }
.ft-btn:hover { background: #2a2e39; }
.ft-btn svg { width: 24px; height: 24px; }
.ft-swatch { position: absolute; left: 7px; right: 7px; bottom: 4px; height: 3px; border-radius: 1px; }
.ft-pen::before { content: ''; display: block; width: 14px; height: 14px; margin: 0 5px 6px; border: 1.5px solid currentColor; border-radius: 2px; transform: rotate(45deg) scale(.7, 1); }
.ft-bucket::before { content: ''; display: block; width: 14px; height: 12px; margin: 0 5px 6px; border: 1.5px solid currentColor; border-radius: 1px 1px 4px 4px; }
.ft-t { font-weight: 600; font-size: 15px; width: 22px; text-align: center; margin-bottom: 4px; }
.ft-num { font-size: 12px; color: var(--muted); margin-right: 2px; }
.ft-sep { width: 1px; height: 22px; background: var(--border-2); margin: 0 3px; }

/* dialogs */
.dlg-body { padding: 8px 18px 4px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 -18px 12px; padding: 0 18px; }
.tab { border: 0; background: none; color: var(--muted); padding: 9px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13px; }
.tab.on { color: var(--text-strong); border-bottom-color: var(--text-strong); }
.tab-body { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; max-height: 60vh; overflow-y: auto; }
.dlg-row { display: flex; align-items: center; gap: 12px; min-height: 30px; }
.dlg-row > label { width: 150px; flex: none; color: var(--text); }
.dlg-ctl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dlg-sub { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.color-btn { width: 30px; height: 30px; border-radius: 4px; border: 1px solid var(--border-2); cursor: pointer; padding: 3px; background: none; }
.color-btn::after { content: ''; display: block; width: 100%; height: 100%; border-radius: 2px; background: var(--c); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06); }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.chk input { accent-color: var(--accent); width: 15px; height: 15px; margin: 0; }
.num, .sel { height: 30px; background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; padding: 0 8px; color: var(--text); }
.num { width: 96px; }
.sel option { background: var(--panel); }
.txt-edit { width: 100%; background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; color: var(--text); padding: 8px; resize: vertical; font-size: 14px; }
.levels { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 18px; }
.lv { display: flex; align-items: center; gap: 6px; }
.lv .num { width: 78px; }
.modal.modal-wide { max-width: 680px; }
.cs { display: flex; gap: 0; padding: 0; min-height: 420px; }
.vtabs { width: 170px; flex: none; border-right: 1px solid var(--border); padding: 8px 0; display: flex; flex-direction: column; }
.vtab { border: 0; background: none; color: var(--text); text-align: left; padding: 10px 18px; cursor: pointer; font-size: 13px; }
.vtab:hover { background: #2a2e39; }
.vtab.on { background: #2a2e39; color: var(--text-strong); box-shadow: inset 3px 0 0 var(--accent); }
.vtab-body { flex: 1; padding: 14px 20px; overflow-y: auto; max-height: 64vh; }
.vtab-body .tab-body { max-height: none; }

/* bottom bar (date ranges, clock, scale modes) */
#bottombar { height: 34px; flex: none; display: flex; align-items: center; gap: 2px; padding: 0 8px 0 4px; border-top: 1px solid var(--border); background: var(--bg); user-select: none; font-size: 12px; }
.bb-left { display: flex; align-items: center; gap: 2px; }
.bb-btn { height: 26px; min-width: 28px; padding: 0 8px; border: 0; background: none; color: var(--text); border-radius: 4px; cursor: pointer; font-size: 12px; font-variant-numeric: tabular-nums; }
.bb-btn:hover { background: var(--border); }
.bb-tog.on { color: var(--accent); }
.bb-sep { width: 1px; height: 16px; background: var(--border); margin: 0 6px; }
.bb-clock { color: var(--text); }

/* ---------- Tradovate connection checklist (status badge) ---------- */
.popup.panel { padding: 12px 14px 10px; }
.conn-pop { width: 360px; }
.conn-title { font-weight: 600; color: var(--text-strong); margin-bottom: 6px; }
.conn-row { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.conn-row:first-of-type { border-top: 0; }
.conn-ico { width: 18px; height: 18px; border-radius: 50%; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; margin-top: 1px; }
.conn-row.ok .conn-ico { background: rgba(8, 153, 129, .18); color: var(--up); }
.conn-row.bad .conn-ico { background: rgba(247, 166, 0, .18); color: var(--warn); }
.conn-label { color: var(--text-strong); }
.conn-txt { min-width: 0; }
.conn-fix { margin-top: 3px; line-height: 1.45; }
.conn-copy { margin-top: 6px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: 4px; padding: 3px 8px; cursor: pointer; font-size: 12px; }
.conn-copy:hover { border-color: var(--accent); }
.conn-note { margin-top: 8px; color: var(--muted); line-height: 1.45; }

/* ---------- narrow windows (e.g. a side panel): icon-only buttons, one timeframe list ---------- */
#topbar { overflow-x: auto; scrollbar-width: none; }
#topbar::-webkit-scrollbar { display: none; }
#tf-compact { display: none; }
@media (max-width: 1180px) {
  #btn-indicators span, #btn-editor span, #btn-replay span { display: none; }
}
@media (max-width: 960px) {
  #tf-group, #tf-more { display: none; }
  #tf-compact { display: block; }
  #status-text { max-width: 175px; overflow: hidden; text-overflow: ellipsis; }
  #btn-full { display: none; }
}

/* ---------- workspace: charts in panels (resize, move, split, close) ---------- */
.ws { position: fixed; inset: 0; background: var(--border-2); overflow: hidden; }
.ws-panel { position: absolute; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.ws-panel.moving { opacity: .55; }
.ws-head { flex: none; height: 22px; display: flex; align-items: center; gap: 6px; padding: 0 4px 0 6px; background: var(--panel); border-bottom: 1px solid var(--border); color: var(--muted); font-size: 11.5px; cursor: grab; user-select: none; }
.ws-grip { opacity: .6; font-size: 12px; }
.ws-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--text); }
.ws-btns { display: flex; gap: 1px; }
.ws-btn { width: 20px; height: 18px; border: 0; border-radius: 3px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; line-height: 18px; padding: 0; }
.ws-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text-strong); }
.ws-btn:disabled { opacity: .3; cursor: default; }
.ws-panel iframe { flex: 1; width: 100%; border: 0; display: block; background: var(--bg); }
.ws-div { position: absolute; z-index: 2; background: var(--border-2); }
.ws-div.row { cursor: col-resize; }
.ws-div.col { cursor: row-resize; }
.ws-div:hover { background: var(--accent); }
.ws-shield { position: absolute; inset: 0; z-index: 5; }
.ws-drop { position: absolute; z-index: 6; background: rgba(41, 98, 255, .22); border: 2px solid var(--accent); border-radius: 4px; pointer-events: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; font-size: 13px; }

/* Trade panel: an order ticket docked right of the chart */
.trade-panel { width: 280px; flex: none; display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; background: var(--bg); border-left: 1px solid var(--border); overflow-y: auto; font-size: 13px; }
.trade-panel .tp-head { display: flex; align-items: baseline; gap: 8px; }
.trade-panel .tp-head b { font-size: 16px; color: var(--text-strong); }
.trade-panel .tp-sub { flex: 1; color: var(--muted); font-size: 12px; }
.trade-panel .x { background: none; border: 0; cursor: pointer; color: var(--muted); font-size: 14px; }
.trade-panel .x:hover { color: var(--text-strong); }
.trade-panel select.tp-acct, .trade-panel .tp-num { height: 34px; background: transparent; border: 1px solid var(--border-2); border-radius: 6px; padding: 0 10px; }
.trade-panel select.tp-acct { width: 100%; }
.trade-panel .tp-num { width: 84px; }
.trade-panel .tp-num:focus, .trade-panel select.tp-acct:focus { outline: none; border-color: var(--accent); }
.trade-panel .tp-sides { display: flex; gap: 2px; }
.trade-panel .tp-side { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 7px 10px; border: 0; cursor: pointer; text-align: left; background: rgba(242, 54, 69, .16); color: var(--down); border-radius: 6px 0 0 6px; }
.trade-panel .tp-side.buy { background: rgba(41, 98, 255, .18); color: #5b8cff; text-align: right; border-radius: 0 6px 6px 0; }
.trade-panel .tp-side span { font-size: 12px; }
.trade-panel .tp-side b { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trade-panel .tp-tabs { display: flex; border-bottom: 1px solid var(--border); }
.trade-panel .tp-tabs span { flex: 1; text-align: center; padding: 7px 0; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.trade-panel .tp-tabs span.on { color: var(--text-strong); border-bottom-color: var(--text-strong); font-weight: 600; }
.trade-panel .tp-label { color: var(--text-strong); font-weight: 600; margin-top: 4px; }
.trade-panel .tp-line { display: flex; align-items: center; gap: 8px; }
.trade-panel .tp-line > span:first-child { flex: 1; }
.trade-panel .tp-unit { color: var(--muted); font-size: 12px; flex: none !important; }
.trade-panel .tp-exit { display: flex; flex-direction: column; gap: 6px; }
.trade-panel .tp-exit.off .tp-line:last-child { opacity: .35; pointer-events: none; }
.trade-panel .tp-exit-px { flex: 1; text-align: right; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.trade-panel .tp-sw { width: 34px; height: 20px; flex: none; padding: 0; border: 0; border-radius: 10px; background: var(--border-2); cursor: pointer; position: relative; transition: background .12s; }
.trade-panel .tp-sw i { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .12s; }
.trade-panel .tp-sw.on { background: var(--accent); }
.trade-panel .tp-sw.on i { left: 16px; }
.trade-panel .tp-opt { color: var(--muted); }
.trade-panel .tp-opt.armed { color: var(--warn); font-weight: 600; }
.trade-panel .tp-grow { flex: 1; min-height: 4px; }
.trade-panel .tp-pos { color: var(--muted); font-variant-numeric: tabular-nums; }
.trade-panel .tp-pos.long { color: #5b8cff; font-weight: 600; }
.trade-panel .tp-pos.short { color: var(--down); font-weight: 600; }
.trade-panel .tp-flat { height: 34px; border: 1px solid var(--border-2); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.trade-panel .tp-flat:hover:not(:disabled) { background: var(--panel-2); }
.trade-panel .tp-main { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px; border: 0; border-radius: 6px; color: #fff; cursor: pointer; }
.trade-panel .tp-main b { font-size: 15px; }
.trade-panel .tp-main span { font-size: 11px; opacity: .9; }
.trade-panel .tp-main.buy { background: var(--accent); }
.trade-panel .tp-main.buy:hover:not(:disabled) { background: var(--accent-hover); }
.trade-panel .tp-main.sell { background: var(--down); }
.trade-panel button:disabled { opacity: .4; cursor: not-allowed; }
.trade-panel .tp-note { color: var(--muted); font-size: 11px; line-height: 1.35; }

.trade-panel .tp-paper { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; color: var(--text-strong); }
.trade-panel .tp-paper .tp-pnl { flex: 1; text-align: right; color: var(--muted); }
.trade-panel .tp-reset { border: 1px solid var(--border-2); background: transparent; color: var(--muted); border-radius: 4px; height: 22px; padding: 0 8px; cursor: pointer; font-size: 11px; }

/* position tags on the chart (paper trading) */
.pos-tags { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
.pos-tag { position: absolute; transform: translateY(-50%); display: flex; align-items: stretch; height: 22px; border-radius: 4px; overflow: hidden; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; pointer-events: auto; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); user-select: none; background: #1e222d; color: #fff; }
.pos-tag > * { display: flex; align-items: center; padding: 0 8px; border: 0; background: transparent; color: inherit; font: inherit; }
.pos-tag .pt-qty { background: #2962ff; }
.pos-tag.short .pt-qty { background: #f23645; }
.pos-tag.stop .pt-qty { background: #f23645; }
.pos-tag.target .pt-qty { background: #089981; }
.pos-tag .pt-val { color: #22ab94; min-width: 74px; justify-content: flex-end; }
.pos-tag .pt-val.neg, .pos-tag.stop .pt-val { color: #f7525f; }
.pos-tag.stop, .pos-tag.target { cursor: ns-resize; }
.pos-tag button { cursor: pointer; border-left: 1px solid rgba(255, 255, 255, .14); color: #b2b5be; }
.pos-tag button:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.pos-tag .pt-add { font-size: 11px; }

.dlg-row .tpl-name { width: 130px; height: 28px; padding: 0 8px; background: var(--bg); border: 1px solid var(--border-2); border-radius: 4px; }
.dlg-row .btn { height: 28px; padding: 0 10px; }
.dlg-row .tpl-note { min-height: 14px; }

/* limit / stop orders */
.trade-panel .tp-tabs span { cursor: pointer; }
.trade-panel .tp-tabs span:hover { color: var(--text-strong); }
.trade-panel .tp-num.tp-price { flex: 1; width: auto; min-width: 0; }
.trade-panel .tp-last { height: 34px; padding: 0 12px; border: 1px solid var(--border-2); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.trade-panel .tp-last:hover { border-color: var(--accent); }
.trade-panel .tp-hint { color: var(--muted); font-size: 11px; line-height: 1.35; }
.trade-panel .tp-orders { display: flex; flex-direction: column; gap: 4px; max-height: 132px; overflow: auto; flex: none; }
.trade-panel .tp-ord { flex: none; }
.trade-panel .tp-ord { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border: 1px solid var(--border-2); border-left: 3px solid #2962ff; border-radius: 4px; font-variant-numeric: tabular-nums; }
.trade-panel .tp-ord.sell { border-left-color: #f23645; }
.trade-panel .tp-ord span { flex: 1; text-transform: capitalize; }
.trade-panel .tp-ord .x { border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.trade-panel .tp-ord .x:hover { color: var(--text-strong); }
.pos-tag.ord-tag .pt-qty { background: #2962ff; }
.pos-tag.ord-tag.sell .pt-qty { background: #f23645; }
.pos-tag.ord-tag .pt-val { color: #d1d4dc; min-width: 0; }
.pos-tag.ord-tag.movable { cursor: ns-resize; }
