/*
 * file.css — documents shown by what they show: a grid of tiles, and the preview of one.
 *
 * <ul class="app-file-grid" role="list" aria-label="Dokumente">
 *   <li class="app-file" data-state="ready | waiting">
 *     <span class="app-file-thumb" aria-hidden="true">
 *       <img class="app-file-image" src="…" alt="" loading="lazy" decoding="async">     (a picture)
 *       <span class="app-file-mark">[icon: file | upload]<span class="app-file-type">PDF</span></span>  (none)
 *     </span>
 *     <a class="app-file-link" href="…" aria-describedby="id-context id-meta">Wartungsprotokoll 2026</a>
 *     <span class="app-file-context" id="id-context">Gasthof Berger</span>
 *     <span class="app-file-meta" id="id-meta">PDF · 18.11.2026</span>
 *     <ul class="app-file-tags" role="list" aria-label="Schlagwörter">
 *       <li class="app-file-tag">[chip]</li> <li class="app-file-tag" data-more>[chip: +2]</li>
 *     </ul>
 *   </li>
 * </ul>
 *
 * A tile is one link, its name; the whole tile takes the click, so a thumb is a target the
 * size of a thumb. Its thumb is the file's picture where there is one (a photo, a page), else
 * a mark of its type; a document whose file has not arrived shows that it waits. The thumbs are
 * one height whatever the picture, cut from the top, so a page shows its heading. The tiles of a
 * row share their rows (subgrid): names, records, dates and tags each start on one line across
 * the row. Context (the record it hangs on) is written in the browser over all records and left
 * out on a record's own documents. Tags take one line: the first, then how many more; the
 * document's page shows them all.
 *
 * <div class="app-preview">
 *   <img class="app-preview-image" src="…" alt="Wartungsprotokoll, Seite 1">   (a picture)
 *   [state: no preview, with its download]                                     (none)
 * </div>
 *
 * The preview shows the whole picture inside a frame of one height, on the muted surface, so a
 * page and a photo sit alike and the page below does not jump when it loads.
 */
@layer components {
    .app-file-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(var(--app-file-column), 1fr));
        gap: var(--app-space-file-text) var(--app-space-file-grid);
    }

    /* Each tile takes five rows of the grid and shares them with the tiles beside it, so a
       name of one line, a missing record or no tags never shift what follows out of line. The
       grid's rows are 4 apart, the tile's own; the room before the next row of tiles is the
       tile's padding (24 with the gap), so a row without tags stays on the rhythm. */
    .app-file {
        position: relative;
        display: grid;
        grid-row: span 5;
        grid-template-rows: subgrid;
        min-inline-size: 0;
        padding-block: 0 var(--app-space-file-grid-row);
    }

    .app-file-thumb {
        display: flex;
        grid-row: 1;
        align-items: center;
        justify-content: center;
        block-size: var(--app-file-thumb-height);
        overflow: hidden;
        border-radius: var(--app-radius-thumb);
        background: var(--app-color-surface-muted);
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-line);
        transition: box-shadow var(--app-duration-hover) var(--app-easing);
    }

    .app-file-image {
        inline-size: 100%;
        block-size: 100%;
        object-fit: cover;
        object-position: top center;
    }

    .app-file-mark {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--app-space-inline);
        color: var(--app-color-text-subtle);
    }

    .app-file-type {
        color: var(--app-color-text-muted);
        font-size: var(--app-text-label-size);
        font-weight: var(--app-text-label-weight);
        line-height: var(--app-text-label-leading);
    }

    /* Two lines at most; the whole name is the document's page title and its tooltip. It stands
       12 under the thumb, the lines under it 4 apart. */
    .app-file-link {
        display: -webkit-box;
        grid-row: 2;
        align-self: start;
        padding-block: var(--app-space-file-name) 0;
        overflow: hidden;
        color: var(--app-color-text);
        font-size: var(--app-text-body-size);
        font-weight: var(--app-text-link-weight);
        line-height: var(--app-text-body-leading);
        text-decoration: none;
        overflow-wrap: anywhere;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

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

    /* The ring goes round the thumb, the name is underlined: the tile's own box runs on into
       the room before the next row. */
    .app-file-link:focus-visible {
        outline: none;
        text-decoration: underline;
        text-underline-offset: var(--app-link-underline-offset);
    }

    .app-file:has(.app-file-link:focus-visible) .app-file-thumb {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: var(--app-focus-ring-offset);
    }

    .app-file-context,
    .app-file-meta {
        overflow: hidden;
        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-file-context {
        grid-row: 3;
        color: var(--app-color-text-muted);
    }

    .app-file-meta {
        grid-row: 4;
        color: var(--app-color-text-subtle);
    }

    /* One line of tags: a long one is cut short, the count of the rest always shows. */
    .app-file-tags {
        display: flex;
        grid-row: 5;
        gap: var(--app-space-chip-gap);
        padding-block: var(--app-space-file-text) 0;
        min-inline-size: 0;
        overflow: hidden;
    }

    .app-file-tag {
        display: flex;
        min-inline-size: 0;
    }

    .app-file-tag[data-more] {
        flex: none;
    }

    .app-file-tag > .app-chip {
        min-inline-size: 0;
    }

    .app-file-tag .app-chip-label {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Waiting for its file: an outline where the picture will be. */
    .app-file[data-state="waiting"] .app-file-thumb {
        background: none;
        box-shadow: none;
        outline: var(--app-border-width) dashed var(--app-color-line-strong);
        outline-offset: calc(-1 * var(--app-border-width));
    }

    .app-file[data-state="waiting"] .app-file-meta {
        color: var(--app-color-warning-text);
    }

    @media (hover: hover) {
        .app-file:hover .app-file-thumb {
            box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-line-hover);
        }

        .app-file:hover .app-file-link {
            text-decoration: underline;
            text-underline-offset: var(--app-link-underline-offset);
        }
    }

    /* ------------------------------------------------------------- the preview */

    .app-preview {
        display: flex;
        align-items: center;
        justify-content: center;
        block-size: var(--app-preview-height-narrow);
        padding: var(--app-space-preview);
        overflow: hidden;
        border-radius: var(--app-radius-card);
        background: var(--app-color-surface-muted);
        box-shadow: inset 0 0 0 var(--app-border-width) var(--app-color-line);
    }

    .app-preview-image {
        max-inline-size: 100%;
        max-block-size: 100%;
        object-fit: contain;
        box-shadow: var(--app-shadow-card);
    }


    @container app-region (width >= 560px) {
        .app-preview {
            block-size: var(--app-preview-height);
        }
    }

    @media (forced-colors: active) {
        .app-file-thumb,
        .app-preview {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
    }
}
