/**
 * Print & PDF Styles
 */

@media print {
  /* Hide non-printable elements */
  .no-print,
  .btn,
  .btn-icon,
  .btn-icon-small,
  .btn-add-item,
  button,
  .filter-section,
  .pagination,
  .back-button-container,
  .invoice-actions,
  .modal-overlay,
  .loading-overlay {
    display: none !important;
  }

  /* Page setup */
  @page {
    size: A4;
    margin: 10mm;
  }

  body {
    margin: 0;
    padding: 0;
    background: white;
  }

  .invoice-container.compact-mode {
    max-width: 100%;
    box-shadow: none;
    margin: 0;
    padding: 0;
    page-break-inside: avoid !important;
    page-break-after: avoid !important;
  }

  /* Prevent page breaks for most elements */
  .invoice-header,
  .info-grid,
  .summary-section,
  .payment-box {
    page-break-inside: avoid !important;
  }

  /* Allow page breaks for sections with long tables */
  .section {
    page-break-inside: auto;
  }

  .section.may-break-inside {
    page-break-inside: auto !important;
  }

  /* Table header repeat */
  .invoice-table thead {
    display: table-header-group;
  }

  .invoice-table tbody {
    display: table-row-group;
  }

  /* Keep table rows together */
  .invoice-table tbody tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Control orphans and widows */
  p, li {
    orphans: 3;
    widows: 3;
  }

  /* Optimize table breaking */
  table {
    orphans: 3;
    widows: 3;
  }

  /* Color preservation */
  .invoice-table thead,
  .status-badge,
  .grand-total-row {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    color-adjust: exact;
  }

  /* Remove shadows */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }

  /* Ensure single page */
  html, body {
    height: auto !important;
    overflow: visible !important;
  }

  /* Hide table actions column */
  .invoice-table th:last-child,
  .invoice-table td:last-child {
    display: none;
  }

  /* Page break controls */
  .page-break-inside-avoid {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .page-break-before {
    page-break-before: always !important;
    break-before: page !important;
  }

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

  /* Ensure each page starts fresh */
  .invoice-page {
    page-break-after: always !important;
  }

  .invoice-page:last-child {
    page-break-after: auto !important;
  }

  /* Micro Agent List Table - Print Optimization */
  .invoice-detail-table {
    width: 100% !important;
    min-width: auto !important;
    font-size: 8px !important;
    border-collapse: collapse !important;
  }

  .invoice-detail-table th,
  .invoice-detail-table td {
    padding: 4px 6px !important;
    font-size: 8px !important;
    border: 1px solid #e5e7eb !important;
  }

  .invoice-detail-table th {
    background: #f3f4f6 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    font-weight: 600 !important;
  }

  .invoice-detail-table thead {
    display: table-header-group !important;
  }

  .invoice-detail-table tbody tr {
    page-break-inside: avoid !important;
  }

  /* Remove horizontal scroll wrapper for print */
  #websitesOver2MonthsSection > div[style*="overflow-x"] {
    overflow-x: visible !important;
    overflow: visible !important;
  }

  /* Adjust summary section for print */
  #websitesOver2MonthsSection .section-title {
    font-size: 12px !important;
    margin-bottom: 8px !important;
  }

  /* Compact summary boxes for print */
  #websitesOver2MonthsSection div[style*="grid-template-columns"] {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 8px !important;
    font-size: 9px !important;
  }

  #websitesOver2MonthsSection div[style*="grid-template-columns"] > div {
    padding: 6px !important;
  }

  /* Status badges - smaller for print */
  #websitesOver2MonthsSection span[style*="border-radius"] {
    padding: 2px 6px !important;
    font-size: 7px !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Hide created date info in print to save space */
  .invoice-detail-table td > div[style*="font-size: 9px"] {
    display: none !important;
  }
}
