/* Alhaseen document print fixes — 2026-08-04
   F-01/F-02/F-08: one-page unified certificates, complete compulsory pages,
   and no horizontal overflow. Loaded after the application stylesheet. */

#motor-certificate,
#universal-certificate,
#compulsory-motor-certificate,
#invoice {
  min-width: 0;
  overflow-wrap: anywhere;
}

#motor-certificate *,
#universal-certificate * {
  min-width: 0;
}

/* F-08: Tailwind's scale-110 on the vehicle artwork enlarged it outside
   its padded card by 7px. Keep the full image inside the insured card. */
#motor-certificate img[alt="المركبة المؤمّنة"] {
  transform: none !important;
  max-width: 100% !important;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 5mm;
  }

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

  /* The application shell is a fixed-height scroll container. If its
     scrollTop survives into print, #invoice starts above page zero and the
     compulsory header is clipped. Remove the shell from the print flow. */
  body:has(#invoice) #root,
  body:has(#invoice) #root > .flex.h-screen {
    display: block !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  body:has(#invoice) #root > .flex.h-screen > :not(main) {
    display: none !important;
  }

  body:has(#invoice) main {
    display: block !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  body:has(#invoice) main > .max-w-4xl,
  body:has(#invoice) main > .max-w-4xl > div {
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    margin: 0 !important;
    overflow: visible !important;
  }

  #invoice {
    position: static !important;
    inset: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 0 !important;
    overflow: visible !important;
    break-before: auto !important;
    page-break-before: auto !important;
    break-after: auto !important;
    page-break-after: auto !important;
  }

  /* The unified certificates exceeded the printable height only slightly,
     sending the footer strip to a blank second page. Preserve full width
     after a 92% print zoom and keep the certificate as one print fragment. */
  #invoice > #universal-certificate,
  #invoice > #motor-certificate {
    zoom: 0.92;
    width: 108.695652% !important;
    max-width: none !important;
    margin: 0 !important;
    overflow: hidden !important;
    break-inside: avoid-page !important;
    page-break-inside: avoid !important;
    break-after: avoid-page !important;
    page-break-after: avoid !important;
  }

  #invoice > #universal-certificate > *,
  #invoice > #motor-certificate > * {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Compulsory insurance intentionally has front and back pages. Reset the
     screen-only 1120px minimum and any transform/offset so the header, logo,
     title and QR begin inside the printable A4 area. */
  #invoice > #compulsory-motor-certificate,
  .ahi-cp-wrap {
    position: static !important;
    inset: auto !important;
    transform: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: none !important;
    overflow: visible !important;
  }

  .ahi-cp-page {
    position: relative !important;
    inset: auto !important;
    transform: none !important;
    width: 200mm !important;
    max-width: 200mm !important;
    min-width: 200mm !important;
    height: 287mm !important;
    min-height: 287mm !important;
    max-height: 287mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }

  .ahi-cp-front {
    break-after: page !important;
    page-break-after: always !important;
  }

  .ahi-cp-back {
    break-after: auto !important;
    page-break-after: auto !important;
  }
}
