/* ============================================================================
   print.css — paginated A4 output for the FULL interactive Quote.

   This replaces the old export path, which was not a PDF renderer at all: it
   ran html2canvas over the DOM and pasted the resulting JPEG onto a single
   jsPDF page of arbitrary height (services/PDFService.ts downloadContinuousPDF).
   Everything here exists so Chromium's OWN print engine can do the job —
   vector text, real pages, native object-fit/filter/transform.

   Pairs with, on the API side:
     printToPDF({ preferCSSPageSize: true, printBackground: true,
                  margins: {top:0,bottom:0,left:0,right:0},
                  displayHeaderFooter: false })
   `preferCSSPageSize` hands page geometry to the @page rules below;
   `printBackground` is what actually paints the covers (it defaults to FALSE,
   and without it every image-backed panel prints white).

   SCOPING — read before adding a rule.
   Structural rules are scoped to `html.vs-print`, which ONLY the #/export route
   sets. Two reasons, both load-bearing:
     1. The interactive site and the admin panel must not change.
     2. Inside the Visualizer the vendor script injects visuallizer-skin.css as
        the LAST stylesheet in <head> (scripts/vendor-quotes.py), and that skin
        carries `html, body { background-color:#0a0a0b !important }`. A plain
        `html, body` rule here has identical specificity and would LOSE on
        source order — printing every page near-black. `html.vs-print` is
        (0,1,1) and wins regardless of who loaded last. Never weaken it.
   Because the rules are live on screen too, /#/export doubles as a WYSIWYG
   preview you can eyeball without printing anything.
   ========================================================================= */

/* Sentinel. printReady() asserts this resolves — if this file 404s after a
   vendor run or a path change, preferCSSPageSize finds no @page and Chromium
   silently falls back to US Letter portrait with ~0.4in margins, which looks
   plausible and is wrong in every dimension. Fail loudly instead. */
:root { --vs-print-css: 1; }

/* ---------------------------------------------------------------------------
   1. PAGE GEOMETRY — A4 LANDSCAPE by default

   Landscape is the house format: it matches the on-screen quotation the client
   already approved, so the printed and interactive versions read the same
   document. Portrait re-flows the pricing columns and stops matching.

   These are DEFAULTS ONLY. The real geometry is emitted at runtime by
   utils/printLayout.ts and appended after this file, because `@page` cannot
   read an attribute or a custom property and the user picks orientation, page
   mode and zoom in the print dialog. Later @page declarations win, so what is
   here is the fallback if that injection ever fails to run.

   Landscape A4 at these margins is a 277 x 182mm content box, ~1047 CSS px —
   above Tailwind's lg: breakpoint, so the quote lays out in the desktop form
   it was designed in.

   One trap worth recording: do NOT reach for printToPDF's `scale` to fit a
   wider layout onto a smaller sheet. `scale` divides the whole layout viewport,
   so physical units stop meaning what they say and a `width: 297mm` full-bleed
   cover ends up covering two thirds of the page. The zoom control in the print
   dialog uses CSS `zoom` on the content root instead, which leaves @page alone.
------------------------------------------------------------------------- */
@page {
  size: A4 landscape;
  margin: 12mm 10mm 16mm;
  /* Chromium implements page-margin boxes and the page/pages counters. It does
     NOT implement `string-set`, so a running header carrying the project name
     is not possible here — that is why there is no @bottom-left. */
  @bottom-right {
    content: counter(page) " / " counter(pages);
    font: 500 8pt/1 "Inter", system-ui, sans-serif;
    color: #64748b;
  }
}

/* The cover gets its own zero-margin page so it can bleed to the edges.
   margin:0 removes the margin boxes with it — intended, no page number there. */
@page cover { size: A4 landscape; margin: 0; }

/* Wide documents (timeline, process flow, call sheet) buy back side margin. */
@page wide { size: A4 landscape; margin: 12mm 6mm 16mm; }

/* ---------------------------------------------------------------------------
   2. COLOUR FIDELITY
   Both halves are required: this, AND printBackground:true on the API side.
   Without print-color-adjust:exact Chromium strips background paint to save
   ink and every dark panel prints white with white text on it.
------------------------------------------------------------------------- */
@media print {
  html.vs-print,
  html.vs-print body,
  html.vs-print #root,
  html.vs-print #quote-content-capture,
  html.vs-print #quote-content-capture * {
    -webkit-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
  }
  /* THEMED, since the export stopped forcing the light look. ExportLayout
     stamps data-print-theme from the proposal once it loads; the white default
     is the fallback for a document that never says otherwise. The attribute
     selector is (0,2,1) against the plain (0,1,1), so the dark rule wins on
     specificity, not on source order — deliberate, because the vendored skin
     stylesheet loads after this file. */
  html.vs-print,
  html.vs-print body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  html.vs-print[data-print-theme="dark"],
  html.vs-print[data-print-theme="dark"] body {
    /* The online quote's canvas (QuoteView's root bg-[#0f172a]). Painted here
       too so the page area outside the content box cannot flash white. */
    background: #0f172a !important;
  }
  /* The on-screen "Save as PDF" bar the export route renders for the web path. */
  html.vs-print .vs-print-toolbar { display: none !important; }
}

