/* KStory Beautiful Preloader Styles */

/* Main preloader container - matches modal style */
.kstory-preloader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 1;
    transition: opacity 0.5s ease-out;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.kstory-preloader.fade-out {
    opacity: 0;
    pointer-events: none;
}

/* Preloader content */
.kstory-preloader-content {
    text-align: center;
    color: white;
}

/* Instagram-style story ring loader */
.kstory-ring-loader {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
}

.kstory-ring-loader::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: conic-gradient(from 0deg, rgba(131, 58, 180, 1), rgba(253, 29, 29, 1), rgba(252, 176, 69, 1), transparent);
    border-radius: 50%;
    animation: kstory-spin 1s linear infinite;
    mask: radial-gradient(circle, transparent 35px, black 38px);
    -webkit-mask: radial-gradient(circle, transparent 35px, black 38px);
}

.kstory-ring-loader::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 6px;
    width: calc(100% - 12px);
    height: calc(100% - 12px);
    background: conic-gradient(from 0deg, rgba(252, 176, 69, 0.8), transparent 90deg);
    border-radius: 50%;
    animation: kstory-spin 0.8s linear infinite reverse;
    mask: radial-gradient(circle, transparent 28px, black 30px);
    -webkit-mask: radial-gradient(circle, transparent 28px, black 30px);
}

/* Spinning animation */
@keyframes kstory-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Pulsing dots loader */
.kstory-dots-loader {
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px 0;
}

.kstory-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.8);
    margin: 0 4px;
    animation: kstory-pulse 1.4s ease-in-out infinite both;
}

.kstory-dot:nth-child(1) { animation-delay: -0.32s; }
.kstory-dot:nth-child(2) { animation-delay: -0.16s; }
.kstory-dot:nth-child(3) { animation-delay: 0s; }

@keyframes kstory-pulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Loading text */
.kstory-loading-text {
    font-size: 16px;
    font-weight: 500;
    margin-top: 15px;
    opacity: 0.9;
    animation: kstory-fade-in-out 2s ease-in-out infinite;
}

@keyframes kstory-fade-in-out {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Progress bar loader */
.kstory-progress-loader {
    width: 200px;
    height: 4px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
    margin: 20px auto;
    overflow: hidden;
    position: relative;
}

.kstory-progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, rgba(131, 58, 180, 1) 0%, rgba(253, 29, 29, 1) 50%, rgba(252, 176, 69, 1) 100%);
    border-radius: 2px;
    transition: width 0.3s ease;
    position: relative;
}

.kstory-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.6) 100%);
    animation: kstory-shimmer 1.5s ease-in-out infinite;
}

@keyframes kstory-shimmer {
    0% { transform: translateX(-20px); }
    100% { transform: translateX(20px); }
}

/* Modal preloader (matches swiper modal style) */
.kstory-modal-preloader {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(12, 12, 12, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(7.7px);
    -webkit-backdrop-filter: blur(17.7px);
    border-radius: 20px;
    border: 15px solid rgba(255, 255, 255, 0.08);
}

.kstory-modal-preloader .kstory-ring-loader {
    width: 60px;
    height: 60px;
}

.kstory-modal-preloader .kstory-loading-text {
    font-size: 14px;
    margin-top: 10px;
}

/* Story slide preloader - matches story modal */
.kstory-slide-preloader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    background: rgba(255, 255, 255, 0.05);
    padding: 20px;
    border-radius: 15px;
    backdrop-filter: blur(7.7px);
    -webkit-backdrop-filter: blur(17.7px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

.kstory-slide-preloader .kstory-ring-loader {
    width: 40px;
    height: 40px;
}

/* Skeleton loader for story content */
.kstory-skeleton {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.1) 25%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.1) 75%);
    background-size: 200% 100%;
    animation: kstory-skeleton-loading 1.5s infinite;
}

@keyframes kstory-skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.kstory-skeleton-text {
    height: 16px;
    border-radius: 8px;
    margin: 8px 0;
}

.kstory-skeleton-title {
    height: 24px;
    border-radius: 12px;
    margin: 12px 0;
    width: 70%;
}

.kstory-skeleton-image {
    height: 200px;
    border-radius: 12px;
    margin: 16px 0;
}

/* Story shortcode skeleton loader - CSS Grid Layout */
.kstory-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
    gap: 15px;
    padding: 0;
    margin: 40px 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.kstory-skeleton-grid::-webkit-scrollbar {
    display: none;
}

.kstory-skeleton-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 84px;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .kstory-skeleton-grid {
        gap: 8px;
        margin: 20px 0;
        grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    }
    
    .kstory-skeleton-item {
        min-width: 70px;
        gap: 6px;
    }
    
    .kstory-skeleton-story-image {
        width: 70px;
        height: 70px;
    }
    
    .kstory-skeleton-item .kstory-skeleton-text {
        width: 50px;
        height: 10px;
    }
}

.kstory-skeleton-story-image {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: linear-gradient(90deg, 
        rgba(131, 58, 180, 0.1) 25%, 
        rgba(253, 29, 29, 0.1) 50%, 
        rgba(252, 176, 69, 0.1) 75%
    );
    background-size: 200% 100%;
    animation: kstory-skeleton-loading 1.5s infinite;
    position: relative;
}

.kstory-skeleton-story-image::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    background: #f8f9fa;
    border-radius: 50%;
    animation: kstory-skeleton-pulse 2s ease-in-out infinite;
}

.kstory-skeleton-item .kstory-skeleton-text {
    width: 60px;
    height: 12px;
    border-radius: 6px;
    margin: 0;
}

@keyframes kstory-skeleton-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 0.9; }
}

/* Skeleton loader container for shortcode */
#kstory-skeleton-loader {
    opacity: 1;
    transition: opacity 0.3s ease;
}

#kstory-skeleton-loader.fade-out {
    opacity: 0;
}

#kstory-actual-content {
    opacity: 0;
    transition: opacity 0.3s ease;
}

#kstory-actual-content.fade-in {
    opacity: 1;
}

/* Error state styling */
.kstory-error-state {
    text-align: center;
    color: #ff6b6b;
    padding: 40px 20px;
}

.kstory-error-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.8;
}

.kstory-error-message {
    font-size: 16px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.kstory-retry-btn {
    background: linear-gradient(90deg, rgba(131, 58, 180, 1) 0%, rgba(253, 29, 29, 1) 50%, rgba(252, 176, 69, 1) 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(131, 58, 180, 0.3);
    backdrop-filter: blur(7.7px);
    -webkit-backdrop-filter: blur(17.7px);
}

.kstory-retry-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(131, 58, 180, 0.4);
    filter: brightness(1.1);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .kstory-ring-loader {
        width: 60px;
        height: 60px;
    }
    
    .kstory-loading-text {
        font-size: 14px;
    }
    
    .kstory-progress-loader {
        width: 150px;
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .kstory-preloader {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .kstory-ring-loader::before,
    .kstory-ring-loader::after {
        animation: none;
    }
    
    .kstory-dot {
        animation: none;
        opacity: 0.8;
    }
    
    .kstory-loading-text {
        animation: none;
        opacity: 0.9;
    }
    
    .kstory-skeleton {
        animation: none;
        background: rgba(255, 255, 255, 0.15);
    }
}