/* ═══════════════════════════════════════════════════════════════════
   stories.css — истории на витрине (карточки на главной + просмотрщик)
   ═══════════════════════════════════════════════════════════════════ */

/* ═══════════════ STORIES BUBBLE (карточки на главной) ═══════════════ */
#stories-bubble-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 32px;
    padding: 4px 0;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
#stories-bubble-row::-webkit-scrollbar { display: none; }

.story-bubble {
    display: block;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.story-bubble:hover { transform: scale(1.03); }
.story-bubble:active { transform: scale(0.97); }

/* ─── Одинаковый размер у всех карточек ─── */
.story-bubble-ring {
    display: block;
    width: 115px;
    height: 153px;              /* 3:4, ещё чуть крупнее */
    padding: 3px;
    border-radius: 27px;
    background: transparent;
}

.story-bubble-inner {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 24px;
    overflow: hidden;
    background: var(--thumb-bg);
    border: 2px solid var(--bg-body);
    display: block;
    transition: border-color 0.3s ease;
}

/* ─── Непросмотренная — рамка в основном цвете ─── */
.story-bubble.is-unviewed .story-bubble-inner {
    border-color: var(--accent);
}

/* ─── Просмотренная — рамка цвета фона ───
   Размер тот же, что у непросмотренной — меняется только цвет. */
.story-bubble.is-viewed .story-bubble-inner {
    border-color: var(--bg-body);
}

/* ─── Медиа внутри карточки: всегда заполняет кружок ───
   position: absolute — чтобы не влиять на размеры обёртки,
   object-fit: cover — чтобы фото/видео вписывалось без искажений. */
.story-bubble-inner img,
.story-bubble-inner video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    pointer-events: none;
}

.story-bubble-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 6px 8px;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, rgba(0,0,0,0.5) 60%, transparent 100%);
    color: var(--white-on-accent);
    font-size: 11px;
    font-weight: 600;
    line-height: 1.25;
    text-align: center;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: break-word;
    pointer-events: none;
    z-index: 2;
}

