/* =========================================================================
   ZeoTec TDS — A4 print sheet  (v1.8.1)
   -------------------------------------------------------------------------
   Enqueued UNLAYERED, so it beats @layer bricks and the ACSS layers without
   needing !important on most rules. !important appears only where Bricks'
   per-element #brxe-xxxx styles would otherwise win.

   Classes to add in Bricks:
     .tds-sheet  -> outermost wrapper of the whole document
     .tds-grid   -> the 2-column parent
     .tds-main   -> left text column
     .tds-aside  -> right column (product image + spec rows)
     .tds-block  -> each heading + paragraph group
     .tds-row    -> each spec row inside the aside
     .tds-footer -> the patent / ISO note at the very end
     .no-print   -> toolbar, banners, anything not for paper
     .tds-break  -> force a page break BEFORE this element
   ========================================================================= */

:root {
	--tds-page-w: 210mm;
	--tds-page-h: 297mm;
	--tds-page-margin: 12mm;
	--tds-aside-w: 44%;      /* width of the floated right column on paper */
	--tds-aside-gap: 8mm;    /* gutter between aside and wrapping text */
	--tds-aside-h: 150mm;    /* fallback only — JS overwrites with the real height */
	--tds-keep: 4em;         /* how much text must stay with a heading */
	--tds-ink: #1a1a1a;
}

/* -------------------------------------------------------------------------
   1. TOOLBAR (screen only)
   ---------------------------------------------------------------------- */

.tds-toolbar {
	display: flex;
	gap: var(--space-s, 0.75rem);
	flex-wrap: wrap;
	justify-content: flex-end;
	margin-block-end: var(--space-m, 1.5rem);
}

