/* General reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.story-box-instance-wrapper {
    max-width: 1200px;
    margin: 1rem auto;
    padding: 0 1rem;
    direction: ltr;
    text-align: left;
}

.story-box-instance-wrapper.story-box-rtl-enabled {
    direction: rtl;
    text-align: right;
}

.stories-container {
    position: relative;
    padding: 1rem 0;
}

.stories-wrapper {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    scroll-behavior: smooth;
    padding: 0.5rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.stories-wrapper::-webkit-scrollbar { display: none; }

.story-box-instance-wrapper .story-item {
    flex: 0 0 auto;
    width: 80px;
    text-align: center;
    cursor: pointer;
}

.story-box-instance-wrapper .story-title {
    font-size: var(--story-box-story-title-fs, 14px);
    font-weight: 500;
    color: #333;
    line-height: 1.4;
    height: 2.8em;
    overflow: hidden;
    text-align: center;
}

.story-box-instance-wrapper .story-avatar-container {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-bottom: 0.5rem;
    padding: 3px;
    background: linear-gradient(45deg, var(--story-box-gradient-start, #f09433) 0%, var(--story-box-gradient-end, #bc1888) 100%);
}

.story-box-instance-wrapper .story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid white;
}

/* Scroller nav buttons */
.story-box-instance-wrapper .nav-button {
    position: absolute;
    top: 50px;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: none; 
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
}
.story-box-instance-wrapper .nav-button svg { width: 24px; height: 24px; }
.story-box-instance-wrapper .nav-button-left { left: -15px; }
.story-box-instance-wrapper .nav-button-right { right: -15px; }
.story-box-instance-wrapper.story-box-rtl-enabled .nav-button-left { right: -15px; left: auto; transform: translateY(-50%) scaleX(-1); }
.story-box-instance-wrapper.story-box-rtl-enabled .nav-button-right { left: -15px; right: auto; transform: translateY(-50%) scaleX(-1); }


/* --- GLOBAL MODAL STYLES --- */
.story-viewer-modal {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.9); z-index: 999999; direction: ltr; text-align: left;
}
.story-viewer-modal.active { display: flex; align-items: center; justify-content: center; }

.story-viewer {
    position: relative; display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%;
    perspective: 1200px;
}

.story-thumbnail {
    position: absolute;
    width: 180px;
    height: 300px;
    cursor: pointer;
    transition: opacity 0.3s ease;
    opacity: 0.6;
    z-index: 10;
    display: none;
    align-items: center;
    justify-content: center;
    background-color: var(--story-box-thumbnail-bg, #000);
    border-radius: 8px;
}
.story-thumbnail:hover { opacity: 1; }
.story-thumbnail-prev { left: 10%; }
.story-thumbnail-next { right: 10%; }

.story-thumbnail .story-avatar-container {
    width: 85px;
    height: 85px;
}
.story-thumbnail .story-avatar-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.story-viewer-content {
    position: relative;
    width: 100%;
    max-width: 450px;
    max-height: 90vh;
    aspect-ratio: 9 / 16;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
    z-index: 5;
    transform-style: preserve-3d;
    transition: opacity 0.2s ease, transform 0.3s ease-out;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.story-viewer-content.is-paused {
    opacity: 0.95;
    transform: none !important;
}

.story-viewer-header {
    position: absolute; top: 0; left: 0; right: 0; padding: 25px 20px;
    display: flex; justify-content: space-between; align-items: center; z-index: 1;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}
#storyViewerModal .story-viewer-user-info { display: flex; align-items: center; gap: 1rem; color: white; }
#storyViewerModal .story-viewer-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
#storyViewerModal .story-viewer-title { font-size: var(--story-box-header-title-fs, 16px); font-weight: bold; color: var(--story-box-header-title-color, #fff); }
#storyViewerModal .story-viewer-close, #storyViewerModal .story-control-button { background: none; border: none; color: white; cursor: pointer; padding: 8px; display: flex; align-items: center; justify-content: center; }
#storyViewerModal .story-viewer-close svg, .story-control-button svg { width: 24px; height: 24px; }
#storyViewerModal .story-viewer-controls { display: flex; align-items: center; gap: 5px; }

#storyViewerModal .story-progress-bar { position: absolute; top: 10px; left: 20px; right: 20px; display: flex; gap: 4px; z-index: 2; }
#storyViewerModal .story-progress { flex: 1; height: 3px; background: rgba(255, 255, 255, 0.3); border-radius: 2px; overflow: hidden; position: relative; }
#storyViewerModal .story-progress-inner { position: absolute; top: 0; left: 0; height: 100%; width: 0; background: white; }

#storyViewerModal .story-viewer-footer { position: absolute; bottom: 0; left: 0; right: 0; padding: 20px; background: linear-gradient(to top, rgba(0, 0, 0, 0.7), transparent); z-index: 2; }
#storyViewerModal .story-viewer-footer-title { font-size: var(--story-box-footer-title-fs, 24px); margin-bottom: 0.5rem; font-weight: bold; color: var(--story-box-footer-title-color, #fff); }
#storyViewerModal .story-viewer-footer p { font-size: var(--story-box-description-fs, 16px); margin-bottom: 1rem; color: var(--story-box-description-color, #f0f0f0); }
#storyViewerModal .story-cta-button {
    font-size: var(--story-box-button-fs, 16px); background-color: var(--story-box-button-bg-color); color: var(--story-box-button-text-color); border: none;
    padding: 0.8rem 2rem; border-radius: 10px; width: 100%; font-weight: 600; cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.story-viewer-media { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background-color: black; }
.story-viewer-media img, .story-viewer-media video { 
    width: 100%; 
    height: 100%; 
}

/* Modal nav buttons (Desktop only) */
#storyViewerModal .story-nav-button {
    position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, 0.2); border: none; border-radius: 50%; width: 40px; height: 40px; cursor: pointer; display: none; align-items: center; justify-content: center; color: white; padding: 0; z-index: 15;
}
#storyViewerModal .story-nav-prev { left: 1rem; }
#storyViewerModal .story-nav-next { right: 1rem; }