/* ===========================================================================
   3. STRUCTURAL — html.vs-print (active on screen too, deliberately)
   ======================================================================== */

/* 3a. Kill the SCROLL containers — and only those.
   A scroll container is monolithic to the fragmentation engine: it never
   splits across pages, so it overflows page one and everything past the fold
   is clipped away. The section pricing tables are `overflow-x-auto`.

   Deliberately targeted by class rather than with a blanket
   `#quote-content-capture * { overflow: visible }`. `overflow: hidden` is what
   gives every card and cover its rounded clip, and stripping that lets images
   bleed out of their boxes and slide under the adjacent text — while the child
   still carries its transform: scale(). Scroll containers are the problem;
   clips are not. */
html.vs-print,
html.vs-print body,
html.vs-print #root,
html.vs-print #quote-content-capture {
  overflow: visible !important;
  max-height: none !important;
  height: auto !important;
}
html.vs-print .overflow-auto,
html.vs-print .overflow-scroll,
html.vs-print .overflow-x-auto,
html.vs-print .overflow-y-auto,
html.vs-print .overflow-x-scroll,
html.vs-print .overflow-y-scroll,
html.vs-print [class*="overflow-x-auto"],
html.vs-print [class*="overflow-y-auto"] {
  overflow: visible !important;
  overflow-x: visible !important;
  overflow-y: visible !important;
  max-height: none !important;
}

/* 3a-bis. Kill backdrop-filter. THIS ONE IS LOAD-BEARING.

   Chromium's PDF backend does not composite backdrop-filter, and the result is
   not a degraded blur — the element and its contents DO NOT PAINT AT ALL. They
   lay out normally (opacity 1, visibility visible, correct box) and then leave
   a blank hole in the PDF, which makes it look like the content was never
   rendered.

   The design uses `backdrop-blur-*` about forty times, and crucially on the
   wrapper around every section's pricing table and on the hero's project
   metadata cards. That single missing property was why whole sections printed
   as empty pages.

   Removing the filter leaves the panel's own translucent background, which is
   what carried the look anyway. */
html.vs-print [class*="backdrop-blur"],
html.vs-print [class*="backdrop-filter"],
html.vs-print [style*="backdrop-filter"] {
  -webkit-backdrop-filter: none !important;
          backdrop-filter: none !important;
}

/* 3a-ter. Kill CSS filters. This is the file-size fix.

   A `filter` forces Chromium to rasterise that whole subtree instead of drawing
   it, and it rasterises at 3x the layout width, LOSSLESSLY. The section covers
   carry `brightness-75`, so each one was embedded as a ~2103px-wide Flate
   bitmap of half a megabyte to a megabyte — eight of them accounted for 4.7MB
   of a 6.7MB file, while the actual resampled source images were ~80KB each.

   Dropping the filter both restores vector drawing and lets the resampled
   bitmap be used. The covers print at full brightness, which is what you want
   on paper anyway — the dimming exists so on-screen text can sit over them. */
html.vs-print [class*="brightness-"],
html.vs-print [class*="contrast-"],
html.vs-print [class*="saturate-"],
html.vs-print [class*="grayscale"],
html.vs-print [class*="drop-shadow"],
html.vs-print #quote-content-capture img,
html.vs-print #quote-content-capture video {
  filter: none !important;
}

/* The covers were not dimmed for fun: brightness-75 is what keeps the section
   title legible over a bright photo, and killing the filter alone printed
   every cover a quarter brighter than the design. A static scrim reproduces
   the dimming without the filter — it is a plain composited fill, so the
   subtree keeps vector drawing and the resampled bitmap keeps being used.
   [data-vs="cover"] is relative + overflow-hidden, so the overlay clips to
   the card's own rounded corners. brightness(0.75) multiplies the image
   toward black; rgba(0,0,0,0.25) over it is the same arithmetic. */
html.vs-print [data-vs="cover"]::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* 3a-quater. Gradient-clipped text becomes solid brand text.

   Every big heading uses `bg-gradient-to-r … bg-clip-text text-transparent`.
   In print that mask is a trap twice over:

     - A COLOUR EMOJI in the heading cannot mask the background, so it prints
       as a solid brand-coloured silhouette — "Phase Four | Revisions 🔁" came
       out with a teal block where the emoji sits. On screen the emoji renders
       in full colour on top of the gradient; on paper it turned into a blob.
     - The mask is a texture Chromium allocates at print time. On a huge
       element (a multi-line hero title at text-7xl) under memory pressure the
       allocation can fail silently: glyphs vanish and the UNMASKED gradient
       paints as a solid rectangle. Load-dependent, so it strikes exactly when
       the app has been running all day.

   Solid brand-colour text has neither failure mode, emoji render in full
   colour again (text-fill-color does not apply to colour glyphs, same as the
   web), and the look stays the design's — most proposals run brand and
   secondary close enough that the gradient read as one colour anyway. */
