/* ============================================================
   LIQUID GLASS (Telegram X Premium) — стили скопированы и
   адаптированы из f.html (приме интерфейса и функций).
   Включается классом .liquid-glass на <html> (настройка
   "Эффект Liquid Glass") или темой data-theme="telegram".
   ============================================================ */

:root {
    --lg-bg-app: #0e1621;
    --lg-bg-panel: #17212b;
    --lg-bg-glass: rgba(23, 33, 43, 0.65);
    --lg-bg-glass-border: rgba(255, 255, 255, 0.1);
    --lg-accent: #5288c1;
    --lg-ease: cubic-bezier(.32, .72, 0, 1);
}

/* ---------- Радиальные градиенты фона (как в f.html) ---------- */
/* Фон приложения + полупрозрачность панелей включаются просто классом
   .liquid-glass на <html> (по умолчанию, настройка "Эффект Liquid Glass").
   Вариант ".full" — форсированный режим с радиальными градиентами даже
   поверх установленных обоев чата. */
html.liquid-glass body {
    background-color: var(--lg-bg-app);
}

html.liquid-glass.full body {
    background-image:
        radial-gradient(circle at 15% 50%, rgba(82, 136, 193, 0.08), transparent 40%),
        radial-gradient(circle at 85% 30%, rgba(122, 92, 255, 0.08), transparent 40%) !important;
    background-attachment: fixed;
}

/* ---------- Стеклянные панели ---------- */
html.liquid-glass .sidebar,
html.liquid-glass .chat-header,
html.liquid-glass .chat-input-area,
html.liquid-glass .chat-list-panel,
html.liquid-glass .main-header {
    background: var(--lg-bg-glass) !important;
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    will-change: transform; /* backdrop-filter не должен ронять FPS */
}

/* Шапка списка чатов на мобильном (chatHeader) тоже становится стеклом */
html.liquid-glass #chatHeader,
html.liquid-glass .mobile-chat-header {
    background: var(--lg-bg-glass) !important;
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
}

html.liquid-glass .chat-header,
html.liquid-glass .chat-input-area {
    border-color: rgba(255, 255, 255, 0.05) !important;
}

html.liquid-glass .messages-container {
    background-image: radial-gradient(circle at 50% 0%, rgba(82, 136, 193, 0.05), transparent 50%);
}

/* Плавающая капсула нижней навигации (glass-капсула из f.html) */
html.liquid-glass .premium-bottom-nav {
    background: var(--lg-bg-glass);
    backdrop-filter: blur(32px) saturate(180%);
    -webkit-backdrop-filter: blur(32px) saturate(180%);
    border: 1px solid var(--lg-bg-glass-border);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

/* ============================================================
   МОБИЛЬНЫЙ РЕЖИМ — точь-в-точь структура f.html:
   один экран = список чатов (sidebar на весь экран), диалог
   выезжает поверх справа налево с пружинной кривой (.32,.72,0,1)
   и уезжает обратно при закрытии (translateX(100%)).
   ============================================================ */
@media (max-width: 768px) {
    /* плавный «выезд/уезд» как в f.html (chat.style.transition) */
    .main-screen .chat-area {
        transition: transform 0.35s cubic-bezier(.32, .72, 0, 1) !important;
        will-change: transform;
    }

    /* во время свайпа-жеста анимацию глушим — чат следует за пальцем */
    .main-screen.premium-swiping .chat-area {
        transition: none !important;
    }

    /* нижний бар не должен перекрывать поле ввода в диалоге */
    .premium-bottom-nav {
        bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        height: 58px;
    }
}

/* ---------- Поле ввода: овальное серое, без внешней обводки ----------
   Структура по образцу f.html:
   input-wrapper (овал): смайлик -> textarea -> скрепка;
   динамическая синяя круглая кнопка (микрофон/самолётик) — снаружи справа. */
html.liquid-glass .message-input-wrapper {
    background: rgba(255, 255, 255, 0.06) !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 22px;
    align-items: flex-end;
    min-height: 44px;
    max-height: 120px;
    padding: 4px 12px;
}

html.liquid-glass .message-input-wrapper:focus-within {
    border: none !important;
    box-shadow: none !important;
}

html.liquid-glass .message-input-wrapper .emoji-btn,
html.liquid-glass .message-input-wrapper .attach-btn {
    color: var(--text-muted);
    margin-bottom: 4px;
    transition: color 0.2s;
}

html.liquid-glass .message-input-wrapper .emoji-btn:active,
html.liquid-glass .message-input-wrapper .attach-btn:active {
    color: var(--lg-accent);
}

/* ---------- Динамическая кнопка действия (main-action-btn) ---------- */
.main-action-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
    border: none;
    box-shadow: 0 4px 12px rgba(82, 136, 193, 0.3);
    transition: transform 0.1s, background 0.2s;
    margin-bottom: 1px;
    position: relative;
}

.main-action-btn i {
    font-size: 17px;
    line-height: 1;
}

/* самолётик скрыт, пока поле пустое (показан микрофон) */
.main-action-send {
    display: none;
}

