/**
 * Stories Viewer - Frontend Styles
 * Mobile-first, responsivo, compativel com LiteSpeed Cache
 */

/* Reset e base */
.stories-container *,
.stories-viewer-wrapper * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Container de thumbnails */
.stories-container {
    padding: 15px 0;
}

.stories-thumbnails {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 15px;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}

.stories-thumbnails::-webkit-scrollbar {
    display: none;
}

/* Thumbnail individual */
.story-thumb {
    flex-shrink: 0;
    cursor: pointer;
    text-align: center;
    width: 75px;
}

.story-thumb-ring {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    padding: 3px;
    background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
    margin: 0 auto 6px;
    transition: transform 0.2s ease;
}

.story-thumb:hover .story-thumb-ring {
    transform: scale(1.05);
}

.story-thumb.viewed .story-thumb-ring {
    background: #c7c7c7;
}

.story-thumb-ring img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid #fff;
}

/* Video thumbnail */
.story-thumb-video {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #fff;
    background: #000;
}

.story-thumb-video video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-thumb-play {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.story-thumb-play svg {
    width: 12px;
    height: 12px;
    margin-left: 2px;
    color: #000;
}

.story-thumb-name {
    display: block;
    font-size: 11px;
    color: #262626;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Body quando viewer esta aberto */
body.stories-open {
    overflow: hidden;
}

/* Viewer Wrapper */
.stories-viewer-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 999999;
    background: #000;
}

/* Viewer */
.stories-viewer {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 450px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
}

/* Overlay */
.stories-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        180deg,
        rgba(0, 0, 0, 0.4) 0%,
        transparent 15%,
        transparent 85%,
        rgba(0, 0, 0, 0.4) 100%
    );
    pointer-events: none;
    z-index: 1;
}

/* Progress Bar */
.stories-progress {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 4px;
    padding: 10px 10px 0;
    z-index: 10;
}

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

.stories-progress-fill {
    height: 100%;
    width: 0;
    background: #fff;
    border-radius: 2px;
    transition: none;
}

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

/* Header */
.stories-header {
    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    z-index: 10;
}

.stories-profile {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stories-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid #fff;
    flex-shrink: 0;
}

.stories-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.stories-profile-info {
    display: flex;
    flex-direction: column;
}

.stories-profile-name {
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.stories-time {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
}

.stories-close {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0, 0, 0, 0.3);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.stories-close:hover {
    background: rgba(0, 0, 0, 0.5);
}

/* Media Container */
.stories-media {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
}

.stories-image,
.stories-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Navigation Areas */
.stories-nav {
    position: absolute;
    top: 80px;
    bottom: 100px;
    width: 30%;
    z-index: 5;
    cursor: pointer;
}

.stories-nav-prev {
    left: 0;
}

.stories-nav-next {
    right: 0;
}

/* Footer */
.stories-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px 15px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
    z-index: 10;
}

.stories-content {
    margin-bottom: 15px;
}

.stories-content p {
    color: #fff;
    font-size: 14px;
    line-height: 1.5;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    word-wrap: break-word;
}

.stories-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.stories-cta {
    flex: 1;
    display: block;
    padding: 12px 20px;
    background: #fff;
    color: #000;
    text-align: center;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    transition: background 0.2s, transform 0.2s;
}

.stories-cta:hover {
    background: #f0f0f0;
    transform: scale(1.02);
}

.stories-chat {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #25d366;
    color: #fff;
    border-radius: 50%;
    text-decoration: none;
    transition: background 0.2s, transform 0.2s;
}

.stories-chat:hover {
    background: #1da851;
    transform: scale(1.05);
}

.stories-chat svg {
    width: 24px;
    height: 24px;
}

/* Watermark */
.stories-watermark {
    position: absolute;
    z-index: 8;
    pointer-events: none;
    max-width: 15%;
}

.stories-watermark img {
    max-width: 100%;
    height: auto;
}

.stories-watermark-top-left {
    top: 70px;
    left: 15px;
}

.stories-watermark-top-center {
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
}

