/* ==========================================================================
   ENSPARA DOCUMENTS
   The A4 grammar shared by every PDF the site publishes: the three print
   sources under /downloads (which load this for all media) and the four case
   studies (which load it media="print", on top of the screen page).

   scripts/render-pdfs.mjs prints each source with headless Chrome and asserts
   the page count in scripts/pdf-manifest.json. The HTML is the source; the
   PDF is never hand-edited. Tokens come from styles.css, loaded first.
   ========================================================================== */

@page {
  size: A4;
  margin: 14mm 15mm 16mm;
}

/* ---------- The document frame (download pages, every medium) ---------- */

.doc {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 24px 64px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.doc p { margin: 0 0 0.6em; }
.doc p:last-child { margin-bottom: 0; }

/* Masthead: what the document is, its title, the wordmark. */
.doc-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 22px;
}

.doc-head img {
  height: 30px;
  width: auto;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.doc-kicker {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent-dark);
}

.doc h1 {
  margin: 0;
  font-size: 1.7rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--primary);
  text-wrap: balance;
}

.doc-lede {
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  max-width: 62ch;
}

/* Numbered sections: the number is the section's index, not decoration. */
.doc h2 {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 26px 0 4px;
  font-size: 1.05rem;
  color: var(--primary);
}

.doc h2 .n {
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
}

.doc-note {
  margin: 0 0 6px;
  font-size: 0.85rem;
  color: var(--text-light);
}

/* Checklist rows: a square to tick, the item, the detail. */
.doc-list {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.88rem;
}

.doc-list td {
  padding: 9px 10px 9px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  line-height: 1.45;
}

.doc-list tr:last-child td { border-bottom: 0; }

.doc-list td.box { width: 30px; padding-top: 11px; }

.doc-list td.item {
  width: 32%;
  font-weight: 600;
  color: var(--primary);
}

.doc-list td.n {
  width: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-dark);
}

.doc-list td.yn {
  width: 118px;
  white-space: nowrap;
  text-align: right;
  color: var(--text-light);
}

.doc-check {
  display: inline-block;
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--primary);
  border-radius: 3px;
  vertical-align: -2px;
  margin-right: 6px;
}

.doc-check:last-child { margin-right: 0; }

/* A ruled aside: what to do with the answers. */
.doc-callout {
  margin-top: 22px;
  padding: 12px 16px;
  background: var(--bg-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.doc-callout strong { color: var(--primary); }

/* A sequence, set as one. */
.doc-steps {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  counter-reset: step;
}

.doc-steps li {
  counter-increment: step;
  position: relative;
  padding: 0 0 12px 40px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.doc-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 26px;
  text-align: center;
}

.doc-steps li::after {
  content: "";
  position: absolute;
  left: 12.5px;
  top: 29px;
  bottom: -2px;
  border-left: 1.5px solid var(--border);
}

.doc-steps li:last-child { padding-bottom: 0; }
.doc-steps li:last-child::after { display: none; }

.doc-steps strong {
  display: block;
  color: var(--primary);
  margin-bottom: 1px;
}

/* A worked figure: three tiles and the arithmetic between them. */
.doc-figure {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: stretch;
  gap: 10px;
  margin: 12px 0 8px;
}

.doc-figure .tile {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.doc-figure .tile.result {
  background: var(--bg-light);
  border-color: var(--accent);
}

.doc-figure .tile .label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-light);
  margin-bottom: 4px;
}

.doc-figure .tile .value {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.doc-figure .tile.result .value { color: var(--accent-dark); }

.doc-figure .tile .unit {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-left: 3px;
}

.doc-figure .op {
  align-self: center;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-light);
}

.doc-figure-note {
  font-size: 0.85rem;
  color: var(--text);
}

.doc-figure-note strong { color: var(--accent-dark); }

.doc-small {
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text-light);
}

/* The sheet: one table, one body cell, one footer cell. On paper Chrome repeats
   a real tfoot on every page and reserves its space, which no positioned
   footer can do. On screen it is invisible structure (role="presentation"). */
.doc-sheet { width: 100%; table-layout: fixed; border-collapse: collapse; }
.doc-sheet > tbody > tr > td, .doc-sheet > tfoot > tr > td { padding: 0; border: 0; vertical-align: top; }

/* Footer: who we are, on every page. */
.doc-foot {
  margin-top: 30px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-light);
}

