/*
 * document.css — a record's detail area, read as a commercial document reads: one anatomy for
 * every record page (an invoice, an offer, an order, a customer, an asset, an employee, an item
 * of the catalogue), so offer and invoice read as one family and every other record page as
 * their kin (Patterns/Record, .impeccable/mocks/decision/invoices3-a.html).
 *
 * <div class="app-record">
 *   [page header: the title; in its meta the identifier line; at the end the page's menu]
 *     <p class="app-record-line"><span class="app-record-id">A-2026-0142</span><span class="app-record-word" data-tone>Entwurf</span></p>
 *   [description list: the facts, a quarter each, as a band over the body]
 *   <div class="app-record-body">
 *     <div class="app-record-main">
 *       <section class="app-record-panel" aria-labelledby>
 *         <header class="app-record-panel-head">
 *           <h3 class="app-record-panel-title" id>Hauptplatz 12, Linz</h3>
 *           <div class="app-record-panel-actions">[a compact button, a menu]</div>
 *           <p class="app-record-panel-value">736,30 €</p>
 *           <p class="app-record-line">[identifier][date, a count]</p>
 *         </header>
 *         <table class="app-record-lines" role="table">                      (amount rows)
 *           <caption class="app-record-hidden">…</caption>
 *           <thead class="app-record-hidden" role="rowgroup"><tr role="row"><th role="columnheader">…</th>…</tr></thead>
 *           <tbody role="rowgroup">
 *             <tr class="app-record-row" role="row" data-kind="discount">
 *               <td class="app-record-name" role="cell"><span class="app-record-label">[a link]</span><span class="app-record-note">Plan 4,0</span></td>
 *               <td class="app-record-qty" role="cell">5,5 Std.</td>
 *               <td class="app-record-price" role="cell">× 82,00 €</td>
 *               <td class="app-record-amount" role="cell">451,00 €</td>
 *             </tr>
 *           </tbody>
 *         </table>
 *         <dl class="app-record-pairs"><div class="app-record-pair"><dt>Hersteller</dt><dd>Carrier</dd></div></dl>   (fact rows)
 *         <div class="app-record-text">[a paragraph]</div>                    (a text)
 *       </section>
 *       <dl class="app-record-totals">
 *         <div class="app-record-total"><dt>Netto</dt><dd>1.407,95 €</dd></div>
 *         <div class="app-record-total" data-kind="grand"><dt>Brutto</dt><dd>1.689,54 €</dd></div>
 *       </dl>
 *     </div>
 *     <aside class="app-record-side" aria-label>
 *       <div class="app-record-state"><p class="app-record-state-word">Entwurf</p><p class="app-record-state-line" data-tone>Nummer bei Ausstellung</p></div>
 *       <div class="app-record-side-actions">[the page's actions, the filled one first]</div>
 *     </aside>
 *   </div>
 *   (or, for a record with parallel views, its tabs in place of the body)
 * </div>
 *
 * The grid is the sketch's. Spacing is 8, 16 and 24 only, 4 only between a fact's term and its
 * value: the parts of a record stand 16 apart, a panel's text 16 in from its edge, panels on the
 * grey page 16 apart. Rows are 36 (8, a line of 20, 8). An amount row is the name, then Menge 72,
 * × Preis 88 and Netto 96 in columns of their own, so every amount ends 16 inside its panel, on
 * one edge across the panels and the totals panel, whose labels stand on the Menge column's edge.
 * Brutto is the heaviest figure (18/24). An identifier is a muted line in the Code face (13/16)
 * directly under the name it identifies, at the same left edge: under the page's title (with
 * the state as a grey word, in the warning tone only for what is overdue or has run out), under
 * a panel's title. A panel's right value stands on its title's baseline.
 *
 * The side holds the record's state and its actions, only where the record has a side and its
 * region is 960 wide: the body takes twelve columns, the main column nine and the side three,
 * on the tracks the facts band uses, so the band's fourth fact stands over the side. There the
 * head's state word and the page's action bar give way to it (the same actions, written twice,
 * one of them shown). Narrower, the side is gone: the state is the word in the head, the actions
 * the action bar, as on every page.
 *
 * Below a region of 560 an amount row takes two lines: the name and the amount, then Menge and
 * × Preis in small text under the name (52); fact rows give the term two fifths; the totals
 * panel takes the column's width, its amounts still on the panels' edge.
 */
