/* ==========================================================================
   Printing the monthly report (Journal -> Review -> Month -> Save as PDF).

   js/views/journal/month-review.js puts a copy of the report in
   #print-report, sets html.is-printing-report and the light theme, and
   calls window.print(). Everything here is keyed on that class, so an
   ordinary Ctrl+P of any other page prints exactly as before.

   No colours of its own: the report prints in the light theme's tokens.
   Loaded last, after the view stylesheets it adjusts.
   ========================================================================== */

#print-report {
  display: none;
}

/* The theme flips to light for the dialog, and base.css eases body colours
   over --dur-slow: the page would be printed mid-fade, grey on grey. Outside
   the print query on purpose - the class is set before the theme flips and
   removed only after it flips back, so no transition ever starts.
   Transitions only: switching animations off page-wide would replay every
   card's entrance once the class goes. */
html.is-printing-report,
html.is-printing-report *,
html.is-printing-report *::before,
html.is-printing-report *::after {
  transition: none !important;
}

/* The copy is new DOM: its .stagger-item cards would start their entrance
   and be printed half-faded. */
#print-report *,
#print-report *::before,
#print-report *::after {
  animation: none !important;
}

@media print {
  @page {
    size: A4;
    /* 190 mm of content = ~718 CSS px: wider than the 700 px breakpoint
       where tables turn into phone cards, so they print as tables. */
    margin: 12mm 10mm;
  }

  html.is-printing-report body > *:not(#print-report) {
    display: none !important;
  }

  html.is-printing-report,
  html.is-printing-report body {
    height: auto;
    overflow: visible;
    background: var(--color-surface); /* paper is white in every look */
  }

  html.is-printing-report #print-report {
    display: block;
    /* Card fills and the profit/loss colours are part of the content. */
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  #print-report [data-no-print] {
    display: none !important;
  }

  #print-report .month-report__print-meta {
    display: block;
    margin-top: var(--space-2);
    font-size: var(--fs-footnote);
    color: var(--color-text-tertiary);
  }

  #print-report .card {
    box-shadow: none;
    margin-bottom: var(--space-4);
  }

  /* A long card may run over a page; its heading, a table row or a metric
     never splits, and a heading never ends a page alone. */
  #print-report .section-header,
  #print-report .tb-head {
    break-after: avoid;
  }

  #print-report tr,
  #print-report .tb-summary,
  #print-report .trade-list__row,
  #print-report .tb-rows__row,
  #print-report .shot-tile {
    break-inside: avoid;
  }

  #print-report .data-table tbody tr {
    cursor: default;
  }
}