.tds-btn {
	display: inline-flex;
	align-items: center;
	gap: 0.5em;
	padding: 0.6em 1.4em;
	border: 1px solid var(--accent, #1a1a1a);
	border-radius: var(--radius-s, 4px);
	background: var(--accent, #1a1a1a);
	color: #fff;
	font: inherit;
	line-height: 1.2;
	cursor: pointer;
	transition: opacity 0.15s ease;
}

.tds-btn--ghost { background: transparent; color: var(--accent, #1a1a1a); }
.tds-btn:hover { opacity: 0.85; }

/* Busy state, styling-agnostic: works on Bricks/ACSS buttons too, not just
   .tds-btn. The JS sets aria-busy while the print frame loads or the PDF
   renders — without this the button looks dead for a few seconds. */
[data-tds-print][aria-busy="true"],
[data-tds-pdf][aria-busy="true"] {
	opacity: 0.55;
	pointer-events: none;
	cursor: progress;
	position: relative;
}

[data-tds-print][aria-busy="true"]::after,
[data-tds-pdf][aria-busy="true"]::after {
	content: "";
	display: inline-block;
	width: 0.85em;
	height: 0.85em;
	margin-inline-start: 0.6em;
	vertical-align: -0.1em;
	border: 2px solid currentColor;
	border-top-color: transparent;
	border-radius: 50%;
	animation: tds-spin 0.7s linear infinite;
}

@keyframes tds-spin { to { transform: rotate(360deg); } }

/* Visible failure message next to the download button. */
.tds-error {
	flex-basis: 100%;
	margin: 0.5em 0 0;
	font-size: 0.85em;
	line-height: 1.4;
	color: #b3261e;
}

@media (prefers-reduced-motion: reduce) {
	[data-tds-print][aria-busy="true"]::after,
	[data-tds-pdf][aria-busy="true"]::after { animation: none; }
}

/* -------------------------------------------------------------------------
   2. THE A4 SHEET  (print route: ?tds_print=1)
      This is what the iframe renders, what prints, and what html2canvas
      captures. One source of truth for all three.
   ---------------------------------------------------------------------- */

body.tds-print-mode {
	background: #e9e9e9;
	margin: 0;
	padding: 10mm 0;
}

/* Neutralise ACSS/Bricks width constraints.
   CRITICAL: never touch our own layout classes — .tds-sheet sits on a
   section and .tds-main / .tds-aside sit on blocks, so an unqualified
   .brxe-* rule would override them.
   width:auto (not 100%) is deliberate: an auto-width block narrows beside
   a float, a 100% one overlaps it. */
body.tds-print-mode .brxe-section:not(.tds-sheet, .tds-grid, .tds-main, .tds-aside),
body.tds-print-mode .brxe-container:not(.tds-sheet, .tds-grid, .tds-main, .tds-aside),
body.tds-print-mode .brxe-block:not(.tds-sheet, .tds-grid, .tds-main, .tds-aside),
body.tds-print-mode .brxe-div:not(.tds-sheet, .tds-grid, .tds-main, .tds-aside) {
	max-width: none !important;
	width: auto !important;
	min-height: 0 !important;
}

/* Strip horizontal padding on wrapper containers only — not on inner
   content, or the grey heading chips lose their padding. */
body.tds-print-mode .tds-sheet .brxe-container {
	padding-inline: 0 !important;
}

body.tds-print-mode .tds-sheet {
	box-sizing: border-box !important;
	width: var(--tds-page-w) !important;
	max-width: var(--tds-page-w) !important;
	min-height: var(--tds-page-h);
	margin-inline: auto !important;
	padding: var(--tds-page-margin) !important;
	background: #fff;
	box-shadow: 0 0 18px rgb(0 0 0 / 0.18);
	color: var(--tds-ink);

	/* Pin the type scale. ACSS clamps resolve against the page box in print
	   media and come out far too small. Adjust these to fill your 2-3 pages. */
	font-size: 10.5pt;
	line-height: 1.5;

	--text-xs: 8pt;
	--text-s: 9pt;
	--text-m: 10.5pt;
	--text-l: 12pt;
	--text-xl: 15pt;
	--h1: 24pt;
	--h2: 15pt;
	--h3: 12pt;
	--content-width: 100%;
}

body.tds-print-mode .tds-sheet h1 { font-size: 24pt; line-height: 1.15; }
body.tds-print-mode .tds-sheet h2 { font-size: 15pt; line-height: 1.2; }
body.tds-print-mode .tds-sheet h3 { font-size: 12pt; line-height: 1.25; }

body.tds-print-mode .tds-sheet img,
body.tds-print-mode .tds-sheet svg { max-width: 100%; height: auto; }

/* -------------------------------------------------------------------------
   3. PAGE-1 ASIDE — absolute, NOT float.
      Chrome cannot fragment a float across page boundaries reliably: on
      page 2+ it still reserves the float region, which shrinks every
      block-formatting-context sibling (a Bricks block is flex, so every
      .tds-block is a BFC) down to zero width.
      Absolute positioning removes the aside from flow entirely, so it can
      have no effect on pagination at all. Only the first few left-column
      blocks are padded to clear it.
   ---------------------------------------------------------------------- */

body.tds-print-mode .tds-grid {
	display: block !important;     /* stop being a grid/flex container */
	grid-template-columns: none !important;
	gap: 0 !important;
	position: relative !important; /* containing block for the aside */
}

body.tds-print-mode .tds-aside {
	/* Sticky was the original page-1 bug. Absolute replaces it outright. */
	position: absolute !important;
	top: 0 !important;
	right: 0 !important;
	left: auto !important;
	bottom: auto !important;

	width: var(--tds-aside-w) !important;
	max-width: var(--tds-aside-w) !important;
	margin: 0 !important;
	float: none !important;

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

/* MUST be display:block, not flex.
   Chrome cannot fragment a flex container across a page boundary — it
   squeezes the container and overlaps the items. .tds-main is a Bricks
   block (flex column) and spans all pages, so it has to become a plain
   block. Its children stay flex; they carry break-inside:avoid so they
   never straddle a boundary and never trigger the bug. */
body.tds-print-mode .tds-main {
	display: block !important;
	width: auto !important;
	max-width: none !important;
	float: none !important;
}

/* Flex gap dies with display:block, so restore the rhythm as margins. */
body.tds-print-mode .tds-main > * + * {
	margin-top: var(--space-m, 1.25rem);
}
body.tds-print-mode .tds-main > *:first-child {
	margin-top: 0;
}

/* ==== THE CUT-OUT ====
   An empty spacer float reserves the space the aside occupies. Text wraps
   beside it for exactly --tds-aside-h, then reclaims the full sheet width.

   Why a float here when floats broke before: this one is EMPTY, has a
   fixed height, and sits entirely on page 1, so Chrome never has to
   fragment it. And .tds-block is display:block now, so its LINE BOXES wrap
   around the float — the earlier failure was block formatting contexts
   shrinking to zero, which no longer applies.

   Counting children (:nth-child) could not work: padding is per-element and
   has no idea which page the element landed on, so a block that spilled to
   page 2 stayed indented with nothing to clear.

   --tds-aside-h is set at runtime by tds-print.js from the aside's real
   measured height, so it adapts per product. The value below is only the
   fallback if JS has not run. */
body.tds-print-mode .tds-main::before {
	content: "";
	float: right;
	width: calc(var(--tds-aside-w) + var(--tds-aside-gap));
	height: var(--tds-aside-h, 150mm);
	pointer-events: none;
}

/* Keep the aside from overhanging a very short product's left column. */
body.tds-print-mode .tds-grid {
	min-height: 0;
}

/* ==== THE GOLDEN RULE FOR PRINT IN BRICKS ====
   Every Bricks section, container and block is display:flex by default.
   Chrome CANNOT fragment a flex or grid container across a page break —
   it squeezes the box and paints the children on top of each other.
   So: anything that spans more than one page must be display:block.
   Only boxes that fit on a single page AND carry break-inside:avoid are
   allowed to stay flex/grid — here that is .tds-block, .tds-row and the
   absolutely-positioned .tds-aside.

   .tds-sheet is on a SECTION, which is itself a flex column spanning all
   three pages — that is why the footer printed over the page-3 text. */
body.tds-print-mode .tds-sheet,
body.tds-print-mode .tds-sheet .brxe-container,
body.tds-print-mode .tds-sheet .brxe-block:not(.tds-block):not(.tds-row):not(.tds-aside) {
	display: block !important;
}

/* Belt and braces: catch any other sticky/fixed element in the sheet. */
body.tds-print-mode .tds-sheet [style*="position:sticky"],
body.tds-print-mode .tds-sheet [style*="position: sticky"],
body.tds-print-mode .tds-sheet [style*="position:fixed"],
body.tds-print-mode .brxe-popup,
body.tds-print-mode .brx-has-megamenu {
	position: static !important;
}

/* ---- Document footer (patent / ISO note) ----
   Do NOT give this .tds-row — that class is for the spec rows inside the
   aside. Give it .tds-footer instead. It flows naturally to the end of the
   document; this just stops it splitting and keeps it clear of the aside. */
body.tds-print-mode .tds-footer {
	padding-right: 0 !important;
	margin-top: var(--space-l, 2rem);
	break-inside: avoid;
	page-break-inside: avoid;
	clear: both;
}

/* The container's align-items:center stops working once it is display:block,
   so centre the inner text box explicitly. */
body.tds-print-mode .tds-footer > * {
	margin-inline: auto !important;
}

/* Consent banners, skip links, admin bar, opted-out elements. */
body.tds-print-mode .no-print,
body.tds-print-mode #cmplz-cookiebanner-container,
body.tds-print-mode .cmplz-cookiebanner,
body.tds-print-mode .cmplz-manage-consent,
body.tds-print-mode #cookie-law-info-bar,
body.tds-print-mode .skip-link,
body.tds-print-mode #wpadminbar {
	display: none !important;
}

/* -------------------------------------------------------------------------
   4. PAGE-BREAK CONTROL
   ---------------------------------------------------------------------- */

.tds-block,
.tds-row,
h1, h2, h3, h4, h5, h6,
figure,
table,
img {
	break-inside: avoid;
	page-break-inside: avoid;
}

/* Never strand a heading alone at the foot of a page. */
h1, h2, h3, h4, h5, h6 {
	break-after: avoid;
	page-break-after: avoid;
}

/* No single stray line of a paragraph across a page boundary. */
body.tds-print-mode .tds-sheet p,
body.tds-print-mode .tds-sheet li {
	orphans: 3;
	widows: 3;
}

.tds-break {
	break-before: page;
	page-break-before: always;
}

/* ======================================================================
   BLOCK INTEGRITY
   A .tds-block (heading + its paragraph) is never split across pages.
   The cost is that a long block which does not fit in the space left on a
   page jumps wholly to the next one, leaving a gap at the bottom. That is
   the deliberate trade: whole blocks over full pages.

   To go the other way — let long blocks split so pages fill completely —
   change break-inside to auto below and add back a keep-with-next rule on
   the headings. You cannot have both.

   display:block is still required: a flex box cannot fragment, and it also
   keeps behaviour identical between the printer and the PDF exporter.
   ====================================================================== */

body.tds-print-mode .tds-main .tds-block {
	display: block !important;
	break-inside: avoid;
	page-break-inside: avoid;
}

body.tds-print-mode .tds-main .tds-block > :is(h1, h2, h3, h4, h5, h6) {
	width: fit-content;
	break-inside: avoid;
}

/* Flex gap dies with display:block, so restore the heading/text spacing. */
body.tds-print-mode .tds-main .tds-block > * + * {
	margin-top: var(--space-s, 0.75rem);
}

/* ----------------------------------------------------------------------
   PDF capture mode (set briefly by tds-print.js during html2canvas).
   The exporter applies the 12mm page margin itself, per page, so the
   sheet must not also carry its own padding during capture — otherwise
   pages 2+ would have no top or bottom margin.
   ---------------------------------------------------------------------- */

body.tds-print-mode .tds-sheet.tds-capturing {
	padding: 0 !important;
	box-shadow: none !important;
	min-height: 0 !important;
	/* Must shrink to the CONTENT width too. Stripping the padding while
	   leaving width at 210mm made the capture 210mm wide but the exporter
	   places it at 186mm, scaling everything down by 11%. */
	width: calc(var(--tds-page-w) - (var(--tds-page-margin) * 2)) !important;
	max-width: calc(var(--tds-page-w) - (var(--tds-page-margin) * 2)) !important;
}

/* -------------------------------------------------------------------------
   5. ACTUAL PRINTING
   ---------------------------------------------------------------------- */

@media print {

	@page {
		size: A4 portrait;
		margin: 12mm;
	}

	html,
	body {
		margin: 0 !important;
		padding: 0 !important;
		background: #fff !important;
		width: auto !important;
		min-height: 0 !important;
	}

	/* Without this Chrome strips every background and the grey label chips
	   become white text on white paper. */
	body.tds-print-mode,
	body.tds-print-mode * {
		-webkit-print-color-adjust: exact !important;
		print-color-adjust: exact !important;
	}

	body.tds-print-mode .tds-sheet {
		width: auto !important;
		max-width: none !important;
		min-height: 0 !important;
		margin: 0 !important;
		padding: 0 !important;
		box-shadow: none !important;
		background: #fff !important;
	}

	/* Catch-all for floating widgets (chat bubbles, debug buttons, back-to-top)
	   that sit at the end of <body> outside the sheet. If something still
	   prints that shouldn't, inspect it and add its class to the list in
	   section 3 instead of relying on this. */
	body.tds-print-mode > *:not(#brx-content):not(script):not(style):not(noscript) {
		display: none !important;
	}

	body.tds-print-mode a {
		color: inherit !important;
		text-decoration: none !important;
	}

	body.tds-print-mode a[href]::after { content: none !important; }

	/* Safety net for Ctrl+P on the plain ?tds=1 page. */
	#brx-header,
	#brx-footer,
	.no-print,
	#cmplz-cookiebanner-container,
	.cmplz-cookiebanner,
	.cmplz-manage-consent,
	#wpadminbar,
	.skip-link {
		display: none !important;
	}
}

/* -------------------------------------------------------------------------
   6. Small screens — keep the print route readable if opened on a phone.
   ---------------------------------------------------------------------- */

@media screen and (max-width: 230mm) {
	body.tds-print-mode .tds-sheet {
		width: 100%;
		min-height: 0;
		padding: var(--space-m, 1.25rem);
		box-shadow: none;
	}
	body.tds-print-mode { padding: 0; background: #fff; }
}
