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;
}

/* Stacked layout for the "ofz-stack" indicator (КБД on top + real-yield
   scatter below). When chart-host-stack is set, chartHost becomes a vertical
   column hosting two .chart-pane children, each owning its own Plotly. */
.chart-host-stack {
  flex-direction: column;
  gap: 16px;
}

.chart-host-stack > .chart-pane {
  flex: 1 1 50%;
  min-height: 60vh;
  width: 100%;
}

.chart-host-stack > .chart-pane > div.js-plotly-plot,
.chart-host-stack > .chart-pane > .plotly {
  width: 100%;
  height: 100%;
}

/* 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;
}

.chart-host:has(.global-rates) {
  flex-direction: column;
  align-items: stretch;
  min-height: auto;
  height: auto;
}

/* Global sovereign rates snapshot (🌐 / Yields / Rates 10Y): график на первый
   экран + полная HTML-таблица ниже; скролл — у страницы целиком. */
.global-rates {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  min-width: 0;
}

.global-rates .gr-meta {
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0.03em;
}

/* Явная height нужна Plotly (min-height одной недостаточно). */
.global-rates .gr-plot {
  width: 100%;
  height: 80vh;
  min-height: 80vh;
  flex-shrink: 0;
}

.global-rates .gr-plot > div.js-plotly-plot,
.global-rates .gr-plot > .plotly,
.global-rates .gr-plot .plot-container,
.global-rates .gr-plot .svg-container {
  width: 100% !important;
  height: 100% !important;
  min-height: 80vh;
}

.global-rates .gr-table-wrap {
  overflow: visible;
}

.gr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  color: var(--ink);
}

.gr-table th,
.gr-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--panel-border);
  white-space: nowrap;
}

.gr-table thead th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.05em;
  border-bottom-width: 2px;
}

.gr-table .c-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.gr-table th.c-num {
  text-align: right;
}

.gr-table .c-date,
.gr-table .c-text {
  color: var(--muted);
  font-size: 12px;
}

.gr-table td.c-name {
  font-weight: 600;
}

.gr-country {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.gr-flag {
  display: block;
  width: 18px;
  height: 13px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(135, 170, 235, 0.25);
  object-fit: cover;
  flex-shrink: 0;
}

.gr-table td.is-empty {
  color: var(--muted);
  opacity: 0.6;
}

.gr-table .is-approx {
  color: #22d3ee;
}

.gr-table .gr-fn {
  margin-left: 1px;
  font-size: 0.75em;
  color: #22d3ee;
  font-weight: 600;
}

.gr-footnote {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.gr-table tbody tr:hover {
  background: rgba(42, 78, 134, 0.25);
}

.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;
}