html.vs-print .bg-clip-text {
  background-image: none !important;
  -webkit-background-clip: border-box !important;
          background-clip: border-box !important;
  color: rgb(var(--brand-rgb, 59 130 246)) !important;
  -webkit-text-fill-color: rgb(var(--brand-rgb, 59 130 246)) !important;
}

/* 3a-quinquies. No box-shadows on paper, anywhere.

   Chromium's print backend rasterises large blurred shadows badly: shadow-xl
   under the package cards and the selector bar came out as flat grey slabs
   and a dark strip between the cards — the single biggest "why is there grey
   everywhere" in client renders. The design's structure survives on real
   borders; the depth cue does not translate to paper and is not worth grey
   smears. (Tailwind ring-* is also box-shadow and goes with it — the one
   ring that carries business meaning, the approved option, is a real border
   and keeps printing.) */
html.vs-print #quote-content-capture *,
html.vs-print #quote-content-capture *::before,
html.vs-print #quote-content-capture *::after {
  box-shadow: none !important;
  text-shadow: none !important;
}

/* Shadowless, the translucent selector-bar band reads as a stray grey strip
   behind the cards. Let the page background through instead — the cards
   themselves carry the design. */
html.vs-print [class*="overflow-x-auto"][class*="border-b"] {
  background: transparent !important;
  border-bottom-color: transparent !important;
}

/* 3b. Fixed and sticky positioning — two problems, two different answers.

   `position: sticky` is on content that belongs in the document: the package
   selector bar. It only needs to stop being sticky, because Chromium would
   otherwise repeat or strand it. Static, and it prints where it sits.

   `position: fixed` is never content here. Every fixed box in the quote is
   screen chrome — the edit-mode banner, the download badge, the IIVPA badge,
   the click-catcher behind an open dropdown, the "Quote Accepted!" toast.
   Chromium repeats a fixed box on EVERY page and clips it from page two on, so
   it cannot stay fixed. But the answer used to be `position: static`, which
   dropped all of that into the document flow at whatever DOM position it
   happened to occupy — and the toast sits near the end of the tree. That is
   how a notification nobody had triggered became the last block of every PDF.
   Hide it instead of relocating it.

   The logo is the one fixed element that IS content; print.css positions it
   against the cover itself just below. Under printPaged QuoteView already
   renders it absolute, so the guard only matters if that flag is ever off. */
html.vs-print .sticky,
html.vs-print [class*="sticky"] { position: static !important; }
html.vs-print .fixed:not([data-vs="logo"]) { display: none !important; }
html.vs-print [data-vs="logo"] { position: absolute !important; }

/* 3c. Remove interactive chrome that has no meaning on paper. */
html.vs-print [data-flag-affordance],
html.vs-print .flag-jump-flash,
html.vs-print [data-vs="section-menu"],
html.vs-print [data-vs="download-badge"],
html.vs-print a[href^="https://iivpa.com"] { display: none !important; }

/* Template variables are highlighted orange for the admin; on paper they are
   just text. */
html.vs-print .vs-template-var {
  background: transparent !important;
  color: inherit !important;
  box-shadow: none !important;
  padding: 0 !important;
}

/* 3d. Freeze animation. Chromium prints whatever frame it happens to be on, so
   a 700ms fade still in flight is captured half-transparent. printReady() adds
   .vs-print-freeze once everything has settled.

   IT RESETS ANIMATION AND TRANSITION ONLY. Do not add opacity or transform
   back — this rule used to also carry `opacity: 1 !important` and
   `transform: none !important` on every element and every pseudo-element, which
   reads like belt-and-braces and was the single largest source of "why is that
   in the PDF":

     - `opacity: 1` unhid everything whose RESTING state is hidden. The
       "Quote Accepted!" toast is `opacity-0 translate-x-full` until a client
       accepts, so it printed as a brand-coloured block at the end of every
       quote. Around 25 `opacity-0 group-hover:opacity-100` affordances and the
       add-on button's hover sheen printed with it.
     - `transform: none` deleted the `-translate-x-1/2` / `-translate-y-1/2`
       centring idiom this codebase uses everywhere — the timeline's week and
       month axis labels, the shooting-dates rail, its highlight and its dots,
       and the rotated vertical month label.

   Neither was ever needed: once `transition: none` and `animation: none` apply,
   the computed value jumps straight to the declared one with no interpolation,
   so a fade caught in flight settles on its own end state.

   Dropping them also retires the exemption list that used to sit here. It
   restored the covers with `transform: revert`, and `revert` rolls an author
   declaration back past the WHOLE author origin — including the style
   attribute, which is exactly where the admin's cover reframe lives
   (QuoteView renders `style={{ objectPosition, transform: scale(...) }}`). So
   every cover, collage tile and reference cover printed at zoom 1 with the
   right crop centre and the wrong crop scale. Leaving transforms alone fixes
   the covers and the centring in one move. */
html.vs-print.vs-print-freeze *,
html.vs-print.vs-print-freeze *::before,
html.vs-print.vs-print-freeze *::after {
  animation: none !important;
  transition: none !important;
  animation-play-state: paused !important;
}

