/* -------------------------------------------------------------------------
   Page Layout & Header
   ------------------------------------------------------------------------- */
.stats-page {
  padding: var(--space-2) 0;
}

/* Alerts using brand blue */
.stats-page .alert-info {
  background-color: var(--color-primary-subtle);
  border-color: var(--color-primary-border);
  color: var(--color-primary);
  border-radius: var(--radius-md);
}

.stats-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* Priority badges */
.priority-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
  color: var(--color-on-accent);
  min-width: 28px;
}

.priority-badge--danger  { background: var(--color-danger); }
.priority-badge--warning { background: var(--color-warning); color: var(--color-on-warning); }
.priority-badge--minor   { background: var(--color-secondary); }

/* -------------------------------------------------------------------------
   Analytics dashboard hierarchy
   ------------------------------------------------------------------------- */
.stats-page {
  background: var(--color-bg-subtle);
  padding: 0 0 5rem;
}

.stats-container {
  max-width: 1480px;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
}

.stats-page-header__row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
}

.stats-page-header__row > div:first-child {
  min-width: 0;
  max-width: 100%;
}

.stats-section-nav-shell {
  position: sticky;
  top: calc(var(--page-tabs-top, var(--navbar-height)) + var(--page-tabs-height, 54px));
  z-index: 1019;
  padding: var(--space-2) 0;
  margin-bottom: 1rem;
  background: var(--color-bg-subtle);
}

/* Ease scrolling content beneath the sticky navigation without blocking clicks. */
.stats-section-nav-shell::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 0;
  left: 0;
  height: var(--space-4);
  background: linear-gradient(to bottom, var(--color-bg-subtle), transparent);
  pointer-events: none;
}

.stats-section-nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  width: max-content;
  max-width: 100%;
  margin: 0;
  padding: 0.28rem;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg-subtle);
  box-shadow: var(--shadow-sm);
  isolation: isolate;
  scrollbar-width: none;
}

.stats-section-nav::-webkit-scrollbar { display: none; }

.stats-section-nav__indicator {
  position: absolute;
  top: 0.28rem;
  bottom: 0.28rem;
  left: 0;
  z-index: 0;
  width: var(--stats-nav-indicator-width, 0px);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
  box-shadow: var(--shadow-xs);
  opacity: 0;
  pointer-events: none;
  transform: translate3d(var(--stats-nav-indicator-x, 0px), 0, 0);
  transform-origin: center;
}

.stats-section-nav.is-ready .stats-section-nav__indicator {
  opacity: 1;
  transition:
    transform 520ms cubic-bezier(0.2, 0.88, 0.24, 1.08),
    width 440ms cubic-bezier(0.34, 1.28, 0.64, 1),
    opacity 180ms ease;
}

.stats-section-nav__link {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  padding: 0.52rem 0.78rem;
  border-radius: 999px;
  color: var(--color-fg-muted);
  font-size: 0.82rem;
  font-weight: 650;
  text-decoration: none;
  transition: color 240ms ease, transform 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stats-section-nav__link:hover {
  color: var(--color-fg);
  background: var(--color-surface-veil);
  transform: translateY(-1px);
}

.stats-section-nav__link.is-active {
  color: var(--color-primary);
  background: transparent;
}

.stats-section-nav__link:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

#pipelineRunCard {
  scroll-margin-top: var(--stats-section-scroll-offset, 8rem);
}

.stats-section-title {
  scroll-margin-top: var(--stats-section-scroll-offset, 8rem);
  margin: var(--space-12) 0 var(--space-4);
  color: var(--color-fg);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  letter-spacing: -0.01em;
}

/* Pipeline timeline */
.pipeline-run-card {
  margin-bottom: 1rem;
  padding: clamp(0.75rem, 1.4vw, 1rem);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-bg);
  box-shadow: var(--shadow-xs);
}

.pipeline-run-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 0.8rem;
}

