/* ==========================================================================
   CraftX toast system — custom renderer aligned with the warm carpenter palette.

   Two stacks (.cx-toast-stack), centered horizontally:
     .is-top    — critical/blocking class (Error/Warning/System/Deadline)
     .is-bottom — non-blocking action confirmations (Success/Info/Chat/etc.)

   Each toast is a hairline-bordered card with a 4px severity-coloured left
   bar, an icon, optional title, message body, optional close button, and
   an optional 2px timer sliver at the bottom that animates from full width
   to zero across the toast's Timeout window.
   ========================================================================== */

.cx-toast-stack {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    /* Toasts are the topmost UI surface — they MUST sit above every dialog,
       otherwise error/warning feedback hides behind an open modal and the
       user keeps retrying a failing action without seeing why. Syncfusion
       dialogs across the app set explicit ZIndex values that range from 2000
       up to 1000000300, so a modest value loses the race.
       This sentinel decisively clears them all while staying well under the
       CSS max (2147483647). The stack itself is pointer-events:none, so a high
       z-index never blocks interaction — only the toast cards capture clicks. */
    z-index: 2000000000;
    pointer-events: none;
    width: min(560px, calc(100vw - 32px));
}

.cx-toast-stack.is-top {
    top: calc(var(--cx-topbar-h) + 16px);
}

.cx-toast-stack.is-bottom {
    bottom: 24px;
    flex-direction: column-reverse;
}

.cx-toast-stack > * {
    pointer-events: auto;
}

