/* Оболонка термінала V2: сітка, рейки, здоров'я з'єднання, стакан, палітра, картка підтвердження */
#app {
  display: grid;
  height: 100dvh;
  grid-template-columns: var(--draw-w, 52px) var(--left, 260px) minmax(0, 1fr) var(--right, 320px);
  grid-template-rows: var(--topbar-h, 48px) var(--tools-h, 44px) minmax(0, 1fr) var(--bottom, 260px);
  grid-template-areas:
    "top top top top"
    "draw left controls right"
    "draw left chart right"
    "draw left bottom right";
}
#topbar { height: var(--topbar-h, 48px); }
#leftRail {
  grid-area: left;
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  position: relative;
}
#leftRail[hidden], #side[hidden], #bottom[hidden], #drawBar[hidden] { display: none !important; }
#app.left-collapsed { --left: 0px; }
#app.right-collapsed { --right: 0px; --side: 0px; }
#app.bottom-collapsed { --bottom: 0px; }
#app.focus-mode { --draw-w: 0px; }
#app.focus-mode #drawBar { display: none !important; }
#side { grid-area: right; border-left: 1px solid var(--border); }
#chart { background: var(--chart-bg); }

.conn-health {
  display: inline-flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 8px 2px 6px;
  color: var(--muted); font-size: 11px; height: 28px;
}
.conn-health .dot { margin: 0; }
.conn-health[data-state="connected"] .dot { background: var(--green); }
.conn-health[data-state="reconnecting"] .dot { background: var(--warning); }
.conn-health[data-state="resyncing"] .dot { background: var(--accent); }
.conn-health[data-state="offline"] .dot { background: var(--red); }
#connLat { font-family: var(--mono); }

#themeSelect { max-width: 9.5rem; background: var(--panel); border: 1px solid var(--border); height: 28px; padding: 0 6px; }
#btnFocus[aria-pressed="true"] { color: var(--accent); background: var(--selected); }

.view-menu, #viewMenu {
  position: fixed; z-index: 40; min-width: 220px;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px; box-shadow: var(--shadow-2);
}
.view-menu[hidden] { display: none !important; }
.view-menu h4, #presetList + .muted { margin: 0 0 6px; font-size: 11px; color: var(--muted); font-weight: 600; }
#presetList, .view-menu .col { display: flex; flex-direction: column; gap: 2px; }
#presetList button, .view-menu button[data-preset] {
  text-align: left; background: transparent; border: 0; color: var(--text);
  padding: 6px 8px; border-radius: 4px;
}
#presetList button:hover, .view-menu button[data-preset]:hover { background: var(--hover); }

.grip-left { right: -3px; left: auto; top: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.panel-grip { position: absolute; z-index: 4; touch-action: none; }
.grip-right, .grip-side { left: -3px; top: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.tabs button[data-panel] { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
#leftRail .tabs, #side .tabs { display: flex; flex-wrap: wrap; gap: 0; border-bottom: 1px solid var(--border); }
#leftRail .panel, #side .panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Стакан */
.ob-head, .ob-mid, .ob-trades-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px; font-size: 11px; color: var(--muted);
}
.ob-mid { flex-direction: column; align-items: center; padding: 8px 6px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
#obMid { font-family: var(--mono); color: var(--text); font-size: 15px; font-weight: 600; }
#obSpread { font-family: var(--mono); font-size: 11px; }
.ob-cols { display: grid; grid-template-columns: 1fr; min-height: 0; flex: 1; }
.ob-side { position: relative; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.ob-rows { display: flex; flex-direction: column; }
.ob-row {
  position: relative; display: grid; grid-template-columns: 1fr auto;
  width: 100%; border: 0; background: transparent; color: var(--text);
  font-family: var(--mono); font-size: 11px; padding: 1px 8px; text-align: left;
}
.ob-row.ask { color: var(--red); }
.ob-row.bid { color: var(--green); }
.ob-row:hover { background: var(--hover); }
.ob-bar {
  position: absolute; inset: 0 auto 0 0; width: 100%; transform-origin: left center;
  pointer-events: none; opacity: .22;
}
.ob-bar.bid { background: var(--green); }
.ob-bar.ask { background: var(--red); }
.ob-px { position: relative; z-index: 1; }
.ob-qty { position: relative; z-index: 1; color: var(--muted); }
#obTrades { max-height: 140px; overflow: auto; font-family: var(--mono); font-size: 11px; padding: 0 8px 8px; }
.ob-trade { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; padding: 1px 0; }
.ob-trade.buy { color: var(--green); }
.ob-trade.sell { color: var(--red); }
#obTick { width: 5.5rem; padding: 2px 4px; font-size: 11px; }

/* Тикет у правій рейці + картка підтвердження (не модалка поверх графіка) */
#ticketPanel { padding: 8px 10px; overflow: auto; }
#ticketSummary { font-size: 12px; color: var(--muted); }
#ticketSummary b { color: var(--text); font-family: var(--mono); }
#confirmCard {
  margin: 8px 10px; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel2);
}
#confirmCard[hidden] { display: none !important; }
#confirmCard h4 { margin: 0 0 8px; font-size: 13px; }
#confirmCard .confirm-rows { display: grid; gap: 4px; font-size: 12px; }
#confirmCard .confirm-rows div { display: flex; justify-content: space-between; gap: 8px; }
#confirmActions { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }
#riskPlaceholder { padding: 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }

#notesBox { flex: 1; min-height: 0; resize: none; border: 0; padding: 10px; background: transparent; }
#portfolioBox { padding: 10px; font-size: 13px; }

/* Палітра команд — зверху, не по центру графіка */
#commandPalette.cmd-palette {
  width: min(560px, 92vw); margin: 8vh auto auto; padding: 0;
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px;
}
#commandPalette::backdrop { background: var(--backdrop); }
#cmdQuery { width: 100%; border: 0; border-bottom: 1px solid var(--border); border-radius: 10px 10px 0 0; padding: 12px 14px; background: var(--panel2); }
.cmd-list { max-height: 50vh; overflow: auto; padding: 6px; }
.cmd-item { display: flex; gap: 10px; width: 100%; text-align: left; background: transparent; border: 0; color: var(--text); padding: 7px 8px; border-radius: 6px; }
.cmd-item.active, .cmd-item:hover { background: var(--hover); }
.cmd-group { color: var(--muted); font-size: 11px; min-width: 7.5rem; }

#screenerPanel .screener-filters { padding: 8px; }
#screenerPanel .screener-table-wrap { flex: 1; max-height: none; overflow: auto; }

/* Button colours live in components.css (tokens --accent-fill/--btn-fg/--on-long/--on-short). */