/* ===========================================================================
   4. THE OPENING HEADER — a panel on page one, or a cover sheet of its own
   Two shapes, chosen per document by utils/printFit.ts chooseCover and stamped
   on <html> as data-print-cover:

   PANEL (the default, and the only shape Safari can print): the header sits
   inside the page margins as a rounded card sized to its content, and the next
   block starts under it on the same sheet. The header used to be forced onto a
   sheet of its own whatever its height, which left most of page one blank; and
   because Safari has no named pages and ignores @page size, its fixed 297mm
   width also shrank the WHOLE document to fit a portrait sheet.

   COVER (data-print-cover="page", engines with named pages): the header fills
   one zero-margin sheet, full bleed — chosen only when nothing else would fit
   beside it anyway, so the sheet reads as a title page and not an empty one.
   You cannot paint the @page box itself, so the cover is an ELEMENT sized to
   exactly one page (mm, never vh: 100vh is the viewport, not the page).
   ======================================================================== */
html.vs-print [data-vs="hero"] {
  position: relative !important;
  width: auto !important;
  height: auto !important;
  min-height: 0 !important;      /* defeats min-h-[60vh] */
  margin: 0 0 8mm !important;
  /* Top padding clears the logo pinned inside it (below). */
  padding: 21mm 9mm 9mm !important;
  display: flex !important;
  align-items: center !important;
  border-radius: 14px;
  /* clip, not hidden: rounds the background into a card without making the
     box a scroll container. */
  overflow: clip !important;
  break-inside: avoid;
  page-break-inside: avoid;
}
@supports (page: cover) {
  html.vs-print[data-print-cover="page"] [data-vs="hero"] {
    page: cover;
    break-after: page;
    page-break-after: always;
    /* width and min-height are emitted at runtime per orientation
       (utils/printLayout.ts); these are the landscape fallback. */
    width: 297mm !important;
    /* min-height, NOT height: a real proposal's header can run taller than
       the sheet, and pinned with align-items:center Chromium clipped the
       overflow off BOTH ends, project title first. ExportLayout scales an
       oversized cover to the sheet instead (buildHeroFitCss). */
    min-height: 210mm !important;
    margin: 0 !important;
    /* Clears the logo pinned 12mm down (about 8mm tall); the sides and foot
       are a printed page's, not the screen's pt-32/pb-20 — every mm here is
       a mm the brief can use before the cover has to shrink. */
    padding: 30mm 18mm 16mm !important;
    border-radius: 0;
    /* Never `hidden`: an overflow-hidden box is monolithic and would clip at
       the page boundary instead of flowing onto the next one. */
    overflow: visible !important;
  }
}
/* The cover on paper (owner's request, 2026-11-05): the words first, across
   the whole sheet — title, brief, the project's facts, deliverables — and the
   option cards in a row UNDER them (QuoteView coverOptions), the approved one
   first, the others faded. The cards used to take the right-hand third: the
   brief got what was left, ran three times as tall, and the whole cover was
   then scaled down to fit one sheet, to 40% on a real quote — type nobody
   could read. When the brief is long enough that the cards would still force
   a shrink, ExportLayout moves them, with the deliverables, to the top of the
   next sheet instead (data-print-options="after", utils/printFit.ts
   placeCoverOptions): the cover keeps the brief at full size.
   The separate option bar is not printed on this route. */
html.vs-print [data-vs="hero"] .vs-cover-split {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 7mm !important;
}
html.vs-print [data-vs="hero"] .vs-cover-split > .max-w-3xl {
  width: 100% !important;
  max-width: none !important;
}
html.vs-print [data-vs="cover-options"] {
  display: grid !important;
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 4mm !important;
  align-items: stretch !important;
  break-inside: avoid;
  page-break-inside: avoid;
}
html.vs-print [data-vs="cover-options"][data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
/* One option: a card as wide as two of three, not a banner across the sheet. */
html.vs-print [data-vs="cover-options"][data-count="1"] { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) !important; }
html.vs-print [data-vs="cover-option"] { break-inside: avoid; page-break-inside: avoid; }
/* The cards' total must never be clipped, whatever the column width. */
html.vs-print [data-vs="cover-option"] [data-vs="pkgprice"] { font-size: 15px !important; }
html.vs-print [data-vs="cover-option"] [data-vs="pkgledger"] span { font-size: 12px !important; }

/* Moved off the cover: the deliverables and the same cards, at the top of the
   next sheet — what each option gives, then what it costs. */
html.vs-print [data-vs="cover-options-after"] { display: none !important; }
html.vs-print[data-print-options="after"] [data-vs="cover-options-after"] {
  display: block !important;
  margin: 0 0 8mm !important;
  break-inside: avoid;
  page-break-inside: avoid;
}
html.vs-print[data-print-options="after"] [data-vs="hero"] [data-vs="cover-options"],
html.vs-print[data-print-options="after"] [data-vs="hero"] [data-vs="hero-deliverables"] { display: none !important; }

/* Paper type for the cover. The screen sizes (a 72px title, 20px brief) are
   made for a 1600px window; on an A4 sheet they ran the cover three sheets
   tall. These read like a printed brochure and leave room for the words. */
