/* =====================================================================================================================
   dm_print.css - Dukan Manager (APEX app 10001) | application static file #APP_FILES#dm_print.css | PRINT agent (AD) 2026-10-18
   Print look of EVERY printable document (G17, owner complaint 2026-10-18 + owner bug S-0058):
   - only the paper prints: no page title / breadcrumb, no success toast / notifications, no APEX developer toolbar,
     no navigation, no buttons, no fixed / floating elements (scroll-to-top, dialogs, tooltips);
   - @page margin 0 = the browser prints NO header / footer (date, URL, page title, 1/2); the white space is inner padding
     on the content, repeated on every page (box-decoration-break: clone);
   - A4 portrait by default, 80 mm when the receipt has the THERMAL_80 class (shop setting RECEIPT_FORMAT), report pages
     that ask for it keep A4 landscape (dm_admin.css body.dm-a-print-land);
   - rows, total blocks and signature blocks never split across two pages; table heads repeat on every page;
   - paper always light, black ink (G3.4 / G17.1), links print as plain text.
   Loaded app-wide: MAIN lists it in the user interface CSS files; until then dm_customers.css @imports it (first line).
   COLOUR RULE: system colours only (Canvas / CanvasText / GrayText) - no hex values.
   ROUND 5 SHELL (AD 2026-10-18): the shared base (sections 1-3 + 6) is wrapped in :where() = specificity 0 while it keeps !important,
   so it still beats the theme but ANY page rule of a module (dm_<module>.css inside @media print, scoped to its page, with !important)
   wins over it - no more fights (e.g. a module may give its paper card a border or its own padding). Sections 4 / 5 / 5b are page rules
   (p33 / p46 / p57 / p41 / 80 mm) kept here until their modules move them into their own CSS.
   ===================================================================================================================== */

@page { size: A4 portrait; margin: 0; }
@page dm-80 { size: 80mm 297mm; margin: 0; }
@page dm-land { size: A4 landscape; margin: 0; }

/* ---------------------------------------------------------------- 0. ONE shop header for every paper (print fixes round 7, owner 2026-10-20)
   Shop name, then icon + phone on their OWN centred line right under it, vertically centred, never overlapping the name.
   Used by: p46 receipt (.dm-i-rphones), p33 sale bill (.dm-r-phone, icon = ::before), p55 purchase bill + p57 supplier voucher
   (.dm-pp-addr), and the name line of every head (qist card, ledger, p52, ops papers). Screen + print (the paper looks the same on screen). */
:root body :is(.dm-i-shop, .dm-r-name, .dm-pp-shop, .dm-i-qc-shop, .dm-p14-ph-shop, .p65-ph-shop) { line-height: 1.3; }
:root body :is(.dm-i-rphones, .dm-r-phone, .dm-pp-addr):not(:empty) { display: flex !important; align-items: center; justify-content: center;
  flex-wrap: wrap; column-gap: 1.5mm; line-height: 1.5; min-height: 1.5em; margin-top: 1mm; padding: 0; }
:root body :is(.dm-i-rphones, .dm-pp-addr) .fa { display: inline-block; flex: 0 0 auto; width: 1.1em; line-height: 1; text-align: center; vertical-align: middle; }
:root body .dm-r-phone::before { display: inline-block; flex: 0 0 auto; width: 1.1em; line-height: 1; text-align: center; margin-right: 0; }

