/* Charts page shell. Dark panels separate controls from the plot, and prices
   use tabular figures. The overlay layer builds on this shell. */

/* NOTHING OUTSIDE THE PAGE MAY ADD HEIGHT TO IT.
   The app shell is `min-height: 100vh` and the browser's default body margin
   is 8px, so a page that is itself 100dvh tall came out 8px lower than the
   viewport and the document scrolled by 16. On a page whose whole point is
   that the chart fills the screen and the axis sits on the bottom edge, that
   is a scrollbar over a chart that is already the right size. The margin goes,
   and above the stacking breakpoint the document is pinned as well. */
html[data-charts-page="1"] body { margin: 0; }

@media (min-width: 1101px) {
  html[data-charts-page="1"],
  html[data-charts-page="1"] body { overflow: hidden; }
}

/* The page owns the viewport height and never scrolls as a whole: the chart
   well takes the slack, the sidebar scrolls inside its own column. A trader
   should not have to scroll to reach the timeframe rail. */
.charts-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 8px;
  padding: 8px;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--banana-background);
  color: var(--banana-text-body);
  font-family: var(--banana-font-body);
}

/* Collapsing the panels is a grid change with no transition on it. A width
   that animates would need the chart resized on every frame of the animation
   or on transitionend, and both are ways to end up one frame out of step with
   the layout. Instant is also what reduced motion would have asked for. */
.charts-page--side-collapsed { grid-template-columns: minmax(0, 1fr); }
.charts-page--side-collapsed .charts-side { display: none; }

@media (max-width: 1100px) {
  .charts-page {
    grid-template-columns: minmax(0, 1fr);
    height: auto;
    overflow: visible;
  }
}

.charts-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

/* Screen reader only. Labels, help text and the live region that carries the
   keyboard readout all live here. */
.charts-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* One focus treatment for the whole page, and it is a ring rather than a
   color change so it reads on the lime buttons as well as the dark ones. */
.charts-page :focus-visible {
  outline: 2px solid var(--banana-primary-fixed);
  outline-offset: 2px;
}

/* ── header ─────────────────────────────────────────────────────────────── */

.charts-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 14px;
  background: var(--banana-surface-container-low);
  border-radius: var(--banana-radius);
}

.charts-head__id {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  min-width: 0;
}

.charts-symbol { position: relative; }

.charts-symbol__input {
  width: 6.5ch;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--banana-text-body);
  font-family: var(--banana-font-heading);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.charts-symbol__input:focus { outline: none; }
.charts-symbol__input:focus-visible {
  outline: none;
  box-shadow: 0 2px 0 0 var(--banana-primary-fixed);
}

.charts-head__quote {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--banana-font-mono);
  font-variant-numeric: tabular-nums;
}

.charts-head__last { font-size: 22px; color: var(--banana-on-surface); }
.charts-head__chg { font-size: 14px; color: var(--banana-on-surface-variant); }
.charts-head__chg[data-dir="up"] { color: var(--banana-chart-call); }
.charts-head__chg[data-dir="down"] { color: var(--banana-chart-put); }

.charts-head__stats {
  display: flex;
  gap: 18px;
  margin: 0;
  flex-wrap: wrap;
}

.charts-stat { display: flex; flex-direction: column; gap: 2px; }

.charts-stat dt {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--banana-on-surface-variant);
}

.charts-stat dd {
  margin: 0;
  font-family: var(--banana-font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--banana-text-body);
}

.charts-head__controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

@media (max-width: 640px) {
  .charts-head__controls,
  .charts-tfs { flex-wrap: wrap; min-width: 0; }
}

/* ── timeframe rail ─────────────────────────────────────────────────────── */

.charts-tfs { display: flex; gap: 4px; }

