/* Keep column names in view inside long, independently scrolling data tables.
   Short tables retain their natural height; card layouts on small screens stay cards. */
.cp-table-wrap,
.cp-table-scroll,
.ca-table-wrap,
.macro-scroll {
  max-height: min(560px, 70vh);
  overflow: auto;
}

.cp-table-wrap .cp-table thead th,
.cp-table-scroll .cp-heat-table thead th,
.ca-table-wrap .ca-table thead th,
.macro-scroll .macro-matrix thead th,
.sd__scroll table thead th,
.ee-table table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--ds-surface-soft);
  box-shadow: inset 0 -2px #c8d8d2;
}

.cp-table-scroll .cp-heat-table thead th { background: var(--ds-surface-soft); }
.ca-table-wrap .ca-table thead th { background: var(--ds-surface-soft); }
.macro-scroll .macro-matrix thead th { background: var(--ds-surface-soft); }
.sd__scroll table thead th,
.ee-table table thead th { background: var(--ds-surface-soft); }

/* The atlas country × region matrix has a single header row.  Freezing every
   cell separately left hairline gaps during vertical scrolling, through which
   the coloured first data row could appear.  Freeze the row as one opaque
   surface instead: the column names remain available without creating a
   phantom coloured strip above them. */
.macro-scroll .macro-matrix {
  border-collapse: collapse;
  border-spacing: 0;
}
.macro-scroll .macro-matrix thead {
  position: sticky;
  top: 0;
  z-index: 5;
}
.macro-scroll .macro-matrix thead th {
  position: static;
  background: var(--ds-surface-soft);
  box-shadow: inset 0 -2px #c8d8d2;
}
.macro-scroll .macro-matrix th,
.macro-scroll .macro-matrix td {
  border: 2px solid var(--ds-surface);
}

/* The source matrix also freezes row labels: they must not sit over the header. */
.sv__matrix tbody th.row { top: auto; }
.sv__matrix thead th { z-index: 3; box-shadow: inset 0 -2px var(--sv-grid); }
.sv__matrix thead th:first-child { left: 0; z-index: 4; }

@media (max-width: 700px) {
  .cp-flight-table .cp-table-wrap,
  #evidence-method .cp-table-wrap { max-height: none; overflow: visible; }
}
