/* ==========================================================================
   Skeleton Loading System
   ========================================================================== */

/* Base Skeleton Classes
   ========================================================================== */

.skeleton {
    animation: skeleton-loading 1.5s ease-in-out infinite;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    display: inline-block;
    position: relative;
    overflow: hidden;
}

/* Dark theme skeleton */
.dark-theme .skeleton,
[data-bs-theme="dark"] .skeleton {
    background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    background-size: 200% 100%;
}

/* Animation */
@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Skeleton Shapes
   ========================================================================== */

/* Text skeletons */
.skeleton-text {
    height: 1em;
    margin-bottom: 0.5rem;
    border-radius: 4px;
}

.skeleton-text-sm {
    height: 0.875em;
}

.skeleton-text-lg {
    height: 1.25em;
}

.skeleton-text-xl {
    height: 1.5em;
}

/* Heading skeletons */
.skeleton-heading {
    height: 1.5em;
    margin-bottom: 1rem;
}

.skeleton-heading-lg {
    height: 2em;
}

.skeleton-heading-xl {
    height: 2.5em;
}

/* Button skeletons */
.skeleton-button {
    height: 2.5rem;
    width: 120px;
    border-radius: 0.375rem;
}

.skeleton-button-lg {
    height: 3rem;
    width: 150px;
}

.skeleton-button-sm {
    height: 2rem;
    width: 80px;
}

/* Image skeletons */
.skeleton-image {
    width: 100%;
    padding-bottom: 75%; /* 4:3 aspect ratio */
    position: relative;
    border-radius: 0.5rem;
}

.skeleton-image-square {
    padding-bottom: 100%; /* 1:1 aspect ratio */
}