.charts-tf {
  padding: 5px 9px;
  border: 0;
  border-radius: var(--banana-radius);
  background: var(--banana-surface-container);
  color: var(--banana-on-surface-variant);
  font-family: var(--banana-font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.charts-tf:hover { background: var(--banana-surface-container-high); }

.charts-tf[aria-pressed="true"] {
  background: var(--banana-primary-fixed);
  color: var(--banana-on-primary-fixed);
}

.charts-iconbtn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: var(--banana-radius);
  background: var(--banana-surface-container);
  color: var(--banana-on-surface-variant);
  cursor: pointer;
}

.charts-iconbtn:hover { background: var(--banana-surface-container-high); }

/* Two bars: the plot and the panel beside it. The right one goes hollow when
   the panel is hidden, so the control states what it did. */
.charts-iconbtn__glyph {
  display: block;
  width: 15px;
  height: 11px;
  border: 1px solid currentColor;
  border-radius: 2px;
  background:
    linear-gradient(to right, transparent 0 8px, currentColor 8px 100%);
}

.charts-iconbtn[aria-expanded="false"] .charts-iconbtn__glyph { background: none; }

.charts-btn {
  padding: 6px 12px;
  border: 0;
  border-radius: var(--banana-radius);
  background: var(--banana-surface-container-high);
  color: var(--banana-text-body);
  font-family: var(--banana-font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
}

.charts-btn:hover { background: var(--banana-surface-container-highest); }

/* ── the chart well ─────────────────────────────────────────────────────── */
/*
   THE BOTTOM AXIS LIVES OR DIES HERE. The well clips its children, so the
   plot host is inset to zero against it and given no padding, no border and
   no margin: the chart's own height is the well's height, and the time axis
   is drawn inside that height by the engine. Anything added to this box that
   takes vertical space (padding, a border, a sibling in normal flow) pushes
   the axis under the clip and it disappears. Every other child of the well is
   absolutely positioned for exactly that reason.
*/

.charts-canvas {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--banana-surface-container-lowest);
  border-radius: var(--banana-radius);
  overflow: hidden;
}

/* Below the breakpoint the page scrolls and the panels stack under the chart,
   so `flex: 1` has no slack to hand out and the well collapses to nothing.
   It needs a height of its own, and this rule has to sit AFTER the base one:
   the first version of it lived up in the layout media query, where the
   later `min-height: 0` below simply overrode it and the chart vanished at
   every width under 1100px. */
@media (max-width: 1100px) {
  .charts-canvas { min-height: 62vh; }
}

/* THE PLOT HAS TO BE ITS OWN STACKING CONTEXT, and this is not decoration.
   The engine gives its canvases `z-index: 1` and `2`. A positioned box with
   `z-index: auto` does not contain them, so those canvases were promoted past
   this element and painted over every sibling that follows it: the readout,
   the loading pill and the failure notice were all in the DOM, all measured a
   real size, and all invisible. `z-index: 0` here is what keeps the engine's
   layers inside the engine's box. */
.charts-canvas__plot {
  position: absolute;
  inset: 0;
  z-index: 0;
  padding: 0;
  border: 0;
  margin: 0;
}

.charts-canvas__plot:focus { outline: none; }
.charts-canvas__plot:focus-visible {
  outline: 2px solid var(--banana-primary-fixed);
  outline-offset: -2px;
}

/* The frame a slow first fetch shows. Ruled lines and nothing else: it is
   plainly an empty grid, so it cannot be misread as a flat price. */
.charts-canvas__skeleton {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(to bottom, rgba(72, 72, 71, 0.22) 0 1px, transparent 1px 14.28%),
    repeating-linear-gradient(to right, rgba(72, 72, 71, 0.16) 0 1px, transparent 1px 9%);
}

.charts-canvas__skeleton[hidden] { display: none; }

/* ── the crosshair readout ──────────────────────────────────────────────── */

.charts-legend {
  position: absolute;
  top: 8px;
  left: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 9px;
  border-radius: var(--banana-radius);
  background: rgba(19, 19, 19, 0.82);
  pointer-events: none;
  font-family: var(--banana-font-mono);
  /* Tabular figures are what keep the numbers from jittering sideways as the
     crosshair moves, and they are the whole reason this reads as steady. */
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  line-height: 1.35;
  color: var(--banana-text-body);
  white-space: nowrap;
}

.charts-legend__row { display: flex; align-items: baseline; gap: 8px; }

.charts-legend__ohlc { gap: 4px; }

.charts-legend__sym {
  font-family: var(--banana-font-heading);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--banana-on-surface);
}

.charts-legend__tf,
.charts-legend__k {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--banana-on-surface-variant);
}

.charts-legend__when {
  font-size: 10px;
  color: var(--banana-on-surface-variant);
}

.charts-legend__v { color: var(--banana-text-body); }
.charts-legend__k + .charts-legend__v { margin-right: 6px; }

