/* =========================================================
   1. GLOBAL & SCREEN VIEW
   ========================================================= */
* { box-sizing: border-box; }
.vimas-print-footer { display: none; }

.card-box {
    width: 4.5in; height: 2.8in;
    border: 1px dashed #ccc;
    float: left; margin: 10px; padding: 0.15in;
    background: white; font-family: Arial, sans-serif;
    display: flex; flex-direction: column; overflow: hidden;
}

/* =========================================================
   2. SHARED PRINT RULES
   ========================================================= */
@media print {
    * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
    .print-logo { max-height: 70px; width: auto; visibility: visible !important; }
    
    .navbar, .sidebar, #sidebar-col-mgmt, .nav-tabs, .d-print-none, .btn {
        display: none !important; height: 0 !important; margin: 0 !important;
    }
}

/* =========================================================
   3. HUSBANDRY REPORTS (Fluid Landscape Fix)
   ========================================================= */
@page husbandry-landscape {
    size: letter landscape;
    margin: 0.4in;
}

@media print {
    body.print-mgmt { 
        page: husbandry-landscape !important; 
    }

    body.print-mgmt .navbar, 
    body.print-mgmt .sidebar, 
    body.print-mgmt #sidebar-col-mgmt,
    body.print-mgmt .nav-tabs,
    body.print-mgmt .d-print-none,
    body.print-mgmt .print-hide,
    body.print-mgmt .DateRangePicker,
    body.print-mgmt .DateRangePicker_picker, 
    body.print-mgmt .SingleDatePicker_picker, 
    body.print-mgmt .CalendarMonthGrid {     
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
    }

    body.print-mgmt #master-print-zone {
        display: block !important;
        position: absolute !important; 
        top: 0 !important;
        left: 0 !important;
        width: 100% !important; 
        visibility: visible !important;
        background-color: white !important;
    }

    body.print-mgmt #master-print-zone * {
        visibility: visible !important;
    }

    body.print-mgmt .room-report-page {
        height: auto !important;
        min-height: auto !important; 
        page-break-after: auto !important;
        break-after: auto !important; 
    }

    body.print-mgmt table {
        width: 100% !important;
        table-layout: auto !important;
        border: 2px solid black !important;
    }
    
    body.print-mgmt tr, 
    body.print-mgmt .card {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    body.print-mgmt #mgmt-report-area {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100vw !important;       
        max-width: 100vw !important; 
        margin: 0 !important;
        padding: 0 !important;
    }

    body.print-mgmt .room-report-page table {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: fixed !important; 
        font-size: 9px !important; 
    }

    body.print-mgmt .room-report-page table th,
    body.print-mgmt .room-report-page table td {
        white-space: normal !important;        /* Let it wrap naturally */
        word-wrap: break-word !important;      /* Force long words to break */
        word-break: break-all !important;      /* 💎 THE SQUISH FIX: Slice words if they don't fit */
        padding: 2px !important;               /* Shrink padding */
        font-size: 8px !important;             /* Slightly smaller font */
        text-align: center !important;
        vertical-align: middle !important;
    }
}

/* =========================================================
   5. CAGE CARDS (MULTI-FORMAT ROUTER)
   ========================================================= */

/* THE FIX: Hardcode the physical margins into the paper so they repeat on EVERY page */
@page laser-format { 
    size: letter landscape; 
    margin: 1.25in 0.5in !important; /* 1.25" top/bottom, 0.5" left/right */
}
@page avery-format { 
    size: letter portrait; 
    margin: 0.5in 0.25in !important; /* 0.5" top/bottom, 0.25" left/right */
}
@page thermal-format { 
    margin: 0.15in !important; 
}

