/* Styling for the shared chart engine, the backtest trade chart, and the
 * "Анализ графиков" page. Reuses the color tokens from styles.css
 * (--bg, --panel, --line, --text, --muted, --accent, --accent-2,
 * --danger) instead of introducing a second palette. */

.tv-subtabs { display: flex; gap: 8px; margin: 10px 0 14px; }
.tv-subtab {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 7px 16px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 600;
}
.tv-subtab.active { color: var(--text); border-color: var(--accent); background: rgba(124,140,255,.12); }

.trade-row-highlight { background: rgba(124,140,255,.16) !important; }

.tc-toolbar, .ca-toolbar {
  display: flex; flex-wrap: wrap; gap: 14px; align-items: center;
  padding: 10px 0; font-size: 13px; color: var(--muted);
}
.tc-toolbar label, .ca-toolbar label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; }
.tc-toolbar select, .tc-toolbar input, .ca-toolbar select, .ca-toolbar input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 6px 8px; font-size: 13px;
}
.tc-toolbar .toggle, .ca-toolbar .toggle { flex-direction: row; align-items: center; gap: 6px; font-size: 12px; }
.ca-toolbar-spacer { flex: 1 1 auto; }

.tc-nav { display: flex; align-items: center; gap: 14px; margin: 4px 0 10px; }
.tc-status, .ca-status { min-height: 18px; font-size: 12px; color: var(--muted); }

.tc-chart-host { width: 100%; height: 460px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0c1019; }
.tc-card {
  margin-top: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2);
}
.tc-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tc-card-head h3 { margin: 0; font-size: 15px; }

.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 32px; height: 32px; border-radius: 7px; cursor: pointer; font-size: 15px;
}
.icon-btn.active { color: var(--accent); border-color: var(--accent); }
.icon-btn:hover { color: var(--text); }

/* ---------------------------------------------------- realtime indicator -- */
/* Its only mount point is the per-tile header (chart-tile.js), where it
 * sits between the tag and the fullscreen/close buttons. "compact" mode
 * (always on there) only shortens the delayed/no_trades labels - other
 * statuses like market_closed still render their full sentence ("Рынок
 * закрыт · последняя сделка HH:MM:SS"), which is wider than a phone-width
 * tile. Without min-width:0 + ellipsis here, that flex item refuses to
 * shrink below its content width (nowrap text's min-content IS its full
 * width) and pushes the close/fullscreen buttons out of the tile entirely
 * - truncate instead; the full text is always one tap away via the popover.
 * overflow stays visible here (unlike a typical truncation wrapper) because
 * .rt-popover is an absolutely-positioned sibling of the button inside this
 * same container - .rt-label's own overflow:hidden below is what clips the
 * text; clipping here too would also clip the popover. */
