.chart-stack {
  --liquidity-profile-width: 120px;
  --price-scale-width: 78px;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) 142px 160px 142px;
  background: var(--chart-bg);
}

.chart-stack.has-rsi:not(.has-macd) {
  grid-template-rows: minmax(0, 1fr) 142px;
}

.chart-stack.has-macd:not(.has-rsi) {
  grid-template-rows: minmax(0, 1fr) 160px;
}

.chart-stack:not(.has-rsi):not(.has-macd) {
  grid-template-rows: minmax(0, 1fr);
}

.chart-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--chart-bg);
}

.chart-surface,
.indicator-chart {
  position: absolute;
  inset: 0;
  touch-action: none;
}

.overlay-canvas {
  position: absolute;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.liquidity-profile-canvas {
  position: absolute;
  z-index: 4;
  top: 0;
  right: var(--price-scale-width);
  bottom: 0;
  display: none;
  width: var(--liquidity-profile-width);
  height: 100%;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0), var(--profile-shade));
  pointer-events: none;
}

.analysis-canvas {
  z-index: 5;
}

.atr-canvas {
  z-index: 3;
}

.support-resistance-canvas {
  z-index: 5;
}

.chart-wrap.liquidity-profile-active .liquidity-profile-canvas {
  display: block;
}

.drawing-canvas {
  z-index: 6;
  right: var(--price-scale-width);
  width: auto;
  touch-action: none;
}

.chart-wrap.liquidity-profile-active .drawing-canvas {
  right: calc(var(--price-scale-width) + var(--liquidity-profile-width) + 12px);
}

.drawing-canvas.navigation {
  pointer-events: none;
  cursor: default;
}

.drawing-canvas.select {
  pointer-events: auto;
  cursor: default;
}

.drawing-canvas.draw {
  pointer-events: auto;
  cursor: crosshair;
}

.drawing-tooltip {
  position: absolute;
  z-index: 12;
  top: 8px;
  left: 8px;
  width: 278px;
  max-width: calc(100% - 16px);
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--blue) 34%, var(--border));
  border-radius: 8px;
  background: var(--floating-surface);
  color: var(--soft-text);
  box-shadow: var(--floating-shadow);
  font-size: 0.74rem;
  line-height: 1.42;
  pointer-events: none;
}

.drawing-tooltip > strong,
.drawing-tooltip-direction {
  display: block;
}

.drawing-tooltip > strong { color: var(--text); }
.drawing-tooltip-direction { margin-bottom: 8px; color: var(--muted); }
.drawing-tooltip-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; }
.drawing-tooltip-grid span { color: var(--muted); }
.drawing-tooltip-grid b { color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }

.indicator-pane {
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--chart-bg);
}

.indicator-pane.hidden {
  display: none;
}

.global-time-axis {
  display: none;
}


.global-time-axis-tick {
  position: absolute;
  top: 5px;
  display: grid;
  gap: 1px;
  min-width: max-content;
  line-height: 1;
  text-align: center;
  transform: translateX(-50%);
  white-space: nowrap;
}

.global-time-axis-tick::before {
  position: absolute;
  top: -6px;
  left: 50%;
  width: 1px;
  height: 4px;
  background: var(--border);
  content: "";
}

.global-time-axis-tick.edge-start { transform: translateX(0); text-align: left; }
.global-time-axis-tick.edge-end { transform: translateX(-100%); text-align: right; }
.global-time-axis-tick small { color: var(--soft-text); font-size: 0.61rem; }

.global-time-axis-cursor {
  position: absolute;
  z-index: 2;
  top: 3px;
  max-width: calc(100% - 8px);
  padding: 3px 6px;
  border: 1px solid color-mix(in srgb, var(--blue) 64%, var(--border));
  border-radius: 4px;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  color: var(--text);
  font-size: 0.64rem;
  font-weight: 750;
  line-height: 1;
  transform: translateX(-50%);
  white-space: nowrap;
  pointer-events: none;
}

.global-time-axis-cursor::before {
  position: absolute;
  top: -5px;
  left: 50%;
  width: 1px;
  height: 5px;
  background: var(--blue);
  content: "";
}

