/*
 * Attestree — print stylesheet
 *
 * Drop-in target: src/Wep.ControlPlane.Web/wwwroot/css/print.css
 * Loaded after tokens.css with `media="print"` so it never affects screen render.
 *
 * Audit reality: people print evidence drawers, audit timelines, CVE matrix
 * pages, and policy decisions. We don't try to rebuild the screen layout — we
 * collapse to a single-column report with mono numbers, hard rules, and explicit
 * URL footnotes (since auditors print to PDF and lose hover-revealed deep-links).
 */

@media print {

  :root {
    /* Force light theme on print. Dark inverts ink-on-paper, which costs trees. */
    color-scheme: only light;
  }
  [data-theme="dark"] {
    /* Override every dark token back to light so dark-mode operators print sanely. */
    --wep-color-bg-0: #ffffff;
    --wep-color-bg-1: #ffffff;
    --wep-color-bg-2: #f5f5f5;
    --wep-color-bg-3: #ebebeb;
    --wep-color-fg-1: #000000;
    --wep-color-fg-2: #1a1a1a;
    --wep-color-fg-3: #4a4a4a;
    --wep-color-fg-4: #6a6a6a;
    --wep-color-border-1: #cccccc;
    --wep-color-border-2: #999999;
    --wep-color-accent-1: #000000;
    --wep-color-accent-bg: #f0f0f0;
    /* #1750 — the link role is its own token now; flatten it to ink alongside
     * accent-1 so a dark-mode operator's printout isn't pale blue on paper.
     * The underline (kept by .wep-link) carries the affordance in print. */
    --wep-color-link: #000000;
    --wep-color-link-hover: #000000;
    /* #1753 — the non-anchor accent-text role flattens to ink for the same
     * reason: pale blue tag/count text on paper is worse than black. */
    --wep-color-accent-text: #000000;
    /* #1764 — the labelled-fill role flattens to ink alongside accent-1, and
     * accent-fg MUST be forced back to paper-white here. Dark theme sets
     * accent-fg to bg-0's near-black ink (#0a0e17) so labels read on the bright
     * dark fill; without this override a dark-mode operator's printout would put
     * that ink on the #000000 flattened fill — an invisible button label. */
    --wep-color-accent-solid: #000000;
    --wep-color-accent-solid-hover: #000000;
    --wep-color-accent-fg: #ffffff;
    /* #1759 — the danger TEXT role flattens to ink for the same reason as the
     * link and accent-text roles above: pale crimson error text on paper is
     * worse than black, and the wording carries the meaning in print. */
    --wep-color-danger-text: #000000;

    /* #3326 — EVERY OTHER TOKEN THE DARK THEME SETS GOES BACK TO ITS LIGHT
     * VALUE. Until #3326 this block reset only the roles above, and the dark
     * theme's state ramps survived into print: an audit evidence page printed
     * from dark mode put its PERMIT pills in the dark clean ink (#6fcf97, about
     * 1.9:1 on white, where text needs 4.5:1), and the CVE page printed its KEV
     * banner as pink text on a near-black #2e1218 block. The light ramps are AA
     * against white, so on paper a dark-mode printout now reads as the light
     * one does wherever a state is drawn.
     *
     * The values below are tokens.css's :root (light) values, verbatim, and
     * PrintDarkOverrideCensusTests holds them there: every custom property the
     * dark block sets must be set here, and each one outside the deliberate
     * ink roles above must equal its light value, so the next token added to
     * the dark theme cannot print dark, and a light retune cannot leave print
     * behind. Grouped as tokens.css groups them. */
    --wep-color-bg-inv: #0f1724;
    --wep-color-fg-inv: #faf9f7;
    --wep-color-border-3: #0f1724;
    --wep-color-border-focus: #1f5fff;
    --wep-color-accent-2: #1849c4;

    --wep-state-clean-fg: #0d6b3a;
    --wep-state-clean-bg: #e3f4ea;
    --wep-state-clean-rule: #2c8c5a;
    --wep-state-detonating-fg: #5a3b00;
    --wep-state-detonating-bg: #fbefcf;
    --wep-state-detonating-rule: #b88410;
    --wep-state-sbomready-fg: #1f4d8a;
    --wep-state-sbomready-bg: #e3edfa;
    --wep-state-sbomready-rule: #356bb0;
    --wep-state-cveblocked-fg: #8a1729;
    --wep-state-cveblocked-bg: #fae3e7;
    --wep-state-cveblocked-rule: #c2304a;
    --wep-state-quarantined-fg: #5d4475;
    --wep-state-quarantined-bg: #efe6f4;
    --wep-state-quarantined-rule: #7d5a9c;
    --wep-state-promoted-fg: #0e4f5a;
    --wep-state-promoted-bg: #d7eef2;
    --wep-state-promoted-rule: #1c7886;
    --wep-state-rolledback-fg: #6b3a00;
    --wep-state-rolledback-bg: #fae3cf;
    --wep-state-rolledback-rule: #b85e10;

    --wep-state-recognizedconfident-fg: #0e7490;
    --wep-state-recognizedconfident-bg: #dcf3fa;
    --wep-state-recognizedconfident-rule: #1a8aa8;
    --wep-state-recognizedpossible-fg: #4a5a78;
    --wep-state-recognizedpossible-bg: #eaeef6;
    --wep-state-recognizedpossible-rule: #6478a0;
    --wep-state-held-fg: #7a5c00;
    --wep-state-held-bg: #fbf0cc;
    --wep-state-held-rule: #b08900;
    --wep-state-lastknownunverified-fg: #6b6152;
    --wep-state-lastknownunverified-bg: #f2efe9;
    --wep-state-lastknownunverified-rule: #9a8c72;
    --wep-state-notdriven-fg: #4f5b66;
    --wep-state-notdriven-bg: #e9edf1;
    --wep-state-notdriven-rule: #7d8a96;
    --wep-state-decommissioned-fg: #5c5750;
    --wep-state-decommissioned-bg: #eeece8;
    --wep-state-decommissioned-rule: #8f897f;
    --wep-state-notcheckingin-fg: #0b5f6b;
    --wep-state-notcheckingin-bg: #ddf3f5;
    --wep-state-notcheckingin-rule: #2a8c99;
    --wep-state-requiresusercontext-fg: #7d4a22;
    --wep-state-requiresusercontext-bg: #f8eee1;
    --wep-state-requiresusercontext-rule: #a5682e;
    --wep-state-withdrawnupstream-fg: #544c74;
    --wep-state-withdrawnupstream-bg: #ecebf3;
    --wep-state-withdrawnupstream-rule: #7a7196;
    --wep-state-appinusedeferred-fg: #55622a;
    --wep-state-appinusedeferred-bg: #f0f3e2;
    --wep-state-appinusedeferred-rule: #7c8a44;
    --wep-state-selfrejecting-fg: #6b6012;
    --wep-state-selfrejecting-bg: #f6f1cf;
    --wep-state-selfrejecting-rule: #998a1e;
    --wep-state-settling-fg: #2b5583;
    --wep-state-settling-bg: #dfeaf6;
    --wep-state-settling-rule: #4c7bab;
    --wep-state-uninstalllooping-fg: #7c2f5f;
    --wep-state-uninstalllooping-bg: #f8e8f2;
    --wep-state-uninstalllooping-rule: #a8517f;
    --wep-state-servedunverified-fg: #8a5a12;
    --wep-state-servedunverified-bg: #fdf7ea;
    --wep-state-servedunverified-rule: #c08a2d;

    --wep-color-warn-fg: #5a3b00;
    --wep-color-warn-bg: #fbefcf;
    --wep-color-danger: #e0364a;
    --wep-color-danger-fg: #ffffff;
    --wep-color-danger-bg: #b22338;
    --wep-color-danger-bg-hover: #8a1729;

    --wep-shadow-sm: 0 1px 0 0 rgb(15 23 36 / 0.04);
    --wep-shadow-pop: 0 8px 24px -8px rgb(15 23 36 / 0.18), 0 2px 4px -1px rgb(15 23 36 / 0.08);
    --wep-shadow-drawer: -16px 0 32px -16px rgb(15 23 36 / 0.22);
  }

  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt;
    line-height: 1.4;
  }

  /* Hide chrome that doesn't belong on paper. */
  .wep-ctxbar,
  .wep-nav,
  .wep-cmdk,
  .wep-theme-toggle,
  .wep-page-actions,
  .wep-table-controls,
  .wep-chip-row,
  button {
    display: none !important;
  }

  /* Collapse the app shell. */
  .wep-shell {
    display: block !important;
    height: auto !important;
  }
  .wep-main { overflow: visible !important; }

  /* Page header is the document header. */
  .wep-page-head {
    border-bottom: 2px solid #000 !important;
    padding: 0 0 8pt !important;
    margin: 0 0 12pt !important;
    background: transparent !important;
  }
  .wep-page-title {
    font-size: 18pt !important;
    font-weight: 600 !important;
  }
  .wep-page-meta {
    font-family: var(--wep-font-mono);
    font-size: 9pt !important;
    color: #4a4a4a !important;
  }

  /* Tables flatten; sticky headers become normal. */
  .wep-table thead th {
    position: static !important;
    background: #f5f5f5 !important;
    color: #000 !important;
    border-bottom: 1px solid #000 !important;
  }
  /* #2495: on screen the sticky header draws its rule as this pseudo-element
     (_shell.css). Printed, the header is static and the border above draws the
     rule, and a static cell is no containing block, so the box would anchor to
     the nearest positioned ancestor and print a stray line there. */
  .wep-table thead th::after { content: none !important; }
  .wep-table tbody td {
    border-bottom: 0.5pt solid #cccccc !important;
  }
  .wep-table tbody tr:hover { background: transparent !important; }

  /* Pills lose colour fills (printer toner is expensive); keep the text + outline.
     (They carry no leading dot since #4561 U3, so there is none to hide.) */
  .wep-pill {
    background: transparent !important;
    border: 0.5pt solid currentColor !important;
    padding: 0 4pt !important;
  }

  /* Drawer becomes inline content (auditors don't print pop-overs). */
  .wep-drawer {
    position: static !important;
    width: auto !important;
    box-shadow: none !important;
    border: 1pt solid #000 !important;
    margin: 12pt 0 !important;
    page-break-inside: avoid;
  }

  /* Code blocks: smaller, monospace, full-width. */
  .wep-code {
    background: #f5f5f5 !important;
    border: 0.5pt solid #999 !important;
    font-size: 9pt !important;
    page-break-inside: avoid;
  }

  /* Reveal URL behind every link (auditors lose hover-targets in PDFs). */
  a[href]:not([href^="#"]):not([href^="mailto:"])::after {
    content: " (" attr(href) ")";
    font-family: var(--wep-font-mono);
    font-size: 8pt;
    color: #4a4a4a;
    word-break: break-all;
  }

  /* Avoid orphaning a section heading at the end of a page. */
  h1, h2, h3, .wep-section-title { page-break-after: avoid; }
  .wep-banner, .step, .step-body { page-break-inside: avoid; }

  /* Page setup. */
  @page {
    size: A4;
    margin: 18mm 14mm 18mm 14mm;
  }
  @page :first {
    margin-top: 24mm;
  }

  /* Footer with the deep-link path on every page (CSS print headers/footers
     vary across browsers; production build ships a server-side render of the
     header into a fixed-position element, so this rule is the fallback). */
  body::after {
    content: "Wep · " attr(data-print-path) " · " attr(data-print-ts);
    position: fixed;
    bottom: 8mm;
    left: 14mm;
    right: 14mm;
    font-family: var(--wep-font-mono);
    font-size: 8pt;
    color: #4a4a4a;
    border-top: 0.5pt solid #cccccc;
    padding-top: 4pt;
  }

  /* #4561 U4 — a timestamp's relative half ("· 4 m") is stale before the page
     is read on paper, so print keeps the absolute ISO stamp only, as the footer
     above does. WepTime renders the relative half as its one inner span. */
  .wep-time > span {
    display: none;
  }
}
