@media print {
  /* Hide non-printable elements */
  #sidebar,
  aside,
  header,
  nav,
  .sidebar,
  .topbar,
  #sidebar-toggle,
  #user-dropdown-container,
  .no-print,
  button:not(.print-include),
  a.btn,
  .pagination,
  .flash,
  [data-controller="flash"],
  [data-controller="sidebar"],
  [data-controller="dropdown"] {
    display: none !important;
  }

  /* Reset layout */
  body {
    background: white !important;
    color: black !important;
    font-size: 12pt !important;
    line-height: 1.4 !important;
  }

  #main-content,
  main {
    margin-left: 0 !important;
    padding: 0 !important;
    width: 100% !important;
  }

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

  /* Prevent page breaks inside elements */
  .card,
  table,
  tr,
  .stat-card,
  .report-card-section {
    page-break-inside: avoid;
  }

  /* Table styling for print */
  table {
    border-collapse: collapse;
    width: 100%;
  }

  th, td {
    border: 1px solid #333;
    padding: 6px 8px;
    text-align: left;
  }

  th {
    background-color: #f3f4f6 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Fee analytics / dashboards — remove overflow clipping so all content prints */
  .overflow-hidden,
  .overflow-x-auto,
  .overflow-y-auto,
  .overflow-auto,
  [style*="overflow"],
  [style*="max-height"] {
    overflow: visible !important;
    max-height: none !important;
    height: auto !important;
  }

  /* Charts should page-break after, not clip */
  canvas {
    max-width: 100% !important;
    height: auto !important;
    page-break-after: auto;
  }

  /* Dashboard stat cards — flow naturally */
  .grid {
    display: block !important;
  }

  .grid > * {
    page-break-inside: avoid;
    margin-bottom: 10px;
  }

  /* Fee receipt specific — fits both A4 and thermal 80mm */
  .fee-receipt {
    max-width: 210mm;
    margin: 0 auto;
    padding: 10mm;
    border: 2px solid #333;
  }

  .fee-receipt .school-header {
    text-align: center;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
    margin-bottom: 15px;
  }

  /* Thermal receipt (80mm POS printer) */
  .fee-receipt.thermal,
  .fee-receipt--thermal {
    max-width: 72mm;    /* 80mm paper minus ~4mm margin each side */
    padding: 2mm;
    border: none;
    font-size: 9pt;
    line-height: 1.2;
  }

  .fee-receipt.thermal .school-header,
  .fee-receipt--thermal .school-header {
    border-bottom: 1px dashed #333;
    padding-bottom: 4px;
    margin-bottom: 6px;
  }

  .fee-receipt.thermal table,
  .fee-receipt--thermal table {
    font-size: 8pt;
  }

  .fee-receipt.thermal th,
  .fee-receipt.thermal td,
  .fee-receipt--thermal th,
  .fee-receipt--thermal td {
    padding: 2px 3px;
    border: none;
    border-bottom: 1px dotted #999;
  }

  /* Report card specific — A4 portrait */
  @page report-card {
    size: A4 portrait;
    margin: 15mm;
  }

  .report-card {
    page: report-card;
    max-width: 210mm;
    margin: 0 auto;
    border: 2px solid #333;
    padding: 15mm;
  }

  .report-card .school-header {
    text-align: center;
    margin-bottom: 20px;
  }

  .report-card .student-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 15px;
  }

  /* Attendance register specific */
  @page attendance-register {
    size: A4 landscape;
    margin: 10mm 8mm;
  }

  .attendance-register {
    page: attendance-register;
    font-size: 9pt;
  }

  .attendance-register th,
  .attendance-register td {
    padding: 3px 4px;
    text-align: center;
  }

  .attendance-register-table {
    font-size: 8pt;
  }

  .attendance-register-table th,
  .attendance-register-table td {
    padding: 2px 3px;
    border: 1px solid #666;
  }

  .attendance-register .print\:block {
    display: block !important;
  }

  /* Certificate specific */
  .certificate {
    max-width: 297mm;
    min-height: 210mm;
    margin: 0 auto;
    padding: 20mm;
    border: 3px double #333;
    text-align: center;
  }

  .certificate .cert-border {
    border: 1px solid #666;
    padding: 15mm;
    min-height: calc(210mm - 40mm);
  }

  /* Remove background colors except where explicitly preserved */
  *:not(th):not(.print-bg) {
    background-color: transparent !important;
  }

  /* Preserve background for elements that need it */
  .print-bg,
  th {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Bulk print: page break between report cards / certificates */
  .report-card + .report-card,
  .certificate + .certificate {
    page-break-before: always;
  }

  /* Transfer certificate specific */
  .transfer-certificate {
    max-width: 210mm;
    margin: 0 auto;
    padding: 15mm;
    border: 2px solid #333;
  }

  .transfer-certificate .school-header {
    text-align: center;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
    margin-bottom: 20px;
  }

  .transfer-certificate .tc-field {
    display: flex;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px dotted #999;
  }

  .transfer-certificate .tc-label {
    font-weight: bold;
    min-width: 180px;
  }

  /* Links */
  a {
    color: black !important;
    text-decoration: none !important;
  }

  /* Images */
  img {
    max-width: 100%;
  }
}