.cx-toast {
    position: relative;
    width: 100%;
    background: #ffffff;
    border: 1px solid var(--hairline, rgba(28, 25, 21, 0.08));
    border-left: 4px solid var(--copper, #B8601F);
    border-radius: var(--cx-radius-surface);
    box-shadow:
        0 1px 2px rgba(28, 25, 21, 0.04),
        0 12px 32px rgba(28, 25, 21, 0.10);
    padding: 12px 14px;
    display: grid;
    grid-template-columns: 22px 1fr auto;
    column-gap: 12px;
    align-items: flex-start;
    overflow: hidden;
    color: var(--ink, #1C1915);
    font-family: var(--font-sans, "Inter", system-ui, sans-serif);
    font-size: 13.5px;
    line-height: 1.5;
}

/* Entry animations. Designed to break the warm-palette camouflage with
   a clear motion signal:
     - longer travel distance (~36px) so the eye catches the move
     - cubic-bezier with overshoot ("back-out") so the card bounces
       slightly past rest and settles — the bounce is what humans notice
     - paired with an attention pulse on the icon (scale + slight rotate)
       and a one-shot halo glow on the card itself
     - exit is calm, fast, and linear so it gets out of the way
   Honours prefers-reduced-motion. */

.cx-toast.from-top {
    animation:
        cx-toast-in-top 420ms cubic-bezier(0.34, 1.56, 0.45, 1) both,
        cx-toast-glow 900ms ease-out 0ms 1 both;
}

.cx-toast.from-bottom {
    animation:
        cx-toast-in-bottom 420ms cubic-bezier(0.34, 1.56, 0.45, 1) both,
        cx-toast-glow 900ms ease-out 0ms 1 both;
}

/* Exit mirrors the entry direction: top toasts fly back up, bottom toasts
   drop back down. Adds a slight scale-down (0.94) and a 2px blur so the
   card reads as dissolving away rather than just snapping off-screen.
   Accelerating ease-in makes the departure feel decisive. */
.cx-toast.from-top.is-exiting {
    animation: cx-toast-out-top 220ms cubic-bezier(0.5, 0, 0.75, 0) forwards;
    pointer-events: none;
}

.cx-toast.from-bottom.is-exiting {
    animation: cx-toast-out-bottom 220ms cubic-bezier(0.5, 0, 0.75, 0) forwards;
    pointer-events: none;
}

/* Fallback: matches old behaviour for any toast without a direction class. */
.cx-toast.is-exiting:not(.from-top):not(.from-bottom) {
    animation: cx-toast-out-bottom 220ms cubic-bezier(0.5, 0, 0.75, 0) forwards;
    pointer-events: none;
}

@keyframes cx-toast-in-top {
    0%   { opacity: 0; transform: translateY(-36px) scale(0.96); }
    60%  { opacity: 1; transform: translateY(4px)   scale(1.01); }
    100% { opacity: 1; transform: translateY(0)     scale(1); }
}

@keyframes cx-toast-in-bottom {
    0%   { opacity: 0; transform: translateY(36px)  scale(0.96); }
    60%  { opacity: 1; transform: translateY(-4px)  scale(1.01); }
    100% { opacity: 1; transform: translateY(0)     scale(1); }
}

/* One-shot halo pulse using box-shadow — uses currentColor (each
   severity skin sets `color` to its accent), so the glow is tinted
   to the toast type without per-severity overrides. */
@keyframes cx-toast-glow {
    0% {
        box-shadow:
            0 0 0 0 rgba(0, 0, 0, 0),
            0 12px 32px rgba(28, 25, 21, 0.10);
    }
    25% {
        box-shadow:
            0 0 0 6px color-mix(in srgb, currentColor 28%, transparent),
            0 18px 44px rgba(28, 25, 21, 0.18);
    }
    100% {
        box-shadow:
            0 0 0 0 rgba(0, 0, 0, 0),
            0 12px 32px rgba(28, 25, 21, 0.10);
    }
}

@keyframes cx-toast-out-top {
    0%   { opacity: 1; transform: translateY(0)     scale(1);    filter: blur(0); }
    100% { opacity: 0; transform: translateY(-22px) scale(0.94); filter: blur(2px); }
}

@keyframes cx-toast-out-bottom {
    0%   { opacity: 1; transform: translateY(0)    scale(1);    filter: blur(0); }
    100% { opacity: 0; transform: translateY(22px) scale(0.94); filter: blur(2px); }
}

/* Icon pulses briefly when the toast appears — small scale + rotate
   delivers a "pop" that draws the eye to the meaning glyph. */
.cx-toast.from-top .cx-toast__icon i,
.cx-toast.from-bottom .cx-toast__icon i {
    animation: cx-toast-icon-pop 700ms cubic-bezier(0.34, 1.56, 0.45, 1) 80ms both;
}

@keyframes cx-toast-icon-pop {
    0%   { transform: scale(0.6) rotate(-8deg); }
    50%  { transform: scale(1.25) rotate(4deg); }
    100% { transform: scale(1) rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
    .cx-toast.from-top,
    .cx-toast.from-bottom,
    .cx-toast.is-exiting,
    .cx-toast.from-top .cx-toast__icon i,
    .cx-toast.from-bottom .cx-toast__icon i {
        animation-duration: 0ms !important;
        animation-iteration-count: 1 !important;
    }
}

.cx-toast__icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--copper, #B8601F);
    margin-top: 1px;
}

.cx-toast__icon i {
    font-size: 18px;
    line-height: 1;
}

.cx-toast__body {
    min-width: 0;
}

.cx-toast__title {
    font-family: var(--font-display, "Bricolage Grotesque", sans-serif);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--ink, #1C1915);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cx-toast__msg {
    font-size: 13px;
    color: var(--walnut, #4A443C);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.cx-toast__close {
    grid-column: 3;
    grid-row: 1;
    align-self: flex-start;
    margin-left: 6px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--cx-radius-control);
    color: var(--cx-text-muted, #8E8679);
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.cx-toast__close:hover {
    background: var(--sand, #F5EFE6);
    color: var(--ink, #1C1915);
}

.cx-toast__close i {
    font-size: 11px;
}

.cx-toast__timer {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 100%;
    background: currentColor;
    opacity: 0.35;
    transform-origin: left center;
    animation-name: cx-toast-timer;
    animation-timing-function: linear;
    animation-fill-mode: forwards;
}

@keyframes cx-toast-timer {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ── Severity skins ──────────────────────────────────────────────────── */

.cx-toast--success {
    border-left-color: var(--success, #3F7D5B);
    color: var(--success, #3F7D5B); /* drives .cx-toast__timer color */
}
.cx-toast--success .cx-toast__icon { color: var(--success, #3F7D5B); }

.cx-toast--info {
    border-left-color: var(--info, #1F4A82);
    color: var(--info, #1F4A82);
}
.cx-toast--info .cx-toast__icon { color: var(--info, #1F4A82); }

.cx-toast--warning {
    border-left-color: var(--warning, #A97514);
    color: var(--warning, #A97514);
    background: var(--paper-2, #FAF7F2);
}
.cx-toast--warning .cx-toast__icon { color: var(--warning, #A97514); }

.cx-toast--danger {
    border-left-color: var(--danger, #9A3B33);
    color: var(--danger, #9A3B33);
    background: #FFF8F7;
}
.cx-toast--danger .cx-toast__icon { color: var(--danger, #9A3B33); }
.cx-toast--danger .cx-toast__title { color: var(--danger, #9A3B33); }

.cx-toast--system,
.cx-toast--reminder,
.cx-toast--calendar,
.cx-toast--chat {
    border-left-color: var(--copper, #B8601F);
    color: var(--copper, #B8601F);
}
.cx-toast--system .cx-toast__icon,
.cx-toast--reminder .cx-toast__icon,
.cx-toast--calendar .cx-toast__icon,
.cx-toast--chat .cx-toast__icon { color: var(--copper, #B8601F); }

/* Compact mode on narrow viewports — drop padding, allow toast to span. */
@media (max-width: 480px) {
    .cx-toast-stack {
        width: calc(100vw - 16px);
    }
    .cx-toast {
        padding: 10px 12px;
        font-size: 13px;
        column-gap: 10px;
    }
    .cx-toast__title { font-size: 13px; }
    .cx-toast__msg   { font-size: 12.5px; }
}

/* Hide the legacy SfToast skin so the old fluent2 chrome doesn't show
   if any consumer still spawns one — e.g. through a Syncfusion grid
   built-in. The redesigned cx-toast above is the canonical surface. */
.modern-toast .e-toast-container,
.e-toast-container.modern-toast { display: none !important; }
