/* 
===========================================
PRINT STYLES - Extracted from all stylesheets
===========================================
*/

@media print {
  /* Base print styles from styles.css */
  body {
    margin: 0;
    padding: 0;
    font-size: 14px;
    line-height: 1.6;
  }

  .container {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
  }

  .card {
    border: none;
    box-shadow: none;
    page-break-inside: avoid;
  }

  .card-header, .card-body {
    padding: 5px;
  }

  .row {
    display: flex;
    flex-wrap: wrap;
  }

  .col-12, .col-md-4, .col-md-6, .col-md-8 {
    flex: 1 0 100%;
    max-width: 100%;
  }

  .text-center {
    text-align: center;
  }

  img {
    max-width: 100%;
    height: auto;
  }

  .btn, .navbar, footer, .breadcrumb, .mobile-bottom-nav {
    display: none !important;
  }

  @page {
    size: A4 portrait;
    margin: 5mm;
  }

  .container::before {
    content: none;
  }

  .table-responsive-custom {
    overflow-x: visible !important;
    width: 100% !important;
  }

  #print-area {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .container, .row, .col-md-12 {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Patient detail print styles from patient_detail.css */
  .page-patient-detail {
    /* Base print setup */
    @page {
      size: A4 portrait;
      margin: 10mm;
    }

    .header-logos-container {
      margin-bottom: 0.5rem;
      padding: 0;
    }

    .header-logo {
      width: 70px;
      height: 70px;
    }

    .header-title h2 {
      font-size: 1.2rem;
    }

    .bg-primary {
      background-color: transparent !important;
    }

    .bg-primary.text-white,
    .bg-primary .text-white {
      color: #000 !important;
    }

    /* Patient main info layout */
    .patient-detail-section .row.patient-main-info {
      display: flex !important;
      align-items: stretch !important;
      flex-wrap: nowrap !important;
    }

    .patient-detail-section .row.patient-main-info > .col-md-6 > div {
      page-break-inside: avoid;
    }

    .patient-detail-section .row.patient-main-info > .col-md-6.d-flex > .p-3.rounded.border.bg-light.flex-fill {
      height: auto !important;
      min-height: 120px !important;
      max-height: 180px !important;
      box-sizing: border-box !important;
    }

    /* Column layouts in print */
    .patient-detail-section .row.mb-4 > .col-md-6,
    .patient-detail-section .row.print-medical-follow_ups > .col-12.col-md-6,
    .patient-detail-section .row.print-medical-comments > .col-12,
    .patient-detail-section .row.print-medical-comments > .col-md-6 {
      width: 50% !important;
      max-width: 50% !important;
      flex: 0 0 50% !important;
      box-sizing: border-box;
      page-break-inside: avoid !important;
      page-break-before: auto !important;
      page-break-after: auto !important;
    }

    /* Row layouts */
    .patient-detail-section .row.mb-4 {
      display: block !important;
      width: 100% !important;
      page-break-inside: avoid !important;
      page-break-before: auto !important;
      page-break-after: auto !important;
    }

    .patient-detail-section .row.print-medical-follow_ups,
    .patient-detail-section .row.print-medical-comments {
      display: flex !important;
      flex-wrap: nowrap !important;
      width: 100% !important;
      page-break-inside: avoid !important;
    }

    /* Additional patient detail print spacing tweaks */
    .patient-detail-section .row.print-medical-follow_ups > .col-12.col-md-6 {
      padding-left: 15px;
      padding-right: 15px;
    }

    .patient-detail-section .row.print-medical-comments > .col-12,
    .patient-detail-section .row.print-medical-comments > .col-md-6 {
      display: block !important;
      float: none !important;
      margin: 0 !important;
      padding: 0 8px !important;
    }

    .patient-detail-section .p-3.rounded.border.bg-light {
      padding: 10px !important;
      border: 1px solid #ddd !important;
      background-color: #fff !important;
      box-shadow: none !important;
    }

    .patient-detail-section h5.text-primary {
      margin-top: 0 !important;
      margin-bottom: 0.5rem !important;
    }

    .patient-detail-section .row.patient-main-info,
    .patient-detail-section .row.print-medical-follow_ups {
      margin-bottom: 1rem !important;
    }

    .patient-detail-section ul.list-unstyled li {
      margin-bottom: 0.25rem !important;
    }

    .patient-detail-section > .card {
      padding: 0 !important;
      margin: 0 !important;
      border: none !important;
      box-shadow: none !important;
    }

    .patient-detail-section .card-body {
      padding: 10px !important;
    }
  }

  /* Operation List Print Styles */
  .page-or-list-detail {
    .pdf-print-area {
      width: 210mm;
      min-width: 210mm;
      max-width: 210mm;
      margin: 0 auto;
      padding: 0;
      background: #fff;
      box-sizing: border-box;
    }

    .pdf-print-area * {
      box-sizing: border-box;
    }

    .pdf-print-area .table-responsive-custom {
      overflow-x: unset;
    }

    .pdf-print-area .table {
      width: 100%;
      min-width: 0;
      table-layout: fixed;
      font-size: 0.85em;
      margin-bottom: 0;
      page-break-inside: avoid;
    }

    .pdf-print-area th,
    .pdf-print-area td {
      word-break: break-word;
      white-space: normal;
      padding: 0.3em 0.2em;
      vertical-align: middle;
      page-break-inside: avoid;
    }

    .pdf-print-area h5 {
      font-size: 1em;
      margin-bottom: 0.2em;
    }

    .pdf-print-area h4 {
      font-size: 1.1em;
      margin-top: 0.2em;
      margin-bottom: 0.5em;
    }

    .pdf-print-area .mt-4 {
      margin-top: 0.5rem !important;
    }

    #print-area {
      page-break-after: avoid;
      page-break-before: avoid;
      page-break-inside: avoid;
    }

    #print-area .logo-wrapper {
      width: 90px;
      height: 70px;
    }

    #print-area .header-logo {
      height: 70px;
      max-width: 90px;
    }

    #print-area .footer-signature {
      font-size: 1.1em;
      font-weight: 500;
      margin-top: 0.5rem !important;
      text-align: right;
    }

    #print-area .footer-text {
      line-height: 1.4;
      text-align: right;
      unicode-bidi: bidi-override;
      padding-right: 5px;
      font-family: 'Arial', 'Tahoma', sans-serif;
    }
  }
}

