/* Printing, for every page.
 *
 * The tender "Print" button no longer uses the browser at all — it asks the
 * server for a real PDF (see js/pdf.js). This file is for the other case:
 * somebody hitting Ctrl+P anywhere in the app.
 *
 * Before this, only css/detail.css had an @media print block (1 of 20
 * stylesheets), so Ctrl+P on any other page printed the entire interface —
 * nav dock, sidebar, topbar, floating buttons.
 */

@page {
  size: A4;
  margin: 18mm;
}

@media print {
  /* ---- The reason printing produced a picture ----------------------------
     .glass-refract::before and friends carry `filter: url(#liquid-refract…)`,
     an SVG displacement filter. Chromium RASTERIZES any subtree carrying an
     SVG filter, so the page came out as a bitmap: no selectable text, huge
     files, fuzzy at print resolution. The old print block styled .detail-hero
     but never the pseudo-element actually holding the filter. */
  .glass-refract::before,
  .glass-refract-soft::before,
  .glass-goo,
  .glass::before,
  .glass-card::before {
    filter: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    background: none !important;
    content: none !important;
  }

  /* ---- Force a light palette ---------------------------------------------
     Theme tokens are set on :root, so a dark-theme user printed near-white
     text onto white paper. */
  :root,
  :root[data-theme="dark"] {
    --text-primary: #111827 !important;
    --text-secondary: #374151 !important;
    --text-tertiary: #6b7280 !important;
    --stage-0: #ffffff !important;
    --stage-1: #ffffff !important;
    --stage-2: #ffffff !important;
    --stage-3: #ffffff !important;
    --stage-4: #ffffff !important;
    --surface-solid: #ffffff !important;
    --surface-soft: #ffffff !important;
    --stage-border: #d1d5db !important;
    --stage-border-strong: #9ca3af !important;
    /* Nothing on paper is raised, and a shadow only costs toner. */
    --elev-rim: none !important;
    --elev-1: none !important;
    --elev-2: none !important;
    --elev-3: none !important;
    --elev-4: none !important;
    --glass-fill-1: #ffffff !important;
    --glass-fill-2: #ffffff !important;
    /* The stages above are already white; this stops the glass fill being
       mixed with transparent and letting the ground show through. */
    --glass-opacity: 100% !important;
    --glass-highlight: transparent !important;
    --glass-edge: transparent !important;
    --ambient-1: transparent !important;
    --ambient-2: transparent !important;
  }

  html,
  body {
    background: #fff !important;
    color: #111827 !important;
  }

  body::before,
  body::after {
    display: none !important;
  }

  /* ---- App chrome: none of it belongs on paper --------------------------- */
  .liquid-nav,
  .sidebar,
  .sidebar-scrim,
  .topbar,
  .burger,
  .topbar-actions,
  .detail-actions,
  .detail-foot,
  #back-btn,
  .ai-fab,
  .ai-root,
  .ai-scrim,
  .fub,
  .fub-panel,
  .dlv-root,
  .dlv-scrim,
  .category-pick-bar,
  .toast,
  .toast-host,
  button,
  .btn {
    display: none !important;
  }

  /* ---- Flatten the glass treatment -------------------------------------- */
  .glass,
  .glass-card,
  .detail-section,
  .detail-hero,
  .panel,
  .card {
    background: #fff !important;
    box-shadow: none !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    border: 1px solid #ddd !important;
    break-inside: avoid;
  }

  .page,
  main {
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  /* ---- Typography for paper --------------------------------------------- */
  body {
    font-size: 11pt;
    line-height: 1.45;
  }

  h1, h2, h3, tr {
    break-inside: avoid;
    break-after: avoid;
  }

  img {
    max-width: 100% !important;
  }

  /* A link's destination is invisible on paper; show it once, inline. */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 9pt;
    color: #6b7280;
    word-break: break-all;
  }
}
