/* public/print.css */
@media print {
  /* Page with bottom margin for footer */
  @page { 
    size: A4; 
    margin: 0 0 12mm 0; 
  }
  
  html, body { 
    background: #fff !important; 
    margin: 0 !important; 
    padding: 0 !important;
  }

  /* Hide everything by default using visibility */
  * {
    visibility: hidden;
  }

  /* Hide dialog containers completely - they take up space even when hidden */
  [data-radix-portal],
  [data-radix-overlay],
  [role="dialog"],
  [data-radix-content] {
    display: none !important;
    visibility: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    height: 0 !important;
    min-height: 0 !important;
  }

  /* Show preview and all its children */
  #preview,
  #preview * {
    visibility: visible !important;
  }

  /* Make sure preview displays correctly */
  #preview {
    display: block !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* The printable sheet */
  #preview .sheet {
    width: 210mm !important;
    max-width: 210mm !important;
    box-sizing: border-box !important;
    padding: 5mm 10mm !important;
    margin: 0 !important;  /* Remove auto margins */
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    page-break-inside: auto !important;
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 285mm !important; /* A4 height minus margin */
  }

  /* Table display types and sizing */
  #preview table {
    display: table !important;
    width: 100% !important;
    max-width: 100% !important;
    table-layout: fixed !important;
    page-break-inside: auto !important;
    font-size: 9px !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }

  #preview thead {
    display: table-header-group !important;
    page-break-inside: avoid !important;
  }

  #preview tbody {
    display: table-row-group !important;
    page-break-inside: auto !important;
  }

  #preview tr {
    display: table-row !important;
    page-break-inside: avoid !important;
  }

  #preview td,
  #preview th {
    display: table-cell !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    padding: 3px 4px !important;
    vertical-align: top !important;
    box-sizing: border-box !important;
  }

  /* Column width constraints to fit A4 */
  #preview th:first-child,
  #preview td:first-child { width: 10% !important; }
  #preview th:nth-child(2),
  #preview td:nth-child(2) { width: 28% !important; min-width: 0 !important; }
  #preview th:nth-child(3),
  #preview td:nth-child(3) { width: 7% !important; }
  #preview th:nth-child(4),
  #preview td:nth-child(4) { width: 11% !important; }
  #preview th:nth-child(5),
  #preview td:nth-child(5) { width: 11% !important; }
  #preview th:nth-child(6),
  #preview td:nth-child(6) { width: 7% !important; }
  #preview th:nth-child(7),
  #preview td:nth-child(7) { width: 16% !important; }

  /* Avoid breaking important elements */
  #preview .avoid-break,
  #preview header {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Hide original footer in print - we use cloned footers instead */
  #preview footer:not(.print-footer-clone) {
    display: none !important;
  }
  
  /* Cloned footers - positioned at bottom of each page using CSS */
  .print-footer-clone {
    position: fixed !important;
    bottom: 0 !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 190mm !important; /* 210mm - 20mm (10mm padding each side) */
    max-width: 190mm !important;
    margin: 0 !important;
    padding: 3mm 0 !important;
    text-align: center !important;
    background: #fff !important;
    z-index: 1000 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    visibility: visible !important;
  }
  
  /* Ensure footer content is centered */
  .print-footer-clone > * {
    text-align: center !important;
    margin: 0 auto !important;
  }
  
  /* Make links clickable and visible in PDF */
  .print-footer-clone a,
  #preview footer a {
    color: inherit !important;
    text-decoration: underline !important;
    cursor: pointer !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  /* Hide cloned footers in normal view, only show in print */
  @media screen {
    .print-footer-clone {
      display: none !important;
    }
  }

  /* Better color fidelity */
  * { 
    -webkit-print-color-adjust: exact; 
    print-color-adjust: exact; 
  }
}