html.vs-print [data-vs="hero"] [data-vs="hero-title"] {
  font-size: 40px !important;
  line-height: 1.1 !important;
  letter-spacing: -0.01em !important;
  margin-bottom: 6mm !important;
}
html.vs-print [data-vs="hero"] [data-vs="hero-desc"] {
  font-size: 15.5px !important;
  line-height: 1.6 !important;
  padding-left: 5mm !important;
  margin-bottom: 7mm !important;
}
html.vs-print [data-vs="hero"] [data-vs="hero-facts"] {
  gap: 3.5mm !important;
  margin-bottom: 0 !important;
  font-size: 13.5px !important;
  line-height: 1.5 !important;
}
html.vs-print [data-vs="hero"] [data-vs="hero-facts"] > * { padding: 3.2mm 4mm !important; }
html.vs-print [data-vs="hero"] [data-vs="hero-facts"] > * > span:first-child { font-size: 10.5px !important; margin-bottom: 1mm !important; }
html.vs-print [data-vs="hero"] [data-vs="hero-facts"] .text-sm { font-size: 13px !important; line-height: 1.5 !important; }
html.vs-print [data-vs="hero"] [data-vs="hero-contact-lines"] { font-size: 12.5px !important; }
/* A landscape sheet is wide: three facts to a row, deliverables across. */
html.vs-print[data-print-orient="landscape"] [data-vs="hero"] [data-vs="hero-facts"] { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
html.vs-print [data-vs="hero"] [data-vs="hero-facts"] > .md\:col-span-2 { grid-column: 1 / -1 !important; }
html.vs-print[data-print-orient="landscape"] [data-vs="hero"] [data-vs="hero-title"] { font-size: 44px !important; }

html.vs-print [data-vs="hero"] > .absolute.inset-0 {
  position: absolute !important;
  inset: 0 !important;
}
html.vs-print [data-vs="hero"] img[alt="Cinematic Background"] {
  position: absolute !important;
  inset: 0 !important;
  width: 100% !important;
  height: 100% !important;
  object-fit: cover !important;      /* native in the print engine — free */
  max-height: none !important;
}
html.vs-print [data-vs="logo"] {
  top: 7mm !important;
  left: 50% !important;
  width: 150px !important;
  filter: none !important;
  z-index: 20 !important;
}
html.vs-print[data-print-cover="page"] [data-vs="logo"] { top: 12mm !important; width: 220px !important; }

/* ===========================================================================
   5. PAGINATION

   Quote sections FLOW. They do NOT each start a new page.

   Forcing `break-before: page` on every section looked tidy in principle and
   was wrong in practice: on a real proposal the eight sections measure
   510–1369px against a ~1017px portrait content box, so one-section-per-page
   left a third to a half of nearly every sheet blank and the whole document
   read as white space. Flowing them fills pages properly — the atomic-block
   rules in section 6 are what stop a section splitting somewhere ugly.

   Only the standalone appendices below get a forced break, because those
   genuinely are separate documents.

   Note the direction: only break-BEFORE. `break-after: page` on a last in-flow
   child propagates to its container and yields a trailing blank page.
   ======================================================================== */

/* Trim the generous on-screen rhythm — mb-32 between sections is a third of a
   page of nothing on paper. */
html.vs-print #quote-content-capture main > section { margin-top: 0 !important; margin-bottom: 8mm !important; }

/* …and the same for the blocks that follow it. `main` ends with pb-32 and each
   standalone block carries mb-32: 34mm of nothing before Curated References
   and 34mm more after it. That gap alone was enough to push a references
   block that WOULD have fitted onto a sheet of its own — the section rule
   above trimmed the sections and stopped at the closing tag. */
html.vs-print #quote-content-capture main { padding-bottom: 0 !important; }
html.vs-print #section-shooting-dates,
html.vs-print #section-timeline,
html.vs-print #section-process-flow,
html.vs-print #section-checklist,
html.vs-print #section-callsheet,
html.vs-print #section-portfolio { margin-bottom: 10mm !important; }

/* Curated References is NOT in this group any more. It is part of the
   quotation's story, not an appendix, and the unconditional break here was
   what stranded it alone on a final sheet while the page before it sat half
   empty. It now flows like a section, and earns a page the same way a section
   does — from the print dialog's break list, or from the Auto plan that
   measures what actually fits. */
html.vs-print #section-timeline,
html.vs-print #section-process-flow,
html.vs-print #section-checklist,
html.vs-print #section-callsheet {
  break-before: page;
  page-break-before: always;
}
html.vs-print #section-timeline,
html.vs-print #section-process-flow,
html.vs-print #section-callsheet { page: wide; }

/* The call sheet's "Page per day" (dailyCallSheetData.layout.dayMode 'page').
   On a screen the client's copy is the same card per day either way — a screen
   has no pages — so the option only means something here: every day card after
   the first starts a sheet of its own. Day one stays under the sheet's own
   header, which is what makes page one a complete call sheet too.

   Gated on the visualizer's root attribute, so 'group' and 'column' sheets
   keep flowing. Deliberately NOT !important: continuous mode strips every
   break with an !important rule of its own (utils/printLayout.ts) and has to
   keep winning, or the "one long page" sprouts a sheet per day.

   These are breaks INSIDE a block, which the page planner cannot see from the
   block's height alone — utils/printPlan.ts measures them through this same
   selector (INNER_BREAK_SELECTORS). Keep the two in step. */
