---
name: a4-print-documents
description: >
  Constraints for producing print-quality A4 HTML documents intended for PDF output
  via browser_pdf_save. Use when creating or modifying any HTML document that will be
  saved as PDF, uses A4 page dimensions, or contains glassmorphism/backdrop-filter effects
  that must survive print. Trigger phrases: "PDF", "print to PDF", "download PDF",
  "one-pager", "A4", "brochure", "executive document", "market analysis", or any request
  to generate a document for print or download.
---

# A4 Print-Ready HTML Documents

Constraints for producing HTML documents that render correctly when saved as PDF via the browser-specialist's `browser_pdf_save` tool. Every rule exists because violating it caused a visible problem in production documents.

## Rendering path

Generate the HTML document, then delegate to the browser-specialist to save it as PDF using `browser_pdf_save`. The browser-specialist controls Playwright — you compose the delegation brief describing what to render and any pre-render steps (like glassmorphism screenshot capture).

## Glassmorphism does not survive print

`backdrop-filter: blur()`, CSS glassmorphism, and layered transparency effects render as flat, transparent boxes in browser print/PDF output. This is a browser limitation, not a CSS error.

**Required pattern:** Every section using glassmorphism needs a pre-rendered PNG fallback that is hidden on screen and shown only in print.

```css
.cover-print-img { display: none; }

@media print {
  .cover > *:not(.cover-print-img) { display: none !important; }
  .cover-print-img {
    display: block !important;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}
```

```html
<div class="cover">
  <img class="cover-print-img" src="cover-print.png" alt="">
  <!-- live glassmorphism content follows -->
</div>
```

This pattern applies to every full-bleed glassmorphism section (cover pages, back pages).

### Capturing the print image

Each glassmorphism section needs its own screenshot — you cannot reuse a print image from a different document or a differently-sized section.

Delegate to the browser-specialist with a brief that includes:

1. **Serve the HTML over HTTP** — `file://` protocol is blocked by Playwright. The specialist should start a local server.
2. **Set the viewport** to match the element's rendered size. Measure the element's bounding box first, then resize the viewport to `Math.ceil(width) + 1` by `Math.ceil(height) + 1` to eliminate scrollbars.
3. **Hide UI chrome** (download buttons, navigation overlays) and set `document.body.style.overflow = 'hidden'` to suppress body-level scrollbars.
4. **Screenshot the specific element** (e.g. `.cover`, `.backpage`) using element-level screenshot — not a full-page or viewport screenshot.
5. **Save the PNG** alongside the HTML, named for the section it replaces (e.g. `cover-print.png`, `backpage-print.png`).
6. **Restore** hidden elements and overflow after capture.
7. **Verify** the saved PNG visually — confirm no scrollbars, no UI chrome, correct dimensions.

After capturing all print images, delegate a second task to save the final PDF via `browser_pdf_save`.

## Page margins, page numbers, and running footers

Use `@page` margin boxes for page numbers and running footers — not `position: fixed` elements.

```css
@page {
  margin: 0.6in 0.7in 0.8in;
  @bottom-center {
    content: counter(page);
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 9pt;
    color: #8A8A84;
  }
}

/* Cover page: zero margins, no page number */
@page :first {
  margin: 0;
  @bottom-center { content: none; }
}

/* Named page for full-bleed back page */
@page backpage-full {
  margin: 0;
  @bottom-center { content: none; }
}
```

Then in `@media print`, the cover needs NO `page:` property — `@page :first` handles it. Only the backpage needs the named page assignment:

```css
@media print {
  .cover {
    width: auto; margin: 0; box-shadow: none; /* reset screen-only properties */
    min-height: 0;
    height: 100vh;
    page-break-after: always;
    position: relative;
    overflow: hidden;
  }
  .backpage {
    width: auto; margin: 0; box-shadow: none; /* reset screen-only properties */
    min-height: 0;
    height: 100vh;
    page-break-before: always;
    position: relative;
    overflow: hidden;
    page: backpage-full;
  }
}
```

