/* ======================================================
   TELEGRAM CHANNEL READER  —  tg.css
   Стиль в духе Memphis Messenger (использует CSS-переменные темы)
   ====================================================== */

/* ── Sliding strip: two 50%-wide panes side by side ───────────────────── */
/* #chatMessages becomes the viewport that clips the 200%-wide strip.     */
#chatMessages:has(.tg-screens) {
    overflow: hidden !important;
    padding: 0 !important;
}

.tg-screens {
    display: flex;
    width: 200%;
    height: 100%;
    transform: translateX(0%) translateZ(0);
    will-change: transform;
}

.tg-screen {
    width: 50%;
    flex-shrink: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Anchor for the floating scroll-to-unread button below — it needs a
   positioned ancestor that stays put while #tgPostsArea (its scrolling
   sibling) scrolls underneath it. */
.tg-screen-posts {
    position: relative;
}

/* ── Scroll-to-unread FAB (bottom-right corner of the posts pane) ─────── */
.tg-scroll-fab {
    display: none; /* toggled to flex in JS once there's something to scroll */
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 6;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--m-surface);
    color: var(--m-dark);
    border: 2.5px solid var(--m-dark);
    box-shadow: 3px 3px 0 var(--m-dark);
    cursor: pointer;
    transition: transform .12s, box-shadow .12s, background .12s;
}
.tg-scroll-fab:hover {
    background: color-mix(in srgb, var(--m-teal, #2dd4bf) 15%, var(--m-surface));
}
.tg-scroll-fab:active {
    transform: translate(2px, 2px);
    box-shadow: 1px 1px 0 var(--m-dark);
}

.tg-scroll-fab-badge {
    display: none; /* toggled to flex in JS when there's an unread count */
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--m-teal, #2dd4bf);
    border: 2px solid var(--m-dark);
    color: var(--m-dark);
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
    box-shadow: 1.5px 1.5px 0 var(--m-dark);
}

/* ── Contacts screen (channel list, like the contacts list) ──────────── */
.tg-contacts-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: var(--m-surface);
}

/* ── Channel list ────────────────────────────────────── */
.tg-channel-list {
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 6px 0;
}

/* ── Back button in panel header (consistent with chess) ──── */
/* Стрелка — не юникод-символ "←", а CSS-«уголок» (border + rotate): у
   символа "←" в разных шрифтах/платформах разные внутренние отступы
   глифа, из-за чего он визуально не центрируется в кнопке даже при
   flex-центрировании самой кнопки. Геометрическая фигура центрируется
   предсказуемо в любом браузере. */
.tg-back-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    margin-right: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}
.tg-back-btn:hover { opacity: .7; }
.tg-back-btn::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    transform: rotate(135deg);
    /* После поворота геометрический центр рамки визуально смещён левее
       острия стрелки — небольшой сдвиг вправо компенсирует это на глаз. */
    margin-left: 3px;
}

/* Мобильный топ-бар открытого канала: ← слева, название по центру, а общий
   крестик закрытия панели (.back-btn) — справа. .back-btn — не наш элемент,
   его вставляет ui.js::ensureBackButton() ПЕРЕД тем, что рендерит tg.js
   (см. setPanelHeader), поэтому в DOM-порядке он всегда идёт первым, т.е.
   слева. Явный flex-order переставляет визуальный порядок без изменения
   DOM. :has(.tg-back-btn) держит это правило строго в рамках экрана постов
   Telegram — в остальных разделах (погода, крипта, обычный чат и т.п.),
   где такой кнопки нет, .back-btn остаётся как есть, слева. */
@media (max-width: 768px) {
    #chatHeader:has(.tg-back-btn) .tg-back-btn {
        order: 1;
        width: 30px;
        height: 30px;
        min-width: 30px;
        margin-right: 8px;
    }
    #chatHeader:has(.tg-back-btn) .tg-back-btn::before {
        width: 11px;
        height: 11px;
        border-width: 0 2.5px 2.5px 0;
        margin-left: 4px;
    }
    #chatHeader:has(.tg-back-btn) .tg-posts-header-title {
        order: 2;
        flex: 1;
        min-width: 0;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        padding: 0 8px;
    }
    #chatHeader:has(.tg-back-btn) .back-btn {
        order: 3;
        margin-right: 0;
        margin-left: 12px;
    }
}

