/* CryptoGraph terminal layout v2 (stage C). Loaded after components.css; only terminal-specific
   placement and density live here — colours and shapes come from tokens/components. */

/* ---------- top bar ---------- */
#topbar { gap: var(--s2); padding: 0 var(--s3) 0 var(--s4); background: var(--panel); border-bottom: 1px solid var(--border); }
#topbar .market { display: inline-flex; align-items: center; gap: var(--s3); padding-left: var(--s1); }
.symbol { display: inline-flex; align-items: center; height: var(--h-md); padding: 0 var(--s2); border-radius: var(--r-sm); font: 600 15px/1 var(--sans); letter-spacing: -0.01em; color: var(--text); }
.symbol::after { margin-left: 8px; border-color: var(--muted); }
#hdrPrice { font: 600 17px/1 var(--mono); letter-spacing: -0.02em; }
.daily-change { display: inline-flex; align-items: center; gap: 6px; font: 600 var(--fs-xs)/1 var(--mono); }
.daily-change small { font: 400 var(--fs-2xs)/1 var(--sans); color: var(--soft); }
#hdrChange.up, #hdrChange.down { padding: 4px 6px; border-radius: var(--r-sm); }
#hdrChange.up { background: var(--long-soft); color: var(--long); }
#hdrChange.down { background: var(--short-soft); color: var(--short); }
.balance { border-left: 0; padding-left: var(--s2); display: inline-flex; align-items: baseline; gap: 6px; font-size: var(--fs-2xs); color: var(--muted); }
.balance b { font: 600 var(--fs-sm)/1 var(--mono); color: var(--text); }
.conn-health { height: var(--h-sm); font-size: var(--fs-2xs); border-color: var(--border); }
.conn-health:hover { border-color: var(--border-strong); color: var(--text); }
.panel-toggle[aria-expanded="false"] { color: var(--soft); }
@media (max-width: 1280px) { .balance-label, .daily-change small { display: none; } }

/* ---------- chart toolbar ---------- */
#chartTools { gap: 2px; padding: 0 var(--s2); background: var(--panel); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
#chartTools::-webkit-scrollbar { display: none; }
#chartTools .sep { width: 1px; height: 18px; margin: 0 var(--s1); background: var(--border); flex: none; }
#chartTools .tb .icon, #chartTools .icon-btn .icon { width: 15px; height: 15px; }
.tfbar { gap: 0; padding: 2px; background: var(--panel2); border: 1px solid var(--border); border-radius: var(--r-sm); flex: none; }
.tfbar button { height: 24px; min-width: 30px; padding: 0 6px; border-radius: 4px; font: 500 var(--fs-xs)/1 var(--mono); color: var(--muted); background: transparent; }
.tfbar button:not(.active):hover { color: var(--text); background: var(--hover); }
.tfbar button.active { background: var(--accent-fill); color: var(--btn-fg); font-weight: 600; }
.tb.tf-more { width: 24px; padding: 0; margin-right: 2px; }
#chartTools select.tb, #chartType {
  height: var(--h-sm); width: 118px; max-width: 150px; padding: 0 26px 0 8px; border: 1px solid transparent;
  background-color: transparent; color: var(--muted); font: 500 var(--fs-xs)/1 var(--sans); background-position: right 7px center;
}
#chartTools select.tb:hover, #chartType:hover { background-color: var(--hover); color: var(--text); border-color: transparent; }
.compare-wrap { display: inline-flex; align-items: center; gap: 2px; }
#compareSym { height: var(--h-sm); width: 118px; padding: 0 8px; font: 500 var(--fs-xs)/1 var(--sans); background: var(--bg); }

/* ---------- drawing rail ---------- */
.drawbar { gap: 2px; padding: var(--s2) 0; background: var(--panel); border-right: 1px solid var(--border); }
.drawbar button { width: 34px; height: 34px; border-radius: var(--r-sm); color: var(--muted); }
.drawbar button:hover { color: var(--text); background: var(--hover); }
.drawbar button.active { color: var(--accent); background: var(--selected); }
.drawbar .icon { width: 18px; height: 18px; }
.drawbar .sep { width: 22px; height: 1px; margin: 6px 0; background: var(--border); }

