/**
 * 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;
    -webkit-tap-highlight-color: transparent;
}

/* Container de thumbnails */
.stories-container {
    padding: 2px 20px;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

/* Titulo opcional dos stories */
.stories-title {
    font-size: 14px;
    font-weight: 600;
    color: inherit;
    opacity: 0.7;
    margin: 0 0 5px 0 !important;
    padding: 0 !important;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Centraliza titulo quando thumbnails centralizados */
@media (min-width: 768px) {
    .stories-container:has(.stories-thumbnails:not(.has-overflow)) .stories-title {
        text-align: center;
    }
}

.stories-thumbnails-wrapper {
    position: relative;
}

.stories-thumbnails {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
    /* Centraliza quando poucos stories (desktop) */
    justify-content: flex-start;
    scroll-behavior: smooth;
}

/* Setas de navegacao - Desktop */
.stories-nav-arrow {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border: none !important;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff !important;
    cursor: pointer;
    z-index: 10;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    transition: background 0.2s, transform 0.2s, opacity 0.2s;
    opacity: 0;
    pointer-events: none;
}

.stories-nav-arrow:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-50%) scale(1.1);
}

.stories-nav-arrow.visible {
    opacity: 1;
    pointer-events: auto;
}

.stories-nav-arrow svg {
    width: 22px;
    height: 22px;
}

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

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

@media (min-width: 768px) {
    .stories-nav-arrow {
        display: flex;
    }

    .stories-thumbnails-wrapper {
        padding: 0 45px;
        margin: 0 -10px;
    }
}

/* Centraliza stories quando couberem na tela (desktop) */
@media (min-width: 768px) {
    .stories-thumbnails:not(.has-overflow) {
        justify-content: center;
    }
}

/* Wrapper para posicao automatica - full width */
.stories-after-header,
.stories-auto-position,
.stories-position-footer,
.stories-position-blog {
    width: 100% !important;
    background: inherit;
    padding: 0 !important;
    margin: 0 !important;
    line-height: normal !important;
}

.stories-after-header .stories-container,
.stories-auto-position .stories-container,
.stories-position-footer .stories-container,
.stories-position-blog .stories-container {
    max-width: 1200px;
    margin: 0 auto !important;
    padding: 2px 20px !important;
    width: 100%;
    box-sizing: border-box;
}

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

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

/* Thumbnail ring - circulo com gradiente */
.story-thumb-ring {
    width: 68px;
    height: 68px;
    min-width: 68px;
    min-height: 68px;
    max-width: 68px;
    max-height: 68px;
    padding: 3px;
    border-radius: 50%;
    background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
    margin: 0 auto 6px;
    transition: transform 0.2s ease;
    box-sizing: border-box;
    overflow: hidden;
    display: block;
}

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

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

/* Imagem dentro do ring */
.story-thumb-ring img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    object-position: center;
    display: block;
    box-sizing: border-box;
    border: 2px solid #fff;
}

/* Video thumbnail container */
.story-thumb-video {
    position: relative;
    overflow: hidden;
    background: #000 !important;
}

.story-thumb-video video {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 150%;
    height: 150%;
    transform: translate(-50%, -50%);
    object-fit: cover;
}

/* 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: 100%;
    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: 12px 12px 0;
    z-index: 10;
}

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

.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;
    gap: 1px;
    line-height: 1.2;
}

.stories-profile-name {
    color: #fff !important;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 4px;
}

.stories-verified-badge {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

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

/* Header Actions Container */
.stories-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Mute Button */
.stories-mute {
    width: 36px;
    height: 36px;
    border: none !important;
    background: rgba(0, 0, 0, 0.3) !important;
    color: #fff !important;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.stories-mute:hover {
    background: rgba(0, 0, 0, 0.5) !important;
}

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

.stories-mute .mute-icon { display: none; }
.stories-mute .unmute-icon { display: block; }
.stories-mute.muted .mute-icon { display: block; }
.stories-mute.muted .unmute-icon { display: none; }

.stories-close {
    width: 36px;
    height: 36px;
    border: none !important;
    background: rgba(0, 0, 0, 0.3) !important;
    color: #fff !important;
    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) !important;
}

/* 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;
    /* Impedir download e selecao */
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

/* Overlay para capturar cliques no video */
.stories-media::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* Pause Indicator */
.stories-pause-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    background: rgba(0, 0, 0, 0.5) !important;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    z-index: 15;
    pointer-events: none;
}

.stories-pause-indicator.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    cursor: pointer;
}

.stories-pause-indicator svg {
    width: 40px;
    height: 40px;
    color: #fff !important;
    margin-left: -3px;
}

/* Animações de transição de navegação - fade simples */
.stories-media.slide-left,
.stories-media.slide-right {
    opacity: 0;
    transition: opacity 0.15s ease;
}

/* Navigation Areas */
.stories-nav {
    position: absolute;
    top: 80px;
    bottom: 100px;
    width: 30%;
    z-index: 5;
    cursor: pointer;
    background: transparent;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    outline: none;
    border: none !important;
}

.stories-nav:focus,
.stories-nav:active {
    outline: none;
    background: transparent;
}

.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 !important;
    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;
    justify-content: center;
}

/* Botao CTA estilo Instagram com icone de link */
.stories-cta {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    background: #fff;
    color: #000;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border-radius: 20px;
    transition: background 0.2s, transform 0.2s;
    width: auto;
    max-width: fit-content;
    margin: 0 auto;
}

.stories-cta-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.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 !important;
    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: 25%;
}

.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 {
        max-width: 450px;
        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;
    }
}

/* 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-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 !important;
    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 Toggle e Dropdown */
