/* ==========================================================================
   ENTERPRISE DEDICATED REPORT PRINT ENGINE
   Transforms all screen prints into official, high-quality institutional reports
   ========================================================================== */

/* Screen Preview styles (hidden by default) */
#dedicated-report-container {
  display: none;
}

@media screen {
  #dedicated-report-container {
    display: none !important;
  }

  /* On-screen Live Report Preview Modal */
  .report-preview-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: rgba(15, 23, 42, 0.75);
    backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px;
    overflow-y: auto;
    animation: fajarPreviewFadeIn 0.2s ease-out;
  }

  .report-preview-toolbar {
    width: 100%;
    max-width: 900px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #0f172a;
    color: #ffffff;
    padding: 12px 18px;
    border-radius: 10px 10px 0 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    margin-top: 10px;
  }

  .report-preview-toolbar-title {
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .report-preview-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .report-preview-btn-print {
    background: #2563eb;
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.15s ease;
  }

  .report-preview-btn-print:hover {
    background: #1d4ed8;
  }

  .report-preview-btn-close {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
  }

  .report-preview-btn-close:hover {
    background: rgba(255, 255, 255, 0.25);
  }

  .report-preview-sheet {
    width: 100%;
    max-width: 900px;
    background: #ffffff;
    color: #0f172a;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    border-radius: 0 0 10px 10px;
    padding: 40px;
    margin-bottom: 40px;
    min-height: 800px;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  }

  /* Floating Quick Print Button on Data Modules */
  .fajar-quick-print-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #1e40af 0%, #0f172a 100%);
    color: #ffffff !important;
    font-size: 13px;
    font-weight: 700;
    border-radius: 9999px;
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.45);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .fajar-quick-print-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.6);
    background: linear-gradient(135deg, #2563eb 0%, #1e3a8a 100%);
  }

  .fajar-quick-print-fab svg {
    width: 16px;
    height: 16px;
    color: #ffffff !important;
    stroke: #ffffff !important;
  }
}

@keyframes fajarPreviewFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

/* ==========================================================================
   PRINT MEDIA RULES (ACTIVE DURING PRINTING & PDF GENERATION)
   ========================================================================== */