.rt-indicator { position: relative; align-self: center; min-width: 0; flex: 0 1 auto; }
.rt-indicator.hidden { display: none; }
.rt-indicator-btn {
  display: flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line);
  min-width: 0; max-width: 100%;
  border-radius: 20px; padding: 5px 10px; font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap;
}
.rt-indicator-btn:hover { border-color: var(--accent); }
.rt-dot { font-size: 9px; line-height: 1; flex: 0 0 auto; }
.rt-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Nominal state for this integration: MOEX's free feed is always ~15min
 * behind (measured, see docs/DYNAMIC_MARKET_DATA.md) - that's expected and
 * fully working, so it gets a calm/neutral color, not green ("actually
 * live") or red ("broken"). Only a delay *worse* than the measured baseline
 * (rti-warning) or a dead feed (rti-stale/rti-disconnected) escalate color. */
.rti-delayed .rt-dot { color: var(--accent); }
.rti-warning .rt-dot { color: #ffb454; }
.rti-warning .rt-indicator-btn { border-color: rgba(255,180,84,.4); }
.rti-stale .rt-dot, .rti-disconnected .rt-dot { color: var(--danger); }
.rti-stale .rt-indicator-btn, .rti-disconnected .rt-indicator-btn { border-color: rgba(255,112,129,.4); }
.rti-closed .rt-dot, .rti-connecting .rt-dot { color: var(--muted); }
.rti-replay .rt-dot { color: var(--accent-2); }
.rti-replay .rt-indicator-btn { border-color: rgba(77,212,172,.4); }
.rt-popover {
  position: absolute; z-index: 40; top: calc(100% + 6px); right: 0; min-width: 260px;
  background: #0d1220; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45); font-size: 12px;
}
.rt-popover.hidden { display: none; }
.rt-pop-row { display: flex; justify-content: space-between; gap: 14px; padding: 3px 0; color: var(--text); }
.rt-pop-row.muted { color: var(--muted); justify-content: flex-start; }
.rt-pop-row .muted { color: var(--muted); }
@media (max-width: 620px) {
  .rt-indicator-btn { padding: 5px 8px; }
  /* Stays right-anchored (unlike a left:0 flip) - this only ever mounts
   * inside a chart tile's own header (chart-tile.js), not the full-width
   * page toolbar, so anchoring from the indicator's own right edge is what
   * keeps the popover inside that tile's bounds instead of sliding past
   * its edge and getting clipped by .ca-tile's overflow:hidden. */
  .rt-popover { min-width: 220px; max-width: min(280px, calc(100vw - 40px)); }
}

/* ---------------------------------------------------------- Анализ графиков -- */

.charts-page-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.charts-page-head h2 { display: flex; align-items: center; gap: 10px; }
.star-btn { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.star-btn:hover { color: #ffce54; }

/* #chartsRoot is a full-height flex column (toolbar, then the workspace
 * filling everything else) - the charts tab gives it the full viewport
 * below the app's tab bar (see styles.css "charts terminal full-bleed"),
 * so this never depends on any fixed pixel height. */
#chartsRoot { display: flex; flex-direction: column; gap: 8px; height: 100%; min-height: 0; }

/* Left tool rail | center column (chart + bottom panel) | watchlist, with
 * two thin drag handles for the resizable dimensions (bottom panel height,
 * watchlist width). Plain flexbox, not CSS grid - the resizable sizes are
 * plain inline styles set by chart-analysis.js's _wireDrag, which is far
 * simpler to reason about than smuggling them through custom properties in
 * a grid-template. */
.ca-workspace { display: flex; flex-direction: row; gap: 8px; flex: 1 1 auto; min-height: 0; }
body.ca-resizing { cursor: grabbing; user-select: none; }

.ca-center { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; min-height: 0; }

.ca-resize-h {
  flex: 0 0 auto; height: 9px; margin: -1px 0; cursor: row-resize; position: relative; z-index: 2;
}
.ca-resize-h::after { content: ""; position: absolute; left: 0; right: 0; top: 4px; height: 2px; background: var(--line); border-radius: 2px; }
.ca-resize-h:hover::after, .ca-resize-h.dragging::after { background: var(--accent); }

.ca-resize-v {
  flex: 0 0 auto; width: 9px; margin: 0 -1px; cursor: col-resize; position: relative; z-index: 2;
}
.ca-resize-v::after { content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px; background: var(--line); border-radius: 2px; }
.ca-resize-v:hover::after, .ca-resize-v.dragging::after { background: var(--accent); }

/* Real Fullscreen API target is #chartsRoot itself (see FullscreenController
 * in chart-engine/fullscreen.js) - only ONE element in the chain gets
 * position:fixed. Previously both #chartsRoot *and* its .ca-workspace child
 * had position:fixed;inset:0 with the same z-index, which - per CSS paint
 * order - made the (later, positioned) workspace box render on top of the
 * toolbar above it, permanently hiding the exit-fullscreen button. */
#chartsRoot.is-fullscreen {
  position: fixed; inset: 0; z-index: 9999; background: var(--bg);
  padding: 12px; margin: 0;
}
/* The browser already renders :fullscreen elements filling the viewport;
 * this mirrors the same box for the no-Fullscreen-API CSS fallback path. */
#chartsRoot:fullscreen { width: 100vw; height: 100vh; }

.ca-tools {
  flex: 0 0 auto; display: flex; flex-direction: column; gap: 6px; padding: 8px 4px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
  overflow-y: auto;
}
.ca-tool-btn {
  width: 42px; height: 38px; border-radius: 8px; border: 1px solid transparent; background: transparent;
  color: var(--muted); font-size: 16px; cursor: pointer;
}
.ca-tool-btn:hover { background: rgba(255,255,255,.05); color: var(--text); }
.ca-tool-btn.active { background: rgba(124,140,255,.16); border-color: var(--accent); color: var(--accent); }
.ca-tool-danger { color: var(--danger); margin-top: 8px; border-top: 1px solid var(--line); border-radius: 0 0 8px 8px; }

.ca-chart-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 auto; min-height: 0; }

/* -------------------------------------------------------- multi-chart grid -- */

.ca-layout-switch { display: flex; gap: 4px; }
.ca-layout-btn {
  width: 34px; height: 30px; border-radius: 7px; border: 1px solid var(--line); background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.ca-layout-btn:hover { border-color: var(--accent); }
.ca-layout-btn.active { background: rgba(124,140,255,.16); border-color: var(--accent); }
.ca-layout-icon { display: grid; gap: 2px; width: 16px; height: 12px; }
.ca-layout-icon i { background: var(--muted); border-radius: 1px; }
.ca-layout-btn.active .ca-layout-icon i { background: var(--accent); }
/* Asymmetric "1 big + 2 small" layout icon - grid-template's repeat() can't
 * express this, so it's a small flex shape instead of the generic <i> grid. */
.ca-layout-icon-3 { display: flex; gap: 2px; width: 16px; height: 12px; }
.ca-layout-icon-3 .ca-li-big { flex: 2 0 0; background: var(--muted); border-radius: 1px; }
.ca-layout-icon-3 .ca-li-col { flex: 1 0 0; display: flex; flex-direction: column; gap: 2px; }
.ca-layout-icon-3 .ca-li-col i { flex: 1; background: var(--muted); border-radius: 1px; }
.ca-layout-btn.active .ca-layout-icon-3 .ca-li-big,
.ca-layout-btn.active .ca-layout-icon-3 .ca-li-col i { background: var(--accent); }
.ca-layout-icon-3-rev { flex-direction: row-reverse; }

.ca-tile-grid { display: grid; gap: 8px; flex: 1 1 auto; min-height: 0; }
.ca-tile-grid.layout-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.ca-tile-grid.layout-2v { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.ca-tile-grid.layout-2h { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.ca-tile-grid.layout-3 {
  grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr;
  grid-template-areas: "big top" "big bottom";
}
.ca-tile-grid.layout-3 .ca-tile:nth-child(1) { grid-area: big; }
.ca-tile-grid.layout-3 .ca-tile:nth-child(2) { grid-area: top; }
.ca-tile-grid.layout-3 .ca-tile:nth-child(3) { grid-area: bottom; }
.ca-tile-grid.layout-3b {
  grid-template-columns: 1fr 2fr; grid-template-rows: 1fr 1fr;
  grid-template-areas: "top big" "bottom big";
}
.ca-tile-grid.layout-3b .ca-tile:nth-child(1) { grid-area: big; }
.ca-tile-grid.layout-3b .ca-tile:nth-child(2) { grid-area: top; }
.ca-tile-grid.layout-3b .ca-tile:nth-child(3) { grid-area: bottom; }
.ca-tile-grid.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.ca-tile-grid.layout-6 { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; }
/* Only one chart on screen: the close button would have nothing to close
 * down to, so hide it instead of guarding every click handler for it. */
.ca-tile-grid.layout-1 .ca-tile-close { display: none; }

.ca-tile {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden;
  border: 2px solid var(--line); border-radius: 10px; background: #0c1019;
}
.ca-tile.active { border-color: var(--accent); }
.ca-tile.is-fullscreen { position: fixed; inset: 0; z-index: 9999; padding: 8px; background: var(--bg); border-radius: 0; }
.ca-tile.is-fullscreen .ca-tile-chart-host { flex: 1 1 auto; height: auto !important; }
.ca-tile:fullscreen { width: 100vw; height: 100vh; }

/* Minimal per-tile identity header (Stage 2): every command control moved
 * up to the single workspace toolbar (#caToolbar) - this is just enough to
 * tell tiles apart in a multi-chart layout and to fullscreen/close one. */
.ca-tile-header {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 12px;
  background: var(--panel-2); border-bottom: 1px solid var(--line); cursor: default; position: relative; min-width: 0;
}
/* flex-shrink:0 - short and fixed ("SBER · 1д"), so all the squeeze from a
 * narrow tile goes to the realtime indicator's label (which has its own
 * ellipsis and a popover with the full text) instead of truncating the
 * tile's own identity first. */
.ca-tile-tag { font-weight: 700; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto; }
.ca-tile-spacer { flex: 1; min-width: 4px; }
.ca-tile-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; line-height: 1; border-radius: 6px; min-width: 30px; min-height: 30px; }
.ca-tile-btn:hover { color: var(--text); background: rgba(255,255,255,.05); }
.ca-tile-close:hover { color: var(--danger); }
.ca-tile-realtime-slot .rt-indicator-btn { padding: 4px 8px; font-size: 11px; }
.ca-tile-chart-host { flex: 1 1 auto; min-height: 0; position: relative; }
.ca-tile-status {
  position: absolute; left: 10px; top: 10px; z-index: 3; font-size: 12px; color: var(--muted);
  background: rgba(12,16,25,.85); padding: 4px 10px; border-radius: 6px; pointer-events: none;
}
.ca-tile-status.hidden { display: none; }
.ca-popover-right { left: auto; right: 0; }
.ca-more-item {
  display: block; width: 100%; text-align: left; background: none; border: none; color: var(--text);
  padding: 8px 6px; font-size: 13px; cursor: pointer; border-radius: 6px;
}
.ca-more-item:hover { background: rgba(255,255,255,.06); }
.ca-more-group { display: flex; flex-direction: column; gap: 6px; }
.ca-more-heading { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 2px; }
.ca-more-sep { height: 1px; background: var(--line); margin: 8px 0; }
.ca-more-toggle { display: flex; flex-direction: row; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text); padding: 3px 0; cursor: pointer; }

/* --------------------------------------------------- unified toolbar (Stage 2) -- */

.ca-toolbar-unified {
  display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; min-width: 0;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
}
/* overflow stays visible (not hidden) so popovers anchored to a child
 * button (.ca-popover, position:absolute) never get clipped - items that
 * don't fit are hidden proactively by _recalcToolbarOverflow() via
 * .gt-hidden instead of relying on clipping, so nowrap alone is enough to
 * keep this a single row. */
.gt-scroll { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; min-width: 0; overflow: visible; flex: 1 1 auto; }
.gt-hidden { display: none !important; }
.gt-select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 7px;
  padding: 6px 8px; font-size: 12.5px; height: 32px; flex: 0 0 auto;
}
.gt-ticker { min-width: 90px; max-width: 150px; font-weight: 700; }
.gt-tf { min-width: 56px; max-width: 76px; }
.gt-type { min-width: 84px; max-width: 130px; }
.gt-name { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; flex: 0 1 auto; }
.gt-price { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; flex: 0 0 auto; }
.gt-change { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; flex: 0 0 auto; }
.gt-menu { position: relative; flex: 0 0 auto; }
.gt-btn {
  background: transparent; border: 1px solid var(--line); color: var(--muted); cursor: pointer;
  font-size: 12px; padding: 6px 10px; border-radius: 7px; height: 32px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px;
}
.gt-btn:hover { color: var(--text); border-color: var(--accent); }
.gt-btn:disabled { opacity: .4; cursor: not-allowed; }
.gt-more { margin-left: auto; }
.gt-badge {
  position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); box-shadow: 0 0 0 2px var(--panel-2);
}
.gt-badge.hidden { display: none; }

/* _recalcToolbarOverflow() only collapses [data-key] buttons into the "Ещё"
 * menu - the ticker select, name/price/change readout, timeframe/chart-type
 * selects and the layout/fullscreen buttons are all data-priority-exempt
 * (never collapsed) because they're core controls. On phone widths that
 * fixed group alone is wider than the viewport, and since .gt-scroll keeps
 * overflow:visible (popovers would get clipped otherwise, see above), the
 * excess used to spill out of #caToolbar and widen the whole page instead
 * of staying inside the toolbar row. Shrink/drop the least essential of
 * that exempt group so it fits real phone widths without touching the
 * overflow:visible popover behavior. */
@media (max-width: 620px) {
  .gt-name { display: none; }
  .gt-change { display: none; }
  .gt-ticker { min-width: 72px; max-width: 100px; }
  .gt-tf { min-width: 46px; max-width: 58px; }
  .gt-type { min-width: 60px; max-width: 80px; }
  .gt-scroll { gap: 4px; }
  .ca-toolbar-unified { padding: 6px; gap: 4px; }
  .gt-scroll .icon-btn { width: 30px; height: 30px; }
  /* Multi-tile grid layouts (2/3/4/6 charts) aren't practical on a phone-width
   * screen - the picker is dropped here, not just shrunk, because it's the
   * single largest remaining exempt control and dropping it is what closes
   * the gap to real phone widths (~375px) after the shrinks above. */
  #gtLayoutMenu { display: none; }
}
@media (max-width: 340px) {
  /* Legacy/small phones (iPhone SE 1st-gen and similar, 320px CSS width) -
   * the 620px shrink above already closes almost all of the gap; this trims
   * the last ~15-20px so the toolbar still fits in one row without scroll. */
  .gt-ticker { min-width: 64px; max-width: 84px; }
  .gt-tf { min-width: 40px; max-width: 50px; }
  .gt-type { min-width: 52px; max-width: 66px; }
  .gt-scroll { gap: 3px; }
  .ca-toolbar-unified { padding: 5px; gap: 3px; }
}

/* ---------------------------------------------------- layout popover (Stage 3) -- */

.ca-popover-layouts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; min-width: 260px; }
.ca-popover-layouts.hidden { display: none; }
.ca-layout-thumb {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer; color: var(--muted);
}
.ca-layout-thumb:hover { border-color: var(--accent); color: var(--text); }
.ca-layout-thumb.active { border-color: var(--accent); background: rgba(124,140,255,.12); color: var(--text); }
.ca-layout-thumb .ca-layout-icon,
.ca-layout-thumb .ca-layout-icon-3 { width: 34px; height: 24px; }
.ca-layout-thumb-label { font-size: 10.5px; text-align: center; line-height: 1.25; }