html.vs-print [data-cs-daymode="page"] [data-vs="cs-day"] ~ [data-vs="cs-day"] {
  break-before: page;
  page-break-before: always;
}

/* The call sheet's day BAND (and the day badge of its 'column' mode) is white
   type on a dark fill. A printer that drops background paint would leave white
   on white — the day's name gone from the very sheet it structures. §2 already
   pins this inside the export route; this rule is deliberately NOT gated on
   html.vs-print, because a client can print the live link from the browser's
   own menu too. The
   property inherits, so the brand-colour bar inside the band rides along. */
@media print {
  [data-cs-day-band],
  [data-cs-daybadge] {
    -webkit-print-color-adjust: exact;
            print-color-adjust: exact;
  }
}

/* A band OPENS what follows it. Stranded at the foot of a sheet with its rows
   overleaf it would read as closing the day before — so the band holds on to
   its meta strip, and the strip to the first row under it. */
html.vs-print [data-cs-day-band],
html.vs-print [data-cs-day-meta] {
  break-inside: avoid;
  break-after: avoid;
  page-break-inside: avoid;
  page-break-after: avoid;
}

/* The magic min-heights in QuoteView are fossils of the raster era — they were
   eyeballed against a 1600px-wide screenshot and match neither A4 orientation.
   @page owns pagination now; left in place they force blank space. */
html.vs-print .min-h-\[1414px\],
html.vs-print .min-h-\[2262px\] { min-height: 0 !important; }

/* Reference titles sit in a third of the card and are set in a display size
   tuned for a wide screen; on a portrait sheet a long one runs into the edge. */
html.vs-print [data-vs="pf-item"] h3 {
  font-size: 20px !important;
  line-height: 1.15 !important;
  /* Whole words: the paper card's text column is wide enough for any real
     title, and an upper-case name hyphenated mid-word ("TRADEBE-YOND") reads
     as a typo. Only a single word wider than the column may still break. */
  overflow-wrap: break-word;
  hyphens: manual;
}

/* Prices must never be clipped — a truncated "HKD 180,0" is worse than no
   quote at all. The option cards are narrower on a portrait sheet than on the
   screen they were sized for, so the monospace price has to give. */
html.vs-print [data-vs="pkgprice"] {
  font-size: 15px !important;
  line-height: 1.2 !important;
  letter-spacing: -0.02em !important;
  white-space: nowrap !important;
  overflow: visible !important;
}

/* The showreel tile beside the option cards is sized for a screen: a fixed
   170px height at 16:9 is 302px wide, more than its four-of-ten columns on a
   portrait sheet (~265px), so it ran under the Approved card of Appendix A.
   On paper it fills its own column instead; the still keeps its object-cover
   crop. */
html.vs-print[data-print-orient="portrait"] [data-vs="pkgbar"] [data-block-id="showreel"] {
  width: 100% !important;
  aspect-ratio: auto !important;
}

/* ===========================================================================
   6. ATOMIC BLOCKS — never split these across a page boundary
   ======================================================================== */
html.vs-print [data-vs="cover"],
html.vs-print [data-vs="pkgcard"],
html.vs-print [data-vs="row"],
html.vs-print [data-vs="cs-row"],
html.vs-print [data-vs="pf-item"],
html.vs-print [data-vs="ref-cover"],
html.vs-print figure,
html.vs-print blockquote,
html.vs-print tr {
  break-inside: avoid;
  page-break-inside: avoid;
}
/* A column-header block must never be the last thing on a page. */
html.vs-print [data-vs="thead"] {
  break-inside: avoid;
  break-after: avoid;
  page-break-after: avoid;
}
html.vs-print h1,
html.vs-print h2,
html.vs-print h3 {
  break-after: avoid;
  page-break-after: avoid;
}
html.vs-print p,
html.vs-print li { orphans: 3; widows: 3; }

/* ===========================================================================
   6b. WHOLE BLOCKS — a section, the package row, a reference card: one sheet each
   The rule for paper: never split a phase section, a package or a reference
   card over two pages. break-inside: avoid holds a block that FITS on a sheet;
   utils/printFit.ts shrinks the few that do not, so it holds for every block,
   and a sheet ends where the next whole block no longer fits.

   Safari honours the hint only for a box in BLOCK flow — in a flex or grid
   parent its pagination ignores it, which is how a reference card came out cut
   in half in a client's Safari PDF. So the parents below print as plain block
   flow, and the spacing the flex `gap` gave becomes margins.
   ======================================================================== */
html.vs-print #quote-content-capture main > section,
html.vs-print [data-vs="pkgbar"],
html.vs-print [data-vs="pf-item"] {
  break-inside: avoid;
  page-break-inside: avoid;
}
/* A section now usually STARTS a sheet, and Chromium paints each sheet as a
   stripe of one long document: ink above the first line's box — the tall "|"
   in "Phase Four | Revisions" — fell into the stripe of the sheet before and
   printed as a purple tick in its bottom margin. Padding (not margin, which a
   page break truncates) keeps that ink on its own sheet. */
