/**
 * Ledech Kiosk - Animation Styles
 * Reusable animations and transitions
 */

/* ========== Entrance Animations ========== */
@keyframes fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fade-in-down {
    from {
        opacity: 0;
        transform: translateY(-30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fade-in-left {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes fade-in-right {
    from {
        opacity: 0;
        transform: translateX(30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes scale-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes scale-in-bounce {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.95);
    }
    100% {
        transform: scale(1);
    }
}

@keyframes slide-in-bottom {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes slide-in-top {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

/* ========== Exit Animations ========== */
@keyframes fade-out {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

@keyframes fade-out-up {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-30px);
    }
}

@keyframes fade-out-down {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(30px);
    }
}

@keyframes scale-out {
    from {
        opacity: 1;
        transform: scale(1);
    }
    to {
        opacity: 0;
        transform: scale(0.9);
    }
}

@keyframes slide-out-bottom {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(100%);
    }
}

/* ========== Attention Animations ========== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-3deg); }
    75% { transform: rotate(3deg); }
}

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.1); }
    50% { transform: scale(1); }
    75% { transform: scale(1.1); }
}

@keyframes flash {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0.5; }
}

/* ========== Loading Animations ========== */
@keyframes skeleton-loading {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: calc(200px + 100%) 0;
    }
}

@keyframes progress-indeterminate {
    0% {
        left: -35%;
        right: 100%;
    }
    60% {
        left: 100%;
        right: -90%;
    }
    100% {
        left: 100%;
        right: -90%;
    }
}

@keyframes dots {
    0%, 20% {
        color: rgba(0, 0, 0, 0);
        text-shadow:
            0.25em 0 0 rgba(0, 0, 0, 0),
            0.5em 0 0 rgba(0, 0, 0, 0);
    }
    40% {
        color: currentColor;
        text-shadow:
            0.25em 0 0 rgba(0, 0, 0, 0),
            0.5em 0 0 rgba(0, 0, 0, 0);
    }
    60% {
        text-shadow:
            0.25em 0 0 currentColor,
            0.5em 0 0 rgba(0, 0, 0, 0);
    }
    80%, 100% {
        text-shadow:
            0.25em 0 0 currentColor,
            0.5em 0 0 currentColor;
    }
}

/* ========== Continuous Animations ========== */
@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes float-gentle {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes glow {
    0%, 100% {
        box-shadow: 0 0 20px var(--primary-glow);
    }
    50% {
        box-shadow: 0 0 40px var(--primary-glow), 0 0 60px var(--primary-glow);
    }
}

/* ========== Animation Utility Classes ========== */
.animate-fade-in {
    animation: fade-in 0.3s ease forwards;
}

.animate-fade-in-up {
    animation: fade-in-up 0.4s ease forwards;
}

.animate-fade-in-down {
    animation: fade-in-down 0.4s ease forwards;
}

.animate-scale-in {
    animation: scale-in 0.3s ease forwards;
}

.animate-scale-in-bounce {
    animation: scale-in-bounce 0.5s ease forwards;
}

.animate-slide-in-bottom {
    animation: slide-in-bottom 0.4s ease forwards;
}

.animate-shake {
    animation: shake 0.6s ease;
}

.animate-bounce {
    animation: bounce 1s ease;
}

.animate-wiggle {
    animation: wiggle 0.5s ease;
}

/* ========== Delay Utilities ========== */
.delay-100 { animation-delay: 100ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-400 { animation-delay: 400ms; }
.delay-500 { animation-delay: 500ms; }

/* ========== Duration Utilities ========== */
.duration-fast { animation-duration: 150ms; }
.duration-normal { animation-duration: 300ms; }
.duration-slow { animation-duration: 500ms; }

/* ========== Screen Transitions ========== */
.screen-enter {
    animation: fade-in-up 0.4s ease forwards;
}

.screen-exit {
    animation: fade-out-up 0.3s ease forwards;
}

.screen-enter-from-right {
    animation: fade-in-left 0.4s ease forwards;
}

.screen-enter-from-left {
    animation: fade-in-right 0.4s ease forwards;
}

/* ========== Card Animations ========== */
.card-enter {
    animation: scale-in 0.3s ease forwards;
}

.card-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

/* ========== Button Press Effect ========== */
.btn-press {
    transition: transform 0.1s ease;
}

.btn-press:active {
    transform: scale(0.95);
}

/* ========== Skeleton Loading ========== */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.1) 0%,
        rgba(255, 255, 255, 0.2) 50%,
        rgba(255, 255, 255, 0.1) 100%
    );
    background-size: 200px 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-md);
}

.skeleton-dark {
    background: linear-gradient(
        90deg,
        rgba(0, 0, 0, 0.05) 0%,
        rgba(0, 0, 0, 0.1) 50%,
        rgba(0, 0, 0, 0.05) 100%
    );
    background-size: 200px 100%;
}

/* ========== Success Animation ========== */
.success-checkmark {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--success-color);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: scale-in-bounce 0.5s ease forwards;
}

