/* ============================================================================
   redesign.css — OKX Terminal · Fintech UI 2026
   Additive layer: loaded after style.css. No trading/API logic here.
   Device hooks: html[data-device="desktop|mobile|tv"]
   Theme hooks:  html[data-theme="dark|silver|white"]
   ========================================================================== */

/* ── 1. Design tokens ───────────────────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg: #0B0E11;
  --bg-deep: #07090C;
  --panel: #131722;
  --panel2: #1C212E;
  --panel3: #222938;
  --line: #1E222D;
  --line-soft: #2A3040;
  --text: #E8EAF0;
  --dim: #8A93A6;
  --muted: #98A2B4;
  --long: #0ECB81;
  --long-soft: rgba(14, 203, 129, .14);
  --long-strong: rgba(14, 203, 129, .52);
  --short: #F6465D;
  --short-soft: rgba(246, 70, 93, .13);
  --short-strong: rgba(246, 70, 93, .50);
  --accent: #F5B83D;
  --accent-soft: rgba(245, 184, 61, .12);
  --focus: #4D8DFF;
  --price: #4D8DFF;
  --liq: #FF9F1A;
  --shadow-1: 0 10px 30px rgba(0, 0, 0, .34);
  --shadow-2: 0 18px 50px rgba(0, 0, 0, .46);
  --radius: 8px;
  --radius-sm: 6px;
  --gap: 8px;
  color-scheme: dark;
}

[data-theme="silver"] {
  --bg: #0D1117;
  --bg-deep: #090D12;
  --panel: #151B24;
  --panel2: #1C232E;
  --panel3: #242D3B;
  --line: #303947;
  --line-soft: #3B4657;
  --text: #D6DEE9;
  --dim: #94A0B2;
  --muted: #A9B5C6;
  --long: #3FB950;
  --long-soft: rgba(63, 185, 80, .15);
  --long-strong: rgba(63, 185, 80, .52);
  --short: #F85149;
  --short-soft: rgba(248, 81, 73, .15);
  --short-strong: rgba(248, 81, 73, .50);
  --accent: #D29922;
  --accent-soft: rgba(210, 153, 34, .12);
  --focus: #58A6FF;
  --price: #58A6FF;
  --liq: #F0883E;
  --shadow-1: 0 10px 30px rgba(0, 0, 0, .34);
  --shadow-2: 0 18px 50px rgba(0, 0, 0, .46);
  color-scheme: dark;
}

[data-theme="white"] {
  --bg: #EEF2F6;
  --bg-deep: #E5EBF1;
  --panel: #FFFFFF;
  --panel2: #F4F7FA;
  --panel3: #EAF0F5;
  --line: #D3DCE6;
  --line-soft: #BFCAD6;
  --text: #17202B;
  --dim: #5D6B7A;
  --muted: #5E6D7E;
  --long: #0B8F5C;
  --long-soft: rgba(11, 143, 92, .12);
  --long-strong: rgba(11, 143, 92, .40);
  --short: #D92D44;
  --short-soft: rgba(217, 45, 68, .10);
  --short-strong: rgba(217, 45, 68, .38);
  --accent: #A66A00;
  --accent-soft: rgba(166, 106, 0, .10);
  --focus: #0B63CE;
  --price: #0B63CE;
  --liq: #B65300;
  --shadow-1: 0 8px 22px rgba(28, 43, 58, .12);
  --shadow-2: 0 18px 50px rgba(28, 43, 58, .18);
  color-scheme: light;
}

/* ── 2. Base / typography ───────────────────────────────────────────────── */
html, body {
  background: var(--bg);
}

body {
  font: 12.5px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 380px at 50% -180px, rgba(77, 141, 255, .10), transparent 70%),
    var(--bg);
}

[data-theme="white"] body {
  background:
    radial-gradient(900px 300px at 50% -160px, rgba(11, 99, 206, .08), transparent 70%),
    var(--bg);
}

::selection { background: var(--focus); color: #fff; }

.num,
.tbl td,
.tbl th,
.r,
.kpi b,
#aEq, #aAv, #aUpl, #kPrice, #kSpread, #kLong, #kShort, #kPress,
#fsPx, #chSym, #ohlc, .dash, #pnlPanel {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-soft) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-soft);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--dim); background-clip: padding-box; }

:focus-visible {
  outline: 2px solid var(--focus) !important;
  outline-offset: 2px !important;
}

/* ── 3. Header / status / mode badges ────────────────────────────────────── */
.bar {
  gap: 7px 12px;
  padding: 8px 14px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg) 100%);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(255,255,255,.02);
}

.brand { position: relative; padding-left: 10px; }
.brand::before {
  content: "";
  position: absolute;
  left: 0; top: 2px; bottom: 2px;
  width: 3px;
  border-radius: 3px;
  background: linear-gradient(180deg, var(--focus), var(--long));
}
.brand strong { font-size: 14px; letter-spacing: .2px; }
.brand span { color: var(--muted); font-size: 10.5px; letter-spacing: .1px; }

.ctl label {
  color: var(--dim);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .35px;
}

input, select {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 5px 8px;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
input:hover, select:hover { border-color: var(--line-soft); }
input:focus, select:focus { border-color: var(--focus); box-shadow: 0 0 0 2px rgba(77,141,255,.12); }

.btn {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 5px 10px;
  font-weight: 500;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.btn:hover { background: var(--panel3); border-color: var(--line-soft); }
.btn:active { transform: translateY(1px); }
.btn.main { background: var(--focus); border-color: var(--focus); color: #fff; box-shadow: 0 4px 14px rgba(77,141,255,.22); }
.btn.main.off { background: var(--short); border-color: var(--short); box-shadow: 0 4px 14px var(--short-soft); }
.btn.sm { padding: 3px 8px; font-size: 11px; border-radius: 5px; }

/* Status pills */
.st {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel2);
  color: var(--dim);
  font-size: 10.5px;
  white-space: nowrap;
}
.st .dot { width: 7px; height: 7px; }
.st.ok { color: var(--long); border-color: rgba(14,203,129,.28); background: var(--long-soft); }
.st.warn { color: var(--accent); border-color: rgba(245,184,61,.28); background: var(--accent-soft); }
.st.err { color: var(--short); border-color: rgba(246,70,93,.30); background: var(--short-soft); }

/* Account mode: add a visible security badge via redesign.js */
#mode { min-width: 152px; font-weight: 600; }
#mode[data-mode="live"],
html[data-account-mode="live"] #mode {
  border-color: var(--short) !important;
  color: var(--short) !important;
  background: var(--short-soft) !important;
}
html[data-account-mode="demo"] #mode {
  border-color: rgba(77,141,255,.35);
  color: var(--price);
}
.acct-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  min-height: 22px;
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .35px;
  text-transform: uppercase;
  border: 1px solid var(--line);
  color: var(--dim);
  background: var(--panel2);
  white-space: nowrap;
}
.acct-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.acct-badge.demo { color: var(--price); border-color: rgba(77,141,255,.35); background: rgba(77,141,255,.08); }
.acct-badge.live { color: var(--short); border-color: var(--short); background: var(--short-soft); animation: livePulse 2.2s ease-in-out infinite; }
.acct-badge.paper { color: var(--dim); }
@keyframes livePulse { 0%,100% { box-shadow: 0 0 0 0 rgba(246,70,93,0); } 50% { box-shadow: 0 0 0 4px rgba(246,70,93,.10); } }

.kpis { gap: 12px; }
.kpi {
  min-width: 78px;
  padding: 4px 10px;
  border-left: 1px solid var(--line);
}
.kpi:first-child { border-left: 0; padding-left: 2px; }
.kpi small { color: var(--muted); font-size: 9.5px; text-transform: uppercase; letter-spacing: .45px; }
.kpi b { font-size: 14px; letter-spacing: .1px; }
.kpi .pbar { margin-top: 5px; height: 4px; background: var(--short-strong); }

