/* Лента постов Instagram / Threads внутри новостей (КФГД).
   Разметка создаётся редактором новостей; слайдер, «показать ещё» и окно просмотра — assets/js/social-feed.js.
   Без JS лента остаётся рабочей: карточки — обычные ссылки на посты. */

.sfeed {
    --gap: 12px;
    --cols: 3;
    --radius: 14px;
    --ink: #0f172a;
    margin: 28px 0;
    position: relative;
    clear: both;
}

.sfeed__title {
    margin: 0 0 14px !important;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.25;
    color: var(--ink);
}

/* ---------- список карточек ---------- */
.sfeed__list {
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    gap: var(--gap);
}

.sfeed[data-cols="1"] { --cols: 1; }
.sfeed[data-cols="2"] { --cols: 2; }
.sfeed[data-cols="3"] { --cols: 3; }
.sfeed[data-cols="4"] { --cols: 4; }
.sfeed[data-cols="5"] { --cols: 5; }

/* ---------- карточка ---------- */
.sfeed__item {
    position: relative;
    display: block;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    border-radius: var(--radius);
    background: #e2e8f0;
    color: #fff !important;
    text-decoration: none !important;
    isolation: isolate;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .08);
    transition: transform .2s ease, box-shadow .2s ease;
    -webkit-tap-highlight-color: transparent;
}

.sfeed__item:hover,
.sfeed__item:focus-visible {
    transform: translateY(-3px);
    box-shadow: 0 10px 24px rgba(15, 23, 42, .18);
}

.sfeed__item:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }

.sfeed__item img {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    object-fit: cover;
    border-radius: 0 !important;
    transition: transform .5s ease;
}

.sfeed__item:hover img { transform: scale(1.05); }

/* подпись поверх фото */
.sfeed__cap {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    padding: 36px 14px 13px;
    font-size: 14px;
    line-height: 1.35;
    font-weight: 500;
    color: #fff;
    background: linear-gradient(0deg, rgba(0, 0, 0, .78) 0%, rgba(0, 0, 0, 0) 100%);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 0 1px 6px rgba(0, 0, 0, .35);
}

/* карточка без фото (например, пост Threads): цветная плитка с текстом */
.sfeed__item--text,
.sfeed__item:not(:has(img)) {
    background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #38bdf8 100%);
}

.sfeed__item[data-platform="threads"]:not(:has(img)) {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 60%, #334155 100%);
}

.sfeed__item--text .sfeed__cap,
.sfeed__item:not(:has(img)) .sfeed__cap {
    top: 0;
    padding: 44px 18px 18px;
    background: none;
    font-size: 17px;
    font-weight: 600;
    -webkit-line-clamp: 8;
    text-shadow: none;
    display: -webkit-box;
}

/* метка площадки */
.sfeed__item::after {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
    color: #fff;
    background: rgba(15, 23, 42, .72);
    backdrop-filter: blur(4px);
}

