/*
 * The document generators (site/pages/free-tools/template.php, site/lib/free-tools.php): a template as a document, and
 * the print of a template. The engine's tool pages use ft-base.css and their family's file (ft-calc.css …) instead.
 * Loaded after site.css and features.css; tokens only (assets/css/nf/tokens.css), no colour value except in the
 * print block, where paper is white and ink is black.
 *
 *   1. Hub and page    .ft-hub__trade, .ft-toolbar(__status), .ft-privacy, .ft-picker > .ft-trades, .ft-links, .ft-notes
 *   2. Document        .ft-doc(--example) > .ft-doc__head (.ft-from with .ft-logo, .ft-meta), .ft-block > .ft-grid > .ft-f,
 *                      .ft-hint, .ft-sign
 *   3. Fields          .ft-f(--wide) > .ft-f__label + .ft-in(--area|--num) | .ft-val
 *   4. Tables          .ft-group > .ft-table > table (.ft-num, .ft-tax, .ft-strong, .ft-due), .ft-remove, .ft-add
 *   5. Print           a template page prints the document alone; blank fields print as lines to write on
 */

/* =========================================================================
   1. Template page
   ========================================================================= */
.ft-hub__trade {
    margin: var(--sp-8) 0 var(--sp-3);
    font-size: var(--fs-lg);
    font-weight: var(--fw-bold);
    color: var(--c-ink);
}

.ft-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-3);
    max-width: 880px;
    margin: 0 auto var(--sp-5);
}

.ft-toolbar__note {
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--c-muted);
}

.ft-toolbar__status {
    flex-basis: 100%;
    margin: 0;
    font-size: var(--fs-sm);
    color: var(--c-text-2);
}

.ft-toolbar__status:empty {
    display: none;
}

/* under the document: what happens to what is typed, and "Forget my details" */
.ft-privacy {
    max-width: 880px;
    margin: var(--sp-4) auto 0;
    font-size: var(--fs-sm);
    color: var(--c-muted);
}

.ft-privacy p {
    margin: 0 0 var(--sp-1);
}

.ft-privacy .btn--link {
    font-size: inherit;
    vertical-align: baseline;
}

/* a generator's trade picker: plain links under the opening paragraph */
.ft-picker {
    margin-top: var(--sp-6);
}

.ft-picker__title {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    color: var(--c-ink);
}

.ft-trades {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-5);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ft-trades a {
    font-weight: var(--fw-medium);
    color: var(--c-brand);
    text-decoration: underline;
    text-decoration-color: var(--c-line-strong);
    text-underline-offset: 3px;
}

.ft-trades a:hover {
    text-decoration-color: currentColor;
}

/* the Nexfield block's three feature links */
.ft-links {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2) var(--sp-5);
}

.ft-notes {
    display: grid;
    gap: var(--sp-2);
    max-width: var(--content-narrow);
    margin: 0;
    padding-left: 1.25em;
    color: var(--c-text);
    line-height: var(--lh-relaxed);
}

/* =========================================================================
   2. Document
   ========================================================================= */
.ft-doc {
    max-width: 880px;
    margin-inline: auto;
    padding: var(--sp-5);
    font-size: var(--fs-base);
    color: var(--c-text);
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--r-lg);
    box-shadow: var(--sh-sm);
}

@media (min-width: 768px) {
    .ft-doc { padding: var(--sp-10); }
}

.ft-doc--example {
    box-shadow: none;
}

.ft-doc__head {
    display: grid;
    gap: var(--sp-6);
    padding-bottom: var(--sp-6);
    border-bottom: 2px solid var(--c-ink);
}

@media (min-width: 640px) {
    .ft-doc__head { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
}

.ft-from {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.ft-from__name {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    color: var(--c-ink);
}

.ft-from__line {
    color: var(--c-text-2);
}

/* the logo the visitor adds (kept in the browser) and its two buttons */
.ft-logo {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-3);
    margin-bottom: var(--sp-2);
}

.ft-logo__img {
    display: block;
    max-width: 200px;
    max-height: 64px;
    object-fit: contain;
}

.ft-logo__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-2);
}