/* -------------------------------------------------- settings dialog (Stage 5) -- */

.ca-settings-modal { width: min(560px, calc(100% - 32px)); }
.ca-settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px 14px; }
.ca-settings-grid input[type=color] { width: 100%; height: 32px; padding: 2px; }
.ca-settings-grid input[type=number], .ca-settings-grid select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 7px 8px; font-size: 13px;
}

/* -------------------------------------------------------- alerts (Stage 9) -- */

.ca-popover-wide { min-width: 300px; max-width: 340px; }
.alert-form { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.alert-form input, .alert-form select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 12px; flex: 1 1 100px;
}
.alert-form #alAdd { flex: 0 0 auto; }
.alert-sound-toggle { margin-bottom: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.alert-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.alert-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; background: var(--panel); font-size: 12px; }
.alert-row-off { opacity: .5; }
.alert-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alert-row-actions { display: flex; gap: 4px; flex: 0 0 auto; }
.alert-row-actions button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.alert-row-actions button:hover { color: var(--text); }

.alert-toast-host { position: fixed; top: 16px; right: 16px; z-index: 9998; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.alert-toast {
  background: #16203a; border: 1px solid rgba(124,140,255,.4); border-radius: 10px; padding: 10px 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.45); min-width: 220px; opacity: 0; transform: translateY(-8px); transition: opacity .25s, transform .25s;
}
.alert-toast.show { opacity: 1; transform: translateY(0); }
.alert-toast-title { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.alert-toast-body { font-size: 12px; color: var(--muted); }

/* Range popover contents (quick presets + custom period form). */
.ca-range-custom { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.ca-range-custom.hidden { display: none; }
.ca-range-custom label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.ca-range-custom input[type=date] {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 12px;
}
.ca-range-custom-toggle { margin-top: 6px; font-size: 12px; }
.ca-range-reset { margin-top: 6px; font-size: 12px; color: var(--danger); }
.link-btn { background: none; border: none; color: var(--accent); cursor: pointer; padding: 2px 0; font-size: 12px; text-align: left; }
.link-btn:hover { text-decoration: underline; }

/* -------------------------------------------------- mobile settings sheet -- */
.ca-sheet-backdrop { position: fixed; inset: 0; background: rgba(5,7,12,.6); z-index: 90; display: flex; align-items: flex-end; }
.ca-sheet {
  width: 100%; max-height: 80vh; overflow-y: auto; background: var(--panel-2); border-radius: 16px 16px 0 0;
  padding: 10px 16px 20px; border: 1px solid var(--line); border-bottom: none;
}
.ca-sheet-handle { width: 40px; height: 4px; background: var(--line); border-radius: 3px; margin: 4px auto 12px; }
.ca-sheet h4 { margin: 0 0 12px; font-size: 14px; }
.ca-sheet-body { display: flex; flex-direction: column; gap: 10px; }
.ca-sheet-body .ca-tile-overflow.in-sheet { flex-direction: column; align-items: stretch; }
.ca-sheet-body .ca-tile-select, .ca-sheet-body .ca-tile-btn2 { width: 100%; max-width: none; height: 44px; font-size: 13px; }
.ca-sheet-body .ca-tile-menu { width: 100%; }
.ca-sheet-body .ca-popover { position: static; box-shadow: none; margin-top: 8px; width: 100%; }
.ca-tile-live-btn {
  position: absolute; right: 10px; bottom: 10px; z-index: 3;
  background: var(--accent); color: #fff; border: none; border-radius: 999px;
  padding: 6px 14px; font-size: 11.5px; font-weight: 700; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,.35); transition: opacity .12s, transform .12s;
}
.ca-tile-live-btn:hover { transform: translateY(-1px); }
.ca-tile-live-btn.hidden { display: none; }

@media (max-width: 980px) {
  .ca-tile-grid.layout-2h,
  .ca-tile-grid.layout-3,
  .ca-tile-grid.layout-4,
  .ca-tile-grid.layout-6 { grid-template-columns: 1fr; }
  .ca-tile-grid.layout-3 { grid-template-rows: repeat(3, minmax(220px, 1fr)); grid-template-areas: "big" "top" "bottom"; }
  .ca-tile-grid.layout-4 { grid-template-rows: repeat(4, minmax(220px, 1fr)); }
  .ca-tile-grid.layout-6 { grid-template-rows: repeat(6, minmax(220px, 1fr)); }
  .ca-tile-grid.layout-2v { grid-template-rows: repeat(2, minmax(220px, 1fr)); }
  /* .ca-tile-grid normally stretches to fill .ca-chart-col via flex (see
   * above #chartsRoot/.ca-workspace/.ca-center chain) - this is just a
   * floor for the rare case that chain doesn't resolve to a definite
   * height (e.g. JS failed to add body.charts-active), so the chart canvas
   * never collapses to a near-0px sliver ("black screen" regression). */
  .ca-tile-grid { min-height: 440px; }
  .ca-tile-ohlc { display: none; }
  /* #caBottom's height is either BOTTOM_HEIGHT_DEFAULT or a value dragged
   * and persisted (localStorage) on a previous, wider visit - up to
   * BOTTOM_HEIGHT_MAX (560px). On a narrow/short viewport that inline
   * height plus the .ca-tile-grid floor above no longer fit .ca-chart-col's
   * flex column together, and since neither box clips the other, they
   * render on top of each other (chart canvas under the Свойства/Объекты
   * panel) instead of one of them shrinking. Cap the panel responsively so
   * the two always coexist regardless of what was persisted. */
  .ca-bottom { max-height: min(50vh, 420px); }
}
@media (max-width: 620px) {
  .ca-tile-change { display: none; }
  .ca-tile-grid { min-height: 220px; }
  .ca-bottom { max-height: 38vh; }
}
.ca-range-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.range-preset {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.range-preset:hover { color: var(--text); border-color: var(--accent); }

/* -------------------------------------------- bottom "Свойства/Объекты" -- */
/* Lives under the chart grid (not between the chart and the watchlist, which
 * used to steal width from the chart itself) - resizable via .ca-resize-h
 * above it, collapsible to just its tab header via .collapsed. */
.ca-bottom {
  flex: 0 0 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
}
.ca-bottom.collapsed { height: 38px !important; }
.ca-bottom.collapsed .ca-bottom-body { display: none; }
.ca-bottom-head { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.ca-bottom.collapsed .ca-bottom-head { border-bottom: none; }
.ca-bottom-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 12px; }

.ca-side-tabs { display: flex; gap: 6px; }
.ca-side-tab { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 7px; padding: 6px 14px; font-size: 12px; cursor: pointer; }
.ca-side-tab.active { color: var(--text); border-color: var(--accent); background: rgba(124,140,255,.12); }
.ca-side-panel { display: flex; flex-flow: row wrap; align-items: flex-start; gap: 10px 16px; font-size: 13px; }
.ca-side-panel.hidden { display: none; }
.ca-side-panel h4 { margin: 0; font-size: 13px; color: var(--text); flex-basis: 100%; }
.ca-side-panel > .muted-note { flex-basis: 100%; }
.ca-side-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); width: 160px; }
.ca-side-panel label.toggle { flex-direction: row; align-items: center; width: auto; }
.ca-side-panel input[type=text], .ca-side-panel input[type=number], .ca-side-panel textarea {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 8px;
}
.ca-side-panel input[type=color] { width: 100%; height: 30px; padding: 2px; }
.ca-side-panel > button { flex: 0 0 auto; align-self: flex-end; }
.ca-prop-coords, .ca-prop-tfvis { flex-basis: 100%; display: flex; flex-direction: column; gap: 3px; }
.ca-coord-row { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.ca-tf-grid { display: grid; grid-template-columns: repeat(4, auto); gap: 4px 12px; margin-top: 4px; }
.ca-tf-grid.hidden { display: none; }

/* Objects list: a real list (not label/row wrap), so it always spans full width. */
#caObjects.ca-side-panel { flex-direction: column; flex-wrap: nowrap; }
.ca-object-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; border-radius: 6px; cursor: pointer; width: 100%; }
.ca-object-row:hover { background: rgba(255,255,255,.04); }
.ca-object-row.active { background: rgba(124,140,255,.14); }
.ca-object-actions button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 3px; }

