@media print {
  .no-print {
    display: none !important;
  }
  
  .print-page {
    page-break-after: always;
  }
  
  .print-avoid-break {
    page-break-inside: avoid;
  }
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .print-optimize {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  
  .print-page-break {
    page-break-before: always;
  }
  
  .print-no-break {
    page-break-inside: avoid;
  }

  /* Force ALL borders to appear in print with maximum specificity */
  .border-b-2, 
  *[class*="border-b-2"] {
    border-bottom: 2px solid #000000 !important;
    border-bottom-style: solid !important;
    border-bottom-width: 2px !important;
    border-bottom-color: #000000 !important;
  }

  .border-b,
  *[class*="border-b"]:not([class*="border-b-2"]) {
    border-bottom: 1px solid #000000 !important;
    border-bottom-style: solid !important;
    border-bottom-width: 1px !important;
    border-bottom-color: #000000 !important;
  }

  .border-slate-800,
  *[class*="border-slate-800"] {
    border-color: #000000 !important;
  }

  .border-gray-300,
  *[class*="border-gray-300"] {
    border-color: #666666 !important;
  }

  .border-gray-400,
  *[class*="border-gray-400"] {
    border-color: #333333 !important;
  }

  /* Force section headers to have borders - but allow inline styles to override */
  h2[class*="border-b"],
  .border-b-2 {
    border-bottom: 2px solid #000000 !important;
  }
  
  /* Only apply default spacing if no inline styles present */
  h2[class*="border-b"]:not([style*="margin"]):not([style*="padding"]),
  .border-b-2:not([style*="margin"]):not([style*="padding"]) {
    padding-bottom: 2px !important;
    margin-bottom: 8px !important;
  }

  /* Ensure text colors appear with maximum contrast */
  .text-slate-900,
  *[class*="text-slate-900"] {
    color: #000000 !important;
  }

  .text-slate-700,
  *[class*="text-slate-700"] {
    color: #333333 !important;
  }

  .text-slate-600,
  *[class*="text-slate-600"] {
    color: #555555 !important;
  }

  .text-black,
  *[class*="text-black"] {
    color: #000000 !important;
  }

  /* Force font weights */
  .font-bold,
  *[class*="font-bold"] {
    font-weight: 700 !important;
  }

  .font-semibold,
  *[class*="font-semibold"] {
    font-weight: 600 !important;
  }

  .font-medium,
  *[class*="font-medium"] {
    font-weight: 500 !important;
  }

  /* Ensure backgrounds print */
  .bg-white,
  *[class*="bg-white"] {
    background: #ffffff !important;
    background-color: #ffffff !important;
  }

  /* Force list styling with maximum specificity */
  .list-disc,
  *[class*="list-disc"],
  ul.list-disc {
    list-style-type: disc !important;
    list-style-position: outside !important;
  }

  ul.list-disc li {
    list-style-type: disc !important;
  }

  .list-disc li,
  *[class*="list-disc"] li {
    display: list-item !important;
    list-style-type: disc !important;
  }

  /* Hide non-printable elements */
  .no-print, nav, button:not(.print-include), [data-testid*="button"] {
    display: none !important;
    visibility: hidden !important;
  }

  /* Ensure proper spacing */
  .space-y-1 > * + *,
  *[class*="space-y-1"] > * + * {
    margin-top: 0.25rem !important;
  }

  .space-y-2 > * + *,
  *[class*="space-y-2"] > * + * {
    margin-top: 0.5rem !important;
  }

  .space-y-3 > * + *,
  *[class*="space-y-3"] > * + * {
    margin-top: 0.75rem !important;
  }

  .space-y-4 > * + *,
  *[class*="space-y-4"] > * + * {
    margin-top: 1rem !important;
  }

  /* Page margins and setup */
  @page {
    margin: 0.5in;
    size: A4;
  }

  /* Ensure non-styled elements print with black text on white background */
  /* Exclude elements with inline color/background styles so template colours are preserved */
  *:not([style*="color:"]) {
    color: #000000 !important;
  }

  *:not([style*="background-color"]):not([style*="background:"]) {
    background: transparent !important;
  }

  .bg-white {
    background: #ffffff !important;
  }
}