/* FM-198 — what the app looks like on paper.
 *
 * Before this file, Ctrl-P on any page printed the APP: the fixed header, the
 * navigation drawer, the notification bell, the four floating tool buttons, the
 * Coach avatar and a white circle over the content. Three sheets of paper, and
 * the thing the contractor actually wanted to hand a client was somewhere in
 * the middle of it.
 *
 * The rule this file applies is one line long: THINGS THAT DO SOMETHING DO NOT
 * PRINT; THINGS THAT SAY SOMETHING DO. A button, a drawer, a bell, a floating
 * tool, a toast — none of them mean anything on paper. Numbers, names, tables
 * and headings do.
 *
 * The one place that rule needs care is form fields, because in this app a form
 * field is often where the DATA is — the draw labels in the payment schedule
 * are <input>s. Hiding controls wholesale would silently delete content from
 * the page. So inputs are FLATTENED, not hidden: the box, border and background
 * go, the value stays and prints as text.
 *
 * Everything here is inside @media print. Nothing in this file can affect the
 * screen.
 */

@media print {

  /* ── Page box ───────────────────────────────────────────────────────────
   * Letter portrait with a half-inch margin. The browser's own header/footer
   * (date, title, URL, page count) is a BROWSER setting, not ours — it lives
   * under "More settings > Headers and footers" in the print dialog and no
   * stylesheet can remove it. The printed document header below is ours.
   */
  @page {
    size: letter portrait;
    margin: 0.5in;
  }

  /* ── 1. The app chrome ──────────────────────────────────────────────────
   * Measured on a live page, not guessed: these are every fixed/sticky
   * element that paints, plus the shell's header, footer and bottom nav.
   * fm-print-coverage.spec.js reads the shell and the FAB partials and fails
   * if a new one appears that is not covered here.
   */
  .fm-sidebar,
  #fmDrawer,
  .fm-mobile-topbar,
  #fmMobileTopbar,
  .fm-mobile-overlay,
  #fmMobileOverlay,
  .fm-bottom-nav,
  .fm-header,
  .fm-app-footer,
  .fm-render-stamp,
  .fm-debug-card,
  .fm-impersonation-banner,
  .fm-billing-alert,

  /* floating tools + the Coach avatar */
  #coach-fab-root,
  #fmcalc-root,
  #fmfit-root,
  #fmspace-root,
  #fmbf-root,
  #fm-tools-fab,

  /* transient UI that can be on screen when Print is pressed */
  .fm-toast-stack,
  .fm-toast,
  .fm-cd-backdrop,
  .fm-command-palette,
  #fmCommandPalette,

  /* anything a page has already marked, including money.ejs's own convention */
  .fm-noprint,
  .ms-noprint,
  [data-noprint] {
    display: none !important;
  }

  /* The mobile shell fights back, and it fights with a bigger stick.
   * fm-theme.css carries
   *
   *     @media (max-width: 900px) {
   *       body.fm-is-mobile #fmDrawer.fm-drawer { display: flex !important; }
   *     }
   *
   * — one id and two classes, with !important. The plain `#fmDrawer` above is
   * one id and no classes, so it LOSES: !important with higher specificity
   * beats !important alone, and the hide-list is not enough on its own.
   *
   * This matters more than it looks. A print sheet is about 7.5in wide, which
   * is ~720 CSS px, so that 900px media query is ACTIVE on paper; and
   * `fm-is-mobile` is a class JavaScript put on <body> from the window size,
   * which does not change just because the page is being printed. So printing
   * from a narrow window kept the whole navigation drawer on the page while
   * printing the same page from a wide one did not — measured, not reasoned.
   *
   * The fix matches that selector's specificity exactly rather than escalating
   * past it. fm-print.css loads last, and an equal-specificity tie goes to the
   * later rule.
   */
  body.fm-is-mobile #fmDrawer.fm-drawer,
  body.fm-is-mobile .fm-drawer,
  body.fm-is-mobile .fm-sidebar,
  body.fm-is-mobile .fm-mobile-topbar,
  body.fm-is-mobile .fm-mobile-overlay,
  body.fm-is-mobile .fm-bottom-nav,
  body.fm-is-mobile .fm-header {
    display: none !important;
  }

  /* ── 2. Controls ────────────────────────────────────────────────────────
   * Buttons and links-as-buttons say "click me" to someone holding paper.
   * A plain <a> is left alone — it is usually a name, not an action.
   */
  button,
  [role="button"],
  .fm-btn,
  .fm-icon-btn,
  .money-section__action,
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  input[type="checkbox"],
  input[type="radio"] {
    display: none !important;
  }

  /* Anchors styled as actions. A <button> is easy — these are <a> tags that
   * look and behave like buttons, and the tag alone cannot tell them apart
   * from a link that is genuinely content. The codebase has two strong BEM
   * conventions to lean on instead, both counted before being relied on:
   * __action/__actions (about 90 uses) and __back (about 40).
   *
   * The selectors are written narrowly on purpose. `[class*="__act"]` would
   * have been shorter and would also have hidden `ia-row__actor` and
   * `lf-upload-card__actor` — an actor is a PERSON, not an action, and those
   * are names on the page. Matching the end of the attribute, or the name
   * followed by a space, cannot make that mistake.
   */
  [class*="__action"],
  [class*="__acts"],
  [class$="__act"],
  [class*="__act "],
  [class$="__back"],
  [class*="__back "],
  .fm-page-back,
  [class*="__backdrop"],

  /* A jump link to another part of the same page is meaningless once the page
   * is a stack of paper — "View invoice" cannot be followed. */
  a[href^="#"],

  /* Chevrons and carets point at an interaction that is not available. The
   * content they used to gate is force-expanded further down, so they are
   * pointing at nothing. `__chev` prefix-matches `__chevron` as well. */
  [class*="__chev"],
  [class*="__caret"],

  /* "Show details" is an instruction, and the details are already showing.
   * NOT extended to `__toggle`: some of those are switches that display a
   * setting's state, and state is worth printing. */
  [class*="__more"],

  /* The kicker directly above a page title — "MONEY" over the project name.
   * The letterhead above now says exactly that, so it prints twice. Scoped to
   * `title-eyebrow` (11 uses) rather than every `eyebrow` (46): the rest are
   * card labels carrying real context, not a repeat of the page name. */
  [class*="title-eyebrow"] {
    display: none !important;
  }

  /* ── 3. Fields are content, not chrome ──────────────────────────────────
   * The value in an <input> is frequently the only copy of that text on the
   * page — the payment schedule's draw labels are the case that made this
   * rule. Flatten them so the value prints and the widget does not.
   */
  input,
  select,
  textarea {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    color: #000 !important;
    font: inherit !important;
    -webkit-appearance: none;
    appearance: none;
  }
  textarea { resize: none !important; overflow: visible !important; }

  /* ── 4. Release the app shell ───────────────────────────────────────────
   * The layout reserves space for a drawer that is no longer there, and caps
   * itself for a screen. On paper the page IS the container.
   */
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
  }
  .fm-app, .app-shell, .fm-main, .fm-content, main, .page, .page-content {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    grid-template-columns: none !important;
    overflow: visible !important;
  }

  /* And the same specificity trap again, one floor down. fm-theme.css has
   *
   *     body.fm-is-mobile .fm-main { padding-top: 68px !important; }
   *
   * which is the gap reserved for the fixed mobile topbar. The topbar is gone
   * by the time this matters, but the hole it was sitting in is not: it opened
   * the printed page with an inch of nothing above the letterhead. Two classes
   * and !important, so the plain `.fm-main` rule above never had a chance.
   */
  body.fm-is-mobile .fm-main,
  body.fm-is-mobile .fm-content,
  body[data-page] .fm-main {
    padding: 0 !important;
    margin: 0 !important;
  }

  /* A printed document reads top to bottom. The dense two-up grid is a
   * screen affordance for a 1440px window; on a 8.5in sheet it produces two
   * narrow columns the eye has to zig-zag between. */
  .fm-dense__grid,
  .fm-page-stack {
    display: block !important;
    max-width: none !important;
  }

  /* ── 5. Ink ─────────────────────────────────────────────────────────────
   * Screen depth costs toner and reads as grey mush. Keep the borders, which
   * are what separate one block from the next on paper; drop the rest.
   */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
  }
  .fm-card, .info-card, .money-section, .project-card, .plan-card,
  .summary-card, .tab-panel, .proposal-panel {
    background: #fff !important;
    border: 1px solid #d0d5dd !important;
    border-radius: 4px !important;
  }

  /* Money is colour-coded and that coding is meaningful — a negative balance
   * in black is a different document. Chrome drops backgrounds and colours in
   * print unless asked; ask. */
  .money-section, .fm-card, table, .ms-pill, .ms-chip, .fm-pill, .fm-badge {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* ── 6. Where the page breaks ───────────────────────────────────────────
   * Left alone, a card splits across a sheet boundary and a table loses its
   * column headings on every page after the first.
   */
  .fm-card, .info-card, .money-section, .project-card, .plan-card,
  .summary-card, .fm-ps, tr, .fm-jw-collapsible {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  h1, h2, h3, h4, .money-section__title, .fm-section-title {
    break-after: avoid;
    page-break-after: avoid;
  }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }

  /* ── 7. A collapsed drawer prints as a heading with nothing under it ────
   * Which is the worst of both outcomes: it costs a line and carries no
   * information, and the reader cannot tell whether the section was empty or
   * merely shut. A printed document is complete.
   */
  /* `display: block` on the children is NOT enough, and it looks like it is,
   * which is the trap. Chromium hides a closed <details> with
   * `content-visibility: hidden` on a shadow ::details-content wrapper, so the
   * children measure as display:block with a real height (155px, measured)
   * and still paint nothing. The section prints as a heading with a void
   * under it and every measurement says it is fine.
   *
   * Doing this in CSS rather than by setting `open` on beforeprint is
   * deliberate: the JS version has to put the attribute back on afterprint,
   * and afterprint does not reliably fire when a print is cancelled — which
   * would leave every drawer on the contractor's screen hanging open with no
   * idea why. A stylesheet cannot get stuck.
   *
   * Both lines stay: the pseudo-element is recent, and the display rule is
   * what engines that do not implement it use.
   */
  details:not([open])::details-content { content-visibility: visible !important; }
  details > *:not(summary) { display: block !important; }
  summary { list-style: none; }
  summary::-webkit-details-marker { display: none; }

  /* ── 8. Links ───────────────────────────────────────────────────────────
   * Some print stylesheets append the href after every link. On a document
   * dense with internal links that turns every line into a wall of URLs.
   */
  a, a:visited { color: #000 !important; text-decoration: none !important; }
  a[href]::after { content: "" !important; }

  /* ── 9. The document header ─────────────────────────────────────────────
   * Printed only. Gives the sheet an identity the browser's own header does
   * not — the browser prints the <title>, which the reader can switch off,
   * and which says "Money • Project • FieldMetriq" rather than naming the
   * business that sent it.
   */
  .fm-print-head {
    display: block !important;
    border-bottom: 2px solid #0F2E4D;
    padding-bottom: 10px;
    margin-bottom: 18px;
  }
  .fm-print-head__brand {
    font-size: 17px;
    font-weight: 800;
    color: #0F2E4D;
    letter-spacing: -0.01em;
  }
  .fm-print-head__title {
    font-size: 22px;
    font-weight: 800;
    color: #101828;
    margin-top: 2px;
  }
  .fm-print-head__meta {
    font-size: 11px;
    color: #475467;
    margin-top: 4px;
  }

  /* ── 10. Type ───────────────────────────────────────────────────────────
   * Screen sizes are tuned for a backlit panel at arm's length. Paper is
   * read closer and holds more.
   */
  body { font-size: 11pt !important; line-height: 1.4 !important; color: #101828 !important; }
  table { width: 100% !important; border-collapse: collapse !important; font-size: 10pt !important; }
  th, td { padding: 4px 6px !important; }
}

/* The document header exists in the DOM on every page and is invisible on
 * screen. It is NOT inside the @media print block above, because this is the
 * screen rule that hides it. */
.fm-print-head { display: none; }