.banner { padding: 7px 14px; letter-spacing: .25px; }
.banner.demo { background: var(--accent-soft); color: var(--accent); border-bottom: 1px solid rgba(245,184,61,.18); }
.banner.live { background: var(--short); color: #fff; box-shadow: 0 4px 16px rgba(246,70,93,.20); }
.note { border-bottom: 1px solid var(--line); background: var(--panel2); }

/* ── 4. Desktop shell / grid ────────────────────────────────────────────── */
.layout {
  gap: 10px;
  padding: 10px;
  grid-template-columns: 292px minmax(0, 1fr) 390px;
  grid-template-rows: minmax(0, 1fr) 204px;
  grid-template-areas: "lad chart ord" "lad tabs ord";
}
.a-chart .cwrap { min-height: 120px; }

.panel {
  background:
    linear-gradient(180deg, rgba(255,255,255,.015), transparent 90px),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
.panel > h2 {
  padding: 8px 12px;
  color: var(--dim);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .7px;
  text-transform: uppercase;
  background: var(--panel2);
}
.panel:hover { border-color: var(--line-soft); }

/* ── 5. Orderbook / walls ───────────────────────────────────────────────── */
.a-lad .scroll { padding: 0 4px 4px; }
.lad { font-size: 11.5px; line-height: 1.2; }
.r {
  grid-template-columns: 68px minmax(0, 1fr) 58px;
  height: 21px;
  border-radius: 4px;
  margin: 0;
}
.r .p { padding-right: 7px; }
.r .s { padding: 0 7px; border-radius: 4px; }
.r.ask .s { background: linear-gradient(to right, var(--short-soft) var(--w), transparent var(--w)); }
.r.bid .s { background: linear-gradient(to right, var(--long-soft) var(--w), transparent var(--w)); }
.r.wall.ask .s { background: linear-gradient(to right, var(--short-strong) var(--w), transparent var(--w)); }
.r.wall.bid .s { background: linear-gradient(to right, var(--long-strong) var(--w), transparent var(--w)); }
.r .c { color: var(--muted); padding-right: 7px; }
.tw {
  border: 1px solid transparent;
  padding: 1px 5px;
  border-radius: 999px;
  font-size: 9px;
  line-height: 1.3;
  background: var(--panel3);
}
.r.ask .tw { color: var(--short); border-color: rgba(246,70,93,.22); }
.r.bid .tw { color: var(--long); border-color: rgba(14,203,129,.22); }
.r.fresh .tw { background: var(--accent); color: #111; border-color: var(--accent); }
.mid {
  margin: 3px 4px 5px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background:
    linear-gradient(90deg, var(--panel2), var(--panel3), var(--panel2));
}
.mid b { font-size: 15px; }
.mid small, .mid .hint { color: var(--muted); }

/* ── 6. Chart header / tooling ──────────────────────────────────────────── */
.a-chart { min-width: 0; }
 .ch1 {
  padding: 6px 10px;
  gap: 4px 8px;
  background: var(--panel2);
  border-bottom: 1px solid var(--line);
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.ch1::-webkit-scrollbar { display: none; }
.ch1 > * { flex-shrink: 0; }
.ch1 b#chSym { font-size: 13px; letter-spacing: .1px; }
.tfs { gap: 2px; }
.tfs button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--dim);
  min-height: 24px;
  padding: 2px 6px;
  border-radius: 5px;
}
.tfs button:hover { background: var(--panel3); color: var(--text); }
.tfs button.on { color: var(--text); background: var(--panel3); border-color: var(--line-soft); }
.fsbar {
  background: var(--panel2);
  border-bottom: 1px solid var(--line);
}
.ohlc {
  color: var(--dim);
  font-size: 10.5px;
  flex-wrap: nowrap;
  overflow: hidden;
  white-space: nowrap;
  padding-top: 2px;
  padding-bottom: 2px;
}
.cwrap { background: var(--bg-deep); }
.chsrow { background: var(--panel); border-top: 1px solid var(--line); }
.fsdock {
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border-top: 1px solid var(--line);
  padding: 7px 10px 8px;
}
.fsrow { gap: 5px; }
.fsdock input, .fsdock select { height: 28px; }
.fsdock .chip { height: 26px; }

/* ── 7. Trade / order panel ────────────────────────────────────────────── */
.a-ord { border-color: var(--line); overflow-y: auto !important; overflow-x: hidden; }
.a-ord > h2 {
  order: -2;
  position: sticky;
  top: 0;
  z-index: 4;
  background: var(--panel2);
  color: var(--dim);
  letter-spacing: .7px;
  text-transform: uppercase;
}
.a-ord > .ordf {
  order: -1;
  flex: 0 0 auto;
  min-height: 0;
  overflow: visible;
}
.a-ord > #autoPanel,
.a-ord > #stDash,
.a-ord > #riskPanel,
.a-ord > #pnlPanel,
.a-ord > #journalPanel { order: 0; flex: 0 0 auto; }
.ordf { padding: 10px; gap: 9px; }
.acc {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel2);
}
.acc > div { padding: 7px 9px; border-right: 1px solid var(--line); }
.acc > div:last-child { border-right: 0; }
.acc small { color: var(--muted); font-size: 9.5px; text-transform: uppercase; letter-spacing: .35px; }
.acc b { font-size: 13px; }

.seg {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel2);
  padding: 2px;
  gap: 2px;
}
.seg button {
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--dim);
  min-height: 28px;
  font-weight: 600;
}
.seg button.on { background: var(--panel3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
#segSide button[data-v="long"].on { background: var(--long-soft); color: var(--long); box-shadow: inset 0 0 0 1px rgba(14,203,129,.25); }
#segSide button[data-v="short"].on { background: var(--short-soft); color: var(--short); box-shadow: inset 0 0 0 1px rgba(246,70,93,.25); }

.fld { gap: 4px; }
.fld > label, .ordf label { color: var(--dim); font-size: 10.5px; }
.row { display: flex; gap: 6px; }
.chips { gap: 4px; }
.chip {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--dim);
  min-height: 24px;
  padding: 2px 7px;
}
.chip:hover { border-color: var(--line-soft); color: var(--text); }
.chip.on { background: var(--focus); color: #fff; border-color: var(--focus); }

.go {
  border: 0;
  border-radius: var(--radius-sm);
  min-height: 38px;
  font-weight: 800;
  letter-spacing: .35px;
  text-transform: uppercase;
}
.go.long { background: var(--long); color: #04130c; box-shadow: 0 6px 18px var(--long-soft); }
.go.short { background: var(--short); color: #fff; box-shadow: 0 6px 18px var(--short-soft); }
.go:hover { filter: brightness(1.06); }
.go:active { transform: translateY(1px); }
#riskBtn { border-color: rgba(77,141,255,.35); color: var(--price); }

.dash {
  background: var(--panel2);
  border-bottom: 1px solid var(--line);
}
#autoPanel { background: var(--panel); }
.tpl-bar { border-bottom: 1px solid var(--line); padding-bottom: 6px; }
#stDash, #riskPanel, #pnlPanel, #journalPanel { border-radius: 0; }

/* ── 8. Bottom tabs / tables ────────────────────────────────────────────── */
.a-tabs { background: var(--panel); }
.tabbar {
  padding: 5px 7px;
  background: var(--panel2);
  border-bottom: 1px solid var(--line);
  gap: 2px;
}
.tabbar button {
  border-radius: 5px;
  min-height: 28px;
  padding: 4px 9px;
  color: var(--dim);
  font-size: 11px;
}
.tabbar button:hover { background: var(--panel3); color: var(--text); }
.tabbar button.on { background: var(--panel3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-soft); }
.tabbar button span { color: var(--muted); font-size: 10px; }
#tabBody { padding: 0 6px; }
.tbl { border-collapse: separate; border-spacing: 0; }
.tbl th {
  background: var(--panel2);
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: uppercase;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.tbl td { border-bottom: 1px solid rgba(30,34,45,.62); padding: 6px 8px; }
[data-theme="white"] .tbl td { border-bottom-color: rgba(211,220,230,.7); }
.tbl tr:hover td { background: var(--panel2); }

/* Generic small badges created by existing modules */
.badge, .pill, .tag {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 1px 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel3);
  color: var(--dim);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .25px;
}

/* ── 9. Settings drawer ─────────────────────────────────────────────────── */
details.set {
  background: transparent;
  border: 0;
  padding: 0 10px;
  flex-shrink: 0;
}
details.set > summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  color: var(--dim);
  font-size: 11px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--panel);
  width: fit-content;
}
details.set > summary::-webkit-details-marker { display: none; }
details.set > summary:hover { color: var(--text); border-color: var(--line-soft); }
details.set[open] {
  position: fixed;
  z-index: 120;
  top: 64px;
  right: 12px;
  bottom: 12px;
  width: min(820px, calc(100vw - 24px));
  display: block;
  padding: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  animation: drawerIn .16s ease-out;
}
details.set[open]::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: rgba(0, 0, 0, .42);
  backdrop-filter: blur(2px);
}
details.set[open] > summary {
  order: 0;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel2);
  padding: 10px 14px;
  color: var(--text);
  font-weight: 700;
  letter-spacing: .3px;
}
details.set[open] > .set-toolbar {
  order: 1;
  flex-shrink: 0;
  padding: 8px 12px;
}
details.set[open] > .set-tabs {
  order: 2;
  flex-shrink: 0;
  padding: 7px 12px;
}
details.set[open] > .set-content {
  position: absolute;
  left: 0;
  right: 0;
  top: 45px;
  bottom: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
details.set[open] > .set-content > .set-toolbar,
details.set[open] > .set-content > .set-tabs { flex: 0 0 auto; }
details.set[open] > .set-content > .set-body-wrap {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
details.set[open] > .set-content > .set-body-wrap > .set-body {
  flex: 1 1 0;
  min-height: 0;
  height: auto;
  overflow: auto;
  padding: 0 12px 16px;
}
details.set:not([open]) > summary { margin-left: 0; }
.set-close {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--dim);
  border-radius: 5px;
  min-height: 24px;
  padding: 1px 7px;
}
.set-close:hover { color: var(--short); border-color: var(--short); }
.set-badge:not(:empty) {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
@keyframes drawerIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* Settings content hierarchy */
.set-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 12px;
  background: var(--panel);
}
.set-toolbar input { min-width: 180px; flex: 1 1 200px; }
.set-tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 7px 12px; border-bottom: 1px solid var(--line); }
.set-tabs button {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--dim);
  background: var(--panel2);
  padding: 5px 11px;
  font-size: 11px;
}
.set-tabs button.on { background: var(--focus); border-color: var(--focus); color: #fff; }
.set-body { padding-top: 10px; }
.set-cat h4 {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .65px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
.set-cat label { color: var(--dim); }
.set-cat label.chk { color: var(--text); }
.set-adv summary { color: var(--dim); }
.set-adv summary:hover { color: var(--text); }

/* ── 10. Modals / popovers ──────────────────────────────────────────────── */
.pop {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  box-shadow: var(--shadow-2);
}
.pop h4 { color: var(--text); font-size: 13px; }
.pop label { color: var(--dim); }
.pop input, .pop select { border-color: var(--line); }
.modal { background: rgba(0,0,0,.62); }
.modal .mbox {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  box-shadow: var(--shadow-2);
}
.modal .mbox h3 { color: var(--text); }
.modal .btns .main { background: var(--focus); }

/* ── 11. Mobile tab bar / mobile layout ────────────────────────────────── */
.mnav { display: none; }

html[data-device="mobile"] body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
html[data-device="mobile"] .bar {
  flex-shrink: 0;
  padding: 6px 8px;
  gap: 5px 8px;
}
html[data-device="mobile"] .brand { flex: 1 1 100%; padding-left: 9px; }
html[data-device="mobile"] .brand strong { font-size: 13px; }
html[data-device="mobile"] .brand span { display: none; }
html[data-device="mobile"] .ctl { flex-wrap: wrap; }
html[data-device="mobile"] .ctl label { display: none; }
html[data-device="mobile"] #instId { width: 54vw; min-height: 32px; }
html[data-device="mobile"] .kpis {
  width: 100%;
  margin: 1px 0 0;
  gap: 0;
  justify-content: space-between;
}
html[data-device="mobile"] .kpi { min-width: 0; flex: 1; padding: 2px 6px; }
html[data-device="mobile"] .kpi small { display: none; }
html[data-device="mobile"] .kpi b { font-size: 12px; }
html[data-device="mobile"] #kPress { display: none; }
html[data-device="mobile"] .bar #logoutBtn { display: none; }
html[data-device="mobile"] .banner { font-size: 10.5px; padding: 4px 8px; }
html[data-device="mobile"] .note { font-size: 10px; }

html[data-device="mobile"] .layout {
  flex: 1;
  min-height: 0;
  display: flex !important;
  flex-direction: column;
  padding: 6px 6px calc(64px + env(safe-area-inset-bottom));
  overflow: hidden;
  background: var(--bg);
}
html[data-device="mobile"] .layout > .panel { display: none !important; }
html[data-device="mobile"][data-mobile-view="chart"] .layout > .a-chart,
html[data-device="mobile"][data-mobile-view="book"] .layout > .a-lad,
html[data-device="mobile"][data-mobile-view="trade"] .layout > .a-ord,
html[data-device="mobile"][data-mobile-view="positions"] .layout > .a-tabs {
  display: flex !important;
  flex: 1 1 0 !important;
  height: 0 !important;
  min-height: 0 !important;
  max-height: none !important;
  border-radius: var(--radius);
}
html[data-device="mobile"] .layout > .a-chart { flex-direction: column; }
html[data-device="mobile"] .a-chart .cwrap { flex: 1; min-height: 0; }
html[data-device="mobile"] .a-chart .fsdock { display: none; }
html[data-device="mobile"] .a-lad { flex-direction: column; }
html[data-device="mobile"] .a-lad .scroll { flex: 1 1 0 !important; min-height: 0 !important; overflow: auto !important; }
html[data-device="mobile"] .a-ord { overflow: hidden; }
html[data-device="mobile"] .a-ord .ordf { flex: 1; overflow: auto; }
html[data-device="mobile"] .a-tabs { flex-direction: column; }
html[data-device="mobile"] .a-tabs .tabbar {
  flex: 0 0 auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}
html[data-device="mobile"] .a-tabs .tabbar button { flex: 0 0 auto; white-space: nowrap; }
html[data-device="mobile"] .a-tabs .scroll { flex: 1 1 0 !important; min-height: 0 !important; overflow: auto !important; }

html[data-device="mobile"] .mnav {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  min-height: calc(58px + env(safe-area-inset-bottom));
  padding: 4px 6px env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px rgba(0,0,0,.25);
  backdrop-filter: blur(10px);
}
html[data-device="mobile"] .mnav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 48px;
  padding: 2px 1px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--dim);
  font-size: 8.2px;
  line-height: 1.1;
  overflow: hidden;
}
html[data-device="mobile"] .mnav button span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html[data-device="mobile"] .mnav button b { font-size: 17px; line-height: 1; font-weight: 500; }
html[data-device="mobile"] .mnav button.on { color: var(--text); background: var(--panel3); }
html[data-device="mobile"] .mnav button.on b { color: var(--focus); }
html[data-device="mobile"] details.set:not([open]) { display: none; }
html[data-device="mobile"] details.set[open] {
  top: 8px;
  right: 8px;
  left: 8px;
  bottom: 8px;
  width: auto;
}
html[data-device="mobile"] .btn,
html[data-device="mobile"] select,
html[data-device="mobile"] input,
html[data-device="mobile"] .seg button,
html[data-device="mobile"] .chip,
html[data-device="mobile"] .tfs button,
html[data-device="mobile"] .tabbar button,
html[data-device="mobile"] .fsl,
html[data-device="mobile"] #levChips .chip {
  min-height: 44px;
}
html[data-device="mobile"] .btn.sm { min-height: 36px; }
html[data-device="mobile"] .go { min-height: 48px; font-size: 14px; }
html[data-device="mobile"] .a-ord .ordf { padding: 9px; }
html[data-device="mobile"] .a-ord .chips .chip { min-height: 36px; }
html[data-device="mobile"] .modal .mbox { width: calc(100vw - 16px) !important; max-height: calc(100vh - 16px); }
html[data-device="mobile"] .pop { width: calc(100vw - 16px) !important; max-height: calc(100vh - 16px); }

/* ── 12. TV: monitoring dashboard ──────────────────────────────────────── */
html[data-device="tv"] body {
  font-size: 16px;
  background:
    radial-gradient(1600px 500px at 50% -220px, rgba(77,141,255,.18), transparent 70%),
    var(--bg-deep);
}
html[data-device="tv"] .bar {
  padding: 14px 28px;
  gap: 12px 22px;
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-deep) 100%);
  border-bottom-color: var(--line-soft);
}
html[data-device="tv"] .brand strong { font-size: 25px; letter-spacing: .2px; }
html[data-device="tv"] .brand span { font-size: 14px; }
html[data-device="tv"] .kpi b { font-size: 22px; }
html[data-device="tv"] .kpi small { font-size: 11px; }
html[data-device="tv"] .kpis { gap: 24px; }
html[data-device="tv"] .ctl label { font-size: 12px; }
html[data-device="tv"] .btn { padding: 9px 16px; border-radius: 9px; font-size: 16px; }
html[data-device="tv"] .btn.sm { padding: 7px 12px; font-size: 15px; }
html[data-device="tv"] input, html[data-device="tv"] select { font-size: 16px; padding: 8px 11px; }
html[data-device="tv"] .layout {
  grid-template-columns: 380px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 300px;
  grid-template-areas: "lad chart" "lad tabs";
  gap: 16px;
  padding: 16px;
}
html[data-device="tv"] .a-ord { display: none !important; }
html[data-device="tv"] .fsdock,
html[data-device="tv"] .fsbar,
html[data-device="tv"] .chsrow .chs-end,
html[data-device="tv"] details.set { display: none !important; }
html[data-device="tv"] .panel { border-radius: 12px; box-shadow: var(--shadow-2); }
html[data-device="tv"] .panel > h2 { font-size: 13px; padding: 12px 16px; }
html[data-device="tv"] .a-chart .ch1 { padding: 11px 16px; font-size: 16px; }
html[data-device="tv"] .tfs button { min-height: 34px; font-size: 15px; padding: 5px 10px; }
html[data-device="tv"] .ohlc { font-size: 14px; padding: 7px 16px; }
html[data-device="tv"] .a-lad .lad { font-size: 14px; }
html[data-device="tv"] .r { height: 27px; grid-template-columns: 82px 1fr 68px; }
html[data-device="tv"] .a-tabs .tabbar button { min-height: 36px; font-size: 15px; padding: 6px 14px; }
html[data-device="tv"] .a-tabs .tbl { font-size: 14px; }
html[data-device="tv"] .a-tabs .tbl td, html[data-device="tv"] .a-tabs .tbl th { padding: 8px 10px; }
html[data-device="tv"] .mnav { display: none !important; }
html[data-device="tv"] :focus-visible { outline: 4px solid var(--focus) !important; outline-offset: 4px !important; }

