.app-notification-stack {
    position: fixed;
    top: max(16px, env(safe-area-inset-top));
    right: max(16px, env(safe-area-inset-right));
    z-index: 1000;
    width: min(420px, calc(100vw - 32px));
    max-height: min(70dvh, calc(100dvh - 32px));
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    pointer-events: none;
}

body:has(.results-anchor-menu) .app-notification-stack {
    --notification-sidebar-reserve: var(--sidebar-active-width, 250px);
    right: 274px;
    width: min(420px, calc(100vw - var(--notification-sidebar-reserve) - 290px));
}

body.is-sidebar-user-compact:has(.results-anchor-menu) .app-notification-stack {
    --notification-sidebar-reserve: var(--sidebar-compact-width, 84px);
}

.app-toast {
    --toast-accent: #60a5fa;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex: 0 0 auto;
    padding: 14px 14px 14px 16px;
    border: 1px solid color-mix(in srgb, var(--toast-accent) 52%, #334155);
    border-left: 4px solid var(--toast-accent);
    border-radius: 14px;
    color: #f1f5f9;
    background: #111c2f;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.38);
    pointer-events: auto;
    animation: app-toast-enter 160ms ease-out;
}

.app-toast--success { --toast-accent: #34d399; }
.app-toast--info { --toast-accent: #60a5fa; }
.app-toast--warning { --toast-accent: #fbbf24; }
.app-toast--error { --toast-accent: #f87171; }

.app-toast.is-dismissing {
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 140ms ease, transform 140ms ease;
}

.app-toast__copy {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.app-toast__title,
.app-toast__message {
    display: block;
    overflow-wrap: anywhere;
}

.app-toast__title {
    color: #f8fafc;
}

.app-toast__message {
    color: #cbd5e1;
    font-size: 0.9rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.app-toast__dismiss {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    flex: 0 0 32px;
    margin: -4px -4px 0 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #cbd5e1;
    font: inherit;
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}

.app-toast__dismiss:hover {
    border-color: #475569;
    background: #1e293b;
    color: #fff;
}

.app-toast__dismiss:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--toast-accent) 70%, white);
    outline-offset: 2px;
}

@keyframes app-toast-enter {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 721px) and (max-width: 1280px) {
    body:has(.results-anchor-menu) .app-notification-stack {
        --notification-sidebar-reserve: var(--sidebar-compact-width, 84px);
    }
}

@media (max-width: 720px) {
    .app-notification-stack,
    body:has(.results-anchor-menu) .app-notification-stack {
        top: max(16px, env(safe-area-inset-top));
        bottom: auto;
        left: max(16px, env(safe-area-inset-left));
        right: max(16px, env(safe-area-inset-right));
        width: auto;
        max-height: 50dvh;
    }

    body:has(.results-anchor-menu) .app-notification-stack {
        top: max(64px, calc(env(safe-area-inset-top) + 48px));
    }

    body.has-results-anchor-open:has(.results-anchor-menu) {
        --notification-narrow-open-reserve: clamp(120px, 32dvh, 220px);
    }

    body.has-results-anchor-open:has(.results-anchor-menu) .results-anchor-list {
        max-height: max(
            0px,
            calc(
                100dvh
                - 64px
                - var(--notification-narrow-open-reserve)
                - max(16px, env(safe-area-inset-bottom))
            )
        );
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    body.has-results-anchor-open:has(.results-anchor-menu) .app-notification-stack {
        top: auto;
        bottom: max(16px, env(safe-area-inset-bottom));
        max-height: var(--notification-narrow-open-reserve);
    }
}

@media (min-width: 1580px) {
    body:has(.results-anchor-menu) .app-notification-stack {
        right: max(16px, env(safe-area-inset-right));
        width: min(420px, calc(100vw - 32px));
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-toast,
    .app-toast.is-dismissing {
        animation: none;
        transition: none;
        transform: none;
    }
}
