/*
 * page-header.css — the head of a page, and the breadcrumb in it.
 *
 * <header class="app-page-header">
 *   <nav class="app-breadcrumb" aria-label="Pfad">
 *     <ol class="app-breadcrumb-list" role="list">
 *       <li class="app-breadcrumb-item"><a class="app-breadcrumb-link" href>Aufträge</a>[icon]</li>
 *     </ol>
 *   </nav>
 *   <a class="app-page-header-back" href aria-label="Zurück zu Aufträge">[icon]</a>
 *   <div class="app-page-header-heading">
 *     <h1 class="app-page-header-title">A-2026-0142</h1>
 *     <div class="app-page-header-meta">[chips, text]</div>
 *   </div>
 *   <div class="app-page-header-actions">[buttons]</div>
 * </header>
 *
 * Breadcrumb and back link are written only when the page has them. The breadcrumb lists the
 * pages above this one, a chevron between each and the next; the title is the current page, so
 * it is not repeated in the trail, and the last chevron, pointing at nothing on its line, is
 * not shown. Meta and actions are always written and
 * take no space when empty.
 *
 * A grid of up to three tracks: back, heading, actions. The breadcrumb spans them all above.
 * The first row is a control row: back link, the title's first line and the buttons are all
 * the control height and share one centre line.
 * From a region of 560 the actions sit beside the heading, at the end. Narrower, they take a
 * row of their own, unless they are the page's menu alone, which stays at the end of the title's
 * row (a work report on a phone, Stornieren behind it), and a page with a back link drops the breadcrumb: the back link is the way
 * up, and the trail would wrap. In the detail pane of a split view that shows its list beside
 * it, the back link goes instead.
 *
 * A list's head (a record lane: Aufträge 148, Neu) has its count as the meta, a badge alone,
 * which then stands beside the title on its line; and its one compact button (Neu) stays at the
 * end of that line in any region, as the page's menu does. Actions centre on the control row.
 */
@layer components {
    .app-page-header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: start;
        gap: var(--app-space-header-row) var(--app-space-header-x);
    }

    .app-page-header:has(> .app-page-header-back) {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .app-breadcrumb {
        grid-column: 1 / -1;
        min-inline-size: 0;
    }

    .app-breadcrumb-list {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--app-space-header-row);
    }

    .app-breadcrumb-item {
        display: inline-flex;
        align-items: center;
        gap: var(--app-space-header-row);
        color: var(--app-color-text-subtle);
    }

    .app-breadcrumb-item:last-child > .app-icon {
        display: none;
    }

    .app-breadcrumb-link {
        border-radius: var(--app-radius-option);
        color: var(--app-color-text-muted);
        font-size: var(--app-text-crumb-size);
        line-height: var(--app-text-label-leading);
        text-decoration: none;
    }

    @media (hover: hover) {
        .app-breadcrumb-link:hover {
            color: var(--app-color-text);
            text-decoration: underline;
        }
    }

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

    .app-page-header-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        inline-size: var(--app-control-height);
        block-size: var(--app-control-height);
        border-radius: var(--app-radius-button);
        color: var(--app-color-text);
        transition: background-color var(--app-duration-hover) var(--app-easing);
    }

    @media (hover: hover) {
        .app-page-header-back:hover {
            background: var(--app-color-surface-hover);
        }
    }

    .app-page-header-back:focus-visible {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: var(--app-focus-ring-offset);
    }

    .app-page-header-heading {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-header-row);
        min-inline-size: 0;
    }

    /* The title's first line is a control row: as tall as the back link and the buttons, and
       centred on the same line. A longer title wraps below it; meta follows. */
    .app-page-header-title {
        display: flex;
        align-items: center;
        min-block-size: var(--app-control-height);
        color: var(--app-color-text);
        font-family: var(--app-font-display);
        font-size: var(--app-text-display-size);
        font-weight: var(--app-text-display-weight);
        line-height: var(--app-text-display-leading);
        letter-spacing: var(--app-text-display-tracking);
        /* A long German word (Heizungswartung) breaks where the language allows, as with large
           text on a phone; anywhere only where it has no break. */
        overflow-wrap: anywhere;
        hyphens: auto;
    }

    .app-page-header-meta {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--app-space-cluster);
        color: var(--app-color-text-muted);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
    }

    .app-page-header-actions {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-end;
        gap: var(--app-space-actions);
        min-block-size: var(--app-control-height);
    }

    /* A count alone stands beside the title, centred on its first line. */
    .app-page-header-heading:has(> .app-page-header-meta > .app-badge:only-child) {
        flex-direction: row;
        align-items: center;
        gap: var(--app-space-cluster);
    }

    .app-page-header-meta:empty,
    .app-page-header-actions:empty {
        display: none;
    }

    @container app-region (width < 560px) {
        .app-page-header {
            row-gap: var(--app-space-header-x);
        }

        .app-page-header-title {
            font-size: var(--app-text-heading-size);
            line-height: var(--app-text-heading-leading);
        }

        .app-page-header-actions {
            grid-column: 1 / -1;
            justify-content: flex-start;
        }

        .app-page-header-actions:is(:has(> .app-menu:only-child), :has(> .app-button[data-size="compact"]:only-child)) {
            grid-column: auto;
            justify-content: flex-end;
        }

        .app-page-header:has(> .app-page-header-back) > .app-breadcrumb {
            display: none;
        }
    }

    /* Beside its list, a detail page needs no way back to it. */
    @container app-split (width >= 960px) {
        [data-pane="detail"] .app-page-header:has(> .app-page-header-back) {
            grid-template-columns: minmax(0, 1fr) auto;
        }

        [data-pane="detail"] .app-page-header-back {
            display: none;
        }
    }

    @media (pointer: coarse) {
        .app-page-header-back {
            inline-size: var(--app-touch-target);
            block-size: var(--app-touch-target);
        }
    }
}