html.vs-print #quote-content-capture main > section,
html.vs-print #section-portfolio { padding-top: 2.5mm !important; }

/* Safari lays a portrait sheet out ~675px wide whatever the window is
   (utils/printFit.ts printsOnOwnPaper), so the on-screen measuring width is
   that sheet's, not the @page the runtime stylesheet pins. */
@media screen {
  html.vs-print[data-print-engine="webkit"] #quote-content-capture { width: 178mm !important; }
}

/* Paper density. The screen rhythm put a phase section at 145-310mm against a
   182mm landscape sheet, so almost none could stay whole at 100%. Two levers
   that cost no legibility: */
/* 1. The section cover prints as a banner rather than at its screen aspect — a
   5:1 cover across a landscape sheet is 55mm, a third of the page. The
   admin's framing (objectPosition and zoom on the element) still applies. The
   compact view's ribbons are banners already. */
html.vs-print { --vs-print-cover-h: 32mm; }
html.vs-print[data-print-orient="portrait"] { --vs-print-cover-h: 26mm; }
html.vs-print #quote-content-capture:not(.cvx-compact) main > section [data-vs="cover"] {
  height: var(--vs-print-cover-h);
  margin-bottom: 4mm !important;
}
html.vs-print #quote-content-capture:not(.cvx-compact) main > section [data-vs="cover"] > div {
  height: 100% !important;
  min-height: 0 !important;
  aspect-ratio: auto !important;
}
html.vs-print #quote-content-capture:not(.cvx-compact) main > section [data-vs="cover-plain"] img {
  height: 100% !important;
  object-fit: cover;
}
/* 2. Rows breathe less: 10px above and below instead of 16. Vertical only — the
   approved column's strip is laid on the rows' horizontal grid. */
html.vs-print [data-vs="row"] {
  padding-top: 10px !important;
  padding-bottom: 10px !important;
}

/* The contract's Approved frame (ExportLayout: approved=1, several options).
   Each row's approved cell reached through the row's padding with negative
   margins (-my-4 py-4) so the green ran unbroken. On screen that nets to zero;
   in Chromium's paged layout the cell grew its row by the full 32px instead,
   so a contract printed every section a third taller than it measured. On
   paper the cell keeps to its row, and the column strip laid behind the
   whole table (data-vs="approved-col") fills the gaps between rows. */
html.vs-print [data-vs="row"] > [class*="-my-4"][class*="self-stretch"] {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/* Curated References on paper: the cover beside the words, sized so two cards
   share a landscape sheet and four a portrait one (the screen card is 96px
   taller than half a landscape sheet). Block layout, for the reason above: the
   text column sits beside the cover and is at least as tall as a 2:1 cover
   (its own aspect ratio), and the cover fills the card's whole height — so a
   card with more words grows without leaving white under its picture. */
html.vs-print #section-portfolio > div:first-child {
  display: block !important;
  margin-bottom: 5mm !important;
  break-inside: avoid;
  break-after: avoid;
  page-break-after: avoid;
}
/* Safari has no break-after: avoid, so the heading reserves a card's height
   below itself: where that does not fit, it moves to the next sheet WITH the
   card instead of closing this one alone. */
html.vs-print #section-portfolio > div:first-child::after {
  content: "";
  display: block;
  height: 50mm;
  margin-bottom: -50mm;
}
html.vs-print #section-portfolio > .flex.flex-col { display: block !important; }
html.vs-print #section-portfolio [data-vs="pf-item"] {
  display: flow-root !important;
  height: auto !important;
  margin-bottom: 6mm;
  border-radius: 12px;
}
html.vs-print:not([data-print-theme="dark"]) #section-portfolio [data-vs="pf-item"] {
  background: #ffffff !important;
  border-color: #e2e8f0 !important;
}
html.vs-print [data-vs="pf-item"] > [data-vs="ref-cover"] {
  position: absolute !important;
  top: 0;
  bottom: 0;
  left: 0;
  width: 56% !important;
  height: auto !important;
}
html.vs-print [data-vs="pf-item"] > [data-vs="ref-cover"] > * { width: 100%; height: 100%; }
html.vs-print [data-vs="pf-item"] > :not([data-vs="ref-cover"]) {
  margin-left: 56%;
  width: auto !important;
  aspect-ratio: 44 / 28;
  padding: 6mm 7mm !important;
  border-top-width: 0 !important;
  border-left-width: 1px !important;
}
html.vs-print [data-vs="pf-item"] .w-12.h-1 { margin-bottom: 4mm !important; }
html.vs-print [data-vs="pf-item"] h3 { margin-bottom: 3mm !important; }
/* "Read more" follows the words instead of floating over the card's corner,
   where a short card's last line ran underneath it. */
html.vs-print [data-vs="pf-item"] .absolute.bottom-8.right-8 {
  position: static !important;
  margin-top: 4mm;
  justify-content: flex-start;
}
/* The project's web address under each reference (QuoteView PortfolioItem): small, blue and underlined so a PDF
   reader sees it is a link. Overrides the `a { color: inherit }` reset at the end of this file. */