@media (min-width: 769px) {
    #storyViewerModal .story-nav-button {
        display: flex;
    }
}

@media (max-width: 768px) {
    .story-viewer-content { width: 100%; height: 100%; max-height: 100%; border-radius: 0; aspect-ratio: unset; }
    .story-thumbnail { display: none !important; }
}

/* Skeleton Loading Styles */
@keyframes loading { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.story-item.skeleton .story-avatar-container, .story-item.skeleton .story-title {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
    color: transparent;
}
.story-viewer-modal.active { background: black; max-height: 100% !important; }
.story-item.skeleton .story-avatar-container { border-radius: 50%; }
.story-item.skeleton .story-title { height: 1.4em; border-radius: 4px; }
.story-viewer-media.skeleton { background: linear-gradient(90deg, #222 25%, #333 50%, #222 75%); background-size: 200% 100%; animation: loading 1.5s infinite; }

/* Animations for Story Transition */
@keyframes fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}
@keyframes cube-to-next {
    from { transform: translateX(0) rotateY(0); }
    to { transform: translateX(-100%) rotateY(90deg); }
}
@keyframes cube-to-prev {
    from { transform: translateX(0) rotateY(0); }
    to { transform: translateX(100%) rotateY(-90deg); }
}

/* Desktop fade animation */
.story-viewer.animate-fade .story-viewer-content {
    animation: fade-out 0.3s forwards;
}

/* Mobile 3D cube animation */
.story-viewer.animate-next-mobile .story-viewer-content {
    animation: cube-to-next 0.5s forwards;
}
.story-viewer.animate-prev-mobile .story-viewer-content {
    animation: cube-to-prev 0.5s forwards;
}

/* Product Modal Styles */
.product-modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000000;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.product-modal-overlay.active {
    opacity: 1;
}

.product-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 90%;
    max-width: 400px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    z-index: 1000001;
    overflow: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}
.product-modal.active {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

.product-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #eee;
}
.product-modal-title {
    font-size: 1.2rem;
    font-weight: 600;
    margin: 0;
    color: #333;
}
.product-modal-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    color: #888;
}

.product-modal-body {
    text-align: center;
}

.product-modal-image {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: cover;
    display: block;
}

.product-modal-price {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    padding: 1rem;
}
.product-modal-price .woocommerce-Price-amount {
    color: #111;
}

.product-modal-description {
    font-size: 0.95rem;
    color: #555;
    padding: 0 1rem 1rem;
    line-height: 1.5;
    text-align: right;
}

.product-modal-button {
    display: block;
    width: calc(100% - 2rem);
    margin: 0 1rem 1rem;
    padding: 0.8rem 1rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background-color: #0073aa;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

/* --- RTL STYLES --- */
.story-viewer-modal.story-viewer-rtl {
    direction: rtl;
    text-align: right;
}

/* Header */
.story-viewer-modal.story-viewer-rtl .story-viewer-header {
    flex-direction: row-reverse;
}
.story-viewer-modal.story-viewer-rtl .story-viewer-user-info {
    flex-direction: row-reverse;
}
.story-viewer-modal.story-viewer-rtl .story-viewer-controls {
    flex-direction: row-reverse;
}

/* Footer */
.story-viewer-modal.story-viewer-rtl .story-viewer-footer {
    text-align: right;
}
.story-viewer-modal.story-viewer-rtl .story-cta-button {
    flex-direction: row-reverse;
}

/* Main Nav Buttons */
.story-viewer-modal.story-viewer-rtl .story-nav-prev {
    left: auto !important;
    right: 1rem;
    transform: translateY(-50%) scaleX(-1) !important; 
}
.story-viewer-modal.story-viewer-rtl .story-nav-next {
    right: auto !important;
    left: 1rem;
    transform: translateY(-50%) scaleX(-1) !important; 
}

/* Thumbnail Previews */
.story-viewer-modal.story-viewer-rtl .story-thumbnail-prev {
    left: auto;
    right: 10%;
}
.story-viewer-modal.story-viewer-rtl .story-thumbnail-next {
    right: auto;
    left: 10%;
}

/* Progress Bar */
.story-viewer-modal.story-viewer-rtl .story-progress-inner {
    left: auto;
    right: 0;
}
