/*
 * progress.css — how far a long task is: photos uploading, changes being sent, a sync.
 *
 * <div class="app-progress" data-tone="accent | success | danger">
 *   <div class="app-progress-head">
 *     <span class="app-progress-label" id="id-label">Fotos hochladen</span>
 *     <span class="app-progress-value" aria-hidden="true">3 von 7</span>
 *   </div>
 *   <progress class="app-progress-bar" aria-labelledby="id-label" max="7" value="3" aria-valuetext="3 von 7"></progress>
 * </div>
 *
 * The native progress element: the browser draws the fill from value and max and reads it out,
 * as aria-valuetext says it ("3 von 7", not 43 %). Without a value it is busy: how far is not
 * known, and a segment sweeps the track (still, as fine stripes, under reduced motion).
 * Over the bar, what is going on and how far, the figures tabular so they do not jump. Done is
 * the success tone, a failure the danger tone where it stopped; the words say which, the colour
 * repeats it. A bar does not announce itself: a screen says the end with a toast.
 */
@layer components {
    .app-progress {
        display: flex;
        flex-direction: column;
        gap: var(--app-space-progress);
        min-inline-size: 0;
        color: var(--app-color-accent);
    }

    .app-progress[data-tone="success"] {
        color: var(--app-color-success);
    }

    /* The danger line, not the button's fill: lighter in the dark scheme, where a bar of the
       fill would sink into the track. */
    .app-progress[data-tone="danger"] {
        color: var(--app-color-danger-line);
    }

    .app-progress-head {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: var(--app-space-inline);
        min-inline-size: 0;
        font-size: var(--app-text-help-size);
        line-height: var(--app-text-help-leading);
    }

    .app-progress-label {
        overflow: hidden;
        color: var(--app-color-text);
        font-weight: var(--app-text-label-weight);
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-progress-value {
        flex: none;
        color: var(--app-color-text-muted);
        font-variant-numeric: tabular-nums;
    }

    .app-progress-value:empty {
        display: none;
    }

    .app-progress[data-tone="danger"] .app-progress-value {
        color: var(--app-color-danger-text);
    }

    /* The bar: the track is the element, the fill the browser's value part. */
    .app-progress-bar {
        display: block;
        inline-size: 100%;
        block-size: var(--app-progress-height);
        overflow: hidden;
        border: 0;
        border-radius: var(--app-radius-round);
        background: var(--app-color-line);
        color: inherit;
        appearance: none;
    }

    .app-progress-bar::-webkit-progress-bar {
        border-radius: inherit;
        background: transparent;
    }

    .app-progress-bar::-webkit-progress-value {
        border-radius: var(--app-radius-round);
        background: currentcolor;
        transition: inline-size var(--app-duration-panel) var(--app-easing);
    }

    .app-progress-bar::-moz-progress-bar {
        border-radius: var(--app-radius-round);
        background: currentcolor;
    }

    /* Busy: a segment half the track wide sweeps across it. */
    .app-progress-bar:indeterminate {
        background:
            linear-gradient(90deg, transparent 40%, currentcolor 40% 60%, transparent 60%) 100% 0 / 250% 100% no-repeat,
            var(--app-color-line);
        animation: app-progress-sweep var(--app-duration-progress) var(--app-easing-busy) infinite;
    }

    .app-progress-bar:indeterminate::-moz-progress-bar {
        background: transparent;
    }

    @keyframes app-progress-sweep {
        to {
            background-position: 0 0, 0 0;
        }
    }

    @media (prefers-reduced-motion: reduce) {
        /* Still: fine stripes over the track, never a fill that would read as done. */
        .app-progress-bar:indeterminate {
            background:
                repeating-linear-gradient(-45deg, currentcolor 0 var(--app-progress-stripe), transparent var(--app-progress-stripe) calc(2 * var(--app-progress-stripe))),
                var(--app-color-line);
            animation: none;
        }

        .app-progress-bar::-webkit-progress-value {
            transition: none;
        }
    }

    /* Forced colours (a Windows contrast theme): the track is an outline, the fill the system
       highlight. */
    @media (forced-colors: active) {
        .app-progress-bar {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
            forced-color-adjust: none;
            background: var(--app-color-forced-canvas);
            color: var(--app-color-forced-current);
        }
    }
}