/* ---------- side rails: icon tabs, label only on the active tab when narrow ---------- */
#leftRail, #side { container-type: inline-size; background: var(--panel); }
#leftRail .tabs, #side .tabs { flex-wrap: nowrap; gap: 0; height: 40px; padding: 0 var(--s1); overflow: visible; }
#leftRail .tabs > button, #side .tabs > button { flex: 1 1 auto; min-width: 34px; justify-content: center; gap: 6px; padding: 0 8px; }
.tabs > button .icon { width: 16px; height: 16px; }
.tabs .tab-label { overflow: hidden; text-overflow: ellipsis; }
#symCount { padding: 2px 5px; border-radius: 4px; font: 500 10px/1 var(--mono); background: var(--panel2); color: var(--muted); }
@container (max-width: 440px) {
  .tabs > button:not(.active) .tab-label, .tabs > button:not(.active) #symCount { display: none; }
  .tabs > button:not(.active) { flex: 0 0 36px; padding: 0; }
}
@container (max-width: 300px) { #symCount { display: none; } }
.tabs > button[data-tip]:hover::after { top: calc(100% + 2px); }
#leftRail .panel, #side .panel { background: var(--panel); }

/* ---------- watchlist ---------- */
.searchrow { padding: var(--s3) var(--s3) var(--s2); gap: var(--s1); }
.searchrow .icon { left: 22px; width: 15px; height: 15px; color: var(--soft); }
.searchrow input { padding-left: 32px; }
#watchToolbar { flex-wrap: nowrap; gap: 2px; padding: 0 var(--s3) var(--s2); border-bottom: 1px solid var(--border); }
#watchToolbar select { flex: 1; min-width: 0; height: var(--h-md); font-size: var(--fs-sm); }
.menu-pop { position: fixed; inset: auto; margin: 0; min-width: 210px; padding: var(--s2); background: var(--surface3); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.menu-pop:popover-open { display: flex; flex-direction: column; gap: 2px; }
#watchToolbar .watch-cols:not(:popover-open) { display: none; }
#watchToolbar .watch-cols:popover-open { display: flex; flex-direction: column; flex-wrap: nowrap; gap: 2px; }
.watch-cols::before { content: "Колонки списку"; padding: 2px 6px 6px; font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.watch-cols label { display: flex; align-items: center; gap: var(--s2); padding: 6px; border-radius: var(--r-sm); font-size: var(--fs-sm); cursor: pointer; }
.watch-cols label:hover { background: var(--hover); }
.watch th { background: var(--panel); color: var(--soft); font: 500 var(--fs-2xs)/1 var(--sans); text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--border); }
.watch th:hover { color: var(--text); }
.watch td { height: 32px; padding: 0 6px; font: 500 var(--fs-xs)/1 var(--mono); border-bottom: 1px solid var(--rule); }
.watch th { padding: 8px 6px; }
.watch td.sym, .watch th:first-child { padding-left: 18px; }
.watch td.sym { position: relative; font-family: var(--sans); }
.watch td.sym b { font-weight: 600; font-size: var(--fs-sm); }
.watch td.sym span { color: var(--soft); font-size: var(--fs-2xs); }
.watch tr.active { background: var(--selected); }
.watch tr.active td:first-child { box-shadow: inset 2px 0 var(--accent); color: var(--text); }
.pin-btn { position: absolute; left: 2px; top: 50%; transform: translateY(-50%); display: grid; place-items: center; width: 16px; height: 16px; margin: 0; padding: 0; border: 0; background: transparent; color: var(--soft); opacity: 0; vertical-align: middle; cursor: pointer; transition: opacity var(--dur-fast) var(--ease); }
.pin-btn .icon { width: 12px; height: 12px; }
.watch tr:hover .pin-btn, .pin-btn.on, .pin-btn:focus-visible { opacity: 1; }
.pin-btn.on { color: var(--accent); }
.tag-dot { width: 8px; height: 8px; border-color: var(--border-strong); }
.tag-dot.tag-none { opacity: 0; }
.watch tr:hover .tag-dot.tag-none { opacity: 1; }
#watchWrap:has(#watchBody:empty) {
  background: repeating-linear-gradient(180deg, transparent 0 8px, var(--panel2) 8px 22px, transparent 22px 32px);
  background-clip: content-box; padding: 40px var(--s3) 0; animation: cg-fade 1s ease-in-out infinite alternate;
}
@keyframes tick-up { from { background-color: var(--long-soft); } to { background-color: transparent; } }
@keyframes tick-down { from { background-color: var(--short-soft); } to { background-color: transparent; } }

/* ---------- toasts: top centre over the chart (below header + toolbar), clear of the trade panel buttons ---------- */
@media (min-width: 768px) {
  #toasts { top: calc(var(--topbar-h, 48px) + var(--tools-h, 44px) + var(--s3)); bottom: auto; right: auto; left: 50%; transform: translateX(-50%); align-items: center; max-width: min(520px, calc(100vw - 32px)); }
}
.toast .toast-msg { flex: 1; }
.toast .toast-x { flex: none; align-self: flex-start; width: 22px; height: 22px; margin: -2px -6px 0 0; padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font: 400 18px/1 var(--sans); cursor: pointer; }
.toast .toast-x:hover { background: var(--hover); color: var(--text); }

/* ---------- alerts panel ---------- */
.alform { padding: var(--s3); gap: var(--s2); }
.alform .row b { font: 600 var(--fs-md)/1 var(--sans); }
.alert-item { padding: 10px 32px 10px var(--s3); border-bottom: 1px solid var(--rule); font-size: var(--fs-xs); }
.alert-item:hover { background: var(--hover); }
.alert-item .x { top: 8px; right: 8px; width: 22px; height: 22px; border-radius: var(--r-sm); }
.alert-item .x:hover { background: var(--hover); color: var(--short); }
#alertList:empty::after { content: "Алертів ще немає. Задайте умову вище або клацніть правою кнопкою по графіку → «Алерт на ціні»."; display: block; padding: var(--s6) var(--s4); text-align: center; color: var(--muted); font-size: var(--fs-xs); line-height: 1.5; }
#notesBox { flex: 1; margin: var(--s3); min-height: 120px; resize: none; }

/* ---------- ticket (right rail) ---------- */
.ticket-quick { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); }
.ticket-sides { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.ticket-summary { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font-size: var(--fs-xs); color: var(--muted); line-height: 1.5; }
#ticketPanel .field-hint { margin: 0; line-height: 1.5; }
#confirmCard { margin: 0 var(--s4) var(--s4); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel2); }
#confirmCard h4 { margin: 0 0 var(--s2); font: 600 var(--fs-md)/1.3 var(--sans); }
#confirmActions { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s3); }
#riskPlaceholder.empty-state { height: 100%; }

/* ---------- order book ---------- */
.ob-head, .ob-mid, .ob-trades-head { padding: 8px var(--s3); font-size: var(--fs-2xs); color: var(--muted); }
.ob-mid { font: 600 var(--fs-md)/1 var(--mono); color: var(--text); background: var(--panel2); }
#obTick { height: var(--h-xs); font-size: var(--fs-2xs); padding: 0 22px 0 6px; }

/* ---------- bottom panel ---------- */
#bottom .tabs { height: 38px; padding: 0 var(--s2); }
#bottom .tabs > button { flex: none; }
.acct { align-self: center; font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.acct b { font: 600 var(--fs-xs)/1 var(--mono); color: var(--text); }
#paperSettingsBtn { align-self: center; }
.grid th { position: sticky; top: 0; z-index: 1; background: var(--panel); color: var(--soft); font: 500 var(--fs-2xs)/1 var(--sans); text-transform: uppercase; letter-spacing: .04em; padding: 8px; border-bottom: 1px solid var(--border); text-align: left; }
.grid td { padding: 7px 8px; font: 500 var(--fs-xs)/1.2 var(--mono); border-bottom: 1px solid var(--rule); }
.grid td[colspan] { padding: var(--s5) var(--s4); text-align: center; font-family: var(--sans); color: var(--muted); }
.grid tbody tr:hover { background: var(--hover); }

/* ---------- chart area ---------- */
.chart-foot { color: var(--soft); font: 400 var(--fs-2xs)/1 var(--sans); border-top: 1px solid var(--rule); background: var(--chart-bg); }
.loading { top: 12px; padding: 6px 12px; border-radius: var(--r-pill); background: var(--surface3); border: 1px solid var(--border-strong); color: var(--muted); font-size: var(--fs-xs); box-shadow: var(--shadow-1); }
#indLegend { top: 8px; left: 8px; max-width: min(620px, 62%); background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--border); border-radius: var(--r-md); padding: 6px 8px; box-shadow: var(--shadow-1); backdrop-filter: blur(6px); font-size: var(--fs-xs); }
.ind-leg-vals { font: 500 var(--fs-2xs)/1.3 var(--mono); color: var(--muted); }
.liqhint { border-color: var(--liq); border-radius: var(--r-md); background: var(--surface3); box-shadow: var(--shadow-1); }
.liqhint .liq-title { color: var(--liq); }

/* ---------- menus and popovers (legacy markup) ---------- */
.menu, .view-menu, #viewMenu, .tf-menu, .drawing-tree, .ctxmenu {
  background: var(--surface3); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-1);
}
.view-menu h4 { margin: var(--s1) 0 var(--s2); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
#presetList button, .view-menu button[data-preset], .tf-menu button, .ctxmenu .item { border-radius: var(--r-sm); }
.ctxmenu { padding: var(--s1); min-width: 240px; }
.ctxmenu .item { padding: 7px 10px; font-size: var(--fs-sm); }
.tf-menu button { font: 500 var(--fs-xs)/1 var(--mono); }
.drawing-tree button, .drawing-inspector button { background: var(--panel2); border-color: var(--border); border-radius: var(--r-sm); }

/* ---------- dialogs with legacy markup ---------- */
.dlg { background: var(--panel); border: 1px solid var(--border-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: var(--s5); }
.dlg h3 { margin: 0 0 var(--s4); font: 600 var(--fs-xl)/1.25 var(--sans); letter-spacing: -0.01em; }
.dlg h3 .muted { font-weight: 400; font-size: var(--fs-xs); }
.sidebtns { gap: var(--s2); margin-bottom: var(--s4); }
.sidebtns button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--h-lg); border-radius: var(--r-md); background: var(--panel2); border: 1px solid var(--border); color: var(--muted); font: 600 var(--fs-md)/1 var(--sans); transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.sidebtns button:hover { color: var(--text); border-color: var(--border-strong); }
#tdLong.active { background: var(--long); border-color: var(--long); color: var(--on-long); }
#tdShort.active { background: var(--short); border-color: var(--short); color: var(--on-short); }
.dlg .form label, .dlg label { font-size: var(--fs-xs); color: var(--muted); }

/* ---------- reduced chrome on short screens ---------- */
@media (max-height: 820px) { :root { --tools-h: 38px; } #leftRail .tabs, #side .tabs { height: 36px; } }

/* ---------- phone shell (< 768px) ---------- */
@media (max-width: 767px) {
  #mTop { gap: var(--s2); }
  #mBack { height: var(--h-md); padding: 0 10px; border-radius: var(--r-sm); background: var(--panel2); border: 1px solid var(--border); color: var(--text); font: 500 var(--fs-sm)/1 var(--sans); }
  .m-sym { font: 600 15px/1.1 var(--sans); }
  #mPrice { font: 600 var(--fs-sm)/1 var(--mono); }
  #mChange { font: 600 var(--fs-2xs)/1 var(--mono); }
  #mTf button { height: 28px; border-radius: var(--r-sm); color: var(--muted); font: 500 var(--fs-xs)/1 var(--mono); }
  #mTf button.active { background: var(--accent-fill); color: var(--btn-fg); }
  #mStrip { color: var(--soft); font-size: var(--fs-2xs); background: var(--panel); }
  #mNav { background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(8px); }
  #mNav button { gap: 4px; font: 500 10px/1 var(--sans); color: var(--muted); }
  #mNav button .icon { width: 20px; height: 20px; }
  #mNav button.active { color: var(--accent); }
  #mFab { width: 48px; height: 48px; background: var(--accent-fill); color: var(--btn-fg); box-shadow: var(--shadow-1); }
  #mFab .icon { width: 22px; height: 22px; stroke-width: 2.25; }
  #mMore, #mQuick { border-top: 1px solid var(--border-strong); border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: var(--shadow-2); padding-top: 4px; }
  #mMore::before, #mQuick::before { content: ""; display: block; width: 36px; height: 4px; margin: 6px auto 8px; border-radius: var(--r-pill); background: var(--border-strong); }
  #mMore button, #mQuick button { display: flex; align-items: center; gap: 12px; padding: 13px 8px; font: 400 15px/1.2 var(--sans); border-bottom-color: var(--rule); }
  #mMore button[hidden], #mQuick button[hidden] { display: none; }
  #mMore button .icon, #mQuick button .icon { width: 18px; height: 18px; color: var(--muted); }
  #toasts { top: auto; }
}

/* ---------- forms in dialogs and sheets: never wider than the screen ---------- */
.form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s3); }
.form label > input:not([type=checkbox]):not([type=radio]), .form label > select { width: 100%; }
.lev input[type=number] { width: 72px; flex: none; padding: 0 8px; }
#aiPanel .ai-run { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--btn-fg); }
#aiPanel .ai-run:hover { background: var(--accent-hover); }

