/* Batch-2 page boxes, the four special layouts, the sheet and print — the
 * second half of documents.css.
 *
 * Loads after `documents.css` and only with it (the document builder partial
 * links both in order), so the cascade is the uncut file's: the unnamed A4
 * `@page` and the ten themes come first, these page boxes and the print block
 * after, exactly as before the split. Contents: Named page boxes
 * (business-document-batch-2), Card, Certificate, Label, Bulk, Sheet layout,
 * Print.
 */
/* ── Named page boxes (business-document-batch-2) ────────────────────────── */

/* `@page` cannot be scoped by a selector, so a layout that needs its own stock
   declares a *named* page and points itself at it with `page:`. The unnamed
   `@page` below stays A4 and still governs every document and sheet.

   The `page:` property is set on `html` (through `:has()`) rather than only on
   `.doc-preview` because the print block takes the preview out of flow
   (`position: absolute`), and a page name is taken from the first *in-flow*
   box. The preview's own `page:` is kept too: it is the declaration that
   computes on the element a reader inspects, and it is what a stylesheet
   review reads. */
@page doc-card {
    size: 85mm 55mm;
    margin: 4mm;
}

@page doc-label {
    size: 70mm 40mm;
    margin: 3mm;
}

@page doc-certificate {
    size: A4 landscape;
    margin: 12mm;
}

/* A bulk document prints on A4, but with the letterhead's generous margin
   removed so the record blocks start at the edge of the sheet. */
@page doc-bulk {
    size: A4;
    margin: 10mm;
}

.doc-layout-card {
    page: doc-card;
}

.doc-layout-label {
    page: doc-label;
}

.doc-layout-certificate {
    page: doc-certificate;
}

.doc-layout-bulk {
    page: doc-bulk;
}

/* The page name must reach an in-flow box, and the print block below takes the
   preview out of flow, so the root carries it as well. These rules sit outside
   any media query on purpose: `page` is inert on screen, and a second print
   media block would be a second print path. */
html:has(.doc-preview.doc-layout-card) {
    page: doc-card;
}

html:has(.doc-preview.doc-layout-label) {
    page: doc-label;
}

html:has(.doc-preview.doc-layout-certificate) {
    page: doc-certificate;
}

html:has(.doc-preview.doc-layout-bulk) {
    page: doc-bulk;
}

/* ── Card: 85 × 55 mm, three labelled extras, no table, no totals ────────── */

.doc-layout-card {
    width: 85mm;
    min-height: 55mm;
    padding: 5mm;
    font-size: 8pt;
    line-height: 1.35;
}

.doc-layout-card .doc-head {
    gap: 3mm;
    padding-bottom: 2mm;
}

.doc-layout-card .doc-business {
    font-size: 0.95rem;
}

.doc-layout-card .doc-title {
    margin-top: 0.15rem;
    font-size: 0.58rem;
    letter-spacing: 0.1em;
}

.doc-layout-card .doc-meta {
    min-width: 0;
    gap: 0.15rem;
    text-align: left;
    font-size: 0.68rem;
}

.doc-layout-card .doc-meta div {
    justify-content: flex-start;
    gap: 0.4rem;
}

.doc-layout-card .doc-extra dt {
    min-width: 2.6rem;
}

.doc-layout-card .doc-parties {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding: 3mm 0 0;
}

/* The issuer is already the head of the card; repeating it as a party block
   spends a third of the stock on the same name. */
.doc-layout-card .doc-party:nth-child(2) {
    display: none;
}

.doc-layout-card .doc-party p {
    font-size: 1rem;
    font-weight: 700;
}

.doc-layout-card .doc-lines-table,
.doc-layout-card .doc-summary {
    display: none;
}

.doc-layout-card .doc-blocks {
    padding-top: 2mm;
    font-size: 0.68rem;
}

/* ── Certificate: A4 landscape, centred, one achievement line ────────────── */

.doc-layout-certificate {
    width: 297mm;
    min-height: 210mm;
    padding: 20mm;
    text-align: center;
}

