/* ═══════════════════════════════════════════════════════
   SLICE PIZZA — Premium Animations & Transitions
   Blush Cream Editorial. 60fps. GPU-accelerated.
   ═══════════════════════════════════════════════════════ */

/* ── 1. PAGE / TAB VIEW TRANSITIONS ── */
.tab-view {
    will-change: opacity, transform;
}

.tab-view-enter {
    animation: tabViewIn 0.4s var(--ease-out) both;
}

.tab-view-exit {
    animation: tabViewOut 0.25s var(--ease) both;
}

@keyframes tabViewIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes tabViewOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ── 2. CARD HOVER / TAP — premium lift + press-down ── */
.product-card {
    will-change: transform, box-shadow;
}

@media (hover: hover) {
    .product-card:hover {
        transform: translateY(-4px) scale(1.015);
        box-shadow:
            0 12px 32px rgba(10, 6, 8, 0.18),
            0 4px 12px rgba(10, 6, 8, 0.10);
        border-color: var(--rose-border);
    }

    .product-card:hover .product-card-img img {
        transform: scale(1.05);
    }
}

.product-card:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-xs);
    transition-duration: 80ms;
}

/* ── 3. MODAL — spring slide-up + overlay blur fade ── */
.modal-overlay {
    will-change: opacity;
    animation: overlayFadeIn 0.3s var(--ease) both;
}

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

.modal-sheet {
    will-change: transform;
    animation: sheetSpringUp 0.45s var(--ease-spring) both;
}

@keyframes sheetSpringUp {
    0% {
        transform: translateY(100%);
        opacity: 0.8;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-sheet--detail {
    animation: detailSpringUp 0.5s cubic-bezier(0.2, 0.85, 0.32, 1.1) both;
}

@keyframes detailSpringUp {
    0% {
        transform: translateY(100%) scale(0.88);
        opacity: 0.5;
    }
    70% {
        transform: translateY(-2%) scale(1.01);
        opacity: 1;
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Closing — slightly faster, no spring */
.modal-sheet.modal-closing {
    animation: sheetSlideDown 0.3s var(--ease) forwards;
}

@keyframes sheetSlideDown {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(100%);
        opacity: 0.6;
    }
}

.modal-sheet--detail.modal-closing {
    animation: detailSlideDown 0.3s var(--ease) forwards;
}

@keyframes detailSlideDown {
    from {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    to {
        transform: translateY(100%) scale(0.95);
        opacity: 0;
    }
}

.overlay-closing {
    animation: overlayFadeOut 0.25s var(--ease) forwards;
}

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

/* ── 4. CART BADGE — bounce on update ── */
@keyframes badgeBounce {
    0% {
        transform: scale(1);
    }
    20% {
        transform: scale(1.35);
    }
    40% {
        transform: scale(0.85);
    }
    60% {
        transform: scale(1.15);
    }
    80% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

.tab-badge.badge-bounce,
.cart-badge.badge-bounce {
    animation: badgeBounce 0.5s var(--ease-spring);
}

/* ── 5. SCROLL ANIMATIONS — fade-in-up staggered ── */
.scroll-reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
    will-change: opacity, transform;
}

.scroll-reveal.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger delays via CSS custom property */
.scroll-reveal[style*="--stagger-delay"] {
    transition-delay: var(--stagger-delay, 0ms);
}

/* ── 6. BUTTON MICRO-INTERACTIONS — scale + ripple ── */
.btn-primary,
.btn-glossy,
.btn-ghost,
.btn-rose,
.pd-add,
.add-btn,
#ai-send {
    position: relative;
    overflow: hidden;
    transition:
        transform var(--dur-fast) var(--ease-spring),
        opacity var(--dur-fast) var(--ease),
        box-shadow var(--dur-normal) var(--ease);
}

.btn-primary:active,
.btn-glossy:active,
.btn-rose:active,
.pd-add:active,
#ai-send:active {
    transform: scale(0.96);
    transition-duration: 80ms;
}

/* Ripple effect element — injected by JS */
.btn-ripple {
    position: absolute;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0);
    animation: rippleExpand 0.5s var(--ease-out) forwards;
    pointer-events: none;
}

@keyframes rippleExpand {
    0% {
        transform: scale(0);
        opacity: 0.6;
    }
    100% {
        transform: scale(4);
        opacity: 0;
    }
}

/* ── 7. TAB BAR — sliding active indicator ── */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
}

.tab-indicator {
    position: absolute;
    top: 0;
    height: 2px;
    background: var(--ink);
    border-radius: 0 0 2px 2px;
    transition: left 0.35s var(--ease-out), width 0.35s var(--ease-out);
    will-change: left, width;
    z-index: 2;
}

[data-theme="dark"] .tab-indicator {
    background: var(--rose);
}

/* Remove the pseudo-element indicator since we use a real element now */
.tab-item.active::before {
    display: none !important;
}

/* ── 8. IMAGE REVEAL — elegant fade-in on load ── */
.img-reveal {
    opacity: 0;
    transform: scale(1.02);
    transition:
        opacity 0.5s var(--ease-out),
        transform 0.6s var(--ease-out);
    will-change: opacity, transform;
}

.img-reveal.img-loaded {
    opacity: 1;
    transform: scale(1);
}

/* Safety: ensure images become visible after 3s even if JS fails */
@keyframes imgSafety {
    to { opacity: 1; transform: scale(1); }
}
.img-reveal {
    animation: imgSafety 0s 3s forwards;
}

/* ── 9. PULL-TO-REFRESH — rubber-band ── */
.ptr-indicator {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    transition: transform 0.3s var(--ease-spring);
    will-change: transform;
}

.ptr-indicator.ptr-pulling {
    transition: none;
}

.ptr-indicator.ptr-refreshing {
    transform: translateX(-50%) translateY(16px);
}

.ptr-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--rose);
    border-radius: 50%;
    animation: ptrSpin 0.7s linear infinite;
}

@keyframes ptrSpin {
    to { transform: rotate(360deg); }
}

/* ── 10. TOAST — spring slide-in + fade dismiss ── */
.toast {
    animation: toastSpringIn 0.45s var(--ease-spring) both;
    will-change: transform, opacity;
}

.toast.toast-out {
    animation: toastFadeOut 0.3s var(--ease) forwards;
}

@keyframes toastSpringIn {
    0% {
        transform: translateY(32px) scale(0.95);
        opacity: 0;
    }
    60% {
        opacity: 1;
    }
    80% {
        transform: translateY(-3px) scale(1.01);
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes toastFadeOut {
    0% {
        transform: translateY(0);
        opacity: 1;
    }
    100% {
        transform: translateY(-16px);
        opacity: 0;
    }
}

/* ═══════════════════════════════════════════════════════
   REDUCED MOTION — respect user preference
   ═══════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .tab-view-enter,
    .tab-view-exit {
        animation: none;
    }

    .scroll-reveal {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .modal-sheet,
    .modal-sheet--detail {
        animation-duration: 0.01ms;
    }

    .modal-overlay {
        animation-duration: 0.01ms;
    }

    .tab-badge.badge-bounce,
    .cart-badge.badge-bounce {
        animation: none;
    }

    .btn-ripple {
        animation: none;
        display: none;
    }

    .tab-indicator {
        transition: none;
    }

    .img-reveal {
        opacity: 1;
        transform: none;
        transition: none;
        animation: none;
    }

    .toast {
        animation-duration: 0.01ms;
    }

    .ptr-indicator {
        transition: none;
    }
}
