/* Story Carousel Frontend Styles */

/* Reset and Base */
.story-carousel-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.story-carousel-container * {
    box-sizing: border-box;
}

/* Section Wrapper */
.story-carousel-section {
    padding: 60px 0;
    background: #ffffff;
}

.story-carousel-section h2 {
    text-align: center;
    font-size: 32px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 12px;
    letter-spacing: -0.01em;
}

.story-carousel-section p {
    text-align: center;
    font-size: 16px;
    color: #6b7280;
    max-width: 500px;
    margin: 0 auto 40px auto;
}

/* Container */
.story-carousel-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

.story-carousel-wrapper.full-width {
    max-width: none;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    width: 100vw;
}

.story-carousel-wrapper.full-width .story-carousel {
    padding: 0 40px;
}

/* Main Carousel */
.story-carousel {
    position: relative;
    width: 100%;
    overflow: hidden;
}

.story-carousel-scroll {
    display: flex;
    gap: 12px;
    padding: 0 20px;
    overflow-x: auto;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.story-carousel-scroll::-webkit-scrollbar {
    display: none;
}

/* Story Cards */
.story-card {
    position: relative;
    flex-shrink: 0;
    border-radius: 16px;
    overflow: hidden;
    cursor: pointer;
    scroll-snap-align: start;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    background: #000;
}

/* Card Sizes */
.story-card.size-small {
    width: 200px;
    height: 350px;
}

.story-card.size-medium {
    width: 260px;
    height: 460px;
}

.story-card.size-large {
    width: 320px;
    height: 560px;
}

.story-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.story-card-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s ease;
}

.story-card:hover .story-card-video {
    transform: scale(1.03);
}

/* Video Overlay */
.story-card-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0.1) 0%,
        rgba(0, 0, 0, 0) 60%,
        rgba(0, 0, 0, 0.4) 100%
    );
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.story-card:hover .story-card-overlay {
    opacity: 1;
}

/* Progress Bar */
.story-card-progress {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 1px;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.story-card:hover .story-card-progress {
    opacity: 1;
}

.story-card-progress-fill {
    height: 100%;
    background: #ffffff;
    width: 0%;
    transition: width 3s ease-out;
    border-radius: 1px;
}

/* Product Overlay */
.story-card-product {
    position: absolute;
    bottom: 16px;
    left: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    border-radius: 12px;
    padding: 14px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.story-card:hover .story-card-product {
    transform: translateY(0);
}

.story-card-product-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.story-card-product-image {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    background: #f3f4f6;
    flex-shrink: 0;
}

.story-card-product-details h4 {
    font-size: 13px;
    font-weight: 500;
    color: #1a1a1a;
    margin: 0 0 2px 0;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.story-card-product-price {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0;
}

/* Navigation Arrows */
.story-carousel-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    background: rgba(0, 0, 0, 0.8);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    opacity: 0;
    z-index: 10;
    color: rgba(255, 255, 255, 0.9);
}

.story-carousel:hover .story-carousel-nav {
    opacity: 1;
}

.story-carousel-nav:hover {
    background: rgba(0, 0, 0, 1);
    transform: translateY(-50%) scale(1.1);
}

.story-carousel-nav.prev {
    left: -18px;
}

.story-carousel-nav.next {
    right: -18px;
}

.story-carousel-nav svg {
    width: 14px;
    height: 14px;
    fill: currentColor;
}

/* Fullscreen Story Viewer */
.story-viewer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 999999;
    display: none;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.story-viewer.active {
    display: flex;
    opacity: 1;
}

.story-viewer-content {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 420px;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Horizontal Layout (Instagram-style) */
.story-viewer.horizontal .story-viewer-content {
    max-width: 420px;
    max-height: 100vh;
}

/* Vertical Layout (TikTok-style) */
.story-viewer.vertical .story-viewer-content {
    max-width: 100vw;
    max-height: 100vh;
    width: 100%;
}

.story-viewer.vertical .story-viewer-video {
    width: 100%;
    height: 100vh;
}

/* Both Layout */
.story-viewer.both .story-viewer-content {
    max-width: 100vw;
    max-height: 100vh;
    width: 100%;
}

.story-viewer-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.story-viewer-embed {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-viewer-embed .instagram-media {
    margin: auto !important; /* Important to override inline styles */
    width: 100% !important;
    min-width: unset !important;
}

/* Viewer Header */
.story-viewer-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 20px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.6) 0%, transparent 100%);
    z-index: 10;
}

.story-progress-bars {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}

.story-progress-segment {
    flex: 1;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 1px;
    overflow: hidden;
}

.story-progress-segment-fill {
    height: 100%;
    background: #ffffff;
    width: 0%;
    transition: width 0.1s linear;
}

.story-progress-segment.viewed .story-progress-segment-fill {
    width: 100%;
}

.story-viewer-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
}