.ft-logo__add {
    cursor: pointer;
}

.ft-logo__add:focus-within {
    outline: 2px solid var(--c-brand);
    outline-offset: 2px;
}

/* above the first money table: the starting prices are examples */
.ft-hint {
    margin: var(--sp-6) 0 0;
    font-size: var(--fs-sm);
    color: var(--c-muted);
}

.ft-hint + .ft-group {
    margin-top: var(--sp-2);
}

.ft-meta {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
}

.ft-doc__name {
    margin: 0 0 var(--sp-1);
    font-size: var(--fs-2xl);
    font-weight: var(--fw-bold);
    line-height: var(--lh-tight);
    color: var(--c-ink);
}

.ft-meta .ft-f {
    display: grid;
    grid-template-columns: 7.5em minmax(0, 1fr);
    align-items: baseline;
    gap: var(--sp-3);
}

.ft-block {
    margin-top: var(--sp-6);
}

.ft-block__title {
    margin: 0 0 var(--sp-2);
    font-size: var(--fs-sm);
    font-weight: var(--fw-bold);
    color: var(--c-ink);
}

.ft-grid {
    display: grid;
    gap: var(--sp-3) var(--sp-6);
}

@media (min-width: 640px) {
    .ft-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.ft-grid--notes {
    margin-top: var(--sp-6);
}

.ft-sign {
    display: grid;
    gap: var(--sp-6);
    margin-top: var(--sp-6);
}

@media (min-width: 640px) {
    .ft-sign { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
    .ft-sign > .ft-f { grid-column: 1 / -1; max-width: 320px; }
}

.ft-sign__line {
    margin-top: var(--sp-10);
    padding-top: var(--sp-1);
    font-size: var(--fs-xs);
    color: var(--c-muted);
    border-top: 1px solid var(--c-ink);
}

/* =========================================================================
   3. Fields: a line to write on, as on paper
   ========================================================================= */
.ft-f {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ft-f--wide {
    grid-column: 1 / -1;
}

.ft-f__label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--c-muted);
}

.ft-in {
    width: 100%;
    min-width: 0;
    padding: 6px 2px;
    font: inherit;
    color: var(--c-ink);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--c-line-strong);
    border-radius: 0;
}

.ft-in:hover {
    border-bottom-color: var(--c-line-hover);
}

.ft-in:focus {
    outline: none;
    background: var(--c-surface-2);
    border-bottom-color: var(--c-brand);
    box-shadow: 0 1px 0 var(--c-brand);
}

.ft-in::placeholder {
    color: var(--c-muted);
}

/* on a touch screen every field of the sheet is a 44 px target (TOOLS-PLAN 3.6); the mouse keeps the paper's tight lines */
@media (pointer: coarse) {
    .ft-in:not(.ft-in--area),
    .ft-add,
    [data-ft-forget] {
        min-height: 44px;
    }

    .ft-remove {
        min-width: 44px;
        min-height: 44px;
    }

    /* the Taxable box: its whole cell answers a tap */
    .ft-tax input[type="checkbox"] {
        width: 24px;
        height: 24px;
        margin: 10px;
    }
}

.ft-from .ft-from__name {
    font-size: var(--fs-xl);
}

.ft-in--area {
    min-height: 3.4em;
    padding: 6px 8px;
    resize: vertical;
    border: 1px solid var(--c-line-strong);
    border-radius: var(--r-sm);
}