/* есть текст — показываем самолётик, прячем микрофон */
.main-action-btn.send-mode .main-action-send {
    display: inline-block;
}

.main-action-btn.send-mode #mainActionIcon {
    display: none;
}

/* долгое нажатие на микрофон (запись) — красная кнопка, как holding в f.html */
.main-action-btn.recording,
.main-action-btn.holding {
    background: var(--danger);
    box-shadow: 0 4px 12px rgba(224, 79, 79, 0.4);
    transform: scale(1.08);
}

/* ---------- Оверлей записи (rec-overlay из f.html) ---------- */
.premium-rec-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 250;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    pointer-events: none;
}

.premium-rec-overlay.on {
    display: flex;
}

.premium-rec-timer {
    font-size: 32px;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
}

.premium-rec-hint {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.2s;
}

.premium-rec-hint.cancel {
    color: var(--danger);
}

/* ============================================================
   ИСТОРИИ — точь-в-точь как в f.html (.stories / .story /
   .av-wrap / .lbl): панель на CSS-переменной --p, при свайпе
   вниз кружки плавно увеличиваются 32->64px, перекрытие
   (-18px -> +12px) исчезает, появляются подписи.
   !important перебивают старые inline-анимации scale().
   ============================================================ */
.stories-bar#storiesBar {
    --p: 0;
    position: static;
    flex: 0 0 auto;
    overflow: hidden;
    height: calc(54px + 46px * var(--p)) !important;
    padding: 0 !important;
    border: 0 !important;
    border-bottom: 1px solid rgba(255, 255, 255, .04) !important;
    background: transparent !important;
    transition: height .4s cubic-bezier(.32,.72,0,1) !important;
    flex-shrink: 0;
}

.stories-bar#storiesBar.dragging {
    transition: none !important;
}

.stories-bar#storiesBar .stories-scroll {
    display: flex;
    padding: 8px 14px !important;
    gap: 0 !important;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    height: 100%;
    align-items: flex-start !important;
}

.stories-bar#storiesBar .stories-scroll::-webkit-scrollbar {
    display: none;
}

.stories-bar#storiesBar .story-bubble {
    flex: 0 0 auto;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px !important;
    width: calc(32px + 32px * var(--p)) !important;
    margin-left: calc(-18px + 30px * var(--p)) !important;
    transform: none !important; /* отключаем старый scale-легаси */
    transition: width .4s cubic-bezier(.32,.72,0,1), margin-left .4s cubic-bezier(.32,.72,0,1) !important;
}

.stories-bar#storiesBar.dragging .story-bubble {
    transition: none !important;
}

.stories-bar#storiesBar .story-bubble:first-child {
    margin-left: 0 !important;
}

/* аватар-кружок = av-wrap из f.html */
.stories-bar#storiesBar .story-avatar-ring {
    position: relative;
    border-radius: 50%;
    padding: 2px !important;
    width: calc(32px + 32px * var(--p)) !important;
    height: calc(32px + 32px * var(--p)) !important;
    background: linear-gradient(135deg, #2b5278, #5288c1) !important;
    box-shadow: 0 0 0 2px var(--lg-bg-panel) !important;
    cursor: pointer;
    transition: width .4s cubic-bezier(.32,.72,0,1), height .4s cubic-bezier(.32,.72,0,1) !important;
}

.stories-bar#storiesBar.dragging .story-avatar-ring {
    transition: none !important;
}

/* просмотренные истории — серый градиент, как viewed в f.html */
.stories-bar#storiesBar .story-avatar-ring.viewed {
    background: linear-gradient(135deg, #2f3d4a, #1c2733) !important;
}

.stories-bar#storiesBar .story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: calc(12px + 10px * var(--p)) !important;
    color: #fff;
    border: none !important;
}

/* подпись = lbl из f.html: появляется при раскрытии */
.stories-bar#storiesBar .story-name {
    font-size: 11px !important;
    max-width: 100% !important;
    width: 100%;
    color: var(--text-muted) !important;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: var(--p) !important;
    height: calc(14px * var(--p)) !important;
    max-height: none !important;
    transform: none !important;
    transition: opacity .4s cubic-bezier(.32,.72,0,1), height .4s cubic-bezier(.32,.72,0,1) !important;
}

.stories-bar#storiesBar.dragging .story-name {
    transition: none !important;
}

/* «Мои истории» плюсик — виден только в раскрытом состоянии */
.stories-bar#storiesBar .story-plus {
    opacity: var(--p);
    bottom: auto;
    top: calc(32px + 32px * var(--p) - 12px);
    right: -2px;
    transition: opacity .4s cubic-bezier(.32,.72,0,1), top .4s cubic-bezier(.32,.72,0,1);
}

.stories-bar#storiesBar.dragging .story-plus {
    transition: none;
}

/* десктоп — всегда раскрыто (как было раньше) */
@media (min-width: 769px) {
    .stories-bar#storiesBar {
        --p: 1 !important;
    }
}

