/*
 * signature.css — a signature by finger, pen or mouse: the customer signs the service report.
 *
 * <div class="app-signature" role="group" aria-labelledby="id-label" aria-describedby="id-hint id-error"
 *      data-state="empty | signed" data-invalid data-disabled data-readonly>
 *   <div class="app-field app-signature-sign">
 *     <span class="app-field-label" id="id-label">Unterschrift Kunde</span>
 *     <div class="app-signature-pad">
 *       <span class="app-signature-mark" aria-hidden="true">[icon: close]</span>
 *       <span class="app-signature-line" aria-hidden="true"></span>
 *       <span class="app-signature-placeholder" aria-hidden="true">Hier unterschreiben</span>
 *       <span class="app-signature-stamp">Maria Berger · 18.11.2026, 14:32</span>
 *       <svg class="app-signature-ink" role="img" aria-label="Noch nicht unterschrieben | Unterschrieben"
 *            viewBox="0 0 w h" preserveAspectRatio="xMidYMid meet"><path class="app-signature-path" d="…"/></svg>
 *     </div>
 *     <div class="app-signature-foot">
 *       <p class="app-field-hint" id="id-hint">…</p>
 *       <p class="app-field-error" id="id-error">…</p>
 *       [button: ghost, compact, "Löschen"; not in read-only]
 *     </div>
 *   </div>
 *   [text field: "Name", id-name, autocomplete="name"; not in read-only]
 * </div>
 *
 * The pad is a strip of paper: a line to sign on with a cross at its start, and under it what to
 * do, until there is ink; then, in its place, who signed and when, as on a signed form. The name
 * is typed in the field below the pad. The ink is one path in the text colour, so it is light in
 * the dark scheme and the system's text colour in a contrast theme; the stored signature carries
 * no colour. The pad takes every touch (touch-action: none), so a finger signs instead of
 * scrolling. Read-only shows a signature kept on the record, on the muted surface, with its
 * stamp, without the prompt, the button and the name field.
 *
 * A signature follows the path of a hand, so it has no keyboard equivalent (WCAG 2.1.1 and 2.5.1
 * except path-dependent input). The ink says by name whether there is a signature; the stamp is
 * text; the button that clears it is an ordinary button.
 */
@layer components {
    .app-signature {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-field);
        min-inline-size: 0;
    }

    .app-signature-pad {
        position: relative;
        block-size: var(--app-signature-height);
        border: var(--app-border-width) solid var(--app-color-line-control);
        border-radius: var(--app-radius-field);
        background: var(--app-color-surface);
        color: var(--app-color-text);
        cursor: crosshair;
        touch-action: none;
        user-select: none;
        -webkit-user-select: none;
        -webkit-touch-callout: none;
        transition: border-color var(--app-duration-hover) var(--app-easing);
    }

    .app-signature-mark {
        position: absolute;
        inset-inline-start: var(--app-space-signature-x);
        inset-block-end: var(--app-space-signature-line);
        display: inline-flex;
        color: var(--app-color-text-subtle);
    }

    /* A step of the rhythm tall, the line its bottom edge: a border, so a contrast theme keeps it. */
    .app-signature-line {
        position: absolute;
        inset-inline: var(--app-space-signature-x);
        inset-block-end: var(--app-space-signature-line);
        block-size: var(--app-signature-line-box);
        border-block-end: var(--app-border-width) solid var(--app-color-line-strong);
    }

    .app-signature-placeholder {
        position: absolute;
        inset-inline: var(--app-space-signature-x);
        inset-block-end: var(--app-space-signature-note);
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
        text-align: center;
    }

    /* Who signed and when, where the prompt was: on the paper, under the line. */
    .app-signature-stamp {
        position: absolute;
        inset-inline: var(--app-space-signature-x);
        inset-block-end: var(--app-space-signature-note);
        overflow: hidden;
        color: var(--app-color-text-muted);
        font-size: var(--app-text-help-size);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-help-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-signature-stamp:empty {
        display: none;
    }

    /* Above the line, the cross and the prompt, and over the whole pad: the pointer lands here. */
    .app-signature-ink {
        position: absolute;
        inset: 0;
        inline-size: 100%;
        block-size: 100%;
        overflow: hidden;
        border-radius: inherit;
        fill: none;
        stroke: currentcolor;
        stroke-linecap: round;
        stroke-linejoin: round;
        stroke-width: var(--app-signature-ink);
    }

    .app-signature-foot {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: var(--app-space-inline);
    }

    .app-signature-foot > :is(.app-field-hint, .app-field-error) {
        grid-column: 1;
        grid-row: 1;
    }

    .app-signature-foot > .app-button {
        grid-column: 2;
        grid-row: 1;
    }

    .app-signature[data-state="signed"] .app-signature-placeholder {
        display: none;
    }

    @media (hover: hover) {
        .app-signature:not([data-disabled], [data-readonly], [data-invalid]) .app-signature-pad:hover {
            border-color: var(--app-color-line-hover);
        }
    }

    /* Invalid: the frame and the error, as on a field. The group carries the state; a role
       for a drawing has no aria-invalid. */
    .app-signature[data-invalid] .app-signature-pad {
        border-color: var(--app-color-danger-line);
    }

    /* The pad's own hint and error, not the name field's, which follows its own input. */
    .app-signature[data-invalid] .app-signature-foot > .app-field-error:not(:empty) {
        display: block;
    }

    .app-signature[data-invalid]:has(.app-signature-foot > .app-field-error:not(:empty)) .app-signature-foot > .app-field-hint {
        display: none;
    }

    .app-signature[data-readonly] .app-signature-pad {
        background: var(--app-color-surface-muted);
        cursor: default;
        touch-action: auto;
    }

    .app-signature[data-readonly] :is(.app-signature-placeholder, .app-signature-mark) {
        display: none;
    }

    .app-signature[data-disabled] .app-signature-pad {
        border-color: var(--app-color-line);
        background: var(--app-color-surface-disabled);
        color: var(--app-color-text-disabled);
        cursor: not-allowed;
        touch-action: auto;
    }

    /* The label keeps its colour: it names the field, as on the attachment field. */
    .app-signature[data-disabled] :is(.app-signature-mark, .app-signature-placeholder) {
        color: var(--app-color-text-disabled);
    }

    /* Forced colours (a Windows contrast theme): the frame and the line are borders and stay;
       the ink is the text colour, which the theme sets. */
    @media (forced-colors: active) {
        .app-signature[data-disabled] :is(.app-signature-pad, .app-signature-mark, .app-signature-placeholder) {
            color: var(--app-color-forced-disabled);
        }
    }
}