.success-checkmark .material-icons-round {
    font-size: 48px;
    color: white;
    animation: fade-in 0.3s ease 0.2s forwards;
    opacity: 0;
}

/* ========== Number Counter Animation ========== */
.counter-animate {
    display: inline-block;
    animation: counter-pop 0.4s ease;
}

@keyframes counter-pop {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* ========== Toast Notification ========== */
.toast-enter {
    animation: slide-in-bottom 0.3s ease forwards;
}

.toast-exit {
    animation: slide-out-bottom 0.3s ease forwards;
}

/* ========== Cart Badge Animation ========== */
.cart-badge-pop {
    animation: scale-in-bounce 0.3s ease;
}

/* ========== Page Transition Wrapper ========== */
.page-transition {
    position: relative;
    overflow: hidden;
}

.page-transition::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary-color);
    transform: translateX(-100%);
    pointer-events: none;
}

.page-transition.transitioning::after {
    animation: page-swipe 0.6s ease;
}

@keyframes page-swipe {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(0);
    }
    100% {
        transform: translateX(100%);
    }
}

/* ========== Stagger Animation Helper ========== */
.stagger-item {
    opacity: 0;
    animation: fade-in-up 0.4s ease forwards;
}

.stagger-item:nth-child(1) { animation-delay: 0ms; }
.stagger-item:nth-child(2) { animation-delay: 50ms; }
.stagger-item:nth-child(3) { animation-delay: 100ms; }
.stagger-item:nth-child(4) { animation-delay: 150ms; }
.stagger-item:nth-child(5) { animation-delay: 200ms; }
.stagger-item:nth-child(6) { animation-delay: 250ms; }
.stagger-item:nth-child(7) { animation-delay: 300ms; }
.stagger-item:nth-child(8) { animation-delay: 350ms; }
.stagger-item:nth-child(9) { animation-delay: 400ms; }
.stagger-item:nth-child(10) { animation-delay: 450ms; }

/* ========== Sidebar Slide-In Animation (Visibility Triggered) ========== */
@keyframes slide-in-left {
    from {
        opacity: 0;
        transform: translateX(-30px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/*
 * Sidebar animation states:
 * - .sidebar-hidden: Initial state, elements invisible and ready
 * - .sidebar-animate: Trigger state, plays the animation
 *
 * IMPORTANT: We use animation-fill-mode: both to ensure elements stay at
 * their 'from' keyframe state before animation starts (prevents flash/jitter)
 */

/* Default state for sidebar items - hidden until animated */
.sidebar-anim-item {
    opacity: 0;
    transform: translateX(-30px);
}

/* When parent has sidebar-hidden, ensure items stay hidden */
.sidebar-hidden .sidebar-anim-item {
    opacity: 0;
    transform: translateX(-30px);
    animation: none; /* Cancel any running animation */
}

/* When parent has sidebar-animate, play the animation */
.sidebar-animate .sidebar-anim-item {
    animation: slide-in-left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

/* Grid card animation states */
.grid-anim-item {
    opacity: 0;
    transform: translateY(30px);
}

.grid-hidden .grid-anim-item {
    opacity: 0;
    transform: translateY(30px);
    animation: none;
}

.grid-animate .grid-anim-item {
    animation: slide-up 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

/* Legacy class support - these will be replaced by visibility-triggered versions */
.animate-slide-in-left {
    animation: slide-in-left 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.animate-slide-up {
    animation: slide-up 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