.story-viewer-title {
    font-size: 15px;
    font-weight: 500;
    margin: 0;
}

.story-viewer-close {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: background 0.3s ease;
}

.story-viewer-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Navigation Areas */
.story-viewer-nav {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 35%;
    cursor: pointer;
    z-index: 5;
    user-select: none;
}

.story-viewer-nav.prev {
    left: 0;
}

.story-viewer-nav.next {
    right: 0;
}

/* Vertical Navigation */
.story-viewer.vertical .story-viewer-nav,
.story-viewer.both .story-viewer-nav {
    width: 100%;
    height: 35%;
    top: auto;
    bottom: auto;
}

.story-viewer.vertical .story-viewer-nav.prev,
.story-viewer.both .story-viewer-nav.prev {
    top: 0;
    left: 0;
    right: 0;
}

.story-viewer.vertical .story-viewer-nav.next,
.story-viewer.both .story-viewer-nav.next {
    bottom: 0;
    left: 0;
    right: 0;
}

/* Viewer Product Info */
.story-viewer-product {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 18px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 10;
}

.story-viewer-product.visible {
    transform: translateY(0);
}

.story-viewer-product-content {
    display: flex;
    align-items: center;
    gap: 14px;
}

.story-viewer-product-image {
    width: 54px;
    height: 54px;
    border-radius: 10px;
    object-fit: cover;
    background: #f3f4f6;
    flex-shrink: 0;
}

.story-viewer-product-details h4 {
    font-size: 15px;
    font-weight: 500;
    color: #1a1a1a;
    margin: 0 0 4px 0;
}

.story-viewer-product-price {
    font-size: 17px;
    font-weight: 600;
    color: #1a1a1a;
    margin: 0 0 8px 0;
}

.story-viewer-shop-btn {
    background: #1a1a1a;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s ease;
    text-decoration: none;
    display: inline-block;
}

.story-viewer-shop-btn:hover {
    background: #333;
    color: white;
    text-decoration: none;
}

/* Loading States */
.story-card-video[data-loading="true"] {
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: loading-bg 0.5s linear infinite;
}

@keyframes loading-bg {
    0% { background-position: 0 0, 0 10px, 10px -10px, -10px 0px; }
    100% { background-position: 20px 20px, 20px 30px, 30px 10px, 10px 20px; }
}

/* Error States */
.story-card-error {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f5f5f5;
    color: #666;
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .story-carousel-section {
        padding: 40px 0;
    }
    
    .story-carousel-section h2 {
        font-size: 24px;
    }
    
    .story-card.size-small {
        width: 180px;
        height: 320px;
    }
    
    .story-card.size-medium {
        width: 220px;
        height: 390px;
    }
    
    .story-card.size-large {
        width: 280px;
        height: 490px;
    }
    
    .story-carousel-scroll {
        padding: 0 16px;
    }
    
    .story-carousel-wrapper.full-width .story-carousel {
        padding: 0 20px;
    }
    
    .story-carousel-nav {
        display: none; /* Hide navigation arrows on mobile */
    }
    
    .story-viewer-content {
        max-width: 100%;
    }
    
    .story-viewer-header {
        padding: 16px;
    }
    
    .story-viewer-product {
        left: 16px;
        right: 16px;
        bottom: 16px;
        padding: 16px;
    }
}

@media (max-width: 480px) {
    .story-carousel-wrapper {
        padding: 0 16px;
    }
    
    .story-carousel-scroll {
        gap: 8px;
        padding: 0 12px;
    }
    
    .story-card.size-small {
        width: 160px;
        height: 280px;
    }
    
    .story-card.size-medium {
        width: 200px;
        height: 350px;
    }
    
    .story-card.size-large {
        width: 240px;
        height: 420px;
    }
}

/* Animations */
.story-card {
    animation: slideInUp 0.6s ease-out;
}

.story-card:nth-child(1) { animation-delay: 0.1s; }
.story-card:nth-child(2) { animation-delay: 0.15s; }
.story-card:nth-child(3) { animation-delay: 0.2s; }
.story-card:nth-child(4) { animation-delay: 0.25s; }
.story-card:nth-child(5) { animation-delay: 0.3s; }

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

/* Accessibility */
.story-card:focus,
.story-viewer-close:focus,
.story-viewer-shop-btn:focus {
    outline: 2px solid #2271b1;
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .story-card {
        border: 2px solid;
    }
    
    .story-card-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
    
    .story-viewer {
        background: #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .story-card,
    .story-card-video,
    .story-card-overlay,
    .story-card-progress,
    .story-card-product,
    .story-viewer {
        transition: none;
        animation: none;
    }
    
    .story-carousel-scroll {
        scroll-behavior: auto;
    }
}