/* ── 13. Light / silver theme polish ───────────────────────────────────── */
[data-theme="white"] .panel { box-shadow: var(--shadow-1); }
[data-theme="white"] .bar { background: linear-gradient(180deg, #fff 0%, var(--bg) 100%); }
[data-theme="white"] .btn { background: #fff; color: var(--text); }
[data-theme="white"] .btn:hover { background: var(--panel2); }
/* White theme: .btn override иначе перебивал .btn.main (белый текст на белом). */
[data-theme="white"] .btn.main { background: var(--focus); border-color: var(--focus); color: #fff; }
[data-theme="white"] .btn.main:hover { background: color-mix(in srgb, var(--focus) 88%, #000); border-color: color-mix(in srgb, var(--focus) 88%, #000); color: #fff; }
[data-theme="white"] .btn.main.off { background: var(--short); border-color: var(--short); color: #fff; }
[data-theme="white"] .mid { background: linear-gradient(90deg, var(--panel2), var(--panel3), var(--panel2)); }
[data-theme="white"] .mnav { background: rgba(255,255,255,.94); }
[data-theme="white"] details.set[open]::before { background: rgba(0,0,0,.25); }
[data-theme="silver"] .brand::before { background: linear-gradient(180deg, #58A6FF, #3FB950); }

/* ── 14. Responsive safety net ─────────────────────────────────────────── */
@media (max-width: 1400px) and (min-width: 1181px) {
  .layout { grid-template-columns: 264px minmax(0, 1fr) 360px; grid-template-rows: minmax(0,1fr) 190px; }
  .kpi { min-width: 68px; padding: 4px 7px; }
}
@media (max-width: 1180px) and (min-width: 761px) {
  html[data-device="desktop"] body { overflow: hidden; }
  html[data-device="desktop"] .layout {
    display: grid;
    grid-template-columns: 238px minmax(0, 1fr) 330px;
    grid-template-rows: minmax(0,1fr) 215px;
    grid-template-areas: "lad chart ord" "lad tabs ord";
    height: auto;
    min-height: 0;
    overflow: hidden;
  }
  html[data-device="desktop"] .a-lad, html[data-device="desktop"] .a-chart,
  html[data-device="desktop"] .a-tabs, html[data-device="desktop"] .a-ord { overflow: hidden; }
  html[data-device="desktop"] .ordf { overflow: auto; }
}
@media (max-width: 900px) {
  .bar { flex-wrap: wrap; }
  .kpis { width: 100%; margin-left: 0; justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ───────── TF manager (row of 5 + custom TFs) ───────── */
.ch1 .tfs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-width: min(52vw, 620px); scrollbar-width: thin; }
.tfs button { min-height: 28px; }
.tfs button.tf-gear { color: var(--accent); }
.tfs button[data-tfsettings] { font-size: 14px; font-weight: 700; }
.pop.tf-manager-pop { width: min(480px, calc(100vw - 20px)); max-height: min(86vh, 760px); overflow-y: auto; }
.tf-mgr-list {
  margin: 8px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-y: auto;
  max-height: min(46vh, 390px);
  background: var(--panel2);
}
.tf-mgr-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto auto;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border-bottom: 1px solid var(--line);
}
.tf-mgr-row:last-child { border-bottom: 0; }
.tf-mgr-row.vis { background: rgba(14,203,129,.06); }
.tf-mgr-name { min-width: 0; display: flex; align-items: baseline; gap: 7px; }
.tf-mgr-name b { color: var(--text); font-size: 13px; white-space: nowrap; }
.tf-mgr-name small { color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tf-mgr-row .btn.sm { min-height: 30px; padding: 4px 8px; }
.tf-mgr-row .tf-toggle.on { border-color: var(--long); color: var(--long); }
.tf-mgr-row .tf-del { color: var(--short); }
.tf-mgr-add { display: grid; grid-template-columns: 72px 82px minmax(0,1fr); gap: 6px; margin-top: 8px; }
.tf-mgr-add input, .tf-mgr-add select { min-width: 0; }
.tf-mgr-add .btn { white-space: nowrap; }
#tf_mgr_info { min-height: 15px; }
@media (max-width: 520px) {
  .pop.tf-manager-pop { width: calc(100vw - 12px); max-height: calc(100vh - 20px); }
  .tf-mgr-list { max-height: 42vh; }
  .tf-mgr-row { grid-template-columns: minmax(0,1fr) auto auto auto; padding: 7px 7px; }
  html[data-device="mobile"] .tf-mgr-row .btn.sm { min-height: 44px !important; min-width: 44px; padding: 4px 7px; }
  .tf-mgr-add { grid-template-columns: 1fr 1fr; }
  html[data-device="mobile"] .tf-mgr-add .btn { grid-column: 1 / -1; min-height: 44px !important; }
  html[data-device="mobile"] .tf-mgr-add input,
  html[data-device="mobile"] .tf-mgr-add select { min-height: 44px; }
  .ch1 .tfs { max-width: 72vw; }
}
html[data-device="tv"] .tf-mgr-row .btn.sm { min-height: 44px; min-width: 44px; font-size: 14px; }
html[data-device="tv"] .tf-mgr-name b { font-size: 16px; }
html[data-device="tv"] .tf-mgr-name small { font-size: 12px; }

.tf-mgr-head {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto auto;
  gap: 6px;
  padding: 0 9px 5px;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
}
.tf-mgr-head .tf-mgr-actions { text-align: right; }

/* ───────── Header actions: Вихід · Адмін · ⚙ settings ───────── */
.bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-wrap: nowrap;
}
.bar-actions .btn { white-space: nowrap; }
.bar-actions details.set {
  padding: 0;
  border: 0;
  background: transparent;
  flex: 0 0 auto;
}
.bar-actions details.set > summary {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
}
.bar-actions details.set:not([open]) > summary {
  color: var(--accent);
  border-color: rgba(77,141,255,.45);
  background: rgba(77,141,255,.10);
}
.bar-actions details.set > summary:hover { border-color: var(--accent); color: var(--accent); background: rgba(77,141,255,.20); }
.bar-actions details.set > summary .gear-ico { font-size: 18px; line-height: 1; }
.bar-actions details.set > summary .set-badge { position: absolute; margin: -18px 0 0 22px; }
.bar-actions details.set:not([open]) .set-close { display: none !important; }
.bar-actions details.set[open] > summary { width: auto; min-width: 36px; padding: 0 10px; }
.bar-actions details.set[open] > summary .gear-ico { display: none; }
html[data-device="mobile"] .bar { position: relative; }
html[data-device="mobile"] .brand { order: -2; flex: 0 1 auto !important; min-height: 36px; padding-left: 2px; white-space: nowrap; }
html[data-device="mobile"] .bar-actions { order: -1; margin-left: auto; gap: 4px; }
html[data-device="mobile"] .bar-actions .btn { min-height: 32px; padding: 3px 7px; font-size: 11px; }
html[data-device="mobile"] .bar #logoutBtn { display: inline-flex !important; }
html[data-device="mobile"] .bar-actions details.set > summary { width: 32px; height: 32px; min-height: 32px; }
html[data-device="mobile"] .bar-actions details.set > summary .gear-ico { font-size: 16px; }

/* ───────── Mobile chart header: pair / TFs+tools / modules sheet ───────── */
html[data-device="mobile"] .a-chart .ch1 {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-areas: "sym sym sym" "tfs tools mod" "ping ping ping";
  align-items: center;
  gap: 5px 6px;
  padding: 6px 8px;
  position: relative;
  z-index: 6;
  overflow: visible !important;
}
html[data-device="mobile"] .a-chart .ch1 #chSym {
  grid-area: sym;
  width: 100%;
  min-width: 0;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
html[data-device="mobile"] .a-chart .ch1 #tfs {
  grid-area: tfs;
  width: 100%;
  max-width: 100% !important;
  overflow-x: auto;
  overflow-y: hidden;
}
html[data-device="mobile"] .a-chart .ch1 #fsBtn {
  grid-area: tools;
  min-width: 44px;
  min-height: 40px;
  padding: 3px 8px;
  font-size: 16px;
}
html[data-device="mobile"] .a-chart .ch1 #lag { display: block; grid-area: ping; margin-left: 0; padding: 2px 0; color: var(--dim); font-size: 10.5px; }
html[data-device="mobile"] .a-chart .ch1 .mob-mod-btn {
  grid-area: mod;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 4px 9px;
  font-size: 11px;
  white-space: nowrap;
}
html[data-device="mobile"] .a-chart .ch1 .mob-mod-btn.on {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(77,141,255,.14);
}
.mob-mod-btn { display: none; }
.mod-dock { display: contents; }
html[data-device="mobile"] .a-chart .ch1 .mod-dock {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 3px);
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 6px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-2);
  max-height: min(52vh, 330px);
  overflow-y: auto;
  z-index: 40;
}
html[data-device="mobile"] .a-chart .ch1 .mod-dock.open { display: grid; }
html[data-device="mobile"] .a-chart .ch1 .mod-dock label {
  min-height: 40px;
  padding: 6px 8px;
  justify-content: flex-start;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
  color: var(--text);
  font-size: 11px;
}
html[data-device="mobile"] .a-chart .ch1 .mod-dock .btn {
  width: 100%;
  min-height: 40px;
  justify-content: flex-start;
  padding: 5px 8px;
  text-align: left;
  font-size: 11px;
}
html[data-device="mobile"] .a-chart .ch1 .mod-dock input[type="checkbox"] {
  width: 15px;
  height: 15px;
  min-height: 0;
}

/* Keep the header gear visible on mobile (legacy rule hid closed settings). */
html[data-device="mobile"] .bar-actions details.set:not([open]) {
  display: block !important;
  visibility: visible !important;
  flex: 0 0 auto;
}
html[data-device="mobile"] .bar-actions details.set:not([open]) > summary {
  display: inline-flex !important;
}
html[data-device="mobile"] .bar-actions details.set:not([open]) .gear-ico {
  display: inline-block !important;
}

/* Drawer must stay opaque even though its trigger lives in the header. */
.bar-actions details.set[open] {
  background: var(--panel) !important;
  border: 1px solid var(--line) !important;
  padding: 0 !important;
  box-shadow: var(--shadow-2);
}
.bar-actions details.set[open] > summary {
  width: 100%;
  min-width: 0;
  height: 45px;
  min-height: 45px;
  padding: 0 14px;
  justify-content: flex-start;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.bar-actions details.set[open] > summary .set-title { display: inline-block; }
.bar-actions details.set:not([open]) > summary .set-title { display: none; }
.bar-actions details.set[open] > summary .set-badge { position: static; margin: 0 0 0 2px; }
.bar-actions details.set[open] > summary .set-close { margin-left: auto; }
.bar-actions details.set[open] > summary .set-close { display: inline-flex !important; }

html[data-device="mobile"] .bar-actions details.set[open] > summary {
  width: 100% !important;
  height: 45px !important;
  min-height: 45px !important;
  padding: 0 12px !important;
}

/* ───────── Mobile: module windows above the tab bar ─────────
   Backtest and module settings use .pop; SmartTrader/pairs use .modal.
   Both must sit above #mnav (z-index 100), keep the close button reachable
   while scrolling, and stop above the tab bar so bottom actions are visible. */
html[data-device="mobile"] .pop {
  left: 8px !important;
  right: 8px !important;
  top: 8px !important;
  bottom: calc(66px + env(safe-area-inset-bottom, 0px)) !important;
  width: auto !important;
  max-height: none !important;
  height: auto !important;
  transform: none !important;
  z-index: 170 !important;
  padding: 0 12px 14px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  border-radius: 12px;
}
html[data-device="mobile"] .pop h4 {
  position: sticky !important;
  top: 0 !important;
  z-index: 20 !important;
  margin: 0 -12px 8px !important;
  padding: 10px 12px !important;
  background: var(--panel) !important;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
html[data-device="mobile"] .pop .al-x {
  min-width: 32px;
  min-height: 32px;
  font-size: 18px;
}
html[data-device="mobile"] .modal {
  z-index: 180 !important;
  align-items: flex-start !important;
  padding: 8px 8px calc(66px + env(safe-area-inset-bottom, 0px)) !important;
  overflow: hidden !important;
}
html[data-device="mobile"] .modal .mbox {
  width: calc(100vw - 12px) !important;
  max-width: none !important;
  max-height: calc(100dvh - 82px - env(safe-area-inset-bottom, 0px)) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-bottom: 14px !important;
}
html[data-device="mobile"] .modal .sthead,
html[data-device="mobile"] .modal .pmctl {
  position: sticky !important;
  top: 0 !important;
  z-index: 12 !important;
  background: var(--panel) !important;
}
html[data-device="mobile"] .modal .sthead {
  margin: 0 -10px 6px !important;
  padding: 8px 10px !important;
  border-bottom: 1px solid var(--line);
}
html[data-device="mobile"] .modal .sthead .btns { flex-wrap: wrap; }
html[data-device="mobile"] .modal .stbody { min-height: 0; }

/* Checkbox fields generated by Backtest used inline flex but inherited the
   .pop label column direction, which centered the box above the label. */
.pop .pf > label[style*="display:flex"],
.pop .pf > label[style*="display: flex"] {
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-start;
  min-height: 32px;
}
.pop .pf > label[style*="justify-content:space-between"] { justify-content: space-between !important; }
.pop .pf > label > input[type="checkbox"] { flex: 0 0 auto; }

/* On a phone, form sections that were built as two inline columns get
   full-width fields. This removes clipped selects and cramped labels in
   Backtest/module popups without touching desktop layout. */
html[data-device="mobile"] .pop div[style*="grid-template-columns:1fr 1fr"],
html[data-device="mobile"] .pop div[style*="grid-template-columns: 1fr 1fr"] {
  grid-template-columns: minmax(0, 1fr) !important;
}

/* ───────── Mobile fullscreen chart ───────── */
/* The active-panel rule uses height:0!important for normal one-screen mode;
   when .fs is set, the chart must become a real fixed full-viewport surface. */
html[data-device="mobile"] .layout > .a-chart.fs {
  display: flex !important;
  position: fixed !important;
  inset: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  min-height: 0 !important;
  max-height: none !important;
  flex: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  z-index: 200 !important;
  flex-direction: column !important;
}
html[data-device="mobile"] .a-chart.fs .fsbar {
  display: flex !important;
  flex: 0 0 auto !important;
  min-height: 48px;
  padding: 5px 8px;
  overflow-x: auto;
  flex-wrap: nowrap;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
html[data-device="mobile"] .a-chart.fs .fsbar > * { flex: 0 0 auto; }
html[data-device="mobile"] .a-chart.fs .ch1 {
  flex: 0 0 auto !important;
  min-height: 0;
}
html[data-device="mobile"] .a-chart.fs .ohlc,
html[data-device="mobile"] .a-chart.fs .chsrow {
  flex: 0 0 auto !important;
}
html[data-device="mobile"] .a-chart.fs .cwrap {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  height: auto !important;
}
html[data-device="mobile"] .a-chart.fs .cwrap canvas {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  display: block !important;
}
html[data-device="mobile"] .a-chart.fs .fsdock { display: none !important; }
body.fs-lock .mnav { display: none !important; }
body.fs-lock .foot { display: none !important; }

/* Mobile fullscreen: the fullscreen bar can scroll horizontally, but Escape
   must never be scrolled off-screen. Keep it pinned to the top-right. */
html[data-device="mobile"] .a-chart.fs .fsbar {
  padding-top: calc(5px + env(safe-area-inset-top, 0px));
  padding-right: 82px;
}
html[data-device="mobile"] .a-chart.fs #fsExit {
  position: fixed !important;
  top: calc(8px + env(safe-area-inset-top, 0px)) !important;
  right: 8px !important;
  z-index: 220 !important;
  min-height: 36px;
  padding: 6px 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-2);
}

html[data-device="mobile"] .a-chart.fs #fsStar,
html[data-device="mobile"] .a-chart.fs #fsFavs { display: none !important; }
html[data-device="mobile"] .a-chart.fs #fsInst { width: 124px !important; }
html[data-device="mobile"] .a-chart.fs #fsPx { margin-left: auto; margin-right: 4px; }

/* Desktop/TV module block — same pattern as mobile, separate panel. */
html[data-device="desktop"] .a-chart .ch1,
html[data-device="tv"] .a-chart .ch1 { position: relative; }
html[data-device="desktop"] .a-chart .ch1 .mob-mod-btn,
html[data-device="tv"] .a-chart .ch1 .mob-mod-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 26px; padding: 2px 8px; font-size: 11px; white-space: nowrap;
}
html[data-device="desktop"] .a-chart .ch1 .mob-mod-btn.on,
html[data-device="tv"] .a-chart .ch1 .mob-mod-btn.on { border-color: var(--accent); color: var(--accent); }
html[data-device="desktop"] .a-chart .ch1 .mod-dock,
html[data-device="tv"] .a-chart .ch1 .mod-dock {
  display: none; position: absolute; right: 0; top: calc(100% + 4px); z-index: 40;
  grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; padding: 9px;
  max-width: min(780px, 92vw); max-height: min(52vh, 360px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-2);
}
html[data-device="tv"] .a-chart .ch1 .mod-dock { grid-template-columns: repeat(5, minmax(0, 1fr)); max-width: min(1100px, 92vw); }
html[data-device="desktop"] .a-chart .ch1 .mod-dock.open,
html[data-device="tv"] .a-chart .ch1 .mod-dock.open { display: grid; }
html[data-device="desktop"] .a-chart .ch1 .mod-dock label,
html[data-device="tv"] .a-chart .ch1 .mod-dock label {
  display: flex; align-items: center; gap: 5px; min-height: 30px; padding: 4px 7px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--panel2);
  color: var(--text); font-size: 11px; white-space: nowrap;
}
html[data-device="desktop"] .a-chart .ch1 .mod-dock .btn,
html[data-device="tv"] .a-chart .ch1 .mod-dock .btn { min-height: 30px; font-size: 11px; }
html[data-device="tv"] .a-chart .ch1 .mod-dock label,
html[data-device="tv"] .a-chart .ch1 .mod-dock .btn { min-height: 40px; font-size: 14px; }
.mod-ping {
  grid-column: 1 / -1; display: flex; align-items: center; min-height: 26px;
  padding: 3px 8px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel2); color: var(--dim); font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

/* iPhone landscape: компактный chart-header, чтобы canvas получил высоту. */
@media (orientation: landscape) and (max-height: 520px) {
  html[data-device="mobile"] .layout { padding-bottom: calc(52px + env(safe-area-inset-bottom, 0px)); }
  html[data-device="mobile"] .a-chart .ch1 {
    grid-template-columns: minmax(0, 180px) minmax(0, 1fr) auto auto;
    grid-template-areas: "sym tfs tools mod" "ping ping ping";
    gap: 3px 5px;
    padding: 4px 8px;
  }
  html[data-device="mobile"] .a-chart .ch1 #chSym { font-size: 12px; }
  html[data-device="mobile"] .a-chart .ch1 #fsBtn,
  html[data-device="mobile"] .a-chart .ch1 .mob-mod-btn { min-height: 32px; font-size: 14px; padding: 2px 8px; }
  html[data-device="mobile"] .a-chart .ch1 #lag { font-size: 9px; padding: 0; }
  html[data-device="mobile"] .a-chart .chsrow { padding: 3px 6px 4px; gap: 4px; }
  html[data-device="mobile"] .a-chart .chs-end { font-size: 10.5px; padding: 3px 7px; }
}

/* Landscape: отдать высоту canvas — header одной строкой, вторичные строки скрыты. */
@media (orientation: landscape) and (max-height: 520px) {
  html[data-device="mobile"] .a-chart .ch1 {
    grid-template-columns: minmax(0, 200px) minmax(0, 1fr) auto auto;
    grid-template-areas: "sym tfs tools mod";
  }
  html[data-device="mobile"] .a-chart .ch1 #lag { display: none; }
  html[data-device="mobile"] .a-chart .ohlc { display: none; }
  html[data-device="mobile"] .a-chart .chsrow { padding: 2px 6px 3px; }
}

/* Landscape: компактное нижнее меню, чтобы вернуть высоту графику. */
@media (orientation: landscape) and (max-height: 520px) {
  html[data-device="mobile"] .mnav {
    min-height: calc(40px + env(safe-area-inset-bottom, 0px));
    padding: 2px 4px env(safe-area-inset-bottom, 0px);
  }
  html[data-device="mobile"] .mnav button {
    min-height: 34px;
    gap: 0;
    font-size: 7.2px;
  }
  html[data-device="mobile"] .mnav button b { font-size: 13px; }
  html[data-device="mobile"] .layout {
    padding-bottom: calc(42px + env(safe-area-inset-bottom, 0px));
  }
}

/* Landscape: вернуть OHLC и Ping, оставив компактное меню. */
@media (orientation: landscape) and (max-height: 520px) {
  html[data-device="mobile"] .a-chart .ch1 {
    grid-template-columns: minmax(0, 200px) minmax(0, 1fr) auto auto;
    grid-template-areas: "sym tfs tools mod" "ping ping ping";
    gap: 2px 5px;
    padding: 3px 8px;
  }
  html[data-device="mobile"] .a-chart .ch1 #lag {
    display: block;
    grid-area: ping;
    font-size: 9px;
    padding: 0;
  }
  html[data-device="mobile"] .a-chart .ohlc {
    display: flex;
    font-size: 9.5px;
    padding: 1px 6px;
    gap: 2px 7px;
  }
}

/* Landscape: скролл меню модулей и pop-модалок (Depth/VP/HM). */
@media (orientation: landscape) and (max-height: 520px) {
  html[data-device="mobile"] .a-chart .ch1 .mod-dock {
    max-height: calc(100dvh - 236px - env(safe-area-inset-bottom, 0px)) !important;
    overflow-y: auto !important;
  }
  html[data-device="mobile"] .pop {
    top: 4px !important;
    bottom: calc(46px + env(safe-area-inset-bottom, 0px)) !important;
    max-height: none !important;
  }
  html[data-device="mobile"] .modal {
    padding-top: 4px !important;
    padding-bottom: calc(46px + env(safe-area-inset-bottom, 0px)) !important;
  }
  html[data-device="mobile"] .modal .mbox {
    max-height: calc(100dvh - 58px - env(safe-area-inset-bottom, 0px)) !important;
  }
}
html[data-device="mobile"] .pop,
html[data-device="mobile"] .modal .mbox,
html[data-device="mobile"] .a-chart .ch1 .mod-dock {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

/* Mobile inputs: 16px отключает iOS Safari auto-zoom при фокусе. */
@media (max-width: 900px) {
  html[data-device="mobile"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  html[data-device="mobile"] select,
  html[data-device="mobile"] textarea {
    font-size: 16px !important;
  }
  html[data-device="mobile"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  html[data-device="mobile"] select {
    min-height: 42px;
  }
}

/* All narrow screens (login/admin/index): no iOS input autozoom. */
@media (max-width: 900px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
  select,
  textarea {
    font-size: 16px !important;
  }
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select {
    min-height: 42px !important;
  }
}

/* Mobile: вернуть кнопку «Пари» в строку инструмента. */
@media (max-width: 900px) {
  html[data-device="mobile"] .ctl:has(#pairsBtn) {
    width: 100% !important;
    max-width: 100% !important;
    flex: 1 1 100%;
    gap: 6px;
  }
  html[data-device="mobile"] .ctl:has(#pairsBtn) #instId {
    width: auto !important;
    max-width: none !important;
    flex: 1 1 0;
    min-width: 0;
  }
  html[data-device="mobile"] #pairsBtn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    min-height: 38px;
    padding: 4px 8px;
    font-size: 11px;
    white-space: nowrap;
  }
}

/* Mobile Pairs modal: fit filters and make wide table scrollable. */
@media (max-width: 900px) {
  html[data-device="mobile"] .modal .mbox.pm {
    width: calc(100vw - 8px) !important;
    max-width: calc(100vw - 8px) !important;
    padding: 8px 6px 6px !important;
  }
  html[data-device="mobile"] .pm .sthead h3 { font-size: 14px; line-height: 1.25; }
  html[data-device="mobile"] .pm .sthead .btns { flex-wrap: wrap; gap: 4px; }
  html[data-device="mobile"] .pmctl {
    display: grid !important;
    grid-template-columns: minmax(0,1fr) minmax(0,1fr);
    gap: 6px !important;
  }
  html[data-device="mobile"] .pmctl #pmQ { grid-column: 1 / -1; width: 100%; }
  html[data-device="mobile"] .pmctl select { width: 100%; min-width: 0; }
  html[data-device="mobile"] .pmctl label.chk {
    grid-column: 1 / -1;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 7px;
    min-height: 32px;
    margin: 0;
    color: var(--text);
  }
  html[data-device="mobile"] .pmctl label.chk input {
    width: 20px !important;
    height: 20px !important;
    min-height: 20px !important;
    margin: 0;
    flex: 0 0 auto;
  }
  html[data-device="mobile"] #pmBody {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }
  html[data-device="mobile"] #pmBody .tbl {
    min-width: 560px;
    font-size: 10.5px;
  }
  html[data-device="mobile"] #pmBody .tbl th,
  html[data-device="mobile"] #pmBody .tbl td { padding: 4px 5px; }
}

/* Mobile Pairs: inline "Лише обрані" checkbox. */
@media (max-width: 900px) {
  html[data-device="mobile"] .pmctl label.chk {
    justify-content: flex-start !important;
    align-content: center;
    flex-wrap: nowrap !important;
    gap: 8px !important;
    width: 100% !important;
  }
  html[data-device="mobile"] .pmctl label.chk input[type="checkbox"] {
    position: static !important;
    margin: 0 !important;
    flex: 0 0 20px !important;
  }
}

/* Mobile Pairs: checkbox must not inherit .pmctl input min-width:150. */
@media (max-width: 900px) {
  html[data-device="mobile"] .pmctl label.chk input[type="checkbox"] {
    width: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
    height: 20px !important;
    flex: 0 0 20px !important;
  }
}

/* Mobile Pairs: все 5 колонок вписываются в экран без horizontal scroll. */
@media (max-width: 900px) {
  html[data-device="mobile"] #pmBody {
    overflow-x: hidden !important;
  }
  html[data-device="mobile"] #pmBody .tbl {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: fixed;
    font-size: 9.5px;
  }
  html[data-device="mobile"] #pmBody .tbl th,
  html[data-device="mobile"] #pmBody .tbl td {
    padding: 4px 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  html[data-device="mobile"] #pmBody .tbl th { font-size: 8.5px; line-height: 1.15; white-space: normal; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(1),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(1) { width: 45%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(2),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(2) { width: 18%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(3),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(3) { width: 15%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(4),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(4) { width: 13%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(5),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(5) { width: 9%; }
  html[data-device="mobile"] #pmBody .tbl td:first-child .hint { display: none; }
  html[data-device="mobile"] #pmBody .star {
    width: 18px !important;
    min-width: 18px !important;
    padding: 0 !important;
    font-size: 13px !important;
  }
  html[data-device="mobile"] #pmBody .atAdd {
    width: 20px !important;
    min-width: 20px !important;
    margin-left: 2px !important;
    padding: 0 !important;
    font-size: 13px !important;
  }
}