.pipeline-run-card__eyebrow {
  margin-bottom: 0.25rem;
  color: var(--color-fg-muted);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.pipeline-run-card__title {
  margin: 0;
  color: var(--color-fg);
  font-size: 1.08rem;
  font-weight: 700;
}

.pipeline-run-card__message {
  max-width: 48rem;
  margin: 0.25rem 0 0;
  color: var(--color-fg-muted);
  font-size: 0.84rem;
}

.pipeline-run-card__detail {
  margin: 0.15rem 0 0;
  color: var(--color-fg-subtle);
  font-size: 0.75rem;
}

.pipeline-run-card__meta {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--color-fg-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pipeline-run-card__status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  color: var(--color-success-fg);
  background: var(--color-success-subtle);
  font-weight: 700;
}

.pipeline-run-card__dot {
  width: 0.42rem;
  height: 0.42rem;
  border-radius: 50%;
  background: currentColor;
}

.pipeline-run-card.is-running .pipeline-run-card__status {
  color: var(--color-primary);
  background: var(--color-primary-subtle);
}

.pipeline-run-card.is-running .pipeline-run-card__dot {
  animation: pipeline-pulse 1.6s ease-in-out infinite;
}

.pipeline-run-card.is-failed .pipeline-run-card__status {
  color: var(--color-danger-fg);
  background: var(--color-danger-subtle);
}

.pipeline-timeline {
  display: flex;
  gap: 0.4rem;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.2rem;
  scrollbar-width: thin;
}

.pipeline-timeline__stage {
  min-width: 6rem;
  flex: var(--stage-size) 1 0;
  transition: flex-grow 950ms linear;
}

.pipeline-timeline__stage:focus-visible {
  border-radius: 6px;
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
}

.pipeline-timeline__label {
  margin-bottom: 0.25rem;
  color: var(--color-fg-muted);
  font-size: 0.72rem;
}

.pipeline-timeline__label span {
  display: block;
  overflow: hidden;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-timeline__label span.is-truncated {
  cursor: help;
  text-decoration: underline dotted;
  text-decoration-color: var(--color-border);
  text-underline-offset: 0.16rem;
}

.pipeline-timeline__track {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  height: 1.5rem;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-primary-subtle);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.pipeline-timeline__stage.is-highlighted .pipeline-timeline__track {
  border-color: var(--color-primary-border);
  box-shadow: inset 0 0 0 1px var(--color-primary-border);
}

.pipeline-timeline__stage.is-highlighted .pipeline-timeline__label { color: var(--color-primary); }

.pipeline-timeline__track strong {
  position: relative;
  z-index: 2;
  margin: 0 0.35rem 0 auto;
  overflow: hidden;
  color: var(--color-fg-muted);
  font-size: 0.66rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pipeline-timeline__state {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.82rem;
  height: 0.82rem;
  flex: 0 0 0.82rem;
  margin-right: 0.42rem;
  border-radius: 50%;
  color: var(--color-on-accent);
  font-size: 0.56rem;
  font-weight: 800;
  line-height: 1;
}

.pipeline-timeline__state.is-complete { background: var(--color-success-fg); }
.pipeline-timeline__state.is-failed { background: var(--color-danger-fg); }
.pipeline-timeline__state.is-active {
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  animation: pipeline-stage-spin 0.9s linear infinite;
}

.pipeline-timeline__fill {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  width: 0;
  border-radius: 5px;
  background: var(--color-success-subtle);
  transition: width 850ms cubic-bezier(0.22, 1, 0.36, 1);
}

.pipeline-timeline__stage.is-active .pipeline-timeline__fill {
  background: var(--color-primary-subtle);
}

.pipeline-timeline__stage.is-active .pipeline-timeline__track { border-color: var(--color-primary-border); }
.pipeline-timeline__stage.is-active .pipeline-timeline__track strong { color: var(--color-primary); }

.pipeline-timeline__stage.is-active .pipeline-timeline__fill::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--color-surface-veil), transparent);
  content: "";
  transform: translateX(-100%);
  animation: pipeline-shimmer 1.8s infinite;
}

.pipeline-timeline__stage.is-active .pipeline-timeline__label span { color: var(--color-primary); }
.pipeline-timeline__stage.is-failed .pipeline-timeline__fill { background: var(--color-danger-subtle); }
.pipeline-timeline__stage.is-failed .pipeline-timeline__label span { color: var(--color-danger-fg); }

.pipeline-timeline__time {
  margin-top: 0.25rem;
  color: var(--color-fg-subtle);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
}

.pipeline-stage-details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 0.55rem;
  margin-top: 0.8rem;
}

.pipeline-stage-detail {
  min-width: 0;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-subtle);
  transition: background-color 160ms ease, box-shadow 160ms ease;
  scroll-margin-top: var(--stats-section-scroll-offset, 8rem);
  scroll-margin-bottom: 1rem;
}

.pipeline-stage-detail.is-highlighted {
  background: var(--color-primary-subtle);
  box-shadow: 0 0 0 2px var(--color-primary-subtle), var(--shadow-sm);
}