/* Единый видимый счётчик "до следующего фонового обновления" в шапке
   списка каналов (см. _tgStartGlobalTimer/_tgRenderGlobalTimer в tg.js) —
   один на весь список, а не по счётчику на каждый канал. */
.tg-global-timer {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    opacity: .5;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ⟳ "refresh all" button in the channel-list header */
.tg-header-refresh-btn {
    margin-left: 10px;
    background: transparent;
    border: 2px solid currentColor;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    color: inherit;
    opacity: .9;
    transition: background .12s, opacity .12s;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.tg-header-refresh-btn:hover   { opacity: 1; background: color-mix(in srgb, currentColor 15%, transparent); }
.tg-header-refresh-btn:disabled { opacity: .5; cursor: wait; }

.tg-empty-list {
    padding: 20px 16px;
    font-size: 12px;
    font-weight: 700;
    opacity: .5;
    text-align: center;
    line-height: 1.5;
}

.tg-channel-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    cursor: pointer;
    border-bottom: 1px solid color-mix(in srgb, var(--m-dark) 10%, transparent);
    transition: background .12s;
    position: relative;
}
.tg-channel-item:hover { background: color-mix(in srgb, var(--m-teal,#2dd4bf) 12%, transparent); }
.tg-channel-item:active { background: color-mix(in srgb, var(--m-teal,#2dd4bf) 20%, transparent); }

.tg-channel-avatar {
    position: relative;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    background: var(--m-yellow, #ffe066);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 900;
    color: var(--m-dark);
    flex-shrink: 0;
    overflow: hidden;
}

/* Real channel photo, when available, sits above the initials fallback and
   fully covers it; onerror removes the <img>, revealing the initials.
   Explicit z-index is required here: the <img> is inserted via prepend()
   (i.e. BEFORE the fallback <span> in DOM order), and without it, two
   positioned siblings at the same stacking level paint in DOM order — the
   later fallback <span> would then paint OVER the photo instead of behind it. */
.tg-channel-avatar img {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.tg-channel-avatar__fallback {
    position: relative;
    z-index: 0;
    line-height: 1;
}

.tg-channel-info {
    flex: 1;
    min-width: 0;
}
.tg-channel-name {
    font-size: 13px;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--m-dark);
}
.tg-channel-handle {
    font-size: 11px;
    font-weight: 600;
    opacity: .55;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tg-channel-preview {
    font-size: 11px;
    font-weight: 500;
    opacity: .45;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
    color: var(--m-dark);
}

.tg-remove-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--m-dark);
    opacity: .35;
    padding: 4px 6px;
    border-radius: 6px;
    transition: opacity .12s, background .12s;
    flex-shrink: 0;
}
.tg-remove-btn:hover { opacity: 1; background: #ef444422; }

/* ── Add form ────────────────────────────────────────── */
.tg-add-form {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--m-dark);
    flex-shrink: 0;
}

.tg-add-input {
    flex: 1;
    min-width: 0;
    border: none;
    border-right: 1.5px solid var(--m-dark);
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 700;
    background: var(--m-surface);
    color: var(--m-dark);
    outline: none;
    font-family: inherit;
}
.tg-add-input::placeholder { opacity: .45; }
.tg-add-input:focus { background: color-mix(in srgb, var(--m-teal,#2dd4bf) 10%, var(--m-surface)); }

.tg-add-btn {
    background: var(--m-teal, #2dd4bf);
    color: var(--m-dark);
    border: none;
    padding: 10px 10px;
    font-size: 11px;
    font-weight: 900;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    transition: background .12s, transform .1s;
}
.tg-add-btn:hover { background: var(--m-yellow, #ffe066); }
.tg-add-btn:active { transform: scale(.96); }
.tg-add-btn:disabled { opacity: .5; cursor: wait; }

/* ── Posts area ──────────────────────────────────────── */
.tg-posts-area {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    background: var(--m-surface2);
    background-image: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 20px,
        rgba(0, 0, 0, .03) 20px,
        rgba(0, 0, 0, .03) 21px
    );
    display: flex;
    flex-direction: column;
}

/* Posts header — той же структуры и классов, что и элемент списка каналов
   (.tg-channel-avatar/.tg-channel-info/.tg-channel-name/.tg-channel-handle/
   .tg-channel-preview, см. выше), чтобы шапка открытого канала выглядела
   как строка в списке: аватарка + название + @handle, а последняя строка,
   которая в списке — превью последнего поста, здесь занята счётчиком
   постов, источником и статусом кеша. Только .tg-posts-header — не кликабелен
   и прилипает к верху, остальное — переиспользованные стили. */
.tg-posts-header {
    position: sticky;
    top: 0;
    z-index: 5;
    background: var(--m-surface);
    border-bottom: 2.5px solid var(--m-dark);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    flex-shrink: 0;
}

.tg-posts-cached,
.tg-posts-fresh {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .3px;
    padding: 2px 8px;
    border-radius: 20px;
    border: 1.5px solid var(--m-dark);
}
.tg-posts-cached {
    opacity: .55;
    background: transparent;
}
.tg-posts-fresh {
    background: var(--m-teal, #2dd4bf);
    color: var(--m-dark);
    border-color: var(--m-dark);
}

/* "· via t.me" — источник постов, полезно на десктопе, но на мобилке
   шапка и так тесная (аватарка + бейдж + кнопка refresh на одной строке
   с мета-текстом), поэтому на узких экранах эту часть прячем (см. media
   query max-width:600px ниже), оставляя только "@channel · N posts". */
.tg-posts-via { }

.tg-refresh-btn {
    margin-left: auto;
    background: transparent;
    border: 1.5px solid var(--m-dark);
    border-radius: 50%;
    width: 26px;
    height: 26px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    color: var(--m-dark);
    transition: background .12s, transform .15s;
    flex-shrink: 0;
}
.tg-refresh-btn:hover { background: color-mix(in srgb, var(--m-teal,#2dd4bf) 20%, transparent); }
.tg-refresh-btn:disabled { opacity: .5; cursor: wait; }
.tg-refresh-btn--spinning { animation: tg-spin .8s linear infinite; }

@keyframes tg-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.tg-posts-list {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ── Date grouping ("Сегодня" / "Вчера" / "13 августа") ───────────────────
   Тот же приём, что и в чате (chat-date-separators.js/css): каждый день —
   свой .tg-date-group (flex column, тот же gap, что у .tg-posts-list, чтобы
   отступы между постами не менялись), а внутри — sticky-таблетка. Она
   ограничена рамками СВОЕЙ группы, поэтому при смене дня корректно
   выталкивается следующей, а не остаётся висеть поверх чужих постов.

   В отличие от чата таблетка здесь непрозрачная и с рамкой/тенью — под
   стать общему "стикерному" стилю модуля (см. .tg-unread-divider выше),
   а не полупрозрачная: фон .tg-posts-area — с диагональным узором, на
   котором блюр читается хуже, чем плашка сплошным цветом.

   --tg-posts-header-h выставляется в JS (_tgSyncPostsHeaderOffset) под
   реальную высоту .tg-posts-header — она не фиксирована (меняется в
   адаптиве), поэтому подобрать смещение статикой в CSS нельзя. */
.tg-date-group {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tg-date-sep {
    position: sticky;
    top: var(--tg-posts-header-h, 64px);
    z-index: 4; /* ниже .tg-posts-header (z-index:5), чтобы не перекрывать её */
    display: flex;
    justify-content: center;
    margin-bottom: -2px; /* компенсирует gap группы перед первым постом дня */
    pointer-events: none;

    opacity: 0;
    transform: translateY(-6px);
    transition: opacity .25s ease, transform .25s ease;
}

/* Пока лента постов скроллится — таблетки видны; после паузы прячутся
   (см. _tgBindPostsScrollFade в tg.js, класс ставится на #tgPostsArea). */
#tgPostsArea.tg-scrolling .tg-date-sep {
    opacity: 1;
    transform: translateY(0);
}

.tg-date-sep span {
    display: inline-block;
    padding: 4px 14px;
    border-radius: 50px;
    background: var(--m-surface);
    border: 1.5px solid var(--m-dark);
    box-shadow: 1.5px 1.5px 0 var(--m-dark);
    color: var(--m-dark);
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}

.tg-no-posts, .tg-error-msg {
    padding: 32px 24px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    opacity: .6;
    line-height: 1.6;
}
.tg-error-msg { color: #ef4444; opacity: 1; }

/* ── Unread divider ("Новые посты") ───────────────────── */
.tg-unread-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 0;
}
.tg-unread-divider::before,
.tg-unread-divider::after {
    content: '';
    flex: 1;
    height: 2px;
    background: var(--m-teal, #2dd4bf);
    border-radius: 2px;
}
.tg-unread-divider span {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--m-dark);
    background: var(--m-yellow, #ffe066);
    border: 1.5px solid var(--m-dark);
    border-radius: 20px;
    padding: 3px 10px;
    white-space: nowrap;
    box-shadow: 1.5px 1.5px 0 var(--m-dark);
}

/* ── Post bubble ─────────────────────────────────────── */
.tg-post {
    border-radius: 18px 18px 18px 4px; /* small tail corner, like an incoming chat bubble */
    overflow: hidden;
    background: var(--m-surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .10);
}

.tg-post__body {
    padding: 14px 16px;
}

/* ── Forward label ("Переслано от …") ─────────────────── */
.tg-post__forward {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 8px;
    font-size: 11px;
    font-weight: 700;
    opacity: .6;
    text-transform: uppercase;
    letter-spacing: .3px;
    color: var(--m-dark);
}
.tg-post__forward a {
    color: var(--m-teal, #2dd4bf);
    text-decoration: none;
    font-weight: 800;
}
.tg-post__forward a:hover { text-decoration: underline; }

/* ── Photo/video gallery ───────────────────────────────── */
.tg-post__media {
    margin-bottom: 8px;
    border-radius: 12px;
    overflow: hidden;
}
.tg-post__media--grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px;
    background: var(--m-dark);
}
.tg-post__media-item {
    position: relative;
    min-width: 0;   /* без этого grid/flex-ячейка растягивается под "родной"
                       размер фото/видео вместо того, чтобы подстроить его
                       под себя через object-fit — именно из-за этого
                       картинки/видео "вылезали" за рамку поста */
    overflow: hidden; /* доп. страховка на случай, если содержимое всё же
                          окажется больше отведённой ячейки */
    background: var(--m-surface2, #f0f0f0);
    line-height: 0;
}
.tg-post__media-item img,
.tg-post__media-item video {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: 420px;
    object-fit: cover;
    cursor: pointer;
}
.tg-post__media-item video {
    /* Разумный дефолт, пока не пришли реальные пропорции: с ним видео до
       загрузки постера/метаданных выглядит намного ближе к правде, чем
       родной браузерный бокс 2:1. Как только постер подгрузится, tg.js
       (_tgLoadPostMedia) переопределяет это инлайн-стилем под реальные
       пропорции конкретного ролика. */
    aspect-ratio: 16 / 9;
}
.tg-post__media--grid .tg-post__media-item img,
.tg-post__media--grid .tg-post__media-item video {
    max-height: 220px;
    cursor: default;
}

/* Round video message ("video circle") — фиксированный размер 220px не
   должен превышать доступную ширину карточки на узких экранах, поэтому
   ограничиваем его через min(), а не жёстким значением. */
.tg-post__media-item--round {
    display: flex;
    justify-content: center;
    padding: 8px 0;
    overflow: visible; /* сам кружок не должен обрезаться собственной рамкой */
    background: transparent;
}
.tg-post__media-item--round video {
    width: min(220px, 100%);
    aspect-ratio: 1 / 1;
    height: auto;
    max-width: 100%;
    max-height: none;
    border-radius: 50%;
    object-fit: cover;
    border: 2.5px solid var(--m-dark);
}

/* GIF (looping muted video) — no controls, plays inline */
.tg-post__media-item--gif video {
    cursor: default;
}

.tg-post__media-duration {
    position: absolute;
    right: 8px;
    bottom: 8px;
    padding: 2px 7px;
    border-radius: 20px;
    background: rgba(0, 0, 0, .65);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .3px;
    pointer-events: none;
}

/* Видео, которое Telegram вообще не встраивает в /s/-страницу (файл больше
   ~15МБ — лимит их лёгкого веб-просмотра, см. tg_extract_media() в
   telegram.php) — карточка-заглушка со ссылкой "открыть в Telegram" вместо
   того, чтобы молча ничего не показывать. */
.tg-post__media-item--unavailable {
    position: relative;
    min-height: 140px;
}
.tg-post__media-unavailable {
    display: flex;
    align-items: flex-end;
    width: 100%;
    height: 100%;
    min-height: 140px;
    text-decoration: none;
    background: var(--m-dark);
    position: relative;
}
.tg-post__media-unavailable img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: .35;
    filter: blur(1px);
}
.tg-post__media-unavailable__badge {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    padding: 10px 14px;
    box-sizing: border-box;
    background: linear-gradient(0deg, rgba(0,0,0,.75), rgba(0,0,0,0));
    color: #fff;
    font-size: 12.5px;
    font-weight: 700;
    line-height: 1.4;
}

/* Media (photo/video) is fetched through the backend proxy ONLY when the
   person explicitly taps the placeholder button — see .tg-media-load-btn
   below and _tgLoadOneMedia() in tg.js. Nothing is downloaded automatically. */
.tg-media-unloaded {
    min-height: 120px;
    background: var(--m-surface2, #f0f0f0);
}
/* .tg-media-loading — тот же элемент, но уже в процессе фетча (после клика
   по кнопке ниже, пока не пришёл ответ прокси) — шиммер именно здесь,
   а не в состоянии "ещё не запрошено" (.tg-media-unloaded), чтобы не
   создавать ложное впечатление, будто что-то грузится само по себе. */
.tg-media-loading {
    min-height: 120px;
    background: linear-gradient(
        100deg,
        var(--m-surface2, #f0f0f0) 30%,
        color-mix(in srgb, var(--m-teal, #2dd4bf) 18%, var(--m-surface2, #f0f0f0)) 50%,
        var(--m-surface2, #f0f0f0) 70%
    );
    background-size: 200% 100%;
    animation: tg-media-shimmer 1.3s ease-in-out infinite;
}
@keyframes tg-media-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Кнопка-плейсхолдер "показать фото/видео" — по центру ещё не загруженного
   элемента; сам .tg-post__media-item уже position:relative (см. выше), так
   что позиционируем кнопку абсолютно поверх него. Для случая --unavailable
   кнопка рендерится СОСЕДОМ <a>, а не внутри неё, именно чтобы клик по
   кнопке не улетал по внешней ссылке на t.me — z-index ставит её поверх. */
.tg-media-load-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border: 2px solid var(--m-dark);
    border-radius: 20px;
    background: var(--m-yellow, #fbbf24);
    color: var(--m-dark);
    font-size: 12.5px;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 2px 2px 0 var(--m-dark);
    transition: transform .1s;
}
.tg-media-load-btn:hover  { transform: translate(-50%, -50%) scale(1.04); }
.tg-media-load-btn:active { transform: translate(-50%, -50%) scale(0.97); }
.tg-media-load-btn__icon { font-size: 14px; line-height: 1; }

.tg-post__media-item--failed {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 72px;
    padding: 16px;
    background: var(--m-surface2, #f0f0f0);
}
.tg-post__media-fallback {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .3px;
    opacity: .5;
}

/* ── Post text (sanitized HTML from the backend) ──────── */
.tg-post__text {
    font-size: var(--content-font-size, 13px);
    font-weight: 500;
    line-height: 1.5;
    margin: 0 0 8px;
    color: var(--m-dark);
    opacity: .85;
    white-space: pre-wrap;
    word-break: break-word;
}
.tg-post__text a {
    color: var(--m-teal, #2dd4bf);
    text-decoration: none;
    word-break: break-word;
}
.tg-post__text a:hover { text-decoration: underline; }
.tg-post__text .tg-spoiler {
    background: var(--m-dark);
    color: transparent;
    border-radius: 4px;
    cursor: pointer;
    transition: color .15s, background .15s;
}
.tg-post__text .tg-spoiler:hover,
.tg-post__text .tg-spoiler:active {
    background: transparent;
    color: inherit;
}

/* ── Quote block (Telegram's "Quote" text formatting) ─── */
.tg-post__text .tg-quote {
    display: block;
    margin: 6px 0;
    padding: 6px 10px;
    border-left: 3px solid var(--m-teal, #2dd4bf);
    background: var(--m-surface2, #f0f0f0);
    border-radius: 0 8px 8px 0;
    font-style: italic;
    opacity: .9;
}
.tg-post__text .tg-quote:first-child { margin-top: 0; }
.tg-post__text .tg-quote:last-child { margin-bottom: 0; }

/* Reply-quote variant ("В ответ на…") — always the first thing in the post;
   slightly more muted/compact than an in-text <blockquote>. */
.tg-post__text .tg-quote--reply {
    font-size: calc(var(--content-font-size, 13px) - 1px);
    opacity: .75;
}
.tg-post__text .tg-quote--reply::before {
    content: '↩ ';
    font-style: normal;
}

/* ── Link preview card (text-only — no thumbnail) ─────── */
.tg-post__preview {
    display: block;
    margin: 4px 0 8px;
    padding: 10px 12px;
    border: 1.5px solid var(--m-dark);
    border-left: 4px solid var(--m-teal, #2dd4bf);
    border-radius: 10px;
    background: var(--m-surface2, #f0f0f0);
    text-decoration: none;
    color: var(--m-dark);
    transition: background .12s;
}
.tg-post__preview:hover {
    background: color-mix(in srgb, var(--m-teal, #2dd4bf) 15%, var(--m-surface2, #f0f0f0));
}
.tg-post__preview-site {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--m-teal, #2dd4bf);
    margin-bottom: 2px;
}
.tg-post__preview-title {
    font-size: 12px;
    font-weight: 800;
    line-height: 1.35;
    margin-bottom: 2px;
}
.tg-post__preview-desc {
    font-size: 11px;
    font-weight: 500;
    opacity: .65;
    line-height: 1.4;
}

.tg-post__meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.tg-post__date {
    font-size: 11px;
    font-weight: 700;
    opacity: .45;
    text-transform: uppercase;
    letter-spacing: .3px;
}

.tg-post__link {
    font-size: 11px;
    font-weight: 800;
    color: var(--m-teal, #2dd4bf);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: .3px;
    border: 1.5px solid var(--m-teal, #2dd4bf);
    border-radius: 20px;
    padding: 2px 9px;
    transition: background .12s, color .12s;
}
.tg-post__link:hover {
    background: var(--m-teal, #2dd4bf);
    color: var(--m-dark);
}

/* ── Loader dots ─────────────────────────────────────── */
.tg-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 60px 0;
    flex: 1;
}
.tg-loader span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--m-teal, #2dd4bf);
    border: 2px solid var(--m-dark);
    animation: tg-bounce 1.1s ease-in-out infinite;
}
.tg-loader span:nth-child(2) { animation-delay: .18s; }
.tg-loader span:nth-child(3) { animation-delay: .36s; }

@keyframes tg-bounce {
    0%, 80%, 100% { transform: scale(1);   opacity: 1;  }
    40%            { transform: scale(1.5); opacity: .7; }
}

/* ── Mobile tweaks ─────────────────────────────────────── */
@media (max-width: 600px) {
    .tg-channel-item { padding: 10px 14px; }
    .tg-posts-header { padding: 10px 14px; }
    .tg-posts-list { padding: 10px; }
    .tg-posts-via { display: none; }
}

/* ── Per-item fetch status ────────────────────────────── */

/* Avatar ring states */
.tg-channel-avatar.tg-av--fetching {
    box-shadow: 0 0 0 2.5px var(--m-dark), 0 0 0 5px var(--m-teal, #2dd4bf);
    animation: tg-av-pulse 1s ease-in-out infinite;
}
.tg-channel-avatar.tg-av--done {
    box-shadow: 0 0 0 2.5px var(--m-dark), 0 0 0 5px #22c55e;
    animation: tg-av-flash .4s ease forwards;
}
.tg-channel-avatar.tg-av--error {
    box-shadow: 0 0 0 2.5px var(--m-dark), 0 0 0 5px #ef4444;
}

@keyframes tg-av-pulse {
    0%, 100% { box-shadow: 0 0 0 2.5px var(--m-dark), 0 0 0 4px var(--m-teal, #2dd4bf); }
    50%       { box-shadow: 0 0 0 2.5px var(--m-dark), 0 0 0 7px color-mix(in srgb, var(--m-teal,#2dd4bf) 40%, transparent); }
}
@keyframes tg-av-flash {
    0%   { box-shadow: 0 0 0 2.5px var(--m-dark), 0 0 0 7px #22c55e; }
    100% { box-shadow: none; }
}

/* Inline status label (replaces @handle during fetch) */
.tg-fetch-label {
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--m-teal, #2dd4bf);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.tg-fetch-label::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--m-teal, #2dd4bf);
    animation: tg-dot-blink .8s ease-in-out infinite;
}
.tg-fetch-label--err {
    color: #ef4444;
}
.tg-fetch-label--err::before {
    background: #ef4444;
    animation: none;
}

@keyframes tg-dot-blink {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .3; transform: scale(.6); }
}

/* ── Unread badge ─────────────────────────────────────── */
.tg-unread-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--m-teal, #2dd4bf);
    border: 2px solid var(--m-dark);
    color: var(--m-dark);
    font-size: 10px;
    font-weight: 900;
    line-height: 16px;
    text-align: center;
    flex-shrink: 0;
    box-shadow: 1.5px 1.5px 0 var(--m-dark);
    animation: tg-badge-pop .2s ease;
}

/* ── Unread badge on the nav "circle-btn" (top-buttons row) ──────────────
   Reuses .requests-badge (position/colors) from style.css, but that one is
   sized for a single "!" glyph — this widens it into a pill so 2-3 digit
   unread counts ("42", "99+") don't get clipped, and adds the same pop-in
   animation as the in-list badges above for a consistent feel. */
.tg-nav-badge {
    min-width: 20px;
    width: auto;
    padding: 0 5px;
    border-radius: 10px;
    font-size: 10px;
    line-height: 16px;
    animation: tg-badge-pop .2s ease;
}

@keyframes tg-badge-pop {
    0%   { transform: scale(0.5); opacity: 0; }
    70%  { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* ── Hide chat input bar in tg-mode ──────────────────── */
.tg-mode .chat-input {
    display: none !important;
}

/* ======================================================
   DESKTOP: posts open as their OWN column next to the
   normal chat-panel, instead of sliding over the list.
   See _tgOpenDesktopPosts()/tgCloseDesktopPosts() in tg.js
   — it's the same #tgScreenPosts node (with #tgPostsArea,
   scroll-fab, unread-observer and all) just relocated here,
   not a separate render path. Mobile/tablet are untouched:
   they keep using the sliding strip above.
   ====================================================== */
.tg-desktop-posts-panel { display: none; }

@media (min-width: 1025px) {
    /* Same fixed size as .chat-panel at this breakpoint (see style.css) so
       the two columns line up exactly. */
    .tg-desktop-posts-panel {
        flex: 0 0 600px;
        width: 600px;
        min-width: 600px;
        max-width: 600px;
        height: 100vh;
        z-index: 1;
        flex-direction: column;
        overflow: hidden;
        background: var(--m-surface2);
        background-image: repeating-linear-gradient(
            45deg,
            transparent, transparent 20px,
            rgba(0,0,0,.03) 20px, rgba(0,0,0,.03) 21px
        );
        border-left: 3px solid var(--m-dark);
    }
    .tg-desktop-posts-panel.tg-open { display: flex; }

    /* While #tgScreenPosts lives here (not in .tg-screens), it must fill
       the column instead of the 50%-of-strip width it has on mobile. */
    .tg-desktop-posts-panel .tg-screen-posts {
        width: 100%;
        height: auto;
        flex: 1 1 auto;
        min-height: 0;
    }
}

.tg-desktop-posts-header {
    background: var(--m-dark);
    padding: 0 20px;
    height: 60px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}
.tg-desktop-posts-header::after {
    content: '';
    position: absolute;
    bottom: 0; left: 0; right: 0;
    height: 4px;
    background: repeating-linear-gradient(
        90deg,
        var(--m-teal)   0, var(--m-teal)   12px,
        var(--m-orange) 12px, var(--m-orange) 24px,
        var(--m-lime)   24px, var(--m-lime)   36px
    );
}
.tg-desktop-posts-title {
    font-weight: 900;
    font-size: 14px;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--m-surface);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tg-desktop-posts-close {
    margin-left: auto;
    border: 2px solid var(--m-orange);
    border-radius: 50px;
    background: transparent;
    color: var(--m-orange);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 900;
    padding: 4px 12px;
    flex-shrink: 0;
    transition: background .15s, color .15s;
}
.tg-desktop-posts-close:hover { background: var(--m-orange); color: #fff; }