/* iOS/Safari Print Fixes for Navbar Bleed */
@media print {
  /* Force hide navbar and related elements with high specificity */
  nav.navbar,
  .navbar,
  #navbarNav,
  .navbar-collapse,
  .mobile-bottom-nav,
  .navbar-and-status-bar-wrapper {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    position: static !important; /* Override fixed positioning */
    z-index: -1 !important;
    overflow: hidden !important;
  }

  /* Hide iOS-specific status bar overlays and pseudo-elements */
  @supports (-webkit-touch-callout: none) {
    body::before,
    body::after,
    .navbar-and-status-bar-wrapper,
    [style*="env(safe-area-inset-top)"] {
      display: none !important;
      visibility: hidden !important;
      height: 0 !important;
      background: transparent !important;
      position: static !important;
    }

    /* Reset any iOS meta theme-color bleed */
    :root {
      --navbar-color: transparent !important;
    }
  }

  /* Additional Safari-specific overrides */
  @media print and (-webkit-min-device-pixel-ratio: 0) {
    .navbar,
    .mobile-nav-toggle,
    .user-profile-container {
      display: none !important;
      -webkit-print-color-adjust: exact; /* Force color discard in Safari */
      print-color-adjust: exact; /* Standard property for compatibility */
    }
  }

  /* Ensure body has no top padding from hidden navbar */
  body {
    padding-top: 0 !important;
    margin-top: 0 !important;
  }
}


@media print {
  .data-group.medications-table-group label {
    text-align: left !important;
    margin-left: 0 !important;
    width: auto !important;
    display: block !important;
    align-self: flex-start !important;
  }
}

/* ===========================================
   iPhone/Safari Print Rendering Fixes
   ===========================================
   Comprehensive fixes for Safari/WebKit print rendering issues
   Ensures consistent print output across all pages
   =========================================== */

