/*
 * toast.css — a short message about something that just happened: saved, cancelled, failed.
 *
 * <section class="app-toaster" popover="manual" aria-label="Meldungen">
 *   <div class="app-toaster-list" aria-live="polite">
 *     <div class="app-toast" data-tone="success | info | danger" role="alert (danger only)">
 *       <span class="app-toast-icon" aria-hidden="true">[icon]</span>
 *       <p class="app-toast-text">Auftrag gespeichert.</p>
 *       <div class="app-toast-actions">[button: Rückgängig]</div>
 *       <button class="app-icon-button" … aria-label="Schließen">[icon: close]</button>
 *     </div>
 *   </div>
 * </section>
 *
 * One toaster per app, always in the DOM and always open (a manual popover, so it is in the top
 * layer above bars and drawers); an empty one takes no room and no clicks. The list is the live
 * region, so a new toast is read out; a failure is an alert. From a viewport of 560 toasts stack
 * at the top end, under the shell's bar. Below it they stand at the bottom across the screen,
 * under the thumb that has just acted and where an undo can be reached: just above the page's
 * action bar (anchor positioning; shell.css names it), else just above the tab bar, or above
 * the gesture bar when the page has neither. Never over the action bar, whose button is the next thing a person presses, and
 * never over the page's title. Success and info go by
 * themselves; a failure stays until it is closed.
 *
 * A row is one line in a control-high box: 4 + 32 + 4 = 40; each more line adds 20.
 */
@layer components {
    .app-toaster {
        position: fixed;
        inset: calc(var(--app-bar-height) + var(--app-space-safe-top) + var(--app-space-overlay-edge)) var(--app-space-overlay-edge) auto auto;
        inline-size: var(--app-toast-width);
        max-inline-size: calc(100% - 2 * var(--app-space-overlay-edge));
        margin: 0;
        padding: 0;
        overflow: visible;
        border: 0;
        background: transparent;
        pointer-events: none;
    }

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

    .app-toast {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto auto;
        align-items: center;
        gap: var(--app-space-inline);
        padding: var(--app-space-toast-y) var(--app-space-toast-x);
        border-radius: var(--app-radius-popover);
        background: var(--app-color-surface-raised);
        color: var(--app-color-text);
        font-size: var(--app-text-body-size);
        line-height: var(--app-text-body-leading);
        box-shadow:
            0 0 0 var(--app-border-width) var(--app-color-line),
            var(--app-shadow-popover);
        pointer-events: auto;
    }

    .app-toast-icon {
        display: inline-flex;
        color: var(--app-color-info-text);
    }

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

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

    .app-toast-actions {
        display: flex;
        gap: var(--app-space-actions);
    }

    .app-toast-actions:empty {
        display: none;
    }

    @media (width < 560px) {
        .app-toaster {
            inset: auto var(--app-space-overlay-edge) calc(var(--app-space-safe-bottom) + var(--app-space-overlay-edge));
            inline-size: auto;
        }

        /* Above the action bar where there is one, else above the tab bar. A browser without
           anchors keeps the line above, at the bottom; with neither bar the fallback is the
           same place. */
        .app-toaster {
            inset-block-end: calc(anchor(--app-action-bar top, anchor(--app-tab-bar top, var(--app-space-safe-bottom))) + var(--app-space-overlay-edge));
        }

        /* With the keyboard up the tab bar has gone: above the action bar, else the keyboard. */
        :root[data-keyboard] .app-toaster {
            inset-block-end: calc(anchor(--app-action-bar top, var(--app-space-keyboard)) + var(--app-space-overlay-edge));
        }
    }

    /* 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-toast {
            outline: var(--app-border-width) solid var(--app-color-forced-line);
            outline-offset: calc(-1 * var(--app-border-width));
        }
    }
}
