/* Quality-improvement page styles; shared colors come from ../styles.css. */

body {
  overflow-x: hidden;
}

.qi-page {
  padding-top: 64px;
}

.qi-page section {
  max-width: 1120px;
}

.qi-hero {
  padding-top: 7.5rem;
  padding-bottom: 4.5rem;
  text-align: left;
}

.qi-eyebrow,
.qi-kicker,
.figure-label {
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.qi-hero h1 {
  max-width: 820px;
  margin-top: 0.7rem;
  color: var(--text-heading);
  font-size: clamp(2.5rem, 6vw, 4.75rem);
  line-height: 1.02;
  letter-spacing: -0.045em;
}

.qi-subtitle {
  max-width: 740px;
  margin-top: 1.5rem;
  color: var(--text-secondary);
  font-size: 1.15rem;
  line-height: 1.75;
}

.qi-generated {
  margin-top: 1.25rem;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.section-heading {
  max-width: 680px;
  margin-bottom: 2rem;
}

.section-heading-wide {
  max-width: 800px;
}

.section-heading h2,
.case-header h2,
.methodology h2 {
  margin-top: 0.35rem;
  color: var(--text-heading);
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

.section-heading > p:last-child {
  margin-top: 1rem;
  color: var(--text-secondary);
  line-height: 1.75;
}

.qi-stats {
  padding-top: 2rem;
  padding-bottom: 4rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.stat-tile {
  min-width: 0;
  padding: 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.stat-value {
  display: block;
  color: var(--text-heading);
  font-size: 2.15rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.stat-label {
  display: block;
  margin-top: 0.45rem;
  color: var(--text-secondary);
  font-size: 0.86rem;
}

.qi-program,
.case-study {
  padding-top: 4.5rem;
  padding-bottom: 4.5rem;
  border-top: 1px solid var(--border-color);
}

.case-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.initiative-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  padding: 0.35rem 0.7rem;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.initiative-status::before {
  width: 7px;
  height: 7px;
  background: var(--text-secondary);
  border-radius: 50%;
  content: "";
}

.initiative-status.status-active::before {
  background: #0d9488;
}

.case-narrative {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
}

.case-narrative p,
.method-grid p {
  color: var(--text-secondary);
  line-height: 1.72;
}

.case-narrative strong,
.method-grid strong {
  color: var(--text-primary);
  font-weight: 600;
}

.qi-figure {
  min-width: 0;
  margin-top: 2rem;
  padding: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
}

.qi-figure figcaption {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.qi-figure figcaption strong {
  display: block;
  margin-top: 0.25rem;
  color: var(--text-heading);
  font-size: 1.05rem;
  line-height: 1.4;
}

.figure-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.4rem 1rem;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-scroll,
.data-table-scroll,
.verdict-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

.chart-scroll {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.chart-scroll:focus-visible,
.data-details summary:focus-visible {
  outline: 2px solid var(--text-secondary);
  outline-offset: 3px;
}

.chart-canvas {
  position: relative;
  min-width: 700px;
  min-height: 360px;
}

.chart-canvas svg {
  display: block;
  width: 100%;
  height: auto;
  min-height: 360px;
}

.chart-grid-line,
.chart-axis-line {
  stroke: var(--border-subtle);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-axis-text,
.chart-intervention-text,
.chart-median-text {
  fill: var(--text-secondary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 12px;
}

.chart-series {
  fill: none;
  stroke: #3b82f6;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-point {
  fill: var(--bg-secondary);
  stroke: #3b82f6;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.chart-median,
.chart-intervention,
.chart-crosshair {
  stroke: var(--text-secondary);
  stroke-width: 1;
  stroke-dasharray: 5 5;
  vector-effect: non-scaling-stroke;
}

.chart-crosshair {
  stroke-dasharray: 3 4;
}

.chart-hover-point {
  fill: var(--bg-card);
  stroke: #3b82f6;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.chart-tooltip {
  position: absolute;
  z-index: 2;
  display: none;
  min-width: 142px;
  padding: 0.55rem 0.7rem;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  font-size: 0.75rem;
  line-height: 1.45;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
}

.chart-tooltip.is-visible {
  display: block;
}

.chart-tooltip span {
  display: block;
}

.chart-tooltip .tooltip-date {
  color: var(--text-secondary);
}

.data-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  text-align: center;
}

.data-details {
  margin-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.data-details summary {
  padding: 1rem 0 0.25rem;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.data-details table,
.verdict-table {
  width: 100%;
  min-width: 610px;
  margin-top: 0.75rem;
  border-collapse: collapse;
}

.data-details caption,
.verdict-table caption {
  padding-bottom: 0.5rem;
  color: var(--text-secondary);
  font-size: 0.75rem;
  text-align: left;
}

.data-details th,
.data-details td,
.verdict-table th,
.verdict-table td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  text-align: left;
  vertical-align: middle;
}

.data-details th,
.verdict-table th {
  color: var(--text-primary);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.verdict-table-scroll {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
}

.verdict-table {
  margin-top: 0;
  background: var(--bg-secondary);
}

.verdict-table td .data-empty {
  min-height: 170px;
}

.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.verdict-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  background: var(--text-secondary);
  border-radius: 50%;
}

.verdict-improving .verdict-dot {
  background: #22c55e;
}

.verdict-worse .verdict-dot {
  background: #ef4444;
}

.arm-value {
  display: block;
  color: var(--text-primary);
}

.arm-count {
  display: block;
  margin-top: 0.1rem;
  color: var(--text-secondary);
  font-size: 0.7rem;
}

.methodology {
  padding-top: 4.5rem;
  padding-bottom: 5rem;
  border-top: 1px solid var(--border-color);
}

.method-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
  margin-top: 2rem;
}

@media (max-width: 800px) {
  .stat-grid,
  .case-narrative,
  .method-grid {
    grid-template-columns: 1fr;
  }

  .case-header {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  nav {
    padding: 0 1rem;
  }

  .nav-links {
    gap: 0.75rem;
  }

  .qi-page section {
    padding-right: 1rem;
    padding-left: 1rem;
  }

  .qi-hero {
    padding-top: 5.5rem;
    padding-bottom: 3.5rem;
  }

  .qi-subtitle {
    font-size: 1rem;
  }

  .qi-figure {
    padding: 16px;
  }

  .qi-figure figcaption {
    flex-direction: column;
  }

  .figure-meta {
    justify-content: flex-start;
  }

  .chart-canvas {
    min-width: 660px;
  }
}

/* Goal line: an owner-chosen target, distinct from the data and the median. */
.chart-goal-line {
  stroke: #2e7d32;
  stroke-width: 1.5;
  stroke-dasharray: 2 4;
  opacity: 0.75;
}

.chart-goal-text {
  fill: #2e7d32;
  font-size: 11px;
  font-weight: 600;
}

/* Low-sample days stay visible but read as provisional. */
.chart-point-thin {
  fill: #ffffff;
  stroke-width: 1.5;
  opacity: 0.7;
}

/* Outliers beyond the robust ceiling: pinned at the top edge, never dropped. */
.chart-point-pinned {
  fill: #ffffff;
  stroke: #c62828;
  stroke-width: 2;
  opacity: 0.9;
}

.chart-pinned-note {
  fill: #c62828;
  font-size: 11px;
  font-weight: 600;
}