.pipeline-stage-detail.is-active { border-color: var(--color-primary-border); }
.pipeline-stage-detail.is-complete { border-color: var(--color-success-border); }
.pipeline-stage-detail.is-failed { border-color: var(--color-danger-fg); }

.pipeline-stage-detail.is-complete .pipeline-stage-detail__label { color: var(--color-success-fg); }
.pipeline-stage-detail.is-complete .pipeline-stage-detail__count { color: var(--color-fg); }

.pipeline-stage-detail__summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.75rem;
}

.pipeline-stage-detail__label { color: var(--color-fg); font-weight: 700; }
.pipeline-stage-detail__count { color: var(--color-fg-muted); font-size: 0.7rem; white-space: nowrap; }

.pipeline-substage-list {
  margin: 0;
  padding: 0 0.65rem 0.55rem;
  list-style: none;
}

.pipeline-substage {
  display: grid;
  grid-template-columns: 1rem minmax(0, 1fr);
  gap: 0.4rem;
  padding: 0.26rem 0;
  color: var(--color-fg-muted);
  font-size: 0.72rem;
}

.pipeline-substage__marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.82rem;
  height: 0.82rem;
  margin-top: 0.1rem;
  border: 1px solid var(--color-border);
  border-radius: 50%;
  color: var(--color-on-accent);
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1;
}

.pipeline-substage__body { display: flex; justify-content: space-between; gap: 0.6rem; min-width: 0; }
.pipeline-substage__label { overflow: hidden; color: inherit; font-weight: 600; text-overflow: ellipsis; }
.pipeline-substage__status { flex: 0 0 auto; color: var(--color-fg-subtle); font-variant-numeric: tabular-nums; white-space: nowrap; }
.pipeline-substage__status-label,
.pipeline-substage__status-meta { color: inherit; }
.pipeline-substage.is-running { color: var(--color-primary); }
.pipeline-substage.is-running .pipeline-substage__marker {
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  animation: pipeline-stage-spin 0.9s linear infinite;
}
.pipeline-substage.is-complete .pipeline-substage__marker { border-color: var(--color-success-fg); background: var(--color-success-fg); }
.pipeline-substage.is-reused .pipeline-substage__marker {
  border-color: transparent;
  background: transparent;
  color: var(--color-success-fg);
  font-family: Arial, sans-serif;
  font-size: 0.95rem;
}
.pipeline-substage.is-complete,
.pipeline-substage.is-reused { color: var(--color-fg); }
.pipeline-substage.is-complete .pipeline-substage__status-label,
.pipeline-substage.is-reused .pipeline-substage__status-label { color: var(--color-success-fg); }
.pipeline-substage.is-complete .pipeline-substage__status-meta,
.pipeline-substage.is-reused .pipeline-substage__status-meta { color: var(--color-fg); }
.pipeline-substage.is-skipped .pipeline-substage__marker { border-color: var(--color-fg-subtle); background: var(--color-fg-subtle); }
.pipeline-substage.is-failed { color: var(--color-danger-fg); }
.pipeline-substage.is-failed .pipeline-substage__marker { border-color: var(--color-danger-fg); background: var(--color-danger-fg); }

@keyframes pipeline-pulse {
  50% { opacity: 0.35; transform: scale(0.75); }
}

@keyframes pipeline-shimmer {
  to { transform: translateX(100%); }
}

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

/* Source freshness */
.source-freshness {
  margin-bottom: 1.5rem;
  padding: 1rem 1.15rem;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: var(--color-bg);
}

.source-freshness__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.source-freshness__item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: var(--color-bg-subtle);
}

.source-freshness__item img {
  width: 1.5rem;
  height: 1.5rem;
  object-fit: contain;
}

.source-freshness__item div { min-width: 0; }

