/* =====================================================================
   DSTMS - assets/css/print.css
   Load LAST with media="print":  <link rel="stylesheet" href="..." media="print">
   Clean paper output for lists, reports, receipts and tickets.
   - Hides the app frame (sidebar, bars, buttons).
   - Forces light colours even when the dark theme is on.
   - Shows .print-only blocks (report title, date, organisation name).
   - Tickets and receipts print as a clean A5 page (.print-ticket, .print-receipt).
   Add the class .no-print to anything that must not be printed.
   ===================================================================== */

@page { size: A4; margin: 12mm; }
@page ticket { size: A5 portrait; margin: 8mm; }

@media print {

  /* Always print in the light palette */
  :root, :root[data-theme="dark"] {
    --bg: #fff; --surface: #fff; --surface-2: #f3f4f6;
    --text: #111; --text-2: #222; --muted: #555; --line: #cfd4dc;
    --primary: #1d4ed8; --primary-d: #1e3a8a; --primary-l: #e8eefc;
    --ok: #166534; --ok-bg: #dcfce7; --warn: #92400e; --warn-bg: #fef3c7;
    --bad: #991b1b; --bad-bg: #fee2e2; --info: #075985; --info-bg: #e0f2fe;
    --shadow: none; --shadow-sm: none; --shadow-lg: none;
    color-scheme: light;
  }

  html, body {
    background: #fff !important;
    color: #111 !important;
    font-size: 11pt;
    line-height: 1.45;
    min-height: 0;
  }

  /* Hide the app frame and controls */
  .sidebar, .scrim, .topbar, .bottomnav, .fab, .toasts, .overlay, .dropdown-menu,
  .a2hs, .hero, .breadcrumb, .toolbar, .pager, .tabs, .chips, .search,
  .page-actions, .form-actions, .table-actions, .cell-actions,
  .btn, .icon-btn, .no-print, .skeleton, .live-region {
    display: none !important;
  }
  .print-only { display: block !important; }
  span.print-only, a.print-only { display: inline !important; }

  /* Layout */
  .app { display: block !important; }
  .app-main { min-height: 0; display: block; }
  .content {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    animation: none !important;
  }
  .page-head { margin-bottom: 8pt; }
  .page-title { font-size: 16pt; }

  /* Cards become plain boxes */
  .card {
    box-shadow: none !important;
    border: 1px solid var(--line) !important;
    border-radius: 6px;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* Tables always print as real tables (even on a narrow A5 page) */
  .table-wrap { overflow: visible !important; border: 0 !important; box-shadow: none !important; background: none !important; }
  .table, .table-cards { display: table !important; width: 100%; font-size: 10pt; }
  .table-cards thead { display: table-header-group !important; }
  .table-cards tbody { display: table-row-group !important; }
  .table-cards tr { display: table-row !important; padding: 0 !important; border: 0 !important; box-shadow: none !important; background: none !important; }
  .table-cards td { display: table-cell !important; text-align: left !important; padding: 5pt 6pt !important; border-bottom: 1px solid var(--line) !important; }
  .table-cards td::before { display: none !important; content: none !important; }
  .table th, .table td { padding: 5pt 6pt; border-bottom: 1px solid var(--line); }
  .table thead th { position: static; background: #f3f4f6 !important; color: #111; text-transform: none; letter-spacing: 0; }
  .table thead { display: table-header-group; }          /* repeat header on every page */
  .table tr { break-inside: avoid; page-break-inside: avoid; }
  .table .num { text-align: right !important; }

  /* Keep status colours on paper */
  .badge, .cat-badge, .chip, .progress > span, .stat-icon, .avatar, .qr-box,
  .ticket-head, .ticket, .receipt {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .badge { border: 1px solid var(--line); }

  /* Links: plain text */
  a { color: inherit !important; text-decoration: none !important; }

  /* Headings stay with their content */
  h1, h2, h3, h4 { break-after: avoid; page-break-after: avoid; }

  /* Report header block: <div class="print-only print-header"> ... </div> */
  .print-header {
    display: block !important;
    margin-bottom: 10pt; padding-bottom: 6pt;
    border-bottom: 2px solid #111;
  }
  .print-header h1 { font-size: 16pt; margin: 0; }
  .print-header p { margin: 2pt 0 0; font-size: 9.5pt; color: #444; }

  .print-footer {
    display: block !important;
    margin-top: 12pt; padding-top: 4pt;
    border-top: 1px solid var(--line);
    font-size: 8.5pt; color: #555;
  }

  /* ---------- Ticket and receipt: one clean A5 page ---------- */
  .print-ticket, .print-receipt { page: ticket; }
  .print-ticket .ticket,
  .print-receipt .receipt {
    max-width: none !important;
    margin: 0 auto !important;
    box-shadow: none !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .print-ticket .qr-box canvas, .print-ticket .qr-box img { width: 48mm !important; height: 48mm !important; }
}
