/* =========================================================================
   summit-print — what a Summit Docs page looks like on paper, and in a
   browser's print-to-PDF. See docs/plans/SUMMIT_DOCS_PLAN.md §6.

   Browser print-to-PDF rather than a server-side renderer: it is free, it
   uses this exact stylesheet, and it produces the same result the author
   saw in print preview. Headless Chrome is an operational dependency worth
   taking on only when export has to be automated rather than invoked by a
   person.

   ⚠️ A printed Docs page must NOT look like a controlled document. No
   classification banner, no approval block, no signature line — those
   belong to the Policies module, and a printed page that mimics them is
   exactly the confusion the scope boundary (§1) exists to prevent. The
   footer says where the page came from and nothing more.
   ========================================================================= */

@media print {

  /* ── Page setup ─────────────────────────────────────────────────────── */
  @page {
    margin: 18mm 16mm 20mm;
  }

  /* ── Hide every piece of chrome ──────────────────────────────────────
     The content column, at full page width, and nothing else. */
  .mud-appbar,
  .mud-drawer,
  .mud-drawer-header,
  .mud-overlay,
  .mud-snackbar-container,
  .mud-popover,
  .mud-breadcrumbs,
  .ht-docs-toolbar,
  .ht-nav-section,
  nav,
  footer,
  button,
  .mud-button-root,
  .mud-icon-button,
  [data-print='hide'] {
    display: none !important;
  }

  /* MudBlazor lays the content out around a drawer that no longer exists. */
  .mud-main-content,
  .mud-container,
  .mud-layout {
    margin: 0 !important;
    padding: 0 !important;
    max-width: none !important;
    width: 100% !important;
  }

  html, body {
    background: #fff !important;
    margin: 0;
    padding: 0;
  }

  /* ── Black on white, whatever the screen theme was ───────────────────
     Printing a dark-mode page wastes toner and reads badly; the tokens are
     redefined rather than every rule rewritten. */
  :root, :root[data-theme='dark'] {
    --ht-bg: #ffffff;
    --ht-surface: #ffffff;
    --ht-surface-2: #f6f6f6;
    --ht-line: #c8c8c8;
    --ht-ink: #000000;
    --ht-muted: #444444;
    --ht-faint: #666666;
    --ht-accent: #0b3d91;
    --ht-chip-bg: #f0f0f0;
  }

  .mud-paper {
    box-shadow: none !important;
    border: 0 !important;
    background: #fff !important;
  }

  /* ── The content column ─────────────────────────────────────────────── */
  .summit-prose {
    /* The screen measure exists to stop lines being too long on a wide
       monitor. A printed page is already narrow, so the cap would just
       waste half the sheet. */
    max-width: none !important;
    font-size: 10.5pt;
    line-height: 1.45;
    color: #000;
  }

  .summit-prose > * { max-width: none !important; }

  /* ── Keep things that belong together, together ─────────────────────── */
  .summit-prose :is(h1, h2, h3, h4) {
    break-after: avoid;
    page-break-after: avoid;
    break-inside: avoid;
  }

  .summit-prose :is(table, pre, figure, .callout, img, blockquote) {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* A long table is the one thing that legitimately spans pages, and when
     it does the header has to come with it. */
  .summit-prose table { break-inside: auto; }
  .summit-prose thead { display: table-header-group; }
  .summit-prose tr { break-inside: avoid; }

  .summit-prose p,
  .summit-prose li {
    orphans: 3;
    widows: 3;
  }

  /* ── Links ───────────────────────────────────────────────────────────
     A printed link is dead, so the destination is printed after it.
     Internal and anchor links are left alone: "/docs/IT/overview" on paper
     helps nobody, and the noise would swamp the text. */
  .summit-prose a {
    color: #000;
    text-decoration: underline;
  }
  .summit-prose a[href^='http']::after {
    content: ' (' attr(href) ')';
    font-size: 0.85em;
    color: #444;
    word-break: break-all;
  }

  /* ── Blocks ─────────────────────────────────────────────────────────── */
  .summit-prose pre {
    background: #f6f6f6 !important;
    border: 1px solid #c8c8c8;
    white-space: pre-wrap;        /* or long lines are simply cut off */
    word-break: break-word;
    font-size: 9pt;
  }

  /* Syntax colours print as grey mush and cost ink. Structure survives
     through the monospace and the border. */
  .summit-prose pre code * { color: #000 !important; font-style: normal !important; }
  .summit-prose pre[data-language]::before { color: #666; }

  .summit-prose :is(th, td) { border: 1px solid #c8c8c8; }
  .summit-prose th { background: #f0f0f0 !important; }

  .summit-prose img {
    max-width: 100% !important;
    border: 1px solid #c8c8c8;
  }

  /* Callouts keep their shape but lose the fill, which would print as a
     grey box. The left bar and the glyph carry the meaning. */
  .summit-prose .callout {
    background: none !important;
    border: 1px solid #c8c8c8;
    border-left: 3px solid #444;
  }
  .summit-prose .callout::before {
    background: #444 !important;
    color: #fff !important;
  }

  /* Checkbox state has to survive — a printed checklist with every box the
     same is worse than no checklist. */
  .summit-prose ul[data-type='taskList'] input[type='checkbox'] {
    -webkit-appearance: none;
    appearance: none;
    width: 0.9em;
    height: 0.9em;
    border: 1px solid #000;
    position: relative;
  }
  .summit-prose ul[data-type='taskList'] li[data-checked='true'] input::after {
    content: '\2713';
    position: absolute;
    inset: -0.25em 0 0 0.05em;
    font-size: 0.95em;
  }
  .summit-prose ul[data-type='taskList'] li[data-checked='true'] > div {
    color: #444;
    text-decoration: line-through;
  }

  /* ── Where this came from ───────────────────────────────────────────────
     Deliberately plain: the page title, its version and when it was
     published, so a printed copy is traceable back to what it came from.
     Nothing that could be mistaken for an approval. */
  .summit-print-footer {
    display: block !important;
    margin-top: 10mm;
    padding-top: 3mm;
    border-top: 1px solid #c8c8c8;
    font-size: 8pt;
    color: #666;
  }
}

/* The footer exists only on paper. */
.summit-print-footer { display: none; }

/* =========================================================================
   What the app puts on the page that is not the document.

   Added after the first real print: a one-paragraph page came out three
   sheets long. The rules above hide MudBlazor's chrome, but three
   components live OUTSIDE MudLayout and were never covered — and below the
   md breakpoint, which is where a sheet of A4 lands, the mobile bar and
   its 80px of content padding are both switched on.
   ========================================================================= */

@media print {

  /* Outside MudLayout, so none of the .mud-* rules above reach them. */
  .ht-bottom-nav,
  .ht-mobile-menu,
  .ht-feedback-fab,
  #blazor-error-ui {
    display: none !important;
  }

  /* Room reserved for a bar that is no longer there. */
  .ht-mobile-content {
    padding-bottom: 0 !important;
  }

  /* Comments are a conversation ABOUT the document, not the document.
     Linked work is kept: "this page describes IT-38" is the sort of thing
     a printed copy is wanted for. */
  .summit-comments {
    display: none !important;
  }

  /* The live table keeps its note saying when it was true (summit-prose.css),
     but nothing in it should ever drag a page onto a second sheet by itself. */
  .summit-prose .summit-tasks { break-inside: avoid; }
}
