/* Sentinel v2 - paper.css
   THE PAPER (the Insight spec, 5.8: the PDF is the page printed). The Document page's own renderer (parsed-view.js, Preview) and its
   own stylesheets (styles.css, v2/document.css) set on paper: the export window's live preview of the first page (v2/wordexport.js),
   the PDF the server prints (backend/doc_paper.py writes a print page; v2/docprint.js draws it) and Ctrl+P on the Document page
   (v2/document.js beforeprint). One stylesheet for the three, so the preview is honestly what the files look like.

   THE PAPER SCOPE is `.v2-paper` - the preview's sheet (.vx-page), the print page's #app, the Document's layout while it prints. It
   is a parchment theme scope (`v2-theme-scope` data-theme="parchment", v2/tokens.css): the contract's words in ink on white
   whatever the reader's theme, the page's own inks and hairlines read from the tokens - never a colour of its own. Its measures are
   the renderer's variables set to Word's print measures (v2/paper.js previewVars: 11 pt on an exact 16 pt line, gutters 36 / 69 /
   87 pt), so the PDF and the .docx paginate alike.

   WHAT NEVER PRINTS: only the contract's words go on paper. The page's own labels and controls - the "Execution / Authorised
   signatures" kicker, the Appendix / Signature / Party / Date / Location tags, "Table", the counts strip (the upload's file name and
   counts), "set by you", "Edit parties", "Your earlier note", a parse warning, the note markers, the history marks, the editing
   chrome, finding bars and evidence marks - are not the document. The facts line prints only when chosen (`.paper-cover`).

   Every look rule is scoped `:is(.app.v2-paper, .app .v2-paper)` - the print page's #app is itself the scope, the preview's sheet
   sits inside the app - which weighs what document.css's `.app .parsed-doc ...` weighs plus one class: the paper wins wherever it
   is, and nothing here reaches the screen's Document page. The pagination rules are print only. */

/* ---------------------------------------------------------------- the scope: ink on white, the page's hairline strong enough to print */
.v2-paper {
  color-scheme: light;
  --v2d-ink-1: var(--ink-1);
  --v2d-ink-2: var(--ink-2);
  --v2d-ink-3: var(--ink-3);
  --v2d-line: var(--line-3);
  --v2d-text: var(--ink-1);
  --v2d-paper: var(--surface-card);
  --v2d-edge: transparent;
  --v2d-lift: none;
}