/* --------------------------------------------------------- right watchlist -- */

#caWatchlistToggleBtn { display: none; }

.ca-watchlist {
  flex: 0 0 auto; width: 280px; min-width: 200px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2);
  display: flex; flex-direction: column; overflow: hidden; min-height: 0;
}
/* !important: chart-analysis.js sets an inline width (the resize handle,
 * and the persisted saved width) which would otherwise always beat this
 * class rule regardless of selector specificity. */
.ca-watchlist.wl-collapsed { width: 44px !important; min-width: 0; }
.ca-watchlist.wl-collapsed .wl-header input,
.ca-watchlist.wl-collapsed .wl-tabs,
.ca-watchlist.wl-collapsed .wl-col-headers,
.ca-watchlist.wl-collapsed .wl-list-viewport,
.ca-watchlist.wl-collapsed .wl-info-panel { display: none; }

.wl-header { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.wl-header input[type=search] {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 6px 8px; font-size: 12px;
}
.wl-tabs { display: flex; gap: 4px; padding: 8px 10px 0; flex: 0 0 auto; flex-wrap: wrap; }
.wl-tab {
  flex: 1 1 auto; background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 7px; padding: 5px 4px; font-size: 10.5px; cursor: pointer; white-space: nowrap;
}
.wl-tab.active { color: var(--text); border-color: var(--accent); background: rgba(124,140,255,.12); }
.wl-tab-add { flex: 0 0 auto; width: 26px; font-weight: 700; }

.wl-col-headers {
  display: grid; grid-template-columns: 18px 1fr 62px 62px 56px; gap: 4px; align-items: center;
  padding: 8px 10px 4px; font-size: 10px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); flex: 0 0 auto;
}
.wl-col-headers span { cursor: pointer; text-align: right; }
.wl-col-headers .wl-col-ticker { text-align: left; grid-column: 1 / span 2; }
.wl-col-headers span.active { color: var(--accent); }
.wl-col-headers span.active::after { content: "▾"; margin-left: 2px; }
.wl-col-headers span.active.desc::after { content: "▴"; }