@media print {
  /* Safari/WebKit specific fixes */
  @supports (-webkit-touch-callout: none) {
    /* Reset all transforms and transitions that can break print layout */
    *,
    *::before,
    *::after {
      transform: none !important;
      transition: none !important;
      animation: none !important;
      -webkit-transform: none !important;
      -webkit-transition: none !important;
      -webkit-animation: none !important;
    }

    /* Fix fixed/absolute positioning issues */
    body,
    html {
      position: relative !important;
      overflow: visible !important;
      height: auto !important;
      min-height: auto !important;
      max-height: none !important;
    }

    /* Ensure all containers use static positioning */
    .container,
    .container-fluid,
    .row,
    .col,
    [class*="col-"],
    .card,
    .card-body,
    .card-header,
    .print-container,
    .patient-detail-section,
    .patient-detail-main {
      position: static !important;
      transform: none !important;
      -webkit-transform: none !important;
      will-change: auto !important;
    }

    /* Fix flexbox rendering in Safari print */
    .d-flex,
    [class*="flex"],
    .row {
      display: flex !important;
      flex-wrap: wrap !important;
      -webkit-flex-wrap: wrap !important;
    }

    /* Fix grid layout issues */
    [class*="grid"] {
      display: grid !important;
    }

    /* Ensure proper width calculations */
    * {
      box-sizing: border-box !important;
      -webkit-box-sizing: border-box !important;
    }

    /* Fix viewport units that don't work in print */
    [style*="vh"],
    [style*="vw"],
    [style*="vmin"],
    [style*="vmax"] {
      width: auto !important;
      height: auto !important;
      max-width: 100% !important;
      max-height: none !important;
    }

    /* Fix page break issues in Safari */
    .page-break-before,
    .page-break-after,
    .page-break-inside-avoid {
      page-break-before: auto !important;
      page-break-after: auto !important;
      page-break-inside: avoid !important;
      break-inside: avoid !important;
      -webkit-break-inside: avoid !important;
    }

    /* Fix column layout rendering */
    [style*="column"],
    [class*="column"] {
      column-count: auto !important;
      -webkit-column-count: auto !important;
    }

    /* Ensure proper color rendering */
    * {
      -webkit-print-color-adjust: exact !important;
      print-color-adjust: exact !important;
    }

    /* Fix overflow issues */
    * {
      overflow: visible !important;
      overflow-x: visible !important;
      overflow-y: visible !important;
    }

    /* Reset z-index stacking */
    * {
      z-index: auto !important;
    }

    /* Fix background rendering */
    body,
    html,
    .container,
    .card,
    .card-body {
      background: white !important;
      background-color: white !important;
      background-image: none !important;
    }

    /* Ensure images render correctly */
    img {
      max-width: 100% !important;
      height: auto !important;
      object-fit: contain !important;
      -webkit-print-color-adjust: exact !important;
      print-color-adjust: exact !important;
    }

    /* Fix table rendering */
    table {
      border-collapse: collapse !important;
      width: 100% !important;
      table-layout: auto !important;
    }

    /* Fix text rendering */
    * {
      text-rendering: optimizeLegibility !important;
      -webkit-font-smoothing: antialiased !important;
      -moz-osx-font-smoothing: grayscale !important;
    }
  }

  /* Additional WebKit-specific fixes */
  @media print and (-webkit-min-device-pixel-ratio: 0) {
    /* Force proper layout calculation */
    body {
      -webkit-print-color-adjust: exact !important;
      print-color-adjust: exact !important;
    }

    /* Fix patient detail specific issues */
    .patient-detail-main,
    .patient-detail-section,
    .print-container {
      position: static !important;
      transform: none !important;
      -webkit-transform: none !important;
      width: 100% !important;
      max-width: 100% !important;
      margin: 0 !important;
      padding: 0 !important;
    }

    /* Fix card layouts */
    .card,
    .card-body,
    .card-header {
      position: static !important;
      transform: none !important;
      page-break-inside: avoid !important;
      break-inside: avoid !important;
    }

    /* Fix data groups and flex containers */
    .data-group,
    .d-flex,
    [class*="flex"] {
      display: flex !important;
      flex-wrap: wrap !important;
      position: static !important;
      transform: none !important;
    }

    /* Ensure proper spacing */
    .mb-4,
    .mb-3,
    .mb-2,
    .mt-4,
    .mt-3,
    .mt-2 {
      margin-top: 0 !important;
      margin-bottom: 0.5rem !important;
    }

    /* Fix header layouts */
    .page-header-custom,
    .card-header {
      position: static !important;
      transform: none !important;
      display: block !important;
    }

    /* Fix two-column layouts in patient detail pages */
    .patient-detail-main > .card-body {
      column-count: 2 !important;
      -webkit-column-count: 2 !important;
      column-gap: 10mm !important;
      -webkit-column-gap: 10mm !important;
      column-rule: none !important;
      -webkit-column-rule: none !important;
      position: static !important;
      transform: none !important;
    }

    /* Ensure cards don't break across columns incorrectly */
    .patient-detail-main > .card-body > .card {
      break-inside: avoid !important;
      -webkit-break-inside: avoid !important;
      page-break-inside: avoid !important;
      position: static !important;
      transform: none !important;
    }

    /* Fix flex containers in print */
    .d-flex,
    .flex-row,
    .flex-column,
    [class*="flex"] {
      display: flex !important;
      position: static !important;
      transform: none !important;
    }

    /* Fix data groups alignment */
    .data-group {
      display: flex !important;
      align-items: center !important;
      position: static !important;
      transform: none !important;
    }
  }
}