.ft-in--num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.ft-in[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.ft-in[type="number"]::-webkit-inner-spin-button,
.ft-in[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.ft-val {
    min-height: 1.75em;
    padding: 4px 0;
    color: var(--c-ink);
    white-space: pre-line;
    border-bottom: 1px solid var(--c-line);
}

/* =========================================================================
   4. Tables: money lines, parts, the worked example
   ========================================================================= */
.ft-group {
    margin-top: var(--sp-6);
}

.ft-table {
    position: relative;   /* holds the .sr-only labels inside the scrolled box */
    overflow-x: auto;
}

.ft-table table {
    width: 100%;
    min-width: 560px;
    border-collapse: collapse;
    font-size: var(--fs-base);
}

.ft-table--plain {
    max-width: 720px;
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--r-lg);
}

.ft-table--plain table {
    min-width: 0;
}

.ft-table caption {
    padding: 0 0 var(--sp-2);
    font-weight: var(--fw-bold);
    text-align: left;
    color: var(--c-ink);
}

.ft-table th,
.ft-table td {
    padding: 8px;
    text-align: left;
    vertical-align: middle;
    border-bottom: 1px solid var(--c-line);
}

.ft-table--plain th,
.ft-table--plain td {
    padding: 10px 16px;
}

.ft-table tbody tr:last-child th,
.ft-table tbody tr:last-child td {
    border-bottom-color: var(--c-line-strong);
}

.ft-table--plain tbody tr:last-child th,
.ft-table--plain tbody tr:last-child td {
    border-bottom: 0;
}

.ft-table thead th {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--c-muted);
    border-bottom: 2px solid var(--c-line-strong);
}

.ft-table tbody th {
    font-weight: var(--fw-medium);
    color: var(--c-text);
}

.ft-table tfoot th,
.ft-table tfoot td {
    padding-block: 6px;
    border-bottom: 0;
}

.ft-table tfoot th {
    font-weight: var(--fw-medium);
    text-align: right;
    color: var(--c-text-2);
}

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

.ft-table .ft-tax {
    width: 3.5em;
    text-align: center;
}

/* Money lines: fixed columns, so the three options of an estimate line up under each other */
.ft-table--money table {
    table-layout: fixed;
}

.ft-table--money .ft-col-part { width: 8.5em; }
.ft-table--money .ft-col-qty { width: 5em; }
.ft-table--money .ft-col-price { width: 7.5em; }
.ft-table--money .ft-col-amount { width: 7.5em; }
.ft-table--money .ft-col-x { width: 2.75em; }

.ft-table--money td {
    overflow-wrap: anywhere;
}

.ft-table tr.ft-strong th,
.ft-table tr.ft-strong td {
    font-weight: var(--fw-bold);
    color: var(--c-ink);
}

.ft-table tr.ft-due th,
.ft-table tr.ft-due td {
    font-size: var(--fs-lg);
    border-top: 2px solid var(--c-ink);
}

.ft-deposit {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--sp-2);
}

.ft-deposit .ft-in {
    width: 7em;
}

.ft-remove {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: var(--fs-md);
    line-height: 1;
    color: var(--c-muted);
    cursor: pointer;
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: var(--r-pill);
}

.ft-remove:hover {
    color: var(--c-danger);
    border-color: var(--c-danger-line);
}

.ft-add {
    margin-top: var(--sp-3);
}

/* On a phone the lines of the form are cards: the description across, then qty, rate, tax and amount under their own
   small labels (the table's header is kept for screen readers); the totals stay right-aligned under them. */