.wl-list-viewport { flex: 1 1 auto; overflow-y: auto; position: relative; min-height: 0; padding: 0 6px; }
.wl-list-spacer { position: relative; }
.wl-list-rows { position: absolute; top: 0; left: 0; right: 0; will-change: transform; }
.wl-row {
  display: grid; grid-template-columns: 18px 1fr 62px 62px 56px; gap: 4px; align-items: center;
  padding: 0 4px; border-radius: 7px; cursor: pointer; font-size: 12px;
}
.wl-row:hover { background: rgba(255,255,255,.04); }
.wl-row.active { background: rgba(124,140,255,.14); }
.wl-star { background: none; border: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 0; width: 18px; flex: none; }
.wl-star.active { color: #ffce54; }
.wl-ticker { font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-num { text-align: right; font-variant-numeric: tabular-nums; font-size: 11.5px; color: var(--text); }
.wl-empty { padding: 12px 6px; }

.wl-context-menu {
  position: absolute; z-index: 60; min-width: 200px; background: #0d1220; border: 1px solid var(--line);
  border-radius: 10px; padding: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.45); font-size: 12.5px;
}
.wl-context-menu.hidden { display: none; }

.wl-info-panel { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 10px 12px; max-height: 42%; overflow-y: auto; }
.wl-info-title { font-weight: 700; font-size: 13px; margin-bottom: 6px; }
.wl-info-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-size: 11.5px; color: var(--text); }
.wl-info-row .muted { color: var(--muted); }
.wl-info-loading { padding: 4px 0; }

