/**
 * Lazy Loading CSS - HerbChecker
 *
 * Comprehensive styles for:
 * - Blur-up placeholder effect
 * - Loading skeletons
 * - Smooth transitions
 * - Error states
 */

/* ========================================
   Base Lazy Loading Styles
   ======================================== */

.lazy-image {
    position: relative;
    overflow: hidden;
    background-color: #f3f4f6;
    background-size: cover;
    background-position: center;
}

/* Placeholder state - shows blurred low-quality image */
.lazy-image[data-lazy-src] {
    filter: blur(10px);
    transform: scale(1.05);
    transition: filter 0.3s ease-out, transform 0.3s ease-out;
}

/* Loading state - during image download */
.lazy-loading {
    position: relative;
}

.lazy-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.4) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

/* Loaded state - sharp, clear image */
.lazy-loaded {
    filter: blur(0);
    transform: scale(1);
    animation: fadeIn 0.3s ease-out;
}

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

/* Error state - when image fails to load */
.lazy-error {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    position: relative;
}

.lazy-error::before {
    content: '';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: #dc2626;
    opacity: 0.3;
}

/* ========================================
   Loading Skeletons
   ======================================== */

.skeleton {
    background: linear-gradient(
        90deg,
        #f3f4f6 0%,
        #e5e7eb 50%,
        #f3f4f6 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton variants */
.skeleton-image {
    width: 100%;
    height: 12rem; /* 192px */
    background: linear-gradient(
        90deg,
        #d1fae5 0%,
        #a7f3d0 50%,
        #d1fae5 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(
        90deg,
        #f3f4f6 0%,
        #e5e7eb 50%,
        #f3f4f6 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

.skeleton-text-sm {
    height: 0.75rem;
    width: 60%;
}

.skeleton-text-lg {
    height: 1.25rem;
    width: 80%;
}

.skeleton-badge {
    height: 1.5rem;
    width: 4rem;
    display: inline-block;
    margin-right: 0.25rem;
    border-radius: 9999px;
}

/* ========================================
   Herb Card Skeleton
   ======================================== */

.herb-card-skeleton {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.herb-card-skeleton .skeleton-image {
    height: 12rem;
    background: linear-gradient(
        135deg,
        #d1fae5 0%,
        #a7f3d0 50%,
        #d1fae5 100%
    );
    background-size: 200% 200%;
    animation: gradient-shift 3s ease infinite;
}

@keyframes gradient-shift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.herb-card-skeleton .skeleton-content {
    padding: 1rem;
}

/* ========================================
   Progressive Enhancement
   ======================================== */

/* Support for reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .lazy-image[data-lazy-src],
    .lazy-loaded {
        transition: none;
    }

    .lazy-loading::after,
    .skeleton,
    .skeleton-image,
    .skeleton-text,
    .herb-card-skeleton {
        animation: none;
    }

    .lazy-loaded {
        animation: none;
    }
}

/* ========================================
   Blur-up Specific Styles
   ======================================== */

.blur-up {
    position: relative;
    overflow: hidden;
}

.blur-up-container {
    position: relative;
    width: 100%;
    height: 100%;
}

.blur-up-placeholder {
    position: absolute;
    inset: 0;
    filter: blur(20px);
    transform: scale(1.1);
    transition: opacity 0.3s ease-out;
}

.blur-up-placeholder.loaded {
    opacity: 0;
}

.blur-up-image {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

.blur-up-image.loaded {
    opacity: 1;
}

/* ========================================
   Loading Progress Indicator
   ======================================== */

.loading-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(
        90deg,
        #10b981 0%,
        #059669 100%
    );
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease-out;
    z-index: 9999;
}

.loading-progress.active {
    transform: scaleX(var(--progress, 0));
}

/* ========================================
   Lazy Load Utilities
   ======================================== */

/* Hide images until they're ready */
[data-lazy-src]:not(.lazy-loaded):not(.lazy-loading) {
    visibility: hidden;
}

/* Ensure aspect ratio is maintained */
.aspect-ratio-box {
    position: relative;
    overflow: hidden;
}

.aspect-ratio-box::before {
    content: '';
    display: block;
    padding-bottom: var(--aspect-ratio, 75%); /* Default 4:3 */
}

.aspect-ratio-box > * {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 640px) {
    .skeleton-image {
        height: 10rem; /* Smaller on mobile */
    }

    .lazy-loading::after {
        animation-duration: 1s; /* Faster on mobile */
    }
}

/* ========================================
   Dark Mode Support (Future)
   ======================================== */

@media (prefers-color-scheme: dark) {
    .lazy-image {
        background-color: #1f2937;
    }

    .skeleton,
    .skeleton-text {
        background: linear-gradient(
            90deg,
            #374151 0%,
            #4b5563 50%,
            #374151 100%
        );
        background-size: 200% 100%;
    }

    .skeleton-image {
        background: linear-gradient(
            90deg,
            #064e3b 0%,
            #065f46 50%,
            #064e3b 100%
        );
        background-size: 200% 100%;
    }
}

/* ========================================
   Print Styles
   ======================================== */

@media print {
    .lazy-loading::after,
    .skeleton,
    .loading-progress {
        display: none;
    }

    .lazy-image[data-lazy-src] {
        filter: none;
        transform: none;
    }
}