.stories-watermark-top-right {
    top: 70px;
    right: 15px;
}

.stories-watermark-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.stories-watermark-bottom-left {
    bottom: 120px;
    left: 15px;
}

.stories-watermark-bottom-center {
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
}

.stories-watermark-bottom-right {
    bottom: 120px;
    right: 15px;
}

/* Estado pausado */
.stories-viewer.paused .stories-progress,
.stories-viewer.paused .stories-header,
.stories-viewer.paused .stories-footer,
.stories-viewer.paused .stories-watermark {
    opacity: 0;
    transition: opacity 0.2s;
}

/* Desktop */
@media screen and (min-width: 768px) {
    .stories-viewer-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(0, 0, 0, 0.9);
    }

    .stories-viewer {
        height: 90vh;
        max-height: 800px;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    }

    .stories-thumbnails {
        padding: 5px 0;
    }

    .story-thumb {
        width: 85px;
    }

    .story-thumb-ring {
        width: 76px;
        height: 76px;
    }

    .story-thumb-name {
        font-size: 12px;
    }
}

/* Acessibilidade */
@media (prefers-reduced-motion: reduce) {
    .stories-cta,
    .stories-chat,
    .story-thumb-ring,
    .stories-close {
        transition: none;
    }
}

/* Dark mode para thumbnails */
@media (prefers-color-scheme: dark) {
    .story-thumb-name {
        color: #f0f0f0;
    }

    .story-thumb-ring img {
        border-color: #1a1a1a;
    }
}

/* Safe areas para iPhone X+ */
@supports (padding: max(0px)) {
    .stories-progress {
        padding-top: max(10px, env(safe-area-inset-top));
    }

    .stories-header {
        top: max(20px, calc(env(safe-area-inset-top) + 10px));
    }

    .stories-footer {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}

/* Aspect ratio 9:16 para viewer */
@media screen and (min-aspect-ratio: 9/16) {
    .stories-viewer {
        aspect-ratio: 9 / 16;
        height: auto;
        max-height: 100%;
    }
}

/* Loading state */
.stories-media::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: stories-spin 0.8s linear infinite;
    z-index: 0;
}

.stories-media:has(img[src])::before,
.stories-media:has(video[src])::before {
    display: none;
}

@keyframes stories-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Fallback para navegadores sem :has */
.stories-image,
.stories-video {
    position: relative;
    z-index: 1;
}

/* Share Sidebar */
.stories-share-sidebar {
    position: fixed;
    right: calc(50% - 225px + 10px);
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000000;
}

@media screen and (max-width: 500px) {
    .stories-share-sidebar {
        right: 10px;
    }
}

.stories-share-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.stories-share-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

.stories-share-btn:active {
    transform: scale(0.95);
}

.stories-share-btn svg {
    width: 22px;
    height: 22px;
}

/* WhatsApp button */
.stories-share-btn[data-action="whatsapp"]:hover {
    background: #25d366;
}

/* Telegram button */
.stories-share-btn[data-action="telegram"]:hover {
    background: #0088cc;
}

/* Copy button */
.stories-share-btn[data-action="copy"]:hover {
    background: rgba(255, 255, 255, 0.4);
}

/* Toast notification */
.stories-share-toast {
    position: absolute;
    right: 60px;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}

.stories-share-toast.show {
    opacity: 1;
    visibility: visible;
}

/* Desktop adjustments for share */
@media screen and (min-width: 768px) {
    .stories-share-sidebar {
        right: calc(50% - 225px + 10px);
    }

    .stories-share-btn {
        width: 48px;
        height: 48px;
    }

    .stories-share-btn svg {
        width: 24px;
        height: 24px;
    }

    .stories-share-toast {
        right: 70px;
    }
}

/* Mobile adjustments */
@media screen and (max-width: 767px) {
    .stories-share-sidebar {
        right: 8px;
        gap: 10px;
    }

    .stories-share-btn {
        width: 40px;
        height: 40px;
    }

    .stories-share-btn svg {
        width: 20px;
        height: 20px;
    }
}