/* ═══════════════ STORIES VIEWER ═══════════════ */
.stories-viewer {
    position: fixed;
    inset: 0;
    background: var(--overlay-modal-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    z-index: 20000;
    display: none;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.25s ease;
    touch-action: none;
}
.stories-viewer.active { display: flex; opacity: 1; }

.stories-viewer-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    padding: 40px 16px 90px;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

.stories-viewer-media-wrap {
    position: relative;
    width: min(480px, calc(85vh * 9 / 16));
    aspect-ratio: 9 / 16;
    background: var(--thumb-bg);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

/* ─── Медиа в просмотрщике — система как в PDP-слайдере ───
   contain: кадр полностью виден, пропорции сохранены.
   width/height: auto + max-*: элемент подстраивается под
   натуральные размеры картинки/видео и центрируется flex-ом
   родителя. Пустоты вокруг заливаются фоном .stories-viewer-media-wrap. */
.stories-viewer-media {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    object-position: center;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

.stories-viewer-progress {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    z-index: 3;
    display: flex;
    gap: 4px;
    padding: 0 16px;
}

.stories-progress-item {
    flex: 1;
    height: 3px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    overflow: hidden;
}
.stories-progress-fill {
    display: block;
    height: 100%;
    width: 0;
    background: var(--white-on-accent);
    border-radius: 2px;
}

.stories-viewer-header {
    position: absolute;
    top: max(30px, calc(env(safe-area-inset-top, 0px) + 20px));
    left: 0;
    right: 0;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 3;
    color: var(--white-on-accent);
    pointer-events: none;
}
.stories-viewer-header > * { pointer-events: auto; }

.stories-viewer-author {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.stories-viewer-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--white-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
}

.stories-viewer-title {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.stories-viewer-time {
    font-size: 11px;
    opacity: 0.8;
    margin-top: 2px;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.stories-viewer-header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    pointer-events: auto;
}

.stories-viewer-icon-btn {
    background: transparent;
    border: none;
    color: var(--white-on-accent);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, opacity 0.2s;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.stories-viewer-icon-btn svg { width: 20px; height: 20px; pointer-events: none; }
.stories-viewer-icon-btn:hover { transform: scale(1.1); }

.stories-viewer-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    color: var(--white-on-accent);
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.2s;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.stories-viewer-close:hover { opacity: 0.7; }

.stories-viewer-media-actions {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    z-index: 10;
}

.stories-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--btn-overlay-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--white-on-accent);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
    padding: 0;
}

.stories-action-btn:hover {
    background: var(--btn-overlay-bg-hover);
    transform: scale(1.08);
}

.stories-action-btn svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    pointer-events: none;
}

.stories-action-count {
    font-size: 11px;
    line-height: 1;
    pointer-events: none;
    margin-top: -2px;
}

.stories-action-btn.like-btn.liked {
    color: var(--danger);
    border-color: rgba(var(--danger-rgb), 0.4);
    background: rgba(var(--danger-rgb), 0.2);
}
.stories-action-btn.like-btn.liked svg {
    animation: like-pop 0.3s ease forwards;
}
@keyframes like-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.stories-viewer-cta {
    position: absolute;
    bottom: 24px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    z-index: 3;
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}
.stories-viewer-cta-link {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 12px 28px;
    background: var(--white-on-accent);
    color: var(--bg-body);
    font-weight: 600;
    font-size: 14px;
    border-radius: 100px;
    text-decoration: none;
    box-shadow: 0 8px 24px var(--shadow-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stories-viewer-cta-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 32px var(--shadow-color);
}

/* ═══════════════ MEDIA ═══════════════ */
@media (max-width: 768px) {
    /* ─── Карточки: один размер, чуть уменьшенный ─── */
    .story-bubble-ring {
        width: 100px;
        height: 133px;
        border-radius: 24px;
    }
    .story-bubble-inner {
        border-radius: 21px;
    }
    .story-bubble-label {
        font-size: 10px;
        padding: 18px 4px 6px;
    }
    #stories-bubble-row { gap: 10px; }

    /* ─── Просмотрщик на весь экран ─── */
    .stories-viewer-content {
        padding: 0;
        max-width: 100%;
        width: 100%;
        height: 100%;
    }
    .stories-viewer-media-wrap {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        aspect-ratio: auto;
        border-radius: 0;
    }

    .stories-viewer-progress {
        padding: 0 12px;
    }
    .stories-viewer-header {
        padding: 0 12px;
    }
    .stories-viewer-header-actions {
        gap: 12px;
    }
    .stories-viewer-media-actions {
        bottom: max(20px, env(safe-area-inset-bottom, 0px));
        right: 12px;
        gap: 8px;
    }
    .stories-action-btn {
        width: 46px;
        height: 46px;
    }
    .stories-action-btn svg {
        width: 18px;
        height: 18px;
    }
    .stories-action-count {
        font-size: 10px;
    }
    .stories-viewer-cta {
        bottom: max(80px, calc(env(safe-area-inset-bottom, 0px) + 80px));
    }
}

/* ─── Защита от «фантомных» кликов после смены слайда ─── */
.stories-switching .stories-viewer-media-actions,
.stories-switching .stories-viewer-media-actions *,
.stories-switching .stories-viewer-close,
.stories-switching .stories-viewer-icon-btn {
    pointer-events: none !important;
}

/* ═══════════════ SKELETON: карточки историй ═══════════════ */
/* Размер совпадает с реальной карточкой — чтобы не было скачка после загрузки. */
.story-bubble-skeleton {
    flex-shrink: 0;
    width: 115px;
    height: 153px;
    border-radius: 27px;
    background-color: var(--skeleton-base);
    animation: skeleton-pulse 1.5s infinite ease-in-out;
    pointer-events: none;
}

@media (max-width: 768px) {
    .story-bubble-skeleton {
        width: 100px;
        height: 133px;
        border-radius: 24px;
    }
}