@media print {
  :root:root, html:root body { color-scheme: light !important; background: Canvas !important; color: CanvasText !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* ---------------------------------------------------------------- 1. app chrome + everything floating */
  :where(#apexDevToolbar, .a-DevToolbar, .apex-dev-toolbar, .dm-bot-btn, .dm-hbtn, .dm-help-btn, .dm-chip,
  .t-Header, #t_Header, .t-Body-nav, #t_Body_nav, .t-Body-title, #t_Body_title, .t-Body-actions, #t_Body_actions, .t-Body-side,
  .t-Footer, .t-Body-topButton, #t_Body_topButton,
  .t-Body-alert, #t_Alert_Success, #t_Alert_Notification, #APEX_SUCCESS_MESSAGE, #APEX_ERROR_MESSAGE, .t-Alert--page,
  .apex-page-success, .apex-page-error, .a-Notification, .ui-dialog, .ui-widget-overlay, .ui-tooltip, .a-Menu, .apex_disabled_overlay,
  .t-BreadcrumbRegion, .t-BreadcrumbRegion-buttons, .t-ButtonRegion, .t-Region-headerItems--buttons,
  button, .t-Button, .a-Button, .a-IRR-toolbar, .a-IRR-pagination, .a-IRR-controls, .t-Report-pagination, .t-Report-links,
  .apex-rds-container, .apex-rds, .dm-no-print, .dm-noprint, .dm-find, .dm-filters, .dm-i-preview-label, .dm-r-preview,
  .dm-preview-label) { display: none !important; }

  /* ---------------------------------------------------------------- 2. the sheet: no app offsets, inner padding = page margin */
  :where(.t-PageBody, .t-Body, .t-Body-main, .t-Body-wrap, .t-Body-content, .t-Body-contentInner, .t-Body-fullContent) {
    margin: 0 !important; padding: 0 !important; width: auto !important; max-width: none !important; min-height: 0 !important;
    transform: none !important; overflow: visible !important; position: static !important; box-shadow: none !important; }
  /* page margin as inner padding = the ONE strong base rule (paper margin, @page margin is 0): it beats a generic module reset such as
     .dm-p33 .t-Body-contentInner { padding: 0 !important }; a page that needs other margins uses body:has(#its_id) .t-Body-contentInner
     (like the 80 mm rule below / dm_ops.css p60-65) */
  :root body .t-Body-contentInner { padding: 10mm 12mm !important; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
  :where(.t-Body-contentInner .container, .t-Body-contentInner .row) { margin: 0 !important; padding: 0 !important; max-width: none !important; }
  :where(.t-Body-contentInner .col) { flex: 0 0 100% !important; max-width: 100% !important; padding: 0 !important; }
  :where(.t-Region, .t-Region-body, .t-Region-header, .a-CardView, .t-Report-report, .t-Report-cell, .t-Report-colHead,
  .a-IRR, .a-IRR-table td, .a-IRR-table th, .t-AVPList-label, .t-AVPList-value) {
    background: transparent !important; color: CanvasText !important; box-shadow: none !important; }
  :where(.t-Region) { border: 0 !important; margin-bottom: 4mm !important; }
  :where(.t-Report-wrap, .t-Report-tableWrap, .a-IRR-tableContainer, .t-Region-bodyWrap, .t-Region--scrollBody .t-Region-body) {
    max-height: none !important; overflow: visible !important; }
  :where(a, a:visited) { color: CanvasText !important; text-decoration: none !important; }
  /* G17.1 black ink: screen colours of money / KPI cards (green paid, orange remaining, muted) print black */
  :where(.dm-money, .dm-money--ok, .dm-money--bad, .dm-sub, .a-CardView-title, .a-CardView-subTitle, .a-CardView-body,
  .t-AVPList-label, .dm-i-rdl dt) { color: CanvasText !important; }

  /* ---------------------------------------------------------------- 3. never split a row / total / signature block */
  tr, .t-AVPList-item, .a-CardView-item, .dm-r-totals, .dm-r-sign, .dm-r-footer, .dm-r-qist, .dm-r-guar, .dm-i-rfoot, .dm-i-signs,
  .dm-i-words-box, .dm-sign, .dm-print-head, .dm-i-rhead, .dm-r-shop, .dm-p14-pf, .dm-p14-ph-shop {
    break-inside: avoid; page-break-inside: avoid; }
  thead { display: table-header-group; }
  h1, h2, h3, .t-Region-header, .dm-i-rtitle, .dm-r-title { break-after: avoid; page-break-after: avoid; }

  /* ---------------------------------------------------------------- 4. one-paper documents: ONLY the paper prints
     p33 sale receipt, p46 payment receipt, p57 supplier voucher (every other column of the page body is left out) */
  body:has(#p33_receipt, #p46_receipt, #p57_voucher) .t-Body-contentInner .col:not(:has(#p33_receipt, #p46_receipt, #p57_voucher)):not(:is(#p33_receipt, #p46_receipt, #p57_voucher) .col) {
    display: none !important; }
  :is(#p33_receipt, #p46_receipt, #p57_voucher) { border: 0 !important; border-radius: 0 !important; max-width: none !important;
    width: 100% !important; margin: 0 !important; padding: 0 !important; position: static !important; visibility: visible !important; }
  :is(#p33_receipt, #p46_receipt, #p57_voucher) * { visibility: visible !important; }

  /* p33 schedule grid (dm_sales.css: tbody = 2-column grid, every tr = a 3-column grid): rows keep together */
  #p33_schedule .t-Report-report tbody { display: grid !important; }
  #p33_schedule .t-Report-report tbody tr { break-inside: avoid; page-break-inside: avoid; }

  /* p33 paper = the mockup receipt (fidelity\mockup_p33_print.png): centred shop head, head fields in 2 columns
     ("No. S-0058" label + bold value), lines + schedule full width, totals / plan in the right half, no cell boxes */
  #p33_receipt .t-Report-wrap, #p33_receipt .t-Report-tableWrap, #p33_receipt table.t-Report-report { width: 100% !important; }
  #p33_receipt .t-Report-report, #p33_receipt .t-Report-report td, #p33_receipt .t-Report-report th { border: 0 !important; }
  #p33_receipt .t-Report-report thead th { border-bottom: 1px solid CanvasText !important; }
  #p33_receipt .t-Report-report tbody td { border-bottom: 1px solid GrayText !important; padding: 4px 6px !important; }
  #p33_shop .t-Report-report tbody td { border: 0 !important; text-align: center; }
  #p33_shop { border-bottom: 1px dashed CanvasText; padding-bottom: 2mm; margin-bottom: 2mm !important; }
  /* head fields + totals + plan are Value Attribute Pair lists (dl > dt + dd) */
  #p33_receipt .t-AVPList-label, #p33_receipt .t-AVPList-value { width: auto !important; border: 0 !important; padding: 1px 0 !important;
    margin: 0 !important; float: none !important; min-height: 0 !important; }
  #p33_meta dl.t-AVPList { display: grid !important; grid-template-columns: max-content 1fr max-content 1fr; column-gap: 3mm; row-gap: 1mm; }
  #p33_meta .t-AVPList-value { font-weight: 700; }
  :is(#p33_totals, #p33_qist) dl.t-AVPList { display: grid !important; grid-template-columns: max-content minmax(0, 1fr); column-gap: 4mm;
    width: 50% !important; margin-left: auto !important; }
  :is(#p33_totals, #p33_qist) .t-AVPList-value { text-align: right; font-weight: 700; }
  #p33_schedule .t-Report-report tbody td { padding: 3px 6px !important; }

  /* p46 paper = the mockup receipt (fidelity\mockup_p46_print.png): dashed rule under the shop head, plain ruled tables,
     balance / next / notes block in the right part, bold values */
  #p46_receipt .dm-i-rhead { border-bottom: 1px dashed CanvasText; padding-bottom: 2mm; }
  #p46_receipt .dm-i-rtitle { border: 0 !important; text-align: left; padding: 0; }
  #p46_receipt .dm-i-rdl dt { color: CanvasText !important; font-weight: 400; }
  #p46_receipt .dm-i-rdl dd { font-weight: 700; }
  #p46_receipt .dm-i-words-box, #p46_receipt .dm-i-words-box * { border: 0 !important; background: transparent !important; }
  #p46_receipt .t-Report-wrap, #p46_receipt table.t-Report-report { width: 100% !important; }
  #p46_receipt .t-Report-report, #p46_receipt .t-Report-report td, #p46_receipt .t-Report-report th { border: 0 !important; }
  /* "Paid for" (mockup receipt): the table runs edge to edge of the paper, the title sits on the paper's left edge, header cell and value cell
     of a column share ONE padding, so every header stands exactly over its values (number column right, text columns left) */
  #p46_receipt .dm-i-paidfor :is(.t-Region-header, .t-Region-headerItems, .t-Region-title, .t-Region-headerIcon) { padding-left: 0 !important; margin-left: 0 !important; }
  #p46_receipt .dm-i-paidfor .t-Region-headerIcon:empty, #p46_receipt .dm-i-paidfor .t-Region-headerIcon { display: none !important; }
  #p46_receipt .dm-i-paidfor :is(.t-Report, .t-Report-wrap, .t-Report-tableWrap) { margin: 0 !important; padding: 0 !important; width: 100% !important; }
  #p46_receipt table.t-Report-report { table-layout: auto; border-collapse: collapse; }
  #p46_receipt .t-Report-report :is(th, td) { padding: 4px 12px !important; box-sizing: border-box; text-align: left; vertical-align: middle; }
  #p46_receipt .t-Report-report :is(th, td)[align="right"] { text-align: right; }
  #p46_receipt .t-Report-report thead th { border-bottom: 1px solid CanvasText !important; font-weight: 700;
    background: color-mix(in srgb, CanvasText 5%, Canvas) !important; }
  #p46_receipt .t-Report-report tbody td { border-bottom: 1px solid GrayText !important; }
  #p46_receipt .dm-i-rfoot .dm-i-rdl { width: 60%; margin-left: auto; }
  #p46_receipt .dm-i-rfoot .dm-i-rdl dd { text-align: right; }
  #p46_receipt .dm-i-rfoot .dm-i-ritem { width: 100% !important; border-top: 1px dashed CanvasText; padding-top: 2mm; color: CanvasText; }   /* C1 2026-10-21: full-width item row on paper too */
  #p46_receipt .dm-i-rfoot > .t-Region-body > .dm-sub, #p46_receipt .dm-i-rfoot p.dm-sub { border-top: 1px dashed CanvasText; padding-top: 2mm; }
  #p46_receipt .dm-i-signs span { border-top-color: CanvasText; }

  /* ---------------------------------------------------------------- 5. 80 mm thermal receipt (RECEIPT_FORMAT = THERMAL_80) */
  /* the named page must sit on the first box of the document (body), else Chrome keeps the A4 first page */
  body:has(.dm-receipt--THERMAL_80) { page: dm-80; }
  .dm-receipt--THERMAL_80 { width: 72mm !important; font-size: 11px !important; }
  .dm-receipt--THERMAL_80 .dm-i-rdl { grid-template-columns: 1fr 1fr !important; font-size: 11px; }
  .dm-receipt--THERMAL_80 .dm-i-signs { flex-direction: column; gap: 10mm; }
  .dm-receipt--THERMAL_80 .dm-i-signs span { min-width: 100%; }
  .dm-receipt--THERMAL_80 .dm-i-shop { font-size: 15px; }
  body:has(.dm-receipt--THERMAL_80) .t-Body-contentInner { padding: 3mm 4mm !important; }
  .dm-receipt--THERMAL_80 #p33_meta dl.t-AVPList { grid-template-columns: max-content 1fr !important; }
  .dm-receipt--THERMAL_80 :is(#p33_totals, #p33_qist) dl.t-AVPList { width: 100% !important; }
  .dm-receipt--THERMAL_80 .dm-r-schedule .t-Report-report tbody { grid-template-columns: 1fr !important; }
  .dm-receipt--THERMAL_80 .dm-r-sign, .dm-receipt--THERMAL_80 .dm-r-sign .t-Region-body { flex-direction: column; gap: 10mm; }
  .dm-receipt--THERMAL_80 .t-Report-cell, .dm-receipt--THERMAL_80 .t-Report-colHead { padding: 2px 3px !important; }

  /* ---------------------------------------------------------------- 5b. p41 "Print Qist Card": plan head + amounts + schedule only */
  #p41_pick, #p41_payments, #p41_promises, #p41_cheques, #p41_history, #p41_profit { display: none !important; }
  #p41_schedule, #p41_guarantors { display: block !important; }

  /* ---------------------------------------------------------------- 6. lists printed from list pages (p14 ledger, p26 sheet, p41,
     p65, reports 81-89): the list prints in full (no inner scroll), the screen-only phone cards stay hidden */
  :where(.dm-i-phone-cards, .dm-phone-only) { display: none !important; }
  :where(.dm-desktop-only, .dm-wide-only) { display: block !important; }
}