.charts-legend[data-dir="up"] .charts-legend__v--close,
.charts-legend[data-dir="up"] .charts-legend__chg { color: var(--banana-chart-call); }
.charts-legend[data-dir="down"] .charts-legend__v--close,
.charts-legend[data-dir="down"] .charts-legend__chg { color: var(--banana-chart-put); }

.charts-legend__chg { color: var(--banana-on-surface-variant); }

/* ── loading, empty and failure ─────────────────────────────────────────── */
/*
   A refresh over bars already on screen gets the pill and nothing else: the
   chart stays live and pannable while it reloads. Only a state with no bars
   to show takes the middle of the well.
*/

.charts-canvas__pill {
  position: absolute;
  top: 8px;
  left: 50%;
  z-index: 3;
  transform: translateX(-50%);
  padding: 4px 10px;
  border-radius: var(--banana-radius);
  background: rgba(19, 19, 19, 0.9);
  pointer-events: none;
  font-family: var(--banana-font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--banana-on-surface-variant);
}

.charts-canvas__pill[hidden] { display: none; }

.charts-canvas__notice {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  /* Not opaque: the well behind it is the frame, and a failure should not
     make the page look like it never had a chart on it. */
  background: rgba(0, 0, 0, 0.72);
}

.charts-canvas__notice[hidden] { display: none; }

/* The strip form: a failure reported over bars that are still on screen. It
   sits along the top, leaves the plot alone, and lets the pointer through
   everywhere except its own button, so the chart underneath stays pannable. */
.charts-canvas__notice[data-mode="strip"] {
  inset: 0 0 auto 0;
  grid-auto-flow: column;
  justify-content: start;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  text-align: left;
  background: rgba(19, 19, 19, 0.94);
  border-bottom: 1px solid var(--banana-outline-variant);
  pointer-events: none;
}

.charts-canvas__notice[data-mode="strip"] .charts-btn { pointer-events: auto; }

/* THE STRIP MUST NOT SIT ON THE READOUT. When a load fails for a new symbol
   the chart still holds the previous symbol's bars, and the only thing on
   screen that says whose bars those are is the readout in this corner. A
   strip covering it turns an honest "these are SPY bars, NVDA did not load"
   into a chart that looks like it is showing the wrong name. */
.charts-canvas:has(.charts-canvas__notice[data-mode="strip"]:not([hidden])) .charts-legend {
  top: 50px;
}
.charts-canvas__notice[data-mode="strip"] .charts-canvas__notice-text {
  max-width: none;
  font-size: 12px;
}

.charts-canvas__notice-text {
  margin: 0;
  max-width: 46ch;
  font-size: 13px;
  line-height: 1.5;
  color: var(--banana-on-surface-variant);
}

.charts-canvas__notice[data-tone="error"] .charts-canvas__notice-text {
  color: var(--banana-chart-put);
}

/* ── overlay rail ───────────────────────────────────────────────────────── */

.charts-overlays {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--banana-surface-container-low);
  border-radius: var(--banana-radius);
}

.charts-overlays__label {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--banana-on-surface-variant);
}

.charts-overlays__rail { display: flex; gap: 6px; flex-wrap: wrap; }

.charts-overlays__pending {
  margin: 0;
  font-size: 12px;
  color: var(--banana-on-surface-variant);
}

/* ── sidebar ────────────────────────────────────────────────────────────── */

.charts-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  min-height: 0;
}

.charts-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--banana-surface-container-low);
  border-radius: var(--banana-radius);
}

/* Which panel takes the slack is decided in charts_sectors.css, next to the
   panels it applies to. The rules that used to live here sized a watchlist and
   a context panel, and both are gone. */

.charts-panel__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.charts-panel__title {
  margin: 0;
  font-family: var(--banana-font-heading);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--banana-on-surface-variant);
}

/* The rows of whatever the sidebar is showing are styled in
   charts_sectors.css, under the csec and chld prefixes, so the two stylesheets
   cannot restyle each other. What stays here is the shell they mount into: the
   panel, its head and its note line. The add form and the tab strip went with
   the watchlist that owned them. */

.charts-panel__note {
  margin: 0;
  font-size: 11px;
  color: var(--banana-on-surface-variant);
}

.charts-panel__note[data-tone="error"] { color: var(--banana-chart-put); }

/* Reduced motion is honored in the engine as well: kinetic scrolling and
   animated jumps are switched off in static/js/charts.js. */
@media (prefers-reduced-motion: reduce) {
  .charts-page *,
  .charts-page *::before,
  .charts-page *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
