/* Business-document renderer.
 *
 * The preview is white paper even though the site chrome is dark: it is a
 * document, and it must look like one. The editor sits on the site's surface
 * around it.
 *
 * One stylesheet, ten themes. A theme is a set of custom properties on the
 * preview root plus a few structural overrides; the markup is identical for all
 * ten, which is what lets one renderer draw every document.
 *
 * Print is the browser's: `@page` sizes the sheet to A4, and the print block
 * hides the editor and the application chrome so only the document is emitted.
 */

.doc-builder {
    display: grid;
    gap: 1.5rem;
}

@media (min-width: 1100px) {
    .doc-builder {
        grid-template-columns: minmax(320px, 26rem) minmax(0, 1fr);
        align-items: start;
    }
}

/* ── Editor ─────────────────────────────────────────────────────────────── */

.doc-controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.doc-preview-host {
    overflow-x: auto;
    min-width: 0;
}

.doc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.doc-editor,
.doc-toolbar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.doc-editor {
    border: 1px solid var(--color-border, #2a2a2e);
    padding: 1rem;
}

.doc-toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.75rem;
}

.doc-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.doc-field > label,
.doc-fieldset > legend {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--color-muted-foreground, #a1a1aa);
}

.doc-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
    gap: 0.75rem;
}