.doc-layout-certificate .doc-head {
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1.5rem;
}

.doc-layout-certificate .doc-meta {
    justify-items: center;
    min-width: 0;
    text-align: center;
}

.doc-layout-certificate .doc-meta div {
    justify-content: center;
    gap: 0.5rem;
}

.doc-layout-certificate .doc-parties {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.5rem;
    padding: 1.5rem 0 2rem;
}

.doc-layout-certificate .doc-party:nth-child(2) {
    display: none;
}

.doc-layout-certificate .doc-party h2 {
    font-size: 0.8rem;
}

.doc-layout-certificate .doc-party p {
    font-family: var(--doc-heading-font);
    font-size: 2.4rem;
    font-weight: var(--doc-heading-weight);
    line-height: 1.2;
}

.doc-layout-certificate .doc-lines-table,
.doc-layout-certificate .doc-summary {
    display: none;
}

.doc-layout-certificate .doc-blocks {
    justify-items: center;
    gap: 1.25rem;
    border-top: 0;
}

.doc-layout-certificate .doc-block p {
    font-size: 1rem;
    color: var(--doc-ink);
}

.doc-layout-certificate .doc-foot {
    justify-content: center;
    margin-top: 3rem;
}

.doc-layout-certificate .doc-signature {
    min-width: 80mm;
    text-align: center;
}

/* ── Label: 70 × 40 mm shelf tag, price prominent, no table, no totals ───── */

.doc-layout-label {
    width: 70mm;
    min-height: 40mm;
    padding: 3mm;
    font-size: 6.5pt;
    line-height: 1.2;
}

.doc-layout-label .doc-head {
    gap: 2mm;
    padding-bottom: 1mm;
}

.doc-layout-label .doc-business {
    font-size: 0.62rem;
    line-height: 1.15;
}

.doc-layout-label .doc-title {
    margin-top: 0.05rem;
    font-size: 0.48rem;
    letter-spacing: 0.08em;
}

.doc-layout-label .doc-meta {
    min-width: 0;
    gap: 0.05rem;
    text-align: right;
    font-size: 0.55rem;
    line-height: 1.2;
}

.doc-layout-label .doc-meta div {
    gap: 0.3rem;
}

/* The base `.doc-meta dt` sets 0.78rem directly on the element, so the label's
   smaller meta block must name the child too — inheritance alone loses to a
   declaration. Seven rows at the base size are what would push a 70×40 tag
   onto a second page. */
.doc-layout-label .doc-meta dt,
.doc-layout-label .doc-meta dd {
    font-size: 0.52rem;
    line-height: 1.2;
}

.doc-layout-card .doc-meta dt,
.doc-layout-card .doc-meta dd {
    font-size: 0.62rem;
    line-height: 1.25;
}

.doc-layout-label .doc-parties {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.25rem;
    padding: 1mm 0;
}

.doc-layout-label .doc-party:nth-child(2) {
    display: none;
}

.doc-layout-label .doc-party h2 {
    margin-bottom: 0.05rem;
    font-size: 0.46rem;
}

.doc-layout-label .doc-party p {
    font-size: 0.75rem;
    font-weight: 700;
}

/* The tag's one job is to show the price. It is the largest element on the
   stock, and the only one that may be. */
.doc-layout-label .doc-extra-price dd {
    font-family: var(--doc-heading-font);
    font-size: 1.35rem;
    font-weight: 800;
    line-height: 1.05;
    color: var(--doc-ink);
}

.doc-layout-label .doc-lines-table,
.doc-layout-label .doc-summary {
    display: none;
}

.doc-layout-label .doc-blocks {
    padding-top: 1mm;
    font-size: 0.6rem;
}

/* ── Bulk: one record block, repeated, on A4 without letterhead spacing ──── */

.doc-layout-bulk {
    padding: 10mm;
}

.doc-layout-bulk .doc-head {
    padding-bottom: 0.75rem;
}

.doc-bulk-records {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4mm;
    padding-top: 4mm;
}

