/* =============================================================================
   toast.css
   In-page notification toasts (Toast.success / Toast.error / Toast.flash …).
   Loaded on every page from fragments/head.jsp so any page can fire a toast
   without bringing in extra assets.

   Anatomy of a toast
   ──────────────────
       ┌────┬──────────────────────────────────┬─────┐
       │    │  Title                           │  ✕  │
       │ ⓘ  │  Optional secondary message      │     │
       │    │                                  │     │
       └────┴──────────────────────────────────┴─────┘
       └─ inline-start accent stripe (per-type gradient)
                                                   └─ progress bar (auto-dismiss)

   Notes
   -----
   • Anchored to the top inline-end corner, so top-right on LTR and top-left
     on RTL; the enter/leave slide follows the same axis.
   • Backdrop-blur card with type-specific accents (success/error/warning/info).
   • Pause-on-hover / pause-on-focus is driven from toast.js, which freezes the
     progress bar's inline transform while the user reads the toast.
   • Honours `prefers-reduced-motion`: drops the slide animation but keeps a
     soft opacity fade (toast.js also skips the progress animation).
   ========================================================================== */

:root {
    --lingo-toast-bg:        rgba(255, 255, 255, 0.96);
    --lingo-toast-fg:        var(--text, #0f1720);
    --lingo-toast-fg-muted:  var(--text-muted, rgba(15, 23, 32, 0.65));
    --lingo-toast-border:    var(--border, rgba(15, 23, 32, 0.06));
    --lingo-toast-shadow:    var(--shadow-lg, 0 22px 50px -14px rgba(15, 23, 32, 0.22));
    --lingo-toast-close-hover: rgba(15, 23, 32, 0.06);
}

[data-theme="dark"] {
    /* Matches --surface (#171d21) with enough alpha for the blur to read. */
    --lingo-toast-bg:        rgba(23, 29, 33, 0.96);
    --lingo-toast-close-hover: rgba(255, 255, 255, 0.08);
}

/* ---------- Stack container ------------------------------------------- */

.lingo-toast-stack {
    position: fixed;
    top: 1.25rem;
    inset-inline-end: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    pointer-events: none;
    width: min(380px, calc(100vw - 2.5rem));
}

@media (max-width: 480px) {
    .lingo-toast-stack {
        top: 0.6rem;
        inset-inline: 0.6rem;
        width: auto;
    }
}

/* ---------- Toast card ------------------------------------------------ */

.lingo-toast {
    position: relative;
    pointer-events: auto;
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    padding-block: 0.85rem 0.95rem;
    padding-inline: 1.45rem 0.95rem;
    border-radius: 14px;
    background: var(--lingo-toast-bg);
    color: var(--lingo-toast-fg);
    border: 1px solid var(--lingo-toast-border);
    box-shadow: var(--lingo-toast-shadow);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    overflow: hidden;
    transform: translateX(120%) scale(0.96);
    opacity: 0;
    transition:
        transform 320ms cubic-bezier(0.18, 0.89, 0.32, 1.28),
        opacity 240ms ease,
        margin 220ms ease;
    will-change: transform, opacity;
}

/* The stack sits against the inline-end edge, so RTL slides in from the left. */
[dir="rtl"] .lingo-toast {
    transform: translateX(-120%) scale(0.96);
}

.lingo-toast.is-visible {
    transform: translateX(0) scale(1);
    opacity: 1;
}

.lingo-toast.is-leaving {
    transform: translateX(120%) scale(0.96);
    opacity: 0;
    transition: transform 200ms ease-in, opacity 180ms ease-in;
}

[dir="rtl"] .lingo-toast.is-leaving {
    transform: translateX(-120%) scale(0.96);
}

/* Accent stripe on the reading edge — coloured per-type. */
.lingo-toast::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    inset-inline-start: 0;
    width: 5px;
    background: var(--lingo-toast-accent);
}

/* ---------- Type variants -------------------------------------------- */

.lingo-toast--success {
    --lingo-toast-accent:   linear-gradient(180deg, #4ec07a 0%, #2f9d5d 100%);
    --lingo-toast-icon-bg:  linear-gradient(135deg, #4ec07a 0%, #2f9d5d 100%);
    --lingo-toast-icon-glow: rgba(47, 157, 93, 0.35);
}

.lingo-toast--error {
    --lingo-toast-accent:   linear-gradient(180deg, #ef6b6b 0%, #c84b4b 100%);
    --lingo-toast-icon-bg:  linear-gradient(135deg, #ef6b6b 0%, #c84b4b 100%);
    --lingo-toast-icon-glow: rgba(200, 75, 75, 0.35);
}

.lingo-toast--warning {
    --lingo-toast-accent:   linear-gradient(180deg, #f5a623 0%, #d97706 100%);
    --lingo-toast-icon-bg:  linear-gradient(135deg, #f5a623 0%, #d97706 100%);
    --lingo-toast-icon-glow: rgba(217, 119, 6, 0.35);
}

/* Brand-coloured; --primary already flips for dark mode. */
.lingo-toast--info {
    --lingo-toast-accent:   linear-gradient(180deg, var(--primary) 0%, var(--primary-hover) 100%);
    --lingo-toast-icon-bg:  linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    --lingo-toast-icon-glow: var(--ring);
}

/* ---------- Inner pieces --------------------------------------------- */

.lingo-toast__icon {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--lingo-toast-icon-bg);
    color: #ffffff;
    font-size: 1rem;
    box-shadow: 0 6px 16px -4px var(--lingo-toast-icon-glow);
}

/* Subtle pop on enter so the icon has a tiny celebratory bounce. */
.lingo-toast.is-visible .lingo-toast__icon {
    animation: lingoToastIconPop 360ms cubic-bezier(0.18, 0.89, 0.32, 1.6);
}

@keyframes lingoToastIconPop {
    0%   { transform: scale(0.6); }
    60%  { transform: scale(1.12); }
    100% { transform: scale(1); }
}

.lingo-toast__body {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding-top: 0.18rem;
}

.lingo-toast__title {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.lingo-toast__message {
    font-size: 0.85rem;
    color: var(--lingo-toast-fg-muted);
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.lingo-toast__close {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    margin-block: -0.2rem;
    margin-inline: 0 -0.3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--lingo-toast-fg-muted);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    font-size: 0.85rem;
}

.lingo-toast__close:hover {
    background: var(--lingo-toast-close-hover);
    color: var(--lingo-toast-fg);
}

.lingo-toast__close:focus-visible {
    background: var(--lingo-toast-close-hover);
    color: var(--lingo-toast-fg);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (max-width: 480px) {
    /* Comfortable thumb target on phones. */
    .lingo-toast__close {
        width: 44px;
        height: 44px;
        margin-block: -0.35rem;
    }
}

.lingo-toast__progress {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    height: 3px;
    background: var(--lingo-toast-accent);
    transform-origin: left center;
    transform: scaleX(1);
    opacity: 0.7;
}

[dir="rtl"] .lingo-toast__progress {
    transform-origin: right center;
}

/* ---------- Reduced-motion friendly fallback ------------------------- */

@media (prefers-reduced-motion: reduce) {
    .lingo-toast {
        transition: opacity 0.18s ease;
        transform: none !important;
    }
    .lingo-toast.is-leaving {
        transform: none !important;
    }
    .lingo-toast.is-visible .lingo-toast__icon {
        animation: none;
    }
    /* toast.js also skips writing the inline transition, but keep the CSS
       guard for any toast rendered before the script decides. */
    .lingo-toast__progress {
        transition: none !important;
    }
}