.wl-mobile-backdrop { display: none; }

@media (max-width: 980px) {
  .ca-watchlist { display: none; }
  .ca-watchlist.wl-mobile-open {
    display: flex; position: fixed; inset: 0 0 0 auto; width: min(320px, 86vw); height: 100vh;
    z-index: 75; border-radius: 0; border-left: 1px solid var(--line);
  }
  .ca-watchlist.wl-mobile-open.wl-collapsed { width: min(320px, 86vw); }
  .ca-watchlist.wl-mobile-open.wl-collapsed .wl-header input,
  .ca-watchlist.wl-mobile-open.wl-collapsed .wl-tabs,
  .ca-watchlist.wl-mobile-open.wl-collapsed .wl-col-headers,
  .ca-watchlist.wl-mobile-open.wl-collapsed .wl-list-viewport,
  .ca-watchlist.wl-mobile-open.wl-collapsed .wl-info-panel { display: revert; }
  #caWatchlistToggleBtn { display: inline-flex; align-items: center; justify-content: center; }
  .wl-mobile-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(5,7,12,.6); z-index: 74; }
}

.ca-indicator-menu, .ca-template-menu { position: relative; }
.ca-popover {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 220px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,.4);
}
/* Same-specificity override: .ca-popover-right (defined earlier in this
 * file, for the tile/workspace "more" menus anchored at the right edge)
 * would otherwise lose its left:auto;right:0 to this rule's left:0 by
 * source order alone, letting a right-edge-anchored popover render mostly
 * off-viewport - see the "Ещё" menu bug this fixes. Combined-class selector
 * beats single-class regardless of order. */