**Key details:**
- `@page :first` zeros the margins for the cover — no named page needed on the cover element.
- Named pages are only needed for non-first full-bleed pages (backpage).
- `counter(page)` gives automatic page numbering with no JavaScript.
- No `position: fixed` hacks are needed for repeating headers/footers.
- If the screen CSS uses `width: 210mm; margin: 20px auto; box-shadow: ...` on the cover/backpage (for the card-on-grey-background look), the print CSS MUST explicitly reset these: `width: auto; margin: 0; box-shadow: none;`. Screen-only layout properties leak into print if not reset. Do NOT use `width: 100vw` or `margin: 0 !important` — just `width: auto; margin: 0`.
- The print image uses `position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;`.

## A4 layout — continuous flow, not fixed-height boxes

Forcing each section into a fixed `height: 297mm` div creates large whitespace gaps when content doesn't fill a full page.

**Correct approach:**

- **Cover page:** `min-height: 100vh` on screen; `height: 100vh; page-break-after: always;` in print.
- **Content:** Flows naturally. The `@page` margins handle spacing. No fixed-height containers.
- Use `page-break-inside: avoid` on logical units (cards, tables, callouts, stat groups, timeline items, competitor cards, pullquotes).
- Use `page-break-before: always` on major section dividers (part breaks).
- Use `page-break-after: avoid` on headings and section numbers so they don't strand at the bottom of a page.
- Set `orphans: 3; widows: 3;` on paragraphs to prevent single-line stragglers.

## Dark backgrounds are stripped in print

Browsers strip background colours by default when printing.

**Required:** Add both properties to every dark element in `@media print`:

```css
@media print {
  .dark-element {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
```

## Stripping glassmorphism from content areas

In multi-page documents, strip `backdrop-filter` from content sections (where it won't render correctly anyway) while preserving it on cover/backpage elements that are replaced with print images:

```css
@media print {
  /* Strip glass from content */
  .content *, .content *::before, .content *::after {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
}
```

## Document structure pattern

Multi-page documents follow this structure:

1. **Cover** — full-bleed, glassmorphism, with print image fallback. Uses `@page :first { margin: 0; }` — NO named page on the element. `page-break-after: always`.
2. **Table of contents** (optional) — `page-break-after: always` to start content on a fresh page.
3. **Content sections** — flowing, with part dividers using `page-break-before: always`.
4. **Back page** — full-bleed CTA/contact page. **Not** an inline footer div — a separate top-level element outside `.body-wrap` with its own named page, print image fallback, and `page-break-before: always`.

**The back page is mandatory for multi-page documents.** An inline CTA footer (a `div` inside flowing content) ends up floating mid-page with whitespace below it. The back page pattern guarantees a clean final page.

```css
@page backpage-full {
  margin: 0;
  @bottom-center { content: none; }
}

@media print {
  .backpage {
    page: backpage-full;
    min-height: 0; height: 100vh;
    page-break-before: always;
    position: relative; overflow: hidden;
  }
  .backpage > *:not(.backpage-print-img) { display: none !important; }
  .backpage-print-img {
    display: block !important;
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
  }
}
```

```html
<!-- Outside .body-wrap, after it closes -->
<div class="backpage">
  <img class="backpage-print-img" src="backpage-print.png" alt="" style="display:none;">
  <!-- live backpage content (bg, text, contact info) -->
</div>
```

The backpage print image is captured via the same browser-specialist delegation process as the cover — element-level screenshot with UI chrome hidden.

## Single-page documents

For single A4 documents (one-pagers), use fixed dimensions:

```css
.page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  overflow: hidden;
}

@page { size: A4; margin: 0; }

@media print {
  .page {
    width: 210mm;
    height: 297mm;
    page-break-after: always;
  }
}
```

## Document background for multi-page screen viewing

Multi-page documents use a neutral body background (e.g. `body { background: var(--background); }`) on screen. In `@media print`, reset to `body { background: white; }`.
