:root {
  --bg: #0e1116; --panel: #151a21; --panel2: #1b2129; --line: #262d37; --text: #d7dde5;
  --muted: #7d8794; --up: #26a69a; --down: #ef5350; --accent: #e8b44a; --warn: #f0a030;
  --radius: 8px; font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel2); border-radius: 6px; padding: 6px 10px; }
button:hover { border-color: #3a4452; }
input { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px; width: 100%; }
input:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.err { color: var(--down); min-height: 1.2em; font-size: 13px; }
.brand { font-weight: 700; letter-spacing: .3px; font-size: 16px; white-space: nowrap; }
.brand span { color: var(--accent); }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; }
.login-box { width: min(320px, 90vw); display: grid; gap: 12px; background: var(--panel); padding: 28px;
  border: 1px solid var(--line); border-radius: 12px; }
.login-box .brand { font-size: 22px; text-align: center; margin-bottom: 6px; }
.login-box button { background: var(--accent); color: #111; border: none; padding: 10px; font-weight: 600; }

/* layout */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { padding: 5px 12px; }
.tabs button.on { background: var(--accent); color: #111; border-color: var(--accent); font-weight: 600; }
.tabs button .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-left: 6px; background: var(--muted); }
.tabs button .dot.ok { background: var(--up); } .tabs button .dot.bad { background: var(--down); }
.sym input { width: 120px; text-transform: uppercase; font-weight: 600; }
.tfs { display: flex; gap: 2px; }
.tfs button, .chip { padding: 5px 8px; font-size: 12px; background: transparent; border-color: transparent; color: var(--muted); }
.tfs button.on, .chip.on { color: var(--accent); border-color: var(--line); background: var(--panel2); }
.badge { background: #4a3a12; color: var(--accent); border-radius: 4px; padding: 3px 7px; font-size: 11px; font-weight: 700; }
.conn { margin-left: auto; color: var(--muted); }
.conn.ok { color: var(--up); } .conn.bad { color: var(--down); }

.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 330px; grid-template-rows: 1fr auto;
  grid-template-areas: "chart side" "bottom side"; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.card-title { font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.card-title.sub { margin-top: 12px; font-size: 13px; }
.spacer { flex: 1; }

/* ticket */
.bidask { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: stretch; margin-bottom: 8px; }
.bidask button { border: none; border-radius: 6px; padding: 8px 6px; display: flex; flex-direction: column; align-items: center; color: #fff; }
.bidask button small { font-size: 11px; opacity: .85; font-weight: 600; }
.bidask button b { font-size: 17px; font-variant-numeric: tabular-nums; }
.bidask .sell { background: var(--down); } .bidask .buy { background: #2a8bd8; }
.bidask button:disabled { opacity: .4; cursor: not-allowed; }
.spread { align-self: center; font-size: 11px; color: var(--muted); min-width: 32px; text-align: center; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.seg button { flex: 1; border: none; border-radius: 0; background: transparent; color: var(--muted); padding: 5px; font-size: 12px; }
.seg button.on { background: var(--panel2); color: var(--text); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.grid2 label { font-size: 11px; color: var(--muted); display: grid; gap: 3px; }
.grid2 input.picking { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(232,180,74,.25); }
.risk-info { font-size: 11px; color: var(--muted); align-self: end; padding-bottom: 6px; }
.hint { font-size: 11px; color: var(--muted); margin: 4px 0; }
.row { display: flex; align-items: center; gap: 6px; }
.small { font-size: 12px; color: var(--muted); }
.notice { background: #2a2315; color: var(--accent); border: 1px solid #4a3a12; padding: 7px 8px; border-radius: 6px; font-size: 12px; margin-bottom: 8px; }

/* account cards */
.acct { cursor: pointer; }
.acct.on { border-color: #4a3a12; }
.acct .head { display: flex; align-items: center; gap: 6px; font-weight: 600; margin-bottom: 6px; }
.acct .head .ro { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-weight: 500; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; font-size: 12px; }
.kv div { display: flex; justify-content: space-between; } .kv span { color: var(--muted); }
.kv b { font-weight: 600; font-variant-numeric: tabular-nums; }
.pos { color: var(--up); } .neg { color: var(--down); }
.acct .error { font-size: 12px; color: var(--down); }
.rule { margin-top: 8px; font-size: 12px; }
.rule .lbl { display: flex; justify-content: space-between; color: var(--muted); margin-bottom: 3px; }
.rule .lbl b { color: var(--text); font-weight: 600; }
.bar { height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--up); transition: width .3s; }
.bar i.warning { background: var(--warn); } .bar i.breached { background: var(--down); } .bar i.target { background: #2a8bd8; }
.rule-alert { margin-top: 8px; padding: 6px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.rule-alert.warning { background: #33270f; color: var(--warn); } .rule-alert.breached { background: #3a1515; color: var(--down); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 5px 6px; border-bottom: 1px solid #1d232b; white-space: nowrap; }
td.side-buy { color: #4ea8f0; font-weight: 600; } td.side-sell { color: var(--down); font-weight: 600; }
td a { color: var(--text); text-decoration: none; border-bottom: 1px dotted var(--muted); }
.mini { padding: 3px 7px; font-size: 11px; }
.mini.danger { color: var(--down); }
td .acts { display: flex; gap: 4px; }
.empty { color: var(--muted); text-align: center; padding: 12px; }

/* popover / modal / toast */
.popover { position: absolute; z-index: 20; top: 50px; right: 12px; width: 250px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; display: grid; gap: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.popover label { display: grid; grid-template-columns: 1fr 70px; align-items: center; font-size: 12px; gap: 6px; }
.popover label.row { display: flex; }
.pop-title { font-weight: 600; } .pop-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.lv-tfs { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.lv-tfs label { display: flex; gap: 4px; grid-template-columns: none; }
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: grid; place-items: center; }
.modal-box { width: min(360px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.modal-title { font-weight: 700; font-size: 16px; margin-bottom: 10px; }
#modalBody { font-size: 13px; display: grid; gap: 8px; }
#modalBody .line { display: flex; justify-content: space-between; } #modalBody .line span { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions #modalOk { background: var(--accent); color: #111; border: none; font-weight: 600; padding: 8px 16px; }
.ghost { background: transparent; }
.toasts { position: fixed; z-index: 60; bottom: 16px; right: 16px; display: grid; gap: 8px; max-width: min(380px, 92vw); }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 3px solid var(--up); padding: 9px 12px; border-radius: 6px; font-size: 13px; }
.toast.bad { border-left-color: var(--down); }

/* phone */

/* DMC indicator */
.dmc-dash { position: absolute; z-index: 3; top: 8px; right: 70px; font-size: 11px; pointer-events: none;
  background: rgba(0,0,0,.6); border: 1px solid #333b46; border-radius: 4px; }
.dmc-dash table { font-size: 11px; }
.dmc-dash th, .dmc-dash td { padding: 2px 7px; border-bottom: 1px solid #262d37; color: #e6e9ee; }
.dmc-dash td.bull { background: rgba(38,166,154,.55); } .dmc-dash td.bear { background: rgba(239,83,80,.55); }
.dmc-dash td.flat { background: rgba(120,120,120,.4); }
.dmc-ms { position: absolute; z-index: 3; bottom: 30px; left: 10px; font-size: 10px; color: #4a5361; pointer-events: none; }
.drawer { position: fixed; z-index: 40; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); overflow-y: auto;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(0,0,0,.5); padding-bottom: 30px; }
.drawer-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 6px; padding: 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.drawer details { border-bottom: 1px solid var(--line); }
.drawer summary { cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 13px; }
.f-body { padding: 0 12px 12px; display: grid; gap: 7px; }
.f-row { display: grid; grid-template-columns: 1fr 110px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.f-row.chk { grid-template-columns: auto 1fr; }
.f-row select, .f-slot select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px; color: var(--text); width: 100%; }
.f-row input[type=color], .f-slot input[type=color] { padding: 0; height: 26px; width: 40px; border: none; background: none; }
.f-slot { display: grid; grid-template-columns: 60px 1fr 24px 44px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }

.themes { display: flex; flex-wrap: wrap; gap: 6px; }
.f-cola { display: flex; align-items: center; gap: 6px; }
.f-cola input[type=range] { width: 60px; padding: 0; }


/* ---------------------------------------------------------------- layout v2 */
.layout { grid-template-areas: "chart side" "bottom side"; grid-template-rows: 1fr auto; }
.chart-area { grid-area: chart; position: relative; min-height: 300px; display: flex; }
.drawbar { width: 38px; flex: none; display: flex; flex-direction: column; gap: 2px; padding: 6px 3px; border-right: 1px solid var(--line); background: var(--panel); overflow-y: auto; }
.drawbar button { width: 32px; height: 30px; padding: 0; border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 15px; }
.drawbar button:hover { color: var(--text); background: var(--panel2); }
.drawbar button.on { color: var(--accent); border-color: #4a3a12; background: #2a2315; }
.db-sep { height: 1px; background: var(--line); margin: 4px 2px; }
.charts { flex: 1; min-width: 0; display: grid; gap: 2px; background: var(--line); }
.charts.layout-1 { grid-template: 1fr / 1fr; }
.charts.layout-2 { grid-template: 1fr / 1fr 1fr; }
.charts.layout-2v { grid-template: 1fr 1fr / 1fr; }
.charts.layout-3 { grid-template: 1fr 1fr / 1.4fr 1fr; }
.charts.layout-3 .pane:first-child { grid-row: 1 / 3; }
.charts.layout-4 { grid-template: 1fr 1fr / 1fr 1fr; }
.pane { position: relative; min-width: 0; min-height: 0; background: var(--bg); outline: 1px solid transparent; outline-offset: -1px; }
.charts:not(.layout-1) .pane.active { outline-color: #4a3a12; }
.pane-chart { position: absolute; inset: 0; }
.pane .legend { position: absolute; z-index: 3; top: 6px; left: 8px; font-size: 12px; color: var(--muted); pointer-events: none; right: 200px; }
.pane .legend b { color: inherit; font-size: 13px; margin-right: 8px; }
.ind-legend { font-size: 11px; margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; }
.pane-loading { position: absolute; z-index: 4; top: 50%; left: 50%; transform: translate(-50%, -50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.pane-style { position: absolute; z-index: 6; top: 32px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px; box-shadow: 0 6px 20px rgba(0,0,0,.45); }
.pane-style button, .pane-style select { padding: 3px 7px; font-size: 12px; background: var(--panel2); border-radius: 5px; }
.pane-style button.on { color: var(--accent); border-color: #4a3a12; }
.pane-style input[type=color] { width: 28px; height: 24px; padding: 0; border: none; background: none; }
.pick-hint { position: absolute; z-index: 7; bottom: 34px; left: 50%; transform: translateX(-50%); background: var(--accent);
  color: #111; padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; pointer-events: none; }
.side { grid-area: side; border-left: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.side-tabs { display: flex; position: sticky; top: 0; z-index: 2; background: var(--panel); border-bottom: 1px solid var(--line); }
.side-tabs button { flex: 1; border: none; border-radius: 0; background: transparent; color: var(--muted); padding: 9px 4px; font-size: 13px; border-bottom: 2px solid transparent; }
.side-tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.side-body { padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.bottom { grid-area: bottom; border-top: 1px solid var(--line); max-height: 30vh; overflow-y: auto; padding: 0 10px 10px; }
body.bottom-big .bottom { max-height: 60vh; }
.bottom-tabs { display: flex; align-items: center; gap: 4px; position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 6px 0; }
.bottom-tabs button[data-t] { border: none; background: transparent; color: var(--muted); padding: 5px 10px; font-size: 13px; border-bottom: 2px solid transparent; border-radius: 0; }
.bottom-tabs button[data-t].on { color: var(--text); border-bottom-color: var(--accent); }
.chip-select { background: transparent; border: 1px solid transparent; color: var(--muted); font-size: 12px; padding: 4px; border-radius: 6px; }
.chip-select:hover { border-color: var(--line); }
.chip-select option { background: var(--panel); color: var(--text); }
.chip.link { display: inline-flex; align-items: center; gap: 2px; cursor: pointer; }
.layouts { display: flex; gap: 1px; }
.layouts button { padding: 3px 6px; font-size: 14px; background: transparent; border-color: transparent; color: var(--muted); }
.layouts button.on { color: var(--accent); border-color: var(--line); background: var(--panel2); }
.pane .dmc-dash { right: 64px; top: 30px; }

/* trade manager + bulk buttons */
.mgr { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 7px; }
.mgr-row { display: flex; align-items: center; gap: 6px; font-size: 12px; padding: 5px 6px; border-radius: 6px; border: 1px solid var(--line); }
.mgr-row.on { border-color: #1f5f55; background: rgba(38,166,154,.08); }
.mgr-row input[type=number] { width: 46px; padding: 3px 4px; font-size: 12px; }
.mgr-row .muted { white-space: nowrap; }
.mgr-row b { margin-right: auto; }
.mgr-row b { font-size: 12px; white-space: nowrap; }
.sw { position: relative; width: 30px; height: 17px; flex: none; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: #39414d; border-radius: 9px; cursor: pointer; transition: .2s; }
.sw span::before { content: ''; position: absolute; width: 13px; height: 13px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; }
.sw input:checked + span { background: var(--up); }
.sw input:checked + span::before { transform: translateX(13px); }
.sw input:disabled + span { opacity: .4; cursor: not-allowed; }
.mgr-scope { display: flex; align-items: center; gap: 6px; }
.mgr-scope select { flex: 1; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 4px; color: var(--text); font-size: 12px; }
.bulk { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.bulk button { font-size: 12px; padding: 7px 4px; }
.bulk button small { color: var(--muted); font-size: 10px; }
.bulk button.danger { color: var(--down); } .bulk button.win { color: var(--up); } .bulk button.loss { color: #ff8a65; }
.bulk button:disabled, .mgr input:disabled { opacity: .45; cursor: not-allowed; }

/* watchlist / alerts / journal */
.watch { display: grid; margin-top: 8px; }
.w-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid #1d232b; cursor: pointer; font-size: 13px; }
.w-row:hover { background: var(--panel2); } .w-row.on { color: var(--accent); }
.w-px { font-variant-numeric: tabular-nums; min-width: 62px; text-align: right; }
.w-px.up { color: var(--up); } .w-px.down { color: var(--down); }
.row input:not([type=checkbox]) { flex: 1; }
.al-row { display: flex; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid #1d232b; font-size: 12px; }
.al-row.off { opacity: .55; }
.ev-list { display: grid; gap: 3px; margin: 8px 0; }
.events { max-height: 260px; overflow-y: auto; }
.ev-row { font-size: 12px; padding: 4px 0; border-bottom: 1px solid #1d232b; }
#tab-alerts select, .j-bar select, .j-bar input:not([type=checkbox]) { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px; color: var(--text); }
.j-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.j-bar input:not([type=checkbox]) { width: 110px; }
.j-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; margin-bottom: 8px; }
.j-stats div { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; display: flex; flex-direction: column; font-size: 12px; }
.j-stats span { color: var(--muted); font-size: 11px; }
#jTable tbody tr { cursor: pointer; } #jTable tbody tr:hover { background: var(--panel2); }
.j-notes { max-width: 200px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.j-img { width: 100%; border-radius: 6px; border: 1px solid var(--line); }
#modalBody textarea, #modalBody input:not([type=checkbox]) { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px; color: var(--text); font: inherit; }
.modal-box { max-height: 92vh; overflow-y: auto; }

/* context menu */
.ctx { position: fixed; z-index: 80; min-width: 230px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.55); }
.ctx-item { padding: 7px 10px; font-size: 13px; border-radius: 5px; cursor: pointer; white-space: nowrap; }
.ctx-item:hover { background: var(--panel2); }
.ctx-sep { height: 1px; background: var(--line); margin: 4px 2px; }


/* saved settings bar, hub settings */
.presets { margin: 10px 12px 0; padding: 10px; border: 1px solid #4a3a12; background: #1d1a12; border-radius: 8px; display: grid; gap: 6px; }
#hubPresets.presets { margin: 0; }
.pr-title { font-size: 12px; font-weight: 600; color: var(--accent); }
.pr-row { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.pr-sel { flex: 1; min-width: 140px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px; color: var(--text); }
.cfg-acct { border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: grid; gap: 6px; margin-bottom: 8px; }
.f-col { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.f-col select, .cfg-acct select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px; color: var(--text); width: 100%; }
.f-row input:not([type=checkbox]) { width: 100%; }
#hubDrawer .f-row { grid-template-columns: 1fr 1.3fr; }
button.primary { background: var(--accent); color: #111; border: none; font-weight: 600; padding: 8px 14px; }
.upd-file { display: block; border: 1px dashed var(--line); border-radius: 8px; padding: 12px; text-align: center; cursor: pointer; font-size: 13px; }
.upd-file:hover { border-color: var(--accent); }
.upd-file input { display: none; }
.adv summary { cursor: pointer; }
.restarting { position: fixed; inset: 0; z-index: 200; background: rgba(14,17,22,.92); display: grid; place-items: center; font-size: 18px; color: var(--accent); }
@media (min-width: 861px) { .drawer { top: var(--topbar, 49px); } }
#hubDrawer .f-row.chk { grid-template-columns: auto 1fr; }
.topbar .tfs button { padding: 5px 6px; }

/* ---------------------------------------------------------------- phone app */
.m-only, .m-nav { display: none; }
@media (max-width: 860px) {
  :root { --nav: 58px; --safe-b: env(safe-area-inset-bottom, 0px); }
  html, body { height: auto; overscroll-behavior: none; }
  .app { height: auto; min-height: 100dvh; padding-bottom: calc(var(--nav) + var(--safe-b)); }
  .topbar { gap: 4px; padding: 6px 8px; padding-top: max(6px, env(safe-area-inset-top)); position: sticky; top: 0; z-index: 30; }
  .topbar .brand, .layouts, .chip.link, #demoBadge, #indBtn, #chartType { display: none; }
  .app.single-acct #acctTabs { display: none; }
  .sym input { width: 104px; }
  .tfs { order: 10; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .tfs::-webkit-scrollbar { display: none; }
  .layout { display: block; }
  .m-only { display: flex; }
  /* views: only one shows at a time */
  .chart-area, .side, .bottom { display: none !important; }
  .app[data-mv=chart] .chart-area { display: flex !important; flex-direction: column; height: calc(100dvh - var(--topbar, 90px) - var(--nav) - var(--safe-b)); min-height: 280px; }
  .app[data-mv=trade] .side, .app[data-mv=watch] .side, .app[data-mv=alerts] .side { display: flex !important; }
  .app[data-mv=positions] .bottom { display: block !important; }
  .side { border-left: none; overflow: visible; }
  .side-tabs { display: none; }
  .bottom { max-height: none !important; padding-bottom: 20px; }
  .charts { grid-template: 1fr / 1fr !important; }
  .charts .pane:not(.active) { display: none; }
  .charts.layout-3 .pane:first-child { grid-row: auto; }
  .pane .legend { right: 8px; font-size: 11px; }
  .pane .dmc-dash { display: none; }
  /* drawing tools fold away behind ✏️ */
  .drawbar { display: none; }
  .app.draw-open .drawbar { display: flex; position: absolute; z-index: 9; top: 50px; left: 6px; width: 40px; max-height: calc(100% - 120px);
    border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
  .draw-toggle { position: absolute; z-index: 9; top: 8px; left: 6px; width: 38px; height: 36px; padding: 0; justify-content: center; align-items: center;
    font-size: 17px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
  .app.draw-open .draw-toggle { border-color: var(--accent); }
  .pane .legend { left: 52px; }
  /* quick buy / sell */
  .quick { position: absolute; z-index: 8; left: 8px; right: 60px; bottom: 34px; gap: 6px; align-items: stretch; }
  .quick > button { flex: 1; border: none; border-radius: 8px; padding: 6px; color: #fff; display: flex; flex-direction: column; align-items: center; opacity: .93; }
  .quick small { font-size: 10px; font-weight: 600; opacity: .85; } .quick b { font-size: 15px; font-variant-numeric: tabular-nums; }
  .quick .sell { background: var(--down); } .quick .buy { background: #2a8bd8; }
  .quick button:disabled { opacity: .35; }
  .q-lots { display: flex; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
  .q-lots button { border: none; background: transparent; font-size: 18px; width: 30px; padding: 0; height: 100%; }
  .q-lots input { width: 54px; border: none; background: transparent; text-align: center; padding: 4px 0; font-weight: 600; }
  .pick-hint { bottom: 92px; }
  /* bottom tab bar */
  .m-nav { display: flex; position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; height: calc(var(--nav) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: var(--panel); border-top: 1px solid var(--line); }
  .m-nav button { flex: 1; border: none; border-radius: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 2px; font-size: 11px; position: relative; padding: 0; }
  .m-nav button i { font-style: normal; font-size: 19px; filter: grayscale(1); opacity: .7; }
  .m-nav button.on { color: var(--accent); } .m-nav button.on i { filter: none; opacity: 1; }
  .badge-n { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--accent); color: #111; font-size: 10px; font-weight: 700; border-radius: 8px; padding: 0 5px; }
  /* bigger touch targets, full-screen panels */
  .mini { padding: 6px 10px; font-size: 12px; }
  .bulk button { padding: 10px 4px; }
  .drawer { top: 0 !important; width: 100vw; z-index: 60; padding-bottom: calc(var(--nav) + 20px); }
  .modal-box { width: 94vw; }
  .ctx { min-width: 70vw; } .ctx-item { padding: 11px 12px; font-size: 14px; }
  .toasts { bottom: calc(var(--nav) + 10px + var(--safe-b)); right: 8px; left: 8px; max-width: none; }
  .pane-style { flex-wrap: wrap; max-width: 92%; top: 50px; }
  input, select, textarea { font-size: 16px; }   /* stops iPhone zooming in on inputs */
}
@media (max-width: 860px) and (orientation: landscape) {
  .app[data-mv=chart] .chart-area { height: calc(100dvh - var(--nav) - var(--safe-b)); }
  .app[data-mv=chart] .topbar { position: static; }
}
/* phone: tables become cards */
@media (max-width: 860px) {
  #posTable thead, #ordTable thead, #jTable thead { display: none; }
  #posTable tr, #ordTable tr, #jTable tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 2px 8px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
  #posTable td, #ordTable td, #jTable td { border: none; padding: 1px 0; white-space: normal; font-size: 13px; }
  #posTable td.empty, #jTable td.empty { grid-column: 1 / -1; }
  /* positions: Acct Symbol Side | Lots Open Now | SL TP P/L | buttons */
  #posTable td:nth-child(1) { color: var(--muted); font-size: 11px; }
  #posTable td:nth-child(2) { font-weight: 700; }
  #posTable td:nth-child(4)::before { content: 'Lots '; color: var(--muted); font-size: 11px; }
  #posTable td:nth-child(5)::before { content: 'Open '; color: var(--muted); font-size: 11px; }
  #posTable td:nth-child(6)::before { content: 'Now '; color: var(--muted); font-size: 11px; }
  #posTable td:nth-child(7)::before { content: 'SL '; color: var(--muted); font-size: 11px; }
  #posTable td:nth-child(8)::before { content: 'TP '; color: var(--muted); font-size: 11px; }
  #posTable td:nth-child(9) { font-size: 15px; }
  #posTable td:nth-child(10) { grid-column: 1 / -1; margin-top: 4px; }
  #posTable td .acts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
  #posTable td .acts .mini { padding: 9px 4px; }
  #ordTable td:nth-child(8) { grid-column: 1 / -1; }
  #ordTable td:nth-child(5)::before { content: '@ '; color: var(--muted); }
  #ordTable td:nth-child(6)::before { content: 'SL '; color: var(--muted); font-size: 11px; }
  #ordTable td:nth-child(7)::before { content: 'TP '; color: var(--muted); font-size: 11px; }
  /* journal: date acct symbol | side lots pips | entry exit P/L | rest */
  #jTable tr { grid-template-columns: 1.2fr 1fr 1fr; }
  #jTable td:nth-child(1) { color: var(--muted); font-size: 11px; }
  #jTable td:nth-child(3) { font-weight: 700; }
  #jTable td:nth-child(6)::before { content: 'In '; color: var(--muted); font-size: 11px; }
  #jTable td:nth-child(7)::before { content: 'Out '; color: var(--muted); font-size: 11px; }
  #jTable td:nth-child(8)::after { content: ' pips'; color: var(--muted); font-size: 11px; }
  #jTable td:nth-child(10), #jTable td:nth-child(11), #jTable td:nth-child(12), #jTable td:nth-child(13), #jTable td:nth-child(14) { font-size: 11px; color: var(--muted); }
  .j-stats { grid-template-columns: 1fr 1fr; }
}

/* ---------------------------------------------------------------- Pine scripts */
.pine-list { display: grid; gap: 4px; margin-top: 6px; }
.pine-row { display: flex; align-items: center; gap: 8px; padding: 7px 4px; border-bottom: 1px solid #1d232b; }
.pine-name { flex: 1; min-width: 0; } .pine-name b { font-size: 13px; }
.pine-editor { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: flex; flex-direction: column; }
.pe-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.pe-name { width: 260px; font-weight: 600; }
.pe-bar label input { width: 70px; padding: 4px; }
.pe-body { flex: 1; min-height: 0; display: flex; overflow: hidden; }
.pe-gutter { margin: 0; padding: 10px 8px; width: 52px; overflow: hidden; text-align: right; color: #4a5361; background: var(--panel); border-right: 1px solid var(--line);
  font: 13px/1.5 ui-monospace, Consolas, 'Cascadia Code', monospace; user-select: none; }
.pe-code { flex: 1; border: none; border-radius: 0; resize: none; padding: 10px 12px; background: var(--bg); color: #d7dde5; tab-size: 4;
  font: 13px/1.5 ui-monospace, Consolas, 'Cascadia Code', monospace; white-space: pre; overflow: auto; }
.pe-code:focus { border: none; }
.pe-status { min-height: 32px; max-height: 30vh; overflow: auto; padding: 7px 12px; border-top: 1px solid var(--line); background: var(--panel); font-size: 12px; white-space: pre-wrap; }
.pe-status.bad { color: #ff8a80; background: #2a1517; }
.pine-tables { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.pine-table { position: absolute; border-collapse: collapse; font-size: 11px; }
.pine-table td { padding: 2px 6px; white-space: nowrap; }
.pine-table.pos-top_right { top: 30px; right: 64px; } .pine-table.pos-top_left { top: 30px; left: 8px; } .pine-table.pos-top_center { top: 30px; left: 50%; transform: translateX(-50%); }
.pine-table.pos-middle_right { top: 50%; right: 64px; transform: translateY(-50%); } .pine-table.pos-middle_left { top: 50%; left: 8px; transform: translateY(-50%); }
.pine-table.pos-middle_center { top: 50%; left: 50%; transform: translate(-50%, -50%); }
.pine-table.pos-bottom_right { bottom: 34px; right: 64px; } .pine-table.pos-bottom_left { bottom: 34px; left: 8px; } .pine-table.pos-bottom_center { bottom: 34px; left: 50%; transform: translateX(-50%); }
.pine-err { position: absolute; left: 50%; transform: translateX(-50%); bottom: 36px; background: #3a1515; color: #ff8a80; border: 1px solid #5a2020; border-radius: 6px;
  padding: 4px 10px; font-size: 12px; max-width: 80%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: auto; }
.pine-inputs { display: grid; gap: 6px; max-height: 60vh; overflow-y: auto; }
.pine-inputs .f-row { grid-template-columns: 1fr 140px; }
#stTable tbody tr { cursor: pointer; } #stTable tbody tr:hover { background: var(--panel2); }
@media (max-width: 860px) {
  .pe-name { width: 150px; } .pe-code, .pe-gutter { font-size: 12px; }
  #pineBtn { font-size: 12px; }
}
.pine-table { width: auto !important; }

/* iPhone notch / status bar: keep full-screen panels below it */
:root { --safe-t: env(safe-area-inset-top, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px); }
@media (max-width: 860px) {
  .drawer-head { padding-top: calc(12px + var(--safe-t)); padding-left: max(12px, var(--safe-l)); padding-right: max(12px, var(--safe-r)); }
  .drawer-head button { min-width: 44px; min-height: 40px; }
  .pine-editor { padding-top: var(--safe-t); padding-left: var(--safe-l); padding-right: var(--safe-r); padding-bottom: var(--safe-b); }
  .modal { padding-top: var(--safe-t); padding-bottom: var(--safe-b); }
  .modal-box { max-height: calc(100dvh - var(--safe-t) - var(--safe-b) - 20px); overflow-y: auto; }
  .login { padding-top: var(--safe-t); }
  .topbar { padding-left: max(8px, var(--safe-l)); padding-right: max(8px, var(--safe-r)); }
}

#mgrManual { padding: 6px 8px; margin-bottom: 6px; border: 1px solid #e8b44a55; border-radius: 6px; color: #e8b44a; }
.mgr.manual-only #mBeRow, .mgr.manual-only #mTrRow { opacity: .45; }

.pane-loading.err { pointer-events: auto; text-align: center; max-width: 80%; line-height: 1.5; padding: 12px 16px; background: var(--panel, #161a22); border: 1px solid #ef535088; border-radius: 8px; }
.pane-loading.err button { margin-top: 8px; }

/* right panel minimised to a strip of vertical tabs (desktop) */
.side-tabs button i { font-style: normal; display: none; }
.side-min-btn { flex: 0 0 34px !important; color: var(--muted); }
@media (min-width: 861px) {
  body.side-min .layout { grid-template-columns: 1fr 38px; }
  body.side-min .side { overflow: hidden; }
  body.side-min .side-body, body.side-min .side-min-btn { display: none !important; }
  body.side-min .side-tabs { flex-direction: column; border-bottom: none; position: static; }
  body.side-min .side-tabs button { flex: none; padding: 12px 0; border-bottom: none; border-left: 2px solid transparent; color: var(--muted); }
  body.side-min .side-tabs button i { display: block; font-size: 15px; margin-bottom: 6px; }
  body.side-min .side-tabs button span { writing-mode: vertical-rl; font-size: 12px; }
  body.side-min .side-tabs button.on { border-left-color: transparent; color: var(--muted); }
  body.side-min .side-tabs button:hover { color: var(--text); background: rgba(255,255,255,.04); }
}
@media (max-width: 860px) { .side-min-btn { display: none !important; } }

/* resizable bottom panel (desktop) */
.bottom-grip { display: none; }
@media (min-width: 861px) {
  .bottom { height: var(--bottom-h, 220px); max-height: none !important; padding-top: 0; }
  body.bottom-min .bottom { overflow: hidden; }
  .bottom-grip { display: block; position: sticky; top: 0; z-index: 3; height: 6px; margin: 0 -10px; cursor: ns-resize; background: transparent; }
  .bottom-grip:hover, body.resizing-bottom .bottom-grip { background: var(--accent); opacity: .6; }
  .bottom-tabs { top: 6px; }
  body.resizing-bottom, body.resizing-bottom * { cursor: ns-resize !important; user-select: none; }
}

/* phones/tablets: the page itself never zooms (only the chart does) */
html, body { touch-action: pan-x pan-y; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.pane, .pane canvas, .chart-area .charts { touch-action: none; }
@media (max-width: 860px), (pointer: coarse) {
  /* iPhone zooms the page when you tap a box with text under 16px - keep inputs at 16px */
  input, select, textarea { font-size: 16px !important; }
}

/* live P/L at the top of the Trade tab */
.live-pnl { padding: 8px 10px; }
.live-pnl .lp-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 13px; color: var(--muted); }
.live-pnl .lp-head b { font-size: 22px; }
.live-pnl .lp-row { display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 5px 0; border-top: 1px solid var(--line); }
.live-pnl .lp-row:first-of-type { border-top: none; }
.live-pnl .lp-row b { font-size: 15px; }
.live-pnl .spacer { flex: 1; }
.live-pnl .lp-x { padding: 2px 8px; }

/* phones: the page itself never scrolls (iPhone could drag the bottom bar along). The app fills the screen
   above the bottom bar and only the panel in the middle scrolls. */
@media (max-width: 860px) {
  html, body { height: 100%; overflow: hidden; position: fixed; inset: 0; width: 100%; }
  .app { position: fixed; left: 0; right: 0; top: 0; bottom: calc(var(--nav) + var(--safe-b));
         height: auto; min-height: 0; padding-bottom: 0; display: flex; flex-direction: column; }
  .app.hidden { display: none; }
  .topbar { position: relative; flex: none; }
  .layout { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
  .app[data-mv=chart] .layout { overflow: hidden; }
  .app[data-mv=chart] .chart-area { height: 100% !important; min-height: 0; }
}

@media (max-width: 860px) {
  /* iPhone home-screen app: iOS leaves a strip under the bottom tabs it doesn't draw into -
     give it the tab bar's colour so it looks like part of the bar instead of a blank band */
  html, body { background: var(--panel); }
  .app { background: var(--bg); }
}

body.no-quick .quick { display: none !important; }

@media (max-width: 860px) {
  /* ⚡ quick-trade toggle, just under the ✏️ drawing button */
  .quick-toggle { position: absolute; z-index: 9; left: 6px; top: 50px; width: 36px; height: 36px; padding: 0; border-radius: 8px;
                  font-size: 17px; background: var(--panel); border: 1px solid var(--line); opacity: .55; display: block; }
  .quick-toggle.on { opacity: 1; border-color: var(--accent); }
  /* bottom tabs: words only */
  .m-nav button i { display: none; }
  .m-nav button { font-size: 14px; font-weight: 600; }
  .m-nav .badge-n { top: 8px; left: auto; right: 6px; }
}
@media (max-width: 860px) { .app.draw-open .quick-toggle { display: none; } }