/* ---------------------------------------------------------------- the paper's look (screen and print alike) */
:is(.app.v2-paper, .app .v2-paper) .parsed-doc { font-size: var(--font-doc-size); color: var(--v2d-text); background: transparent; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc h1.parsed-title { font-size: var(--vx-title, 19.5px); line-height: 1.25; max-width: none; margin: 0 auto .3em; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .parsed-parties { font-size: var(--vx-parties, 14px); line-height: 1.5; margin-bottom: 1.6em; }
/* the page's labels and tools: not the contract's words */
:is(.app.v2-paper, .app .v2-paper) .parsed-doc :is(.parsed-meta:not(.paper-cover), .pp-edit, .pp-tag, .pp-note, .parsed-warnings,
  .seg-comment-marker, .vr-hmark, .pb-table-label, .v2d-dock, .v2d-margin, .pb-signature-head, .pb-tag, .pb-toolbar, .pb-align,
  .pb-add-after, .draft-return-pill) { display: none; }
/* the facts line, when chosen: the page's facts strip - one quiet centred line between two hairlines, the sure facts only */
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .parsed-meta.paper-cover {
  display: block; margin: -.6em 0 1.8em; padding: .35em 0 .3em; border-top: .5pt solid var(--line-3); border-bottom: .5pt solid var(--line-3);
  font-family: var(--font-doc); font-size: var(--vx-cover, 11.7px); line-height: 1.5; text-align: center; color: var(--ink-3);
  font-variant-numeric: lining-nums tabular-nums;
}
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb { text-align: var(--vx-align, justify); scroll-margin: 0; }
:is(.app.v2-paper, .app .v2-paper)[data-align="left"] .parsed-doc .pb { hyphens: manual; -webkit-hyphens: manual; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb:hover { background: none; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb::before { content: none; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-section { font-size: var(--vx-heading, 13.5px); letter-spacing: var(--vx-tracking, .07em); margin-top: 1.9em; }
:is(.app.v2-paper, .app .v2-paper)[data-rules="off"] .parsed-doc .pb-section { background-image: none; }
/* PAPER IS NARROWER THAN A PHONE'S BREAKPOINT: A4's text column is 604 px, and the page's own rules for a narrow screen (styles.css
   and v2/document.css under max-width 760 / 720 px - a sub-clause stepped in by 1 rem, the signature columns stacked into one)
   would apply on paper too. The paper keeps the page's desktop distances and its columns, as the Word file does. */
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-clause.is-sub { margin-left: calc(-12px + var(--v2d-gutter)); padding-left: calc(12px + var(--v2d-sub)); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-clause.is-bullet { margin-left: calc(-12px + var(--v2d-gutter) + var(--v2d-sub)); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-layout { grid-template-columns: repeat(var(--sig-cols, 2), minmax(0, 1fr)); row-gap: 0; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-clause.is-bullet { padding-left: calc(12px + var(--vx-bullet, 1.5rem)); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-clause.is-bullet > .pb-num { width: calc(var(--vx-bullet, 1.5rem) - 6px); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-table { font-size: var(--vx-table, 13.5px); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .parsed-blocks > .pb:first-child { margin-top: 0; }
/* signature blocks side by side as the Word file sets them: no boxes, one hairline over the zone, the signing rule under each
   column, the page's sizes as shares of the text's (word_export style_map "signature") */
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-zone { margin: 1.4em 0 1em; padding-top: .95em; border-top: .75pt solid var(--line-3); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-layout { gap: 0 21pt; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-col { padding: 0; border: 0; border-radius: 0; background: none; }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-line { font-size: calc(var(--font-doc-size) * .8333); line-height: 1.36; color: var(--ink-1); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-line.is-role { font-size: calc(var(--font-doc-size) * .7333); color: var(--ink-3); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-line.is-entity { font-size: calc(var(--font-doc-size) * .7667); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-line.is-meta { font-size: calc(var(--font-doc-size) * .7867); color: var(--ink-2); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-caption { color: var(--ink-2); }
:is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-signature-rule { height: 13.5pt; margin: 6pt 0 3pt; border-bottom: .75pt solid var(--ink-4); }

/* ---------------------------------------------------------------- the print page itself (backend/doc_paper.py): white, no frame */
/* the app's own page is one fixed screen (styles.css: html, body 100 % high, overflow hidden; .app a grid one screen tall): the print
   page is a document as long as the contract, every page of it laid out */
html.paper-html, html.paper-html > body { height: auto; min-height: 0; overflow: visible; margin: 0; padding: 0; background: var(--surface-card); }
.app.is-paper { display: block; min-height: 0; height: auto; background: var(--surface-card); color: var(--ink-1); }
.app.is-paper .draft-layout { display: block; max-width: none; margin: 0; padding: 0; background: none; }
.app.is-paper .draft-layout > .parsed-doc { width: auto; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: none; }
/* the draft mark: faint, diagonal, behind the words, on every page (Chromium repeats a fixed box on each printed page); never on a
   Signed version (the server - or, for Ctrl+P, v2/document.js - leaves data-mark off) */
.app.is-paper[data-mark="on"]::after {
  content: attr(data-mark-word);
  position: fixed; left: 50%; top: 50%; z-index: -1;
  transform: translate(-50%, -50%) rotate(-45deg);
  font: 600 110pt/1 var(--font-doc); letter-spacing: .12em; white-space: nowrap;
  color: var(--line-3); opacity: .5; pointer-events: none;
}

/* ---------------------------------------------------------------- paper: the pages (print only - the PDF and Ctrl+P) */
@media print {
  /* the sheet on paper has no frame, no desk and no padding of its own: the @page margins are the paper's (v2/paper.js pageCss) */
  .app .mode-stage:has(> .draft-layout.v2-paper) { background: none; }
  .app .draft-layout.v2-paper { padding: 0; background: none; }
  .app .v2-paper.draft-layout > .parsed-doc, .app.is-paper .draft-layout > .parsed-doc {
    width: auto; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; box-shadow: none; background: none;
  }
  /* a heading, a ':' stem and the lead-in line never end a page: each keeps with what it opens */
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc :is(.pb-section, .pb-subsection:not(.is-prose), .pb-appendix, .pb.is-stem, .pb-paragraph.is-lead) { break-after: avoid; }
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc :is(.pb-section, .pb-subsection, .pb-appendix) { break-inside: avoid; }
  /* a clause may split, but never leaves a single line behind or ahead */
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb { orphans: 2; widows: 2; }
  /* a signature zone and each party's column stay whole (a zone taller than a page still splits) */
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc :is(.pb-signature-zone, .pb-signature-col) { break-inside: avoid; }
  /* a long table: its first row repeats on every page it runs onto, and no row is cut in two */
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-table thead { display: table-header-group; }
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-table tr { break-inside: avoid; }
  /* a table Word turns landscape prints on the named landscape page (word_export.wide_table_ids, v2/docprint.js marks it) */
  :is(.app.v2-paper, .app .v2-paper) .parsed-doc .pb-table-host.is-wide { page: wide; }
  /* appendices on a new page: one page break before each run of appendix headings, as in Word (never before the first block) */
  :is(.app.v2-paper, .app .v2-paper)[data-appx="on"] .parsed-doc .parsed-blocks > :is(.pb-appendix, .pb-section.is-appendix):not(:first-child):not(:is(.pb-appendix, .pb-section.is-appendix) + *) { break-before: page; }
  /* the evidence marks a finding paints (the CSS Custom Highlight API) are the reader's, not the document's */
  ::highlight(v2d-ev-critical), ::highlight(v2d-ev-high), ::highlight(v2d-ev-medium), ::highlight(v2d-ev-low) { background-color: transparent; }
  /* CTRL+P ON THE DOCUMENT PAGE prints this paper: the app's chrome, the Overview panel, the outline and its ruler, the margin
     cards, Askbot, the finding bars and the original beside the text are left on the screen */
  .v2-side, .v2-top, .v2-tabbar, .v2-skip, .v2-ovp, .v2d-dock, .v2d-margin, .draft-return-pill, .draft-compare-orig,
  .v2ab, .v2-toaster { display: none !important; }
  .app .draft-layout.v2-paper .parsed-doc .pb[data-v2-sev]::before, .app .draft-layout.v2-paper .parsed-doc .pb.is-v2-landed::after { content: none; }
  .app .draft-layout.v2-paper .parsed-doc .pb { background: none; }
  /* the Document's own draft mark, as the PDF's (on paper only: never over the screen while the print dialog is open) */
  .app .draft-layout.v2-paper[data-mark="on"]::after {
    content: attr(data-mark-word);
    position: fixed; left: 50%; top: 50%; z-index: -1;
    transform: translate(-50%, -50%) rotate(-45deg);
    font: 600 110pt/1 var(--font-doc); letter-spacing: .12em; white-space: nowrap;
    color: var(--line-3); opacity: .5; pointer-events: none;
  }
}
