/* ============================================
   PROFESSIONAL PRINT STYLESHEET FOR REPORTS
   Browser-native PDF generation with perfect fidelity
   ============================================ */

@media print {
  /* Page setup - A4 format with professional margins */
  @page {
    size: A4;
    margin: 15mm 12mm;
  }
  
  /* Ensure colors and backgrounds print correctly */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  
  /* Hide UI elements - buttons, navigation, etc. */
  .no-print,
  [data-no-print="true"],
  .report-actions,
  button:not(.print-keep),
  nav,
  header,
  footer,
  aside,
  .sidebar,
  .navigation,
  .breadcrumb,
  [role="navigation"],
  [role="banner"],
  [role="complementary"],
  .site-header,
  .site-footer,
  [role="button"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
  }
  
  /* ONLY show report content - Include iframes for report display */
  body > *:not(.report-content):not(#report-content):not(main):not(iframe) {
    display: none !important;
  }
  
  /* Ensure iframes are visible and full-width in print */
  iframe {
    display: block !important;
    width: 100% !important;
    border: none !important;
  }
  
  /* Body styling for professional output */
  body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
    line-height: 1.5;
  }
  
  /* Page break control - keep headers with content */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    break-after: avoid !important;
    break-inside: avoid !important;
    orphans: 2;
    widows: 2;
  }
  
  /* Ensure headers stay with next element */
  h1 + *, h2 + *, h3 + * {
    page-break-before: avoid !important;
    break-before: avoid !important;
  }
  
  p, blockquote, li {
    page-break-inside: auto;
  }
  
  /* Force page breaks where needed */
  .page-break-before {
    page-break-before: always;
  }
  
  .page-break-after {
    page-break-after: always;
  }
  
  .avoid-break {
    page-break-inside: avoid;
  }
  
  /* Table handling - keep tables together */
  table {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    border-collapse: collapse;
    width: 100%;
  }
  
  thead {
    display: table-header-group;
  }
  
  tbody tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  
  /* Images - keep together */
  img {
    max-width: 100%;
    page-break-inside: avoid;
  }
  
  /* Report content - full width utilization */
  .report-content,
  .container,
  #report-content,
  #report-iframe {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }
  
  /* Card containers should be visible in print */
  .card {
    border: none !important;
    box-shadow: none !important;
    background: white !important;
  }
  
  /* Cards and sections - PREVENT breaks inside */
  .card, 
  [class*="card"],
  .category-section,
  .factor-summary,
  .quiz-answer-card,
  [class*="section"] {
    border: 1px solid #e5e7eb !important;
    box-shadow: none !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin-bottom: 15pt;
  }
  
  /* Orphans and widows control - professional typography */
  p {
    orphans: 3;
    widows: 3;
  }
  
  /* Links - show URL for reference */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #6b7280;
  }
  
  /* Remove link underlines in print for cleaner look */
  a {
    text-decoration: none;
    color: inherit;
  }
  
  /* Ensure proper text contrast */
  h1, h2, h3, h4, h5, h6,
  .text-primary,
  .text-foreground {
    color: black !important;
  }
  
  .text-muted-foreground,
  .text-secondary {
    color: #4b5563 !important;
  }
  
  /* Background colors for sections */
  .bg-card,
  .bg-background {
    background: white !important;
  }
  
  /* Borders and dividers */
  .border {
    border-color: #e5e7eb !important;
  }
  
  /* Score displays and metrics */
  .score-display,
  .metric-value {
    font-weight: bold;
    color: black !important;
  }
  
  /* Quiz answers section - natural flow, no forced breaks */
  .quiz-answers {
    page-break-before: auto;
    margin-top: 30pt;
  }
  
  /* Ensure proper spacing between sections */
  section {
    margin-bottom: 20pt;
  }
  
  /* Header styling for printed version */
  .report-header {
    margin-bottom: 25pt;
    page-break-after: avoid;
  }
  
  /* Footer - hide or style appropriately */
  footer {
    display: none;
  }
}
