/* ==========================================================================
   PRODUCTION PRINT SYSTEM STYLESHEET (HAJJ OS)
   Ensures 100% UI isolation and exact physical dimensions for all documents:
   1. Haji ID Card (CR80 Standard: 85.6mm x 54mm)
   2. Luggage Tag (194mm x 66mm, Foldable, 4 per A4 sheet)
   3. Hotel Voucher (ISO A4 Portrait: 194mm x 275mm)
   4. Rooming Allocation Slip (194mm x 132mm, 2 per A4 sheet)
   5. Bus Boarding Manifest (ISO A4 with repeating thead)
   ========================================================================== */

/* 1. SCREEN DISPLAY RULES: Hide dedicated print portal on screen */
@media screen {
  #print-root {
    display: none !important;
  }
}

/* 2. PRINT ENGINE RULES */
@media print {
  /* Universal Color & Background Fidelity */
  *,
  *::before,
  *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: 'Hind Siliguri', 'Noto Sans Bengali', 'SolaimanLipi', 'Kalpurush', 'Nirmala UI', sans-serif !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }

  /* -------------------------------------------------------------
     A. PORTAL ISOLATION (When PrintPortal is active)
     Completely eliminates the entire application (#root) from the
     print render tree. Zero sidebar, zero header, zero layout drift!
     ------------------------------------------------------------- */
  body.has-print-portal #root {
    display: none !important;
  }

  body.has-print-portal #print-root {
    display: block !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    overflow: visible !important;
  }

  /* -------------------------------------------------------------
     B. FALLBACK ISOLATION (For non-portal print triggers)
     Ensures sidebars and headers never leak even if printed directly
     ------------------------------------------------------------- */
  body:not(.has-print-portal) header,
  body:not(.has-print-portal) nav,
  body:not(.has-print-portal) aside,
  body:not(.has-print-portal) .sidebar,
  body:not(.has-print-portal) .no-print,
  body:not(.has-print-portal) [role="navigation"] {
    display: none !important;
  }

  body:not(.has-print-portal) main {
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    width: 100% !important;
  }

  .no-print {
    display: none !important;
  }

  /* -------------------------------------------------------------
     C. PAGE BREAK CONTROL UTILITIES
     ------------------------------------------------------------- */
  .print-page-break {
    break-after: page !important;
    page-break-after: always !important;
  }

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

  .print-avoid-break,
  .cr80-card,
  .luggage-tag,
  .rooming-slip,
  .table-row-avoid-break tr,
  .print-card-item {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* -------------------------------------------------------------
     D. DOCUMENT TYPE 1: HAJI ID CARD (CR80: 85.6mm x 54mm)
     ------------------------------------------------------------- */
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  /* Single ID Card view: Cleanly centered card pair */
  .print-doc-id_card .cr80-single-wrapper {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8mm !important;
    justify-content: center !important;
    align-items: center !important;
    margin: 20mm auto !important;
  }

  /* Bulk ID Cards: Exact 2x4 Badge Sheet Grid (8 cards per A4 page) */
  .print-doc-id_card .cr80-bulk-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 85.6mm) !important;
    gap: 6mm 10mm !important;
    justify-content: center !important;
    margin: 0 auto !important;
    page-break-inside: auto !important;
  }

  .print-doc-id_card .cr80-card {
    width: 85.6mm !important;
    min-width: 85.6mm !important;
    max-width: 85.6mm !important;
    height: 54mm !important;
    min-height: 54mm !important;
    max-height: 54mm !important;
    box-sizing: border-box !important;
    border: 1px solid #94a3b8 !important;
    box-shadow: none !important;
    border-radius: 3.18mm !important; /* CR80 rounded corners */
    overflow: hidden !important;
  }

  /* -------------------------------------------------------------
     E. DOCUMENT TYPE 2: LUGGAGE TAG (194mm x 66mm Foldable)
     Exact dimensions so 4 tags fit on an A4 sheet without spilling
     ------------------------------------------------------------- */
  .print-doc-luggage_tag {
    width: 100% !important;
    max-width: 194mm !important;
    margin: 0 auto !important;
  }

  .print-doc-luggage_tag .luggage-tag-container {
    padding: 0 !important;
    margin: 0 auto !important;
  }

  .print-doc-luggage_tag .luggage-tag {
    width: 194mm !important;
    min-width: 194mm !important;
    max-width: 194mm !important;
    height: 66mm !important;
    min-height: 66mm !important;
    max-height: 66mm !important;
    box-sizing: border-box !important;
    margin: 0 auto 4mm auto !important;
    box-shadow: none !important;
    border: 2px dashed #475569 !important;
    border-radius: 8px !important;
    overflow: hidden !important;
  }

  .print-doc-luggage_tag .luggage-tag:last-child {
    margin-bottom: 0 !important;
  }

  /* -------------------------------------------------------------
     F. DOCUMENT TYPE 3: HOTEL VOUCHER (ISO A4 Portrait)
     ------------------------------------------------------------- */
  .print-doc-hotel_voucher {
    width: 100% !important;
    max-width: 194mm !important;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  .print-doc-hotel_voucher .hotel-voucher-container {
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-doc-hotel_voucher .a4-page {
    width: 100% !important;
    max-width: 194mm !important;
    min-height: 275mm !important;
    box-sizing: border-box !important;
    padding: 6mm 8mm !important;
    margin: 0 auto !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* -------------------------------------------------------------
     G. DOCUMENT TYPE 4: ROOMING ALLOCATION SLIP (A5 / 2 per A4)
     ------------------------------------------------------------- */
  .print-doc-rooming_slip {
    width: 100% !important;
    max-width: 194mm !important;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  .print-doc-rooming_slip .rooming-slip-container {
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-doc-rooming_slip .rooming-slip {
    width: 194mm !important;
    min-width: 194mm !important;
    max-width: 194mm !important;
    min-height: 130mm !important;
    box-sizing: border-box !important;
    padding: 6mm 8mm !important;
    margin: 0 auto 6mm auto !important;
    border: 1px solid #cbd5e1 !important;
    box-shadow: none !important;
    border-radius: 8px !important;
  }

  .print-doc-rooming_slip .rooming-slip:last-child {
    margin-bottom: 0 !important;
  }

  /* -------------------------------------------------------------
     H. DOCUMENT TYPE 5: BUS BOARDING MANIFEST (ISO A4 Table)
     ------------------------------------------------------------- */
  .print-doc-bus_manifest {
    width: 100% !important;
    max-width: 194mm !important;
    margin: 0 auto !important;
    padding: 0 !important;
  }

  .print-doc-bus_manifest .bus-manifest-container {
    padding: 0 !important;
    margin: 0 !important;
  }

  .print-doc-bus_manifest .a4-page {
    width: 100% !important;
    max-width: 194mm !important;
    min-height: 275mm !important;
    box-sizing: border-box !important;
    padding: 6mm 8mm !important;
    margin: 0 auto !important;
    border: none !important;
    box-shadow: none !important;
  }

  .print-doc-bus_manifest table thead {
    display: table-header-group !important;
  }

  .print-doc-bus_manifest table tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
}
