/**
 * BMCPC Print Framework — narrow component pagination rules.
 *
 * These rules apply only to declared component rows/items and the owned
 * source Footer. Container-wide grid/flex fragmentation remains under each
 * component adapter so oversized content is never made artificially atomic.
 */

@media print {
  /* Elementor tab wrappers are commonly flex containers. Chromium treats the
     relocated Footer as a separate flex item and can defer that small item to
     a new sheet even when the current sheet has room. The adapter marks only
     the one temporary parent; normal block fragmentation is restored exactly
     after printing. */
	body.bmcpc-print-active [data-bmcpc-print-footer-flow-container="1"] {
		display: block !important;
		width: 100% !important;
		max-width: 100% !important;
		flex: none !important;
		height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    contain: none !important;
  }

  body.bmcpc-print-active [data-bmcpc-print-footer-flow-pair="1"] {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }

  /* Screen templates often reserve 60–80px below page-content. Once the
     source Footer is relocated that margin is between content and Footer and
     can create a nearly empty final sheet. */
  body.bmcpc-print-active [data-bmcpc-print-footer-flow-anchor="1"] {
    margin-bottom: 0 !important;
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }

  body.bmcpc-print-active [data-bmcpc-print-footer-flow-anchor="oversized"] {
    margin-bottom: 0 !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  body.bmcpc-print-active :is(
    [data-bmcpc-print-role="heading"],
    [data-bmcpc-print-component] > [data-bmcpc-print-role="header"],
    details.e-n-accordion-item > summary
  ) {
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }

  body.bmcpc-print-active :is(
    [data-bmcpc-print-role="row"],
    .bmcpc-offering-results__row,
    .bmcpc-print-gallery-grid > [data-bmcpc-print-gallery-item],
    .bmcpc-print-media-image-grid-owned > [data-bmcpc-print-gallery-item],
    .bmcpc-print-media-image-grid-owned > .elementor-widget-image,
    .bmcpc-print-video-card
  ) {
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }

	body.bmcpc-print-active :is(
		.bmcpc-print-footer,
		[data-bmcpc-print-footer],
		footer[data-elementor-id="174"],
		footer[data-elementor-type="footer"]
	)[data-bmcpc-print-footer-flow-owned="active-scope"] {
		--bmcpc-print-footer-logo-max-height: 10mm;
		margin-top: 1mm !important;
		padding: var(--bmcpc-print-header-footer-edge-inset, 2.5mm) !important;
		break-before: auto !important;
		page-break-before: auto !important;
		break-inside: auto !important;
		page-break-inside: auto !important;
	}

	/* Home's legacy popup stylesheet reserves a dedicated Footer sheet for the
	 * normal closed-popup state. The shared Footer flow now owns the placement;
	 * cancel only that old forced break so the Footer can use remaining space. */
	body.bmcpc-print-active.bmcpc-print-profile-home.bmcpc-print-home-normal footer[data-elementor-id="174"][data-bmcpc-print-footer-flow-owned="active-scope"] {
		break-before: auto !important;
		page-break-before: auto !important;
	}

	/* Keep a short Footer from becoming a Footer-only trailing sheet. Elementor
	 * nests the logo/copyright row in several flex/grid shells; those shells
	 * must remain fragmentable when the last content row leaves only a small
	 * amount of printable space. */
	body.bmcpc-print-active :is(
		.bmcpc-print-footer,
		[data-bmcpc-print-footer],
		footer[data-elementor-id="174"],
		footer[data-elementor-type="footer"]
	)[data-bmcpc-print-footer-flow-owned="active-scope"] :is(
		.e-con,
		.e-con-inner,
		.elementor-widget,
		.elementor-widget-container
	) {
		min-height: 0 !important;
		max-height: none !important;
		break-inside: auto !important;
		page-break-inside: auto !important;
	}

	body.bmcpc-print-active footer[data-elementor-id="174"][data-bmcpc-print-footer-flow-owned="active-scope"] > .e-con > .e-con-inner > .e-con:has(
		> [data-id="c2f6016"]
	) {
		padding-top: 0 !important;
	}

  /* A generated video endpoint must stay in its source grid: wrapping it
     changes Elementor's direct-child grid selectors. Compact only print-only
     card whitespace and the adjacent owned Footer gap. Long media endpoints
     remain fragmentable and every source card remains in document order. */
  body.bmcpc-print-active.bmcpc-print-profile-fgfa
  [data-bmcpc-print-footer-flow-anchor="1"]:has(.bmcpc-print-video-card) {
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    row-gap: 2mm !important;
  }

  body.bmcpc-print-active.bmcpc-print-profile-fgfa
  [data-bmcpc-print-footer-flow-anchor="1"]:has(.bmcpc-print-video-card)
  .bmcpc-print-video-card {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 2mm !important;
    padding-bottom: 2mm !important;
  }

  body.bmcpc-print-active.bmcpc-print-profile-fgfa
  [data-bmcpc-print-footer-flow-anchor="1"]:has(.bmcpc-print-video-card)
  + footer[data-bmcpc-print-footer-flow-owned="active-scope"] {
    margin-top: 1mm !important;
  }

  body.bmcpc-print-active footer[data-elementor-id="174"][data-bmcpc-print-footer-flow-owned="active-scope"] > .e-con > .e-con-inner > .e-con:has(
    > [data-id="c2f6016"]
  ) {
    padding-top: 1mm !important;
  }

  /* The shared table adapter preserves source cell order and assigns
   * deterministic grid tracks. Let long tables fragment between complete
   * cells, while preventing a cell's own text from splitting into a thin
   * overlay fragment. This is scoped to prepared print tables only. */
  body.bmcpc-print-active [data-bmcpc-print-table-prepared="1"] {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
  }

  body.bmcpc-print-active .bmcpc-print-table-grid[data-bmcpc-print-table-prepared="1"] {
    grid-auto-flow: row !important;
    grid-auto-rows: auto !important;
    align-items: stretch !important;
    break-inside: auto !important;
    page-break-inside: auto !important;
  }

  body.bmcpc-print-active .bmcpc-print-table-grid[data-bmcpc-print-table-prepared="1"] > [data-bmcpc-print-table-cell="1"] {
    min-width: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    overflow-wrap: anywhere !important;
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
  }

  body.bmcpc-print-active.bmcpc-print-profile-fee-table .bmcpc-print-table-grid[data-bmcpc-print-table-prepared="1"],
  body.bmcpc-print-active.bmcpc-print-profile-form .bmcpc-print-table-grid[data-bmcpc-print-table-prepared="1"] {
    break-inside: auto !important;
    page-break-inside: auto !important;
  }

  /* Logical fee-group attributes remain on the original source-grid cells, so
   * table geometry is untouched. Break hints join only adjacent units inside a
   * fitting group; an oversized group receives no cross-unit hints and can
   * fragment between its complete cells. */
  body.bmcpc-print-active.bmcpc-print-profile-fee-table
  [data-bmcpc-print-table-cell="1"][data-bmcpc-print-fee-keep-before="1"] {
    break-before: avoid-page !important;
    page-break-before: avoid !important;
  }

  body.bmcpc-print-active.bmcpc-print-profile-fee-table
  [data-bmcpc-print-table-cell="1"][data-bmcpc-print-fee-keep-after="1"] {
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }
}
