/*
 * This file is part of the govuk-dita-plugin project.
 * Copyright 2026 iStandUK. Licensed under the Apache License, Version 2.0.
 *
 * Print stylesheet (FR-P1, D-20), loaded with media="print" by every page.
 * govuk-frontend already supplies print typography (point sizes, printed link
 * URLs); this file adds the page box, hides the site chrome, sets a single
 * column and controls page breaks. The page size is filled in at build time
 * from govuk.pdf.paper and govuk.pdf.orientation.
 */

@page {
  size: A4 portrait;
  margin: 20mm 18mm 22mm 18mm;

  @bottom-right {
    content: counter(page) " / " counter(pages);
    font-family: sans-serif;
    font-size: 9pt;
    color: #505a5f;
  }
}

/* Chrome with no meaning on paper */
.govuk-skip-link,
.app-masthead,
.govuk-header,
.govuk-phase-banner,
.app-sidebar,
.govuk-pagination,
.govuk-footer,
.govuk-back-link,
.app-print-screen-only {
  display: none !important;
}

/* Single column */
.govuk-width-container {
  max-width: none;
  margin: 0;
}

.govuk-main-wrapper {
  padding: 0;
}

.govuk-grid-column-two-thirds,
.govuk-grid-column-one-third {
  width: 100%;
  float: none;
  padding: 0;
}

/* Breaks */
h1,
h2,
h3,
h4,
h5,
h6,
[role="heading"] {
  break-after: avoid;
  page-break-after: avoid;
}

figure,
table,
pre,
.govuk-inset-text,
.govuk-warning-text,
.app-hazard {
  break-inside: avoid;
  page-break-inside: avoid;
}

/* A warning or note that introduces a code block is not left at the foot of a
   page with the code overleaf: the block takes the warning with it (#158) */
.govuk-warning-text + pre,
.govuk-inset-text + pre {
  break-before: avoid;
  page-break-before: avoid;
}

tr {
  break-inside: avoid;
  page-break-inside: avoid;
}

thead {
  display: table-header-group;
}

p,
li,
dd {
  orphans: 3;
  widows: 3;
}

/* Wide content flows rather than scrolls */
#main-content table {
  display: table;
  overflow: visible;
}

pre {
  white-space: pre-wrap;
  overflow: visible;
}

img,
svg {
  max-width: 100%;
}

/* Type scale of the print document (#148). The Design System's print sizes
 * are for a web page sent to a printer (body 14pt, headings 32/24/18/14pt).
 * The print document is a publication, and becomes the PDF, so it takes the
 * sizes government practice gives for documents: title 24-28pt, section
 * headings 18-20pt, subheadings 14-16pt, body 12pt, captions 10-11pt. A page
 * printed from the site keeps the Design System's sizes. These are defaults:
 * a publisher's stylesheet (args.css) is linked later and can change them. */

/* Title: the publication's, on the cover */
.app-print .govuk-heading-xl {
  font-size: 28pt;
}

/* Section headings: chapters, parts, and topics at the top of the map */
.app-print .govuk-heading-l {
  font-size: 20pt;
}

/* Subheadings: topics inside a chapter, then the sections inside a topic */
.app-print .govuk-heading-m {
  font-size: 16pt;
}

.app-print .govuk-heading-s,
.app-print #main-content .sectiontitle.tasklabel,
.app-print #main-content .sectiontitle:not([class*="govuk-heading"]) {
  font-size: 14pt;
}

/* The lead paragraph: the cover's abstract and each topic's summary */
.app-print .govuk-body-l,
.app-print .govuk-body-lead {
  font-size: 14pt;
}

/* Body text, in every component that sets its own size */
.app-print .govuk-body,
.app-print .govuk-body-m,
.app-print .govuk-body-s,
.app-print .govuk-list,
.app-print .govuk-table,
.app-print .govuk-inset-text,
.app-print .govuk-warning-text,
.app-print .govuk-details,
.app-print .govuk-summary-list {
  font-size: 12pt;
}

/* Captions of tables and figures, and the cover's imprint (#150) */
.app-print .govuk-table__caption,
.app-print #main-content figcaption,
.app-print .app-print-imprint .govuk-body-s {
  font-size: 11pt;
}

/* The cover gives the site's address as the link's own text; the Design
 * System would print the address again after it */
.app-print .app-print-imprint a.app-print-url::after {
  content: none;
}

/* Code, set a little smaller than the text around it, and endnotes */
.app-print pre.codeblock,
.app-print pre.pre {
  font-size: 10.5pt;
}

.app-print .app-print-endnotes,
.app-print .app-print-endnotes .govuk-body {
  font-size: 10pt;
}

/* Print document structure (FR-P2): cover and contents on their own pages,
   every chapter on a new page */
.app-print-cover,
.app-print-contents {
  break-after: page;
  page-break-after: always;
}

.app-print-chapter {
  break-before: page;
  page-break-before: always;
}

/* Page references (#107). A link that resolves inside the print document is
 * followed by the page it points at — "Installing the plugin (page 13)" — and
 * the contents and index carry page numbers instead of being bare links. The
 * label travels in data-page-label so it stays localisable. target-counter()
 * is CSS Generated Content for Paged Media: browsers do not implement it and
 * drop these declarations whole, so printing from a browser is unchanged;
 * a CSS Paged Media formatter (govuk.pdf.command) resolves them. */
.app-print a.xref[data-page-label]::after {
  content: " (" attr(data-page-label) " " target-counter(attr(href url), page) ")";
}

.app-print .app-print-contents__list a[data-page-label]::after {
  content: " " leader('.') " " target-counter(attr(href url), page);
}

.app-print .app-index-list a[data-page-label]::after,
.app-print .app-itemlist a[data-page-label]::after {
  content: " " target-counter(attr(href url), page);
}