/* Mobile Pairs: короткие заголовки и баланс колонок. */
@media (max-width: 900px) {
  html[data-device="mobile"] #pmBody .tbl th:nth-child(1),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(1) { width: 42%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(2),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(2) { width: 19%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(3),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(3) { width: 14%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(4),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(4) { width: 15%; }
  html[data-device="mobile"] #pmBody .tbl th:nth-child(5),
  html[data-device="mobile"] #pmBody .tbl td:nth-child(5) { width: 10%; }
}

/* ══════════════════════════════════════════════════════════════════════════
   PC / TV redesign: order book + chart info strip
   ══════════════════════════════════════════════════════════════════════════ */
.layout { grid-template-columns: 316px minmax(0, 1fr) 390px; }

/* ── Order book: header, imbalance, best prices, mid card ── */
.a-lad { min-width: 0; }
.a-lad .scroll { padding: 0 6px 8px; }
.a-lad .lad { font-size: 12px; line-height: 1.15; }
.lad-head {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 58px;
  align-items: center;
  height: 22px;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .45px;
  text-transform: uppercase;
}
.lad-head span:nth-child(1) { text-align: right; padding-right: 8px; }
.lad-head span:nth-child(2) { padding-left: 8px; }
.lad-head span:nth-child(3) { text-align: right; padding-right: 7px; }
.lad-imb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  padding: 4px 4px 5px;
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: .2px;
}
.lad-imb .lb { color: var(--long); }
.lad-imb .la { color: var(--short); }
.lad-imb .lbar {
  flex: 1;
  height: 5px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--short-soft);
  box-shadow: inset 0 0 0 1px var(--line);
}
.lad-imb .lbar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--long), rgba(14,203,129,.55));
}
.r {
  height: 22px;
  border-radius: 4px;
  border-bottom: 1px solid rgba(128,145,165,.07);
}
.r:hover { background: var(--panel2); }
.r .p { font-size: 12px; font-weight: 700; }
.r .s { padding-left: 8px; }
.r .c { font-size: 10.5px; }
.r.best .p { text-decoration: underline; text-decoration-color: var(--focus); text-underline-offset: 3px; }
.r.best.ask .p { color: var(--short); }
.r.best.bid .p { color: var(--long); }
.r.wall .s { box-shadow: inset 3px 0 0 currentColor; }
.tw { font-size: 8px; padding: 1px 4px; max-width: 92px; overflow: hidden; text-overflow: ellipsis; }
.mid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 7px 2px 6px;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(100deg, var(--panel2), var(--panel3));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.mid .msp, .mid .mpx { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.mid .mpx { align-items: flex-end; }
.mid small {
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .55px;
  text-transform: uppercase;
}
.mid b { font-size: 14px; line-height: 1.2; white-space: nowrap; }

/* ── Chart info strip (OHLC) ── */
.ohlc {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0;
  min-height: 38px;
  padding: 0 6px 0 10px;
  background: linear-gradient(180deg, var(--panel2), var(--panel));
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.ohlc::-webkit-scrollbar { display: none; }
.ohlc > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  min-height: 22px;
  padding: 0 10px;
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
.ohlc > span:first-child { padding-left: 0; color: var(--dim); font-weight: 600; }
.ohlc > span:last-child { border-right: 0; }
.ohlc b { color: var(--text); font-weight: 700; }
.ohlc .l { color: var(--long); }
.ohlc .s { color: var(--short); }
.ohlc b.l { color: var(--long); }
.ohlc b.s { color: var(--short); }
.ch1 { background: linear-gradient(180deg, var(--panel2), var(--panel)); }

/* ── TV: larger book + readable chart info ── */
html[data-device="tv"] .layout { grid-template-columns: 430px minmax(0, 1fr); }
html[data-device="tv"] .a-lad .scroll { padding: 0 9px 10px; }
html[data-device="tv"] .a-lad .lad { font-size: 14.5px; }
html[data-device="tv"] .lad-head {
  grid-template-columns: 94px minmax(0, 1fr) 76px;
  height: 30px;
  font-size: 11px;
}
html[data-device="tv"] .lad-head span:nth-child(1) { padding-right: 10px; }
html[data-device="tv"] .lad-head span:nth-child(2) { padding-left: 10px; }
html[data-device="tv"] .lad-head span:nth-child(3) { padding-right: 9px; }
html[data-device="tv"] .lad-imb { min-height: 32px; font-size: 12px; gap: 12px; }
html[data-device="tv"] .lad-imb .lbar { height: 7px; }
html[data-device="tv"] .r { height: 28px; grid-template-columns: 94px minmax(0, 1fr) 76px; }
html[data-device="tv"] .r .p { font-size: 15px; }
html[data-device="tv"] .r .s { font-size: 14px; padding-left: 10px; }
html[data-device="tv"] .r .c { font-size: 12.5px; }
html[data-device="tv"] .tw { font-size: 10px; max-width: 116px; }
html[data-device="tv"] .mid { padding: 11px 14px; margin: 10px 3px; }
html[data-device="tv"] .mid small { font-size: 11px; }
html[data-device="tv"] .mid b { font-size: 19px; }
html[data-device="tv"] .ohlc {
  min-height: 54px;
  padding: 0 10px 0 16px;
  font-size: 16px;
}
html[data-device="tv"] .ohlc > span { min-height: 32px; padding: 0 15px; }
html[data-device="tv"] .ohlc b { font-size: 17px; }

/* ── Mobile: не добавляем новую шапку/imb в узкую панель ── */
html[data-device="mobile"] .lad-head,
html[data-device="mobile"] .lad-imb { display: none; }
html[data-device="mobile"] .mid { padding: 6px 9px; }
html[data-device="mobile"] .ohlc > span { padding: 0 8px; }

/* AutoTrader mode badge: DL / DO / RO сразу справа от ON/OFF */
.at-mode {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  flex: 0 0 24px;
  border-radius: 5px;
  border: 1px solid var(--line-soft);
  background: var(--panel3);
  color: var(--dim);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .2px;
  line-height: 1;
  user-select: none;
}
.at-mode.paper { background: var(--panel3); color: var(--dim); border-color: var(--line-soft); }
.at-mode.demo { background: rgba(245,184,61,.16); color: var(--accent); border-color: rgba(245,184,61,.45); }
.at-mode.live { background: var(--short-soft); color: var(--short); border-color: rgba(246,70,93,.45); }
.at-mode-mismatch { color: var(--accent); font-size: 13px; line-height: 1; cursor: help; }
html[data-device="tv"] .at-mode { width: 30px; height: 27px; flex-basis: 30px; font-size: 11px; }


/* ── Mobile compact header + touch targets (visual audit P2) ───────────── */
html[data-device="mobile"] .bar {
  flex-wrap: nowrap !important;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 6px;
  padding: 4px 6px;
  max-height: 104px;
  scrollbar-width: none;
}
html[data-device="mobile"] .bar::-webkit-scrollbar { display: none; }
html[data-device="mobile"] .bar .brand { flex: 0 0 auto !important; min-height: 34px; }
html[data-device="mobile"] .bar .brand span { display: none; }
html[data-device="mobile"] .bar .ctl { flex: 0 0 auto; flex-wrap: nowrap; }
html[data-device="mobile"] .bar .ctl label { display: none; }
html[data-device="mobile"] .bar #instId { width: 112px; }
html[data-device="mobile"] .bar #exchangeSelect { max-width: 92px; }
html[data-device="mobile"] .bar #mode { max-width: 132px; }
html[data-device="mobile"] .bar #themeSelect,
html[data-device="mobile"] .bar #deviceSelect { max-width: 96px; }
html[data-device="mobile"] .bar #monSt { display: none !important; }
html[data-device="mobile"] .bar .kpis { display: none !important; }
html[data-device="mobile"] .bar .btn,
html[data-device="mobile"] .bar select,
html[data-device="mobile"] .bar input { min-height: 38px; }
html[data-device="mobile"] .set-close,
html[data-device="mobile"] .bar-actions details.set > summary {
  min-width: 40px; min-height: 40px;
}
html[data-device="mobile"] details.set > summary { min-height: 40px; }
html[data-device="mobile"] .btn.sm { min-height: 38px; }

/* мобильный select не должен молча обрезать текст без ellipsis */
html[data-device="mobile"] select { text-overflow: ellipsis; }

/* Touch targets: 44px на mobile (visual audit P2) */
html[data-device="mobile"] .bar .btn,
html[data-device="mobile"] .bar select,
html[data-device="mobile"] .bar input,
html[data-device="mobile"] .btn.sm,
html[data-device="mobile"] .set-toolbar .btn,
html[data-device="mobile"] .set-tabs button,
html[data-device="mobile"] details.set > summary {
  min-height: 44px;
}
html[data-device="mobile"] .bar { max-height: 120px; }

/* Checkbox/radio не должны раздуваться из-за coarse min-height */
@media (pointer: coarse) {
  .mbox input[type="checkbox"],
  .mbox input[type="radio"],
  .pop input[type="checkbox"],
  .pop input[type="radio"],
  details.set input[type="checkbox"],
  details.set input[type="radio"] {
    min-height: auto !important;
    height: auto;
    width: auto;
    flex: 0 0 auto;
  }
}

/* Disabled CTA визуально отличается от активной */
.btn:disabled,
.btn[disabled] {
  opacity: .45 !important;
  cursor: not-allowed !important;
  filter: grayscale(.25);
  box-shadow: none !important;
}

/* Итоговые touch-таргеты: 44px и min-width 40px для мелких контролов. */
html[data-device="mobile"] #pairsBtn,
html[data-device="mobile"] .bar .btn,
html[data-device="mobile"] .bar select,
html[data-device="mobile"] .bar input,
html[data-device="mobile"] .btn.sm,
html[data-device="mobile"] .tfs button,
html[data-device="mobile"] .set-toolbar .btn,
html[data-device="mobile"] .set-toolbar select,
html[data-device="mobile"] .set-tabs button,
html[data-device="mobile"] #fsBtn {
  min-height: 44px !important;
  min-width: 44px;
}


/* ── Visual audit round 2: common controls ───────────────────────────── */
.al-x {
  min-width: 30px !important;
  min-height: 30px !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 !important;
}
.modal .btn.sm, #pop .btn.sm { min-height: 32px; }
#setPanel .set-close { min-width: 32px !important; min-height: 32px !important; }

/* Checkboxes/radios не должны растягиваться на всю ширину в модалках */
.modal input[type="checkbox"], .modal input[type="radio"],
#pop input[type="checkbox"], #pop input[type="radio"],
details.set input[type="checkbox"], details.set input[type="radio"],
.stbody input[type="checkbox"], .stbody input[type="radio"] {
  width: 18px !important;
  min-width: 18px !important;
  height: 18px !important;
  min-height: 18px !important;
  flex: 0 0 auto !important;
  padding: 0 !important;
  margin: 0 4px 0 0;
}

/* Mobile journal: controls grid + scrollable table, важные колонки. */
html[data-device="mobile"] .j-toolbar {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-items: stretch;
}
html[data-device="mobile"] .j-toolbar #jSearch {
  grid-column: 1 / -1;
  width: 100% !important;
  min-width: 0;
  min-height: 42px;
}
html[data-device="mobile"] .j-toolbar select,
html[data-device="mobile"] .j-toolbar .btn {
  width: 100% !important;
  min-height: 42px;
}
html[data-device="mobile"] .j-body {
  overflow: auto !important;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}
