/* ============================================================
   Ernesto Theme — Print Styles
   A4, editorial layout, image float, page break control
   ============================================================ */

/* ---- Page setup ---- */
@page {
	size: A4 portrait;
	margin: 20mm 18mm;
}

@page :first {
	margin-top: 25mm;
}

@media print {

	/* ---- Global reset for print ---- */
	*,
	*::before,
	*::after {
		background: #fff !important;
		background-color: #fff !important;
		background-image: none !important;
		color: #000 !important;
		box-shadow: none !important;
		text-shadow: none !important;
		-webkit-print-color-adjust: exact;
		print-color-adjust: exact;
	}

	html,
	body {
		font-size: 11pt;
		line-height: 1.6;
		color: #000;
		background: #fff;
		font-family: Georgia, 'Times New Roman', serif;
		width: 100%;
		margin: 0;
		padding: 0;
	}

	/* ---- Hide non-print elements ---- */
	header,
	.site-header,
	#site-header,
	nav,
	.site-navigation,
	#site-navigation,
	.main-navigation,
	.nav-menu,
	footer,
	.site-footer,
	#site-footer,
	.hero-slider,
	.slider-container,
	.slider-wrapper,
	.slider-arrows,
	.slider-dot,
	.slider-dots,
	.cookie-consent,
	.cookie-banner,
	.back-to-top,
	.accessibility-toolbar,
	.accessibility-toolbar-toggle,
	.social-sharing,
	.post-navigation,
	.pagination,
	.nav-links,
	.comments-area,
	.comment-respond,
	.sidebar,
	#sidebar,
	.widget-area,
	.wp-block-buttons,
	.wp-block-button,
	.breadcrumbs,
	.entry-meta,
	.entry-footer,
	.skip-link,
	.screen-reader-text,
	.no-print,
	form,
	button,
	input,
	select,
	textarea,
	video,
	audio,
	iframe:not(.print-include) {
		display: none !important;
	}

	/* ---- Main content area ---- */
	.site-content,
	.entry-content,
	main,
	#main,
	.wp-block-post-content,
	article {
		width: 100% !important;
		max-width: 100% !important;
		margin: 0 !important;
		padding: 0 !important;
		float: none !important;
		display: block !important;
	}

	/* ---- Typography ---- */
	h1, h2, h3, h4, h5, h6 {
		page-break-after: avoid;
		break-after: avoid;
		page-break-inside: avoid;
		break-inside: avoid;
		orphans: 3;
		widows: 3;
		clear: both; /* clear floated images before headings in single-column flow */
		margin-top: 0 !important; /* no top margin — prevents text column from starting lower than image column */
		margin-bottom: 4pt;
	}

	h1 { font-size: 22pt; line-height: 1.2; }
	h2 { font-size: 17pt; line-height: 1.3; }
	h3 { font-size: 13pt; line-height: 1.3; }
	h4 { font-size: 11pt; }
	h5, h6 { font-size: 10pt; }

	p {
		orphans: 3;
		widows: 3;
		margin-bottom: 5pt;
	}

	/* ---- URLs after links ---- */
	a[href]::after {
		content: ' (' attr(href) ')';
		font-size: 8pt;
		color: #444 !important;
		word-break: break-all;
	}

	/* Suppress URLs on internal anchors, image links, nav links */
	a[href^='#']::after,
	a[href^='javascript']::after,
	.wp-block-image a::after,
	figure a::after,
	a[href^='mailto']::after {
		content: '';
	}

	/* ---- Images — editorial float style ---- */
	/* All images: never cut across page breaks.
	   break-before: avoid stops Chrome starting a page
	   just above an image, break-inside: avoid stops it
	   cutting through the image itself. */
	img {
		display: block;
		max-width: 100% !important;
		height: auto !important;
		page-break-before: avoid !important;
		page-break-inside: avoid !important;
		break-before: avoid !important;
		break-inside: avoid !important;
	}

	/* Default: float left, text wraps around */
	.wp-block-image,
	.entry-content figure,
	article figure {
		float: left;
		max-width: 60mm !important;
		width: 60mm !important;
		margin: 2mm 8mm 6mm 0 !important;
		page-break-before: avoid !important;
		page-break-inside: avoid !important;
		break-before: avoid !important;
		break-inside: avoid !important;
	}

	/* Even figures float right for alternating editorial look */
	.entry-content figure:nth-of-type(even),
	article figure:nth-of-type(even),
	.wp-block-image:nth-of-type(even) {
		float: right;
		margin: 2mm 0 6mm 8mm !important;
	}

	/* Explicitly aligned images override the alternating float */
	.wp-block-image.alignleft {
		float: left !important;
		margin: 2mm 8mm 6mm 0 !important;
	}

	.wp-block-image.alignright {
		float: right !important;
		margin: 2mm 0 6mm 8mm !important;
	}

	/* Full-width and wide images: clear floats, span full width */
	.wp-block-image.alignfull,
	.wp-block-image.alignwide,
	.wp-block-image.size-full {
		float: none !important;
		clear: both;
		max-width: 100% !important;
		width: 100% !important;
		margin: 6mm 0 !important;
	}

	.wp-block-image.aligncenter {
		float: none !important;
		clear: both;
		margin: 6mm auto !important;
		text-align: center;
	}

	figcaption,
	.wp-element-caption {
		font-size: 8pt;
		color: #555 !important;
		font-style: italic;
		margin-top: 2mm;
		line-height: 1.3;
	}

	/* ---- Column grids (Gutenberg wp-block-columns) ---- */

	/* Override Gutenberg's per-column vertical alignment — everything top-aligned in print */
	/* Use higher specificity (.wp-block-columns .wp-block-column) to beat WordPress block CSS */
	.wp-block-columns .wp-block-column.is-vertically-aligned-top,
	.wp-block-columns .wp-block-column.is-vertically-aligned-center,
	.wp-block-columns .wp-block-column.is-vertically-aligned-bottom {
		align-self: flex-start !important;
	}

	.wp-block-columns {
		display: flex !important;
		flex-wrap: nowrap !important;
		align-items: flex-start !important; /* both columns start at the top */
		gap: 8mm;
		clear: both;
		width: 100%;
		page-break-inside: avoid;
		break-inside: avoid;
	}

	.wp-block-column {
		flex: 1 1 0;
		min-width: 0;
		page-break-inside: avoid;
		break-inside: avoid;
		/* No overflow: hidden — it interferes with break detection */
	}

	/* Ensure first child of every column starts flush at the top —
	   prevents heading/image misalignment in ½|½ patterns */
	.wp-block-column > *:first-child {
		margin-top: 0 !important;
		padding-top: 0 !important;
	}

	/* 3-column groups: slightly smaller text to fit A4 */
	.wp-block-columns:has(> .wp-block-column:nth-child(3)) .wp-block-column {
		font-size: 9pt;
		line-height: 1.5;
	}

	/* Images inside columns: don't float, let column flow naturally */
	.wp-block-column .wp-block-image,
	.wp-block-column figure {
		float: none !important;
		max-width: 100% !important;
		width: auto !important;
		margin: 0 0 4mm 0 !important; /* no top margin — keeps image flush with heading in adjacent column */
		page-break-before: avoid !important;
		page-break-inside: avoid !important;
		break-before: avoid !important;
		break-inside: avoid !important;
	}

	.wp-block-column .wp-block-image img,
	.wp-block-column figure img {
		max-width: 60mm !important;
		width: auto !important;
		height: auto !important;
	}

	/* ---- Media & Text block ---- */
	.wp-block-media-text {
		display: grid !important;
		grid-template-columns: 60mm 1fr;
		gap: 8mm;
		clear: both;
		page-break-inside: avoid;
		break-inside: avoid;
	}

	.wp-block-media-text.has-media-on-the-right {
		grid-template-columns: 1fr 60mm;
	}

	.wp-block-media-text .wp-block-media-text__media {
		page-break-inside: avoid;
		break-inside: avoid;
	}

	/* ---- Cover block — strip background, show text ---- */
	.wp-block-cover {
		background: none !important;
		color: #000 !important;
		padding: 0 !important;
		min-height: 0 !important;
	}

	.wp-block-cover__background,
	.wp-block-cover__image-background {
		display: none !important;
	}

	/* ---- Blockquotes ---- */
	blockquote,
	.wp-block-quote {
		border-left: 2pt solid #999 !important;
		padding: 3mm 0 3mm 5mm;
		margin: 5mm 0;
		font-style: italic;
		page-break-inside: avoid;
		break-inside: avoid;
	}

	blockquote cite,
	.wp-block-quote cite {
		font-size: 9pt;
		font-style: normal;
	}

	/* ---- Pullquote ---- */
	.wp-block-pullquote {
		border-top: 2pt solid #000 !important;
		border-bottom: 2pt solid #000 !important;
		padding: 5mm 0;
		text-align: center;
		clear: both;
		page-break-inside: avoid;
		break-inside: avoid;
	}

	/* ---- Tables ---- */
	table {
		width: 100%;
		border-collapse: collapse;
		font-size: 9pt;
		page-break-inside: auto;
	}

	thead {
		display: table-header-group; /* repeat header on each page */
	}

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

	th, td {
		border: 0.5pt solid #ccc !important;
		padding: 2mm 3mm;
		text-align: left;
	}

	th {
		font-weight: bold;
		background: #f0f0f0 !important;
	}

	/* ---- Code ---- */
	pre,
	code {
		font-size: 8pt;
		font-family: 'Courier New', monospace;
		white-space: pre-wrap;
		word-break: break-all;
		border: 0.5pt solid #ccc !important;
		padding: 2mm;
		page-break-inside: avoid;
		break-inside: avoid;
	}

	/* ---- Separator ---- */
	hr,
	.wp-block-separator {
		border: none !important;
		border-top: 0.5pt solid #ccc !important;
		margin: 5mm 0;
		clear: both;
	}

	/* ---- Utility ---- */
	/* Force page break before/after specific elements */
	.print-break-before { page-break-before: always; break-before: page; }
	.print-break-after  { page-break-after: always;  break-after: page;  }
	.print-no-break     { page-break-inside: avoid;  break-inside: avoid; }

} /* end @media print */