.source-freshness__item span,
.source-freshness__item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-freshness__item span {
  margin-bottom: 0.12rem;
  color: var(--color-fg-subtle);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-freshness__item strong {
  color: var(--color-fg);
  font-size: 0.9rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------------
   Analytics sections
   A section heading, then flat blocks: one border per block, and figures,
   tables and charts inside it without frames of their own. Colour marks
   the data source (ATLAS navy, OSM green) and problem severity only.
   ------------------------------------------------------------------------- */
[data-source="atlas"] {
  --source: var(--color-primary);
  --source-subtle: var(--color-primary-subtle);
}

[data-source="osm"] {
  --source: var(--color-success);
  --source-subtle: var(--color-success-subtle);
}

.stats-block {
  margin-bottom: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
}

.stats-block > :last-child {
  margin-bottom: 0;
}

.stats-block__title {
  margin: 0 0 var(--space-3);
  color: var(--color-fg);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
}

.stats-block__subtitle {
  margin: var(--space-6) 0 var(--space-2);
  color: var(--color-fg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.stats-block__lead,
.stats-note,
.stats-empty {
  max-width: 76ch;
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.stats-block__lead {
  margin: 0 0 var(--space-3);
}

.stats-note {
  margin: var(--space-3) 0 0;
  font-size: var(--text-xs);
}

.stats-eyebrow {
  display: block;
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Key figures: a framed strip on its own, a tinted strip inside a block. */
.stats-figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: var(--space-4) var(--space-6);
  margin-bottom: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
}

.stats-block .stats-figures {
  padding: var(--space-4);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
}

.stats-figure {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.stats-figure__value {
  color: var(--color-fg);
  font-size: var(--text-2xl);
  font-weight: var(--font-semibold);
  letter-spacing: -0.02em;
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}

.stats-figure__label {
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.stats-figure__note {
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

/* Side-by-side parts of a block, without frames. */
.stats-columns {
  display: grid;
  gap: var(--space-6) var(--space-8);
}

.stats-columns--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stats-columns--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-block > * + .stats-columns {
  margin-top: var(--space-6);
}

.stats-columns > div > .stats-block__subtitle:first-child {
  margin-top: 0;
}

.stats-panel {
  min-width: 0;
}

.stats-panel__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.stats-panel__head h4 {
  margin: 0.125rem 0 0;
  color: var(--color-fg);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
}

.stats-panel__head > strong {
  color: var(--color-fg);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-panel__help {
  margin: 0 0 var(--space-3);
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.stats-key {
  padding: 0.125rem 0.45rem;
  border-radius: var(--radius-sm);
  color: var(--source);
  background: var(--source-subtle);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  white-space: nowrap;
}

/* Proportions: a split bar or meter with its legend. */
.stats-split,
.stats-meter {
  display: flex;
  height: 0.625rem;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
}

.stats-split > span,
.stats-meter > span {
  display: block;
}

.stats-meter {
  margin-top: var(--space-1);
}

.stats-meter > span {
  min-width: 2px;
  border-radius: inherit;
  background: var(--source, var(--color-fg-muted));
}

.stats-split > .is-strong,
.stats-swatch.is-strong {
  background: var(--source, var(--color-fg-muted));
}

.stats-split > .is-soft,
.stats-swatch.is-soft {
  background: var(--source, var(--color-fg-muted));
  opacity: 0.4;
}

.stats-swatch {
  flex: none;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.5rem;
  border-radius: 2px;
}

.stats-legend {
  display: grid;
  gap: var(--space-2);
  margin: var(--space-3) 0 0;
}

.stats-legend > div,
.stats-kv > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
}

.stats-legend dt {
  display: flex;
  align-items: center;
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-normal);
}

.stats-legend dd,
.stats-kv dd {
  margin: 0;
  color: var(--color-fg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-legend dd small,
.stats-kv dd small {
  margin-left: 0.35em;
  color: var(--color-fg-muted);
  font-weight: var(--font-normal);
}

.stats-meters {
  display: grid;
  gap: var(--space-3);
}

.stats-meters__label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--text-sm);
}

.stats-meters__label span {
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
}

.stats-meters small {
  display: block;
  margin-top: var(--space-1);
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

/* Label and value pairs, in short columns so values stay near labels. */
.stats-kv {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(24rem, 100%), 1fr));
  column-gap: var(--space-8);
  margin: 0;
}

.stats-kv--single {
  grid-template-columns: minmax(0, 1fr);
}

.stats-kv > div {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.stats-kv dt {
  min-width: 0;
  color: var(--color-fg);
  font-size: var(--text-sm);
  font-weight: var(--font-normal);
}

.stats-figures + .stats-kv,
.stats-kv + .stats-note {
  margin-top: var(--space-3);
}

/* Tables */
.stats-table-wrap {
  overflow-x: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.stats-table--compact {
  max-width: 48rem;
}

.stats-table th,
.stats-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  text-align: right;
  white-space: nowrap;
}

.stats-table th:first-child,
.stats-table td:first-child {
  padding-left: 0;
  text-align: left;
  white-space: normal;
}

.stats-table th:last-child,
.stats-table td:last-child {
  padding-right: 0;
}

.stats-table thead th {
  border-bottom-color: var(--color-border-emphasis);
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stats-table tbody th {
  color: var(--color-fg);
  font-weight: var(--font-normal);
}

.stats-table .is-total th,
.stats-table .is-total td,
.stats-table .is-group th,
.stats-table .is-group td {
  font-weight: var(--font-semibold);
}

.stats-table .is-level-1 th {
  padding-left: var(--space-4);
  color: var(--color-fg-muted);
}

.stats-table .is-secondary,
.stats-table .is-empty td {
  color: var(--color-fg-muted);
}

.stats-table .is-empty td {
  padding-left: var(--space-4);
  text-align: left;
}

.stats-table tfoot th,
.stats-table tfoot td {
  border-bottom: 0;
  font-weight: var(--font-semibold);
}

.stats-table--priorities .is-group th,
.stats-table--priorities .is-group td {
  padding-top: var(--space-4);
}

.stats-table--priorities .priority-badge {
  margin-right: var(--space-2);
}

/* Shares of a total, one bar per row. */
.stats-bars {
  display: grid;
  gap: var(--space-2);
  max-width: 48rem;
}

.stats-bar {
  display: grid;
  grid-template-columns: minmax(10rem, 1.6fr) minmax(4rem, 1fr) 4.5rem 3.5rem;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.stats-bar__track {
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
}

.stats-bar__track span {
  display: block;
  min-width: 2px;
  height: 100%;
  border-radius: inherit;
  background: var(--source, var(--color-fg-muted));
}

.stats-bar strong,
.stats-bar small {
  text-align: right;
}

.stats-bar strong {
  font-weight: var(--font-semibold);
}

.stats-bar small {
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.stats-details {
  margin-top: var(--space-4);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.stats-details summary {
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  cursor: pointer;
}

.stats-details summary span {
  margin-left: 0.5em;
  font-weight: var(--font-normal);
}

.stats-details .stats-kv {
  margin-top: var(--space-2);
}

/* Many-to-one distribution */
.distribution-chart {
  display: grid;
  gap: var(--space-2);
}

.distribution-chart__row {
  display: grid;
  grid-template-columns: 3.7rem minmax(3rem, 1fr) 3.4rem 3rem;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-fg);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.distribution-chart__row strong {
  font-family: var(--font-mono);
  font-weight: var(--font-semibold);
}

.distribution-chart__row > span,
.distribution-chart__row small {
  text-align: right;
}

.distribution-chart__row small {
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.distribution-chart__track {
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--source-subtle, var(--color-bg-muted));
}

.distribution-chart__track span {
  display: block;
  min-width: 3px;
  height: 100%;
  border-radius: inherit;
  background: var(--source, var(--color-fg-muted));
}

/* What unmatched OSM stops carry */
.attribute-matrix__grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.attribute-matrix__item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.125rem var(--space-3);
  min-width: 0;
  padding: var(--space-3);
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
}

.attribute-matrix__item:nth-child(4n) { border-right: 0; }
.attribute-matrix__item:nth-last-child(-n + 4) { border-bottom: 0; }

.attribute-matrix__item span {
  overflow: hidden;
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attribute-matrix__item strong {
  grid-row: span 2;
  color: var(--color-fg);
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
}

.attribute-matrix__item small {
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.attribute-matrix__item--muted {
  background: var(--color-bg-subtle);
}

/* Ordered GTFS → ATLAS matching paths */
.mapping-paths {
  margin: var(--space-6) 0;
}

.mapping-paths__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
}

.mapping-paths__header .stats-block__subtitle {
  margin: 0.125rem 0 0;
}

.mapping-paths__header p {
  margin: var(--space-1) 0 0;
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.mapping-paths__total {
  text-align: right;
  white-space: nowrap;
}

.mapping-paths__total strong {
  display: block;
  color: var(--color-fg);
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
}

.mapping-paths__total span {
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.mapping-path {
  position: relative;
  display: grid;
  grid-template-columns: 2rem minmax(14rem, 1.4fr) minmax(9rem, 1fr) 5rem;
  align-items: center;
  gap: var(--space-4);
  min-height: 4.5rem;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

.mapping-path:last-child { border-bottom: 0; }

.mapping-path__step {
  position: relative;
  z-index: 1;
  display: grid;
  width: 1.75rem;
  height: 1.75rem;
  place-items: center;
  border-radius: var(--radius-full);
  color: var(--source);
  background: var(--source-subtle);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
}

.mapping-path:not(:last-child) .mapping-path__step::after {
  position: absolute;
  top: 1.75rem;
  left: calc(50% - 1px);
  width: 2px;
  height: 3rem;
  background: var(--source-subtle);
  content: "";
}

.mapping-path__copy h5 {
  margin: 0;
  color: var(--color-fg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.mapping-path__copy p {
  margin: var(--space-1) 0 0;
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
}

.mapping-path__measure {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 3rem;
  align-items: center;
  gap: var(--space-2);
}

.mapping-path__measure > div {
  height: 0.5rem;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
}

.mapping-path__measure > div span {
  display: block;
  min-width: 2px;
  height: 100%;
  border-radius: inherit;
  background: var(--source);
}

.mapping-path__measure small {
  color: var(--color-fg-muted);
  font-size: var(--text-xs);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mapping-path__count {
  color: var(--color-fg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 991.98px) {
  .source-freshness { grid-template-columns: 1fr; }
  .source-freshness__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-columns--3 { grid-template-columns: 1fr; }
  .attribute-matrix__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attribute-matrix__item:nth-child(4n) { border-right: 1px solid var(--color-border); }
  .attribute-matrix__item:nth-child(2n) { border-right: 0; }
  .attribute-matrix__item:nth-last-child(-n + 4) { border-bottom: 1px solid var(--color-border); }
  .attribute-matrix__item:nth-last-child(-n + 2) { border-bottom: 0; }
  .mapping-path { grid-template-columns: 2rem minmax(12rem, 1.4fr) minmax(7rem, 1fr) 4.5rem; }
}

@media (max-width: 767.98px) {
  .stats-container { padding: 0 0.85rem; }
  .stats-page-header__row { align-items: flex-start; flex-direction: column; }
  .stats-page-header__row > .d-flex {
    align-items: flex-start !important;
    flex-direction: column;
    gap: 0.65rem;
    width: 100%;
  }
  .stats-page-header__row .text-muted { white-space: normal; }
  .pipeline-run-card__header { flex-direction: column; }
  .pipeline-run-card__meta { align-items: flex-start; }
  .pipeline-timeline { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pipeline-timeline__stage { min-width: 0; }
  .stats-block { padding: var(--space-4); }
  .stats-columns--2 { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: minmax(0, 1fr) 4rem 3rem; }
  .stats-bar__track { grid-column: 1 / -1; grid-row: 2; }
  .mapping-paths__header { flex-direction: column; }
  .mapping-paths__total { text-align: left; }
  .mapping-path {
    grid-template-columns: 2rem minmax(0, 1fr) 4.2rem;
    gap: var(--space-3);
  }
  .mapping-path__measure { grid-column: 2 / -1; }
  .mapping-path:not(:last-child) .mapping-path__step::after { height: 5rem; }
}

@media (max-width: 575.98px) {
  .source-freshness__grid,
  .attribute-matrix__grid { grid-template-columns: 1fr; }
  .source-freshness__item { padding: 0.6rem; }
  .attribute-matrix__item,
  .attribute-matrix__item:nth-child(2n),
  .attribute-matrix__item:nth-child(4n),
  .attribute-matrix__item:nth-last-child(-n + 4) { border-right: 0; border-bottom: 1px solid var(--color-border); }
  .attribute-matrix__item:last-child { border-bottom: 0; }
  .distribution-chart__row { grid-template-columns: 3.2rem minmax(2rem, 1fr) 3rem; }
  .distribution-chart__row small { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stats-section-nav.is-ready .stats-section-nav__indicator,
  .stats-section-nav__link { transition: none; }
  .pipeline-timeline__fill,
  .pipeline-timeline__track,
  .pipeline-stage-detail { transition: none; }
  .pipeline-timeline__stage.is-active .pipeline-timeline__fill::after,
  .pipeline-run-card.is-running .pipeline-run-card__dot,
  .pipeline-timeline__state.is-active { animation: none; }
}

@media print {
  .stats-section-nav-shell,
  .stats-section-nav,
  .pipeline-run-card { display: none !important; }
  .stats-page { background: var(--color-bg); }
  .stats-section-title { scroll-margin-top: 0; }
  .stats-figures,
  .stats-panel,
  .stats-table tr { break-inside: avoid; }
}

/* Quiet page action beside "Stats computed", as on the documentation pages. */
.stats-page-action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
}

.stats-page-action:hover,
.stats-page-action:focus-visible {
  color: var(--color-fg);
  text-decoration: underline;
}
