/*
 * attachment.css — files on a record: photos of the job, a delivery note, a test report.
 *
 * <div class="app-field app-attachments" role="group" aria-labelledby="id-label">
 *   <span class="app-field-label" id="id-label">Fotos</span>
 *   <ul class="app-attachment-list" role="list">
 *     <li class="app-attachment" data-state="ready | uploading | error">
 *       <span class="app-attachment-icon" aria-hidden="true">[icon: image | file]</span>
 *       <span class="app-attachment-name">Heizraum.jpg</span>
 *       <span class="app-attachment-meta">2,4 MB</span>
 *       <button class="app-icon-button" … data-size="compact" aria-label="Entfernen: Heizraum.jpg">[icon: close]</button>
 *     </li>
 *   </ul>
 *   <div class="app-attachment-adds">
 *     <label class="app-button app-attachment-add" …>                       (the camera, when asked)
 *       <input class="app-attachment-input" type="file" id="id-camera" accept="image/*" capture="environment" …>
 *       <span class="app-button-icon" aria-hidden="true">[icon: camera]</span>
 *       <span class="app-button-label">Foto aufnehmen</span>
 *     </label>
 *     <label class="app-button app-attachment-add" data-variant="secondary" data-size="regular">
 *       <input class="app-attachment-input" type="file" id accept multiple capture aria-describedby disabled>
 *       <span class="app-button-icon" aria-hidden="true">[icon: plus]</span>
 *       <span class="app-button-label">Foto hinzufügen</span>
 *     </label>
 *   </div>
 *   <p class="app-field-hint" id="id-hint">…</p>
 *   <p class="app-field-error" id="id-error">…</p>
 * </div>
 *
 * The add button is a label over the browser's own file input, which covers it unseen: the
 * phone offers camera, gallery and files, the desktop its file dialog, and a file dropped on
 * the button is taken. Where a camera is at hand (the field app on a phone or tablet), "Foto
 * aufnehmen" stands first and opens the rear camera at once, skipping the choice; a desktop
 * browser ignores capture, so the office leaves it out. A row is one control high; its meta line says the size, or that the
 * file is on its way, or why it was refused. Removing is the screen's (it may ask first).
 */
@layer components {
    .app-attachment-list {
        display: flex;
        flex-direction: column;
        border-radius: var(--app-radius-field);
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    .app-attachment-list:empty {
        display: none;
    }

    .app-attachment {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto auto;
        align-items: center;
        gap: var(--app-space-inline);
        min-block-size: var(--app-control-height);
        padding: 0 var(--app-space-attachment-x);
    }

    .app-attachment + .app-attachment {
        box-shadow: inset 0 var(--app-border-width) 0 var(--app-color-line);
    }

    .app-attachment-icon {
        display: inline-flex;
        color: var(--app-color-text-subtle);
    }

    .app-attachment-name {
        overflow: hidden;
        color: var(--app-color-text);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-attachment-meta {
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-help-size);
        font-variant-numeric: tabular-nums;
        line-height: var(--app-text-help-leading);
        white-space: nowrap;
    }

    .app-attachment[data-state="uploading"] :is(.app-attachment-icon, .app-attachment-name) {
        animation: app-pulse var(--app-duration-skeleton) var(--app-easing) infinite alternate;
    }

    .app-attachment[data-state="error"] .app-attachment-meta,
    .app-attachment[data-state="error"] .app-attachment-icon {
        color: var(--app-color-danger-text);
    }

    .app-attachment-adds {
        display: flex;
        flex-wrap: wrap;
        gap: var(--app-space-actions);
    }

    .app-attachment-add {
        position: relative;
        cursor: pointer;
    }

    /* Over the whole button, its border too. */
    .app-attachment-input {
        position: absolute;
        inset: calc(-1 * var(--app-border-width));
        inline-size: calc(100% + 2 * var(--app-border-width));
        block-size: calc(100% + 2 * var(--app-border-width));
        margin: 0;
        opacity: 0;
        cursor: inherit;
    }

    .app-attachment-add:has(.app-attachment-input:focus-visible) {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: var(--app-focus-ring-offset);
    }

    .app-attachment-add:has(.app-attachment-input:disabled) {
        border-color: transparent;
        background: var(--app-color-surface-disabled);
        color: var(--app-color-text-disabled);
        cursor: not-allowed;
    }

    .app-attachments:has([aria-invalid="true"]) .app-attachment-list {
        box-shadow: 0 0 0 var(--app-border-width) var(--app-color-danger-line);
    }

    @keyframes app-pulse {
        to {
            opacity: 0.4;
        }
    }

    /* Forced colours (a Windows contrast theme): shadows and backgrounds are gone, so frames
       are outlines and a chosen state is the system highlight. */
    @media (forced-colors: active) {
        .app-attachment-list {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
        .app-attachment + .app-attachment {
            border-block-start: var(--app-border-width) solid var(--app-color-forced-line);
        }
    }
}