.stories-share-wrapper {
    position: relative;
}

.stories-share-toggle {
    width: 36px;
    height: 36px;
    border: none !important;
    background: rgba(0, 0, 0, 0.3) !important;
    color: #fff !important;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.stories-share-toggle:hover {
    background: rgba(0, 0, 0, 0.5) !important;
}

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

.stories-share-dropdown {
    position: absolute;
    top: 45px;
    right: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 6px 0;
    display: none;
    flex-direction: column;
    min-width: 150px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.stories-share-dropdown.active {
    display: flex;
}

.stories-share-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: none;
    border: none !important;
    border-radius: 50% !important;
    color: #fff !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.stories-share-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

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

.stories-share-btn[data-action="whatsapp"]:hover {
    background: rgba(37, 211, 102, 0.2);
}

.stories-share-btn[data-action="telegram"]:hover {
    background: rgba(0, 136, 204, 0.2);
}

/* Toast notification */
.stories-share-toast {
    display: none;
    padding: 10px 14px;
    color: #4ade80;
    font-size: 13px;
    text-align: center;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.stories-share-toast.show {
    display: block;
}

/* Animação de fechar arrastando para baixo */
.stories-viewer-wrapper {
    transition: transform 0.15s ease, opacity 0.15s ease;
}

.stories-viewer-wrapper.closing-down {
    animation: slideDownClose 0.25s ease forwards;
}

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

/* Loading Indicator - Transparente para mostrar thumbnail */
.stories-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3) !important;
    z-index: 20;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.stories-loading.visible {
    opacity: 1;
    visibility: visible;
}

.stories-loading-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff !important;
    border-radius: 50%;
    animation: stories-loading-spin 0.8s linear infinite;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.stories-loading-text {
    color: #fff !important;
    font-size: 14px;
    margin-top: 16px;
    letter-spacing: 0.5px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

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

/* Buffering Indicator - Durante playback */
.stories-buffering {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 16;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    pointer-events: none;
}

.stories-buffering.visible {
    opacity: 1;
    visibility: visible;
}

.stories-buffering-spinner {
    width: 56px;
    height: 56px;
    border: 3px solid rgba(255, 255, 255, 0.15);
    border-top-color: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    animation: stories-buffering-spin 0.7s linear infinite;
    background: rgba(0, 0, 0, 0.3) !important;
}

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

/* Esconder loading antigo quando novo esta ativo */
.stories-loading.visible ~ .stories-media::before {
    display: none;
}

/* High specificity overrides for theme compatibility */
.stories-viewer-wrapper button.stories-close,
.stories-viewer-wrapper button.stories-mute,
.stories-viewer-wrapper button.stories-share-toggle,
button.stories-close,
button.stories-mute,
button.stories-share-toggle {
    background: rgba(0, 0, 0, 0.3) !important;
    background-color: rgba(0, 0, 0, 0.3) !important;
    border: none !important;
    color: #fff !important;
}

.stories-viewer-wrapper button.stories-close:hover,
.stories-viewer-wrapper button.stories-mute:hover,
.stories-viewer-wrapper button.stories-share-toggle:hover,
button.stories-close:hover,
button.stories-mute:hover,
button.stories-share-toggle:hover {
    background: rgba(0, 0, 0, 0.5) !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
}
/* SVG icons inside buttons */
.stories-viewer-wrapper button.stories-close svg,
.stories-viewer-wrapper button.stories-mute svg,
.stories-viewer-wrapper button.stories-share-toggle svg,
button.stories-close svg,
button.stories-mute svg,
button.stories-share-toggle svg {
    width: 20px !important;
    height: 20px !important;
    fill: currentColor !important;
    color: #fff !important;
}

/* ===========================================
   THEME OVERRIDE - Maximum specificity for Soledad/Penci theme
   Added for version 1.4.3 to fix button styling
   =========================================== */

/* Override theme button reset with maximum specificity */
html body .stories-viewer-wrapper button.stories-close,
html body .stories-viewer-wrapper button.stories-mute,
html body .stories-viewer-wrapper button.stories-share-toggle,
html body button.stories-close,
html body button.stories-mute,
html body button.stories-share-toggle {
    background: rgba(0, 0, 0, 0.3) !important;
    background-color: rgba(0, 0, 0, 0.3) !important;
    border: none !important;
    border-radius: 50% !important;
    -webkit-border-radius: 50% !important;
    -moz-border-radius: 50% !important;
    color: #fff !important;
    width: 36px !important;
    height: 36px !important;
    min-width: 36px !important;
    min-height: 36px !important;
    max-width: 36px !important;
    max-height: 36px !important;
    padding: 0 !important;
    margin: 0 4px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    outline: none !important;
    box-shadow: none !important;
}

html body .stories-viewer-wrapper button.stories-close:hover,
html body .stories-viewer-wrapper button.stories-mute:hover,
html body .stories-viewer-wrapper button.stories-share-toggle:hover,
html body button.stories-close:hover,
html body button.stories-mute:hover,
html body button.stories-share-toggle:hover {
    background: rgba(0, 0, 0, 0.5) !important;
    background-color: rgba(0, 0, 0, 0.5) !important;
    border-radius: 50% !important;
}

/* SVG icons inside buttons */
html body .stories-viewer-wrapper button.stories-close svg,
html body .stories-viewer-wrapper button.stories-mute svg,
html body .stories-viewer-wrapper button.stories-share-toggle svg,
html body button.stories-close svg,
html body button.stories-mute svg,
html body button.stories-share-toggle svg {
    width: 20px !important;
    height: 20px !important;
    fill: currentColor !important;
    color: #fff !important;
}