@media print {
    /* 1. THE SLEDGEHAMMER: Hide UI ONLY when printing cards */
    body[class*="printing-cards-"] .dash-table-container, 
    body[class*="printing-cards-"] table, 
    body[class*="printing-cards-"] .Select, 
    body[class*="printing-cards-"] input, 
    body[class*="printing-cards-"] select,
    body[class*="printing-cards-"] .btn-lobby,
    body[class*="printing-cards-"] #fix-edit-card-container,
    body[class*="printing-cards-"] .cage-card-generator-inputs,
    body[class*="printing-cards-"] #printer-target-hardware-section,
    body[class*="printing-cards-"] .card, 
    body[class*="printing-cards-"] h5,
    body[class*="printing-cards-"] h6 {
        display: none !important;
        visibility: hidden !important;
    }

    body[class*="printing-cards-"] #printable-cards-container {
        position: absolute !important;
        top: 0 !important; left: 0 !important;
        background-color: white !important;
        z-index: 99999 !important;
        visibility: visible !important;
    }

    body[class*="printing-cards-"] .card-box {
        visibility: visible !important;
        page-break-inside: avoid !important;
        background-color: white !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
    }

    /* ---------------------------------------------------------
       FORMAT A: INNOVIVE 3x5 (4-up Landscape Laser)
       --------------------------------------------------------- */
    body.printing-cards-laser { page: laser-format !important; }

    body.printing-cards-laser #printable-cards-container {
        display: grid !important;
        grid-template-columns: 5in 5in !important;
        grid-auto-rows: 3in !important; 
        column-gap: 0 !important;
        row-gap: 0 !important;
        width: 10in !important; /* Exact width of 2 cards */
        margin: 0 !important;
        padding: 0 !important;
    }

    body.printing-cards-laser .card-box {
        width: 5in !important; 
        height: 3in !important;
        border: 1px dashed black !important;
        padding: 0.15in !important;
        margin: 0 !important;
    }

    /* ---------------------------------------------------------
       FORMAT B: AVERY 15264 (6-up Portrait)
       --------------------------------------------------------- */
    body.printing-cards-avery { page: avery-format !important; }

    body.printing-cards-avery #printable-cards-container {
        display: grid !important;
        grid-template-columns: 4in 4in !important;
        grid-auto-rows: 3.333in !important; 
        column-gap: 0 !important;
        row-gap: 0 !important;
        width: 8in !important; /* Exact width of 2 Avery cards */
        margin: 0 !important;
        padding: 0 !important;
    }

    body.printing-cards-avery .card-box {
        width: 4in !important; 
        height: 3.333in !important;
        /* Note: Kept the light border so you can see bounds, but you can change to 'border: none' if it bleeds off the sticker */
        border: 1px dashed #ccc !important;
        padding: 0.15in !important;
        margin: 0 !important;
    }

    /* ---------------------------------------------------------
       FORMAT C: ZEBRA/TECNIPLAST/ALLENTOWN (1-up Thermal Roll)
       --------------------------------------------------------- */
    body.printing-cards-tecniplast,
    body.printing-cards-allentown {
        page: thermal-format !important;
    }

    body.printing-cards-tecniplast #printable-cards-container,
    body.printing-cards-allentown #printable-cards-container {
        display: block !important; 
    }

    body.printing-cards-tecniplast .card-box,
    body.printing-cards-allentown .card-box {
        width: 5in !important;
        height: 3in !important;
        border: 2px solid black !important;
        padding: 0.15in !important;
        margin: 0 auto 0.2in auto !important; 
        page-break-after: always !important; 
    }
}

/* =========================================================
   6. THE NUCLEAR PRINT OVERRIDE (FOR AUDIT LOGS)
   ========================================================= */
@media print {
    body.printing-vimas-report #mgmt-report-area {
        display: block !important;
        position: absolute !important;
        left: 0 !important; top: 0 !important;
        width: 100% !important;
        visibility: visible !important;
    }

    .room-report-page {
        page-break-after: auto !important;
        break-after: auto !important;
        display: block !important;
    }
}

/* =========================================================
   7. AUDIT LOG SPECIFIC STYLING
   ========================================================= */
@media print {
    .print-audit {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        background-color: white !important;
        box-shadow: 0 0 0 5000px white !important; 
        z-index: 9999 !important;
        border: none !important;
    }
    
    .print-audit .print-hide {
        display: none !important;
    }

    .print-audit table {
        border-collapse: collapse !important;
        width: 100% !important;
    }
    
    .print-audit th, .print-audit td {
        border: 1px solid black !important;
        color: black !important;
    }
}

/* =========================================================
   FACILITY LOG PRINTING
   ========================================================= */
@media print {
    body.print-facility-log * {
        visibility: hidden;
    }
    body.print-facility-log .print-facility-log, 
    body.print-facility-log .print-facility-log * {
        visibility: visible;
    }
    body.print-facility-log .print-facility-log {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
}

/* Fixes contrast and gives a visual cue that it can be clicked */
.vet-deviation-alert {
    background-color: #d9534f; 
    color: #ffffff !important; 
    padding: 10px;
    border-radius: 5px;
    cursor: pointer; 
    transition: background-color 0.2s ease;
}

.vet-deviation-alert:hover {
    background-color: #c9302c; 
}

/* ==========================================================================
   VIMAS MANAGEMENT REPORT PRINTING (GLP SIGNATURE FIX)
   ========================================================================== */
@media print {
    body.print-mgmt #master-print-zone {
        padding-bottom: 40px !important; 
    }

    body.print-mgmt #standalone-report-output {
        display: none !important; 
    }

    body.print-mgmt #qa-verify-status-mgmt {
        display: block !important;
        visibility: visible !important;
        page-break-inside: avoid !important;
        margin-top: 30px !important;
    }

    body.print-mgmt .vimas-print-footer {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 100% !important;
        padding: 5px 20px !important;
        font-size: 11px !important;
        font-weight: bold !important;
        color: #000 !important;
        border-top: 2px solid #000 !important;
        background-color: white !important;
        display: flex !important;
        justify-content: space-between !important;
        z-index: 1000 !important;
    }
}