.doc-foot-inner {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.doc-foot .brand {
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

.doc-foot .brand span {
  font-weight: 400;
  color: var(--text-light);
}

.doc-foot .right { text-align: right; max-width: 60%; }

@media screen and (max-width: 560px) {
  .doc-head { flex-wrap: wrap; gap: 14px; }
  .doc-figure { grid-template-columns: 1fr; }
  .doc-figure .op { justify-self: center; }
  .doc-foot-inner { flex-direction: column; }
  .doc-foot .right { text-align: left; max-width: none; }
}

/* ---------- On paper ---------- */

@media print {
  html, body { background: #fff !important; }

  .doc {
    max-width: none;
    padding: 0;
    font-size: 9.5pt;
    line-height: 1.45;
  }

  /* The one-pager has room to breathe; the checklists are set to fit. */
  .doc.doc-roomy { font-size: 10.5pt; line-height: 1.5; }
  .doc.doc-roomy .doc-lede { font-size: 11pt; }
  .doc.doc-roomy .doc-steps li { font-size: 9.8pt; padding-bottom: 11pt; }
  .doc.doc-roomy .doc-figure .tile .value { font-size: 19pt; }
  .doc.doc-roomy .doc-figure .tile { padding: 11pt 13pt; }
  .doc.doc-roomy .doc-figure-note { font-size: 9.5pt; }
  .doc.doc-roomy .doc-small { font-size: 8.8pt; }
  .doc.doc-roomy h2 { font-size: 12pt; margin-top: 20pt; }

  .doc h1 { font-size: 19pt; }
  .doc-lede { font-size: 10pt; }
  .doc h2 { font-size: 11pt; margin-top: 16pt; break-after: avoid; }
  .doc-note { font-size: 8.5pt; }
  .doc-list { font-size: 8.8pt; }
  .doc-list td { padding: 6pt 8pt 6pt 0; }
  .doc-list tr { break-inside: avoid; }
  .doc-callout { font-size: 8.8pt; break-inside: avoid; }
  .doc-steps li { font-size: 8.8pt; padding-bottom: 8pt; break-inside: avoid; }
  .doc-steps li::before { width: 20pt; height: 20pt; line-height: 20pt; font-size: 8pt; }
  .doc-steps li::after { left: 9.5pt; top: 22pt; }
  .doc-figure { break-inside: avoid; }
  .doc-figure .tile .value { font-size: 15pt; }
  .doc-figure-note, .doc-small { font-size: 8.3pt; }
  .doc-head img { height: 26px; }

  /* The footer repeats on every sheet. A fixed element shares the page area
     with the text and overprints it on a full page, and one pushed into the
     margin makes Chrome emit a blank sheet. A table footer group does what a
     printed table's tfoot does: repeats on each page with its space reserved. */
  .doc-foot { margin: 0; font-size: 7.5pt; }
  .doc-foot-inner { padding-top: 6pt; }

  /* A heading never ends a page on its own. */
  .doc h2, .doc-note { break-after: avoid; }
  .doc-list tr:first-child { break-before: avoid; }
}

/* ==========================================================================
   CASE STUDIES ON PAPER
   A one-page evidence sheet. The screen page links this media="print", so
   nothing here touches the screen. The PDF is an allow list: only the hero
   and the sections marked .cs-print print, so a section added to the page
   later cannot silently lengthen the sheet. Set densely on purpose.
   ========================================================================== */

@media print {
  body.case-study {
    font-size: 8.2pt;
    line-height: 1.34;
    color: var(--text);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body.case-study main > section { display: none !important; }
  body.case-study main > section.projects-hero,
  body.case-study main > section.cs-print { display: block !important; padding: 0 !important; background: none !important; }
  body.case-study .cs-narrative, body.case-study .cs-cta, body.case-study #deployment-assurance,
  body.case-study .product-image { display: none !important; }

  body.case-study .container { max-width: none !important; padding: 0 !important; }
  body.case-study main > section > .container > * { max-width: none !important; }

  /* Masthead: eyebrow, title and subtitle left; wordmark right; a rule under. */
  body.case-study .projects-hero .container { position: relative; text-align: left; padding-right: 120px !important; padding-bottom: 8pt !important; border-bottom: 2px solid var(--primary); margin-bottom: 8pt; }
  body.case-study .projects-hero { color: var(--text) !important; }
  body.case-study .projects-hero .section-badge {
    display: inline-block !important; margin: 0 0 3pt; padding: 0; background: none !important;
    font-size: 7pt; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent-dark) !important;
  }
  body.case-study .projects-hero h1 { font-size: 18pt; line-height: 1.15; margin: 0 0 3pt; color: var(--primary) !important; text-align: left; }
  body.case-study .projects-hero .section-subtitle { font-size: 8.5pt; line-height: 1.35; margin: 0; color: var(--text-light) !important; text-align: left; max-width: none; }
  body.case-study .cs-print-head { display: block !important; position: absolute; top: 2pt; right: 0; }
  body.case-study .cs-print-head img { height: 24px; width: auto; }

  /* The three headline figures, in a row. */
  body.case-study .stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6pt; margin: 8pt 0 4pt; }
  body.case-study .stat-card { padding: 7pt 8pt !important; border: 1px solid var(--border); border-radius: 6px; background: var(--bg-light) !important; text-align: left; }
  body.case-study .stat-prefix { display: block; font-size: 6.5pt; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-light) !important; margin: 0 0 1pt; }
  body.case-study .stat-number { display: block; font-size: 17pt; font-weight: 800; line-height: 1.1; margin: 0 0 2pt; color: var(--accent-dark) !important; }
  body.case-study .stat-label { font-size: 7.4pt; line-height: 1.3; color: var(--text) !important; }
  body.case-study .projects-hero .stat-qualifier { margin: 0 !important; font-size: 6.8pt; color: var(--text-light); max-width: none !important; text-align: left; }

  /* Sections. */
  body.case-study main > section.cs-print { margin-top: 7pt; }
  body.case-study main > section > .container > h2 { font-size: 10.5pt; line-height: 1.2; margin: 0 0 3pt !important; padding-bottom: 2pt; border-bottom: 1px solid var(--border); color: var(--primary); }
  body.case-study main > section > .container > h3 { font-size: 8pt; margin: 4pt 0 1pt; color: var(--primary); }
  body.case-study main > section > .container > p, body.case-study li { margin: 0 0 2.5pt; }
  body.case-study main > section > .container > p + p { margin-top: 0 !important; }
  body.case-study .cs-print .section-badge { display: none !important; }
  body.case-study .project-highlights { margin: 0; padding: 0; list-style: none; }
  body.case-study .project-highlights li { position: relative; padding-left: 9pt; }
  body.case-study .project-highlights li::before { content: ""; position: absolute; left: 0; top: 5pt; width: 4pt; height: 4pt; border-radius: 50%; background: var(--accent); }

  /* The results table. */
  body.case-study .table-scroll { border: 1px solid var(--border); border-radius: 5px; overflow: hidden; margin: 4pt 0 3pt; break-inside: avoid; }
  body.case-study .results-table { margin: 0 !important; font-size: 7.4pt; border-collapse: collapse; }
  body.case-study .results-table caption { padding: 4pt 7pt; font-size: 7.2pt; color: var(--text-light); border-bottom: 1px solid var(--border); background: var(--bg-light); text-align: left; }
  body.case-study .results-table thead th { background: var(--primary) !important; color: #fff !important; font-size: 6.6pt; letter-spacing: 0.08em; text-transform: uppercase; padding: 3.5pt 7pt; border: 0; }
  body.case-study .results-table th, body.case-study .results-table td { padding: 3pt 7pt; vertical-align: top; border-bottom: 1px solid var(--border); line-height: 1.3; }
  body.case-study .results-table tbody th { color: var(--primary); font-weight: 600; background: transparent !important; }
  body.case-study .results-table tbody tr:nth-child(even) > * { background: var(--bg-light) !important; }
  body.case-study .results-table tbody tr:last-child > * { border-bottom: 0; }
  body.case-study .stat-qualifier { font-size: 7pt; line-height: 1.3; color: var(--text-light); margin: 2pt 0 0 !important; }

  /* The evidence note is a footnote and reads as one. */
  body.case-study #evidence p, body.case-study #evidence li { font-size: 7pt; line-height: 1.3; }

  /* Links print as text. */
  body.case-study a { color: var(--primary); text-decoration: none; }
  body.case-study a[href]::after { content: ""; }

  /* Footer on the sheet. */
  body.case-study .cs-print-foot {
    display: flex !important; justify-content: space-between; gap: 12pt;
    position: fixed; left: 0; right: 0; bottom: 0;
    padding-top: 4pt; border-top: 1px solid var(--border);
    font-size: 6.8pt; line-height: 1.35; color: var(--text-light); background: #fff;
  }
  body.case-study .cs-print-foot .brand { font-weight: 600; color: var(--primary); white-space: nowrap; }
  body.case-study .cs-print-foot .brand span { font-weight: 400; color: var(--text-light); }
  body.case-study .cs-print-foot .right { text-align: right; }
  body.case-study main { padding-bottom: 12mm; }
}