/* ---------- very narrow rails: icons only, even for the active tab ---------- */
@container (max-width: 250px) {
  .tabs > button.active .tab-label { display: none; }
  .tabs > button { flex: 1 1 0 !important; padding: 0 !important; }
}

/* ---------- indicator legend icons ---------- */
.ind-ico { display: inline-grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); cursor: pointer; }
.ind-ico:hover { background: var(--hover); color: var(--text); }
.ind-ico .icon { width: 14px; height: 14px; }

/* ---------- account chip (top bar) ---------- */
.acct-chip { display: inline-flex; align-items: center; gap: 6px; height: var(--h-sm); padding: 0 var(--s2) 0 6px;
  border: 1px solid var(--border); border-radius: var(--r-pill); color: var(--muted); text-decoration: none; }
.acct-chip:hover { color: var(--text); border-color: var(--border-strong); background: var(--hover); text-decoration: none; }
.acct-chip .badge { font-size: var(--fs-2xs); }
#acctChip.btn { text-decoration: none; }
@media (max-width: 767px) { #acctChip { display: none; } }

/* watchlist: the pair column stays put while extra columns scroll sideways (Binance / TradingView) */
.watch td.sym, .watch th:first-child { position: sticky; left: 0; z-index: 1; background: var(--panel); }
.watch thead th { z-index: 2; }
.watch thead th:first-child { z-index: 3; }
.watch tbody tr:hover td.sym { background: var(--hover); }
.watch tr.active td.sym { background: var(--selected); }
.watch td.sym::after { content: ""; position: absolute; top: 0; right: -1px; bottom: 0; width: 1px; background: var(--rule); }

/* ---------- backtester panel (over the chart, right side) ---------- */
.bt-panel { position: absolute; top: 8px; right: 72px; bottom: 8px; z-index: 9; width: min(360px, calc(100% - 96px)); overflow: auto;
  display: grid; align-content: start; gap: var(--s3); padding: var(--s3); background: color-mix(in srgb, var(--panel) 96%, transparent);
  border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-2); backdrop-filter: blur(8px); }
