/* ==========================================================================
   KITAB 9 IMAM - DEDICATED PRINT STYLESHEET
   Guaranteed Fixed Bottom Footer (All Pages & Last Page)
   Automatic Page Breaks for New Kitab Transitions
   ========================================================================== */

@page {
  size: A4 portrait;
  margin: 14mm 14mm 18mm 14mm; /* Bottom margin reserves room for fixed footer */
}

@media print {
  /* 1. Reset all decorative shadows, filters, outlines */
  *, *::before, *::after {
    box-shadow: none !important;
    text-shadow: none !important;
    filter: none !important;
    -webkit-box-shadow: none !important;
  }

  /* 2. Hide non-printable UI elements */
  .no-print,
  .app-header,
  .app-sidebar-right,
  .app-config-drawer,
  .workspace-toolbar,
  .toast-container,
  .loading-overlay,
  button,
  input,
  select {
    display: none !important;
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    height: auto !important;
    overflow: visible !important;
    width: 100% !important;
    font-size: 12pt !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .app-container,
  .app-main,
  .app-workspace,
  .preview-canvas-container,
  #previewCanvas,
  .document-wysiwyg-canvas,
  .document-content-column {
    display: block !important;
    position: static !important;
    overflow: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  /* 3. Section Container & Page Breaks for New Kitab */
  .kitab-section-container {
    display: block !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    background: transparent !important;
    color: #000000 !important;
  }

  /* Lompat ke halaman baru ketika masuk kitab berikutnya */
  .kitab-section-container.new-kitab-page,
  table.print-document-table.new-kitab-page,
  .new-kitab-page {
    page-break-before: always !important;
    break-before: page !important;
  }

  /* =======================================================================
     4. TABLE ARCHITECTURE
     - thead: repeating header at the top of every page
     - tfoot: INVISIBLE spacer that reserves bottom space on every page
              so content never overlaps the fixed footer
     - position:fixed footer: the VISIBLE footer, pinned to the absolute
              bottom of every printed sheet including the last page
     ======================================================================= */
  table.print-document-table {
    display: table !important;
    width: 100% !important;
    border-collapse: collapse !important;
    border: none !important;
    background: transparent !important;
  }

  /* THEAD: Repeating header at top of every page */
  thead.print-repeating-header {
    display: table-header-group !important;
  }

  /* TFOOT: Invisible height spacer (reserves 12mm so text never hits the footer) */
  tfoot.print-repeating-footer {
    display: table-footer-group !important;
  }

  tfoot.print-repeating-footer td {
    height: 12mm !important;
    padding: 0 !important;
    border: none !important;
    vertical-align: top !important;
  }

  tfoot.print-repeating-footer .sheet-footer {
    visibility: hidden !important;
    height: 12mm !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  tbody.print-content-body {
    display: table-row-group !important;
  }

  .print-repeating-header td,
  .print-content-td {
    padding: 0 !important;
    border: none !important;
    vertical-align: top !important;
  }

  /* 5. Running Page Header (inside thead) */
  .running-page-header {
    display: flex !important;
    justify-content: flex-start !important;
    text-align: right !important;
    border-bottom: 1.5px solid #000000 !important;
    color: #000000 !important;
    font-size: 11pt !important;
    padding-bottom: 2.5mm !important;
    margin-bottom: 4mm !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    width: 100% !important;
  }

  .running-book-title,
  .running-chapter-title {
    color: #000000 !important;
    font-weight: 700 !important;
  }

  .running-sep {
    color: #000000 !important;
  }

  /* =======================================================================
     6. FIXED BOTTOM FOOTER — GUARANTEED AT THE BOTTOM OF EVERY PAGE & LAST PAGE
     position:fixed in @media print pins the element to the bottom edge
     on EVERY printed sheet, including partially-filled last pages.
     ======================================================================= */
  .print-fixed-page-footer {
    display: block !important;
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    border-top: 1.5px solid #000000 !important;
    padding-top: 2.5mm !important;
    margin: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 9.5pt !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    z-index: 99999 !important;
  }

  .print-fixed-page-footer .sheet-footer-left {
    color: #000000 !important;
    font-weight: 600 !important;
  }

  /* 7. Doc Header (Judul Utama Kitab di Awal) */
  .doc-header {
    border-bottom: none !important;
    margin-bottom: 4mm !important;
    padding-bottom: 0 !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
    text-align: center !important;
  }

  .book-title-arabic {
    color: #000000 !important;
    font-size: 18pt !important;
    text-align: center !important;
  }

  /* 8. Sub-Bab Header */
  .sub-bab-header-box {
    page-break-after: avoid !important;
    break-after: avoid !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    margin: 4mm 0 2mm !important;
    padding: 0 !important;
    text-align: center !important;
  }

  .sub-bab-title-arabic,
  .sub-bab-title-arabic .achapno,
  .sub-bab-title-arabic .arabicchapter {
    color: #000000 !important;
    font-size: 13.5pt !important;
    text-align: center !important;
  }

  .achapintro {
    color: #000000 !important;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin-top: 1.5mm !important;
    font-size: 11pt !important;
    page-break-after: avoid !important;
    break-after: avoid !important;
    text-align: center !important;
  }

  /* 9. Hadith Items */
  .hadith-item {
    page-break-inside: auto !important;
    break-inside: auto !important;
    margin-bottom: 3mm !important;
  }

  .hadith-word-layout {
    display: flex !important;
    flex-direction: row !important;
  }

  .arabic-text {
    color: #000000 !important;
    text-align: justify !important;
    text-justify: inter-word !important;
    orphans: 2 !important;
    widows: 2 !important;
  }

  .hadith-num-gutter,
  .hadith-num-gutter .num-badge,
  .hadith-inline-num {
    color: #000000 !important;
    background: transparent !important;
    border: none !important;
  }
}