/* ---------- Архив: аккордеон (archive-wrapper из f.html) ---------- */
.archive-wrapper {
    overflow: hidden;
    height: 0;
    opacity: 0;
    transition: height 0.35s var(--lg-ease), margin 0.35s var(--lg-ease), opacity 0.35s ease;
    flex-shrink: 0;
}

.archive-wrapper.open {
    height: 84px;
    margin-bottom: 8px;
    opacity: 1;
}

.archive-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.04);
    margin: 0 16px 12px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    height: 72px;
}

.archive-item:active {
    background: rgba(255, 255, 255, 0.08);
}

.archive-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3a4a5c, #242f3d);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
    flex-shrink: 0;
}

.archive-info {
    flex: 1;
    min-width: 0;
}

.archive-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.archive-count {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---------- Плавающая нижняя навигация (bottom-nav из f.html) ---------- */
.premium-bottom-nav {
    position: fixed;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: 16px;
    max-width: 420px;
    margin: 0 auto;
    height: 64px;
    display: flex; /* видна всегда (мобильный и ПК), скрывается только в диалоге классом .hidden */
    justify-content: space-around;
    align-items: center;
    z-index: 900;
    border-radius: 24px;
    padding: 0 10px;
    transition: transform 0.35s var(--lg-ease), opacity 0.35s ease;
}

.premium-bottom-nav.visible {
    display: flex;
}

/* при переходе в диалог панель плавно уезжает вниз */
.premium-bottom-nav.hidden {
    transform: translateY(150%);
    opacity: 0;
    pointer-events: none;
}

.premium-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    gap: 4px;
    cursor: pointer;
    transition: color 0.2s;
    width: 70px;
    background: none;
    border: none;
    user-select: none;
    -webkit-user-select: none;
}

.premium-nav-btn i {
    font-size: 19px;
}

.premium-nav-btn.active {
    color: var(--accent);
}

/* Нижняя навигация видна и на ПК — размещается над сайдбаром слева */
@media (min-width: 769px) {
    .premium-bottom-nav {
        left: 24px;
        right: auto;
        width: 320px;
        max-width: 320px;
        margin: 0;
    }
}

/* ---------- Toast (из f.html) ---------- */
.premium-toast {
    position: fixed;
    left: 50%;
    bottom: 100px;
    transform: translateX(-50%) translateY(10px);
    background: rgba(30, 40, 50, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    font-size: 14px;
    padding: 12px 20px;
    border-radius: 24px;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    transition: opacity 0.2s, transform 0.2s;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.premium-toast.on {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   ДОДЕЛ: шапка cl-header + пикер эмодзи (точь-в-точь из f.html),
   мобильные правки старых стилей, премиум-анимация чата.
   ============================================================ */

/* ---------- Шапка cl-header из f.html (внутри #chatList) ---------- */
.cl-header {
    padding: 14px 16px 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.cl-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 0;
}

#premiumUserName {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.emoji-status {
    background: rgba(255, 255, 255, 0.08);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 16px;
    cursor: pointer;
    position: relative;
    transition: background 0.2s;
    line-height: 1.2;
    flex-shrink: 0;
}

.emoji-status:hover {
    background: rgba(255, 255, 255, 0.14);
}

.emoji-picker {
    position: absolute;
    top: 40px;
    left: 0;
    width: 220px;
    background: rgba(30, 40, 50, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    padding: 12px;
    display: none;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    z-index: 100;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.emoji-picker.on {
    display: grid;
}

.emoji-picker span {
    font-size: 24px;
    cursor: pointer;
    text-align: center;
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}

.header-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--accent);
}

/* ---------- Мобильный: старые «три полоски» скрываем, premium-шапка видна всегда ---------- */
@media (max-width: 768px) {
    .sidebar-header {
        display: none !important;
    }

    /* страховка: панель историй не может исчезнуть — минимум видимых кружков */
    .stories-bar#storiesBar {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        min-height: 54px;
    }
}

/* ---------- Истории: на мобильном НЕ форсируем раскрытие (аккордеон управляется --p) ---------- */
@media (max-width: 768px) {
    .stories-bar#storiesBar.expanded .story-avatar-ring {
        width: calc(32px + 32px * var(--p)) !important;
        height: calc(32px + 32px * var(--p)) !important;
    }

    .stories-bar#storiesBar.expanded .story-bubble {
        width: calc(32px + 32px * var(--p)) !important;
        margin-left: calc(-18px + 30px * var(--p)) !important;
    }

    .stories-bar#storiesBar.expanded .story-name {
        opacity: var(--p) !important;
        height: calc(14px * var(--p)) !important;
    }
}

/* ---------- Чат: точная анимация выхода из f.html (.chat) ---------- */
@media (max-width: 768px) {
    .chat-area {
        transition: transform 0.35s cubic-bezier(.32, .72, 0, 1) !important;
        will-change: transform;
    }

    html.liquid-glass .chat-area {
        background-image: radial-gradient(circle at 50% 0%, rgba(82, 136, 193, 0.05), transparent 50%);
    }
}