.bt-panel[hidden] { display: none; }
.bt-head { display: flex; align-items: center; justify-content: space-between; }
.bt-form { display: grid; gap: var(--s2); }
.bt-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s2); }
.bt-field { gap: 4px; }
.bt-field input, .bt-field select { width: 100%; height: var(--h-sm); font-size: var(--fs-xs); }
.bt-opp { font-size: var(--fs-xs); color: var(--muted); }
.bt-results { display: grid; gap: var(--s3); }
.bt-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s2); }
.bt-kpi { display: grid; gap: 2px; padding: var(--s2); border-radius: var(--r-sm); background: var(--panel2); }
.bt-kpi span { font-size: var(--fs-2xs); color: var(--muted); }
.bt-kpi b { font: 600 var(--fs-xs)/1.2 var(--mono); }
.bt-kpi b.pos { color: var(--long); } .bt-kpi b.neg { color: var(--short); }
.bt-equity { width: 100%; height: 80px; border-radius: var(--r-sm); background: var(--chart-bg); }
.bt-equity polyline { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.bt-equity polyline.up { stroke: var(--long); } .bt-equity polyline.down { stroke: var(--short); }
.bt-equity line.base { stroke: var(--border-strong); stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.bt-trades { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: var(--r-sm); }
.bt-trades table { width: 100%; font-size: var(--fs-2xs); }
.bt-trades td.pos { color: var(--long); } .bt-trades td.neg { color: var(--short); }
.bt-trades tr { cursor: pointer; } .bt-trades tbody tr:hover { background: var(--hover); }
.bt-note { line-height: 1.5; }
#btnBacktest.active { color: var(--text); background: var(--selected); }
@media (max-width: 767px) { .bt-panel { left: 4px; right: 4px; width: auto; top: 4px; bottom: 4px; } }

/* replay start menu and candle picking */
.replay-start { position: fixed; z-index: var(--z-menu, 60); display: grid; gap: 2px; min-width: 260px; padding: var(--s1); }
.replay-start[hidden] { display: none; }
.replay-start button { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border: 0; border-radius: var(--r-sm); background: none; color: var(--text); font-size: var(--fs-sm); text-align: left; cursor: pointer; }
.replay-start button:hover, .replay-start button:focus-visible { background: var(--hover); }
.replay-start p { margin: var(--s1) var(--s3) var(--s2); line-height: 1.4; }
#chartWrap.replay-pick #chart { cursor: crosshair; outline: 2px dashed var(--accent); outline-offset: -2px; }

/* ---------- alerts L3: rule dialog, panel badges, event log ---------- */
.rule-dlg { width: min(680px, calc(100vw - 16px)); max-height: 92vh; padding: 0; overflow: hidden; }
.rule-dlg[open] { display: flex; }
.rd-form { display: flex; flex-direction: column; min-width: 0; width: 100%; max-height: 92vh; }
.rd-body { display: flex; flex-direction: column; gap: var(--s3); overflow-y: auto; min-width: 0; }
.rd-body label { display: flex; flex-direction: column; gap: var(--s1); font-size: var(--fs-xs); color: var(--muted); min-width: 0; }
.rd-body input:not([type=checkbox]), .rd-body select, .rd-body textarea { width: 100%; min-width: 0; }
.rd-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s3); }
.rd-check { display: flex !important; flex-direction: row !important; align-items: center; gap: var(--s2) !important; }
.rd-sect { font: 600 var(--fs-2xs)/1 var(--sans); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.rd-rows { display: flex; flex-direction: column; gap: var(--s2); }
.rd-row { display: flex; flex-direction: column; gap: var(--s1); }
.rd-and { font: 600 var(--fs-sm)/1 var(--sans); color: var(--accent); }
.rd-cond { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.6fr) auto; gap: var(--s2); align-items: start; padding: var(--s2); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--panel2); }
.rd-op { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; min-width: 0; }
.rd-op select { flex: 1 1 110px; width: auto; }
.rd-op input.rd-p { flex: 0 1 64px; width: 64px; }
.rd-op input[type=number]:not(.rd-p) { flex: 1 1 90px; width: auto; }
.rd-right { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; min-width: 0; }
.rd-right > .rd-op { flex: 1 1 100%; }
.rd-line { overflow-wrap: anywhere; }
.rd-addrow { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.rd-plan { font-size: var(--fs-2xs); color: var(--warning); }
.rd-preview { padding: var(--s2) var(--s3); border-radius: var(--r-md); background: var(--accent-soft); color: var(--text); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.rd-err { padding: var(--s2) var(--s3); border-radius: var(--r-md); background: var(--short-soft); color: var(--short); font-size: var(--fs-sm); }
.rd-err[hidden] { display: none; }
@media (max-width: 600px) {
  .rd-cond { grid-template-columns: minmax(0, 1fr) auto; }
  .rd-cond > .rd-op:first-child, .rd-cond > select, .rd-cond > .rd-right { grid-column: 1 / -1; }
  .rd-cond > .rd-rm { grid-column: 2; grid-row: 1; }
  .rd-cond > .rd-op:first-child { grid-column: 1; }
  .rd-grid { grid-template-columns: minmax(0, 1fr); }
}
#alertInboxBar { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }
#alertInboxBar .al-top, #alertInboxBar .al-filters { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; }
#alertInboxBar .al-filters[hidden] { display: none; }
#alertInboxBar button[aria-pressed=true] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.al-meta { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-top: 2px; }
.al-badge { padding: 1px 6px; border-radius: var(--r-pill); background: var(--accent-soft); color: var(--text); font-size: var(--fs-2xs); }
.al-badge.warn { background: var(--warning-soft); color: var(--warning); }
.alert-item.paused { opacity: .7; }
.alert-item .al-toggle { position: absolute; right: 34px; top: 8px; width: 22px; height: 22px; border: 0; border-radius: var(--r-sm); background: none; color: var(--muted); cursor: pointer; font-size: var(--fs-xs); }
.alert-item .al-toggle:hover { background: var(--hover); color: var(--text); }
.al-event .al-price { float: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.drawing-tree .tree-row { display: flex; gap: var(--s1); }
.drawing-tree .tree-row > button:first-child { flex: 1; }
.drawing-inspector .di-alert { display: inline-flex; align-items: center; gap: 4px; }
.drawing-inspector .di-alert[hidden] { display: none; }
.ind-more-menu button:disabled { opacity: .5; cursor: not-allowed; }
.alert-item.rule-al { padding-right: 60px; }

/* chart type settings popover (box / brick size, reversal) */
.type-opts { z-index: 40; gap: var(--s2); min-width: 240px; }
.type-opts label { justify-content: space-between; }
.type-opts input { width: 90px; }

#chartType { min-width: 150px; }

/* narrow chart toolbar: icon-only buttons (the title keeps the name), nothing wraps out of view */
/* one row always: a wrapped second row was hidden by overflow (buttons became unreachable) */
/* no container-type here: it would trap the fixed dropdowns (Макет, ТФ, Об'єкти) inside the toolbar */
#chartTools { flex-wrap: nowrap; }
@media (max-width: 1786px) {
  #chartTools .tb:has(> svg.icon) { font-size: 0; gap: 0; padding-inline: 7px; }
  #chartTools .tb:has(> svg.icon) > svg.icon { margin: 0; }
}
@media (max-width: 1536px) {
  #chartTools #compareSym { width: 64px; }
  #chartTools #chartType { width: 96px; }
  #chartTools .sep { display: none; }
}
@media (max-width: 1786px) {
  #chartTools #chartType { width: 112px; }
  #chartTools #compareSym { width: 64px; }
  #chartTools #btnInv { font-size: 0; padding-inline: 7px; }
  #chartTools #btnInv::before { content: "⇅"; font-size: var(--fs-sm); }
  #chartTools > .tb:not(:has(svg.icon)) { padding-inline: 6px; }
}
/* when the row still does not fit, show a thin scrollbar so it is clear there is more */
#chartTools.is-scroll { scrollbar-width: thin; }
#chartTools.is-scroll::-webkit-scrollbar { display: block; height: 4px; }
/* secondary tools are icon-only at every width (TradingView style); the title keeps the name */
#chartTools :is(#btnScreener, #btnBacktest, #btnLayout, #btnReplay ~ .tb:has(> svg.icon)) { font-size: 0; gap: 0; padding-inline: 7px; }
#chartTools .tb:has(> svg[class~="icon"]):is([title*="Об"], [title*="бʼєкт"]) { font-size: 0; gap: 0; padding-inline: 7px; }
@media (max-width: 1786px) {
  #chartTools { gap: 1px; }
  #chartTools .tfbar button { padding-inline: 5px; }
  #chartTools #chartType { width: 96px; }
}

/* Indicator legend like TradingView: text straight on the chart (no box hiding candles), a soft halo keeps it
   readable; the background and the row icons appear only while the pointer is over the legend (.is-hot). */
#indLegend { background: transparent; border-color: transparent; box-shadow: none; backdrop-filter: none;
  text-shadow: 0 0 2px var(--chart-bg), 0 0 5px var(--chart-bg); transition: background-color .12s; }
#indLegend.is-hot { background: color-mix(in srgb, var(--chart-bg) 78%, transparent); border-color: var(--border); }
#indLegend:not(.is-hot) .ind-leg-icons { visibility: hidden; }

/* legend: capped width, one line per row with an ellipsis, «+N» row for long lists (the legend stays transparent) */
@media (min-width: 768px) { #indLegend { max-width: min(440px, 64%); } }
#indLegend .ind-leg-row { min-width: 0; }
#indLegend .ind-leg-title { flex: 1 1 auto; min-width: 0; }
#indLegend .ind-leg-icons { flex: none; }
#indLegend .ind-leg-sym { min-width: 0; max-width: 100%; }
#indLegend .ind-leg-more { display: inline-flex; align-self: flex-start; margin: 2px 0 0 22px; padding: 1px 8px; border: 1px solid var(--border); border-radius: var(--r-pill); background: transparent; color: var(--muted); font: 500 var(--fs-2xs)/1.4 var(--mono); cursor: pointer; pointer-events: auto; text-shadow: inherit; }
#indLegend .ind-leg-more:hover { color: var(--text); background: color-mix(in srgb, var(--chart-bg) 78%, transparent); border-color: var(--border-strong); }

/* chart toolbar overflow («···»): measured at natural widths, the overflowing tools live in a dropdown */
#chartTools.measuring > * { flex: none !important; }
#chartTools .tools-more { flex: none; font-size: var(--fs-md); letter-spacing: .08em; padding-inline: 8px; }
#chartTools .tools-more[hidden] { display: none; }
#chartTools .tools-more.has-active, #chartTools .tools-more[aria-expanded="true"] { color: var(--accent); background: var(--selected); }
.tools-more-menu { position: fixed; z-index: var(--z-menu, 60); display: flex; flex-direction: column; gap: 2px; min-width: 200px; max-width: min(320px, calc(100vw - 16px)); padding: var(--s1); background: var(--surface3); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
.tools-more-menu[hidden] { display: none; }
.tools-more-menu > * { flex: none; width: 100%; justify-content: flex-start; text-align: left; gap: 8px; font-size: var(--fs-sm); white-space: nowrap; }
.tools-more-menu > .tb, .tools-more-menu > .icon-btn { display: flex; align-items: center; height: var(--h-md); padding: 0 10px; border-radius: var(--r-sm); background: transparent; color: var(--text); }
.tools-more-menu > .tb:hover, .tools-more-menu > .icon-btn:hover { background: var(--hover); }
.tools-more-menu > .tb[data-ovf-label]::after, .tools-more-menu > .icon-btn[data-ovf-label]::after { content: attr(data-ovf-label); }
.tools-more-menu .icon { width: 15px; height: 15px; flex: none; }
.tools-more-menu .compare-wrap { padding: 4px 6px; }
.tools-more-menu .compare-wrap input { flex: 1; min-width: 0; width: auto; }

/* ---------- tablet (768–1100 px): side panels are overlays, the chart keeps the full width ---------- */
@media (min-width: 768px) and (max-width: 1100px) {
  #app { position: relative; grid-template-columns: var(--draw-w, 52px) minmax(0, 1fr) var(--strip-w, 40px) !important;
    grid-template-areas: "top top top" "draw controls strip" "draw chart strip" "draw bottom strip" !important; }
  #leftRail, #side { grid-area: auto; position: absolute; top: var(--topbar-h, 48px); bottom: 0; z-index: 35; width: min(320px, 86vw);
    display: none !important; box-shadow: var(--shadow-2); }
  #leftRail { left: var(--draw-w, 52px); }
  #side { right: var(--strip-w, 40px); }
  #app.t-left-open #leftRail, #app.t-right-open #side { display: flex !important; }
  #leftRail .panel-grip, #side .panel-grip { display: none; }
  /* top bar: drop the secondary text so everything fits at 768 */
  #topbar { min-width: 0; padding-inline: var(--s3); }
  #topbar .balance-label, #topbar .daily-change small, #topbar .wordmark, #btnTrade { font-size: 0; }
  #topbar .wordmark, #topbar .balance-label { display: none; }
  #btnTrade { gap: 0; padding-inline: 8px; }
  #connHealth #connLat { display: none; }
}
@media (min-width: 768px) and (max-width: 900px) {
  #topbar .balance, #connHealth #connLabel { display: none; }
  #topbar #hdrPrice { font-size: 15px; }
}

/* plain toasts sit over the chart: let clicks / right-clicks pass through; only the dismissible hint is interactive */
@media (min-width: 768px) { .toast { pointer-events: none; } .toast:has(.toast-x) { pointer-events: auto; } }
