/* ---------------------------------------------------------------------------
   Toasts (Components/Shared/ToastHost.razor), drawn like the Studio's notice
   cards (Botzilla.Studio/StudioWindow.Notices.cs): bottom-right, newest in the
   corner, at most four, a 360px card with an accent dot, a semibold title,
   secondary message, a close button and a 2px countdown bar that pauses on
   hover. They slide in 28px from the right while fading in (220 ms), restack
   (200 ms) and leave 20px to the right while fading out (160 ms), eased out.
   The timer bar's animationend is what dismisses the toast.
--------------------------------------------------------------------------- */
.bz-toasts {
    --bz-toast-ease: cubic-bezier(.33, 1, .68, 1); /* ease-out cubic, the Studio's EaseOut */
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    width: min(360px, calc(100vw - 24px));
    pointer-events: none;
}

/* The slot's grid row grows from 0fr so toasts already on screen glide up instead of jumping. */
.bz-toast-slot {
    display: grid;
    grid-template-rows: 1fr;
    margin-top: 12px;
    animation: bz-toast-grow 200ms var(--bz-toast-ease) both;
}

.bz-toast-slot > .bz-toast { min-height: 0; }

.bz-toast-slot.is-leaving {
    animation: bz-toast-out 160ms var(--bz-toast-ease) both;
    pointer-events: none;
}

.bz-toast {
    --k: #5291EF;
    position: relative;
    display: flex;
    align-items: flex-start;
    padding: 12px 8px 14px 14px;
    border: 1px solid var(--bz-border, #4E5764);
    border-radius: 6px;
    background: var(--bz-card, #353B44);
    color: var(--mud-palette-text-primary, #E7EAEF);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .28);
    overflow: hidden;
    pointer-events: auto;
    cursor: pointer;
    animation: bz-toast-in 220ms var(--bz-toast-ease) backwards;
}

/* The Studio's Raised colours in the dark theme. */
.app-theme-dark .bz-toast { background: #353B44; border-color: #4E5764; color: #E7EAEF; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); }

.is-leaving > .bz-toast { animation: none; }
.bz-toast:focus-visible { outline: 2px solid var(--k); outline-offset: 2px; }

.bz-toast-success { --k: #4EC984; }
.bz-toast-error { --k: #F76B63; }
.bz-toast-warning { --k: #E0A84A; }
.bz-toast-info { --k: #5291EF; }

.bz-toast-dot {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    margin: 4px 10px 0 0;
    border-radius: 50%;
    background: var(--k);
}

.bz-toast-body {
    flex: 1 1 auto;
    min-width: 0;
    margin-right: 8px;
    overflow-wrap: anywhere;
    white-space: pre-line;
}

.bz-toast-title { font-size: 13px; font-weight: 600; line-height: 1.35; }
.bz-toast-title.bz-toast-plain { font-weight: 400; }

.bz-toast-message {
    margin-top: 2px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--mud-palette-text-secondary, #A6AFBB);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    overflow: hidden;
}

.app-theme-dark .bz-toast-message { color: #A6AFBB; }

.bz-toast-action {
    margin: 6px 0 0 -6px;
    padding: 3px 6px;
    border: 0;
    border-radius: 4px;
    background: none;
    color: var(--k);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.bz-toast-action:hover,
.bz-toast-action:focus-visible { background: color-mix(in srgb, var(--k) 16%, transparent); outline: none; }

.bz-toast-count {
    flex: 0 0 auto;
    align-self: flex-start;
    margin: 1px 6px 0 0;
    padding: 0 6px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--k) 22%, transparent);
    color: var(--k);
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
}

/* The Studio's "tool" button: a quiet ✕ that lights up under the pointer. */
.bz-toast-close {
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: none;
    color: inherit;
    font-size: 12px;
    line-height: 1;
    opacity: .7;
    cursor: pointer;
}

.bz-toast-close:hover,
.bz-toast-close:focus-visible { opacity: 1; background: rgba(127, 127, 127, .2); outline: none; }

.bz-toast-timer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: var(--k);
    transform-origin: left center;
    animation-name: bz-toast-countdown;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

/* Only hovering pauses the countdown: focus could stay on a toast (its Undo button) and keep it open for good. */
.bz-toast:hover .bz-toast-timer { animation-play-state: paused; }

@keyframes bz-toast-grow { from { grid-template-rows: 0fr; margin-top: 0; } to { grid-template-rows: 1fr; margin-top: 12px; } }
@keyframes bz-toast-in { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes bz-toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(20px); } }
@keyframes bz-toast-countdown { from { transform: scaleX(1); } to { transform: scaleX(0); } }

@media (max-width: 600px) {
    .bz-toasts { left: 8px; right: 8px; bottom: 8px; width: auto; }
}

/* Reduced motion keeps a plain fade; the timer bar still runs because it drives dismissal. */
@media (prefers-reduced-motion: reduce) {
    .bz-toast-slot, .bz-toast { animation-name: bz-toast-fade; }
    .bz-toast-slot.is-leaving { animation-name: bz-toast-fade; animation-direction: reverse; }
}

@keyframes bz-toast-fade { from { opacity: 0; } to { opacity: 1; } }
