/* ==========================================================================
   PAGE LAYOUT & EDITORIAL TYPOGRAPHY
   ========================================================================== */
body.analysis-page {
  overflow-y: auto !important;
  background-color: #f8fafc;
  color: #0f172a;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
}

.analysis-container {
  max-width: 1140px;
  margin: calc(var(--header-height, 90px) + 24px) auto 80px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.analysis-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 32px 36px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

.analysis-card-header {
  border-bottom: 1.5px solid #f1f5f9;
  padding-bottom: 20px;
  margin-bottom: 24px;
}

.analysis-card-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: #0f172a;
  letter-spacing: -0.025em;
  margin: 0 0 6px 0;
}

.analysis-card-subtitle {
  font-size: 0.96rem;
  color: #64748b;
  margin: 0;
  font-weight: 500;
  line-height: 1.5;
}

/* ==========================================================================
   SCENARIO TOGGLE CONTROLS
   ========================================================================== */
.chart-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
}

.scenario-toggle-group {
  display: inline-flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  gap: 4px;
}

.scenario-btn {
  background: transparent;
  border: none;
  color: #64748b;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.scenario-btn:hover {
  color: #0f172a;
}

.scenario-btn.active {
  background: #ffffff;
  color: #0f172a;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* ==========================================================================
   CHART CANVASES & D3 TYPOGRAPHY
   ========================================================================== */
.charts-dual-stack {
  display: flex;
  flex-direction: column;
  gap: 36px;
}

.chart-sub-panel {
  background: #ffffff;
}

.chart-sub-panel-header {
  margin-bottom: 14px;
}

.chart-sub-panel-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 4px 0;
}

.chart-sub-panel-desc {
  font-size: 0.88rem;
  color: #64748b;
  margin: 0;
}

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  background: #ffffff;
  border: 1px solid #f1f5f9;
  border-radius: 8px;
  padding: 14px 12px;
  box-sizing: border-box;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#gerrymander-chart,
#state-delegation-chart {
  min-width: 860px;
  width: 100%;
  position: relative;
}

#gerrymander-chart svg,
#state-delegation-chart svg {
  width: 100%;
  height: auto;
  display: block;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Axis & Gridlines */
.chart-grid-line {
  stroke: #f1f5f9;
  stroke-dasharray: 2, 2;
}

.chart-center-divider {
  stroke: #cbd5e1;
  stroke-width: 1.5px;
}

.chart-zero-line {
  stroke: #d97706;
  stroke-width: 1.8px;
  stroke-dasharray: 4, 3;
}

.chart-threshold-label {
  fill: #d97706;
  font-size: 11px;
  font-weight: 700;
  text-anchor: end;
}

.chart-axis text {
  fill: #64748b;
  font-size: 11px;
  font-weight: 600;
}

.chart-axis path,
.chart-axis line {
  stroke: #cbd5e1;
}

.chart-axis-label {
  font-size: 12px;
  font-weight: 700;
  text-anchor: middle;
}

.chart-axis-label.dem-label {
  fill: #2563eb;
}

.chart-axis-label.rep-label {
  fill: #dc2626;
}

.chart-axis-label.y-axis-title {
  fill: #475569;
}

/* District Dots & State Nodes */
.district-dot {
  stroke-width: 1.5px;
  cursor: pointer;
  fill-opacity: 0.85;
  transition: fill-opacity 0.15s ease, stroke-width 0.15s ease;
}

.district-dot.dem {
  fill: #2563eb;
  stroke: #1d4ed8;
}

.district-dot.rep {
  fill: #dc2626;
  stroke: #b91c1c;
}

.district-dot:hover {
  fill-opacity: 1 !important;
  stroke-width: 3px !important;
  stroke: #0f172a !important;
}

.chart-dot-label {
  font-size: 11px;
  font-weight: 700;
  fill: #1e293b;
  pointer-events: none;
}

.label-leader-line {
  stroke: #94a3b8;
  stroke-width: 1px;
  stroke-dasharray: 2, 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.label-leader-line.active {
  opacity: 0.7;
}

.state-scatter-node {
  cursor: pointer;
  pointer-events: all !important;
}

.state-scatter-node circle {
  pointer-events: all;
  transition: stroke 0.15s ease, stroke-width 0.15s ease, filter 0.15s ease;
}

.state-scatter-node:hover circle {
  stroke: #38bdf8 !important;
  stroke-width: 3.5px !important;
  filter: drop-shadow(0 2px 8px rgba(56, 189, 248, 0.45));
}

.state-scatter-node:hover text.state-name-text {
  fill: #0f172a !important;
  font-weight: 800 !important;
}

.state-name-text {
  font-size: 11.5px !important;
  font-weight: 700 !important;
  fill: #334155 !important;
  cursor: pointer !important;
  pointer-events: all !important;
  paint-order: stroke fill;
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.state-leader-line {
  stroke: #64748b;
  stroke-width: 1.2px;
  stroke-dasharray: 3, 2;
  cursor: pointer;
  pointer-events: stroke !important;
}

/* ==========================================================================
   TOOLTIPS
   ========================================================================== */
.d3-chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  padding: 12px 14px;
  font-size: 0.88rem;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 8px;
  pointer-events: none;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  z-index: 100;
  min-width: 220px;
  will-change: transform;
}

.d3-chart-tooltip.visible {
  opacity: 1;
  visibility: visible;
}

.tt-title {
  font-size: 1.02rem;
  font-weight: 800;
  margin-bottom: 6px;
  color: #ffffff;
}

.tt-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  color: #cbd5e1;
}

.tt-row strong {
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
  color: #ffffff;
}

.dem-text,
.tt-row strong.dem-text {
  color: #60a5fa !important;
}

.rep-text,
.tt-row strong.rep-text {
  color: #f87171 !important;
}

.tt-divider {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   METHODOLOGY CARDS & FORMULAS (LIGHT THEME)
   ========================================================================== */
.methodology-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: 20px;
}

.methodology-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 22px;
}

.methodology-card h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  margin: 0 0 10px 0;
}

.methodology-card p {
  font-size: 0.94rem;
  line-height: 1.6;
  color: #475569;
  margin: 0 0 12px 0;
}

.methodology-formula {
  background: #ffffff;
  color: #0f172a;
  border: 1px solid #cbd5e1;
  border-left: 4px solid #2563eb;
  padding: 12px 14px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 600;
  margin: 12px 0;
}

.methodology-list {
  margin: 0;
  padding-left: 18px;
  color: #475569;
  font-size: 0.92rem;
  line-height: 1.55;
}

.methodology-list strong {
  color: #0f172a;
}

.methodology-list code {
  color: #0f172a;
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88rem;
}
