/*!
 * garxly-toast.css — Garxly Centralised Notification surface.
 *
 * The single visual system for transient toasts (window.GxToast, and
 * everything routed through window.Notify / notify()) AND the premium skin for
 * the SweetAlert2 confirm / dialog modals that Notify.confirm / Notify.dialog
 * still drive.
 *
 * Design language adapted from the 21st.dev "Toast" component (Base UI stacked
 * toast): peek-stacked cards that fan out on hover/focus, status icon chip +
 * title + message + optional action, thin depleting progress bar, swipe- or
 * click-to-dismiss, direction-aware enter/exit. Reimplemented natively — no
 * React, no new runtime.
 *
 * Tokens map to the app's --tblr-* / DESIGN.md scale with hard fallbacks so
 * the file also works in layouts/super_admin_plain.php (no gx-* token layer).
 * Radius: 14px card = {rounded.lg} modal scale, 10px = {rounded.btn-sm},
 * 8px = {rounded.sm}. Type: rem steps off the DESIGN.md ramp. Status colours
 * are the DESIGN.md status palette ({colors.good/warn/danger/info}). Dark mode
 * follows [data-bs-theme="dark"] only. Fully neutralised under
 * prefers-reduced-motion. Load AFTER garxly-motion.css.
 */

/* ────────────────────────────────────────────────────────────────────────
   Tokens
   ──────────────────────────────────────────────────────────────────────── */
