@media print {
	/* Key rule: print can't "scroll". Make scroll containers expand so content can paginate. */
	html,
	body {
		height: auto !important;
		overflow: visible !important;
	}

	/* Common app/layout wrappers that often cap height or create scroll regions */
	.empty-layout,
	.main-wrapper,
	.main-content,
	main,
	.content,
	.content-wrapper,
	.content-container,
	.RV_contentSection,
	.RV_chartsView,
	.CreateNewReportContainer,
	.CreateNewReportContainer.ReportViewerScreen,
	.CreateNewReportContainer.ReportViewerScreen.content-wrapper,
	.CNR_landingChartsWrapper {
		height: auto !important;
		max-height: none !important;
		overflow: visible !important;
		position: static !important;
	}

	/* If any child elements use fixed positioning/sticky toolbars, disable for print */
	*[style*="position:fixed"],
	*[style*="position: sticky"] {
		position: static !important;
	}

	/* Hide left sidebar and any explicitly marked non-print elements */
	.sidebar,
	.no-export {
		display: none !important;
	}

	/* Reset grid so content doesn't shift into the sidebar column */
	.main-wrapper {
		display: block !important;
		grid-template-columns: none !important;
		grid-template-areas: none !important;
	}

	/* Make the main content span full width for printing */
	html,
	body,
	.main-content {
		margin: 0 !important;
		padding: 0 !important;
		background: #ffffff !important;
		width: 100% !important;
	}

	.main-content {
		display: block !important;
		grid-column: auto !important;
	}

	/* Ensure the ReportViewer container uses available width */
	.CreateNewReportContainer.ReportViewerScreen.content-wrapper {
		width: 100% !important;
	}
	
	/* Dashboard only (viewer + public viewer): reduce top/bottom gap (gray area fix). Report export unchanged. */
	.dashboard-viewer .CNR_infoSection,
	.dashboard-viewer .RV_contentSection,
	.dashboard-viewer .RV_chartsView,
	.public-dashboard-viewer .CNR_infoSection,
	.public-dashboard-viewer .RV_contentSection,
	.public-dashboard-viewer .RV_chartsView {
		padding-top: 4px !important;
		padding-bottom: 4px !important;
		margin-top: 0 !important;
		margin-bottom: 0 !important;
	}
	.dashboard-viewer .CNR_infoSection,
	.public-dashboard-viewer .CNR_infoSection {
		padding-left: 8px !important;
		padding-right: 8px !important;
	}
	.dashboard-viewer .RV_contentSection,
	.public-dashboard-viewer .RV_contentSection {
		padding-left: 8px !important;
		padding-right: 8px !important;
	}
	.dashboard-viewer .RV_chartsView,
	.public-dashboard-viewer .RV_chartsView {
		padding: 4px 8px !important;
		margin-top: 4px !important;
	}

	/* Dashboard export/print: sequential layout (same as report). Export view uses .dashboard-export-stack with col-12. */
	.dashboard-export-stack,
	.dashboard-export-stack .col-12 {
		display: block !important;
		width: 100% !important;
		max-width: 100% !important;
	}

	/* Dashboard print: remove extra space at end of each report – no min-height, minimal gap between components */
	.dashboard-viewer .CNR_landingChartsWrapper,
	.dashboard-viewer .CNR_landingChartsWrapper.ChartsCardSize,
	.public-dashboard-viewer .CNR_landingChartsWrapper,
	.public-dashboard-viewer .CNR_landingChartsWrapper.ChartsCardSize,
	.dashboard-export-stack .CNR_landingChartsWrapper,
	.dashboard-export-stack .CNR_landingChartsWrapper.ChartsCardSize {
		min-height: 0 !important;
		height: auto !important;
	}
	.dashboard-viewer .CNR_landingChartsWrapper .chart-container,
	.dashboard-viewer .CNR_landingChartsWrapper .gauge-container,
	.dashboard-viewer .CNR_landingChartsWrapper .map-container,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .chart-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .gauge-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .map-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container,
	.dashboard-export-stack .CNR_landingChartsWrapper .chart-container,
	.dashboard-export-stack .CNR_landingChartsWrapper .gauge-container,
	.dashboard-export-stack .CNR_landingChartsWrapper .map-container,
	.dashboard-export-stack .CNR_landingChartsWrapper .grid-container {
		min-height: 0 !important;
		height: auto !important;
		flex: none !important;
	}
	.dashboard-export-stack .row,
	.dashboard-export-stack.dashboard-export-stack {
		margin-bottom: 0 !important;
		gap: 0 !important;
	}
	.dashboard-export-stack .export-pdf,
	.dashboard-export-stack .col-12 {
		margin-bottom: 8px !important;
		padding-bottom: 0 !important;
		height: auto !important;
	}
	.dashboard-export-stack .export-pdf:last-child,
	.dashboard-export-stack .col-12:last-child {
		margin-bottom: 0 !important;
	}

	.RV_chartsView .row .col-12 .CNR_landingChartsWrapper .grid-container{
		flex:none !important;
	}
	/* Dashboard only: remove grid scrollbar so all records print (like report export) */
	.dashboard-viewer .grid-container,
	.dashboard-viewer .grid-container .k-grid-aria-root,
	.dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container,
	.dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container .k-grid-content,
	.dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-height-container,
	.dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-grid-table-wrap,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container .k-grid-content,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-height-container,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-grid-table-wrap,
	.public-dashboard-viewer .grid-container,
	.public-dashboard-viewer .grid-container .k-grid-aria-root,
	.public-dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container,
	.public-dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container .k-grid-content,
	.public-dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-height-container,
	.public-dashboard-viewer .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-grid-table-wrap,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container .k-grid-content,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-height-container,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid-aria-root .k-grid-container .k-grid-content .k-grid-table-wrap {
		height: auto !important;
		max-height: none !important;
		min-height: 0 !important;
		overflow-y: visible !important;
	}
	.dashboard-viewer .grid-container .k-grid,
	.dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid,
	.public-dashboard-viewer .grid-container .k-grid,
	.public-dashboard-viewer .CNR_landingChartsWrapper .grid-container .k-grid {
		height: auto !important;
	}
	
    .k-grid-content,
    .k-grid-aria-root .k-grid-content,
    .k-grid-content,
    .k-grid-aria-root .k-grid-content {
        height: auto !important;
        max-height: none !important;
        overflow-y: visible !important;
        overflow: visible !important;
    }
	

	/* Tweak common button classes just in case any remain */
	.btn,
	.telerik-button,
	.k-button,
	.k-button-group {
		display: none !important;
	}

	/* Hide Telerik Grid pagination and toolbars in print */
	.k-grid .k-pager,
	.k-grid .k-pager-wrap,
	.k-grid .k-pager-numbers,
	.k-grid .k-pager-sizes,
	.k-grid .k-pager-info,
	.k-grid .k-pager-nav,
	.k-grid-pager,
	.k-pager,
	.k-toolbar {
		display: none !important;
	}

	/* Add some space in report footer and content */
    .k-grid-footer {
        padding-top: 25px;
    }
	/* Help pagination: avoid cutting a chart/card in half when possible */
	.CNR_landingChartsWrapper > *,
	.k-card,
	.k-chart,
	canvas,
	svg {
		break-inside: avoid !important;
		page-break-inside: avoid !important;
	}

	/* The rule above only protects each direct child (title block, visual) individually - it
	   does nothing to stop a break landing BETWEEN them, e.g. a part's title stranded at the
	   bottom of one page and its chart/map starting fresh on the next. Glue title+visual
	   together ONLY for a single (non-split) part, where the visual container is a DIRECT
	   child of the wrapper (title + container are siblings, nothing nests them together).
	   A split part (separator/multi-instance chart or gauge) wraps EACH item in its own
	   anonymous <div> first, so its container is a grandchild, not a direct child - this
	   selector deliberately does NOT match that shape, because forcing an entire multi-item
	   split group (which is often taller than one page) to stay atomic doesn't work: "avoid"
	   is a soft constraint, and once content can't fit at all the browser breaks it at an
	   arbitrary point anyway, producing worse fragmentation than leaving it alone. Grids are
	   likewise excluded (not listed here) since a tall grid must be free to paginate. */
	.CNR_landingChartsWrapper:has(> .map-container),
	.CNR_landingChartsWrapper:has(> .chart-container),
	.CNR_landingChartsWrapper:has(> .gauge-container) {
		break-inside: avoid !important;
		page-break-inside: avoid !important;
	}

	/* The export wrapper should not force a new page; let the browser pack content naturally */
	.export-pdf,
	.CNR_landingChartsWrapper {
		break-before: auto !important;
		page-break-before: auto !important;
		break-after: auto !important;
		page-break-after: auto !important;
	}

	/* Chrome's print engine does not honor forced break-before/after on flex-item children -
	   ComponentPreview's report parts (.export-pdf) are direct children of Bootstrap's .row,
	   which is display:flex by default. Without unflexing it here, the Page Break After Report
	   Part setting's break-before:always (applied dynamically in app.v5.js) is silently ignored. */
	.RV_chartsView .row {
		display: block !important;
	}
	.RV_chartsView .row > * {
		width: 100% !important;
		max-width: 100% !important;
	}

	/* The grid is typically taller than a page; allow splitting even though we avoid-split for other cards. */
	.CNR_landingChartsWrapper > .grid-container,
	.CNR_landingChartsWrapper > .grid-container *,
	.grid-container,
	.grid-container *,
	.k-grid,
	.k-grid *,
	.k-grid-content,
	.k-grid-content * {
		break-inside: auto !important;
		page-break-inside: auto !important;
	}

	/* Remove "scroll viewport" behavior inside Telerik grid so it can paginate.
	   height must be auto (not 100%) - 100% resolves against the paginated containing
	   block, not the grid's natural content size, so a grid taller than one page would
	   still be height-constrained and keep its scrollbar. This also cascades after (and
	   would otherwise win over) the height:auto rule near the top of this file since both
	   use !important on the same selectors - keep this one as auto too so they agree. */
	.k-grid,
	.k-grid-content,
	.k-grid-aria-root,
	.k-grid-container,
	.k-height-container,
	.k-grid-table-wrap {
		height: auto !important;
		max-height: none !important;
		overflow: visible !important;
	}

	/* Nothing readable on screen may be silently dropped from the PDF. The Telerik theme
	   clips overflowing grid text with an ellipsis in two places: column headers, where
	   .k-column-title is white-space:nowrap + overflow:hidden + text-overflow:ellipsis
	   inside an overflow:hidden .k-cell-inner flex wrapper, and data cells, where
	   .k-table-td is overflow:hidden + text-overflow:ellipsis. On screen that clipping is
	   recoverable - the reader can widen or resize the column - but on paper the cut
	   characters are simply gone, so for print we trade width for height: let the text
	   wrap onto extra lines and let the row grow. Height is the axis a PDF can absorb
	   (vertical pagination already works); width is not, which is why this wraps instead
	   of widening columns. Columns that overflow the page HORIZONTALLY are a separate
	   problem already handled by applyGridColumnsAutoFit/applyGridColumnsPerPage in
	   app.v5.js, which split them across pages.

	   Deliberately scoped to .k-grid and NOT to the hierarchical .k-pivotgrid: that
	   widget lays its row headers and its values out as two sibling panes of a CSS grid,
	   aligned only by their rows happening to be the same height, so letting a row header
	   wrap taller than its value row would slide every following row out of alignment and
	   caption data with the wrong label. It is never exported anyway - GridPreview.razor
	   renders TelerikPivotGrid only when `IsExport != true`, so an exported pivot is the
	   flat TelerikGrid path, which the selectors below already cover. */
	.k-grid .k-table-th,
	.k-grid .k-cell-inner,
	.k-grid .k-column-title,
	.k-grid .k-table-td {
		white-space: normal !important;
		overflow: visible !important;
		text-overflow: clip !important;
		/* Normal wrapping only breaks at spaces, so a long unbroken token (reference
		   codes, URLs, concatenated ids) would still overrun its fixed-width column and
		   be clipped. "anywhere" both permits a mid-token break and lets the token's
		   min-content contribution collapse, so it cannot force the column wider either. */
		overflow-wrap: anywhere !important;
	}

	/* Grids are often taller than a page; allowing them to split prevents blank pages */
	.CreateNewReportContainer .CNR_gridSection,
	.CreateNewReportContainer .CNR_gridSection *,
	.k-grid,
	.k-grid *,
	.k-grid-content,
	.k-grid-content * {
		break-inside: auto !important;
		page-break-inside: auto !important;
		break-before: auto !important;
		page-break-before: auto !important;
	}

	/* Telerik Window used for subreport drill-down popups scrolls its content internally
	   (ComponentPreview.razor: ".subreport-window .k-window-content { overflow: auto; }") -
	   nothing else in this file touches k-window, so its scrollbar otherwise prints as-is. */
	.k-window,
	.k-window-content,
	.subreport-window .k-window-content {
		height: auto !important;
		max-height: none !important;
		overflow: visible !important;
	}

	/* Prevent a forced blank page between filter and grid */
	.CreateNewReportContainer .CNR_filter_section {
		break-after: avoid-page !important;
		page-break-after: avoid !important;
		margin-bottom: 0 !important;
		padding-bottom: 0 !important;
	}

	/* In app.css the grid wrapper has height:56vh and min-height:530px; this can push it to the next page. */
	.CreateNewReportContainer .CNR_gridSection {
		height: auto !important;
		min-height: 0 !important;
		max-height: none !important;
		background: transparent !important;
		background-image: none !important;
	}

	/* Ensure large charts can scale to page width */
	img,
	svg,
	canvas {
		max-width: 100% !important;
	}

	/* Page setup for better print margins (reports and dashboard) */
	@page {
		size: A4;
		margin: 12mm;
	}
}