/* =========================================================
   SCIENTIFIC REPORTS (TECH REPORTS) PRINT ISOLATION
   ========================================================= */
@media print {
    #view-tech-reports .print-hide {
        display: none !important;
    }

    #tech-master-print-zone {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important; 
        padding: 0 !important;
        margin: 0 !important;
    }

    .dash-debug-menu, .dash-debug-alert {
        display: none !important;
    }
}

/* =========================================================
   8. DYMO TUBE LABEL PRINTING
   ========================================================= */
@page dymo-format { 
    size: 1.25in 0.5in; /* Forces the physical paper size in Chrome! */
    margin: 0; 
}

@media print {
    body.print-tubes {
        page: dymo-format !important; 
        background-color: white !important;
    }
    
    body.print-tubes * {
        visibility: hidden !important;
    }

    body.print-tubes #tube-label-print-zone,
    body.print-tubes #tube-label-print-zone * {
        visibility: visible !important;
    }

    body.print-tubes #tube-label-print-zone {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* =========================================================
   9. BATCH LABEL BOX FIX (2x1 Inch Hardware Dimensions)
   ========================================================= */
@media print {
    .print-label-box {
        width: 2in !important; 
        height: 1in !important;
        border: 1px solid black;
        padding: 0.1in;
        margin-bottom: 5px;
        page-break-after: always;
        font-family: Arial, sans-serif;
        font-size: 14px;
    }
}

/* ==========================================
   LIFETIME ANIMAL RECORD - STYLING ARMOR
   ========================================== */

/* 1. The Header Fix: Forces headers to stay on a single line */
#printable-area th { 
    white-space: nowrap !important; 
    padding: 10px; 
    background-color: #ecf0f1; 
}

/* 2. The Cell Alignment Fix: Keeps text cleanly at the top of the box */
#printable-area td { 
    vertical-align: top; 
    padding: 8px; 
    border: 1px solid #bdc3c7; 
}

