/*
 * Comparison guides (release 0.14.0): the box that says how a page was made, and the tables that set the makers'
 * figures side by side.
 *
 *   design-system/buildbatch/pages/job-and-comparison-pages.md   "Comparison articles": what this implements
 *
 * Loaded by pages/guides/[slug].astro after app.css, only for a guide tagged "comparison". Tokens from site.css
 * only, never a raw colour. No shadows, no sticky parts, no motion. Phone first.
 *
 * A table has two shapes. From 48rem it is a table in a wrapper: a table wider than its column scrolls inside the
 * wrapper, which takes the keyboard's focus. Below 48rem a table with more than two columns becomes one block per
 * row, each figure under its own heading (the cell's data-label), so nothing has to be scrolled sideways to be read.
 * A short table (compare-table--narrow) fits a phone as it is and is left a table. The page never scrolls sideways.
 */

/* "How this page was made": an information icon and words, straight after the lead, before any result. */
.guide__body .made-box {
  margin: var(--space-lg) 0 0;
  padding: var(--space-md);
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-muted);
}

.made-box__head {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

.made-box__icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  color: var(--color-link);
}

.guide__body .made-box__title {
  margin: 0;
  font-size: var(--text-lg);
}

.guide__body .made-box p {
  margin-top: var(--space-smd);
  max-width: 42rem;
  font-size: var(--text-base);
}

/* A comparison table: a caption, headings that say what they head, figures that line up. */
.guide__body .table-scroll {
  max-width: 100%;
  margin: var(--space-md) 0 0;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: var(--border-thin) solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
}

/* The wrapper is a control: it takes the keyboard's focus so a table too wide for the screen can be scrolled without a mouse. */
.guide__body .table-scroll:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
}

.guide__body .compare-table {
  width: 100%;
  min-width: 34rem;
  margin: 0;
  border-collapse: collapse;
  font-size: var(--text-sm);
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.guide__body .compare-table--narrow {
  min-width: 0;
}

.guide__body .compare-table caption {
  padding: var(--space-smd) var(--space-smd) var(--space-sm);
  text-align: left;
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.2;
}

.guide__body .compare-table th,
.guide__body .compare-table td {
  padding: var(--space-sm) var(--space-smd);
  border-top: var(--border-thin) solid var(--color-border);
  border-bottom: 0;
  text-align: left;
  vertical-align: top;
}

.guide__body .compare-table thead th {
  border-top: 0;
  border-bottom: var(--border-control) solid var(--color-primary);
  background: var(--color-muted);
  font-weight: 600;
}

/* What is being compared: a product, or a maker. Its own words, one step heavier than the figures. */
.guide__body .compare-table tbody th {
  font-weight: 600;
}

/* A row that names the group under it, such as the floor. It spans the table and is shaded, not coloured. */
.guide__body .compare-table th.compare-table__band {
  background: var(--color-background);
  font-family: var(--font-heading);
  font-size: var(--text-base);
  font-weight: 700;
}

.guide__body .compare-table .num {
  text-align: right;
  white-space: nowrap;
}

/* The maker's own words, and what is left unsaid, in the same cell: the second line is quieter. */
.compare-table small {
  display: block;
  margin-top: var(--space-xs);
  color: var(--color-muted-foreground);
  font-size: var(--text-sm);
}

/* The note under each table: where each figure was read, and when. Small, not hidden. */
.guide__body .table-note {
  margin: var(--space-sm) 0 var(--space-lg);
  max-width: 42rem;
  color: var(--color-muted-foreground);
  font-size: var(--text-sm);
}

.table-note a {
  overflow-wrap: anywhere;
}

/* An example price sits beside the "Example" tag site.css already draws, so it cannot be read as a real one. */
.compare-table .tag,
.guide__body p .tag,
.guide__body li .tag {
  margin-left: var(--space-xs);
  vertical-align: baseline;
}

@media (min-width: 48rem) {
  .guide__body .compare-table {
    font-size: var(--text-base);
    line-height: 1.5;
  }

  .guide__body .compare-table--stack {
    min-width: 40rem;
  }
}

/* A phone: one block per row, each figure under its own heading. The header row stays for a screen reader. */
@media (max-width: 47.99rem) {
  .guide__body .compare-table--stack {
    min-width: 0;
    font-size: var(--text-base);
    line-height: 1.5;
  }

  .compare-table--stack,
  .compare-table--stack tbody,
  .compare-table--stack tr,
  .compare-table--stack th,
  .compare-table--stack td,
  .compare-table--stack caption {
    display: block;
  }

  .compare-table--stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
  }

  .guide__body .compare-table--stack tr {
    padding: var(--space-sm) 0 var(--space-smd);
    border-top: var(--border-thin) solid var(--color-border);
  }

  .guide__body .compare-table--stack tbody tr:first-child {
    border-top: 0;
  }

  .guide__body .compare-table--stack th,
  .guide__body .compare-table--stack td {
    padding: var(--space-xs) var(--space-smd);
    border-top: 0;
  }

  .guide__body .compare-table--stack tbody th {
    font-size: var(--text-lg);
    font-family: var(--font-heading);
  }

  .guide__body .compare-table--stack th.compare-table__band {
    margin-top: var(--space-xs);
    padding: var(--space-sm) var(--space-smd);
    border-top: var(--border-thin) solid var(--color-border);
    font-size: var(--text-lg);
  }

  /* The heading of each figure, from its data-label: the header row is hidden, so the block says what each part is.
     The second content line gives the label empty alternative text where it is understood, so a screen reader, which
     still has the header row, does not read it twice (methods.css does the same). */
  .compare-table--stack td[data-label]::before {
    content: attr(data-label);
    content: attr(data-label) / "";
    display: block;
    color: var(--color-muted-foreground);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .guide__body .compare-table--stack .num {
    text-align: left;
    white-space: normal;
  }

  /* Short figures, such as litres and tins: each beside its heading, so a block is not a page long. */
  .guide__body .compare-table--inline td[data-label] {
    display: grid;
    grid-template-columns: minmax(6rem, 9.5rem) minmax(0, 1fr);
    column-gap: var(--space-smd);
    align-items: baseline;
  }

  .compare-table--inline td[data-label]::before {
    grid-column: 1;
  }

  .compare-table--inline td[data-label] > * {
    grid-column: 2;
  }
}

@media print {
  .guide__body .table-scroll {
    overflow: visible;
    border-color: var(--color-control-border);
  }

  .guide__body .compare-table {
    min-width: 0;
  }
}
