/* Shared A4 and footer dimensions used by quote and contract print layouts. */
:where(body.quote-singleview-page, body.contract-singleview-page) {
  --document-print-page-height: 297mm;
  --document-print-footer-reserve: 150px;
}

body.contract-singleview-page .document-closing-sections {
  display: flex;
  flex-direction: column;
  gap: 1em;
}

/* Keep the normal screen footer spacing after the relocated closing sections. */
@media screen {
  :where(body.quote-singleview-page, body.contract-singleview-page) .table_print .page-footer-space {
    display: none;
    height: 0;
  }

  body.quote-singleview-page .document-summary-page {
    margin-bottom: var(--document-print-footer-reserve);
  }

  body.contract-singleview-page .document-closing-sections {
    margin-bottom: var(--document-print-footer-reserve);
  }

  body.contract-singleview-page .document-summary {
    order: 1;
  }

  body.contract-singleview-page .contract-signature-section {
    order: 2;
  }
}

/* Shared final-page placement for quote and contract totals in Chromium PDF output. */
@media print {
  :where(body.quote-singleview-page, body.contract-singleview-page) .table_print {
    height: auto !important;
  }

  :where(body.quote-singleview-page, body.contract-singleview-page) .document-summary-page {
    break-before: page;
    page-break-before: always;
    min-height: calc(var(--document-print-page-height) - var(--document-print-footer-reserve));
    width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  :where(body.quote-singleview-page, body.contract-singleview-page) .document-summary {
    flex: 0 0 auto !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body.contract-singleview-page .document-closing-sections {
    flex: 0 0 auto;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  body.quote-singleview-page table.dataTable#evx_table {
    border-left: 1px solid var(--quote-column-border) !important;
  }

  body.contract-singleview-page table.dataTable#evx_table {
    border-left: 1px solid var(--contract-column-border) !important;
  }

  :where(body.contract-singleview-page) .contract-signature-section {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* The fixed footer becomes normal flow content in the existing iOS print fallback. */
  @supports (-webkit-touch-callout: none) {
    :where(body.quote-singleview-page, body.contract-singleview-page) .document-summary-page {
      break-before: auto;
      page-break-before: auto;
      min-height: 0;
      display: block;
    }
  }
}
