html,
body.market-page {
  overflow: auto;
}

.market-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: clamp(14px, 2vw, 28px);
  gap: 12px;
}

.market-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.market-back {
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: lowercase;
}

.market-back:hover {
  color: var(--ink);
}

.market-title {
  margin: 0;
  color: var(--ink);
  font-size: clamp(20px, 2.4vw, 28px);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.tab-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  align-items: flex-end;
  border-bottom: 1px solid var(--panel-border);
}

.tab {
  appearance: none;
  border: 1px solid var(--panel-border);
  border-bottom: 1px solid transparent;
  background: rgba(7, 17, 36, 0.35);
  color: var(--muted);
  border-radius: 6px 6px 0 0;
  padding: 10px 18px 8px;
  font-size: 13px;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  font-family: inherit;
  margin-right: -1px;
  margin-bottom: -1px;
  position: relative;
}

.tab:hover {
  color: var(--ink);
  background: rgba(42, 78, 134, 0.5);
}

.tab.is-active {
  color: #eaf6ff;
  font-weight: 600;
  background: var(--panel-bg);
  border-color: var(--panel-border);
  border-bottom-color: var(--panel-bg);
  box-shadow: inset 0 3px 0 0 var(--ok);
  z-index: 1;
}

.tab:focus-visible {
  outline: 2px solid rgba(127, 162, 212, 0.85);
  outline-offset: 2px;
}

.chart-host {
  flex: 1 1 auto;
  min-height: 75vh;
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: stretch;
  justify-content: stretch;
}

.chart-host > div.js-plotly-plot,
.chart-host > .plotly {
  width: 100%;
  height: 100%;
  min-height: 75vh;
}

/* Mid chart (S&P 500 line + z-score signed-stacked bars) injected by JS on
   the Analysis tab between the main chart-host and the backtest scatter. */
.mid-section {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(4px);
  display: flex;
}

.mid-host {
  flex: 1 1 auto;
  min-height: 75vh;
  width: 100%;
}

.mid-host > div.js-plotly-plot,
.mid-host > .plotly {
  width: 100%;
  height: 100%;
  min-height: 75vh;
}

/* Secondary analytics chart (scatter + regression) injected by JS on the
   Analysis tab. Sized smaller than the main chart-host and sits below it. */
.backtest-section {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: var(--panel-bg);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.backtest-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.backtest-toolbar .label {
  letter-spacing: 0.04em;
}

.backtest-host {
  flex: 1 1 auto;
  min-height: 50vh;
  width: 100%;
}

.backtest-host > div.js-plotly-plot,
.backtest-host > .plotly {
  width: 100%;
  height: 100%;
  min-height: 50vh;
}

.chart-caption {
  margin: 8px 4px 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  /* wrap responsively instead of overflowing a narrow viewport */
  white-space: normal;
  overflow-wrap: anywhere;
}

.chart-caption[hidden] {
  display: none;
}

.empty-state,
.loading-state,
.error-state {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.03em;
  text-align: center;
  padding: 24px;
}

.error-state {
  color: #f4c7d2;
}
