/* ============================================================================
   shared-fx.css — canonical shared effects.

   Phase 3 CSS foundation. Two things live here:
     (a) the ONE canonical coupon-notification toast, used on the homepage,
         listing pages and the cart (DOM: templates/_coupon_notification.html).
     (b) hoisted @keyframes that were previously duplicated across index.css /
         cart.css / listing.css / credential-modal.css / price-editor.css.

   CSS @keyframes are global, so a single definition here serves every page.
   payment-modal.css keeps its own intentionally-divergent local variants
   (translateZ-hardened spin, -4px errorShake, 3-stop successPulse, etc.) —
   those are NOT hoisted here.

   This sheet loads async (media="print" swap). Every animation defined here is
   interaction- or below-fold-triggered (toasts, spinners, hover glows), never
   a first-paint animation, so async loading is safe.
   ============================================================================ */

/* ==================== HOISTED KEYFRAMES ==================== */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes rippleText {
    0% { background-position: 0% center; }
    100% { background-position: -200% center; }
}

@keyframes shimmerEffect {
    0% { background-position: 200% center; }
    100% { background-position: -200% center; }
}

@keyframes borderPulse {
    0%, 100% {
        border-color: rgba(var(--pulse-color), 0.3);
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4),
                    0 0 20px rgba(var(--pulse-color), 0.1),
                    0 0 30px rgba(var(--pulse-color), 0.05);
    }
    50% {
        border-color: rgba(var(--pulse-color), 1);
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4),
                    0 0 30px rgba(var(--pulse-color), 0.5),
                    0 0 50px rgba(var(--pulse-color), 0.3),
                    0 0 70px rgba(var(--pulse-color), 0.15);
    }
}

@keyframes successPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
    20%, 40%, 60%, 80% { transform: translateX(2px); }
}

@keyframes slideInScale {
    0% { opacity: 0; transform: scale(0.8) translateY(50px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes slideOutScale {
    0% { opacity: 1; transform: scale(1) translateY(0); }
    100% { opacity: 0; transform: scale(0.8) translateY(50px); }
}

/* 3-shadow variant (from cart.css / index.css). listing.css had a 2-shadow
   copy — this canonical 3-shadow definition supersedes it. */
@keyframes reverberateGlow {
    0%, 100% {
        text-shadow: 0 0 8px rgba(23, 127, 255, 0.35),
                     0 0 16px rgba(23, 127, 255, 0.25),
                     0 0 28px rgba(23, 127, 255, 0.15);
    }
    50% {
        text-shadow: 0 0 12px rgba(23, 127, 255, 0.65),
                     0 0 24px rgba(23, 127, 255, 0.45),
                     0 0 40px rgba(23, 127, 255, 0.35);
    }
}

/* lightningGlow was USED by listing.css (instant-delivery toast) but never
   DEFINED there — a live bug. Defining it here fixes it for every page. */
@keyframes lightningGlow {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(255, 216, 20, 0.8)); }
    50% { filter: drop-shadow(0 0 12px rgba(255, 216, 20, 1)); }
}

/* ==================== CANONICAL COUPON TOAST ==================== */
/* Show/hide via transform: translateY (GPU-composited — NOT cart's `top`
   animation). Enhanced with cart's glassmorphism + borderPulse. */
.coupon-notification {
    position: fixed !important;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-200px);
    width: fit-content;
    min-width: 300px;
    max-width: min(700px, 80vw);
    background: linear-gradient(135deg, rgba(26, 26, 31, 0.98) 0%, rgba(35, 35, 42, 0.98) 100%);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-xl);
    padding: 20px 32px;
    z-index: 9998;
    transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    pointer-events: auto;
    margin: 0 auto !important;
    display: none;
    box-sizing: border-box;
    overflow: visible;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.2);
    opacity: 1;
    backface-visibility: hidden;
    -webkit-font-smoothing: antialiased;
}

.coupon-notification.show {
    display: block !important;
    transform: translateX(-50%) translateY(100px);
    visibility: visible !important;
    pointer-events: auto !important;
    overflow: visible;
}

.coupon-notification.success {
    --pulse-color: 40, 167, 69;
    border-color: rgba(40, 167, 69, 0.8);
}

.coupon-notification.success.show {
    animation: borderPulse 2s ease-in-out infinite 0.4s;
}

.coupon-notification.error {
    --pulse-color: 220, 53, 69;
    border-color: rgba(220, 53, 69, 0.8);
}

.coupon-notification.error.show {
    animation: borderPulse 2s ease-in-out infinite 0.4s;
}

/* Hiding animation — slide back up */
.coupon-notification.hiding {
    transform: translateX(-50%) translateY(-200px);
    pointer-events: none;
}

.notification-content {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    z-index: 1;
}

.notification-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notification-message {
    font-size: clamp(12px, 2.5vw, 16px);
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.03em;
    color: #fff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    position: relative;
    display: inline-block;
    text-transform: uppercase;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    white-space: normal;
}

.notification-message.long-message {
    font-size: 14px;
}

.notification-message.extra-long-message {
    font-size: 12px;
}

.coupon-notification.success .notification-message { color: var(--color-success); }
.coupon-notification.error .notification-message { color: var(--color-danger); }

.coupon-notification .notification-message::before,
.coupon-notification .notification-message::after {
    display: inline-block;
    font-size: 20px;
    vertical-align: middle;
}

/* Correctly-separated ::before / ::after margins (fixes the index.css bug
   where ::after carried both margin-right AND margin-left). */
.coupon-notification.success .notification-message::before { content: '✓'; margin-right: 8px; }
.coupon-notification.success .notification-message::after { content: '✓'; margin-left: 8px; }
.coupon-notification.error .notification-message::before { content: '✗'; margin-right: 8px; }
.coupon-notification.error .notification-message::after { content: '✗'; margin-left: 8px; }

/* ==================== MOBILE COUPON TOAST ==================== */
@media (max-width: 767.98px) {
    .coupon-notification {
        width: calc(100% - 16px);
        max-width: calc(100% - 16px);
        min-width: 280px;
        border-radius: 14px;
        padding: 16px 20px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    .coupon-notification.show {
        transform: translateX(-50%) translateY(90px) !important;
    }

    .coupon-notification.hiding {
        transform: translateX(-50%) translateY(-200px) !important;
    }

    .notification-message {
        font-size: 14px !important;
        font-weight: 600;
    }
}

/* iPhone X+ with notch / Dynamic Island */
@supports (padding-top: env(safe-area-inset-top)) {
    @media (max-width: 767.98px) {
        .coupon-notification.show {
            transform: translateX(-50%)
                      translateY(calc(90px + env(safe-area-inset-top, 0px))) !important;
        }
    }
}

/* Very small phones (iPhone SE, older Android) */
@media (max-width: 380px) {
    .coupon-notification {
        padding: 14px 16px;
        min-width: 260px;
    }

    .notification-message {
        font-size: 13px !important;
    }
}

/* ==================== REDUCED MOTION ==================== */
@media (prefers-reduced-motion: reduce) {
    .coupon-notification, .coupon-notification * { animation: none !important; transition: none !important; }
}