.ca-popover.ca-popover-right { left: auto; right: 0; }
.ca-indicator-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 4px; font-size: 13px; }
/* flex-direction: row is explicit (not just the flex default) because
 * these popovers live inside .ca-toolbar-unified, which still matches the
 * older ".ca-toolbar label { flex-direction: column }" rule - that
 * property is never touched by this rule otherwise, so the cascade would
 * keep applying the older column value even though this rule "wins" on
 * every property it does set. */
.ca-indicator-row label { display: flex; flex-direction: row; align-items: center; gap: 8px; flex: 1; }
.ca-ind-settings {
  display: flex; flex-direction: column; gap: 8px; padding: 8px 10px; margin: 2px 0 6px;
  background: var(--panel); border-radius: 8px; border: 1px solid var(--line);
}
.ca-ind-settings.hidden { display: none; }
.ca-ind-settings label { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.ca-ind-settings input[type=number] { width: 70px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 6px; }
.ca-ind-settings input[type=color] { width: 50px; height: 26px; padding: 1px; }
.ca-ind-settings select { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 4px 6px; }
.ca-template-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 2px; }
.ca-ws-save-row { display: flex; gap: 6px; margin-bottom: 8px; }
.ca-ws-save-row input {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 6px 8px; font-size: 12px;
}
.ca-ws-actions { display: flex; gap: 2px; flex: 0 0 auto; }

.ca-modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,7,12,.72); display: flex; align-items: center; justify-content: center;
  z-index: 80;
}
.ca-modal-backdrop.hidden { display: none; }
.ca-modal {
  width: min(560px, calc(100% - 32px)); max-height: 86vh; overflow: auto; background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 14px; padding: 24px; position: relative; display: flex; flex-direction: column; gap: 10px;
}
.ca-modal label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ca-modal input, .ca-modal textarea {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 8px 10px; font: inherit;
}
.ca-warning { background: rgba(255,180,84,.12); border: 1px solid rgba(255,180,84,.35); color: #ffb454; border-radius: 8px; padding: 10px 12px; font-size: 12.5px; }

@media (max-width: 980px) {
  /* Watchlist becomes the off-canvas drawer above (#caWatchlistToggleBtn) -
   * nothing left to drag it against. */
  .ca-resize-v { display: none; }
}

/* ---------------------------------------------------------- Market Replay -- */

.mr-setup { max-width: 900px; }
.mr-setup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; margin-bottom: 10px; }
.mr-setup-grid label, .mr-setup-actions { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.mr-setup-grid input, .mr-setup-grid select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; min-height: 40px;
}
.mr-tick-note { max-width: 700px; margin: 4px 0 14px; }
.mr-setup-actions { margin-bottom: 8px; }
.mr-setup-actions .primary { width: auto; padding: 12px 22px; }
.mr-setup-message { min-height: 18px; color: var(--danger); font-size: 12.5px; margin-bottom: 14px; }
.mr-sessions { margin-top: 10px; }
.mr-sessions h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.mr-session-row {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: baseline; width: 100%; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  color: var(--text); cursor: pointer; margin-bottom: 6px; font-size: 13px; min-height: 44px;
}
.mr-session-row:hover { border-color: var(--accent); }