@media print {
  /* Page Geometry */
  @page {
    size: A4 portrait;
    margin: 12mm 15mm 15mm 15mm;
  }

  @page landscape-sheet {
    size: A4 landscape;
    margin: 10mm 12mm 12mm 12mm;
  }

  body.print-landscape {
    page: landscape-sheet;
  }

  /* 1. If Dedicated Report Container is active, strictly hide all normal application chrome */
  body.has-dedicated-print > *:not(#dedicated-report-container) {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    overflow: hidden !important;
  }

  /* Hide screen previews or helper overlays */
  .report-preview-overlay,
  .fajar-quick-print-fab {
    display: none !important;
  }

  /* 2. Dedicated Report Container Root Styling */
  body.has-dedicated-print #dedicated-report-container {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    background-color: #ffffff !important;
    background-image: none !important;
    color: #0f172a !important;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif !important;
    font-size: 9.5pt !important;
    line-height: 1.35 !important;
    opacity: 1 !important;
  }

  /* Force CSS custom variables to light contrast mode (Overrides any active dark mode) */
  #dedicated-report-container,
  #dedicated-report-container * {
    --background: 0 0% 100% !important;
    --foreground: 222.2 84% 4.9% !important;
    --card: 0 0% 100% !important;
    --card-foreground: 222.2 84% 4.9% !important;
    --muted: 210 40% 96.1% !important;
    --muted-foreground: 215.4 16.3% 46.9% !important;
    --border: 214.3 31.8% 91.4% !important;
    color: #0f172a !important;
    border-color: #cbd5e1 !important;
    text-shadow: none !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* 3. Global Screen UI Suppression */
  html aside,
  body aside,
  aside,
  header,
  nav,
  .sidebar,
  [data-sidebar],
  button:not(.allow-print),
  input,
  select,
  textarea,
  .print-actions,
  .toaster,
  .sonner,
  .sidebar-toggle-btn,
  [title*="sidebar"],
  [title*="Sidebar"],
  [title*="Collapse"],
  [title*="collapse"],
  [title*="Expand"],
  [title*="expand"],
  [role="dialog"] button,
  .print\:hidden,
  [data-tooltip] {
    display: none !important;
    visibility: hidden !important;
    position: absolute !important;
    top: -99999px !important;
    left: -99999px !important;
    width: 0 !important;
    height: 0 !important;
    max-width: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* Reset document canvas & eliminate all height/overflow clipping */
  html,
  body,
  #__next,
  .h-screen,
  div:has(> aside),
  div:has(> main) {
    background: #ffffff !important;
    background-color: #ffffff !important;
    background-image: none !important;
    color: #0f172a !important;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif !important;
    font-size: 9.5pt !important;
    line-height: 1.4 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
    box-shadow: none !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  main {
    background: #ffffff !important;
    background-image: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: auto !important;
    display: block !important;
    position: static !important;
  }

  /* Universal Container Cleanup for Print */
  div, section, article {
    overflow: visible !important;
    max-height: none !important;
  }

  /* Multi-page Data Table Engine */
  table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin: 10px 0 !important;
    page-break-inside: auto !important;
    font-size: 8.5pt !important;
  }

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

  tfoot {
    display: table-footer-group !important;
  }

  tr {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  th {
    background-color: #f1f5f9 !important;
    color: #0f172a !important;
    font-weight: 700 !important;
    border: 1px solid #94a3b8 !important;
    padding: 6px 8px !important;
    text-align: left !important;
    text-transform: uppercase !important;
    font-size: 7.5pt !important;
    letter-spacing: 0.03em !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  td {
    border: 1px solid #cbd5e1 !important;
    padding: 5px 8px !important;
    color: #1e293b !important;
    font-size: 8.5pt !important;
  }

  tr:nth-child(even) td {
    background-color: #f8fafc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  th.text-right, td.text-right, td[align="right"] {
    text-align: right !important;
  }

  th.text-center, td.text-center, td[align="center"] {
    text-align: center !important;
  }

  /* Financial Totals & Accounting Underlines */
  .report-total-row td,
  tr.bg-muted\/30 td,
  tr.font-bold td {
    font-weight: 700 !important;
    background-color: #f1f5f9 !important;
    border-top: 1.5px solid #475569 !important;
    border-bottom: 3px double #0f172a !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Monospace Currency Figures */
  .font-mono, td.text-right, .report-currency-val {
    font-family: 'Consolas', 'Courier New', monospace !important;
    font-size: 8.5pt !important;
    font-weight: 600 !important;
  }
}

/* ==========================================================================
   REPORT LAYOUT COMPONENTS (USED FOR BOTH PRINT & SCREEN PREVIEW)
   ========================================================================== */

/* Official Letterhead Header */
.report-letterhead {
  border-bottom: 2px solid #0f172a;
  padding-bottom: 12px;
  margin-bottom: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.report-letterhead-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.report-logo-box {
  width: 68px;
  height: 68px;
  border-radius: 8px;
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 4px;
  box-sizing: border-box;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.report-logo-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
}

.report-academy-title {
  font-size: 16pt;
  font-weight: 800;
  color: #0f172a !important;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.15;
}

.report-academy-sub {
  font-size: 8.5pt;
  font-weight: 700;
  color: #059669 !important;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.report-academy-contact {
  font-size: 8pt;
  color: #64748b !important;
  margin-top: 3px;
  line-height: 1.35;
}

.report-letterhead-right {
  text-align: right;
  font-size: 8pt;
  color: #475569 !important;
}

.report-badge-official {
  display: inline-block;
  background: #0f172a !important;
  color: #ffffff !important;
  font-size: 7.5pt;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

/* Report Title Banner */
.report-title-banner {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%) !important;
  color: #ffffff !important;
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.report-title-banner * {
  color: #ffffff !important;
}

.report-title-text {
  font-size: 13pt;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
}

.report-period-text {
  font-size: 8.5pt;
  font-weight: 500;
  opacity: 0.95;
  margin-top: 2px;
}

/* Metadata Grid */
.report-meta-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: #f8fafc !important;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
  font-size: 8pt;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.report-meta-item-label {
  color: #64748b !important;
  font-size: 7.5pt;
  text-transform: uppercase;
  font-weight: 600;
}

.report-meta-item-val {
  color: #0f172a !important;
  font-weight: 700;
  margin-top: 1px;
}

/* Filter Context Tag */
.report-filter-bar {
  background: #eff6ff !important;
  border: 1px solid #bfdbfe;
  border-left: 4px solid #2563eb;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 8pt;
  color: #1e3a8a !important;
  margin-bottom: 12px;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.report-filter-bar strong {
  color: #1e40af !important;
}

/* Executive Summary Box (Total Records, Total Amount, Paid, Outstanding) */
.report-summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.report-summary-card {
  background: #f8fafc !important;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 12px;
  text-align: left;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.report-summary-card.accent-emerald {
  border-top: 3px solid #10b981;
}

.report-summary-card.accent-blue {
  border-top: 3px solid #3b82f6;
}

.report-summary-card.accent-rose {
  border-top: 3px solid #f43f5e;
}

.report-summary-card.accent-purple {
  border-top: 3px solid #8b5cf6;
}

.report-summary-label {
  font-size: 7.5pt;
  font-weight: 600;
  color: #64748b !important;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.report-summary-val {
  font-size: 12pt;
  font-weight: 800;
  color: #0f172a !important;
  margin-top: 2px;
  font-family: 'Consolas', monospace;
}

.report-summary-sub {
  font-size: 7pt;
  color: #64748b !important;
  margin-top: 1px;
}

/* Status Badges */
.report-status-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 7pt;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.report-status-badge.status-paid,
.report-status-badge.status-active,
.report-status-badge.status-balanced {
  background: #d1fae5 !important;
  color: #065f46 !important;
  border: 1px solid #10b981;
}

.report-status-badge.status-unpaid,
.report-status-badge.status-overdue,
.report-status-badge.status-destructive {
  background: #fee2e2 !important;
  color: #991b1b !important;
  border: 1px solid #ef4444;
}

.report-status-badge.status-partial,
.report-status-badge.status-pending {
  background: #fef3c7 !important;
  color: #92400e !important;
  border: 1px solid #f59e0b;
}

.report-status-badge.status-default {
  background: #f1f5f9 !important;
  color: #475569 !important;
  border: 1px solid #cbd5e1;
}

/* Formal Signatures Block */
.report-signatures {
  margin-top: 32px;
  padding-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  text-align: center;
  page-break-inside: avoid !important;
  break-inside: avoid !important;
}

.report-signature-col {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.report-signature-line {
  width: 100%;
  max-width: 170px;
  border-top: 1.5px solid #0f172a;
  margin-bottom: 6px;
}

.report-signature-role {
  font-size: 8.5pt;
  font-weight: 700;
  color: #0f172a !important;
  text-transform: uppercase;
}

.report-signature-title {
  font-size: 7.5pt;
  color: #64748b !important;
}

/* Audit Footer */
.report-footer-audit {
  margin-top: 20px;
  padding-top: 8px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 7pt;
  color: #64748b !important;
  page-break-inside: avoid !important;
  break-inside: avoid !important;
}

/* Empty State Message */
.report-empty-state {
  padding: 30px;
  text-align: center;
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc !important;
  margin: 16px 0;
  color: #475569 !important;
}

.report-empty-title {
  font-size: 11pt;
  font-weight: 700;
  color: #0f172a !important;
  margin-bottom: 4px;
}

.report-empty-desc {
  font-size: 8.5pt;
  color: #64748b !important;
}