.doc-builder input,
.doc-builder select,
.doc-builder textarea {
    min-height: 44px;
    width: 100%;
    border: 1px solid var(--color-border, #2a2a2e);
    background: var(--color-background, #101012);
    color: var(--color-foreground, #f4f4f5);
    padding: 0.5rem 0.65rem;
    font: inherit;
    font-size: 0.9rem;
}

.doc-builder textarea {
    min-height: 4.5rem;
    resize: vertical;
}

.doc-builder input:focus-visible,
.doc-builder select:focus-visible,
.doc-builder textarea:focus-visible,
.doc-builder button:focus-visible,
.letter-builder button:focus-visible {
    outline: 2px solid var(--color-primary, #7dd3fc);
    outline-offset: 2px;
}

.doc-builder button,
.letter-builder button {
    min-height: 44px;
    padding: 0 1rem;
    border: 1px solid var(--color-border, #2a2a2e);
    background: transparent;
    color: var(--color-foreground, #f4f4f5);
    font-weight: 600;
    cursor: pointer;
}

.doc-builder button:hover,
.letter-builder button:hover {
    border-color: var(--color-primary, #7dd3fc);
    color: var(--color-primary, #7dd3fc);
}

.doc-builder button.doc-primary,
.letter-builder button.doc-primary {
    background: var(--color-primary, #7dd3fc);
    border-color: var(--color-primary, #7dd3fc);
    color: var(--color-on-primary, #0b0b0c);
}

.doc-lines {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.doc-line {
    display: grid;
    /* The builder sets the real track list on each row from the spec's columns
       (`lineTemplate`); this is the fallback for a wide table. */
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
    gap: 0.5rem;
    align-items: end;
}

.doc-line .doc-remove {
    padding: 0;
    width: 2.75rem;
    font-size: 1.1rem;
    line-height: 1;
}

.doc-line-total {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 0.65rem;
    border: 1px dashed var(--color-border, #2a2a2e);
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
}

.doc-hint {
    margin: 0;
    font-size: 0.75rem;
    color: var(--color-muted-foreground, #a1a1aa);
}

/* ── Theme picker ───────────────────────────────────────────────────────── */

.doc-fieldset {
    border: 0;
    margin: 0;
    padding: 0;
    min-width: 0;
}

.doc-themes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
    gap: 0.5rem;
    margin-top: 0.4rem;
}

.doc-theme-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--color-border, #2a2a2e);
    cursor: pointer;
    font-size: 0.8rem;
}

.doc-theme-option:has(input:checked) {
    border-color: var(--color-primary, #7dd3fc);
    color: var(--color-primary, #7dd3fc);
}

.doc-theme-option input {
    min-height: 0;
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-primary, #7dd3fc);
}

/* ── The document ───────────────────────────────────────────────────────── */

.doc-preview {
    --doc-ink: #14161a;
    --doc-muted: #5c6470;
    --doc-accent: #1d3f8f;
    --doc-rule: #d5d9e0;
    --doc-wash: #f4f6fa;
    --doc-heading-font: Georgia, "Times New Roman", serif;
    --doc-body-font: "Helvetica Neue", Arial, sans-serif;
    --doc-heading-weight: 700;
    --doc-heading-tracking: 0;
    --doc-heading-transform: none;
    --doc-radius: 0;
    --doc-rule-weight: 1px;

    box-sizing: border-box;
    width: 210mm;
    min-height: 297mm;
    max-width: 100%;
    margin: 0 auto;
    padding: 14mm;
    background: #ffffff;
    color: var(--doc-ink);
    font-family: var(--doc-body-font);
    font-size: 10.5pt;
    line-height: 1.5;
    box-shadow: 0 0 0 1px rgb(0 0 0 / 12%), 0 24px 60px rgb(0 0 0 / 45%);
}

.doc-preview * {
    box-sizing: border-box;
}

.doc-head {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    padding-bottom: 1.25rem;
    border-bottom: var(--doc-rule-weight) solid var(--doc-rule);
}

.doc-business {
    margin: 0;
    font-family: var(--doc-heading-font);
    font-size: 1.35rem;
    font-weight: var(--doc-heading-weight);
    letter-spacing: var(--doc-heading-tracking);
    text-transform: var(--doc-heading-transform);
}

.doc-title {
    margin: 0.35rem 0 0;
    font-family: var(--doc-heading-font);
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--doc-muted);
}

.doc-meta {
    display: grid;
    gap: 0.35rem;
    margin: 0;
    min-width: 13rem;
    text-align: right;
}

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

.doc-meta dt {
    color: var(--doc-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.doc-meta dd {
    margin: 0;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

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

.doc-party h2,
.doc-block h2 {
    margin: 0 0 0.35rem;
    font-family: var(--doc-heading-font);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--doc-accent);
}

.doc-party p {
    margin: 0;
    white-space: pre-line;
}

.doc-lines-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5rem 0 1rem;
}

.doc-lines-table th {
    padding: 0.55rem 0.5rem;
    border-bottom: calc(var(--doc-rule-weight) * 2) solid var(--doc-ink);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    text-align: left;
    color: var(--doc-ink);
}

.doc-lines-table td {
    padding: 0.55rem 0.5rem;
    border-bottom: var(--doc-rule-weight) solid var(--doc-rule);
    vertical-align: top;
}

.doc-lines-table .doc-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.doc-lines-table tbody tr:nth-child(even) {
    background: var(--doc-wash);
}

.doc-summary {
    display: flex;
    justify-content: flex-end;
    margin: 0.5rem 0 1rem;
}

.doc-summary dl {
    display: grid;
    grid-template-columns: auto minmax(7rem, auto);
    gap: 0.35rem 1.5rem;
    margin: 0;
    min-width: 16rem;
}

.doc-summary dt {
    color: var(--doc-muted);
    text-align: right;
}

.doc-summary dd {
    margin: 0;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.doc-summary .doc-grand {
    padding-top: 0.5rem;
    border-top: var(--doc-rule-weight) solid var(--doc-ink);
    font-size: 1.05rem;
}

.doc-blocks {
    display: grid;
    gap: 1rem;
    padding-top: 0.75rem;
    border-top: var(--doc-rule-weight) solid var(--doc-rule);
}

.doc-block p {
    margin: 0;
    white-space: pre-line;
    color: var(--doc-muted);
}

.doc-foot {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-top: 2rem;
}

.doc-signature {
    min-width: 12rem;
    padding-top: 2.5rem;
    border-top: var(--doc-rule-weight) solid var(--doc-ink);
    font-size: 0.8rem;
    color: var(--doc-muted);
}

.doc-empty {
    margin: 0;
    padding: 1rem 0;
    color: var(--doc-muted);
    font-style: italic;
}

/* ── Ten themes ─────────────────────────────────────────────────────────── */

.doc-theme-classic-business {
    --doc-accent: #1d3f8f;
    --doc-heading-font: Georgia, "Times New Roman", serif;
    --doc-heading-weight: 700;
    --doc-heading-tracking: 0;
    --doc-heading-transform: none;
}

.doc-theme-modern-clean {
    --doc-accent: #0f766e;
    --doc-rule: #dbe4e2;
    --doc-wash: #f2f8f6;
    --doc-heading-font: "Helvetica Neue", Arial, sans-serif;
    --doc-heading-weight: 700;
    --doc-heading-tracking: -0.01em;
    --doc-heading-transform: none;
    --doc-radius: 6px;
}

.doc-theme-modern-clean .doc-head {
    border-bottom-width: 3px;
    border-bottom-color: var(--doc-accent);
}

.doc-theme-minimal-black-white {
    --doc-ink: #000000;
    --doc-muted: #555555;
    --doc-accent: #000000;
    --doc-rule: #000000;
    --doc-wash: transparent;
    --doc-rule-weight: 1px;
    --doc-heading-font: Georgia, "Times New Roman", serif;
    --doc-heading-weight: 400;
    --doc-heading-tracking: 0.02em;
    --doc-heading-transform: none;
}

.doc-theme-minimal-black-white .doc-lines-table tbody tr:nth-child(even) {
    background: transparent;
}

.doc-theme-bold-branded {
    --doc-ink: #16110c;
    --doc-muted: #6b5b4c;
    --doc-accent: #d4481f;
    --doc-rule: #f0d9cf;
    --doc-wash: #fdf0ea;
    --doc-heading-font: "Arial Black", "Helvetica Neue", sans-serif;
    --doc-heading-weight: 900;
    --doc-heading-tracking: -0.02em;
    --doc-heading-transform: uppercase;
}

.doc-preview.doc-theme-bold-branded {
    border-top: 10px solid var(--doc-accent);
}

.doc-theme-bold-branded .doc-head {
    border-bottom: 2px solid var(--doc-ink);
    padding-top: 1rem;
}

.doc-theme-premium-corporate {
    --doc-ink: #241417;
    --doc-muted: #6d5a5e;
    --doc-accent: #7b1e2b;
    --doc-rule: #d8c6a6;
    --doc-wash: #fbf7ef;
    --doc-heading-font: "Palatino Linotype", Palatino, Georgia, serif;
    --doc-heading-weight: 700;
    --doc-heading-tracking: 0.03em;
    --doc-heading-transform: none;
}

.doc-theme-premium-corporate .doc-head {
    border-bottom: 3px double var(--doc-rule);
}

.doc-theme-retail-style {
    --doc-ink: #1f2933;
    --doc-muted: #52606d;
    --doc-accent: #c2410c;
    --doc-rule: #f3d7c3;
    --doc-wash: #fff7ed;
    --doc-heading-font: "Trebuchet MS", Verdana, sans-serif;
    --doc-heading-weight: 700;
    --doc-heading-tracking: 0;
    --doc-heading-transform: none;
    --doc-radius: 10px;
}

.doc-theme-retail-style .doc-summary dl {
    padding: 0.75rem 1rem;
    border: 2px dashed var(--doc-accent);
    border-radius: var(--doc-radius);
}

.doc-theme-contractor-style {
    --doc-ink: #111111;
    --doc-muted: #4b4b4b;
    --doc-accent: #b77900;
    --doc-rule: #111111;
    --doc-wash: #fffbeb;
    --doc-heading-font: "Arial Narrow", Arial, sans-serif;
    --doc-heading-weight: 700;
    --doc-heading-tracking: 0.04em;
    --doc-heading-transform: uppercase;
    --doc-rule-weight: 2px;
}

.doc-theme-contractor-style .doc-lines-table th {
    background: var(--doc-ink);
    color: #ffffff;
    border-bottom-color: var(--doc-ink);
}

.doc-theme-service-company-style {
    --doc-ink: #102a2a;
    --doc-muted: #4a6566;
    --doc-accent: #047857;
    --doc-rule: #cfe3dd;
    --doc-wash: #ecf7f3;
    --doc-heading-font: "Segoe UI", "Helvetica Neue", sans-serif;
    --doc-heading-weight: 600;
    --doc-heading-tracking: 0;
    --doc-heading-transform: none;
    --doc-radius: 8px;
}

.doc-theme-service-company-style .doc-head {
    padding: 1rem;
    margin: -0.5rem -0.5rem 0;
    background: var(--doc-wash);
    border-radius: var(--doc-radius);
    border-bottom: 0;
}

.doc-theme-elegant-letterhead {
    --doc-ink: #1b1a17;
    --doc-muted: #6e685e;
    --doc-accent: #8a6d3b;
    --doc-rule: #cbb98f;
    --doc-wash: #faf7f0;
    --doc-heading-font: "Didot", "Bodoni MT", Georgia, serif;
    --doc-heading-weight: 400;
    --doc-heading-tracking: 0.22em;
    --doc-heading-transform: uppercase;
}

.doc-theme-elegant-letterhead .doc-head {
    flex-direction: column;
    align-items: center;
    text-align: center;
    border-bottom-width: 1px;
    border-bottom-color: var(--doc-accent);
}

.doc-theme-elegant-letterhead .doc-meta {
    justify-items: center;
    text-align: center;
}

.doc-theme-elegant-letterhead .doc-meta div {
    justify-content: center;
    gap: 0.5rem;
}

.doc-theme-tax-invoice-style {
    --doc-ink: #0b1220;
    --doc-muted: #4b5563;
    --doc-accent: #0b1220;
    --doc-rule: #c7ccd4;
    --doc-wash: #eef1f5;
    --doc-heading-font: "Courier New", Courier, monospace;
    --doc-heading-weight: 700;
    --doc-heading-tracking: 0;
    --doc-heading-transform: uppercase;
    --doc-rule-weight: 1px;
}

.doc-theme-tax-invoice-style .doc-head,
.doc-theme-tax-invoice-style .doc-blocks {
    border: 1px solid var(--doc-rule);
    padding: 0.75rem;
}

.doc-theme-tax-invoice-style .doc-lines-table th {
    background: var(--doc-wash);
    border: 1px solid var(--doc-rule);
}

.doc-theme-tax-invoice-style .doc-lines-table td {
    border: 1px solid var(--doc-rule);
}

.doc-theme-tax-invoice-style .doc-summary dl {
    padding: 0.75rem;
    border: 1px solid var(--doc-rule);
}


/* ── Fill-in-a-sample documents ─────────────────────────────────────────── */

/* The five letters and the salary slip of `document-format-cluster`. They are
   rendered by `static/js/documents/letter.js` from the text a skill returned,
   and they reuse `.doc-preview` — the paper box defined above — so the page
   size and the single print section in `documents-formats.css` apply to them
   without a second print path or a second stylesheet.

   The mount is not `.doc-builder`: that class is a two-column editor/preview
   grid, and these pages have no editor of their own (the shared skill form
   above them is the editor). The buttons are the same buttons, which is why the
   selectors above name `.letter-builder` beside `.doc-builder`. */
.letter-builder {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

/* `hidden` is a UA rule with almost no specificity, so any class here that sets
   `display` (`.doc-toolbar` does) would win over it and show a toolbar before
   there is a document to print. This is the one rule that keeps the attribute
   meaning what it says. */
.letter-builder [hidden] {
    display: none !important;
}

.doc-letter {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-family: var(--doc-heading-font);
    font-size: 11.5pt;
    line-height: 1.55;
    color: var(--doc-ink);
}

/* A salary slip's columns are aligned with spaces by the skill, so it sets in a
   monospace face or the amounts do not line up with their labels. */
.doc-preview.doc-kind-slip .doc-letter {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9.5pt;
    line-height: 1.45;
}