.mr-controlbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.mr-cb-left, .mr-cb-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mr-clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.mr-cb-right .secondary, .mr-cb-right .danger { width: auto; padding: 8px 12px; font-size: 12px; min-height: 38px; }

.mr-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.mr-chart-col { min-width: 0; }
.mr-chart-host { width: 100%; min-width: 0; height: 480px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0c1019; }
.mr-transport { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; }
.mr-transport button { width: auto; margin-top: 0; padding: 10px 14px; font-size: 13px; min-height: 40px; }
.mr-speed-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.mr-speed-inline select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 7px;
  padding: 8px 10px; min-height: 40px; font-size: 13px;
}
.mr-goto { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: center; }
.mr-goto.hidden { display: none; }
.mr-goto input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 7px;
  padding: 8px 10px; min-height: 40px; font-size: 13px;
}
.mr-goto input[type="number"] { width: 80px; }
.mr-goto button { width: auto; margin-top: 0; padding: 8px 12px; font-size: 12px; min-height: 40px; }

.mr-side-col { display: flex; flex-direction: column; gap: 12px; }
.mr-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--panel-2); }
.mr-card h4 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.mr-account-row { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; font-size: 13px; }
.mr-account-total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; font-size: 14px; }

.mr-order label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.mr-order input {
  background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 7px;
  padding: 9px 10px; font-size: 13px; min-height: 40px;
}

.mr-position-status { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.mr-no-position { color: var(--muted); font-size: 13px; }
.mr-position-status-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 14px; }

.mr-order-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; }
.mr-order-buttons button {
  width: 100%; margin-top: 0; padding: 11px 0; border-radius: 8px; font-weight: 700; font-size: 13px;
  border: 1px solid var(--line); cursor: pointer; min-height: 44px; transition: background .15s ease, opacity .15s ease;
}
.mr-buy { background: rgba(77,212,172,.16); color: var(--accent-2); border-color: rgba(77,212,172,.4) !important; }
.mr-buy:hover:not(:disabled) { background: rgba(77,212,172,.26); }
.mr-sell { background: rgba(255,112,129,.14); color: var(--danger); border-color: rgba(255,112,129,.4) !important; }
.mr-sell:hover:not(:disabled) { background: rgba(255,112,129,.24); }
.mr-order-buttons button:disabled { opacity: .4; cursor: not-allowed; filter: grayscale(.4); }
.mr-order-message { min-height: 16px; color: var(--danger); font-size: 12px; margin-top: 8px; }

.mr-trades-list { max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 8px; }
.mr-trade-row {
  display: flex; flex-direction: column; gap: 4px; font-size: 12px; padding: 8px 10px;
  border-radius: 8px; border: 1px solid var(--line); border-left: 3px solid var(--line);
}
.mr-trade-buy { border-left-color: var(--accent-2); }
.mr-trade-sell { border-left-color: var(--danger); }
.mr-trade-main { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.mr-trade-buy .mr-trade-action { color: var(--accent-2); }
.mr-trade-sell .mr-trade-action { color: var(--danger); }
.mr-trade-qty, .mr-trade-price { color: var(--text); font-weight: 400; }
.mr-trade-meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.mr-trade-pnl { font-weight: 700; }
.mr-trade-side { font-weight: 700; padding: 2px 6px; border-radius: 6px; font-size: 11px; }
.mr-side-long { color: var(--accent-2); background: rgba(77,212,172,.14); }
.mr-side-short { color: var(--danger); background: rgba(255,112,129,.14); }
.mr-exit-reason { color: var(--muted); font-size: 11px; }

@media (max-width: 980px) {
  .mr-layout { grid-template-columns: minmax(0, 1fr); }
  .mr-chart-host { height: 360px; }
}
@media (max-width: 560px) {
  .mr-setup-grid { grid-template-columns: 1fr 1fr; }
  .mr-transport { justify-content: stretch; }
  .mr-transport button { flex: 1 1 calc(50% - 8px); }
  .mr-order-buttons { grid-template-columns: 1fr 1fr; }
  .mr-controlbar { flex-direction: column; align-items: flex-start; }
}
