/*
 * Print stylesheet (UI optimization plan, Phase 4 step 7). Loaded with media="print" by Element/stylesheets.ctp, so
 * nothing here affects the screen. People print with Ctrl+P (there is no print button); invoices themselves are
 * PDFs generated on the server and don't use this.
 *
 * Goal: a list, report or record prints as its content only - no header, menu, toolbars or filter controls - with
 * scroll boxes expanded so nothing is cut off, and tables readable on paper.
 */

@page {
    margin: 12mm 10mm;
}

/* ---------- 1. App chrome ---------- */

#m_header,
.m-header,
.app-subheader,
.m-footer,
#m_scroll_top,
.modal,
.modal-backdrop,
.tooltip,
.popover {
    display: none !important;
}

/* The fixed header leaves room above the content; reclaim it. The layout also stretches a grey body to the full
   window height, which would print as a grey panel. */
.m-body,
.m-header--fixed .m-body {
    padding-top: 0 !important;
}

.m-page,
.m-body,
.m-wrapper,
.m-content--skin-light2 .m-body {
    min-height: 0 !important;
    height: auto !important;
    background: #ffffff !important;
}

.m-content.common-wrapper {
    padding: 0 !important;
}

/* ---------- 2. On-screen controls ---------- */

.form-top-action,                       /* add/edit toolbars (ui/record_toolbar) */
.m-portlet__head .m-portlet__nav,       /* list header tools: counters, Add/Import/Export, Advance Search, list tabs */
.list-counter,
.nav-tabs,                              /* record tabs and report tab-navs; the active pane still prints */
.list-filter-icon,                      /* column filter funnels (ui/column_filter) ... */
.m-dropdown__wrapper,                   /* ... and every dropdown panel */
.multiple-record-action-box,            /* bulk bars (ui/bulk_actions) */
.m-datatable__pager-nav,                /* pagination buttons; "Displaying x - y of z" stays */
.m-datatable .m-datatable__limit-control,  /* legacy.css forces this one to display: flex !important at (0,2,0) */
.btn:not(.bootstrap-select > .btn),     /* buttons and button-like links, except the one bootstrap-select shows a field's value in */
.clear_search_data,
.app-import,
.m-accordion__item-head,                /* record header's collapse arrow */
.mCSB_scrollTools,                      /* custom scrollbar rails */
.dropdown-menu,
.bootstrap-select .dropdown-toggle .bs-caret {
    display: none !important;
}

/* The select arrow is drawn as a pseudo-element on the toggle; on paper it overlaps the value */
.bootstrap-select .dropdown-toggle::after {
    display: none !important;
}

/* Row checkboxes and row action icons: hide the whole column, header included (only on tables that have them).
   :has() is in current Chrome, Safari and Firefox; older browsers just print those columns. */
.m_datatable table:has(td.list-action:last-child) tr > :last-child,
.m_datatable table:has(td:first-child .m-checkbox) tr > :first-child {
    display: none !important;
}

/* ---------- 3. Let content flow ---------- */

.app-card-bleed,
.m-portlet.app-card-bleed,
.app-dashboard,
.app-report,
.app-report.app-report--tight {
    margin: 0 !important;
}

.m-portlet {
    box-shadow: none !important;
    margin-bottom: 10px !important;
}

/* Card headers have a fixed 5.1rem height; with their buttons hidden they'd leave an empty band */
.m-portlet .m-portlet__head {
    height: auto !important;
    min-height: 0 !important;
}

/* Fixed-height scroll boxes (follow-ups, activities, documents, payment history ...) print in full */
.m-scrollable,
.mCustomScrollBox,
.mCSB_container,
.mCSB_inside > .mCSB_container,
[class*="app-h-"],
.app-adv-search__scroll {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

.mCSB_inside > .mCSB_container {
    margin-right: 0 !important;
}

.table-responsive {
    overflow: visible !important;
}

/* Cards meant to fill the window (m-portlet--full-height) would push an empty page out after the content */
.m-portlet--full-height {
    height: auto !important;
}

/* Report filter bars (#list_filter_form, 17+ fields): print only the filters that are set, side by side, instead of
   a page of empty boxes. Empty text inputs show their placeholder; bootstrap-select marks "nothing chosen" with
   .bs-placeholder. Each column holds one control. (The Advance Search panels use the same id but sit in a hidden
   dropdown.) */
#list_filter_form .row {
    display: block !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
}

#list_filter_form [class*="col-"] {
    display: inline-block !important;
    width: auto !important;
    max-width: none !important;
    flex: none !important;
    padding: 0 16px 4px 0 !important;
    vertical-align: top;
}

#list_filter_form [class*="col-"]:has(input:placeholder-shown),
#list_filter_form [class*="col-"]:has(.bs-placeholder),
#list_filter_form [class*="col-"]:has(select option:checked[value=""]),   /* "Beds", "Created Date": a default with no value */
#list_filter_form [class*="col-"]:not(:has(input, select, span, b)) {
    display: none !important;
}

#list_filter_form .form-control,
#list_filter_form .bootstrap-select > .btn {
    border: 0 !important;
    padding: 0 !important;
    height: auto !important;
    width: auto !important;
    background: none !important;
}

/* ---------- 4. Tables and text on paper ---------- */

body {
    background: #ffffff !important;
}

.m_datatable table,
.table {
    font-size: 11px;
}

.m_datatable table td,
.m_datatable table th {
    padding: 4px 6px !important;
}

/* Every list cell is a link; underlined (Bootstrap's print default) they're hard to read */
.m_datatable a,
.m-portlet a {
    text-decoration: none !important;
    color: inherit !important;
}

/* Keep a row or a field together. Not whole section boxes: a tall one would jump to the next page and leave a blank one. */
tr,
.form-group {
    page-break-inside: avoid;
}

/* Keep status pills, type chips and "B" badges in colour */
.app-status,
.app-type-chip,
.brokerage-confirm,
.m-badge,
[class*="-badge"] {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