.skeleton-image-wide {
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

/* Icon skeletons */
.skeleton-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.skeleton-icon-sm {
    width: 32px;
    height: 32px;
}

.skeleton-icon-lg {
    width: 64px;
    height: 64px;
}

.skeleton-icon-xl {
    width: 80px;
    height: 80px;
}

/* Card skeletons */
.skeleton-card {
    border: 1px solid #e9ecef;
    border-radius: 0.5rem;
    padding: 1.5rem;
    background: #fff;
}

.dark-theme .skeleton-card,
[data-bs-theme="dark"] .skeleton-card {
    background: #1a1a1a;
    border-color: #3a3a3a;
}

/* Component-Specific Skeletons
   ========================================================================== */

/* Navigation skeleton */
.skeleton-nav {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 1rem 0;
}

.skeleton-nav-logo {
    width: 140px;
    height: 40px;
    border-radius: 4px;
}

.skeleton-nav-item {
    width: 80px;
    height: 1.2em;
    border-radius: 4px;
}

/* Hero skeleton */
.skeleton-hero {
    padding: 4rem 0;
}

.skeleton-hero-title {
    width: 80%;
    max-width: 600px;
    margin: 0 auto 1.5rem;
}

.skeleton-hero-subtitle {
    width: 60%;
    max-width: 500px;
    margin: 0 auto 2rem;
}

.skeleton-hero-buttons {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Service card skeleton */
.skeleton-service-card {
    text-align: center;
}

.skeleton-service-icon {
    margin: 0 auto 1.5rem;
}

.skeleton-service-title {
    width: 80%;
    margin: 0 auto 1rem;
}

.skeleton-service-description {
    width: 100%;
}

/* Stats/Counter skeleton */
.skeleton-stat {
    text-align: center;
}

.skeleton-stat-value {
    width: 60%;
    height: 2.5rem;
    margin: 0 auto 0.5rem;
}

.skeleton-stat-label {
    width: 80%;
    margin: 0 auto;
}

/* Table skeleton */
.skeleton-table {
    width: 100%;
}

.skeleton-table-header {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 2px solid #e9ecef;
}

.skeleton-table-row {
    display: flex;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid #e9ecef;
}

.skeleton-table-cell {
    flex: 1;
    height: 1.2em;
}


/* Utility Classes
   ========================================================================== */

/* Width variants */
.skeleton-w-25 { width: 25%; }
.skeleton-w-50 { width: 50%; }
.skeleton-w-75 { width: 75%; }
.skeleton-w-100 { width: 100%; }

/* Margin utilities */
.skeleton-mb-1 { margin-bottom: 0.25rem; }
.skeleton-mb-2 { margin-bottom: 0.5rem; }
.skeleton-mb-3 { margin-bottom: 1rem; }
.skeleton-mb-4 { margin-bottom: 1.5rem; }
.skeleton-mb-5 { margin-bottom: 3rem; }

/* Skeleton Container */
.skeleton-container {
    position: relative;
    min-height: 100px;
}

/* Pulse variant */
.skeleton-pulse {
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes skeleton-pulse {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
    100% {
        opacity: 1;
    }
}

/* Wave variant (Bootstrap-style) */
.skeleton-wave {
    position: relative;
    overflow: hidden;
}

.skeleton-wave::after {
    animation: skeleton-wave 1.5s linear infinite;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
    content: "";
    position: absolute;
    transform: translateX(-100%);
    inset: 0;
}

@keyframes skeleton-wave {
    100% {
        transform: translateX(100%);
    }
}

/* Loading State Management
   ========================================================================== */

/* Only hide content for specific skeleton types that need it */
[data-skeleton-loading][data-skeleton="stat-card"] > *:not(.skeleton-container),
[data-skeleton-loading][data-skeleton="card"] > *:not(.skeleton-container),
[data-skeleton-loading][data-skeleton="table"] > *:not(.skeleton-container) {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

/* Show skeleton container when loading */
[data-skeleton-loading] .skeleton-container {
    display: block;
}

/* Hide skeleton when loaded */
[data-skeleton-loaded] .skeleton-container {
    display: none;
}

/* Show content when loaded */
[data-skeleton-loaded] > * {
    opacity: 1;
}

/* Fade transition */
.skeleton-fade-out {
    animation: skeleton-fade-out 0.3s ease-out forwards;
}

@keyframes skeleton-fade-out {
    to {
        opacity: 0;
    }
}

.skeleton-fade-in {
    animation: skeleton-fade-in 0.3s ease-out forwards;
}

@keyframes skeleton-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Responsive Skeleton Adjustments
   ========================================================================== */

@media (max-width: 768px) {
    .skeleton-hero-title,
    .skeleton-hero-subtitle {
        width: 90%;
    }
    
    .skeleton-hero-buttons {
        flex-direction: column;
        align-items: center;
    }
    
    .skeleton-table-header,
    .skeleton-table-row {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .skeleton-nav {
        gap: 1rem;
    }
}

/* Image Fade-In Loading with Progress Bar
   ========================================================================== */

.image-loading-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
}

.fade-in-image {
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    display: block;
    width: 100%;
    height: auto;
}

.fade-in-image.loaded {
    opacity: 1;
}

/* Minimal progress bar */
.image-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.1);
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.3s ease-out;
}

.image-progress-fill {
    height: 100%;
    background: var(--bs-primary, #0d6efd);
    animation: progress-loading 1.5s ease-in-out infinite;
}

@keyframes progress-loading {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(200%);
    }
}

/* Hide progress bar when loaded */
.image-loading-wrapper.loaded .image-progress-bar {
    opacity: 0;
    pointer-events: none;
}

/* Faster fade for smaller images */
.fade-in-image[width][height] {
    transition-duration: 0.3s;
}

/* Preserve space while loading to prevent layout shift */
img[width][height] {
    display: block;
    height: auto;
}

/* Performance Optimizations
   ========================================================================== */

/* Use CSS containment for better performance */
.skeleton-container {
    contain: layout style;
}

/* Reduce animation overhead for many skeletons */
@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: #f0f0f0;
    }
    
    .skeleton-pulse {
        animation: none;
    }
    
    .skeleton-wave::after {
        animation: none;
    }
    
    .fade-in-image {
        transition: none;
        opacity: 1;
    }
}