@layer components {
    .app-record {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-record);
        min-inline-size: 0;
    }

    /* The identifier line: under the page's title, under a panel's title. */
    .app-record-line {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        column-gap: var(--app-space-record);
        min-inline-size: 0;
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
    }

    .app-record-id {
        color: var(--app-color-text-subtle);
        font-family: var(--app-font-mono);
        font-size: var(--app-text-id-size);
        font-weight: var(--app-text-code-weight);
        font-variant-numeric: tabular-nums slashed-zero;
        /* As tall as its letters, so the smaller Code face sits in the line it is in (a fact's
           20, the muted line's 16) without making it a pixel taller. */
        line-height: var(--app-text-id-leading);
        letter-spacing: var(--app-text-code-tracking);
        white-space: nowrap;
    }

    /* A linked identifier (Aus Anfrage AN-2026-0057) keeps the link's colour. */
    /* On its own muted line the identifier is an item of the line, as tall as the line. */
    .app-record-line > .app-record-id {
        line-height: inherit;
    }

    .app-link-label > .app-record-id {
        color: inherit;
    }

    .app-record-word {
        color: var(--app-color-text-muted);
        font-weight: var(--app-text-label-weight);
    }

    .app-record-word[data-tone="warning"],
    .app-record-state-line[data-tone="warning"] {
        color: var(--app-color-warning-text);
        font-weight: var(--app-text-label-weight);
    }

    /* In the page header the line stands right under the title's row. */
    .app-page-header-heading:has(> .app-page-header-meta > .app-record-line:only-child) {
        gap: 0;
    }

    /* The body: the main column, and the side beside it from a region of 960. */
    .app-record-body {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: var(--app-space-record) var(--app-space-gutter-wide);
        align-items: start;
        min-inline-size: 0;
    }

    .app-record-main {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-record);
        min-inline-size: 0;
    }

    /* A panel: white on the grey page, its title inside. */
    .app-record-panel {
        display: flex;
        flex-direction: column;
        min-inline-size: 0;
        padding-block: 0 var(--app-space-record-row);
        border-radius: var(--app-radius-card);
        background: var(--app-color-surface);
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    /* Panels side by side, each alone in its column, are as tall as their row, so they end on
       one line; beside a column that holds more, a panel keeps its own height. */
    .app-columns:not(:has(> .app-column > :not(.app-record-panel))) > .app-column:has(> .app-record-panel:only-child) {
        align-content: stretch;
    }

    .app-record-panel:has(> .app-record-panel-head:only-child) {
        padding-block: 0;
    }

    .app-record-panel-head {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-areas:
            "title actions value"
            "line line line";
        align-items: baseline;
        column-gap: var(--app-space-record);
        padding-block: var(--app-space-record) var(--app-space-record-row);
        padding-inline: var(--app-space-record);
    }

    .app-record-panel-head:only-child {
        padding-block: var(--app-space-record);
    }

    .app-record-panel-title {
        grid-area: title;
        min-inline-size: 0;
        color: var(--app-color-text);
        font-family: var(--app-font-display);
        font-size: var(--app-text-heading-size);
        font-weight: var(--app-text-heading-weight);
        line-height: var(--app-text-heading-leading);
        overflow-wrap: anywhere;
        text-wrap: pretty;
    }

    /* Compact controls at the end of the title's line (a menu, "+ Position") stand centred on
       it and reach past it, so a head with them is as tall as one without and rows of panels
       side by side stay level. */
    .app-record-panel-actions {
        display: flex;
        grid-area: actions;
        align-self: center;
        align-items: center;
        gap: var(--app-space-actions);
        block-size: var(--app-text-heading-leading);
    }

    .app-record-panel-actions:empty {
        display: none;
    }

    /* Without a value or without actions, the head has no track for them. */
    .app-record-panel-head:has(> .app-record-panel-value:empty) {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "title actions"
            "line line";
    }

    .app-record-panel-head:has(> .app-record-panel-actions:empty) {
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "title value"
            "line line";
    }

    .app-record-panel-head:has(> .app-record-panel-actions:empty):has(> .app-record-panel-value:empty) {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "title"
            "line";
    }

    .app-record-panel-value {
        grid-area: value;
        color: var(--app-color-text);
        font-size: var(--app-text-body-size);
        font-weight: var(--app-text-strong-weight);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-body-leading);
        text-align: end;
        white-space: nowrap;
    }

    .app-record-panel-value:empty {
        display: none;
    }

    .app-record-panel-head > .app-record-line {
        grid-area: line;
    }

    /* What is read out, not shown: a table's caption and its column heads. */
    .app-record-hidden {
        position: absolute;
        inline-size: var(--app-border-width);
        block-size: var(--app-border-width);
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }

    /* Rows: amount rows (a table), fact rows (a description list). */
    .app-record-lines,
    .app-record-lines > tbody {
        display: block;
        min-inline-size: 0;
    }

    .app-record-row,
    .app-record-pair {
        position: relative;
        display: grid;
        align-items: baseline;
        column-gap: var(--app-space-record);
        padding: var(--app-space-record-row) var(--app-space-record);
        box-shadow: inset 0 var(--app-border-width) 0 var(--app-color-line);
        color: var(--app-color-text-muted);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
    }

    .app-record-row:first-child,
    .app-record-pair:first-child {
        box-shadow: inset 0 var(--app-border-width) 0 var(--app-color-line-strong);
    }

    .app-record-row {
        grid-template-columns: minmax(0, 1fr) var(--app-record-quantity) var(--app-record-price) var(--app-record-amount);
        column-gap: 0;
    }

    .app-record-row > * {
        display: block;
        min-inline-size: 0;
        padding: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-record-name {
        display: flex;
        align-items: baseline;
        gap: var(--app-space-record-row);
        padding-inline: 0 var(--app-space-record-row);
        color: var(--app-color-text);
    }

    .app-record-row > .app-record-name {
        display: flex;
    }

    .app-record-label {
        min-inline-size: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .app-record-note {
        flex: none;
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
    }

    .app-record-qty,
    .app-record-price,
    .app-record-amount {
        font-variant-numeric: tabular-nums;
        text-align: end;
    }

    .app-record-amount {
        color: var(--app-color-text);
        font-weight: var(--app-text-value-weight);
    }

    /* A discount, an hour of a repair: a line of its own in the muted text, its name across. */
    .app-record-row[data-kind="discount"] > .app-record-name {
        grid-column: 1 / 4;
        color: var(--app-color-text-muted);
    }

    .app-record-row[data-kind="discount"] > .app-record-amount {
        color: var(--app-color-text-muted);
        font-weight: var(--app-text-body-weight);
    }

    /* A row that opens (a line of a draft): its name's link covers the row. */
    .app-record-link {
        max-inline-size: 100%;
        padding: 0;
        overflow: hidden;
        border: 0;
        background: none;
        color: inherit;
        font: inherit;
        text-align: start;
        text-decoration: none;
        text-overflow: ellipsis;
        white-space: nowrap;
        cursor: pointer;
    }

    .app-record-link::after {
        position: absolute;
        inset: 0;
        content: "";
    }

    .app-record-link:focus-visible {
        outline: none;
    }

    .app-record-row:has(.app-record-link:focus-visible) {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: calc(-1 * var(--app-focus-ring-width));
    }

    @media (hover: hover) {
        .app-record-row:has(.app-record-link):hover {
            background: var(--app-color-row-hover);
        }
    }

    .app-record-pairs {
        display: block;
        min-inline-size: 0;
    }

    .app-record-pair {
        grid-template-columns: var(--app-record-term-width) minmax(0, 1fr);
    }

    .app-record-pair > dd {
        min-inline-size: 0;
        color: var(--app-color-text);
        font-weight: var(--app-text-value-weight);
        overflow-wrap: anywhere;
    }

    .app-record-text {
        padding-block: 0 var(--app-space-record-row);
        padding-inline: var(--app-space-record);
        color: var(--app-color-text-muted);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
        text-wrap: pretty;
    }

    /* The totals: at the amounts' edge, Brutto the heaviest. */
    .app-record-totals {
        align-self: flex-end;
        inline-size: var(--app-record-totals-width);
        max-inline-size: 100%;
        padding-block: var(--app-space-record-row);
        border-radius: var(--app-radius-card);
        background: var(--app-color-surface);
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-line-strong);
    }

    .app-record-total {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: var(--app-space-record);
        padding: var(--app-space-record-row) var(--app-space-record);
        color: var(--app-color-text-muted);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
    }

    .app-record-total > dd {
        color: var(--app-color-text);
        font-weight: var(--app-text-value-weight);
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    .app-record-total[data-kind="grand"] {
        box-shadow: inset 0 var(--app-border-width) 0 var(--app-color-line-strong);
        color: var(--app-color-text);
        font-weight: var(--app-text-strong-weight);
    }

    .app-record-total[data-kind="grand"] > dd {
        font-size: var(--app-text-heading-size);
        font-weight: var(--app-text-strong-weight);
        line-height: var(--app-text-heading-leading);
    }

    /* The side: the state, then the actions, the filled one first and every one as wide. */
    .app-record-side {
        position: sticky;
        inset-block-start: 0;
        display: none;
        flex-direction: column;
        gap: var(--app-space-record);
        min-inline-size: 0;
        padding: var(--app-space-record);
        border-radius: var(--app-radius-card);
        background: var(--app-color-surface);
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    .app-record-state {
        display: flex;
        flex-direction: column;
        min-inline-size: 0;
    }

    .app-record-state-word {
        color: var(--app-color-text-muted);
        font-family: var(--app-font-display);
        font-size: var(--app-text-heading-size);
        font-weight: var(--app-text-heading-weight);
        line-height: var(--app-text-heading-leading);
    }

    .app-record-state-line {
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
    }

    .app-record-state-line:empty {
        display: none;
    }

    .app-record-side-actions {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-actions);
    }

    @container app-region (width < 560px) {
        .app-record-row {
            grid-template-columns: auto auto minmax(0, 1fr) auto;
            column-gap: var(--app-space-record-row);
        }

        .app-record-name {
            grid-column: 1 / 4;
        }

        .app-record-amount {
            grid-area: 1 / 4;
        }

        .app-record-qty,
        .app-record-price {
            grid-row: 2;
            font-size: var(--app-text-help-size);
            line-height: var(--app-text-help-leading);
            text-align: start;
        }

        .app-record-pair {
            grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
        }

        .app-record-totals {
            align-self: stretch;
            inline-size: auto;
        }
    }

    @container app-region (width >= 960px) {
        .app-record-body:has(> .app-record-side) {
            grid-template-columns: repeat(12, minmax(0, 1fr));
        }

        .app-record-body:has(> .app-record-side) > .app-record-main {
            grid-column: span 9;
        }

        .app-record-side {
            display: flex;
            grid-column: span 3;
        }

        .app-record:has(> .app-record-body > .app-record-side) .app-record-word {
            display: none;
        }

        .app-page:has(> .app-page-body > .app-record > .app-record-body > .app-record-side) > .app-action-bar {
            display: none;
        }
    }

    /* Forced colours (a Windows contrast theme): rings are gone, so frames are outlines. */
    @media (forced-colors: active) {
        :is(.app-record-panel, .app-record-totals, .app-record-side) {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
    }
}