@media screen and (max-width: 639px) {
    [data-ft-money] .ft-table--money {
        overflow: visible;
    }

    [data-ft-money] .ft-table--money table {
        min-width: 0;
        table-layout: auto;
    }

    [data-ft-money] .ft-table--money thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
    }

    [data-ft-money] .ft-table--money tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto minmax(0, 1fr) auto;
        grid-template-areas:
            "desc desc desc desc x"
            "part part part part part"
            "qty price tax amount amount";
        gap: var(--sp-2) var(--sp-3);
        padding: var(--sp-3) 0;
        border-bottom: 1px solid var(--c-line);
    }

    [data-ft-money] .ft-table--money tbody td {
        padding: 0;
        border: 0;
    }

    [data-ft-money] .ft-c-desc { grid-area: desc; }
    [data-ft-money] .ft-c-part { grid-area: part; }
    [data-ft-money] .ft-c-qty { grid-area: qty; }
    [data-ft-money] .ft-c-price { grid-area: price; }
    [data-ft-money] .ft-c-tax { grid-area: tax; width: auto; }
    [data-ft-money] .ft-c-amount { grid-area: amount; align-self: end; padding-bottom: 6px; }
    [data-ft-money] .ft-c-x { grid-area: x; align-self: center; }

    [data-ft-money] td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: var(--fs-xs);
        font-weight: var(--fw-semibold);
        text-align: left;
        color: var(--c-muted);
    }

    [data-ft-money] td.ft-c-amount::before {
        text-align: right;
    }

    [data-ft-money] .ft-table--money tfoot tr {
        display: flex;
        align-items: baseline;
        justify-content: flex-end;
        gap: var(--sp-4);
    }

    [data-ft-money] .ft-table--money tfoot th,
    [data-ft-money] .ft-table--money tfoot td {
        padding: 4px 0;
    }

    [data-ft-money] .ft-table--money tfoot td.ft-noprint {
        display: none;
    }

    .ft-deposit .ft-in {
        width: 6em;
    }
}

/* =========================================================================
   5. Print: a template page prints the document alone (site.css already hides the header, the footer and the
   closing band). Blank fields keep their line, so a printed blank copy can be filled in by hand.
   ========================================================================= */
@media print {
    @page {
        margin: 10mm;
    }

    .ft-page main > :not(.ft-sheet),
    .ft-noprint,
    .ft-toolbar {
        display: none !important;
    }

    /* no logo added: the empty slot takes no room on paper */
    .ft-logo:has(.ft-logo__img[hidden]) {
        display: none;
    }

    .ft-logo__img {
        max-height: 56px;
    }

    /* the remove column keeps its place (the totals span the columns before it); only the button goes */
    .ft-table th.ft-noprint,
    .ft-table td.ft-noprint {
        display: table-cell !important;
        visibility: hidden;
    }

    .ft-page .ft-sheet,
    .ft-page .ft-sheet .site-container {
        max-width: none;
        padding: 0;
    }

    .ft-doc {
        max-width: none;
        padding: 0;
        font-size: 10pt;
        color: #000;
        border: 0;
        box-shadow: none;
    }

    .ft-doc__head {
        padding-bottom: var(--sp-4);
    }

    .ft-block,
    .ft-group,
    .ft-grid--notes {
        margin-top: var(--sp-3);
    }

    .ft-f {
        gap: 0;
    }

    /* paper is wider than a phone: three fields a row, the address over two */
    .ft-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: var(--sp-2) var(--sp-6);
    }

    .ft-f--addr {
        grid-column: span 2;
    }

    .ft-doc {
        line-height: 1.3;
    }

    .ft-in {
        padding: 2px;
        color: #000;
        background: none;
    }

    .ft-in::placeholder {
        color: transparent;
    }

    select.ft-in {
        -webkit-appearance: none;
        appearance: none;
    }

    .ft-in--area {
        height: 2.4em;
        min-height: 0;
        resize: none;
        border: 0;
        border-bottom: 1px solid #888;
        border-radius: 0;
    }

    .ft-table {
        overflow: visible;
    }

    .ft-table table {
        min-width: 0;
    }

    .ft-table th,
    .ft-table td {
        padding: 4px 6px;
    }

    .ft-sign {
        margin-top: var(--sp-2);
    }

    .ft-sign__line {
        margin-top: var(--sp-8);
    }

    .ft-block,
    .ft-sign,
    .ft-table tr,
    .ft-group {
        break-inside: avoid;
    }
}