html[data-device="mobile"] .j-body .tbl { width: 100%; min-width: 0; font-size: 11px; }
html[data-device="mobile"] .j-body .tbl th,
html[data-device="mobile"] .j-body .tbl td { padding: 5px 4px; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(6),
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(7),
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(9),
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(10),
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(11) { display: none; }

/* Pairs modal touch targets */
html[data-device="mobile"] .pm .star { min-width: 32px; min-height: 32px; }
html[data-device="mobile"] .pm .atAdd { min-width: 30px; min-height: 30px; }
html[data-device="mobile"] .pmctl input, html[data-device="mobile"] .pmctl select { min-height: 40px; }
html[data-device="mobile"] .pmctl .chk { min-height: 40px; align-items: center; }

/* Desktop settings toolbar: чуть крупнее компактные кнопки */
#setPanel .btn.sm, #setPanel .set-tabs button { min-height: 30px; }

/* Pairs: перебиваем старые !important-размеры звезды/плюса на mobile */
html[data-device="mobile"] #pmBody .star {
  width: 32px !important; min-width: 32px !important; height: 32px !important; padding: 0 !important;
}
html[data-device="mobile"] #pmBody .atAdd {
  width: 32px !important; min-width: 32px !important; height: 32px !important; padding: 0 !important;
}

