/*
 * sync.css — whether the device is connected and its changes are sent, and why a control that
 * stays visible cannot be used now.
 *
 * Sync status, in the shell bar (or wherever the screen keeps it):
 * <p class="app-sync" role="status" data-state="online | syncing | offline | failed">
 *   <span class="app-sync-icon" aria-hidden="true">[cloud-check | sync | cloud-off | danger]</span>
 *   <span class="app-sync-label">Offline</span>
 *   <span class="app-sync-count" aria-hidden="true">3</span>
 *   <span class="app-sync-detail">3 Änderungen ausstehend</span>
 * </p>
 *
 * role="status" makes a change of state a polite announcement. Online and syncing are quiet:
 * text in the subtle colour, no fill. Offline and failed are a ringed pill in the warning and
 * danger tones, the one time the status asks to be seen. Every state has the same box, so a
 * change of state moves nothing beside it. Count and detail are written only while changes
 * wait to be sent. In a container narrower than 560 (the shell bar on a phone) the status gets
 * short: the detail is read out but not shown and the count stands in for it, and online and
 * syncing show only their icon, their label read out. Wider, label and detail show and the count
 * goes; the pill is tighter there, so offline or failed with a count fits beside a title and an
 * icon button at 320. The syncing icon turns, and stands still under reduced motion.
 *
 * Reason:
 * <button class="app-button" … aria-disabled="true" aria-describedby="id">Abschließen</button>
 * <p class="app-reason" id="id">
 *   <span class="app-reason-icon" aria-hidden="true">[cloud-off]</span>
 *   <span class="app-reason-text">Abschließen geht nur online.</span>
 * </p>
 *
 * The control is aria-disabled, not disabled: it stays in the tab order, so the keyboard and a
 * screen reader reach it and hear the reason through aria-describedby. The reason is text on
 * the screen, never only a hover hint. In an action bar it takes a line of its own above the
 * buttons (shell.css).
 */
@layer components {
    .app-sync {
        position: relative;
        display: inline-flex;
        flex: none;
        align-items: center;
        gap: var(--app-space-sync-gap);
        min-block-size: var(--app-sync-height);
        padding-inline: var(--app-space-sync-x);
        border-radius: var(--app-radius-sync);
        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);
        white-space: nowrap;
    }

    .app-sync-icon {
        display: inline-flex;
        flex: none;
    }

    .app-sync[data-state="syncing"] .app-sync-icon {
        animation: app-sync-turn var(--app-duration-busy) var(--app-easing-busy) infinite;
    }

    .app-sync[data-state="offline"] {
        background: var(--app-color-warning-soft);
        box-shadow: inset 0 0 0 var(--app-border-width) currentcolor;
        color: var(--app-color-warning-text);
    }

    .app-sync[data-state="failed"] {
        background: var(--app-color-danger-soft);
        box-shadow: inset 0 0 0 var(--app-border-width) currentcolor;
        color: var(--app-color-danger-text);
    }

    .app-sync-detail {
        font-weight: var(--app-text-body-weight);
    }

    .app-sync-count {
        display: none;
        align-items: center;
        justify-content: center;
        min-inline-size: var(--app-badge-size);
        block-size: var(--app-badge-size);
        padding-inline: var(--app-space-badge-x);
        border-radius: var(--app-radius-round);
        background: var(--app-color-surface-muted);
        color: var(--app-color-text-muted);
        font-size: var(--app-text-count-size);
        font-variant-numeric: tabular-nums;
    }

    .app-sync[data-state="offline"] .app-sync-count {
        background: var(--app-color-warning-text);
        color: var(--app-color-text-on-accent);
    }

    .app-sync[data-state="failed"] .app-sync-count {
        background: var(--app-color-danger-text);
        color: var(--app-color-text-on-accent);
    }

    .app-sync-detail:empty {
        display: none;
    }

    /* Narrow: the count is shown, the detail is read out. */
    @container (width < 560px) {
        .app-sync {
            gap: var(--app-space-sync-gap-narrow);
            padding-inline: var(--app-space-sync-x-narrow);
        }

        .app-sync-count:not(:empty) {
            display: inline-flex;
        }

        .app-sync:is([data-state="online"], [data-state="syncing"]) .app-sync-label,
        .app-sync-detail {
            position: absolute;
            inline-size: var(--app-border-width);
            block-size: var(--app-border-width);
            overflow: hidden;
            clip-path: inset(50%);
            white-space: nowrap;
        }
    }

    @media (prefers-reduced-motion: reduce) {
        .app-sync[data-state="syncing"] .app-sync-icon {
            animation: none;
        }
    }

    @keyframes app-sync-turn {
        to {
            transform: rotate(1turn);
        }
    }

    /* Reason. */
    .app-reason {
        display: flex;
        align-items: flex-start;
        gap: var(--app-space-reason-gap);
        color: var(--app-color-text-muted);
        font-family: var(--app-font-text);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
    }

    .app-reason-icon {
        display: inline-flex;
        flex: none;
        align-items: center;
        block-size: var(--app-text-body-leading);
    }

    .app-reason-icon:empty {
        display: none;
    }

    .app-reason-text {
        min-inline-size: 0;
    }

    /* Forced colours: fills and rings are gone, so the pill and the count are outlined. */
    @media (forced-colors: active) {
        .app-sync:is([data-state="offline"], [data-state="failed"]),
        .app-sync-count {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
    }
}
