/*
 * OT Terminal — Multi-Chart Layout System
 * -----------------------------------------------------------------
 * The chart workspace slot (`.ot-chart-workspace`, mounted by
 * ChartGrid.js) is unchanged at the outer level: a flex column with a
 * fixed-height global toolbar on top. What used to be a single
 * `.ot-chart-panes` block underneath is now `.ot-chart-grid` — a CSS
 * Grid container holding 1/2/4 `.ot-chart-panel` cells, each of which
 * is its own flex column reproducing the exact same
 * header/panes/time-axis structure Phase 1-12's single chart had
 * (see ChartPanel.js's _renderShell()).
 *
 * Visual language: dark charcoal panel wells (--ot-bg-inset, same as
 * Phase 1-12), a 1px gap between panels using the existing subtle
 * border token (not a heavy divider), and the one gold accent
 * (--ot-gold) reserved for the active-panel outline — no gradients,
 * no drop shadows, no third-party charting-platform visual borrowing,
 * consistent with the rest of OT Terminal's original design system.
 * -----------------------------------------------------------------
 */

.ot-chart-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  gap: 2px;
  background: var(--ot-border-subtle); /* shows through the gap as a thin divider */
}

.ot-chart-grid[data-ot-layout="1"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}
.ot-chart-grid[data-ot-layout="2h"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
}
.ot-chart-grid[data-ot-layout="2v"] {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
}
.ot-chart-grid[data-ot-layout="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.ot-chart-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--ot-bg-inset);
  outline: 1px solid transparent;
  outline-offset: -1px;
  transition: outline-color var(--ot-transition-fast);
}

/* Active-panel indicator: a subtle gold ring, never color alone in the
   accessibility sense — the panel's own header chip also gets a gold
   symbol color (below) as a second, non-color-only signal is not
   strictly needed here since outline is already a shape/border change,
   not a color-only distinction. */
.ot-chart-panel.is-active {
  outline-color: var(--ot-gold);
}

.ot-panel-header {
  flex: 0 0 26px;
  height: 26px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  font-size: var(--ot-fs-xs);
  color: var(--ot-text-secondary);
  border-bottom: 1px solid var(--ot-border-subtle);
  background: var(--ot-bg-panel);
  cursor: default;
  user-select: none;
}

.ot-panel-header__glyph {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border-radius: 3px;
  background: var(--ot-gold-wash);
  color: var(--ot-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ot-panel-header__symbol {
  color: var(--ot-text-primary);
  font-weight: 600;
}

.ot-chart-panel.is-active .ot-panel-header__symbol {
  color: var(--ot-gold-bright);
}

.ot-panel-header__tf {
  color: var(--ot-text-tertiary);
  text-transform: uppercase;
  font-family: var(--ot-font-mono);
}

.ot-panel-state {
  position: absolute;
  left: 0;
  right: 0;
  top: 26px;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 13, 0.88);
  color: var(--ot-text-secondary);
  font-size: var(--ot-fs-sm);
  text-align: center;
  padding: 16px;
  z-index: 6;
  pointer-events: none;
}

/* Chart-visibility fix: `display:flex` above overrode the [hidden]
   attribute, so this 88%-opaque scrim sat over every chart permanently
   and dimmed candles, axes and readouts. Respect [hidden]. */
.ot-panel-state[hidden] {
  display: none;
}

.ot-panel-state[data-ot-panel-state-kind="error"] {
  color: var(--ot-down);
}

/* ---- Layout selector (mounted into ChartToolbar's [data-ot-layout-slot]) ---- */

.ot-chart-toolbar__layout {
  display: flex;
  align-items: center;
}

.ot-layout-select {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  background: var(--ot-bg-input);
  border: 1px solid var(--ot-border-subtle);
  border-radius: var(--ot-radius-sm);
}

.ot-layout-select__btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  color: var(--ot-text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: background var(--ot-transition-fast), color var(--ot-transition-fast);
}
.ot-layout-select__btn svg {
  width: 15px;
  height: 15px;
}
.ot-layout-select__btn:hover {
  color: var(--ot-text-primary);
  background: var(--ot-bg-panel-raised);
}
.ot-layout-select__btn.is-active {
  color: var(--ot-gold);
  background: var(--ot-gold-wash);
}
.ot-layout-select__btn:focus-visible {
  outline: 1px solid var(--ot-gold);
  outline-offset: 1px;
}

.ot-chart-toolbar__clock {
  color: var(--ot-text-tertiary);
  font-size: var(--ot-fs-xs);
  margin-right: 4px;
  white-space: nowrap;
}

/* ===== Responsive =====
 * 1600px/1024px: the grid-template rules above already give 1 chart the
 * full workspace, 2h/2v an even 50/50 split, and 4 an even 2x2 split —
 * CSS Grid's `1fr` tracks handle this identically at any desktop/tablet
 * width, so no extra rules are needed down to 1024px (the existing
 * tablet breakpoint in responsive.css already narrows the watchlist and
 * auto-collapses the drawing rail, which is what keeps each panel's
 * available width reasonable at 1024px).
 *
 * Mobile (<=760px): per the brief, four (or even two) genuinely tiny
 * charts would be unusable, and the brief explicitly prefers NOT
 * forcing that. Decision (documented here and in README): single-chart
 * layout is untouched (one full-width, full-height chart, exactly like
 * Phase 1-12). Any multi-chart layout becomes a vertically scrollable
 * stack of full-width panels, each given a real usable minimum height
 * (340px / 62% of viewport height, whichever is larger) rather than a
 * cramped grid — every panel stays fully reachable by scrolling, none
 * of them get smaller than something a finger can actually use. */
@media (max-width: 760px) {
  .ot-chart-grid:not([data-ot-layout="1"]) {
    grid-template-columns: 1fr !important;
    grid-template-rows: none !important;
    grid-auto-flow: row;
    /* max(), not minmax(): in this scrolling grid there is never "free
       space" for a minmax() track to grow into, so rows stayed at 340px
       and the price pane got cramped. Each stacked chart is now 62vh. */
    grid-auto-rows: max(340px, 62vh);
    overflow-y: auto;
  }
  .ot-panel-header {
    flex-basis: 24px;
    height: 24px;
  }
  .ot-panel-state {
    top: 24px;
  }
  .ot-layout-select__btn {
    width: 24px;
    height: 24px;
  }
  .ot-chart-toolbar__clock {
    display: none;
  }
}