.pane-resize-handle {
  position: absolute;
  z-index: 11;
  right: 0;
  top: 0;
  bottom: auto;
  left: 0;
  width: 100%;
  height: 16px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: row-resize;
  touch-action: none;
}

.pane-resize-handle::after {
  position: absolute;
  top: 7px;
  right: 42%;
  left: 42%;
  height: 2px;
  border-radius: 2px;
  background: transparent;
  content: "";
  transition: background 120ms ease, right 120ms ease, left 120ms ease;
}

.pane-resize-handle:hover::after,
.pane-resize-handle:focus-visible::after,
.pane-resize-handle.resizing::after {
  right: 38%;
  left: 38%;
  background: var(--blue, #3e79ff);
}

.pane-resize-handle:focus-visible { outline: 0; }

.pane-label {
  position: absolute;
  z-index: 8;
  top: 18px;
  left: 10px;
  padding: 4px 7px;
  border-radius: 6px;
  background: var(--panel-glass);
  color: var(--soft-text);
  font-size: 0.72rem;
  pointer-events: none;
}

.chart-state {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: none;
  place-items: center;
  gap: 12px;
  background: color-mix(in srgb, var(--chart-bg) 64%, transparent);
  color: var(--soft-text);
}

.divergence-tooltip {
  position: absolute;
  z-index: 9;
  width: 248px;
  padding: 9px 10px;
  border: 1px solid color-mix(in srgb, var(--blue) 30%, var(--border));
  border-radius: 8px;
  background: var(--floating-surface);
  color: var(--soft-text);
  box-shadow: var(--floating-shadow);
  font-size: 0.74rem;
  line-height: 1.45;
  pointer-events: none;
}

.divergence-tooltip strong,
.divergence-tooltip span {
  display: block;
}

.divergence-tooltip strong {
  color: var(--text);
}

.divergence-tooltip span {
  margin-bottom: 5px;
  color: var(--muted);
}

.liquidity-tooltip {
  position: absolute;
  z-index: 10;
  width: 278px;
  max-width: calc(100% - 16px);
  padding: 11px 12px;
  border: 1px solid color-mix(in srgb, var(--blue) 34%, var(--border));
  border-radius: 8px;
  background: var(--floating-surface);
  color: var(--soft-text);
  box-shadow: var(--floating-shadow);
  font-size: 0.74rem;
  line-height: 1.42;
  pointer-events: auto;
}

.liquidity-tooltip-head,
.liquidity-tooltip-grid {
  display: grid;
  gap: 4px 10px;
}

.liquidity-tooltip-head {
  grid-template-columns: 1fr auto;
  align-items: start;
  margin-bottom: 7px;
}

.liquidity-tooltip-head strong,
.liquidity-tooltip-price {
  color: var(--text);
}

.liquidity-tooltip-status {
  color: var(--muted);
  font-size: 0.66rem;
  text-align: right;
}

.liquidity-tooltip-status.active {
  color: var(--green);
}

.liquidity-tooltip-price {
  margin-bottom: 8px;
  font-size: 1.05rem;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.liquidity-tooltip-grid {
  grid-template-columns: auto 1fr;
  margin-bottom: 8px;
}

.liquidity-tooltip-grid span,
.liquidity-tooltip small {
  color: var(--muted);
}

.liquidity-tooltip-grid strong {
  color: var(--text);
  text-align: right;
}

.liquidity-info-dot {
  display: inline-grid;
  width: 13px;
  height: 13px;
  place-items: center;
  margin-left: 2px;
  border: 1px solid currentColor;
  border-radius: 50%;
  color: var(--muted);
  cursor: help;
  font-size: 0.58rem;
  font-weight: 850;
  line-height: 1;
  vertical-align: 1px;
}

.liquidity-info-dot:hover {
  color: var(--text);
}

.liquidity-tooltip p {
  margin: 0 0 7px;
  color: var(--soft-text);
}

.liquidity-tooltip small {
  display: block;
  font-size: 0.66rem;
}

.chart-state.visible {
  display: grid;
}

.chart-state.error {
  color: var(--red);
}

.loader {
  width: 28px;
  height: 28px;
  border: 3px solid var(--loader-track);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.chart-state.error .loader {
  display: none;
}

.history-page-status {
  position: absolute;
  z-index: 11;
  top: 10px;
  left: 10px;
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: min(320px, calc(100% - 20px));
  min-height: 28px;
  padding: 5px 9px;
  border: 1px solid color-mix(in srgb, var(--blue) 35%, var(--border));
  border-radius: 7px;
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
  color: var(--soft-text);
  font-size: 0.7rem;
  font-weight: 700;
  pointer-events: none;
}

.history-page-status[hidden] {
  display: none;
}

.history-page-loader {
  display: none;
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 2px solid var(--loader-track);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.history-page-status.loading .history-page-loader { display: block; }
.history-page-status.error { border-color: color-mix(in srgb, var(--red) 42%, var(--border)); color: var(--red); }
.history-page-status.limit {
  max-width: min(440px, calc(100% - 20px));
  padding: 7px 11px;
  border-color: color-mix(in srgb, var(--yellow) 72%, var(--border));
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--yellow) 20%, var(--panel)),
    color-mix(in srgb, var(--yellow) 8%, var(--panel))
  );
  box-shadow: 0 8px 24px color-mix(in srgb, var(--yellow) 20%, transparent);
  color: color-mix(in srgb, var(--yellow) 78%, var(--text));
  font-size: 0.74rem;
}

.history-page-status.limit::before {
  content: "!";
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  flex: 0 0 17px;
  border-radius: 50%;
  background: var(--yellow);
  color: var(--panel);
  font-size: 0.7rem;
  font-weight: 900;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .chart-stack {
    grid-template-rows: minmax(0, 1fr) 128px 148px;
  }

  .chart-stack.has-rsi:not(.has-macd) { grid-template-rows: minmax(0, 1fr) 128px; }
  .chart-stack.has-macd:not(.has-rsi) { grid-template-rows: minmax(0, 1fr) 148px; }

  .indicator-pane {
    min-height: 128px;
  }


  .chart-wrap {
    --liquidity-profile-width: 96px;
  }

  .chart-stack {
    --liquidity-profile-width: 96px;
    --price-scale-width: 66px;
  }
}

/* 8BIT.C chart chrome: the series and interaction model remain unchanged. */
.chart-stack,
.chart-wrap,
.indicator-pane { background: var(--brand-canvas); }
.indicator-pane { border-color: var(--chart-grid); }
.pane-label {
  top: 16px;
  left: 12px;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-glass);
  color: var(--muted);
  font-size: 0.66rem;
  letter-spacing: 0.025em;
}
.pane-resize-handle:hover::after,
.pane-resize-handle:focus-visible::after,
.pane-resize-handle.resizing::after { background: var(--brand-accent); }
.drawing-tooltip,
.divergence-tooltip,
.liquidity-tooltip {
  border-color: color-mix(in srgb, var(--brand-accent) 28%, var(--border));
  border-radius: 12px;
  box-shadow: var(--floating-shadow);
}
.global-time-axis-cursor {
  border-color: color-mix(in srgb, var(--brand-accent) 56%, var(--border));
  border-radius: 7px;
}
.global-time-axis-cursor::before { background: var(--brand-accent); }
.loader,
.history-page-loader { border-top-color: var(--brand-accent); }
.history-page-status {
  border-color: color-mix(in srgb, var(--brand-accent) 28%, var(--border));
  border-radius: 10px;
  box-shadow: none;
}

:root[data-theme="light"] .pane-label {
  border-color: var(--border);
  background: color-mix(in srgb, var(--brand-surface-raised) 92%, transparent);
  color: #625e56;
}
:root[data-theme="light"] .drawing-tooltip,
:root[data-theme="light"] .divergence-tooltip,
:root[data-theme="light"] .liquidity-tooltip {
  background: var(--floating-surface);
  color: var(--text);
}
