/*
 * nav.css — the navigation of the shell.
 *
 * <div class="app-nav-group" role="group" aria-labelledby>
 *   <h2 class="app-nav-group-title" id>Arbeit</h2>
 *   <ul class="app-nav-list" role="list">
 *     <li class="app-nav-entry">
 *       <a class="app-nav-item" href aria-current="page">
 *         <svg class="app-icon">…</svg>
 *         <span class="app-nav-label">Aufträge</span>
 *         <span class="app-nav-count">12</span>
 *       </a>
 *     </li>
 *   </ul>
 * </div>
 *
 * Groups sit in .app-shell-nav (shell.css), which spaces them. A group without a title has
 * neither the heading nor role and aria-labelledby. The count is written only when there is
 * one. An item is a row of three tracks: icon, label, count. The icon track sits under the
 * group title's first letter's left edge, so titles, icons and labels make two straight lines.
 */
@layer components {
    .app-nav-group {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-label);
    }

    .app-nav-group-title {
        padding: 0 var(--app-space-nav-item-x);
        color: var(--app-color-text-subtle);
        font-family: var(--app-font-text);
        font-size: var(--app-text-label-size);
        font-weight: var(--app-text-label-weight);
        line-height: var(--app-text-label-leading);
    }

    .app-nav-list {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-nav-items);
    }

    .app-nav-item {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        align-items: center;
        gap: var(--app-space-inline);
        min-block-size: var(--app-control-height);
        padding: var(--app-space-control-y) var(--app-space-nav-item-x);
        border-radius: var(--app-radius-nav-item);
        color: var(--app-color-text-muted);
        font-family: var(--app-font-text);
        font-size: var(--app-text-nav-size);
        font-weight: var(--app-text-nav-weight);
        line-height: var(--app-text-control-leading);
        text-decoration: none;
        transition:
            background-color var(--app-duration-hover) var(--app-easing),
            color var(--app-duration-hover) var(--app-easing);
    }

    .app-nav-label {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-nav-count {
        color: var(--app-color-text-subtle);
        font-size: var(--app-text-count-size);
        font-variant-numeric: tabular-nums;
    }

    .app-nav-item[aria-current="page"] {
        background: var(--app-color-nav-current);
        color: var(--app-color-nav-current-text);
    }

    .app-nav-item[aria-current="page"] .app-nav-count {
        color: inherit;
    }

    @media (hover: hover) {
        .app-nav-item:hover:not([aria-current="page"]) {
            background: var(--app-color-surface-hover);
            color: var(--app-color-text);
        }
    }

    .app-nav-item:focus-visible {
        outline: var(--app-focus-ring-width) solid var(--app-color-focus);
        outline-offset: calc(-1 * var(--app-focus-ring-width));
    }

    /* Once the navigation is a column (shell.css), the menu button that opens it goes. It is an
       icon button, styled in this layer, so the rule that hides it has to be here too. */
    @media (width >= 960px) {
        .app-shell-header > .app-icon-button[popovertarget] {
            display: none;
        }
    }

    @media (pointer: coarse) {
        .app-nav-item {
            min-block-size: var(--app-touch-target);
        }
    }

    /* The rail (shell.css): from 960, until the person widens the column, an item is its icon in
       a touch target's square. The label is still the link's name and the group's title still
       the group's, for a screen reader; a count waits for the wide column. */
    @media (width >= 960px) {
        .app-shell:not([data-nav="wide"]) .app-nav-item {
            grid-template-columns: auto;
            justify-content: center;
            min-block-size: var(--app-touch-target);
            padding-inline: 0;
        }

        .app-shell:not([data-nav="wide"]) .app-nav-item > .app-icon {
            inline-size: var(--app-nav-rail-icon);
            block-size: var(--app-nav-rail-icon);
        }

        .app-shell:not([data-nav="wide"]) :is(.app-nav-label, .app-nav-count, .app-nav-group-title) {
            position: absolute;
            inline-size: var(--app-border-width);
            block-size: var(--app-border-width);
            overflow: hidden;
            padding: 0;
            clip-path: inset(50%);
            white-space: nowrap;
        }
    }

    /* 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-nav-item[aria-current="page"] {
            forced-color-adjust: none;
            background: var(--app-color-forced-current);
            color: var(--app-color-forced-current-text);
        }
        .app-nav-item[aria-current="page"] .app-nav-count {
            forced-color-adjust: none;
            background: var(--app-color-forced-current);
            color: var(--app-color-forced-current-text);
        }
    }
}
