/**
 * Shared print stylesheet for ITT application surfaces (#27646).
 *
 * Problem: only two `@media print` stylesheets existed across the 100+-app
 * monorepo, so customers who browser-print invoice lists, account statements,
 * financial reports or dashboards got the on-screen layout (nav bars, sidebars,
 * buttons, dark backgrounds, clipped overflow tables) instead of a clean,
 * printable document.
 *
 * This file is the reusable, shared print layer for the *application* host
 * shells (finance / invoicing / dashboards / reports). It is intentionally
 * additive and behaviour-preserving on screen: every print rule lives inside
 * `@media print`, so nothing here affects the on-screen rendering.
 *
 * Conventions (reusable across apps):
 *   - `.no-print`       → element is hidden when printing.
 *   - `.print-only`     → element is hidden on screen, shown only when printing.
 *   - `[data-no-print]` → attribute form of `.no-print` for dynamic markup.
 *   - `.print-container`→ opt-in wrapper that gets full-width, black-on-white
 *                         treatment plus sensible page margins.
 *
 * Import this once per host (e.g. in `main.tsx`) so it applies to every
 * mounted app:  import "@itt/platform-app-shell/styles/print-app.css";
 */

/* `.print-only` must be hidden on screen. This is the ONLY non-`@media print`
 * rule in this file, and it only hides opt-in helper markup that does not exist
 * in any current view — so screen rendering of existing surfaces is unchanged. */
.print-only {
  display: none;
}

@media print {
  /* ---- Page geometry ------------------------------------------------- */
  @page {
    margin: 1.5cm;
  }

  html,
  body {
    background: #fff !important;
    color: #000 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* ---- Hide on-screen chrome ---------------------------------------- */
  nav,
  aside,
  [role="navigation"],
  [role="toolbar"],
  [role="tablist"],
  button,
  [role="button"],
  input[type="button"],
  input[type="submit"],
  input[type="reset"],
  .no-print,
  [data-no-print],
  /* Floating / fixed widgets: chat, scroll-to-top, FABs */
  [class*="chat-widget"],
  [class*="ChatWidget"],
  [class*="scroll-top"],
  /* Cookie banners */
  [class*="cookie"],
  [class*="Cookie"],
  /* Toast / snackbar notifications (transient, never useful on paper) */
  [role="status"][class*="fixed"],
  [role="alert"][class*="fixed"],
  [class*="Toast"],
  [class*="toast"],
  [class*="Snackbar"] {
    display: none !important;
  }

  /* Re-show opt-in print-only content. */
  .print-only {
    display: revert !important;
  }

  /* Sidebars / drawers commonly use sticky/fixed positioning; collapse them so
   * the printed document is not offset by an empty rail. */
  [class*="sidebar"],
  [class*="Sidebar"],
  [class*="drawer"],
  [class*="Drawer"] {
    display: none !important;
  }

  /* ---- Force black-on-white over Tailwind backgrounds/shadows -------- */
  /* Strip the dark theme and the elevated "card" look so paper stays clean.
   * Targets the on-screen utility patterns the apps actually use
   * (bg-gray-*, bg-white, dark:bg-*, shadow-*, rounded-*). */
  [class*="bg-gray-"],
  [class*="bg-slate-"],
  [class*="bg-zinc-"],
  [class*="bg-neutral-"],
  [class*="bg-white"],
  [class*="dark:bg-"],
  [class*="shadow"] {
    background: transparent !important;
    background-color: transparent !important;
    box-shadow: none !important;
    color: #000 !important;
  }

  /* Borders: keep them but make them light grey so tables/cards stay legible
   * without the heavy on-screen dark borders. */
  [class*="border"] {
    border-color: #ccc !important;
  }

  /* ---- Tables: full width, no clipping ------------------------------ */
  /* On screen, wide tables live inside `overflow-x-auto` / `overflow-auto`
   * wrappers that clip content when printed. Let them flow to full width. */
  [class*="overflow-x-auto"],
  [class*="overflow-auto"],
  [class*="overflow-x-scroll"] {
    overflow: visible !important;
  }

  table {
    width: 100% !important;
    border-collapse: collapse !important;
    page-break-inside: auto;
  }

  thead {
    display: table-header-group; /* repeat header on every printed page */
  }

  th,
  td {
    color: #000 !important;
    background: transparent !important;
  }

  /* ---- Page-break hygiene ------------------------------------------- */
  tr,
  /* Cards / list rows / summary widgets that should not be split mid-row. */
  [class*="rounded"],
  [class*="Card"],
  [class*="card"],
  [class*="row"],
  [class*="Row"],
  li {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    page-break-after: avoid;
    break-after: avoid;
    color: #000 !important;
  }

  img,
  figure,
  svg,
  canvas {
    page-break-inside: avoid;
    break-inside: avoid;
    max-width: 100% !important;
  }

  /* ---- Opt-in print container --------------------------------------- */
  .print-container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
    box-shadow: none !important;
  }

  /* Print resolved URLs for external links so paper copies stay actionable,
   * but skip internal/relative links to avoid noise. */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #555;
    word-break: break-all;
  }
}