html.vs-print [data-vs="ref-url"] {
  color: #2563eb !important;
  text-decoration: underline !important;
  text-decoration-color: rgba(37, 99, 235, 0.45) !important;
  text-underline-offset: 2px;
}
html.vs-print[data-print-theme="dark"] [data-vs="ref-url"] {
  color: #60a5fa !important;
  text-decoration-color: rgba(96, 165, 250, 0.45) !important;
}

/* Real <table>s (the timeline visualizer) get repeating headers for free. The
   quote's own pricing grid is CSS grid, not a table — see the limitation note
   at the end. The call sheet visualizer is not a table either: it is cards of
   div rows, so that a client can read it on a phone — its rows are kept whole
   by [data-vs="cs-row"] above, and a day card that runs onto a second sheet
   does not repeat its heading. */
html.vs-print thead { display: table-header-group; break-inside: avoid; }
html.vs-print tfoot { display: table-footer-group; }

/* ===========================================================================
   7. COVERS AND IMAGES — the two reported symptoms
   object-fit, object-position, transform:scale and filter:brightness are all
   NATIVE here. html2canvas implemented none of them: its whole image path was
   one drawImage() into the box, which non-uniformly squashed every cover and
   discarded the admin's crop. Moving to the print engine fixes that for free —
   so this section is deliberately small.
   ======================================================================== */

/* 7a. The unzoomed cover branch is `w-full h-auto` with no aspect box. If the
   bitmap has not resolved its intrinsic size at layout time the box is 0px
   tall and the cover silently vanishes — which is exactly why SOME covers came
   out and others did not. printReady() awaits decode() so this should never
   fire; the floor is kept as a visible failure indicator, not a fix. */
html.vs-print [data-vs="cover-plain"] { min-height: 24mm !important; }
html.vs-print [data-vs="cover-plain"] img {
  width: 100% !important;
  height: auto !important;
}

/* 7b. Nothing may exceed one page. An oversized image is monolithic: it clips
   rather than splitting. The hero is exempt — it IS a page. */
html.vs-print #quote-content-capture img {
  max-width: 100% !important;
  /* Never taller than the content box, or the figure turns monolithic and
     clips at the page boundary instead of moving to the next page. Overridden
     at runtime per orientation. */
  max-height: 150mm;
}
html.vs-print [data-vs="hero"] img { max-height: none !important; }

/* 7c. Any <video> still in the DOM at print time renders as an empty box.
   printReady() converts cover videos to still frames; anything that survives
   to here failed the grab, so make the hole obvious in review rather than
   letting it pass as white space. */
html.vs-print video {
  background: #0f172a !important;
  min-height: 12mm;
}

/* ===========================================================================
   8. TYPE AND WIDTH
   ======================================================================== */
html.vs-print #quote-content-capture {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 0 !important;
}
/* Background is per theme, like §2. This used to be a bare `#ffffff
   !important` — a (1,1,1) selector that beat QuoteView's own bg-[#0f172a]
   (0,1,0) unconditionally, so passing the real theme through produced dark
   text on a forced white sheet. Never re-merge these into an unscoped rule. */
html.vs-print:not([data-print-theme="dark"]) #quote-content-capture {
  background: #ffffff !important;
}
html.vs-print[data-print-theme="dark"] #quote-content-capture {
  background: #0f172a !important;
}
html.vs-print .max-w-\[1600px\] { max-width: 100% !important; }
html.vs-print .min-w-\[800px\] { min-width: 0 !important; }
html.vs-print a { text-decoration: none; color: inherit; }

/* The export route's own on-screen toolbar (hidden in @media print above). */
.vs-print-toolbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 2147483647;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 16px;
  font: 500 13px/1.4 "Inter", system-ui, sans-serif;
  color: #e2e8f0;
  background: #0f172a;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}
.vs-print-toolbar button {
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  color: #fff;
  background: #f97316;
  cursor: pointer;
}
.vs-print-toolbar[data-state="working"] { background: #78350f; }
.vs-print-toolbar[data-state="error"] { background: #7f1d1d; }

/* ===========================================================================
   KNOWN LIMITATIONS — deliberate, not oversights
   ---------------------------------------------------------------------------
   * The pricing grid's column header (QuoteView.tsx, the `grid grid-cols-10`
     block above the rows) is a sibling <div>, NOT a <thead>, so no engine can
     repeat it. A section whose rows spill past one page loses its column
     headers on the continuation page. `break-after: avoid` above stops it
     orphaning at a page foot, but the real fix is a <table> rewrite.
   * Portrait (selectable in the print dialog) renders below Tailwind's md:
     breakpoint, so reference cards stack their cover above their text instead
     of sitting side by side, and the pricing columns get tight. Landscape is
     the format the design was drawn for and the default for that reason.
   * Firefox and Safari do not implement @page margin boxes, so a client saving
     from those browsers loses the page-number footer. Pagination, breaks,
     covers and vector text all still work.
   ======================================================================== */