:root {
    --gxt-ease: var(--gx-ease-emphasized, cubic-bezier(0.16, 1, 0.3, 1));
    --gxt-ease-out: var(--gx-ease-standard, cubic-bezier(0.2, 0, 0, 1));
    --gxt-dur-in: 420ms;
    --gxt-dur-out: 220ms;
    --gxt-dur-move: 380ms;

    --gxt-width: 380px;
    --gxt-gap: 12px;             /* gap between cards when the stack is expanded */
    --gxt-peek: 9px;             /* how far each collapsed card peeks past the front one */
    --gxt-inset: 18px;          /* viewport distance from the screen edge */

    --gxt-surface: var(--tblr-bg-surface, #ffffff);
    --gxt-surface-raised: var(--tblr-bg-surface-secondary, #f4f1e6);
    --gxt-border: var(--tblr-border-color, rgba(92, 64, 51, 0.15));
    --gxt-title: var(--tblr-body-color, #5c4033);
    --gxt-text: var(--tblr-secondary-color, #7b675b);
    --gxt-shadow:
        0 6px 16px -4px rgba(15, 23, 42, 0.12),
        0 2px 6px -2px rgba(15, 23, 42, 0.08);
    --gxt-ring-inset: inset 0 1px 0 rgba(255, 255, 255, 0.55);
    --gxt-focus-ring: 0 0 0 3px rgba(var(--tblr-primary-rgb, 6, 64, 43), 0.28);

    --gxt-success: var(--tblr-success, #1e7a4b);
    --gxt-success-bg: rgba(30, 122, 75, 0.12);
    --gxt-error: var(--tblr-danger, #b3261e);
    --gxt-error-bg: rgba(179, 38, 30, 0.12);
    --gxt-warning: var(--tblr-warning, #92650a);
    --gxt-warning-bg: rgba(146, 101, 10, 0.14);
    --gxt-info: var(--tblr-info, #1d4ed8);
    --gxt-info-bg: rgba(29, 78, 216, 0.12);
    --gxt-loading: var(--tblr-primary, #06402b);
    --gxt-loading-bg: rgba(6, 64, 43, 0.12);
}

[data-bs-theme="dark"] {
    --gxt-surface: var(--tblr-bg-surface, #141d1a);
    --gxt-surface-raised: var(--tblr-bg-surface-secondary, #101815);
    --gxt-border: var(--tblr-border-color, rgba(212, 175, 55, 0.22));
    --gxt-title: var(--tblr-body-color, #f5f5dc);
    --gxt-text: var(--tblr-secondary-color, rgba(245, 245, 220, 0.72));
    --gxt-shadow:
        0 10px 26px -6px rgba(0, 0, 0, 0.55),
        0 4px 10px -4px rgba(0, 0, 0, 0.45);
    --gxt-ring-inset: inset 0 1px 0 rgba(255, 255, 255, 0.05);

    --gxt-success: var(--tblr-success, #6fcf97);   --gxt-success-bg: rgba(111, 207, 151, 0.16);
    --gxt-error: var(--tblr-danger, #f0857d);      --gxt-error-bg: rgba(240, 133, 125, 0.16);
    --gxt-warning: var(--tblr-warning, #e0b64d);   --gxt-warning-bg: rgba(224, 182, 77, 0.16);
    --gxt-info: var(--tblr-info, #7aa2f7);         --gxt-info-bg: rgba(122, 162, 247, 0.16);
    --gxt-loading: var(--tblr-primary, #086343);   --gxt-loading-bg: rgba(8, 99, 67, 0.20);
}

/* ────────────────────────────────────────────────────────────────────────
   Viewport — one per document, positioned top-right, created by the engine.
   pointer-events:none so the empty area never blocks the page; each card
   re-enables them. The engine sets inline height (collapsed vs expanded).
   ──────────────────────────────────────────────────────────────────────── */
.gx-toast-viewport {
    position: fixed;
    top: var(--gxt-inset);
    right: var(--gxt-inset);
    z-index: 11000;                 /* above SweetAlert2 (1060) and app overlays */
    width: var(--gxt-width);
    max-width: calc(100vw - var(--gxt-inset) * 2);
    pointer-events: none;
    /* No height/transition here on purpose: cards are absolutely positioned
       and placed via transform only (see garxly-toast.js layout()) — the
       viewport box itself never needs to be measured, sized, or animated. */
}

@media (max-width: 480px) {
    .gx-toast-viewport {
        left: var(--gxt-inset);
        right: var(--gxt-inset);
        width: auto;
    }
}

/* ────────────────────────────────────────────────────────────────────────
   Card
   ──────────────────────────────────────────────────────────────────────── */
.gx-toast {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    pointer-events: auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
        "icon body close"
        "icon action action";
    align-items: start;
    column-gap: 12px;
    row-gap: 8px;
    padding: 14px 14px 15px;
    border-radius: 14px;
    border: 1px solid var(--gxt-border);
    background: var(--gxt-surface);
    color: var(--gxt-title);
    box-shadow: var(--gxt-shadow), var(--gxt-ring-inset);
    overflow: hidden;
    transform-origin: top right;
    will-change: transform, opacity;
    /* Enter starts here; the engine flips --gxt-enter to 0 on the next frame. */
    --gxt-enter: 1;
    --gxt-swipe: 0px;
    --gxt-stack-y: 0px;
    --gxt-stack-scale: 1;
    --gxt-accent: var(--gxt-info);
    --gxt-accent-bg: var(--gxt-info-bg);
    transform:
        translateX(calc((100% + var(--gxt-inset) + 40px) * var(--gxt-enter) + var(--gxt-swipe)))
        translateY(var(--gxt-stack-y))
        scale(var(--gxt-stack-scale));
    opacity: calc(1 - var(--gxt-enter));
    transition:
        transform var(--gxt-dur-move) var(--gxt-ease),
        opacity var(--gxt-dur-out) var(--gxt-ease-out),
        box-shadow var(--gxt-dur-move) var(--gxt-ease);
}

/* Entering: use the slower, settling curve for the incoming slide. */
.gx-toast.is-entering {
    transition:
        transform var(--gxt-dur-in) var(--gxt-ease),
        opacity var(--gxt-dur-in) var(--gxt-ease-out);
}

/* Leaving: slide back out to the right and fade. */
.gx-toast.is-leaving {
    --gxt-enter: 1;
    opacity: 0;
    transition:
        transform var(--gxt-dur-out) var(--gxt-ease-out),
        opacity var(--gxt-dur-out) var(--gxt-ease-out);
}

/* While a pointer is dragging the card, kill the transform transition so it
   tracks the finger 1:1 (engine adds .is-dragging). */
.gx-toast.is-dragging {
    transition: none;
    cursor: grabbing;
}

/* Collapsed cards behind the front one. */
.gx-toast.is-behind { cursor: pointer; }
.gx-toast.is-behind .gx-toast__close,
.gx-toast.is-behind .gx-toast__action {
    opacity: 0;
    pointer-events: none;
}

/* Expanded stack (hover / focus-within / touch-held): every card to full
   scale. The engine sets --gxt-stack-y to the expanded offset in that state. */
.gx-toast-viewport.is-expanded .gx-toast { --gxt-stack-scale: 1; }
.gx-toast-viewport.is-expanded .gx-toast.is-behind .gx-toast__close,
.gx-toast-viewport.is-expanded .gx-toast.is-behind .gx-toast__action {
    opacity: 1;
    pointer-events: auto;
}

/* Deep in the collapsed pile (4th and beyond) — hidden until expanded. */
.gx-toast.is-overflow { opacity: 0; pointer-events: none; }
.gx-toast-viewport.is-expanded .gx-toast.is-overflow { opacity: 1; pointer-events: auto; }

/* ── Icon chip ─────────────────────────────────────────────────────────── */
.gx-toast__icon {
    grid-area: icon;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--gxt-accent-bg);
    color: var(--gxt-accent);
    flex: none;
}
.gx-toast__icon svg { width: 18px; height: 18px; display: block; }
.gx-toast--loading .gx-toast__icon svg { animation: gxt-spin 0.8s linear infinite; }

/* Success: a brief blue spark burst around the check icon, once on entrance —
   decorative accent only, distinct from the icon's own success (green) tint.
   One pseudo-element, four box-shadow "sparks" faking multiple dots. */
.gx-toast--success .gx-toast__icon { position: relative; }
.gx-toast--success .gx-toast__icon::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow:
        0 -9px 0 -7px var(--gxt-info),
        0 9px 0 -7px var(--gxt-info),
        -9px 0 0 -7px var(--gxt-info),
        9px 0 0 -7px var(--gxt-info);
    opacity: 0;
    animation: gxt-spark 0.7s ease-out 0.05s 1;
}
@keyframes gxt-spark {
    0%   { opacity: 0; transform: scale(0.5); }
    35%  { opacity: 1; transform: scale(1.15); }
    100% { opacity: 0; transform: scale(1.7); }
}

/* error/warning: sad-face emoji, one gentle jump on entrance. */
.gx-toast__emoji {
    font-size: 1.05rem; /* {typography.card-title} step — closest documented size to the 18px icon it replaces */
    line-height: 1;
    display: block;
    animation: gxt-jump 0.6s ease-out 0.05s 1;
}
@keyframes gxt-jump {
    0%, 100% { transform: translateY(0); }
    30%      { transform: translateY(-5px); }
    55%      { transform: translateY(0); }
    75%      { transform: translateY(-2px); }
}

/* ── Body ─────────────────────────────────────────────────────────────── */
.gx-toast__body {
    grid-area: body;
    min-width: 0;
    padding-top: 1px;
}
.gx-toast__title {
    font-size: 0.9rem;
    font-weight: 650;
    line-height: 1.35;
    color: var(--gxt-title);
    letter-spacing: -0.01em;
}
.gx-toast__msg {
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--gxt-text);
    margin-top: 2px;
    overflow-wrap: anywhere;
}
.gx-toast__title + .gx-toast__msg { margin-top: 3px; }
.gx-toast__msg:first-child { margin-top: 0; }
.gx-toast__msg ul { margin: 4px 0 0; padding-left: 16px; }
.gx-toast__msg a { color: var(--gxt-accent); font-weight: 500; }

/* ── Action button ────────────────────────────────────────────────────── */
.gx-toast__action {
    grid-area: action;
    justify-self: start;
    appearance: none;
    border: 1px solid var(--gxt-border);
    background: var(--gxt-surface-raised);
    color: var(--gxt-title);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 5px 11px;
    border-radius: 10px;
    cursor: pointer;
    transition: background-color var(--gx-motion-fast, 120ms) var(--gxt-ease-out),
                border-color var(--gx-motion-fast, 120ms) var(--gxt-ease-out),
                color var(--gx-motion-fast, 120ms) var(--gxt-ease-out);
}
.gx-toast__action:hover {
    background: var(--gxt-accent-bg);
    border-color: var(--gxt-accent);
    color: var(--gxt-accent);
}
.gx-toast__action:focus-visible {
    outline: none;
    box-shadow: var(--gxt-focus-ring);
}

/* ── Close ────────────────────────────────────────────────────────────── */
.gx-toast__close {
    grid-area: close;
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--gxt-text);
    width: 22px;
    height: 22px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--gx-motion-fast, 120ms) linear,
                background-color var(--gx-motion-fast, 120ms) linear,
                color var(--gx-motion-fast, 120ms) linear;
}
.gx-toast:hover .gx-toast__close,
.gx-toast:focus-within .gx-toast__close { opacity: 1; }
.gx-toast__close:hover { background: var(--gxt-accent-bg); color: var(--gxt-accent); }
.gx-toast__close:focus-visible { opacity: 1; outline: none; box-shadow: var(--gxt-focus-ring); }
.gx-toast__close svg { width: 13px; height: 13px; display: block; }

/* ── Progress bar ─────────────────────────────────────────────────────── */
.gx-toast__progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 3px;
    width: 100%;
    transform-origin: left center;
    transform: scaleX(var(--gxt-progress, 1));
    background: var(--gxt-accent);
    opacity: 0.5;
}
.gx-toast__progress.is-running {
    transition: transform linear var(--gxt-progress-dur, 4000ms);
}
.gx-toast.is-paused .gx-toast__progress { transition: none; }

/* ── Per-type accent ──────────────────────────────────────────────────── */
.gx-toast--success { --gxt-accent: var(--gxt-success); --gxt-accent-bg: var(--gxt-success-bg); }
.gx-toast--error   { --gxt-accent: var(--gxt-error);   --gxt-accent-bg: var(--gxt-error-bg); }
.gx-toast--warning { --gxt-accent: var(--gxt-warning); --gxt-accent-bg: var(--gxt-warning-bg); }
.gx-toast--info    { --gxt-accent: var(--gxt-info);    --gxt-accent-bg: var(--gxt-info-bg); }
.gx-toast--loading { --gxt-accent: var(--gxt-loading); --gxt-accent-bg: var(--gxt-loading-bg); }

@keyframes gxt-spin { to { transform: rotate(360deg); } }

/* ────────────────────────────────────────────────────────────────────────
   Reduced motion — no slide, no stack choreography, instant show/hide.
   ──────────────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .gx-toast-viewport { transition: none; }
    .gx-toast,
    .gx-toast.is-entering,
    .gx-toast.is-leaving {
        transition: opacity 120ms linear;
        transform: translateY(var(--gxt-stack-y));
    }
    .gx-toast { --gxt-enter: 0; }
    .gx-toast.is-leaving { opacity: 0; }
    .gx-toast--loading .gx-toast__icon svg { animation: none; }
    .gx-toast__progress.is-running { transition: none; }
    .gx-toast--success .gx-toast__icon::after { animation: none; opacity: 0; }
    .gx-toast__emoji { animation: none; }
}

@media print {
    .gx-toast-viewport { display: none !important; }
}

/* ════════════════════════════════════════════════════════════════════════
   SweetAlert2 premium skin — Notify.confirm / Notify.dialog.
   notify.js passes these class names via customClass.
   ════════════════════════════════════════════════════════════════════════ */
.gx-swal-popup.swal2-popup {
    border-radius: 14px;
    padding: 26px 26px 22px;
    border: 1px solid var(--gxt-border);
    background: var(--gxt-surface);
    color: var(--gxt-title);
    box-shadow:
        0 4px 14px rgba(15, 23, 42, 0.10),
        0 24px 60px -14px rgba(15, 23, 42, 0.24),
        var(--gxt-ring-inset);
}

.gx-swal-popup .swal2-icon { margin: 6px auto 14px; border-width: 3px; }
.gx-swal-popup .swal2-title {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--gxt-title);
    padding: 0;
}
.gx-swal-popup .swal2-html-container {
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--gxt-text);
    margin-top: 8px;
}

.gx-swal-actions.swal2-actions {
    margin-top: 22px;
    gap: 10px;
    width: 100%;
}

.gx-swal-popup .swal2-styled {
    margin: 0;
    padding: 9px 18px;
    border-radius: 12px;
    font-size: 0.92rem;
    font-weight: 620;
    letter-spacing: 0.01em;
    box-shadow: none;
    transition: filter 120ms linear, background-color 120ms linear, color 120ms linear;
}
.gx-swal-popup .swal2-styled:focus { box-shadow: var(--gxt-focus-ring); }

.gx-swal-confirm.swal2-styled {
    background: var(--tblr-primary, #06402b);
    color: #fff;
}
.gx-swal-confirm.swal2-styled:hover { filter: brightness(1.08); }

.gx-swal-cancel.swal2-styled {
    background: transparent;
    border: 1px solid var(--gxt-border);
    color: var(--gxt-title);
}
.gx-swal-cancel.swal2-styled:hover {
    background: var(--gxt-error-bg);
    border-color: var(--gxt-error);
    color: var(--gxt-error);
}

/* Destructive confirms: notify.js adds .gx-swal--danger to the popup. */
.gx-swal-popup.gx-swal--danger .gx-swal-confirm.swal2-styled { background: var(--gxt-error); }

.gx-swal-popup .swal2-close { color: var(--gxt-text); }
.gx-swal-popup .swal2-close:hover { color: var(--gxt-error); }

@media (prefers-reduced-motion: reduce) {
    .swal2-popup.swal2-show,
    .swal2-popup.swal2-hide { animation: none !important; }
}