/* Journal mobile: фиксированная сетка, важные колонки помещаются */
html[data-device="mobile"] .j-body .tbl {
  table-layout: fixed !important;
  width: 100% !important;
}
html[data-device="mobile"] .j-body .tbl th,
html[data-device="mobile"] .j-body .tbl td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(1) { width: 17%; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(2) { width: 22%; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(3) { width: 9%; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(4) { width: 18%; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(5) { width: 11%; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(8) { width: 13%; }
html[data-device="mobile"] .j-body .tbl tr > *:nth-child(12) { width: 10%; }


/* Mobile journal: карточки вместо сжатой таблицы */
html[data-device="mobile"] .j-body { overflow: visible !important; max-height: none !important; }
html[data-device="mobile"] .j-body table,
html[data-device="mobile"] .j-body thead,
html[data-device="mobile"] .j-body tbody,
html[data-device="mobile"] .j-body tr,
html[data-device="mobile"] .j-body td { display: block; width: 100%; }
html[data-device="mobile"] .j-body thead { display: none; }
html[data-device="mobile"] .j-body tbody { display: block; }
html[data-device="mobile"] .j-body tr {
  display: block;
  margin: 0 0 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel2);
}
html[data-device="mobile"] .j-body td,
html[data-device="mobile"] .j-body .tbl tr > * {
  display: flex !important;
  align-items: baseline;
  gap: 8px;
  width: auto !important;
  padding: 3px 2px !important;
  border: 0 !important;
  white-space: normal !important;
  overflow: visible !important;
  text-overflow: clip !important;
  font-size: 11.5px;
}
html[data-device="mobile"] .j-body td::before {
  content: attr(data-label);
  flex: 0 0 78px;
  color: var(--dim);
  font-size: 10px;
  text-transform: none;
}
html[data-device="mobile"] .j-body td[data-label=""]::before { display: none; }
html[data-device="mobile"] .j-body td.j-del { justify-content: flex-end; }
html[data-device="mobile"] .j-body td.j-note-cell, html[data-device="mobile"] .j-body td:has(.j-note) { display: block !important; }
html[data-device="mobile"] .j-body .j-note { width: 100% !important; min-width: 0; margin-top: 2px; }
html[data-device="mobile"] .j-body td.j-tags { cursor: pointer; }

/* Mobile modal close buttons — удобный touch */
html[data-device="mobile"] .al-x { min-width: 40px !important; min-height: 40px !important; }


/* Mobile header priority: сначала Brand → Біржа → Режим → Підключити/акаунт.
   Менш важливі theme/device/instrument — далі по горизонтальному скролу. */
html[data-device="mobile"] .bar .brand { order: -20 !important; max-width: 82px; overflow: hidden; }
html[data-device="mobile"] .bar .brand strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
html[data-device="mobile"] .bar #exchangeCtl { order: -19 !important; }
html[data-device="mobile"] .bar > .ctl:has(#mode) { order: -18 !important; }
html[data-device="mobile"] .bar > #btn { order: -17 !important; }
html[data-device="mobile"] .bar-actions { order: -16 !important; }
html[data-device="mobile"] .bar > .ctl:has(#instId) { order: -15 !important; }
html[data-device="mobile"] .bar > .ctl:has(#themeSelect),
html[data-device="mobile"] .bar > .ctl:has(#deviceSelect) { order: 10 !important; }
html[data-device="mobile"] .bar #logoutBtn { order: 20 !important; }
html[data-device="mobile"] #exchangeSt, html[data-device="mobile"] #acctSt {
  max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Tablet/touch header (iPad 768-1100): приоритет биржи/режиму, всё в одной прокручиваемой строке */
@media (max-width: 1100px) {
  .bar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    align-items: center;
    padding: 4px 6px;
    gap: 6px;
    max-height: 108px;
    scrollbar-width: none;
  }
  .bar::-webkit-scrollbar { display: none; }
  .bar .brand { order: -20 !important; flex: 0 0 auto !important; max-width: 96px; overflow: hidden; }
  .bar .brand strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar #exchangeCtl { order: -19 !important; flex: 0 0 auto !important; }
  .bar > .ctl:has(#mode) { order: -18 !important; flex: 0 0 auto !important; }
  .bar > #btn { order: -17 !important; flex: 0 0 auto !important; }
  .bar-actions { order: -16 !important; flex: 0 0 auto !important; margin-left: 0 !important; }
  .bar > .ctl:has(#instId) { order: -15 !important; flex: 0 0 auto !important; }
  .bar > .ctl:has(#themeSelect),
  .bar > .ctl:has(#deviceSelect) { order: 10 !important; flex: 0 0 auto !important; }
  .bar #logoutBtn { order: 20 !important; flex: 0 0 auto !important; }
  .bar #monSt { display: none !important; }
  .bar #exchangeSt, .bar #acctSt { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar .ctl label { display: none; }
  .bar #instId { width: 118px; }
  .bar select { max-width: 140px; }
}

/* Mobile: exchange + mode должны быть в первом экране */
html[data-device="mobile"] #exchangeSt { display: none !important; }
@media (max-width: 360px) {
  html[data-device="mobile"] .bar .brand { display: none !important; }
}

/* Mobile header v2: две строки, все ключевые действия доступны без скрытого скролла */
html[data-device="mobile"] .bar {
  flex-wrap: wrap !important;
  overflow: visible !important;
  max-height: none !important;
  height: auto;
  align-items: center;
  padding: 4px 6px;
  gap: 4px 6px;
}
html[data-device="mobile"] .bar .brand { display: none !important; }
html[data-device="mobile"] .bar #exchangeCtl { order: 0 !important; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar-actions { order: 1 !important; margin-left: auto !important; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar-actions .acc-chip { max-width: 168px; }
html[data-device="mobile"] .bar > .ctl:has(#mode) { order: 2 !important; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar > #btn { order: 3 !important; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar > .ctl:has(#instId) { order: 4 !important; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar #st,
html[data-device="mobile"] .bar #monSt,
html[data-device="mobile"] .bar #logoutBtn,
html[data-device="mobile"] .bar > .ctl:has(#themeSelect),
html[data-device="mobile"] .bar > .ctl:has(#deviceSelect) { display: none !important; }
html[data-device="mobile"] .bar #instId { display: none !important; }
html[data-device="mobile"] .bar #pairsBtn { display: inline-flex !important; min-height: 42px; }
html[data-device="mobile"] .bar-actions details.set > summary { min-width: 40px; min-height: 40px; }

/* OHLC: не обрезаем справа, переносим значения */
html[data-device="mobile"] .ohlc {
  flex-wrap: wrap !important;
  white-space: normal !important;
  overflow: visible !important;
  height: auto !important;
  row-gap: 2px;
  line-height: 1.45;
}

/* Mobile header v3: строгий grid 2 строки */
html[data-device="mobile"] .bar {
  display: grid !important;
  grid-template-columns: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "exch exch exch actions"
    "mode btn inst inst";
  align-items: center;
  gap: 4px 6px;
  padding: 4px 6px;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  flex-wrap: nowrap !important;
}
html[data-device="mobile"] .bar #exchangeCtl { grid-area: exch; justify-self: start; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar-actions { grid-area: actions; justify-self: end; flex: 0 0 auto !important; margin: 0 !important; }
html[data-device="mobile"] .bar-actions .acc-chip { max-width: 150px; overflow: hidden; }
html[data-device="mobile"] .bar > .ctl:has(#mode) { grid-area: mode; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar > #btn { grid-area: btn; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar > .ctl:has(#instId) { grid-area: inst; justify-self: start; flex: 0 0 auto !important; }
html[data-device="mobile"] .bar #mode { max-width: 148px; }
html[data-device="mobile"] .bar #pairsBtn { display: inline-flex !important; min-height: 42px; }
html[data-device="mobile"] .bar .set-badge { display: none; }

/* Mobile header v3.1: компактный аккаунт-аватар, без статус-плашек в header */
html[data-device="mobile"] .bar .acc-chip {
  max-width: 40px !important;
  min-width: 40px;
  width: 40px;
  padding: 2px;
  justify-content: center;
}
html[data-device="mobile"] .bar .acc-chip-txt { display: none !important; }
html[data-device="mobile"] .bar .acct-badge,
html[data-device="mobile"] .bar #acctSt { display: none !important; }
html[data-device="mobile"] .bar > .ctl:has(#mode) { max-width: 152px; overflow: hidden; }
html[data-device="mobile"] .bar #mode { width: 148px; max-width: 148px; }

/* Tablet settings: toolbar не обрезает Скинути/експорт */
@media (max-width: 1100px) {
  details.set[open] .set-toolbar { flex-wrap: wrap !important; row-gap: 6px; }
  details.set[open] .set-toolbar input[type="search"],
  details.set[open] .set-toolbar input[type="text"] { flex: 1 1 100% !important; min-width: 0 !important; width: 100%; }
  details.set[open] .set-toolbar select { flex: 1 1 calc(50% - 4px) !important; min-width: 0 !important; max-width: none; }
  details.set[open] .set-toolbar .btn { flex: 0 0 auto; min-height: 38px; }
}

/* Journal mobile: видимая нота и нормальная кнопка удаления */
html[data-device="mobile"] .j-body .j-note {
  background: var(--panel2) !important;
  border: 1px solid var(--line) !important;
  border-radius: 6px;
  min-height: 40px;
  padding: 8px 10px !important;
  color: var(--text) !important;
  font-size: 13px !important;
}
html[data-device="mobile"] .j-body .j-note::placeholder { color: var(--dim); opacity: .85; }
html[data-device="mobile"] .j-body td:has(.j-note) { padding-top: 4px; }
html[data-device="mobile"] .j-body .j-del .btn { min-width: 44px !important; min-height: 40px !important; }

/* Модалки: нижний safe-area, чтобы кнопки Risk/AT не липли к краю */
html[data-device="mobile"] #pop {
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  overscroll-behavior: contain;
}

/* Pairs: вся площадь star — touch target */
html[data-device="mobile"] #pmBody .star {
  min-width: 32px !important; min-height: 32px !important;
  display: inline-flex !important; align-items: center; justify-content: center;
}
@media (max-width: 1100px) {
  #pmBody .star {
    min-width: 30px !important; min-height: 30px !important;
    display: inline-flex !important; align-items: center; justify-content: center;
  }
}

/* Journal: заметная нота */
html[data-device="mobile"] .j-body .j-note {
  background: var(--panel3) !important;
  border-color: var(--line-soft) !important;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.02);
}

/* Tablet: компактные модалки по центру вместо пустого fullscreen */
@media (min-width: 700px) and (max-width: 1100px) {
  html[data-device="mobile"] .pop {
    top: 40px !important;
    bottom: auto !important;
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: min(720px, calc(100vw - 48px)) !important;
    max-height: calc(100dvh - 80px) !important;
    height: auto !important;
    overflow-y: auto !important;
    padding-bottom: 14px !important;
  }
  html[data-device="mobile"] .modal.on {
    align-items: flex-start !important;
    padding: 32px 16px !important;
    overflow-y: auto !important;
  }
  html[data-device="mobile"] .modal.on .mbox {
    width: min(760px, calc(100vw - 48px)) !important;
    max-width: 760px !important;
    max-height: calc(100dvh - 64px) !important;
    height: auto !important;
    overflow-y: auto !important;
    border-radius: 12px !important;
  }
}


/* OHLC: переносим значения, не обрезаем */
.ohlc { flex-wrap: wrap !important; white-space: normal !important; overflow: visible !important; height: auto !important; row-gap: 2px; line-height: 1.45; }

/* Pairs: удобная площадь star/+ на ПК */
.pm .star { min-width: 26px !important; min-height: 26px !important; display: inline-flex !important; align-items: center; justify-content: center; font-size: 15px; }
.pm .atAdd { min-width: 26px !important; min-height: 26px !important; display: inline-flex !important; align-items: center; justify-content: center; }

/* Mobile theme control in settings */
.set-interface { padding-top: 8px; }
.set-interface label { display: flex; flex-direction: column; gap: 5px; color: var(--dim); font-size: 11px; margin-top: 4px; }
.set-interface select { min-height: 42px; width: 100%; max-width: 260px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 0 10px; }
@media (min-width: 1101px) { #mobileThemeRow { display: none !important; } }

#mobileThemeRow { display: block !important; }
#mobileThemeRow.set-cat { border-bottom: 1px solid var(--line); padding: 8px 0 10px; }


/* ── Settings dialog v2: centered on desktop/tablet/TV/mobile ──────────────
   Old style was a right-side drawer with an absolutely positioned content
   viewport. It clipped long forms and left the window off-center. */
details.set[open] {
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  width: min(960px, calc(100vw - 32px)) !important;
  max-height: min(90vh, 900px) !important;
  height: auto !important;
  transform: translate(-50%, -50%) !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  animation: settingsIn .16s ease-out !important;
}
@keyframes settingsIn { from { opacity: 0; } to { opacity: 1; } }
details.set[open] > summary { flex: 0 0 auto !important; }
details.set[open] > .set-content {
  position: relative !important;
  inset: auto !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}
details.set[open] > .set-content > .set-toolbar,
details.set[open] > .set-content > .set-tabs,
details.set[open] > .set-content > .exchange-drawer-row { flex: 0 0 auto !important; }
details.set[open] > .set-content > .set-body-wrap {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow: hidden !important;
  display: flex !important;
}
details.set[open] > .set-content > .set-body-wrap > .set-body {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding: 8px 14px 18px !important;
}
#setPanel .exchange-drawer-row { padding: 4px 12px 0 !important; }

/* Mobile: full-height sheet inside 8px safe margins, still centered. */
html[data-device="mobile"] details.set[open] {
  top: 8px !important;
  left: 8px !important;
  right: 8px !important;
  bottom: 8px !important;
  width: auto !important;
  max-height: none !important;
  transform: none !important;
}

/* TV: settings must be reachable (previously display:none). */
html[data-device="tv"] details.set { display: block !important; }
html[data-device="tv"] details.set[open] {
  width: min(1240px, 92vw) !important;
  max-height: 88vh !important;
}
html[data-device="tv"] details.set[open] .set-body { font-size: 14px !important; }

/* Tablet / narrow desktop: never exceed viewport and always leave margins. */
@media (max-width: 1024px) {
  details.set[open] { width: min(96vw, 960px) !important; max-height: 92vh !important; }
}

/* Settings v2.1: constrain height so .set-body really scrolls on every device. */
details.set[open] {
  height: min(90vh, 900px) !important;
  max-height: min(90vh, 900px) !important;
}
@media (max-width: 1024px) {
  details.set[open] { height: 92vh !important; max-height: 92vh !important; }
}
html[data-device="mobile"] details.set[open] {
  height: calc(100dvh - 16px) !important;
  max-height: calc(100dvh - 16px) !important;
  top: 8px !important;
  bottom: auto !important;
}
html[data-device="tv"] details.set { display: block !important; }
html[data-device="tv"] details.set[open] {
  display: flex !important;
  flex-direction: column !important;
  height: 88vh !important;
  max-height: 88vh !important;
}

/* Settings v2.2: <details> has UA content wrapper, so flex-height is unreliable.
   Keep a fixed centered dialog and absolutely position the content viewport. */
details.set[open] {
  display: block !important;
  flex-direction: initial !important;
}
details.set[open] > .set-content {
  position: absolute !important;
  top: 45px !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  flex: none !important;
  min-height: 0 !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

/* Settings v2.3: exact mobile centering + TV block layout override. */
html[data-device="mobile"] details.set[open] {
  top: 50% !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  width: calc(100vw - 16px) !important;
  height: calc(100dvh - 16px) !important;
  max-height: calc(100dvh - 16px) !important;
  transform: translate(-50%, -50%) !important;
}
html[data-device="tv"] details.set[open] { display: block !important; }

/* Settings v2.4: action rows/hints must span the whole form grid. */
.set-cat .btns,
.set-cat #notifyPermState {
  grid-column: 1 / -1;
  width: 100%;
}
.set-cat .btns {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  align-items: center;
}
.set-cat .btns .btn { flex: 0 1 auto; }

/* ── Mobile v2: explicit version switch + AutoTrader tab ─────────────── */
.mobile-device-row{display:none;align-items:center;justify-content:space-between;gap:10px;padding:9px 10px;margin:0 0 8px;border:1px solid var(--line);border-radius:8px;background:var(--panel2)}
.mobile-device-row b{display:block;font-size:12px;color:var(--text)}
.mobile-device-row small{display:block;color:var(--dim);font-size:10.5px;margin-top:2px}
.mobile-device-row select{min-width:130px}
html[data-device="mobile"] .mobile-device-row{display:flex}
html[data-device="mobile"] .mnav{grid-template-columns:repeat(6,1fr)}
html[data-device="mobile"] .mnav button{font-size:7.6px}
html[data-device="mobile"][data-mobile-view="auto"] .layout > .a-ord{display:flex!important;flex:1 1 0!important;height:0!important;min-height:0!important;max-height:none!important;border-radius:var(--radius);overflow:auto!important}
html[data-device="mobile"][data-mobile-view="auto"] .a-ord > :not(#autoPanel){display:none!important}
html[data-device="mobile"][data-mobile-view="auto"] .a-ord #autoPanel{display:block!important;flex:1 1 auto!important;max-height:none!important;overflow:auto!important;padding-bottom:8px}
html[data-device="mobile"][data-mobile-view="trade"] .a-ord #autoPanel{display:none!important}

/* Fullscreen chart must never cover its trade/dialogs. */
body.fs-lock #pop{z-index:300!important}
body.fs-lock #drawFormat{z-index:410!important}
body.fs-lock #drawMenu{z-index:400!important}
/* Mobile bottom chrome: hide fixed desktop status/footer at every mobile width.
   They used to be hidden only below 640px, so tablet/landscape mobile layouts
   (e.g. 821px wide) showed both bars above the bottom navigation. */
html[data-device="mobile"] .runtime-status,
html[data-device="mobile"] .foot {
  display: none !important;
}
html[data-device="mobile"] body {
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
}
html[data-device="mobile"] .layout {
  min-height: 0;
  padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
}
html[data-device="mobile"] .mnav {
  padding-bottom: max(4px, env(safe-area-inset-bottom, 0px));
}

/* ── Responsive v3: tablet stack, phone landscape, TV scale ───────────────
   Toчechnye overrides only. Desktop >1024 and the existing mobile shell are
   intentionally left untouched. */
@media (min-width: 761px) and (max-width: 1024px) {
  html[data-device="desktop"] body {
    height: auto !important;
    min-height: 100dvh;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
  }
  html[data-device="desktop"] .bar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    max-height: 56px;
    padding: 4px 6px;
    gap: 4px 6px;
    scrollbar-width: none;
  }
  html[data-device="desktop"] .bar .brand,
  html[data-device="desktop"] .bar .kpis,
  html[data-device="desktop"] .bar .ctl:has(#themeSelect),
  html[data-device="desktop"] .bar .ctl:has(#deviceSelect),
  html[data-device="desktop"] .bar #logoutBtn,
  html[data-device="desktop"] .bar #adminBtn,
  html[data-device="desktop"] .bar #monSt {
    display: none !important;
  }
  html[data-device="desktop"] .bar > .ctl:has(#instId) { flex: 0 0 auto !important; }
  html[data-device="desktop"] .bar > #btn,
  html[data-device="desktop"] .bar-actions { flex: 0 0 auto !important; }
  html[data-device="desktop"] .bar .acc-chip {
    width: 40px !important;
    min-width: 40px;
    max-width: 40px !important;
    padding: 2px;
    justify-content: center;
  }
  html[data-device="desktop"] .bar .acc-chip-txt { display: none !important; }
  html[data-device="desktop"] .bar #instId { width: 122px; }

  html[data-device="desktop"] .layout {
    display: flex !important;
    flex-direction: column;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    gap: 8px;
    padding: 8px;
  }
  html[data-device="desktop"] .layout > .panel { min-height: 0 !important; width: 100%; }
  html[data-device="desktop"] .layout > .a-chart { order: -2; }
  html[data-device="desktop"] .layout > .a-lad { order: -1; }
  html[data-device="desktop"] .layout > .a-lad,
  html[data-device="desktop"] .layout > .a-chart,
  html[data-device="desktop"] .layout > .a-tabs,
  html[data-device="desktop"] .layout > .a-ord {
    flex: 0 0 auto !important;
    width: 100%;
    border-radius: var(--radius);
    overflow: hidden !important;
  }
  html[data-device="desktop"] .layout > .a-chart {
    height: clamp(340px, 52vh, 560px);
    min-height: 340px;
  }
  html[data-device="desktop"] .layout > .a-lad {
    height: clamp(230px, 30vh, 360px);
    min-height: 230px;
  }
  html[data-device="desktop"] .layout > .a-tabs {
    height: clamp(300px, 34vh, 400px);
    min-height: 300px;
  }
  html[data-device="desktop"] .layout > .a-ord {
    min-height: 360px;
    max-height: none;
  }
  html[data-device="desktop"] .a-chart .cwrap { min-height: 0; }
  html[data-device="desktop"] .a-lad .scroll,
  html[data-device="desktop"] .a-tabs .scroll {
    overflow: auto !important;
    min-height: 0 !important;
  }
  html[data-device="desktop"] .a-ord .ordf { overflow: auto !important; }
}

/* Tablet touch targets: keep the two-column desktop controls usable. */
@media (pointer: coarse) and (min-width: 761px) and (max-width: 1180px) {
  .btn, .seg button, .tabbar button, .chip, .tfs button, .star { min-height: 40px; }
  .btn.sm { min-height: 36px; }
  input, select, textarea { min-height: 40px; }
}

/* Phone landscape: the top bar was 109px on a 390px-high viewport. Keep the
   chart usable by hiding only secondary chrome; portrait is unchanged. */
@media (orientation: landscape) and (max-height: 520px) {
  html[data-device="mobile"] .bar {
    padding: 3px 6px;
    gap: 2px 5px;
  }
  html[data-device="mobile"] .bar .brand,
  html[data-device="mobile"] .bar .kpis,
  html[data-device="mobile"] .bar .ctl:has(#themeSelect),
  html[data-device="mobile"] .bar .ctl:has(#deviceSelect),
  html[data-device="mobile"] .bar #logoutBtn,
  html[data-device="mobile"] .bar #adminBtn,
  html[data-device="mobile"] .bar > #exchangeCtl,
  html[data-device="mobile"] .bar > .ctl:has(#mode),
  html[data-device="mobile"] .bar #monSt,
  html[data-device="mobile"] .banner,
  html[data-device="mobile"] .note {
    display: none !important;
  }
  html[data-device="mobile"] .bar {
    display: flex !important;
    flex-wrap: nowrap !important;
    grid-template-columns: none !important;
    grid-template-areas: none !important;
    height: auto !important;
    max-height: 52px;
    padding: 3px 6px;
    gap: 5px;
    overflow-x: auto !important;
    overflow-y: hidden !important;
  }
  html[data-device="mobile"] .bar > .ctl:has(#instId) {
    order: 0 !important;
    flex: 0 0 auto !important;
    width: auto !important;
    min-width: 0;
    justify-content: flex-start !important;
  }
  html[data-device="mobile"] .bar > #btn { order: 1 !important; flex: 0 0 auto !important; }
  html[data-device="mobile"] .bar-actions { order: 2 !important; flex: 0 0 auto !important; margin-left: 0 !important; }
  html[data-device="mobile"] .layout {
    padding: 4px;
    padding-bottom: calc(44px + env(safe-area-inset-bottom, 0px));
  }
}

/* Phone safe-area: honor the notch without changing the normal 6px padding. */
html[data-device="mobile"] .bar {
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
}

/* TV: safe overscan margins at 1080p and readable scaling on 4K panels. */
@media (min-width: 1200px) {
  html[data-device="tv"] .layout {
    padding: clamp(16px, 1.2vw, 32px);
    gap: clamp(12px, 0.9vw, 24px);
  }
  html[data-device="tv"] .bar {
    padding-left: clamp(20px, 1.4vw, 40px);
    padding-right: clamp(20px, 1.4vw, 40px);
  }
  html[data-device="tv"] .a-tabs .tbl { font-size: clamp(14px, 0.75vw, 20px); }
  html[data-device="tv"] .a-chart .ch1 { font-size: clamp(16px, 0.75vw, 22px); }
  html[data-device="tv"] .ohlc { font-size: clamp(14px, 0.65vw, 19px); }
  html[data-device="tv"] .kpi b { font-size: clamp(22px, 1.1vw, 32px); }
  html[data-device="tv"] .bar > .ctl:has(#themeSelect),
  html[data-device="tv"] .bar > .ctl:has(#deviceSelect) { display: none !important; }
}
@media (min-width: 2400px) {
  html[data-device="tv"] .layout {
    grid-template-columns: clamp(400px, 22vw, 560px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) clamp(300px, 28vh, 480px);
  }
  html[data-device="tv"] .a-tabs .tbl td,
  html[data-device="tv"] .a-tabs .tbl th { padding: 10px 14px; }
  html[data-device="tv"] .a-tabs .tabbar button { min-height: 44px; font-size: clamp(15px, .7vw, 20px); }
  html[data-device="tv"] .r { height: clamp(27px, 1.55vh, 40px); }
}


/* v1 (2026-11-25): desktop chart height + comfortable future pan area. */
html[data-device="desktop"] .layout {
  grid-template-rows: minmax(0, 1fr) clamp(148px, 16.5vh, 188px);
}
html[data-device="desktop"] .a-chart .cwrap {
  min-height: 240px;
}

/* ===== BT UX-01/02: start modal, tray, live HUD (2026-11-26) ===== */
.bt-start-overlay{position:fixed;inset:0;z-index:100000;background:rgba(3,7,18,.72);display:flex;align-items:center;justify-content:center;padding:18px;box-sizing:border-box}
.bt-start-modal{width:min(440px,100%);max-height:calc(100dvh - 32px);overflow:auto;background:var(--panel,#111827);border:1px solid var(--line,#334155);border-radius:14px;padding:18px 20px;box-shadow:0 24px 80px rgba(0,0,0,.55);color:var(--text,#e5e7eb);box-sizing:border-box}
.bt-start-title{font-size:19px;font-weight:800;line-height:1.25;margin-bottom:10px}
.bt-start-body{font-size:13px;line-height:1.7;margin-bottom:12px;overflow-wrap:anywhere}
.bt-start-row{margin-top:6px}
.bt-start-hint{margin:0 0 12px;line-height:1.55}
.bt-start-actions{display:flex;gap:10px;justify-content:flex-end;flex-wrap:wrap}
.bt-start-actions .btn{min-height:38px}
.bt-live-hud{position:fixed;left:50%;bottom:92px;transform:translateX(-50%);z-index:90000;pointer-events:none;background:var(--panel,#0a0f1c);border:1px solid var(--focus,#5b8def);border-radius:10px;padding:7px 12px;color:var(--text,#e5e7eb);font:600 12px/1.35 system-ui,sans-serif;box-shadow:0 10px 30px rgba(0,0,0,.45);white-space:nowrap;max-width:min(94vw,760px);overflow:hidden;text-overflow:ellipsis;box-sizing:border-box}
.bt-live-hud b{font-variant-numeric:tabular-nums}
@media (max-width:900px){
  .bt-start-modal{width:min(420px,100%);padding:16px 17px;border-radius:12px}
  .bt-live-hud{bottom:78px;font-size:11.5px;padding:6px 10px;max-width:calc(100vw - 16px)}
}
@media (max-width:600px){
  .bt-start-overlay{padding:12px;align-items:flex-start;padding-top:max(12px,env(safe-area-inset-top))}
  .bt-start-modal{margin-top:12vh;padding:14px;border-radius:12px}
  .bt-start-title{font-size:17px}
  .bt-start-body{font-size:12px;line-height:1.6}
  .bt-start-actions{flex-direction:column-reverse}
  .bt-start-actions .btn{width:100%;justify-content:center}
  .bt-live-hud{left:8px;right:8px;bottom:74px;transform:none;max-width:none;text-align:center;white-space:normal;font-size:11px;padding:6px 8px}
}
@media (min-width:1600px){
  .bt-start-modal{width:min(500px,100%)}
  .bt-start-title{font-size:21px}
  .bt-start-body{font-size:14px}
  .bt-live-hud{font-size:13px;padding:8px 14px;bottom:104px}
}
@media (prefers-reduced-motion:reduce){
  .bt-start-overlay,.bt-start-modal,.bt-live-hud{transition:none!important;animation:none!important}
}
html[data-device="tablet"] .bt-start-modal{width:min(430px,100%)}
html[data-device="mobile"] .bt-start-modal{width:100%;margin-top:8vh}
html[data-device="tv"] .bt-start-modal{width:min(560px,100%)}
html[data-device="tv"] .bt-live-hud{font-size:15px;bottom:120px}

/* ===== Chart/BT design tokens + action states (2026-11-26) ===== */
:root{
  --chart-grid:rgba(255,255,255,.045);
  --chart-crosshair:rgba(255,255,255,.35);
  --chart-hover-bg:rgba(91,141,239,.14);
  --chart-object:#5b8def;
  --chart-object-selected:#f5b83d;
  --chart-object-handle:#e5e7eb;
  --chart-preview:rgba(91,141,239,.22);
  --chart-invalid:#f0455a;
  --entry-long:#14b77d; --entry-short:#f0455a;
  --sl-color:#f0455a; --tp-color:#14b77d; --liq-color:#f5b83d;
  --avg-color:#a78bfa; --bt-open:#5b8def; --bt-win:#14b77d; --bt-loss:#f0455a;
  --bt-modal-bg:var(--panel,#111827); --bt-overlay-bg:rgba(3,7,18,.72);
  --bt-hud-bg:rgba(10,15,28,.9); --touch-target:44px;
}
html[data-theme="silver"]{
  --chart-grid:rgba(30,41,59,.08); --chart-crosshair:rgba(30,41,59,.45);
  --chart-hover-bg:rgba(37,99,235,.10); --chart-object:#2563eb;
  --chart-object-selected:#b45309; --chart-object-handle:#1e293b;
  --chart-preview:rgba(37,99,235,.16); --bt-hud-bg:rgba(241,245,249,.95);
  --bt-overlay-bg:rgba(15,23,42,.52);
}
html[data-theme="white"]{
  --chart-grid:rgba(15,23,42,.07); --chart-crosshair:rgba(15,23,42,.42);
  --chart-hover-bg:rgba(37,99,235,.10); --chart-object:#2563eb;
  --chart-object-selected:#b45309; --chart-object-handle:#0f172a;
  --chart-preview:rgba(37,99,235,.14); --bt-hud-bg:rgba(255,255,255,.96);
  --bt-overlay-bg:rgba(15,23,42,.42);
}
.bt-confirm-box{color:var(--text,#e5e7eb);background:var(--bt-modal-bg,var(--panel,#111827))}
.bt-confirm{background:var(--bt-overlay-bg,rgba(3,7,18,.72))}
.bt-hud{background:var(--bt-hud-bg,var(--panel,#0a0f1c));border-color:var(--bt-open,#5b8def);color:var(--text,#e5e7eb)}
.bt-hud .bt-hud-val,.bt-live-hud b{font-variant-numeric:tabular-nums}
.bt-start-actions .btn:focus-visible,.bt-start-actions .btn:hover{border-color:var(--focus,#5b8def)}
.bt-start-overlay,.bt-confirm{overscroll-behavior:contain}
body.bt-running #btGo,body.bt-running #btAutoGo{opacity:.55;pointer-events:none}
body.bt-error #btInfo,.bt-error{color:var(--short,#f0455a)}
body.bt-cancelled #btInfo{color:var(--accent,#f5b83d)}
.bt-live-paused{opacity:.7;filter:saturate(.7)}
.bt-live-done{border-color:var(--bt-win,#14b77d)}
.bt-open-trade{box-shadow:0 0 0 1px var(--bt-open,#5b8def),0 0 16px rgba(91,141,239,.28)}
.bt-win{color:var(--bt-win,#14b77d)}
.bt-loss{color:var(--bt-loss,#f0455a)}
@media (pointer:coarse){
  .bt-start-actions .btn{min-height:var(--touch-target,44px)}
}
@media (prefers-reduced-motion:reduce){
  .bt-open-trade,.bt-hud,.bt-confirm-box{animation:none!important;transition:none!important}
}

/* ===== Chart action states / devices (2026-11-26) ===== */
#chart.chart-hover{cursor:crosshair}
#chart.is-panning{cursor:grabbing!important;user-select:none}
#chart.is-panning *{cursor:grabbing!important}
#chart.axis-drag{cursor:ns-resize!important}
#chart.is-dragging{cursor:ns-resize!important}
#chart.is-zooming{transition:none!important}
#chart.is-autofit{animation:chartAutofit .22s ease-out}
@keyframes chartAutofit{0%{filter:brightness(1.12)}100%{filter:none}}
body.chart-draw-mode #chart{cursor:crosshair}
body.draw-ruler-mode #chart{cursor:crosshair}
.chscroll{scrollbar-width:thin;min-width:0}
.chthumb{cursor:grab;touch-action:none}
.chthumb.drag,.chthumb:active{cursor:grabbing}
.btn:disabled,.btn.disabled,[aria-busy="true"]{opacity:.5;cursor:not-allowed;pointer-events:none}
.btn.loading{position:relative;color:transparent!important}
.btn.loading::after{content:"";position:absolute;inset:50% auto auto 50%;width:14px;height:14px;margin:-7px 0 0 -7px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:btSpin .7s linear infinite;color:var(--text)}
@keyframes btSpin{to{transform:rotate(360deg)}}
@media (max-width:767px){}

@media (pointer:coarse){
  .chthumb,.fsbar button,.fsdock button{min-height:var(--touch-target,44px);min-width:var(--touch-target,44px)}
}
@media (prefers-reduced-motion:reduce){
  #chart.is-autofit,.btn.loading::after{animation:none!important}
}

/* ===== Drawing action state classes (2026-11-26) ===== */
body.draw-selected .draw-overlay{cursor:move}
body.draw-multi .draw-overlay{cursor:move}
body.draw-handle-active .draw-overlay{cursor:grab}
body.draw-object-drag .draw-overlay{cursor:grabbing}
body.draw-preview .draw-overlay{cursor:crosshair}
body.draw-magnet #drawMagnet.on,body.draw-stay #drawStay.on{box-shadow:0 0 0 2px var(--focus,#5b8def) inset}
body.draw-hidden .draw-overlay{opacity:.55}
#drawUndo:disabled,#drawRedo:disabled{opacity:.45;cursor:not-allowed}
#drawFormat .df-actions button:focus-visible,#drawFormat select:focus-visible,#drawFormat input:focus-visible{outline:2px solid var(--focus,#5b8def);outline-offset:1px}
.toast.ok{color:var(--long,#14b77d)}
.toast.warn{color:var(--accent,#f5b83d)}
.toast.err{color:var(--short,#f0455a)}
@media (pointer:coarse){
  #drawToolbar [data-tool],#drawFormat .df-actions button{min-height:var(--touch-target,44px)}
  #drawFormat .df-head button{min-width:var(--touch-target,44px);min-height:var(--touch-target,44px)}
  html[data-device="mobile"] .btn.sm,
  html[data-device="mobile"] .tfs button,
  html[data-device="mobile"] .tabbar button,
  html[data-device="mobile"] #fsBtn,
  html[data-device="mobile"] #accChip,
  html[data-device="mobile"] #drawToolbar [data-tool]{
    min-width:var(--touch-target,44px);
    min-height:var(--touch-target,44px);
  }
}
@media (prefers-reduced-motion:reduce){
  body.draw-selected .draw-overlay,body.draw-preview .draw-overlay{transition:none!important;animation:none!important}
}

/* Fullscreen lock must win over the <=1180px responsive overflow override. */
html.fs-lock,body.fs-lock{overflow:hidden!important;height:100%;overscroll-behavior:none}

/* UI-AUDIT P12-R1 (2026-11-27): narrow desktop (761-1100px) header wraps
   instead of being a horizontal scroll strip. Off-screen controls used to
   extend the document scroll width (docSW up to 1.9x viewport) and the
   settings drawer contributed to the page-level horizontal scroll.
   Wrapping keeps every control reachable and the drawer usable. */
@media (max-width: 1100px) {
  html[data-device="desktop"] .bar {
    flex-wrap: wrap !important;
    overflow: visible !important;
    max-height: none !important;
    align-items: center !important;
    gap: 6px 8px !important;
  }
  html[data-device="desktop"] .bar > .ctl {
    width: auto !important;
    flex: 0 1 auto !important;
    min-width: 0 !important;
    flex-wrap: wrap !important;
  }
  html[data-device="desktop"] .bar .brand {
    flex: 0 1 auto !important;
    max-width: 120px !important;
  }
  html[data-device="desktop"] .bar-actions {
    flex: 0 1 auto !important;
    margin-left: 0 !important;
  }
  html[data-device="desktop"] .bar #instId { width: min(40vw, 160px) !important; }
  html[data-device="desktop"] .bar .kpis {
    width: auto !important;
    flex-wrap: wrap !important;
    margin-left: 0 !important;
  }
}


/* S9.3 touch targets: settings drawer controls on touch layouts. */
@media (max-width: 900px) {
  #setPanel input:not([type="hidden"]),
  #setPanel select,
  #setPanel button {
    min-height: 44px;
  }
  #setPanel input[type="checkbox"],
  #setPanel input[type="radio"] {
    min-width: 44px;
    min-height: 44px;
  }
}


/* S9.3 force touch hit areas (mobile/tablet). */
@media (max-width: 900px) {
  #setPanel input:not([type="hidden"]), #setPanel select, #setPanel button { min-height: 44px !important; }
  #setPanel input[type="checkbox"], #setPanel input[type="radio"] { min-width: 44px !important; min-height: 44px !important; }
}