.sfeed__item[data-platform="instagram"]::after {
    content: "Instagram";
    background: linear-gradient(45deg, #f09433 0%, #dc2743 55%, #bc1888 100%);
}

.sfeed__item[data-platform="threads"]::after {
    content: "Threads";
    background: #000;
}

/* ---------- слайдер ---------- */
.sfeed[data-layout="slider"] .sfeed__viewport { position: relative; }

.sfeed[data-layout="slider"] .sfeed__list {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px 2px 10px;
}

.sfeed[data-layout="slider"] .sfeed__list::-webkit-scrollbar { display: none; }

.sfeed[data-layout="slider"] .sfeed__item {
    flex: 0 0 calc((100% - (var(--cols) - 1) * var(--gap)) / var(--cols));
    scroll-snap-align: start;
}

.sfeed__nav {
    position: absolute;
    top: 50%;
    z-index: 5;
    width: 42px;
    height: 42px;
    margin-top: -26px;
    border: 0;
    border-radius: 50%;
    background: #fff;
    color: #0f172a;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(15, 23, 42, .28);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .2s, transform .2s;
}

.sfeed__nav:hover { transform: scale(1.08); }
.sfeed__nav[disabled] { opacity: 0; pointer-events: none; }
.sfeed__nav--prev { left: -14px; }
.sfeed__nav--next { right: -14px; }

/* ---------- один пост ---------- */
.sfeed[data-layout="single"] .sfeed__list { grid-template-columns: minmax(0, 420px); justify-content: center; }
.sfeed[data-layout="single"] .sfeed__item { aspect-ratio: 4 / 5; }

/* ---------- пост по ссылке (прямо в тексте) ---------- */
.sfeed[data-layout="post"] { max-width: 540px; margin: 24px auto; }
.sfeed[data-layout="post"] .sfeed__list { grid-template-columns: minmax(0, 1fr); }
.sfeed[data-layout="post"] .sfeed__item { aspect-ratio: auto; min-height: 150px; }
.sfpost { max-width: 540px; margin: 0 auto; }
.sfpost__frame {
    display: block; width: 100%; height: 640px; border: 1px solid #e2e8f0;
    border-radius: 6px; background: #fff;
}
.sfpost__link { display: block; margin-top: 6px; font-size: 13px; color: #64748b !important; text-align: right; text-decoration: none !important; }
.sfpost__link:hover { color: #2563eb !important; }

/* ---------- «показать ещё» ---------- */
.sfeed__more {
    display: block;
    margin: 16px auto 0;
    padding: 10px 26px;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    background: #fff;
    color: #0f172a;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: .15s;
}

.sfeed__more:hover { border-color: #2563eb; color: #2563eb; }
.sfeed__item[hidden] { display: none !important; }

/* ---------- окно просмотра ---------- */
.sfbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(2, 6, 23, .82);
    backdrop-filter: blur(3px);
}

.sfbox.is-open { display: flex; animation: sfbox-in .18s ease; }
@keyframes sfbox-in { from { opacity: 0; } to { opacity: 1; } }

.sfbox__dialog {
    position: relative;
    width: min(540px, 100%);
    max-height: calc(100vh - 32px);
    display: flex;
    flex-direction: column;
    border-radius: 18px;
    background: #fff;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, .5);
}

.sfbox__body {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    background: #f8fafc;
}

.sfbox__frame {
    display: block;
    width: 100%;
    height: min(720px, calc(100vh - 150px));
    min-height: 420px;
    border: 0;
    background: #fff;
}

.sfbox__fallback {
    padding: 58px 20px 22px;
    color: #334155;
    font-size: 15px;
    line-height: 1.5;
}

.sfbox__fallback img { display: block; width: 100%; height: auto; border-radius: 12px; margin-bottom: 14px; }
.sfbox__fallback p { margin: 0 0 8px; white-space: pre-line; }
.sfbox__hint { font-size: 12px; color: #64748b; padding: 0 20px 14px; }

.sfbox__bar {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

.sfbox__open {
    display: inline-block;
    padding: 9px 18px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 700;
    color: #fff !important;
    text-decoration: none !important;
    background: #1e40af;
}

.sfbox__open:hover { background: #1d4ed8; }
.sfbox__count { font-size: 13px; color: #64748b; }

.sfbox__close,
.sfbox__arrow {
    position: absolute;
    z-index: 3;
    border: 0;
    cursor: pointer;
    color: #0f172a;
    background: rgba(255, 255, 255, .95);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 22px;
    line-height: 1;
    box-shadow: 0 4px 16px rgba(15, 23, 42, .3);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sfbox__close { top: 10px; right: 10px; }
.sfbox__arrow { top: 50%; margin-top: -20px; }
.sfbox__arrow--prev { left: max(8px, calc(50% - 320px)); }
.sfbox__arrow--next { right: max(8px, calc(50% - 320px)); }
.sfbox__arrow[hidden] { display: none; }

body.sfbox-lock { overflow: hidden; }

/* ---------- адаптив ---------- */
@media (max-width: 900px) {
    .sfeed[data-layout="grid"] { --cols: 2; }
    .sfeed[data-layout="slider"] { --cols: 2; }
    .sfeed__nav--prev { left: 4px; }
    .sfeed__nav--next { right: 4px; }
}

@media (max-width: 560px) {
    .sfeed[data-layout="slider"] { --cols: 1.25; }
    .sfeed__cap { font-size: 13px; }
    .sfeed__nav { display: none; }
    .sfbox { padding: 0; align-items: stretch; }
    .sfbox__dialog { width: 100%; max-height: none; border-radius: 0; }
    .sfbox__frame { height: calc(100vh - 130px); }
    .sfbox__arrow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    .sfeed__item, .sfeed__item img, .sfeed__nav { transition: none; }
    .sfeed[data-layout="slider"] .sfeed__list { scroll-behavior: auto; }
    .sfbox.is-open { animation: none; }
}