/* 3. The Ghost Assassin: Completely hides Dash developer tools from the printer */
@media print {
    body { padding: 0; color: #000; }
    
    #dash-debug-menu, 
    .dash-debug-menu, 
    .dash-debug-alert { 
        display: none !important; 
    }
}

/* ========================================== */
/* VIMAS REPORT PRINT FORMATTING              */
/* ========================================== */
@media print {
    /* 1. Force the PDF to Landscape mode globally for these reports */
    @page {
        size: landscape;
        margin: 10mm;
    }

    /* 2. Namespace Isolation: Only target the report wrapper */
    .print-report-layout {
        display: block !important;
        overflow: visible !important;
        page-break-inside: auto !important;
    }
    
    /* 3. Strip away web scrolling/flexbox that confuses the printer */
    .print-report-layout .card,
    .print-report-layout .card-body,
    .print-report-layout .table-responsive,
    .print-report-layout .container-fluid {
        display: block !important;
        overflow: visible !important;
        page-break-inside: auto !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
    }

    /* 4. Tell the browser NEVER to page-break right after the header */
    .print-report-layout h2, 
    .print-report-layout h3, 
    .print-report-layout h4,
    .print-report-layout h5,
    .print-report-layout .border-bottom {
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
    }

    /* 5. 💎 THE NIGHTMARE FIX: Force the grid to calculate fixed widths */
    .print-report-layout table {
        page-break-inside: auto !important;
        table-layout: fixed !important;
        width: 100% !important;
        border-collapse: collapse !important;
    }

    /* 6. 💎 THE SQUISH FIX: Force text to wrap cleanly instead of overlapping */
    .print-report-layout td, 
    .print-report-layout th {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
        white-space: normal !important;
        font-size: 8pt !important; /* Shrink font slightly to fit 25 columns */
        padding: 4px !important;
    }

    /* 7. Keep rows intact so text isn't sliced in half horizontally */
    .print-report-layout tr {
        page-break-inside: avoid !important;
        page-break-after: auto !important;
    }
    
    /* 8. Repeat table headers at the top of every printed page */
    .print-report-layout thead {
        display: table-header-group !important;
    }
}

/* ========================================= */
/* ENTERPRISE PRINT AUTO-FORMATTER           */
/* ========================================= */
@media print {
    /* 1. Automatically apply the 90% scale the user liked */
    body {
        zoom: 90%; 
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* 2. Tighten the physical paper margins so more data fits */
    @page {
        margin: 0.5in; 
    }

    /* 3. Strip out any wasteful Bootstrap margins from the tables */
    .table {
        margin-bottom: 0 !important;
    }
}

/* =========================================================
   9. ZEBRA FORMALIN LABEL PRINTING (2in x 1in)
   ========================================================= */
@page zebra-format { 
    size: 2in 1in; 
    margin: 0; 
}

@media print {
    /* 1. Force the physical paper size */
    body.print-zebra {
        page: zebra-format !important; 
        background-color: white !important;
    }
    
    /* 2. Hide everything on the entire app */
    body.print-zebra * {
        visibility: hidden !important;
    }

    /* 3. Wake up ONLY the print zone container and its children */
    body.print-zebra #hidden-label-print-zone,
    body.print-zebra #hidden-label-print-zone * {
        visibility: visible !important;
    }

    /* 4. Anchor the master container to the top left */
    body.print-zebra #hidden-label-print-zone {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* 5. 💎 THE FIX: Format the individual labels to split onto new stickers */
    .zebra-label {
        width: 2in !important;
        height: 1in !important;
        padding: 0.1in !important;
        page-break-after: always !important; /* Forces the Zebra to roll to the next sticker */
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        font-family: Arial, sans-serif !important;
        box-sizing: border-box !important;
        /* Optional: border: 1px dashed #ccc; (Remove if printing to actual Zebra roll) */
    }

    /* Typography sizing for the label */
    .zebra-label .z-id { font-size: 11px !important; font-weight: bold; }
    .zebra-label .z-tissue { font-size: 13px !important; font-weight: 900; text-transform: uppercase; margin: 2px 0; }
    .zebra-label .z-date { font-size: 9px !important; }
}

/* =========================================================
   10. CHAIN OF CUSTODY MANIFEST (8.5x11 Portrait)
   ========================================================= */
@page manifest-format { 
    size: letter portrait; 
    margin: 0.5in; 
}

@media print {
    body.print-manifest {
        page: manifest-format !important; 
        background-color: white !important;
    }
    
    body.print-manifest * { visibility: hidden !important; }

    body.print-manifest #hidden-manifest-print-zone,
    body.print-manifest #hidden-manifest-print-zone * {
        visibility: visible !important;
    }

    body.print-manifest #hidden-manifest-print-zone {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Make the table text black for standard laser printers */
    body.print-manifest table { color: black !important; }
    body.print-manifest .table-dark th { 
        background-color: #ddd !important; 
        color: black !important; 
        -webkit-print-color-adjust: exact !important; 
        print-color-adjust: exact !important; /* 💎 ADDED TO CLEAR THE ERROR */
    }
}

/* =========================================
   GLP PRINT ISOLATION: INVESTIGATOR PORTAL
   ========================================= */
@media print {
    /* 💎 THE FIX: Properly namespaced so it ONLY hides things when this specific class is active! */
    body.print-investigator-report * {
        visibility: hidden;
    }

    body.print-investigator-report .print-investigator-report, 
    body.print-investigator-report .print-investigator-report * {
        visibility: visible;
    }

    body.print-investigator-report .print-investigator-report {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
    }

    body.print-investigator-report .btn, 
    body.print-investigator-report .form-control {
        display: none !important;
    }
}

/* =======================================================
   VET HQ: OFFICIAL REPORTS PRINT REVEAL
   ======================================================= */

/* 1. Force the Master Log and Lifetime Record to become visible */
body.print-vet #patient-history-output,
body.print-vet #patient-history-output *,
body.print-vet #lifetime-record-display-area,
body.print-vet #lifetime-record-display-area * {
    visibility: visible !important;
}

/* 2. Flow naturally so multi-page tables do not get cut off or blank out */
body.print-vet #patient-history-output,
body.print-vet #lifetime-record-display-area {
    position: relative !important;
    width: 100% !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
}

@media print {
    /* Hide global navigation and sidebars so they don't waste paper */
    .sidebar, .navbar, .nav-tabs {
        display: none !important;
    }

    /* Expand the archive zone to take up the full printed page */
    .print-archive-zone {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* Hide the buttons inside the print zone (we don't need buttons on a piece of paper) */
    #btn-open-bulk-dispo, #btn-print-archive, #btn-export-archive {
        display: none !important;
    }
}

.hidden-timeout-btn {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
}