.doc-bulk-record {
    display: flex;
    flex-direction: column;
    gap: 1.5mm;
    padding: 3mm;
    border: var(--doc-rule-weight) solid var(--doc-rule);
    break-inside: avoid;
    page-break-inside: avoid;
}

.doc-bulk-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1.5mm;
    border-bottom: var(--doc-rule-weight) solid var(--doc-rule);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--doc-muted);
}

.doc-bulk-meta {
    display: grid;
    gap: 0.2rem;
    margin: 0;
    font-size: 0.72rem;
}

.doc-bulk-meta div {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
}

.doc-bulk-meta dt {
    color: var(--doc-muted);
}

.doc-bulk-meta dd {
    margin: 0;
    font-weight: 600;
    text-align: right;
}

.doc-layout-bulk .doc-blocks {
    margin-top: 4mm;
}

/* ── Sheet layout ───────────────────────────────────────────────────────── */

/* A sheet is the same markup as a document: a heading, a table and a summary.
   What changes is the rhythm (a tighter row) and the hierarchy (the table is
   the document, so it is promoted above the party block). Declared after the
   themes so a theme's padding cannot undo the denser rhythm.

   Nothing here touches print: the print page is A4 for both layouts and the
   block below hides the same chrome, because both layouts are one
   `.doc-preview`. */
.doc-layout-sheet {
    display: flex;
    flex-direction: column;
    gap: 0;
    font-size: 10pt;
    line-height: 1.35;
}

.doc-layout-sheet .doc-head {
    order: 1;
    padding-bottom: 0.75rem;
}

.doc-layout-sheet .doc-lines-table {
    order: 2;
    margin: 0.25rem 0 0.5rem;
}

.doc-layout-sheet .doc-lines-table th,
.doc-layout-sheet .doc-lines-table td {
    padding: 0.3rem 0.4rem;
}

.doc-layout-sheet .doc-parties {
    order: 3;
    gap: 1rem;
    padding: 0.75rem 0;
}

.doc-layout-sheet .doc-summary {
    order: 4;
    margin: 0.25rem 0 0.5rem;
}

.doc-layout-sheet .doc-summary dl {
    gap: 0.2rem 1rem;
    min-width: 14rem;
}

.doc-layout-sheet .doc-blocks {
    order: 5;
    gap: 0.75rem;
}

.doc-layout-sheet .doc-foot {
    order: 6;
    margin-top: 1rem;
}

/* ── Print ──────────────────────────────────────────────────────────────── */

@page {
    size: A4;
    margin: 14mm;
}

@media print {
    html,
    body,
    #app,
    #main,
    .main-content,
    #tool-detail-page {
        background: #ffffff !important;
    }

    /* The document is the output. Everything else is the app that produced it. */
    header,
    footer,
    nav,
    .doc-editor,
    .doc-toolbar,
    .reviews-section,
    .sidebar-section,
    .tool-cta-card,
    .markdown-content,
    #credit-estimate-widget,
    [data-tool-faq],
    [data-tool-siblings],
    [data-tool-inverse],
    /* Server-rendered page chrome (`tool-page-copy-in-document`): the hero,
       the page-spec prose and the operator slot cards left the inert template
       and are now in the document, so the print rule has to name them instead
       of losing them for free with the template. */
    [data-tool-hero],
    [data-tool-copy],
    [data-page-slot],
    .doc-builder > noscript {
        display: none !important;
    }

    /* The document is the output; the page that hosts it is not. On the tool
       detail page the builder sits inside the shared tool surface, so every
       sibling of that surface — breadcrumb, hero, estimate, share bar, related
       links, notes, body copy, CTA — is removed from the print flow. `:has()`
       names the surface's parent without depending on a Tailwind class name. */
    #tool-detail-page :has(> [data-tool-surface]) > :not([data-tool-surface]) {
        display: none !important;
    }

    .doc-preview {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        min-height: 0;
        margin: 0;
        padding: 0;
        box-shadow: none;
        border: 0;
    }
}
