        :root {
            /* Палитра в духе Telegram Desktop / Android */
            --app-bg: #e6ebee;
            --surface: #ffffff;
            --surface-muted: #f4f4f5;
            --input-bg: #f0f2f5;
            --border: rgba(0, 0, 0, 0.08);
            --accent: #3390ec;
            --accent-soft: rgba(51, 144, 236, 0.12);
            --accent-softer: rgba(51, 144, 236, 0.08);
            --text: #000000;
            --text-muted: #707579;
            --radius: 12px;
            --radius-pill: 22px;
            --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
            --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
            --app-vh: 100dvh;
            --app-vv-top: 0px;
        }
        *, *::before, *::after { box-sizing: border-box; }
        body {
            margin: 0;
            font-family: var(--font);
            background: var(--app-bg);
            color: var(--text);
            -webkit-font-smoothing: antialiased;
            -moz-osx-font-smoothing: grayscale;
        }
        html, body {
            min-height: 100%;
            background: var(--app-bg);
        }
        /* PWA standalone: iOS needs explicit safe-area handling for status bar. */
        @media (display-mode: standalone) {
            body { background: var(--app-bg); }
            #authScreen.screen.active,
            #chatScreen.screen.active { background: var(--app-bg); }
        }
        input:focus-visible,
        textarea:focus-visible,
        button:focus-visible {
            outline: 2px solid var(--accent);
            outline-offset: 1px;
        }
        @media (max-width: 900px) {
            html.app-chat-open,
            body.app-chat-open {
                height: 100%;
                max-height: 100dvh;
                overflow: hidden;
                overscroll-behavior: none;
            }
            body.app-chat-open {
                display: flex;
                flex-direction: column;
            }
            /* iOS Safari: отключаем auto-zoom на фокусе любых текстовых полей */
            input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="button"]):not([type="submit"]):not([type="file"]),
            textarea,
            select {
                font-size: 16px !important;
            }
        }
        .screen { min-height: 100vh; display: none; }
        .screen.active { display: block; }
        /* Поверх мобильного drawer/backdrop (z-index ~80), иначе после выхода виден «пустой» чат */
        #authScreen.screen.active {
            position: relative;
            z-index: 200;
            min-height: 100vh;
            min-height: 100dvh;
            background: var(--app-bg);
        }
        .auth-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); padding-bottom: max(16px, env(safe-area-inset-bottom)); position: relative; z-index: 50; }
        .auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 22px 20px; box-shadow: var(--shadow); position: relative; z-index: 51; }
        .h1 { font-size: 22px; margin: 0 0 8px 0; }
        .muted { color: #6b7280; font-size: 13px; margin-bottom: 12px; }
        .auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
        .auth-tab { background: #eef3fb; color: #334155; border: 1px solid #dde6f4; }
        .auth-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
        .row { display: flex; gap: 8px; margin-bottom: 10px; }
        input, button { border-radius: var(--radius); border: 1px solid transparent; padding: 11px 12px; font-size: 15px; }
        input { width: 100%; background: var(--input-bg); color: var(--text); }
        button { background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; transition: opacity 0.15s ease, transform 0.1s ease; }
        button:active:not(:disabled) { opacity: 0.92; transform: scale(0.98); }
        button.secondary { background: var(--surface-muted); color: var(--text); border-color: var(--border); }
        .chat-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: 100vh; height: 100dvh; max-height: 100%; min-height: 0; box-sizing: border-box; }
        .chat-layout > .left,
        .chat-layout > .right { min-height: 0; }
        #chatScreen.screen.active {
            height: 100vh;
            height: 100dvh;
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }
        .chat-main-shell {
            flex: 1;
            min-height: 0;
            display: flex;
            flex-direction: row;
            align-items: stretch;
            width: 100%;
            overflow: hidden;
        }
        .chat-main-shell > .chat-layout {
            flex: 1;
            min-width: 0;
            min-height: 0;
            height: 100%;
            max-height: 100%;
        }
        .left {
            box-sizing: border-box;
            background: var(--surface);
            border-right: 1px solid rgba(0, 0, 0, 0.08);
            display: flex;
            flex-direction: column;
            min-height: 0;
            min-width: 0;
        }
        .left-header {
            background: var(--surface);
            padding: 0 10px;
            padding-top: max(10px, env(safe-area-inset-top));
            padding-bottom: 10px;
            min-height: 72px;
            box-sizing: border-box;
            border-bottom: 1px solid rgba(0, 0, 0, 0.08);
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
        }
        .left-header--sub {
            justify-content: flex-start;
            gap: 2px;
        }
        .left-header--sub .session-wrap {
            flex: 1;
            min-width: 0;
        }
        .left-back {
            display: none;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            margin: 0;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            cursor: pointer;
            flex-shrink: 0;
            transition: background 0.12s ease;
        }
        .left-back:hover {
            background: rgba(51, 144, 236, 0.1);
        }
        .left-back:active {
            opacity: 0.85;
        }
        .left-back svg {
            display: block;
            width: 22px;
            height: 22px;
        }
        .left-back.show {
            display: inline-flex;
        }
        .left-title {
            font-size: 17px;
            font-weight: 600;
            color: var(--text);
            letter-spacing: -0.02em;
        }
        .left-header--sub .left-title {
            font-size: 20px;
            font-weight: 600;
            color: #000;
        }
        .session-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
        .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; border: 1px solid #d6dfeb; background: #e8eef8; }
        .avatar.small { width: 20px; height: 20px; }
        .actions { display: flex; gap: 6px; align-items: center; }
        .left-actions-tg {
            gap: 8px;
        }
        .left-action-tg {
            width: 40px;
            height: 40px;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: var(--surface-muted);
            color: var(--accent);
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            transition: background 0.15s ease, transform 0.1s ease;
            box-shadow: 0 0 0 1px var(--border);
        }
        .left-action-tg:hover {
            background: #e8eef8;
        }
        .left-action-tg:active {
            transform: scale(0.96);
        }
        .left-action-tg svg {
            display: block;
            width: 22px;
            height: 22px;
        }
        .chat-list {
            padding: 0;
            margin: 0;
            overflow: auto;
            flex: 1;
            min-height: 0;
            background: var(--surface);
            -webkit-overflow-scrolling: touch;
            touch-action: pan-y;
        }
        /* Без класса --grow не растягиваем: иначе делим колонку с .chat-list пополам и список «обрезается». */
        #leftPanelsMount {
            flex: 0 0 auto;
            min-height: 0;
            min-width: 0;
            display: flex;
            flex-direction: column;
        }
        #leftPanelsMount.left-panels-mount--grow {
            flex: 1;
            min-height: 0;
        }
        .thread-empty-placeholder {
            text-align: center;
            padding: 28px 20px 20px;
            font-size: 14px;
            line-height: 1.45;
            color: #64748b;
            max-width: 280px;
            margin: 0 auto;
            user-select: none;
        }
        .settings-panel { padding: 10px; overflow: auto; display: none; }
        .settings-panel.show { display: block; }
        .settings-panel.settings-panel--account {
            padding: 0;
        }
        .settings-tg-menu {
            display: flex;
            flex-direction: column;
            gap: 0;
            margin: 0 0 10px;
        }
        .settings-tg-card {
            background: var(--surface);
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
            margin: 0 12px 12px;
        }
        .settings-tg-row {
            display: flex;
            align-items: center;
            gap: 12px;
            width: 100%;
            text-align: left;
            padding: 11px 14px 11px 12px;
            min-height: 52px;
            border: none;
            border-bottom: 0.5px solid rgba(0, 0, 0, 0.08);
            border-radius: 0;
            background: transparent;
            font: inherit;
            color: var(--text);
            cursor: pointer;
            margin: 0;
            box-sizing: border-box;
        }
        .settings-tg-row:last-child {
            border-bottom: none;
        }
        .settings-tg-row:active {
            background: rgba(0, 0, 0, 0.04);
        }
        .settings-tg-icon {
            width: 29px;
            height: 29px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
        }
        .settings-tg-icon svg {
            width: 17px;
            height: 17px;
            color: #fff;
            stroke: #fff;
            fill: none;
            stroke-width: 2;
            stroke-linecap: round;
            stroke-linejoin: round;
        }
        .settings-tg-icon--blue {
            background: linear-gradient(165deg, #5eb0ff 0%, #2b8ef0 100%);
        }
        .settings-tg-icon--green {
            background: linear-gradient(165deg, #5dd48a 0%, #2fb350 100%);
        }
        .settings-tg-icon--orange {
            background: linear-gradient(165deg, #ffb14a 0%, #e88600 100%);
        }
        .settings-tg-icon--violet {
            background: linear-gradient(165deg, #b794f6 0%, #805ad5 100%);
        }
        .settings-tg-row-text {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 2px;
        }
        .settings-tg-row-title {
            font-size: 17px;
            font-weight: 400;
            letter-spacing: -0.02em;
            color: #000;
        }
        .settings-tg-row-sub {
            font-size: 13px;
            font-weight: 400;
            color: #8e8e93;
            line-height: 1.25;
        }
        .settings-tg-row-chev {
            flex-shrink: 0;
            color: #c7c7cc;
            font-size: 22px;
            font-weight: 300;
            line-height: 1;
            margin-left: 2px;
        }
        .settings-subsection-title {
            font-size: 15px;
            font-weight: 600;
            color: #000;
            text-transform: none;
            letter-spacing: -0.02em;
            margin: 0 0 10px 2px;
        }
        #settingsAccountSection,
        #settingsPrivacySection,
        #settingsFeedbackSection,
        #settingsBroadcastsSection {
            background: var(--surface);
            border-radius: 12px;
            margin: 0 12px 12px;
            padding: 14px 12px 16px;
            box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.06);
        }
        #settingsAccountSection .row,
        #settingsPrivacySection .row {
            margin-bottom: 8px;
        }
        #settingsAccountSection .row:last-child,
        #settingsPrivacySection .row:last-child {
            margin-bottom: 0;
        }
        .settings-field-label {
            display: block;
            font-size: 13px;
            font-weight: 600;
            color: #000;
            margin: 10px 2px 6px;
        }
        .settings-textarea {
            width: 100%;
            box-sizing: border-box;
            min-height: 88px;
            padding: 10px 12px;
            border-radius: 10px;
            border: 1px solid #d7d7db;
            font: inherit;
            font-size: 15px;
            line-height: 1.4;
            resize: vertical;
            margin-bottom: 4px;
        }
        .feedback-actions-row {
            display: flex;
            align-items: center;
            gap: 10px;
            flex-wrap: wrap;
            margin: 6px 0 0;
        }
        .feedback-screenshots-preview {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin: 10px 0 12px;
        }
        .feedback-screenshots-preview img {
            width: 72px;
            height: 72px;
            object-fit: cover;
            border-radius: 8px;
            border: 1px solid #e5e7eb;
        }
        .feedback-send-btn {
            width: 100%;
            margin-top: 4px;
            padding: 12px;
            border-radius: 10px;
            border: none;
            background: var(--accent);
            color: #fff;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
        }
        .feedback-reports-list {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin-top: 8px;
        }
        .feedback-report-card {
            border: 1px solid #e5e7eb;
            border-radius: 10px;
            padding: 10px 12px;
            background: #fafafa;
        }
        .feedback-report-meta {
            font-size: 12px;
            color: #8e8e93;
            margin-bottom: 6px;
        }
        .feedback-report-snippet {
            font-size: 14px;
            color: #111827;
            line-height: 1.35;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .feedback-report-reply {
            margin-top: 8px;
            padding: 8px 10px;
            border-radius: 8px;
            background: #e8f4ff;
            font-size: 13px;
            line-height: 1.4;
            color: #1e3a5f;
        }
        .broadcast-messages-list {
            display: flex;
            flex-direction: column;
            gap: 10px;
            margin-top: 4px;
            max-height: min(55vh, 420px);
            overflow: auto;
            -webkit-overflow-scrolling: touch;
        }
        .broadcast-msg-card {
            padding: 10px 12px;
            border-radius: 10px;
            background: #f4f7fb;
            border: 1px solid #e5eaf0;
            text-align: left;
        }
        .broadcast-msg-meta {
            font-size: 12px;
            color: #8e8e93;
            margin-bottom: 8px;
        }
        .broadcast-msg-body {
            font-size: 15px;
            line-height: 1.45;
            color: #111827;
            white-space: pre-wrap;
            word-break: break-word;
        }
        .settings-privacy-hint {
            font-size: 13px;
            line-height: 1.45;
            color: #8e8e93;
            margin: 0 2px 12px;
        }
        .sessions-list {
            max-height: min(48vh, 340px);
            overflow: auto;
            margin: 0 0 12px;
            padding: 0;
            background: #fff;
            border-radius: 10px;
            box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.1), 0 1px 4px rgba(0, 0, 0, 0.06);
            -webkit-overflow-scrolling: touch;
        }
        .session-row {
            display: flex;
            align-items: flex-start;
            justify-content: space-between;
            gap: 10px;
            padding: 12px 14px;
            border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
            text-align: left;
        }
        .session-row-main {
            flex: 1;
            min-width: 0;
        }
        .session-row-actions {
            flex-shrink: 0;
            padding-top: 2px;
        }
        .session-row-logout-btn {
            padding: 6px 12px;
            border: none;
            border-radius: 8px;
            background: rgba(229, 57, 53, 0.1);
            color: #e53935;
            font-size: 14px;
            font-weight: 500;
            font-family: inherit;
            cursor: pointer;
            white-space: nowrap;
        }
        .session-row-logout-btn:active {
            background: rgba(229, 57, 53, 0.18);
        }
        .session-row:last-child {
            border-bottom: none;
        }
        .session-row-title {
            font-size: 16px;
            font-weight: 500;
            color: #000;
            line-height: 1.3;
            letter-spacing: -0.02em;
        }
        .session-row-badge {
            font-size: 13px;
            font-weight: 500;
            color: #34c759;
            margin-left: 6px;
        }
        .session-row-meta {
            font-size: 13px;
            color: #8e8e93;
            line-height: 1.4;
            margin-top: 4px;
        }
        .sessions-revoke-btn {
            width: 100%;
            padding: 14px 16px;
            border: none;
            border-radius: 10px;
            background: #fff;
            box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.1), 0 1px 4px rgba(0, 0, 0, 0.06);
            font-size: 16px;
            font-weight: 400;
            color: #e53935;
            cursor: pointer;
            font-family: inherit;
            text-align: center;
            box-sizing: border-box;
        }
        .sessions-revoke-btn:active {
            background: rgba(0, 0, 0, 0.04);
        }
        .settings-self-header {
            text-align: center;
            padding: 16px 16px 20px;
            margin: 0 0 4px;
            border-bottom: none;
        }
        .settings-self-avatar-wrap {
            margin: 0 auto 12px;
            width: 100px;
            height: 100px;
            border-radius: 50%;
            overflow: hidden;
            border: 3px solid #fff;
            box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
            background: linear-gradient(180deg, #dbeafe 0%, #e8eef8 100%);
        }
        .settings-big-avatar {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
            cursor: pointer;
        }
        .settings-self-name {
            font-size: 20px;
            font-weight: 600;
            color: #000;
            line-height: 1.2;
            letter-spacing: -0.03em;
        }
        .settings-self-tag {
            font-size: 15px;
            margin-top: 5px;
            color: #8e8e93;
        }
        #profilePanel {
            text-align: center;
            background: var(--surface);
        }
        #profilePanel.settings-panel.show {
            flex: 1;
            min-height: 0;
            overflow: auto;
        }
        .profile-write-row {
            display: none;
            justify-content: center;
            margin: 4px 0 18px;
            padding: 0 16px;
        }
        .profile-write-chip {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-width: 200px;
            max-width: 100%;
            padding: 10px 22px;
            border: none;
            border-radius: 24px;
            background: rgba(51, 144, 236, 0.1);
            color: #3390ec;
            font-size: 16px;
            font-weight: 600;
            font-family: inherit;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease;
        }
        .profile-write-chip:hover {
            background: rgba(51, 144, 236, 0.16);
        }
        .profile-write-chip:active {
            background: rgba(51, 144, 236, 0.22);
        }
        .profile-write-chip svg {
            width: 22px;
            height: 22px;
            flex-shrink: 0;
            opacity: 0.95;
        }
        #profilePanel .status { margin-left: auto; margin-right: auto; max-width: 280px; }
        .profile-peer-chat-tools {
            width: 100%;
            max-width: 360px;
            margin: 0 auto 12px;
            text-align: center;
            box-sizing: border-box;
            padding: 0 8px;
        }
        .profile-peer-chat-actions {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 8px;
            margin-bottom: 10px;
            justify-content: center;
        }
        .profile-peer-qbtn {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-height: 72px;
            padding: 10px 6px;
            border: none;
            border-radius: 14px;
            background: rgba(0, 0, 0, 0.04);
            color: var(--accent);
            font-size: 12px;
            font-weight: 600;
            font-family: inherit;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease;
        }
        .profile-peer-qbtn:hover {
            background: rgba(0, 0, 0, 0.07);
        }
        .profile-peer-qbtn__ico {
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--accent);
        }
        .profile-peer-qbtn__lab {
            line-height: 1.15;
            color: var(--text);
        }
        .profile-peer-media-wrap {
            text-align: left;
            height: min(52vh, 420px);
            min-height: 180px;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            border-radius: 12px;
            border: 1px solid rgba(0, 0, 0, 0.06);
            background: #fafafa;
        }
        .profile-peer-media-panels {
            flex: 1;
            min-height: 120px;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        #profilePanel .profile-peer-media-wrap .chat-media-grid {
            max-height: none;
        }
        /* Профиль: третья колонка (десктоп) / нижний лист (мобайл) */
        .profile-rail-wrap {
            flex: 0 0 0;
            width: 0;
            min-width: 0;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            align-items: stretch;
            pointer-events: none;
            transition: flex-basis 0.22s ease, width 0.22s ease, min-width 0.22s ease;
        }
        .profile-rail-wrap.profile-rail-wrap--open {
            flex: 0 0 clamp(340px, 32vw, 440px);
            width: clamp(340px, 32vw, 440px);
            min-width: clamp(340px, 32vw, 440px);
            border-left: 1px solid rgba(0, 0, 0, 0.08);
            background: var(--surface);
            pointer-events: auto;
        }
        .profile-rail-backdrop {
            display: none;
        }
        .profile-rail {
            flex: 1;
            min-height: 0;
            min-width: 0;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        .profile-rail__card {
            flex: 1;
            min-height: 0;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        .profile-rail__head {
            flex-shrink: 0;
            display: grid;
            grid-template-columns: 44px 1fr 44px;
            align-items: center;
            padding: 8px 6px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.07);
            background: linear-gradient(180deg, #fafbfc 0%, #fff 100%);
        }
        .profile-rail__close {
            border: none;
            background: transparent;
            font-size: 28px;
            line-height: 1;
            color: #3390ec;
            cursor: pointer;
            border-radius: 50%;
            width: 44px;
            height: 44px;
            padding: 0;
            justify-self: start;
        }
        .profile-rail__title {
            text-align: center;
            font-size: 17px;
            font-weight: 600;
            letter-spacing: -0.02em;
        }
        .profile-rail__body {
            flex: 1;
            min-height: 0;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
        }
        .chat-info-rail-mount {
            flex: 1;
            min-height: 0;
            display: none;
            flex-direction: column;
            overflow: hidden;
        }
        .chat-info-rail-mount .chat-info-card {
            flex: 1;
            min-height: 0;
            max-height: none;
            width: 100%;
            border-radius: 0;
            border: none;
            box-shadow: none;
            background: var(--surface);
            overflow-x: hidden;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            display: flex;
            flex-direction: column;
        }
        #profilePanel.profile-panel--rail.settings-panel.show {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            overflow-x: hidden;
            -webkit-overflow-scrolling: touch;
            display: flex;
            flex-direction: column;
            text-align: center;
            padding: 12px 12px max(16px, env(safe-area-inset-bottom));
        }
        #profilePanel.profile-panel--rail .profile-peer-media-wrap {
            height: auto;
            min-height: 0;
            max-height: none;
            overflow: visible;
        }
        #profilePanel.profile-panel--rail .profile-peer-media-panels {
            flex: 0 0 auto;
            min-height: 0;
            overflow: visible;
        }
        #profilePanel.profile-panel--rail .profile-peer-media-wrap .chat-info-tab-panels {
            flex: 0 0 auto;
            min-height: 0;
            overflow: visible;
            position: static;
        }
        #profilePanel.profile-panel--rail .profile-peer-media-wrap .chat-info-panel {
            position: static;
            inset: auto;
            opacity: 1;
            transform: none;
            pointer-events: auto;
            display: none;
            overflow: visible;
        }
        #profilePanel.profile-panel--rail .profile-peer-media-wrap .chat-info-panel.show {
            display: flex;
        }
        .settings-panel-inner {
            flex: 1;
            min-height: 0;
            overflow: auto;
            background: var(--surface);
            padding-top: 4px;
        }
        #settingsPanel.settings-panel--account.show {
            display: flex;
            flex-direction: column;
            flex: 1;
            min-height: 0;
            overflow: hidden;
            padding-bottom: 0;
            background: var(--surface);
        }
        .settings-logout-footer {
            flex-shrink: 0;
            padding: 0 0 max(12px, env(safe-area-inset-bottom));
        }
        .settings-tg-card--logout {
            margin: 0 12px 12px;
        }
        .settings-logout-footer-btn {
            display: block;
            width: 100%;
            margin: 0;
            padding: 14px 16px;
            border: none;
            border-radius: 0;
            background: transparent;
            color: #e53935;
            font-size: 17px;
            font-weight: 400;
            font-family: inherit;
            cursor: pointer;
            text-align: center;
            box-sizing: border-box;
        }
        .settings-logout-footer-btn:active {
            background: rgba(0, 0, 0, 0.04);
        }
        .settings-status-centered { text-align: center; margin-top: 8px; }
        .collapse-head { display: flex; justify-content: space-between; align-items: center; width: 100%; }
        .collapse-body { display: none; margin-top: 8px; }
        .collapse-body.show { display: block; }
        .chat-item {
            padding: 0;
            margin: 0;
            border: none;
            border-bottom: 1px solid rgba(15, 23, 42, 0.06);
            border-radius: 0;
            cursor: pointer;
            background: transparent;
            transition: background 0.12s ease;
            touch-action: manipulation;
            -webkit-tap-highlight-color: rgba(43, 124, 255, 0.12);
            -webkit-user-select: none;
            user-select: none;
            -webkit-touch-callout: none;
        }
        button.chat-item {
            display: block;
            width: 100%;
            font: inherit;
            color: inherit;
            text-align: left;
            -webkit-appearance: none;
            appearance: none;
        }
        .chat-item b,
        .chat-item .chat-item-preview,
        .chat-item .meta {
            -webkit-user-select: none;
            user-select: none;
        }
        .chat-item:active { background: rgba(15, 23, 42, 0.03); }
        .chat-item.active {
            background: rgba(43, 124, 255, 0.14);
            box-shadow: inset 4px 0 0 var(--accent);
        }
        .chat-item.active .chat-item-head b { color: var(--accent); }
        .chat-item-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; padding: 9px 12px 10px; }
        .chat-item-main { flex: 1; min-width: 0; }
        .chat-item-head b { font-weight: 600; font-size: 15px; color: var(--text); letter-spacing: -0.02em; }
        .chat-item-preview-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; min-width: 0; }
        .chat-item-preview { font-size: 13px; color: #8b95a5; margin-top: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
        /* Единый вид ✓/✓✓ в списке чатов и в нитке сообщений */
        .chat-item-ticks,
        .msg-read-ticks {
            flex-shrink: 0;
            font-size: 13px;
            font-weight: 600;
            letter-spacing: -2px;
            line-height: 1;
            user-select: none;
            font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
        }
        .chat-item-ticks--out.chat-item-ticks--read,
        .chat-item-ticks--out.chat-item-ticks--unread,
        .chat-item-ticks--in.chat-item-ticks--read,
        .chat-item-ticks--in.chat-item-ticks--unread { color: #8fa2b8; }
        .chat-item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
        .chat-item-head b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .chat-item-unread-badge {
            flex-shrink: 0;
            min-width: 20px;
            height: 20px;
            padding: 0 6px;
            border-radius: 10px;
            background: #3390ec;
            color: #fff;
            font-size: 12px;
            font-weight: 700;
            line-height: 20px;
            text-align: center;
            box-sizing: border-box;
        }
        .chat-item-time { flex-shrink: 0; font-size: 13px; font-weight: 500; color: #a8b0ba; letter-spacing: -0.02em; }
        .chat-item-avatar-wrap { flex-shrink: 0; width: 44px; height: 44px; border-radius: 50%; overflow: hidden; background: #e8eef8; border: 1px solid #d6dfeb; display: grid; place-items: center; }
        .chat-item-avatar-wrap img.avatar { width: 100%; height: 100%; object-fit: cover; border: 0; border-radius: 50%; }
        .left-panel-search { padding: 8px 10px 10px; border-bottom: 1px solid rgba(15, 23, 42, 0.06); flex-shrink: 0; background: var(--surface); }
        .left-panel-search input { width: 100%; box-sizing: border-box; font-size: 15px; border-radius: 10px; margin: 0; border: none; background: var(--input-bg); padding: 10px 12px; }
        .sidebar-user-results { padding: 0 10px 8px; max-height: 38vh; overflow: auto; border-bottom: 1px solid rgba(15, 23, 42, 0.06); flex-shrink: 0; }
        .sidebar-user-results .muted { font-size: 12px; margin: 4px 0 6px; }
        .sidebar-user-row { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid #e6ecf2; border-radius: 10px; margin-bottom: 6px; cursor: pointer; background: #f8fafc; }
        .sidebar-user-row:active { background: #eef3fb; }
        .sidebar-user-row .mini-av { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 1px solid #d6dfeb; background: #e8eef8; flex-shrink: 0; }
        .right {
            position: relative;
            display: flex;
            flex-direction: column;
            min-width: 0;
            min-height: 0;
            flex: 1;
            height: 100%;
            overflow: hidden;
            box-sizing: border-box;
        }
        .top {
            flex: 0 0 auto;
            position: sticky;
            top: 0;
            z-index: 15;
            display: flex;
            flex-direction: column;
            align-items: stretch;
            justify-content: flex-start;
            gap: 0;
            min-height: 72px;
            padding: 0 10px;
            padding-top: max(10px, env(safe-area-inset-top));
            padding-bottom: 10px;
            box-sizing: border-box;
            border-bottom: 1px solid rgba(0, 0, 0, 0.06);
            background: #ffffff;
        }
        .top-row {
            display: flex;
            align-items: center;
            gap: 6px;
            flex-wrap: nowrap;
            min-width: 0;
            width: 100%;
            flex: 0 0 auto;
        }
        #chatTitle {
            display: block;
            font-weight: 600;
            font-size: 16px;
            letter-spacing: -0.02em;
            color: var(--text);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .chat-subtitle { font-size: 13px; margin-top: 1px; color: #707579; line-height: 1.3; text-transform: none; letter-spacing: 0; font-weight: 500; }
        .chat-subtitle.chat-subtitle--online { color: #34c759; }
        .chat-subtitle.chat-subtitle--typing { color: #2b7cff; font-style: italic; }
        .chat-item-presence {
            font-size: 12px;
            font-weight: 500;
            color: #707579;
            margin-top: 3px;
            line-height: 1.3;
        }
        .chat-item-presence--online {
            color: #34c759;
        }
        .chat-header-main {
            flex: 1;
            min-width: 0;
            display: flex;
            align-items: center;
            gap: 10px;
        }
        .chat-header-avatar-wrap {
            flex-shrink: 0;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            overflow: hidden;
            background: #e8eef8;
            border: 1px solid #d6dfeb;
            display: none;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .chat-header-avatar-wrap:active {
            opacity: 0.92;
            transform: scale(0.98);
        }
        .chat-header-avatar {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }
        .chat-thread-back-btn {
            display: none !important;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            min-width: 40px;
            padding: 0 !important;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            cursor: pointer;
            flex-shrink: 0;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease;
        }
        .chat-thread-back-btn:active {
            background: rgba(51, 144, 236, 0.12);
        }
        .chat-thread-back-btn svg {
            display: block;
            width: 24px;
            height: 24px;
        }
        @media (max-width: 900px) {
            .chat-thread-back-btn.thread-back-visible {
                display: flex !important;
            }
        }
        .chat-header-tap {
            flex: 1;
            min-width: 0;
            padding: 4px 8px;
            margin: 0;
            border-radius: 10px;
            cursor: default;
            transition: background 0.15s;
        }
        .chat-header-tap.chat-header-tap--active { cursor: pointer; }
        .chat-header-tap.chat-header-tap--active:hover { background: rgba(43, 124, 255, 0.06); }
        .chat-header-tap.chat-header-tap--active:active { background: rgba(43, 124, 255, 0.1); }
        .chat-media-section {
            margin-bottom: 14px;
        }
        .chat-media-section-title {
            font-size: 12px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 0.04em;
            color: #64748b;
            margin: 0 0 8px 2px;
        }
        .chat-doc-list {
            display: flex;
            flex-direction: column;
            gap: 6px;
            max-height: 200px;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        .chat-doc-row {
            display: block;
            padding: 10px 12px;
            border: 1px solid #e6ecf2;
            border-radius: 10px;
            background: #f8fafc;
            font-size: 14px;
            color: #1d4ed8;
            text-decoration: none;
            word-break: break-word;
        }
        .chat-doc-row:active {
            background: #eef3f9;
        }
        .chat-media-empty {
            font-size: 13px;
            color: #94a3b8;
            padding: 6px 4px 4px;
        }
        .chat-info-card .chat-media-grid {
            max-height: min(26vh, 200px);
            min-height: 56px;
            flex: none;
        }
        .top-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
        .top-actions .mobile-menu-trigger { padding: 8px 10px; font-size: 14px; }
        /* Поиск по сообщениям — в стиле сайта (как поиск в списке чатов) */
        .chat-search-bar {
            width: 100%;
            margin-top: 8px;
            padding-top: 8px;
            display: flex;
            gap: 8px;
            align-items: center;
            flex-wrap: wrap;
            box-sizing: border-box;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
        }
        .chat-search-field {
            flex: 1;
            min-width: 0;
            display: flex;
            align-items: center;
            gap: 8px;
            background: var(--input-bg);
            border-radius: 999px;
            padding: 8px 14px 8px 16px;
            border: 1px solid var(--border);
            box-sizing: border-box;
            transition: border-color 0.15s ease, background 0.15s ease;
        }
        .chat-search-field:focus-within {
            border-color: rgba(51, 144, 236, 0.5);
            background: #fff;
        }
        .chat-search-field svg {
            flex-shrink: 0;
            color: var(--accent);
            opacity: 0.85;
        }
        .chat-search-bar input[type="search"] {
            flex: 1;
            min-width: 0;
            margin: 0;
            padding: 4px 2px;
            border: none;
            border-radius: 0;
            background: transparent;
            font-size: 15px;
            color: var(--text);
            -webkit-appearance: none;
            appearance: none;
        }
        /* Глобальный outline у input даёт прямоугольник внутри «пилюли» — убираем, фокус на обёртке */
        .chat-search-bar input[type="search"]:focus,
        .chat-search-bar input[type="search"]:focus-visible {
            outline: none;
        }
        .chat-search-bar input[type="search"]::placeholder {
            color: #8e8e93;
        }
        .chat-search-bar input[type="search"]::-webkit-search-cancel-button {
            -webkit-appearance: none;
        }
        .chat-search-count {
            font-size: 12px;
            font-weight: 600;
            color: var(--accent);
            padding: 5px 10px;
            border-radius: 999px;
            background: var(--accent-softer);
            flex-shrink: 0;
            line-height: 1.2;
            min-width: 2.5em;
            text-align: center;
        }
        .chat-search-count:empty {
            display: none;
        }
        /* Модальное окно «Перейти к дате» — календарь как в Telegram */
        .chat-date-jump-modal.modal {
            z-index: 320;
        }
        .chat-date-jump-card {
            max-width: 340px;
            padding: 0;
            overflow: hidden;
            border-radius: 14px;
            border: 1px solid rgba(0, 0, 0, 0.06);
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
        }
        .chat-date-jump-toolbar {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            padding: 12px 10px 8px;
            background: var(--surface);
        }
        .chat-date-jump-title {
            flex: 1;
            text-align: center;
            font-size: 16px;
            font-weight: 600;
            color: #000;
            letter-spacing: -0.02em;
        }
        .chat-date-jump-nav {
            width: 40px;
            height: 40px;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            flex-shrink: 0;
            transition: background 0.12s ease;
        }
        .chat-date-jump-nav:hover:not(:disabled) {
            background: rgba(0, 0, 0, 0.06);
        }
        .chat-date-jump-nav:disabled {
            opacity: 0.28;
            cursor: default;
        }
        .chat-date-jump-nav svg {
            display: block;
            width: 22px;
            height: 22px;
        }
        .chat-date-jump-weekdays {
            display: grid;
            grid-template-columns: repeat(7, 1fr);
            gap: 0;
            padding: 0 8px 6px;
            font-size: 11px;
            font-weight: 600;
            color: #aeb7c2;
            text-transform: uppercase;
            letter-spacing: 0.04em;
            text-align: center;
        }
        .chat-date-jump-grid {
            display: grid;
            grid-template-columns: repeat(7, 1fr);
            gap: 2px;
            padding: 4px 8px 12px;
        }
        .chat-date-jump-cell {
            aspect-ratio: 1;
            max-height: 44px;
            border: none;
            border-radius: 50%;
            background: transparent;
            font-size: 15px;
            font-weight: 500;
            color: #000;
            cursor: pointer;
            padding: 0;
            font-family: inherit;
            transition: background 0.1s ease, color 0.1s ease;
        }
        .chat-date-jump-cell:hover:not(:disabled):not(.is-empty) {
            background: rgba(0, 0, 0, 0.06);
        }
        .chat-date-jump-cell.is-empty {
            visibility: hidden;
            pointer-events: none;
        }
        .chat-date-jump-cell.is-today:not(.is-future) {
            box-shadow: inset 0 0 0 2px #3390ec;
            color: #3390ec;
        }
        .chat-date-jump-cell.is-future {
            color: #c4c9cc;
            cursor: default;
        }
        .chat-date-jump-footer {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 10px;
            padding: 10px 12px 14px;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
            background: var(--surface-muted);
        }
        .chat-date-jump-today {
            border: none;
            background: transparent;
            color: #3390ec;
            font-size: 15px;
            font-weight: 600;
            font-family: inherit;
            cursor: pointer;
            padding: 8px 4px;
        }
        .chat-date-jump-today:hover {
            text-decoration: underline;
        }
        .chat-date-jump-footer .secondary {
            margin: 0;
            background: #fff;
            color: #3390ec;
            border: 1px solid rgba(0, 0, 0, 0.08);
        }
        .chat-search-close-btn {
            flex-shrink: 0;
            width: 40px;
            height: 40px;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            font-size: 24px;
            line-height: 1;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background 0.12s ease, color 0.12s ease;
            -webkit-tap-highlight-color: transparent;
        }
        .chat-search-close-btn:hover {
            background: rgba(51, 144, 236, 0.12);
            color: #2176d9;
        }
        .chat-search-close-btn:active {
            background: rgba(51, 144, 236, 0.18);
        }
        .chat-search-close-btn:focus-visible {
            outline: none;
            box-shadow: 0 0 0 2px var(--accent-soft);
        }
        .chat-search-nav-group {
            display: inline-flex;
            flex-shrink: 0;
            align-items: center;
            gap: 4px;
        }
        .chat-search-nav-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            min-height: 40px;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            cursor: pointer;
            transition: background 0.12s ease, color 0.12s ease;
            -webkit-tap-highlight-color: transparent;
        }
        .chat-search-nav-btn:hover {
            background: rgba(51, 144, 236, 0.12);
            color: #2176d9;
        }
        .chat-search-nav-btn:active {
            background: rgba(51, 144, 236, 0.18);
        }
        .chat-search-nav-btn:focus-visible {
            outline: none;
            box-shadow: 0 0 0 2px var(--accent-soft);
        }
        .chat-search-nav-btn svg {
            width: 20px;
            height: 20px;
            display: block;
        }
        .pinned-bar {
            flex: 0 0 auto;
            display: none;
            align-items: flex-start;
            gap: 10px;
            padding: 8px 10px;
            margin: 0;
            box-sizing: border-box;
            background: linear-gradient(180deg, #e8f0fe 0%, #eef4fc 100%);
            border-bottom: 1px solid #dbe4f4;
            cursor: pointer;
            font-size: 13px;
            color: #1e3a5f;
        }
        .pinned-bar.open { display: flex; }
        .pinned-bar .pin-ico { flex-shrink: 0; font-size: 16px; line-height: 1.4; }
        .pinned-bar .pin-body { flex: 1; min-width: 0; }
        .pinned-bar .pin-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #3b82f6; margin-bottom: 2px; }
        .pinned-bar .pin-snippet { opacity: 0.9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .composer-attachment-strip {
            display: none;
            flex-direction: column;
            gap: 0;
            padding: 8px 10px 0;
            border-top: 1px solid var(--border);
            background: var(--surface-muted);
        }
        .attachment-strip-pick {
            display: flex;
            align-items: center;
            gap: 10px;
            min-height: 56px;
        }
        .attachment-strip-thumb-wrap {
            flex: 0 0 auto;
            max-width: min(200px, 42vw);
            max-height: 120px;
            border-radius: 10px;
            overflow: hidden;
            background: #e5e7eb;
            border: 1px solid var(--border);
        }
        .attachment-strip-thumb-wrap img {
            display: block;
            max-width: 100%;
            max-height: 120px;
            width: auto;
            height: auto;
            object-fit: cover;
        }
        .attachment-strip-file {
            display: flex;
            align-items: center;
            gap: 8px;
            padding: 10px 12px;
            font-size: 14px;
            font-weight: 500;
            color: var(--text);
            word-break: break-word;
        }
        .attachment-strip-remove {
            flex-shrink: 0;
            width: 36px;
            height: 36px;
            border: none;
            border-radius: 50%;
            background: rgba(15, 23, 42, 0.08);
            color: var(--text);
            font-size: 20px;
            line-height: 1;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .attachment-strip-remove:hover {
            background: rgba(15, 23, 42, 0.12);
        }
        .attachment-strip-previews {
            flex: 1;
            min-width: 0;
            display: flex;
            flex-wrap: wrap;
            gap: 6px;
            align-items: center;
            max-height: 168px;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        .attachment-strip-preview-cell {
            position: relative;
            width: 56px;
            height: 56px;
            border-radius: 8px;
            overflow: hidden;
            background: #e5e7eb;
            flex-shrink: 0;
            border: 1px solid var(--border);
        }
        .attachment-strip-preview-cell img {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
        }
        .attachment-strip-preview-file {
            font-size: 10px;
            padding: 4px;
            line-height: 1.2;
            word-break: break-word;
            display: flex;
            align-items: center;
            justify-content: center;
            height: 100%;
            text-align: center;
            color: var(--text);
        }
        .attachment-strip-preview-remove {
            position: absolute;
            top: 2px;
            right: 2px;
            width: 22px;
            height: 22px;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: rgba(15, 23, 42, 0.55);
            color: #fff;
            font-size: 14px;
            line-height: 1;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .attachment-strip-upload {
            display: none;
            align-items: center;
            justify-content: flex-start;
            gap: 12px;
            padding: 8px 0 4px;
            font-size: 14px;
        }
        .attachment-strip-upload.show {
            display: flex;
        }
        .messages-thread-wrap {
            flex: 1 1 auto;
            min-height: 0;
            position: relative;
            display: flex;
            flex-direction: column;
        }
        .messages-date-float {
            display: none;
            position: absolute;
            top: 10px;
            left: 50%;
            transform: translateX(-50%);
            z-index: 11;
            max-width: calc(100% - 24px);
            padding: 5px 12px;
            border-radius: 14px;
            background: rgba(15, 23, 42, 0.52);
            color: #fff;
            font-size: 12px;
            font-weight: 600;
            line-height: 1.25;
            letter-spacing: 0.02em;
            text-align: center;
            pointer-events: none;
            box-shadow: 0 2px 10px rgba(15, 23, 42, 0.12);
        }
        .messages {
            flex: 1 1 auto;
            min-height: 0;
            overflow: auto;
            overflow-x: hidden;
            padding: 12px 10px 16px;
            box-sizing: border-box;
            background: var(--app-bg);
            /* Чтобы последний пузырь не оказывался визуально под полем ввода при scrollIntoView / докрутке */
            scroll-padding-bottom: 12px;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior: contain;
            touch-action: pan-y;
            /* auto: браузер удерживает позицию при сдвигах выше (пин, галочки, resize). none давало «прыжки» вверх и сброс ощущений у плеера. */
            overflow-anchor: auto;
            /* container-type: size + cqh для медиа отключены: при клавиатуре высота #messages мала — 72cqh давало крошечный max-height и «сжатые» фото */
            container-type: inline-size;
            container-name: chat-thread;
        }
        .messages.thread-loading-older {
            position: relative;
        }
        /* Не в потоке: иначе полоска «Загрузка…» меняет scrollHeight и дёргает позицию при подгрузке. */
        .messages.thread-loading-older::before {
            content: "Загрузка истории…";
            position: absolute;
            left: 0;
            right: 0;
            top: 0;
            z-index: 3;
            display: block;
            text-align: center;
            padding: 8px 8px 4px;
            font-size: 13px;
            color: #8e8e93;
            line-height: 1.2;
            pointer-events: none;
        }
        .thread-new-messages-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0 14px;
    padding: 0;
            user-select: none;
            width: 100%;
            max-width: 100%;
            box-sizing: border-box;
        }
        .thread-new-messages-divider::before,
        .thread-new-messages-divider::after {
    display: none;
        }
        .thread-new-messages-divider span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    padding: 4px 12px;
    border-radius: 12px;
    border: 1px solid #d7def8;
    background: #f4f0ff;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: #6d63a8;
            white-space: nowrap;
        }
        .msg-text-link {
            color: #2563eb;
            text-decoration: none;
            word-break: break-word;
        }
        .msg-text-link:hover {
            text-decoration: underline;
        }
        .msg.me .msg-text-link {
            color: #e0e7ff;
        }
        .scroll-to-bottom-fab {
            display: none;
            position: absolute;
            bottom: 96px;
            right: 16px;
            z-index: 25;
            width: 42px;
            height: 42px;
            border-radius: 50%;
            border: none;
            background: var(--surface);
            box-shadow: 0 4px 20px rgba(15, 23, 42, 0.14), 0 0 0 1px rgba(15, 23, 42, 0.06);
            align-items: center;
            justify-content: center;
            cursor: pointer;
            padding: 0;
            color: #64748b;
            transition: transform 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
        }
        .scroll-to-bottom-fab svg {
            display: block;
            width: 22px;
            height: 22px;
        }
        .scroll-to-bottom-fab:hover {
            color: var(--accent);
            box-shadow: 0 6px 24px rgba(15, 23, 42, 0.16), 0 0 0 1px rgba(43, 124, 255, 0.15);
        }
        .scroll-to-bottom-fab:active { transform: scale(0.96); }
        @media (max-width: 900px) {
            .scroll-to-bottom-fab { bottom: 118px; right: 12px; }
            /* iOS/Android: браузерный scroll anchoring + смена --app-vh дают рывки; для ленты якорение не нужно. */
            .messages {
                overflow-anchor: none;
            }
        }

        .desktop-toasts {
            position: fixed;
            right: 14px;
            bottom: 14px;
            z-index: 9999;
            display: flex;
            flex-direction: column;
            gap: 10px;
            pointer-events: none;
            max-width: min(380px, calc(100vw - 28px));
        }
        @media (max-width: 900px) {
            .desktop-toasts { display: none; }
        }
        .desktop-toast {
            pointer-events: auto;
            display: grid;
            grid-template-columns: 44px 1fr;
            gap: 10px;
            align-items: center;
            padding: 10px 12px;
            border-radius: 16px;
            background: rgba(255, 255, 255, 0.92);
            border: 1px solid rgba(148, 163, 184, 0.35);
            box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18), 0 2px 10px rgba(15, 23, 42, 0.08);
            backdrop-filter: blur(10px);
            transform: translateY(6px);
            opacity: 0;
            transition: opacity var(--anim) var(--ease-out), transform var(--anim) var(--ease-out);
        }
        .desktop-toast.show {
            opacity: 1;
            transform: translateY(0);
        }
        .desktop-toast__av {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            object-fit: cover;
            border: 1px solid rgba(148, 163, 184, 0.35);
            background: #e8eef8;
        }
        .desktop-toast__title {
            font-weight: 700;
            font-size: 14px;
            color: #0f172a;
            line-height: 1.2;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .desktop-toast__body {
            margin-top: 2px;
            font-size: 13px;
            color: rgba(15, 23, 42, 0.76);
            line-height: 1.25;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .msg {
            margin-bottom: 8px;
            width: fit-content;
            max-width: min(78%, 520px);
            min-width: 0;
            padding: 8px 12px 9px;
            border-radius: 16px;
            background: var(--surface);
            box-shadow: 0 1px 1px rgba(15, 23, 42, 0.04);
            touch-action: manipulation;
            overscroll-behavior: contain;
            /* Длинные «слова» без пробелов — не вылезают за скругление пузыря */
            overflow-wrap: anywhere;
            word-break: break-word;
        }
        :root {
            --anim-fast: 120ms;
            --anim: 160ms;
            --anim-slow: 220ms;
            --ease-out: cubic-bezier(0.2, 0.85, 0.2, 1);
        }

        @media (prefers-reduced-motion: reduce) {
            .msg,
            .reply-preview-bar,
            .forward-draft-bar,
            .chat-info-panel,
            .chat-info-primary-panel {
                transition: none !important;
                animation: none !important;
            }
        }

        .msg.msg--removing {
            overflow: hidden;
            will-change: height, opacity, transform, margin, padding;
            transition:
                height var(--anim) var(--ease-out),
                opacity var(--anim-fast) var(--ease-out),
                transform var(--anim-fast) var(--ease-out),
                margin var(--anim) var(--ease-out),
                padding var(--anim) var(--ease-out);
        }
        .msg.msg--removing.msg--removing-go {
            opacity: 0;
            transform: scale(0.985);
            margin-top: 0 !important;
            margin-bottom: 0 !important;
            padding-top: 0 !important;
            padding-bottom: 0 !important;
            height: 0 !important;
        }
        /* На телефоне отключаем выделение текста при удержании (иначе срабатывает системное копирование) */
        @media (max-width: 900px) {
            .msg:not(.msg-service) {
                -webkit-user-select: none;
                user-select: none;
                -webkit-touch-callout: none;
            }
            /* Свайп влево → ответ: смещение пузыря и иконка «ответ» */
            .msg:not(.msg-service).msg--reply-swipe-drag {
                position: relative;
                z-index: 2;
                will-change: transform;
            }
            .msg:not(.msg-service).msg--reply-swipe-drag::before {
                content: "";
                position: absolute;
                top: 50%;
                right: -24px;
                transform: translateY(-50%) scale(calc(0.86 + var(--reply-swipe, 0) * 0.14));
                width: 20px;
                height: 20px;
                background: var(--accent);
                -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M9.2 7.3c.4-.4.4-1 0-1.4s-1-.4-1.4 0L3.7 10c-.7.7-.7 1.8 0 2.5l4.1 4.1c.4.4 1 .4 1.4 0s.4-1 0-1.4L6 12h9.6c2.5 0 4.4 1.2 4.4 3.5v.5c0 .6.4 1 1 1s1-.4 1-1v-.5c0-3.5-2.9-5.5-6.4-5.5H6l3.2-3.2z'/%3E%3C/svg%3E");
                -webkit-mask-repeat: no-repeat;
                -webkit-mask-size: 20px 20px;
                -webkit-mask-position: center;
                mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='black' d='M9.2 7.3c.4-.4.4-1 0-1.4s-1-.4-1.4 0L3.7 10c-.7.7-.7 1.8 0 2.5l4.1 4.1c.4.4 1 .4 1.4 0s.4-1 0-1.4L6 12h9.6c2.5 0 4.4 1.2 4.4 3.5v.5c0 .6.4 1 1 1s1-.4 1-1v-.5c0-3.5-2.9-5.5-6.4-5.5H6l3.2-3.2z'/%3E%3C/svg%3E");
                mask-repeat: no-repeat;
                mask-size: 20px 20px;
                mask-position: center;
                opacity: calc(0.2 + var(--reply-swipe, 0) * 0.72);
                filter: drop-shadow(0 1px 1px rgba(15, 23, 42, 0.12));
                pointer-events: none;
            }
        }
        .msg.me { margin-left: auto; background: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(43, 124, 255, 0.25); }
        .msg.msg-service {
            margin-left: auto;
            margin-right: auto;
            max-width: 100%;
            width: 100%;
            background: transparent;
            box-shadow: none;
            padding: 6px 14px 10px;
            cursor: default;
        }
        .msg-service-text {
            font-size: 13px;
            line-height: 1.4;
            color: #8e8e93;
            text-align: center;
            font-weight: 500;
        }
        .msg.search-hit {
            outline: 2px solid rgba(255, 171, 0, 0.65);
            border-radius: 12px;
        }
        .msg.search-current {
            outline: 2px solid #3390ec;
            border-radius: 12px;
        }
        .msg.date-search-hit {
            outline: 2px solid #3390ec;
            box-shadow: 0 0 0 2px rgba(51, 144, 236, 0.22);
            border-radius: 16px;
        }
        .chat-photo-wrap { margin-top: 6px; border-radius: 12px; overflow: hidden; max-width: min(360px, 88vw); }
        .chat-photo-thumb {
            width: 100%;
            max-height: min(75dvh, 420px);
            object-fit: cover;
            cursor: zoom-in;
            display: block;
            border-radius: 12px;
            background: #e5e7eb;
        }
        .msg.me .chat-photo-thumb { opacity: 0.98; }
        .chat-album-grid {
            display: grid;
            gap: 2px;
            margin-top: 6px;
            max-width: min(360px, 88vw);
            /* Лимит высоты: иначе 1fr при height:auto тянется под самый высокий кадр и съедает чат */
            --album-max-h: min(75dvh, 420px);
            max-height: var(--album-max-h);
            height: min(var(--album-max-h), max-content);
            border-radius: 12px;
            overflow: hidden;
        }
        .chat-album-grid--1 {
            grid-template-columns: 1fr;
            grid-template-rows: minmax(0, 1fr);
        }
        .chat-album-grid--1 .chat-album-cell {
            max-height: 100%;
            min-height: 0;
        }
        .chat-album-grid--2 {
            grid-template-columns: 1fr 1fr;
        }
        .chat-album-grid--3 {
            grid-template-columns: 1.15fr 1fr;
            grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
        }
        .chat-album-grid--3 .chat-album-cell:nth-child(1) {
            grid-row: 1 / -1;
        }
        .chat-album-grid--4 {
            grid-template-columns: 1.15fr 1fr;
            grid-template-rows: repeat(3, minmax(0, 1fr));
        }
        .chat-album-grid--4 .chat-album-cell:nth-child(1) {
            grid-row: 1 / -1;
        }
        .chat-album-grid--many {
            grid-template-columns: repeat(3, 1fr);
            grid-auto-rows: minmax(0, 1fr);
        }
        .chat-album-cell {
            position: relative;
            min-height: 0;
            background: #e5e7eb;
        }
        .chat-album-grid--2 .chat-album-cell,
        .chat-album-grid--many .chat-album-cell {
            aspect-ratio: 1;
        }
        .chat-album-grid--3 .chat-album-cell:nth-child(1),
        .chat-album-grid--4 .chat-album-cell:nth-child(1) {
            aspect-ratio: auto;
        }
        .chat-album-cell img,
        .chat-album-cell video {
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
            cursor: zoom-in;
        }
        .chat-album-play {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-size: 22px;
            text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
            pointer-events: none;
        }
        .chat-album-upload-overlay {
            position: absolute;
            inset: 0;
            overflow: hidden;
            pointer-events: none;
            z-index: 3;
        }
        .chat-album-upload-bar {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            height: 100%;
            transform-origin: bottom center;
            transform: scaleY(0);
            background: linear-gradient(
                180deg,
                rgba(51, 144, 236, 0.12) 0%,
                rgba(51, 144, 236, 0.42) 100%
            );
            transition: transform 0.06s linear;
        }
        .chat-album-upload-pct {
            position: absolute;
            bottom: 5px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 11px;
            font-weight: 600;
            color: #fff;
            text-shadow: 0 1px 3px rgba(0, 0, 0, 0.65);
            z-index: 1;
        }
        .media-viewer {
            position: fixed;
            inset: 0;
            z-index: 400;
            display: none;
        }
        .media-viewer.open { display: block; }
        .media-viewer-backdrop {
            position: absolute;
            inset: 0;
            background: rgba(8, 12, 22, 0.94);
            cursor: pointer;
        }
        .media-viewer-inner {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 48px 52px 56px;
            padding-top: max(48px, env(safe-area-inset-top));
            padding-bottom: max(56px, env(safe-area-inset-bottom));
            padding-left: max(52px, env(safe-area-inset-left));
            padding-right: max(52px, env(safe-area-inset-right));
            box-sizing: border-box;
            pointer-events: none;
        }
        .media-viewer-close,
        .media-viewer-nav,
        .media-viewer-stage,
        .media-viewer-goto,
        .media-viewer-download {
            pointer-events: auto;
        }
        @media (max-width: 900px) {
            .media-viewer-inner { padding: 84px 10px 56px; }
        }
        .media-viewer-close {
            position: absolute;
            top: max(10px, env(safe-area-inset-top));
            right: max(10px, env(safe-area-inset-right));
            z-index: 5;
            width: 44px;
            height: 44px;
            border: none;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            color: #fff;
            font-size: 26px;
            line-height: 1;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background 0.15s ease;
        }
        .media-viewer-close:hover { background: rgba(255, 255, 255, 0.18); }
        .media-viewer-nav {
            position: absolute;
            top: calc(50% - 22px);
            z-index: 25;
            width: 44px;
            height: 44px;
            border: none;
            border-radius: 50%;
            background: rgba(255, 255, 255, 0.1);
            color: #fff;
            font-size: 30px;
            line-height: 1;
            cursor: pointer;
            display: none;
            align-items: center;
            justify-content: center;
            padding: 0 0 2px 0;
            transition: background 0.15s ease;
        }
        .media-viewer-nav:hover { background: rgba(255, 255, 255, 0.2); }
        .media-viewer-prev { left: max(8px, env(safe-area-inset-left)); }
        .media-viewer-next { right: max(8px, env(safe-area-inset-right)); }
        .media-viewer-stage {
            position: relative;
            z-index: 1;
            max-width: 100%;
            max-height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            touch-action: none;
            isolation: isolate;
        }
        .media-viewer-stage img,
        .media-viewer-stage video {
            max-width: 100%;
            max-height: min(88vh, calc(100dvh - 120px));
            width: auto;
            height: auto;
            object-fit: contain;
            border-radius: 10px;
            display: block;
        }
        .media-viewer-stage img {
            opacity: 1 !important;
            visibility: visible !important;
            transform: none !important;
            filter: none !important;
            backface-visibility: hidden;
            -webkit-backface-visibility: hidden;
            will-change: auto;
            image-rendering: auto;
        }
        .media-viewer-unsupported {
            display: none;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 10px;
            min-width: min(560px, 86vw);
            max-width: min(700px, 90vw);
            min-height: min(240px, 48vh);
            padding: 18px 20px;
            text-align: center;
            color: #dbeafe;
            background: rgba(15, 23, 42, 0.72);
            border: 1px solid rgba(148, 163, 184, 0.35);
            border-radius: 12px;
            backdrop-filter: blur(6px);
        }
        .media-viewer-unsupported-title {
            font-size: 15px;
            font-weight: 600;
            color: #f8fafc;
        }
        .media-viewer-unsupported-hint {
            font-size: 13px;
            color: rgba(203, 213, 225, 0.92);
        }
        .media-viewer-unsupported-link {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 8px 12px;
            border-radius: 10px;
            background: rgba(37, 99, 235, 0.9);
            color: #fff;
            text-decoration: none;
            font-weight: 600;
        }
        .media-viewer-unsupported-link:hover {
            background: rgba(29, 78, 216, 0.95);
            text-decoration: none;
        }
        .media-viewer-counter {
            position: absolute;
            bottom: max(14px, env(safe-area-inset-bottom));
            left: 50%;
            transform: translateX(-50%);
            color: rgba(255, 255, 255, 0.88);
            font-size: 14px;
            font-weight: 600;
            letter-spacing: 0.06em;
            pointer-events: none;
        }
        .media-viewer-hint {
            position: absolute;
            bottom: max(42px, calc(env(safe-area-inset-bottom) + 28px));
            left: 50%;
            transform: translateX(-50%);
            color: rgba(148, 163, 184, 0.85);
            font-size: 12px;
            pointer-events: none;
            text-align: center;
            max-width: 90vw;
        }
        @media (max-width: 900px) {
            .media-viewer-hint { display: none; }
        }
        .chat-video-wrap {
            position: relative;
            display: block;
            width: min(360px, 88vw);
            max-width: 100%;
            aspect-ratio: 16 / 10;
            margin-top: 6px;
            border-radius: 10px;
            overflow: hidden;
            background: #0b1020;
        }
        .chat-video-wrap video {
            display: block;
            width: 100%;
            height: 100%;
            border-radius: 10px;
            vertical-align: top;
            object-fit: contain;
            background: #000;
        }
        .chat-video-expand-btn {
            position: absolute;
            top: 8px;
            right: 8px;
            z-index: 2;
            width: 36px;
            height: 36px;
            border: none;
            border-radius: 50%;
            background: rgba(15, 23, 42, 0.5);
            color: #fff;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background 0.15s ease, transform 0.1s ease;
        }
        .chat-video-expand-btn:hover { background: rgba(15, 23, 42, 0.65); }
        .chat-video-expand-btn:active { transform: scale(0.96); }
        .chat-video-expand-btn svg { width: 18px; height: 18px; display: block; opacity: 0.95; }
        .meta { font-size: 12px; opacity: .75; margin-top: 2px; }
        .msg-header {
            display: flex;
            align-items: center;
            gap: 8px;
            margin: 0 0 6px 0;
            min-width: 0;
        }
        .msg:not(.me) .msg-header {
            justify-content: flex-start;
        }
        .msg.me .msg-header {
            justify-content: flex-end;
            flex-direction: row-reverse;
        }
        .msg-header-avatar {
            width: 32px;
            height: 32px;
            border-radius: 50%;
            object-fit: cover;
            flex-shrink: 0;
            background: #e8eef8;
            border: 1px solid rgba(148, 163, 184, 0.35);
        }
        .msg.me .msg-header-avatar {
            border-color: rgba(255, 255, 255, 0.35);
        }
        .msg-header-name {
            font-size: 14px;
            font-weight: 600;
            line-height: 1.25;
            min-width: 0;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            max-width: min(220px, 55vw);
        }
        .msg:not(.me) .msg-header-name {
            color: #3390ec;
        }
        .msg.me .msg-header-name {
            color: rgba(255, 255, 255, 0.96);
        }
        .composer-wrap {
            flex: 0 0 auto;
            width: 100%;
            background: #ffffff;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
            z-index: 20;
        }
        .message-selection-bar {
            display: none;
            flex: 0 0 auto;
            width: 100%;
            box-sizing: border-box;
            align-items: center;
            gap: 6px;
            padding: 8px 10px 10px;
            margin: 0;
            background: var(--app-bg);
            border-bottom: 1px solid rgba(0, 0, 0, 0.08);
            z-index: 12;
        }
        .message-selection-cancel {
            flex-shrink: 0;
            width: 40px;
            height: 40px;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #475569;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            justify-content: center;
        }
        .message-selection-cancel:hover {
            background: rgba(0, 0, 0, 0.06);
            color: var(--accent);
        }
        .message-selection-count {
            flex: 0 1 auto;
            min-width: 0;
            font-weight: 600;
            font-size: 15px;
            color: #0f172a;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .message-selection-actions {
            display: flex;
            flex-wrap: nowrap;
            align-items: center;
            gap: 4px;
            flex: 1 1 auto;
            min-width: 0;
            justify-content: flex-end;
            overflow-x: auto;
            overflow-y: hidden;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior-x: contain;
            scrollbar-width: thin;
            padding-bottom: 2px;
        }
        .message-selection-actions::-webkit-scrollbar {
            height: 4px;
        }
        .message-selection-actions::-webkit-scrollbar-thumb {
            background: rgba(15, 23, 42, 0.2);
            border-radius: 4px;
        }
        .message-selection-act {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 5px;
            flex-shrink: 0;
            padding: 7px 10px;
            font-size: 13px;
            border-radius: 10px;
            border: none;
            background: #f1f5f9;
            color: #0f172a;
            cursor: pointer;
            font-weight: 500;
            white-space: nowrap;
        }
        .message-selection-act-ico {
            width: 18px;
            height: 18px;
            flex-shrink: 0;
            display: block;
        }
        .message-selection-act:hover {
            background: #e2e8f0;
        }
        .message-selection-act--danger {
            background: rgba(239, 68, 68, 0.12);
            color: #b91c1c;
        }
        .message-selection-act--danger:hover {
            background: rgba(239, 68, 68, 0.2);
        }
        @media (max-width: 520px) {
            .message-selection-act-label {
                display: none;
            }
            .message-selection-act {
                padding: 10px 11px;
                min-width: 44px;
                min-height: 44px;
                box-sizing: border-box;
            }
        }
        @media (max-width: 900px) {
            .message-selection-bar {
                padding: 2px 0 8px;
                gap: 4px;
            }
            .message-selection-count {
                font-size: 14px;
                max-width: 38%;
            }
        }
        .msg.msg--selected {
            outline: 3px solid rgba(51, 144, 236, 0.85);
            outline-offset: 2px;
            border-radius: 14px;
            box-shadow: 0 8px 26px rgba(51, 144, 236, 0.12), 0 0 0 1px rgba(51, 144, 236, 0.12);
            position: relative;
        }
        .msg.me.msg--selected {
            outline-color: rgba(255, 255, 255, 0.88);
        }
        .msg.msg--selected::after {
            content: "✓";
            position: absolute;
            top: -10px;
            right: -10px;
            width: 22px;
            height: 22px;
            border-radius: 999px;
            background: #3390ec;
            color: #fff;
            font-weight: 800;
            font-size: 13px;
            display: grid;
            place-items: center;
            box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
            pointer-events: none;
        }
        .msg.me.msg--selected::after {
            background: rgba(255, 255, 255, 0.92);
            color: #3390ec;
        }
        .reply-preview-bar {
            display: none;
            align-items: center;
            gap: 10px;
            padding: 8px 12px;
            background: #e9f1ff;
            border-bottom: 1px solid #dbeafe;
            font-size: 13px;
            color: #1e293b;
            opacity: 0;
            transform: translateY(4px);
            transition: opacity var(--anim) var(--ease-out), transform var(--anim) var(--ease-out);
        }
        .reply-preview-bar.is-open {
            display: flex;
            opacity: 1;
            transform: translateY(0);
        }
        .reply-preview-bar .reply-preview-text { flex: 1; min-width: 0; }
        .reply-preview-bar button { flex-shrink: 0; padding: 4px 10px; font-size: 12px; }
        .forward-draft-bar {
            display: none;
            align-items: center;
            gap: 12px;
            padding: 10px 12px 10px 10px;
            background: linear-gradient(180deg, #f0f8ff 0%, #ffffff 100%);
            border-bottom: 1px solid rgba(51, 144, 236, 0.18);
            border-left: 3px solid #3390ec;
            margin-left: 0;
            font-size: 13px;
            opacity: 0;
            transform: translateY(4px);
            transition: opacity var(--anim) var(--ease-out), transform var(--anim) var(--ease-out);
        }
        .forward-draft-bar.is-open {
            display: flex;
            opacity: 1;
            transform: translateY(0);
        }
        .forward-draft-bar-icon {
            flex-shrink: 0;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: #fff;
            box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
            display: grid;
            place-items: center;
            color: #3390ec;
        }
        .forward-draft-bar-text { flex: 1; min-width: 0; }
        .forward-draft-bar-title {
            font-weight: 600;
            font-size: 14px;
            color: #3390ec;
            line-height: 1.25;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .forward-draft-bar-sub { font-size: 12px; color: #8b95a5; margin-top: 2px; line-height: 1.3; }
        .forward-draft-bar-close {
            flex-shrink: 0;
            border: none;
            background: transparent;
            color: #94a3b8;
            font-size: 20px;
            line-height: 1;
            padding: 6px 8px;
            cursor: pointer;
            border-radius: 8px;
            font-family: inherit;
        }
        .forward-draft-bar-close:hover { background: rgba(0, 0, 0, 0.06); color: #64748b; }
        .edit-draft-bar {
            display: none;
            align-items: center;
            gap: 10px;
            padding: 9px 12px 9px 10px;
            background: linear-gradient(180deg, #eef7ff 0%, #ffffff 100%);
            border-bottom: 1px solid rgba(51, 144, 236, 0.2);
            border-left: 3px solid #3390ec;
            font-size: 13px;
        }
        .edit-draft-bar-icon {
            flex-shrink: 0;
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: #fff;
            box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
            display: grid;
            place-items: center;
            color: #3390ec;
        }
        .edit-draft-bar-text { flex: 1; min-width: 0; }
        .edit-draft-bar-title {
            font-weight: 600;
            font-size: 14px;
            color: #3390ec;
            line-height: 1.25;
        }
        .edit-draft-bar-sub {
            font-size: 12px;
            color: #8b95a5;
            margin-top: 2px;
            line-height: 1.3;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .edit-draft-bar-close {
            flex-shrink: 0;
            border: none;
            background: transparent;
            color: #94a3b8;
            font-size: 20px;
            line-height: 1;
            padding: 6px 8px;
            cursor: pointer;
            border-radius: 8px;
            font-family: inherit;
        }
        .edit-draft-bar-close:hover { background: rgba(0, 0, 0, 0.06); color: #64748b; }
        .forward-modal .modal-card.forward-modal-card {
            max-width: 440px;
            padding: 0;
            overflow: hidden;
        }
        .forward-modal-title {
            margin: 0;
            padding: 16px 16px 8px;
            font-size: 17px;
            font-weight: 600;
            color: #0f172a;
        }
        .forward-modal-search-wrap {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 0 16px 10px;
            padding: 8px 12px;
            border-radius: 10px;
            background: #f1f5f9;
            border: 1px solid #e2e8f0;
            box-sizing: border-box;
        }
        .forward-modal-search-wrap svg { flex-shrink: 0; color: #94a3b8; }
        .forward-modal-search-wrap input {
            flex: 1;
            min-width: 0;
            border: none;
            background: transparent;
            font-size: 15px;
            font-family: inherit;
            outline: none;
        }
        .forward-modal-list {
            max-height: min(52vh, 420px);
            overflow: auto;
            padding: 0 4px 8px;
            -webkit-overflow-scrolling: touch;
        }
        .forward-modal-empty { padding: 16px; text-align: center; font-size: 14px; }
        .forward-modal-footer {
            display: flex;
            justify-content: flex-end;
            padding: 8px 12px 14px;
            border-top: 1px solid #f1f5f9;
        }
        .forward-modal-cancel {
            border: none;
            background: transparent;
            color: #3390ec;
            font-size: 15px;
            font-weight: 500;
            font-family: inherit;
            cursor: pointer;
            padding: 8px 12px;
            border-radius: 8px;
        }
        .forward-modal-cancel:hover { background: rgba(51, 144, 236, 0.08); }
        .forward-pick {
            display: flex;
            width: 100%;
            align-items: center;
            gap: 12px;
            padding: 10px 12px;
            margin: 0 0 2px;
            border: none;
            border-radius: 10px;
            background: transparent;
            cursor: pointer;
            text-align: left;
            font: inherit;
            color: inherit;
            box-sizing: border-box;
        }
        .forward-pick:hover { background: #f4f4f5; }
        .forward-pick-av {
            flex-shrink: 0;
            width: 44px;
            height: 44px;
            border-radius: 50%;
            overflow: hidden;
            background: #e8eef8;
            border: 1px solid #d6dfeb;
            display: grid;
            place-items: center;
        }
        .forward-pick-av img.avatar { width: 100%; height: 100%; object-fit: cover; border: 0; border-radius: 50%; }
        .forward-pick-main { flex: 1; min-width: 0; }
        .forward-pick-name { font-weight: 600; font-size: 15px; color: #0f172a; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .forward-pick-sub { font-size: 13px; color: #8b95a5; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .composer {
            width: 100%;
            box-sizing: border-box;
            padding: 8px 10px;
            display: flex;
            gap: 8px;
            align-items: flex-end;
            background: #ffffff;
        }
        .composer textarea#msg {
            flex: 1 1 auto;
            min-width: 0;
            width: 0;
            min-height: 44px;
            max-height: min(200px, 42dvh);
            resize: vertical;
            font-family: inherit;
            font-size: 15px;
            line-height: 1.35;
            border-radius: var(--radius-pill);
            border: 1px solid var(--border);
            background: var(--surface);
            padding: 10px 16px;
            margin: 0;
            overflow-y: hidden;
            box-sizing: border-box;
        }
        @media (max-width: 900px) {
            /* iOS Safari: предотвращаем focus-zoom, который ломает позиционирование */
            .composer textarea#msg {
                font-size: 16px;
                resize: none;
            }
        }
        .composer .composer-icon-btn,
        .composer #sendBtn {
            flex-shrink: 0;
            width: 44px;
            height: 44px;
            min-width: 44px;
            padding: 0;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            line-height: 1;
            touch-action: manipulation;
        }
        .composer .composer-icon-btn svg,
        .composer #sendBtn svg {
            display: block;
            width: 22px;
            height: 22px;
        }
        .composer .composer-icon-btn { color: #475569; }
        .composer .composer-icon-btn:hover { color: var(--accent); background: #fff; }
        .composer #sendBtn svg { width: 20px; height: 20px; }
        .composer #sendBtn:disabled {
            opacity: 0.55;
            cursor: not-allowed;
        }
        .composer #voiceBtn svg {
            width: 22px;
            height: 22px;
        }
        .voice-recording-panel {
            width: 100%;
            box-sizing: border-box;
            padding: 8px 10px;
            display: flex;
            align-items: center;
            gap: 10px;
            background: #ffffff;
            border-top: 1px solid var(--border);
        }
        .voice-recording-cancel {
            flex-shrink: 0;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border: 1px solid var(--border);
            background: var(--surface);
            color: #64748b;
            font-size: 18px;
            line-height: 1;
            cursor: pointer;
            touch-action: manipulation;
        }
        .voice-recording-cancel:hover {
            color: #0f172a;
            background: #f1f5f9;
        }
        .voice-recording-center {
            flex: 1;
            min-width: 0;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .voice-recording-dot {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #ef4444;
            animation: voiceRecPulse 1.1s ease-in-out infinite;
        }
        @keyframes voiceRecPulse {
            0%,
            100% {
                opacity: 1;
                transform: scale(1);
            }
            50% {
                opacity: 0.55;
                transform: scale(0.92);
            }
        }
        .voice-recording-timer {
            font-variant-numeric: tabular-nums;
            font-weight: 600;
            font-size: 15px;
            color: #0f172a;
        }
        .voice-recording-hint {
            font-size: 12px;
        }
        .voice-recording-send {
            flex-shrink: 0;
            width: 44px;
            height: 44px;
            border-radius: 50%;
            border: none;
            padding: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: var(--accent);
            color: #fff;
            cursor: pointer;
            touch-action: manipulation;
        }
        .voice-recording-send svg {
            width: 20px;
            height: 20px;
            display: block;
        }
        .voice-recording-send:hover {
            filter: brightness(1.05);
        }
        .msg-voice {
            margin: 4px 0 6px 0;
            max-width: min(340px, 100%);
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 6px;
            padding: 0;
            border-radius: 0;
            background: transparent;
            border: none;
            position: relative;
        }
        .msg-voice--loading .msg-voice-track {
            pointer-events: none;
            opacity: 0.72;
        }
        .msg.me .msg-voice {
            background: transparent;
            border-color: transparent;
        }
        .msg-voice-play {
            flex-shrink: 0;
            width: 34px;
            height: 34px;
            border-radius: 50%;
            border: none;
            padding: 0;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            background: #3390ec;
            color: #fff;
            font-size: 13px;
            line-height: 1;
            cursor: pointer;
            touch-action: manipulation;
        }
        .msg.me .msg-voice-play {
            background: rgba(255, 255, 255, 0.95);
            color: #3390ec;
        }
        .msg-voice-play:disabled {
            opacity: 0.45;
            cursor: default;
        }
        .msg-voice-play .msg-voice-play-icon--pause {
            display: none;
            font-size: 11px;
            letter-spacing: -2px;
        }
        .msg-voice-play.playing .msg-voice-play-icon--play {
            display: none;
        }
        .msg-voice-play.playing .msg-voice-play-icon--pause {
            display: inline;
        }
        .msg-voice-track {
            flex: 1 1 160px;
            min-width: 120px;
            height: 22px;
            position: relative;
            border-radius: 6px;
            overflow: hidden;
            background: rgba(15, 23, 42, 0.10);
            --vo-play: 0%;
            touch-action: none;
            user-select: none;
            -webkit-user-select: none;
        }
        .msg.me .msg-voice-track {
            background: rgba(255, 255, 255, 0.22);
        }
        .msg-voice-track--seekable:focus {
            outline: 2px solid rgba(51, 144, 236, 0.45);
            outline-offset: 2px;
        }
        .msg-voice-track--seekable:focus:not(:focus-visible) {
            outline: none;
        }
        .msg-voice-track--seekable {
            cursor: pointer;
        }
        .msg-voice-track--seekable.msg-voice-track--dragging {
            cursor: grabbing;
        }
        .msg-voice-wave {
            position: absolute;
            inset: 0;
            display: flex;
            align-items: center;
            gap: 2px;
            padding: 0 6px;
            pointer-events: none;
        }
        .msg-voice-bar {
            width: 2px;
            flex: 0 0 2px;
            border-radius: 999px;
            background: rgba(15, 23, 42, 0.32);
        }
        .msg.me .msg-voice-bar {
            background: rgba(255, 255, 255, 0.65);
        }
        .msg-voice-prog {
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            width: 100%;
            clip-path: inset(0 calc(100% - var(--vo-play, 0%)) 0 0);
            background: rgba(51, 144, 236, 0.22);
            pointer-events: none;
        }
        .msg.me .msg-voice-prog { background: rgba(255, 255, 255, 0.20); }
        .msg-voice-time {
            width: 100%;
            flex-basis: 100%;
            font-size: 11px;
            color: #64748b;
            font-variant-numeric: tabular-nums;
            padding-left: 42px;
            margin-top: -6px;
        }
        .msg.me .msg-voice-time {
            color: rgba(255, 255, 255, 0.82);
        }
        .msg-voice-err {
            width: 100%;
            flex-basis: 100%;
            font-size: 11px;
            line-height: 1.35;
            color: #b45309;
            padding-left: 48px;
            margin-top: 2px;
        }
        .msg.me .msg-voice-err {
            color: rgba(254, 243, 199, 0.95);
        }
        .msg-voice-upload {
            position: absolute;
            inset: 0;
            border-radius: 16px;
            background: rgba(255, 255, 255, 0.55);
            display: flex;
            flex-direction: column;
            align-items: stretch;
            justify-content: flex-end;
            padding: 6px 8px;
            pointer-events: none;
        }
        .msg.me .msg-voice-upload {
            background: rgba(15, 23, 42, 0.25);
        }
        .msg-voice-upload-bar {
            height: 4px;
            width: 0%;
            border-radius: 3px;
            background: #3390ec;
            align-self: flex-start;
        }
        .msg-voice-upload-pct {
            font-size: 11px;
            color: #475569;
            margin-top: 4px;
            align-self: flex-end;
        }
        .msg.me .msg-voice-upload-pct {
            color: rgba(255, 255, 255, 0.9);
        }
        .msg-reply { font-size: 12px; padding: 6px 8px; margin: 0 0 8px 0; border-left: 3px solid rgba(43, 124, 255, 0.55); background: rgba(15, 23, 42, 0.06); border-radius: 8px; color: #334155; }
        .msg.me .msg-reply { background: rgba(255, 255, 255, 0.18); border-left-color: rgba(255, 255, 255, 0.65); color: #f1f5f9; }
        .msg-reply.msg-reply--jump { cursor: pointer; transition: filter 0.15s ease, transform 0.1s ease; }
        .msg-reply.msg-reply--jump:hover { filter: brightness(0.96); }
        .msg-reply.msg-reply--jump:active { transform: scale(0.99); }
        .msg-highlight-jump { animation: msgJumpFlash 1.3s ease; outline: 2px solid rgba(43, 124, 255, 0.85); outline-offset: 2px; border-radius: 16px; }
        @keyframes msgJumpFlash {
            0% { outline-color: rgba(43, 124, 255, 0.95); }
            40% { outline-color: rgba(43, 124, 255, 0.55); }
            100% { outline-color: transparent; }
        }
        .msg.me.msg-highlight-jump { outline-color: rgba(255, 255, 255, 0.75); }
        /* Переслано — как в Telegram: полоска слева, строка «Переслано от» + аватар + имя, текст ниже */
        .msg-forward {
            margin: 0 0 10px 0;
            padding: 0;
            border: none;
            background: transparent;
            color: inherit;
        }
        .msg-forward__inner {
            border-left: 2px solid #3390ec;
            padding: 2px 0 2px 10px;
            margin: 0;
            border-radius: 0;
        }
        .msg.me .msg-forward__inner {
            border-left-color: rgba(255, 255, 255, 0.5);
        }
        .msg-forward__head {
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 6px 8px;
            line-height: 1.25;
        }
        .msg-forward__label {
            font-size: 14px;
            font-weight: 500;
            color: #3390ec;
        }
        .msg.me .msg-forward__label {
            color: rgba(255, 255, 255, 0.55);
        }
        .msg-forward__av {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            object-fit: cover;
            flex-shrink: 0;
            background: rgba(255, 255, 255, 0.35);
            border: 1px solid rgba(51, 144, 236, 0.18);
            vertical-align: middle;
        }
        .msg.me .msg-forward__av {
            border-color: rgba(255, 255, 255, 0.35);
            background: rgba(255, 255, 255, 0.2);
        }
        .msg-forward__name {
            font-size: 14px;
            font-weight: 600;
            color: #3390ec;
            line-height: 1.25;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            max-width: 100%;
        }
        .msg.me .msg-forward__name {
            color: #fff;
        }
        .msg-forward__name--link {
            cursor: pointer;
            text-decoration: none;
            border: none;
            background: transparent;
            font: inherit;
            padding: 0;
            text-align: left;
        }
        .msg-forward__name--link:hover {
            text-decoration: underline;
            text-underline-offset: 2px;
        }
        .msg-forward__name--link:focus-visible {
            outline: 2px solid #3390ec;
            outline-offset: 2px;
            border-radius: 4px;
        }
        .msg.me .msg-forward__name--link:focus-visible {
            outline-color: rgba(255, 255, 255, 0.85);
        }
        .msg-forward__preview {
            margin-top: 5px;
            font-size: 15px;
            line-height: 1.45;
            white-space: pre-wrap;
            word-break: break-word;
            color: #0f172a;
        }
        .msg.me .msg-forward__preview {
            color: rgba(255, 255, 255, 0.96);
        }
        .msg-forward-comment {
            margin: 0 0 8px 0;
            font-size: 15px;
            line-height: 1.45;
            white-space: pre-wrap;
            word-break: break-word;
            color: #0f172a;
        }
        .msg.me .msg-forward-comment {
            color: #fff;
        }
        .msg-read-ticks { margin-left: 4px; margin-right: 2px; }
        .msg-read-ticks--incoming { cursor: default; }
        .msg-read-ticks--incoming.msg-read-ticks--in-read,
        .msg-read-ticks--incoming.msg-read-ticks--in-unread { color: #8fa2b8; }
        .msg-context-menu { position: fixed; z-index: 450; background: #fff; border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12); padding: 0; min-width: 180px; max-width: min(92vw, 288px); max-height: min(85dvh, calc(100vh - 24px)); display: none; overflow-x: hidden; overflow-y: auto; -webkit-overflow-scrolling: touch; }
        .msg-context-menu.open { display: block; }
        .ctx-readers-block { padding: 10px 12px; border-bottom: 1px solid #e2e8f0; background: #f8fafc; }
        .ctx-readers-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; margin-bottom: 8px; }
        .ctx-readers-hint { display: block; margin-top: 4px; font-weight: 500; text-transform: none; letter-spacing: normal; color: #94a3b8; font-size: 11px; line-height: 1.3; }
        .ctx-readers-chips { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
        .ctx-reader-chip { display: flex; flex-direction: column; align-items: center; width: 64px; gap: 4px; cursor: pointer; border-radius: 10px; padding: 4px 2px; margin: -4px -2px; }
        .ctx-reader-chip:hover { background: #f1f5f9; }
        .ctx-reader-av { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #e2e8f0; border: 1px solid #cbd5e1; }
        .ctx-reader-name { font-size: 11px; line-height: 1.2; color: #0f172a; text-align: center; word-break: break-word; max-width: 64px; }
        .ctx-readers-toggle { display: block; width: 100%; margin-top: 8px; text-align: left; border: 0; background: transparent; padding: 6px 0; font-size: 13px; color: #2563eb; cursor: pointer; font-weight: 600; }
        .ctx-readers-toggle:hover { text-decoration: underline; }
        .ctx-readers-list { max-height: 200px; overflow-y: auto; margin-top: 6px; -webkit-overflow-scrolling: touch; }
        .ctx-readers-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 0 -10px; border-bottom: 1px solid #f1f5f9; font-size: 14px; cursor: pointer; border-radius: 8px; }
        .ctx-readers-row:last-child { border-bottom: 0; }
        .ctx-readers-row:hover { background: #f8fafc; }
        .ctx-readers-row .ctx-reader-av { width: 32px; height: 32px; flex-shrink: 0; }
        .ctx-menu-actions { padding: 4px; }
        .msg-context-menu .ctx-menu-actions button {
            display: flex;
            align-items: center;
            gap: 10px;
            width: 100%;
            text-align: left;
            border: 0;
            background: #fff;
            padding: 9px 12px;
            border-radius: 8px;
            font-size: 14px;
            font-weight: 500;
            color: #0f172a;
            cursor: pointer;
        }
        .msg-context-menu .ctx-menu-actions button:hover { background: #f1f5f9; }
        .msg-context-menu .ctx-menu-actions .ctx-menu-ico {
            width: 20px;
            height: 20px;
            flex-shrink: 0;
            color: #707579;
        }
        .msg-context-menu .ctx-menu-actions .ctx-menu-ico.ctx-menu-ico--fill { stroke: none; }
        .msg-context-menu .ctx-menu-actions button:hover .ctx-menu-ico { color: #3390ec; }
        .msg-context-menu .ctx-menu-actions button.ctx-menu-danger { color: #e53935; }
        .msg-context-menu .ctx-menu-actions button.ctx-menu-danger .ctx-menu-ico { color: #e53935; }
        .msg-context-menu .ctx-menu-actions button.ctx-menu-danger:hover { background: rgba(229, 57, 53, 0.08); color: #c62828; }
        .msg-context-menu .ctx-menu-actions button.ctx-menu-danger:hover .ctx-menu-ico { color: #c62828; }
        .status { font-size: 12px; color: #6b7280; }
        .modal {
            position: fixed;
            inset: 0;
            z-index: 300;
            background: rgba(15, 23, 42, 0.38);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            display: none;
            align-items: center;
            justify-content: center;
            padding: 16px;
            padding-top: max(16px, env(safe-area-inset-top));
            padding-bottom: max(16px, env(safe-area-inset-bottom));
        }
        .modal.open { display: flex; }
        .modal-card { width: 100%; max-width: 460px; background: var(--surface); border-radius: 16px; border: 1px solid var(--border); padding: 16px; box-shadow: var(--shadow); }
        .avatar-crop-card { max-width: 420px; }
        .avatar-crop-stage-wrap {
            position: relative;
            width: 320px;
            height: 320px;
            margin: 8px auto 0;
            border-radius: 14px;
            overflow: hidden;
            background: #0f172a;
        }
        #avatarCropCanvas {
            display: block;
            width: 320px;
            height: 320px;
            touch-action: none;
            cursor: grab;
            user-select: none;
            -webkit-user-select: none;
            -webkit-touch-callout: none;
        }
        #avatarCropCanvas:active { cursor: grabbing; }
        .avatar-crop-circle {
            position: absolute;
            inset: 12px;
            border-radius: 50%;
            border: 2px solid rgba(255,255,255,.95);
            box-shadow: 0 0 0 9999px rgba(15,23,42,.35);
            pointer-events: none;
        }
        .avatar-crop-rect {
            position: absolute;
            border: 2px solid rgba(255,255,255,.96);
            box-shadow: 0 0 0 9999px rgba(15,23,42,.35);
            border-radius: 8px;
            display: none;
            touch-action: none;
        }
        .avatar-crop-handle {
            position: absolute;
            width: 18px;
            height: 18px;
            background: #fff;
            border: 1px solid #cbd5e1;
            border-radius: 999px;
            box-shadow: 0 0 0 8px rgba(255,255,255,.001);
            touch-action: none;
        }
        .avatar-crop-handle.tl { left: -9px; top: -9px; cursor: nwse-resize; }
        .avatar-crop-handle.tr { right: -9px; top: -9px; cursor: nesw-resize; }
        .avatar-crop-handle.bl { left: -9px; bottom: -9px; cursor: nesw-resize; }
        .avatar-crop-handle.br { right: -9px; bottom: -9px; cursor: nwse-resize; }
        .avatar-crop-controls { margin-top: 12px; }
        .avatar-crop-controls input[type="range"] { width: 100%; }
        .profile-avatar-frame {
            display: flex;
            width: 100%;
            box-sizing: border-box;
            align-items: center;
            justify-content: center;
            margin: 0 0 12px 0;
        }
        .profile-avatar-frame .profile-avatar-lg {
            display: block;
            flex-shrink: 0;
        }
        .profile-avatar-lg {
            width: min(220px, 78vw) !important;
            height: min(220px, 78vw) !important;
            max-width: 100%;
            cursor: zoom-in;
            border-radius: 50%;
            object-fit: cover;
            box-sizing: border-box;
            border: 2px solid #e2e8f0;
            box-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
        }
        .profile-action-stack {
            display: flex;
            flex-direction: column;
            align-items: center;
            gap: 10px;
            margin-top: 8px;
            padding: 0 12px 12px;
        }
        .profile-action-stack .profile-action-btn {
            width: 100%;
            max-width: 280px;
            padding: 12px 22px;
            font-size: 15px;
            font-weight: 600;
            border-radius: 12px;
            box-sizing: border-box;
            justify-content: center;
        }
        .profile-action-stack .profile-action-btn--write {
            box-shadow: 0 4px 14px rgba(43, 124, 255, 0.28);
        }
        .contacts-pick { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow: auto; margin: 8px 0; }
        .contact-pick { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border: 1px solid #e6ecf2; border-radius: 10px; cursor: pointer; background: #fff; }
        .contact-pick.selected { border-color: #2b7cff; background: #e9f1ff; }
        .member-row-tg { display: flex; align-items: center; gap: 10px; padding: 10px 8px; margin: 0 -6px; border-radius: 12px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
        .member-row-tg { position: relative; }
        .member-row-tg:last-child { border-bottom: 0; }
        .member-row-tg:hover { background: #f8fafc; }
        .member-row-av { width: 40px; height: 40px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: #e8eef8; border: 1px solid #e2e8f0; display: grid; place-items: center; font-size: 20px; }
        .member-row-av img { width: 100%; height: 100%; object-fit: cover; border: 0; }
        .member-row-main { flex: 1; min-width: 0; }
        .member-name { font-weight: 600; font-size: 15px; color: #0f172a; }
        .member-name,
        .member-meta {
            max-width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .member-meta { font-size: 12px; margin-top: 2px; color: #64748b; }
        .member-meta.member-meta--online {
            color: #34c759;
        }
        .member-row-right { flex-shrink: 0; display: flex; justify-content: flex-end; align-items: center; gap: 6px; min-width: 40px; }
        .member-more-btn {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            border: none;
            padding: 0;
            display: grid;
            place-items: center;
            background: rgba(15, 23, 42, 0.06);
            color: #334155;
            cursor: pointer;
            font-size: 20px;
            line-height: 1;
            font-family: inherit;
            -webkit-tap-highlight-color: transparent;
        }
        .member-more-btn:hover {
            background: rgba(15, 23, 42, 0.10);
        }
        .member-more-btn:active {
            transform: scale(0.98);
        }

        .member-more-menu {
            position: absolute;
            right: 8px;
            top: 50px;
            z-index: 50;
            display: flex;
            flex-direction: column;
            gap: 4px;
            min-width: 190px;
            padding: 8px;
            background: #fff;
            border: 1px solid rgba(0, 0, 0, 0.08);
            border-radius: 12px;
            box-shadow: 0 16px 48px rgba(15, 23, 42, 0.14);
        }

        .member-more-menu-item {
            border: none;
            background: transparent;
            padding: 10px 10px;
            border-radius: 10px;
            text-align: left;
            cursor: pointer;
            font-size: 14px;
            color: #0f172a;
            -webkit-tap-highlight-color: transparent;
        }
        .member-more-menu-item:hover {
            background: rgba(51, 144, 236, 0.10);
        }

        .member-more-menu-item--danger,
        button.member-more-menu-item--danger {
            color: #e53935;
        }
        .member-chevron { color: #cbd5e1; font-size: 22px; line-height: 1; font-weight: 300; }
        button.member-kick-btn {
            padding: 0 !important;
            min-width: 36px !important;
            width: 36px;
            height: 36px;
            border-radius: 50% !important;
            font-size: 16px;
            line-height: 1;
            background: transparent !important;
            color: #aeb7c2 !important;
            border: none !important;
            box-shadow: none !important;
        }
        button.member-kick-btn:hover {
            background: rgba(0, 0, 0, 0.06) !important;
            color: #e53935 !important;
        }
        button.member-role-btn {
            height: 30px;
            min-width: 92px;
            padding: 0 10px !important;
            border-radius: 10px !important;
            border: 1px solid #d7e2f3 !important;
            background: #f3f7ff !important;
            color: #35507a !important;
            font-size: 12px !important;
            font-weight: 600;
            line-height: 28px;
            box-shadow: none !important;
            text-align: center;
        }
        button.member-role-btn:hover {
            background: #e8f0ff !important;
            color: #1f3d69 !important;
        }
        /* Модалка «Участники» — центрированный заголовок, сетка как в системных sheet */
        .group-members-card {
            max-width: 420px;
            padding: 0;
            overflow: hidden;
            border-radius: 16px;
            background: #fff;
            border: 1px solid rgba(0, 0, 0, 0.06);
            box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12);
        }
        .gm-header--sheet {
            display: grid;
            grid-template-columns: 44px 1fr 44px;
            align-items: center;
            gap: 0;
            padding: 12px 8px 14px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.07);
            background: linear-gradient(180deg, #fafbfc 0%, #fff 100%);
        }
        .gm-header-center {
            text-align: center;
            min-width: 0;
        }
        .gm-header-side {
            width: 44px;
            min-height: 1px;
        }
        .gm-header-side--end {
            display: flex;
            justify-content: flex-end;
            align-items: center;
        }
        .gm-header-close {
            position: static;
            width: 40px;
            height: 40px;
            margin: 0;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #94a3b8;
            font-size: 28px;
            line-height: 1;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            -webkit-tap-highlight-color: transparent;
        }
        .gm-header-close:hover {
            background: rgba(0, 0, 0, 0.06);
            color: #475569;
        }
        .group-members-card .gm-header-center h3 {
            margin: 0;
            font-size: 18px;
            font-weight: 600;
            letter-spacing: -0.02em;
            color: #0f172a;
            line-height: 1.25;
        }
        .group-members-card .gm-subtitle {
            margin: 4px 0 0;
            font-size: 13px;
            color: #64748b;
            font-weight: 500;
        }
        .group-members-card .gm-invite-row {
            padding: 12px 16px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.06);
        }
        .group-members-card .gm-invite-row .muted {
            display: block;
            margin-bottom: 8px;
            font-size: 13px;
            color: #707579;
            line-height: 1.35;
        }
        .group-members-card .gm-copy-link-btn,
        .group-invite-picker-card .gm-copy-link-btn {
            width: 100%;
            box-sizing: border-box;
            padding: 10px 14px;
            border-radius: 10px;
            font-size: 15px;
            font-weight: 500;
            background: #f4f4f5 !important;
            color: #3390ec !important;
            border: none !important;
        }
        .group-members-card .gm-copy-link-btn:hover,
        .group-invite-picker-card .gm-copy-link-btn:hover {
            background: #eaecef !important;
        }
        .group-members-card .gm-members-list {
            max-height: min(42vh, 320px);
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        /* В карточке группы список не в отдельном скролле — прокручивается вся модалка */
        .chat-info-members-embed .gm-members-list {
            max-height: none;
            overflow: visible;
        }
        .group-members-card .gm-members-list .member-row-tg,
        .chat-info-members-embed .gm-members-list .member-row-tg {
            padding: 10px 16px;
            margin: 0;
            border-radius: 0;
        }
        .group-members-card .gm-add-block {
            padding: 12px 16px 16px;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
            background: #fafafa;
        }
        .chat-info-members-embed .gm-add-block {
            padding: 12px 16px 14px;
            border-top: none;
            border-bottom: 1px solid rgba(0, 0, 0, 0.06);
            background: #fafafa;
        }
        .gm-add-member-btn {
            width: 100%;
            box-sizing: border-box;
            padding: 12px 16px;
            border-radius: 10px;
            font-size: 16px;
            font-weight: 500;
            border: 1px solid rgba(51, 144, 236, 0.45) !important;
            background: #fff !important;
            color: #3390ec !important;
            cursor: pointer;
        }
        .gm-add-member-btn:hover {
            background: rgba(51, 144, 236, 0.06) !important;
        }
        .group-members-card .gm-footer,
        .chat-info-members-embed .gm-footer {
            display: flex;
            flex-direction: column;
            gap: 10px;
            padding: 12px 16px 16px;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
            background: #fff;
        }
        .group-members-card .gm-footer-leave,
        .chat-info-members-embed .gm-footer-leave {
            width: 100%;
            box-sizing: border-box;
            margin: 0 !important;
            padding: 12px 16px !important;
            border-radius: 10px !important;
            font-size: 16px !important;
            font-weight: 500 !important;
            background: #fff !important;
            color: #3390ec !important;
            border: 1px solid rgba(51, 144, 236, 0.4) !important;
        }
        .group-members-card .gm-footer-leave:hover,
        .chat-info-members-embed .gm-footer-leave:hover {
            background: rgba(51, 144, 236, 0.06) !important;
        }
        .group-members-card .gm-footer-delete,
        .chat-info-members-embed .gm-footer-delete {
            width: 100%;
            box-sizing: border-box;
            margin: 0 !important;
            padding: 10px 16px !important;
            border-radius: 10px !important;
            font-size: 15px !important;
            font-weight: 500 !important;
            background: transparent !important;
            color: #e53935 !important;
            border: none !important;
            box-shadow: none !important;
        }
        .group-members-card .gm-footer-delete:hover,
        .chat-info-members-embed .gm-footer-delete:hover {
            background: rgba(229, 57, 53, 0.08) !important;
        }
        /* Второе окно: добавить участника */
        .group-invite-picker-modal.modal {
            z-index: 340;
        }
        .group-invite-picker-card {
            max-width: 400px;
            padding: 0;
            overflow: hidden;
            border-radius: 16px;
            background: #fff;
            border: 1px solid rgba(0, 0, 0, 0.06);
            box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12);
        }
        .gip-head--sheet {
            display: grid;
            grid-template-columns: 44px 1fr 44px;
            align-items: center;
            padding: 12px 8px 12px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.07);
            background: linear-gradient(180deg, #fafbfc 0%, #fff 100%);
        }
        .gip-head--sheet .gm-header-center h3 {
            margin: 0;
            font-size: 17px;
            font-weight: 600;
            color: #0f172a;
            letter-spacing: -0.02em;
        }
        .gip-search-block {
            padding: 12px 16px 14px;
            background: #fff;
        }
        .gip-invite-tools {
            margin-bottom: 12px;
        }
        .gip-invite-tools .muted {
            display: block;
            margin-bottom: 8px;
            font-size: 13px;
            color: #707579;
            line-height: 1.35;
        }
        .group-invite-picker-card .gip-search {
            width: 100%;
            box-sizing: border-box;
            margin: 0;
            padding: 11px 14px;
            border-radius: 12px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            font-size: 16px;
            background: #f4f4f5;
        }
        .group-invite-picker-card .gip-search:focus {
            outline: none;
            border-color: rgba(51, 144, 236, 0.45);
            background: #fff;
        }
        .invite-picker-list {
            max-height: min(50vh, 280px);
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        .invite-picker-list .contact-pick {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 16px;
            margin: 0;
            border: none;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            border-radius: 0;
            background: #fff;
            cursor: pointer;
            font-size: 15px;
        }
        .invite-picker-list .contact-pick:hover {
            background: #f4f4f5;
        }
        .invite-picker-list .contact-pick:last-child {
            border-bottom: none;
        }
        .invite-picker-empty {
            padding: 20px 16px;
            text-align: center;
            font-size: 14px;
        }
        .invite-picker-tag-row {
            display: block;
            width: 100%;
            box-sizing: border-box;
            margin: 0;
            padding: 14px 16px;
            border: none;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
            background: #fff;
            font-size: 15px;
            text-align: left;
            color: #3390ec;
            cursor: pointer;
            font-weight: 500;
        }
        .invite-picker-tag-row:hover {
            background: #f4f4f5;
        }
        .invite-picker-tag-row strong {
            font-weight: 600;
        }
        .modal-card h3 { margin: 0 0 10px 0; font-size: 17px; }
        .chat-info-card {
            max-height: 85vh;
            display: flex;
            flex-direction: column;
            min-height: 0;
            border-radius: 16px;
            overflow-x: hidden;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
            border: 1px solid rgba(0, 0, 0, 0.06);
            box-shadow: 0 16px 48px rgba(15, 23, 42, 0.12);
        }
        .chat-info-modal__top--sheet {
            display: grid;
            grid-template-columns: 44px 1fr 44px;
            align-items: start;
            gap: 0;
            padding: 8px 8px 4px;
            flex-shrink: 0;
        }
        .chat-info-modal__brand {
            text-align: center;
            min-width: 0;
            padding: 0 4px 8px;
        }
        .chat-info-modal__title {
            margin: 0 0 6px 0;
            font-size: 18px;
            font-weight: 600;
            letter-spacing: -0.02em;
            color: #0f172a;
            line-height: 1.25;
        }
        .chat-info-modal__subtitle {
            font-size: 13px;
            margin: 0 0 10px 0;
            line-height: 1.4;
            color: #64748b;
        }

        .chat-info-rename-group {
            margin: 0 0 10px 0;
            padding: 10px 12px;
            border-radius: 12px;
            background: var(--surface-muted);
            border: 1px solid var(--border);
        }

        .chat-info-rename-group__label {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.04em;
            text-transform: uppercase;
            margin-bottom: 6px;
        }

        .chat-info-rename-group__row {
            display: flex;
            gap: 8px;
            align-items: center;
        }

        .chat-info-rename-group__input {
            flex: 1;
            min-width: 0;
            border-radius: 10px;
            border: 1px solid var(--border);
            padding: 10px 12px;
            font-size: 14px;
            font-family: inherit;
            background: #fff;
        }

        .chat-info-rename-group__save {
            border-radius: 10px;
            border: none;
            background: #3390ec;
            color: #fff;
            font-weight: 700;
            padding: 10px 14px;
            cursor: pointer;
            font-size: 14px;
            white-space: nowrap;
            -webkit-tap-highlight-color: transparent;
        }

        .chat-info-rename-group__save:active {
            transform: scale(0.98);
        }
        .chat-info-quick-actions {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 8px;
            padding: 0 2px 12px;
            flex-shrink: 0;
        }

        .group-settings-body {
            padding: 12px;
            display: flex;
            flex-direction: column;
            gap: 12px;
        }
        .group-settings-section {
            border: 1px solid var(--border);
            background: var(--surface-muted);
            border-radius: 12px;
            padding: 12px;
        }
        .group-settings-label {
            font-size: 11px;
            font-weight: 800;
            letter-spacing: 0.04em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 8px;
        }
        .group-settings-row {
            display: flex;
            gap: 8px;
            align-items: center;
        }
        #groupSettingsTitleInput {
            flex: 1;
            min-width: 0;
            border-radius: 10px;
            border: 1px solid var(--border);
            padding: 10px 12px;
            font-size: 14px;
            font-family: inherit;
            background: #fff;
        }
        .group-settings-primary {
            border-radius: 10px;
            border: none;
            background: #3390ec;
            color: #fff;
            font-weight: 800;
            padding: 10px 14px;
            cursor: pointer;
            font-size: 14px;
            white-space: nowrap;
        }
        .group-settings-action {
            width: 100%;
            border: none;
            background: #fff;
            border-radius: 10px;
            padding: 12px 12px;
            text-align: left;
            cursor: pointer;
            font-size: 14px;
            font-weight: 700;
            color: #0f172a;
            box-shadow: 0 0 0 1px var(--border);
        }
        .group-settings-action + .group-settings-action {
            margin-top: 8px;
        }
        .group-settings-toggle {
            display: grid;
            grid-template-columns: 44px 1fr;
            column-gap: 12px;
            align-items: center;
            font-size: 14px;
            line-height: 1.25;
            padding: 12px 0;
            user-select: none;
        }
        .group-settings-toggle input {
            position: absolute;
            opacity: 0;
            width: 1px;
            height: 1px;
            margin: 0;
            pointer-events: none;
        }
        .group-settings-switch {
            width: 44px;
            height: 26px;
            border-radius: 999px;
            background: rgba(15, 23, 42, 0.16);
            border: 1px solid rgba(15, 23, 42, 0.14);
            position: relative;
            flex: 0 0 auto;
            transition: background 0.14s ease, border-color 0.14s ease;
            justify-self: start;
        }
        .group-settings-switch::after {
            content: "";
            position: absolute;
            top: 50%;
            left: 2px;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background: #fff;
            box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
            transform: translateY(-50%);
            transition: transform 0.14s ease;
        }
        .group-settings-toggle input:checked + .group-settings-switch {
            background: rgba(51, 144, 236, 0.85);
            border-color: rgba(51, 144, 236, 0.85);
        }
        .group-settings-toggle input:checked + .group-settings-switch::after {
            transform: translateX(18px) translateY(-50%);
        }
        .group-settings-toggle:active .group-settings-switch::after {
            transform: translateX(1px) translateY(-50%) scaleX(1.05);
        }

        .chat-info-settings-head {
            display: grid;
            grid-template-columns: 44px 1fr 44px;
            align-items: center;
            gap: 0;
            padding: 10px 8px 8px;
            position: sticky;
            top: 0;
            background: linear-gradient(180deg, #fff 0%, rgba(255, 255, 255, 0.96) 100%);
            border-bottom: 1px solid rgba(0, 0, 0, 0.06);
            z-index: 2;
        }
        .chat-info-settings-title {
            text-align: center;
            font-size: 15px;
            font-weight: 800;
            color: #0f172a;
        }
        /* Кнопка "назад" берёт стиль из .chat-date-jump-nav */
        .group-settings-foot {
            padding: 0 12px 12px 12px;
        }
        .chat-info-qbtn {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 6px;
            margin: 0;
            padding: 10px 4px;
            border: none;
            border-radius: 12px;
            background: var(--surface-muted);
            color: var(--accent);
            cursor: pointer;
            font-family: inherit;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease, transform 0.08s ease;
            box-shadow: 0 0 0 1px var(--border);
        }
        .chat-info-qbtn:hover {
            background: #e8eef8;
        }
        .chat-info-qbtn:active {
            transform: scale(0.98);
        }
        .chat-info-qbtn__ico {
            display: flex;
            align-items: center;
            justify-content: center;
            color: var(--accent);
        }
        .chat-info-qbtn__ico svg {
            display: block;
        }
        .chat-info-qbtn__lab {
            font-size: 11px;
            font-weight: 600;
            color: var(--text-muted);
            line-height: 1.2;
            text-align: center;
            max-width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .chat-info-desc {
            margin: 0 0 12px;
            padding: 12px 14px;
            border-radius: 12px;
            background: var(--surface-muted);
            border: 1px solid var(--border);
            box-sizing: border-box;
        }
        .chat-info-desc__label {
            display: block;
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 0.04em;
            text-transform: uppercase;
            color: var(--text-muted);
            margin-bottom: 6px;
        }
        .chat-info-desc__text {
            margin: 0;
            font-size: 14px;
            line-height: 1.45;
            color: var(--text);
            word-break: break-word;
        }
        .chat-info-primary-tabs {
            display: none;
            flex-wrap: wrap;
            align-items: center;
            justify-content: center;
            gap: 6px;
            padding: 2px 4px 12px;
            flex-shrink: 0;
        }
        .chat-info-pill {
            padding: 8px 16px;
            border: none;
            border-radius: 999px;
            background: transparent;
            font-size: 14px;
            font-weight: 600;
            line-height: 1.2;
            color: var(--text-muted);
            cursor: pointer;
            font-family: inherit;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease, color 0.12s ease;
        }
        .chat-info-pill:hover {
            background: rgba(0, 0, 0, 0.05);
            color: var(--text);
        }
        .chat-info-pill.active {
            background: var(--accent-soft);
            color: var(--accent);
        }
        .chat-info-primary-panel {
            flex-shrink: 0;
            min-height: 0;
        }
        .chat-info-primary-panel--media {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-height: 0;
            overflow: hidden;
        }
        .chat-info-primary-panel--members {
            flex: 0 1 auto;
            display: flex;
            flex-direction: column;
            min-height: 0;
            overflow: visible;
        }
        .chat-info-primary-panel--settings {
            flex: 1;
            display: flex;
            flex-direction: column;
            min-height: 0;
            overflow: auto;
            -webkit-overflow-scrolling: touch;
        }
        .chat-info-primary-panel--settings .group-settings-body {
            flex: 1;
            min-height: 0;
        }
        .chat-info-members-embed {
            flex: 0 1 auto;
            display: flex;
            flex-direction: column;
            min-height: 0;
            overflow: visible;
            border-radius: 12px;
            border: 1px solid rgba(0, 0, 0, 0.06);
            background: #fafafa;
        }
        .chat-info-setting-toggle {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 12px 8px;
            font-size: 14px;
            color: #1f2937;
            border-top: 1px solid rgba(0, 0, 0, 0.06);
        }
        .chat-info-setting-toggle input[type="checkbox"] {
            width: 17px;
            height: 17px;
            margin: 0;
            accent-color: var(--accent);
            cursor: pointer;
        }
        .chat-info-members-sheet {
            padding: 4px 2px 8px;
        }
        .chat-info-members-lead {
            margin: 0 0 12px;
            font-size: 13px;
            line-height: 1.45;
        }
        .chat-info-members-cta {
            width: 100%;
            box-sizing: border-box;
            padding: 12px 16px;
            border-radius: 12px;
            border: 1px solid rgba(51, 144, 236, 0.45);
            background: #fff;
            color: var(--accent);
            font-size: 15px;
            font-weight: 600;
            font-family: inherit;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
        }
        .chat-info-members-cta:hover {
            background: rgba(51, 144, 236, 0.06);
        }
        .chat-info-modal__close {
            border: none;
            background: transparent;
            width: 40px;
            height: 40px;
            border-radius: 50%;
            font-size: 26px;
            line-height: 1;
            color: #707579;
            cursor: pointer;
            display: grid;
            place-items: center;
            font-family: inherit;
            flex-shrink: 0;
        }
        .chat-info-modal__close:hover {
            background: rgba(0, 0, 0, 0.06);
            color: #0f172a;
        }
        .chat-info-hero {
            display: none;
            flex-direction: column;
            align-items: center;
            margin: 0 0 10px 0;
        }
        .chat-info-hero__avatar-wrap {
            position: relative;
            width: 96px;
            height: 96px;
            flex-shrink: 0;
            cursor: pointer;
        }
        .chat-info-hero__avatar {
            width: 96px;
            height: 96px;
            border-radius: 50%;
            object-fit: cover;
            border: 1px solid rgba(0, 0, 0, 0.08);
            background: #e8eef8;
        }
        .chat-info-hero__placeholder {
            width: 96px;
            height: 96px;
            border-radius: 50%;
            background: linear-gradient(145deg, #e8eef8, #dbeafe);
            display: grid;
            place-items: center;
            font-size: 40px;
            border: 1px solid rgba(0, 0, 0, 0.06);
        }
        .chat-info-hero__camera {
            position: absolute;
            right: -2px;
            bottom: -2px;
            width: 34px;
            height: 34px;
            border-radius: 50%;
            border: 2px solid #fff;
            background: #3390ec;
            color: #fff;
            display: grid;
            place-items: center;
            cursor: pointer;
            padding: 0;
            box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
        }
        .chat-info-hero__camera:hover {
            filter: brightness(1.05);
        }
        .chat-info-hero__camera svg {
            display: block;
        }
        .group-avatar-flash {
            position: fixed;
            inset: 0;
            z-index: 520;
            display: none;
            align-items: center;
            justify-content: center;
            background: rgba(15, 23, 42, 0.42);
            pointer-events: none;
        }
        .group-avatar-flash.show {
            display: flex;
        }
        .group-avatar-flash__inner img {
            max-width: min(280px, 72vw);
            max-height: min(280px, 42vh);
            border-radius: 16px;
            box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
            object-fit: cover;
        }
        .chat-info-tabs {
            display: flex;
            gap: 0;
            /* Нельзя тянуть вкладки отрицательным margin за пределы скруглённого блока с overflow:hidden
             * (например .profile-peer-media-wrap) — нижняя граница крайних вкладок обрезается по дуге и «уезжает». */
            margin: 0 0 10px 0;
            padding: 0 6px;
            border-bottom: 1px solid var(--border);
            flex-shrink: 0;
            overflow-x: auto;
            overflow-y: visible;
            scroll-padding-inline: 6px;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
            -ms-overflow-style: none;
        }
        .chat-info-tabs::-webkit-scrollbar {
            display: none;
            width: 0;
            height: 0;
        }
        .chat-info-primary-panel--media > .chat-info-tabs {
            margin-top: 0;
        }
        .chat-info-tab {
            flex: 1;
            min-width: 72px;
            margin: 0;
            padding: 10px 6px 11px;
            border: none;
            border-bottom: 3px solid transparent;
            margin-bottom: -1px;
            border-radius: 0;
            background: transparent;
            font: inherit;
            font-size: 13px;
            font-weight: 600;
            color: var(--text-muted);
            cursor: pointer;
            white-space: nowrap;
            text-align: center;
            transition: color 0.12s ease, border-color 0.12s ease;
            box-sizing: border-box;
            appearance: none;
            -webkit-appearance: none;
        }
        /* Глобальный outline у button:focus-visible здесь обрезается overflow и визуально «уезжает» */
        .chat-info-tab:focus,
        .chat-info-tab:focus-visible {
            outline: none;
        }
        .chat-info-tab:focus-visible:not(.active) {
            background: rgba(51, 144, 236, 0.1);
        }
        .chat-info-tab:hover {
            color: var(--text);
        }
        .chat-info-tab.active {
            color: var(--accent);
            border-bottom-color: var(--accent);
        }
        .chat-info-tab-panels {
            flex: 1;
            min-height: 0;
            display: flex;
            flex-direction: column;
            overflow: hidden;
            position: relative;
        }
        .chat-info-panel {
            display: flex;
            flex-direction: column;
            min-height: 0;
            flex: 1;
            overflow: hidden;
            position: absolute;
            inset: 0;
            opacity: 0;
            transform: translateX(6px);
            pointer-events: none;
            transition: opacity var(--anim) var(--ease-out), transform var(--anim) var(--ease-out);
        }
        .chat-info-panel.show {
            opacity: 1;
            transform: translateX(0);
            pointer-events: auto;
        }
        .chat-info-panel .chat-media-section-title {
            display: none;
        }
        .chat-info-panel .chat-media-grid {
            max-height: min(52vh, 380px);
        }
        .chat-info-panel .chat-doc-list {
            max-height: min(52vh, 380px);
        }
        .chat-link-list {
            display: flex;
            flex-direction: column;
            gap: 0;
            max-height: min(52vh, 380px);
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        #profilePanel.profile-panel--rail .chat-info-panel .chat-media-grid,
        #profilePanel.profile-panel--rail .chat-info-panel .chat-doc-list,
        #profilePanel.profile-panel--rail .chat-link-list {
            max-height: none;
            overflow: visible;
        }
        .chat-link-row {
            display: flex;
            flex-direction: column;
            gap: 4px;
            padding: 12px 10px;
            border-bottom: 1px solid var(--border);
            cursor: pointer;
            text-align: left;
            background: transparent;
            font: inherit;
            color: inherit;
            width: 100%;
            box-sizing: border-box;
        }
        .chat-link-row:first-child {
            padding-top: 8px;
        }
        .chat-link-row:active {
            background: rgba(15, 23, 42, 0.04);
        }
        .chat-link-url {
            font-size: 14px;
            color: #2563eb;
            word-break: break-all;
            line-height: 1.35;
        }
        .chat-link-preview {
            font-size: 13px;
            color: var(--text-muted);
            line-height: 1.35;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .chat-doc-row-tg {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 10px 12px;
            border: 1px solid var(--border);
            border-radius: 10px;
            background: var(--surface-muted);
            cursor: pointer;
            transition: background 0.12s ease;
        }
        .chat-doc-row-tg:active {
            background: rgba(15, 23, 42, 0.05);
        }
        .chat-doc-row-main {
            flex: 1;
            min-width: 0;
            font-size: 14px;
            color: var(--text);
            word-break: break-word;
        }
        .chat-doc-open {
            flex-shrink: 0;
            font-size: 13px;
            font-weight: 600;
            color: var(--accent);
            text-decoration: none;
        }
        .chat-doc-open:hover {
            text-decoration: underline;
        }
        .chat-top-menu-wrap {
            position: relative;
            flex-shrink: 0;
        }
        /* Как в Telegram Web: иконка без «таблетки», круглый hover */
        .chat-top-menu-btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            margin: 0;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #707579;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease, color 0.12s ease;
        }
        .chat-top-menu-btn:hover {
            background: rgba(0, 0, 0, 0.06);
            color: #3390ec;
        }
        .chat-top-menu-btn:active {
            background: rgba(0, 0, 0, 0.1);
        }
        .chat-top-menu-btn svg {
            display: block;
            flex-shrink: 0;
        }
        .chat-top-menu-backdrop {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 250;
            background: rgba(15, 23, 42, 0.42);
            backdrop-filter: blur(6px);
            -webkit-backdrop-filter: blur(6px);
            -webkit-tap-highlight-color: transparent;
        }
        .chat-top-menu-dropdown {
            position: absolute;
            top: calc(100% + 6px);
            right: 0;
            z-index: 251;
            min-width: 192px;
            padding: 6px 0;
            background: #fff;
            border: 1px solid rgba(0, 0, 0, 0.08);
            border-radius: 14px;
            box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
            overflow: hidden;
        }
        .chat-top-menu-item {
            display: block;
            width: 100%;
            text-align: left;
            padding: 12px 18px;
            border: none;
            background: transparent;
            font-size: 15px;
            font-weight: 500;
            color: #0f172a;
            cursor: pointer;
            line-height: 1.35;
        }
        .chat-top-menu-item:hover {
            background: #f1f5f9;
        }
        .chat-top-menu-item:active {
            background: #e8eef8;
        }
        @media (max-width: 900px) {
            .chat-top-menu-dropdown {
                position: fixed;
                left: 50%;
                top: 50%;
                right: auto;
                transform: translate(-50%, -50%);
                min-width: min(300px, calc(100vw - 40px));
                max-width: calc(100vw - 40px);
                padding: 8px 0;
                border-radius: 16px;
            }
        }
        .media-viewer-goto {
            position: absolute;
            top: max(10px, env(safe-area-inset-top));
            left: max(10px, env(safe-area-inset-left));
            z-index: 6;
            padding: 8px 14px;
            border-radius: 20px;
            border: none;
            background: rgba(255, 255, 255, 0.12);
            color: #fff;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            display: none;
            align-items: center;
            justify-content: center;
            transition: background 0.15s ease;
        }
        .media-viewer-goto:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        .media-viewer-download {
            position: absolute;
            top: max(10px, env(safe-area-inset-top));
            left: max(168px, calc(env(safe-area-inset-left) + 168px));
            z-index: 6;
            padding: 8px 14px;
            border-radius: 20px;
            background: rgba(255, 255, 255, 0.12);
            color: #fff;
            font-size: 14px;
            font-weight: 600;
            text-decoration: none;
            transition: background 0.15s ease;
        }
        .media-viewer-download:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        @media (max-width: 560px) {
            .media-viewer-download {
                left: max(10px, env(safe-area-inset-left));
                top: calc(max(10px, env(safe-area-inset-top)) + 40px);
            }
            .media-viewer-stage img,
            .media-viewer-stage video {
                max-height: min(80vh, calc(100dvh - 170px));
            }
        }
        @media (min-width: 901px) {
            .media-viewer-unsupported {
                backdrop-filter: none;
                -webkit-backdrop-filter: none;
            }
            .media-viewer-stage img,
            .media-viewer-stage video {
                border-radius: 0;
            }
        }
        .chat-media-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
            gap: 5px;
            overflow-y: auto;
            flex: 1;
            min-height: 120px;
            max-height: min(48vh, 420px);
            -webkit-overflow-scrolling: touch;
        }
        .chat-media-cell {
            aspect-ratio: auto;
            border-radius: 10px;
            overflow: hidden;
            background: #e5e7eb;
            position: relative;
            cursor: pointer;
            -webkit-touch-callout: none;
            user-select: none;
        }
        .chat-media-cell::before {
            content: "";
            display: block;
            padding-top: 100%;
        }
        .chat-media-cell img,
        .chat-media-cell video {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            display: block;
            transform: translateZ(0);
            backface-visibility: hidden;
            -webkit-backface-visibility: hidden;
        }
        .chat-info-panel .chat-media-cell {
            box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
            border: 1px solid rgba(0, 0, 0, 0.06);
            background: #e5e7eb;
            transform: none;
            z-index: 1;
        }
        @media (max-width: 900px) {
            /* На телефоне ровная аккуратная сетка. */
            .chat-info-panel .chat-media-grid {
                grid-template-columns: repeat(3, minmax(0, 1fr));
                gap: 6px;
                max-height: min(58vh, calc(100dvh - 240px));
            }
            #chatInfoModal.modal,
            #groupInvitePickerModal.modal {
                align-items: center;
                justify-content: center;
                padding-left: max(16px, env(safe-area-inset-left));
                padding-right: max(16px, env(safe-area-inset-right));
                padding-top: max(16px, env(safe-area-inset-top));
                padding-bottom: max(16px, env(safe-area-inset-bottom));
            }
            .chat-info-card {
                margin-top: 0;
                max-height: min(85vh, calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom))));
                border-radius: 16px;
            }
            .group-members-card,
            .group-invite-picker-card {
                max-height: min(88vh, calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom))));
            }
        }
        .mobile-menu-trigger { display: none; padding: 8px 12px !important; font-size: 18px; line-height: 1; min-width: 44px; }
        .mobile-menu-backdrop {
            display: none;
            position: fixed;
            inset: 0;
            z-index: 80;
            background: rgba(15, 23, 42, 0.4);
            backdrop-filter: blur(4px);
            -webkit-backdrop-filter: blur(4px);
            opacity: 0;
            transition: opacity 0.2s ease;
            pointer-events: none;
        }
        .mobile-menu-backdrop.open {
            display: block;
            opacity: 1;
            pointer-events: auto;
        }
        .mobile-side-drawer {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            width: min(100vw - 48px, 380px);
            max-width: 100%;
            z-index: 81;
            background: var(--surface);
            box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
            flex-direction: column;
            transform: translateX(-100%);
            transition: transform 0.22s ease;
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
            /* Меньше горизонтального «резинового» скролла поверх жеста «Назад» (iOS). */
            overscroll-behavior: contain;
            overscroll-behavior-x: none;
            touch-action: pan-y;
        }
        .mobile-side-drawer.open {
            display: flex;
            transform: translateX(0);
        }
        .mobile-side-drawer-back {
            display: none;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            margin: 0;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            flex-shrink: 0;
            cursor: pointer;
            -webkit-tap-highlight-color: transparent;
            transition: background 0.12s ease;
        }
        .mobile-side-drawer-back:active {
            background: rgba(51, 144, 236, 0.1);
        }
        .mobile-side-drawer-back svg {
            width: 22px;
            height: 22px;
        }
        .mobile-side-drawer-top {
            display: flex;
            align-items: center;
            gap: 4px;
            padding: 8px 6px 10px 8px;
            padding-top: max(8px, env(safe-area-inset-top));
            border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
            flex-shrink: 0;
            background: #fff;
        }
        .mobile-side-drawer-title {
            font-weight: 600;
            font-size: 20px;
            color: #000;
            flex: 1;
            min-width: 0;
            letter-spacing: -0.03em;
        }
        .mobile-side-drawer-close {
            flex-shrink: 0;
            width: 40px;
            height: 40px;
            margin: 0;
            padding: 0;
            border: none;
            border-radius: 50%;
            background: transparent;
            color: #3390ec;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background 0.12s ease;
        }
        .mobile-side-drawer-close:hover {
            background: rgba(51, 144, 236, 0.1);
        }
        .mobile-side-drawer-close svg {
            width: 22px;
            height: 22px;
        }
        .mobile-drawer-panels-mount {
            flex: 1;
            min-height: 0;
            overflow-y: auto;
            -webkit-overflow-scrolling: touch;
        }
        .mobile-drawer-panels-mount .settings-panel { padding-top: 8px; }
        @media (max-width: 900px) {
            .mobile-drawer-panels-mount #settingsPanel.settings-panel--account.show {
                display: block;
                overflow: visible;
                flex: none;
                min-height: 0;
                background: var(--surface);
            }
            .mobile-drawer-panels-mount .settings-panel-inner {
                overflow: visible;
            }
        }
        .icon { display: block; font-size: 18px; line-height: 18px; }
        .label { display: block; font-size: 11px; margin-top: 2px; }
        @media (max-width: 900px) {
            .left .left-back { display: none !important; }
            .mobile-menu-trigger {
                display: inline-block !important;
            }
            .mobile-menu-trigger.menu-hidden-in-chat {
                display: none !important;
            }
            #chatScreen.screen.active {
                flex: 1;
                min-height: 0 !important; /* сброс .screen { min-height: 100vh } — иначе колонка чата выше видимой области и скроллится вся страница */
                display: flex;
                flex-direction: column;
                position: fixed;
                top: var(--app-vv-top);
                left: 0;
                right: 0;
                width: 100%;
                height: var(--app-vh);
                max-height: var(--app-vh);
                overflow: hidden;
            }
            /* iOS Safari: обработка клавиатуры — через JS корректировку --app-vh (см. applyVisualViewportCss). */
            #chatScreen.screen.active .chat-layout {
                flex: 1;
                min-height: 0;
                height: 100% !important;
                max-height: 100%;
                overflow: hidden;
                grid-template-columns: 1fr;
                /* Одна строка на всю высоту — иначе список и тред в двух рядах сетки, тред может перекрывать не тем слоем */
                grid-template-rows: 1fr;
                position: relative;
            }
            #chatScreen.screen.active .chat-layout > .left,
            #chatScreen.screen.active .chat-layout > .right {
                grid-column: 1;
                grid-row: 1;
                align-self: stretch;
                min-height: 0;
            }
            .left { display: none; }
            .left.mobile-show {
                display: flex;
                height: 100%;
                border-right: 0;
                min-height: 0;
                position: relative;
                z-index: 6;
                background: var(--surface);
            }
            .right.mobile-hide { display: none; }
            /* Выход из треда жестом «Назад» (iOS): скрыть тред до следующего кадра, иначе мелькает пустая лента. */
            #chatScreen.screen.active.mobile-thread-exit-hide .chat-layout > .right {
                display: none !important;
                visibility: hidden !important;
                pointer-events: none !important;
            }
            .right:not(.mobile-hide) {
                flex: 1;
                min-height: 0;
                max-height: 100%;
                overflow: hidden;
                touch-action: manipulation;
                position: relative;
                z-index: 5;
                background: var(--app-bg);
            }
            .composer { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
            /* При открытой клавиатуре убираем лишний «зазор» снизу (safe area перекрыта клавиатурой). */
            /* sticky + fixed + смена visualViewport на iOS даёт «уезжающую» шапку и пустоту сверху */
            html.composer-keyboard-open .right > .top {
                position: relative;
                top: auto;
            }
            html.composer-keyboard-open .composer {
                padding-bottom: 6px;
            }
            /* Освобождаем место над клавиатурой: подсказка про лимиты скрывается при вводе */
            html.composer-keyboard-open #attachmentLimitsHint {
                display: none !important;
            }
            /* Чуть воздуха у последнего пузыря при программной прокрутке к низу */
            html.composer-keyboard-open .messages {
                scroll-padding-bottom: 12px;
            }
            .composer-wrap {
                flex-shrink: 0;
                position: relative;
            }
            #chatScreen.screen.active .chat-main-shell {
                flex: 1;
                min-height: 0;
                display: flex;
                flex-direction: row;
                overflow: hidden;
            }
            #chatScreen.screen.active .chat-main-shell > .chat-layout {
                flex: 1;
                min-width: 0;
                min-height: 0;
            }
            .profile-rail-wrap {
                position: fixed;
                inset: 0;
                z-index: 299;
                width: auto !important;
                min-width: 0 !important;
                flex: none !important;
                max-width: none;
                border-left: none;
                background: transparent;
                align-items: center;
                justify-content: flex-end;
                flex-direction: column;
                padding: max(6px, env(safe-area-inset-top)) 12px max(20px, calc(10px + env(safe-area-inset-bottom))) 12px;
                box-sizing: border-box;
                transition: none;
            }
            .profile-rail-wrap:not(.profile-rail-wrap--open) {
                visibility: hidden;
                pointer-events: none;
            }
            .profile-rail-wrap.profile-rail-wrap--open {
                visibility: visible;
                pointer-events: auto;
            }
            .profile-rail-backdrop {
                display: block;
                position: absolute;
                inset: 0;
                background: rgba(15, 23, 42, 0.38);
                backdrop-filter: blur(10px);
                -webkit-backdrop-filter: blur(10px);
                opacity: 0;
                transition: opacity 0.2s ease;
            }
            .profile-rail-wrap.profile-rail-wrap--open .profile-rail-backdrop {
                opacity: 1;
            }
            .profile-rail {
                width: 100%;
                max-width: 380px;
                border-radius: 16px;
                background: var(--surface);
                box-shadow: 0 12px 48px rgba(15, 23, 42, 0.2);
                display: flex;
                flex-direction: column;
                /* Лист тянется вверх почти на весь экран — без большой «пустой четверти» сверху */
                min-height: min(82dvh, calc(100dvh - 28px));
                max-height: min(92dvh, calc(100dvh - 12px));
            }
            .profile-rail__head {
                flex-shrink: 0;
                position: relative;
                z-index: 4;
            }
            .profile-rail__close {
                display: flex;
                align-items: center;
                justify-content: center;
            }
            /* Нижний лист профиля: не обрезать вкладки, воздух между блоками */
            .profile-rail #profilePanel.profile-panel--rail.settings-panel.show {
                padding: 16px 14px max(32px, calc(14px + env(safe-area-inset-bottom)));
            }
            .profile-rail #profilePanel #profileSeen.status {
                margin-bottom: 20px !important;
            }
            .profile-rail .profile-peer-chat-tools {
                margin-top: 4px;
                margin-bottom: 16px;
            }
            .profile-rail .profile-peer-chat-actions {
                margin-bottom: 14px;
            }
            .profile-rail .profile-peer-media-wrap {
                padding: 12px 0 16px;
                margin-top: 2px;
            }
            .profile-rail .profile-peer-media-wrap .chat-info-tabs {
                margin-bottom: 14px;
            }
            .profile-rail .profile-peer-media-wrap .chat-info-tab {
                padding-top: 10px;
                padding-bottom: 13px;
            }
            .profile-rail .profile-peer-media-wrap .chat-info-tab.active {
                border-bottom-width: 4px;
            }
        }
        @media (max-width: 900px) and (max-height: 500px) {
            .profile-rail {
                min-height: min(72dvh, calc(100dvh - 20px));
                max-height: min(88dvh, calc(100dvh - 12px));
            }
        }
        @media (min-width: 901px) {
            .mobile-menu-backdrop,
            .mobile-side-drawer {
                display: none !important;
            }
            /*
             * Список чатов — фиксированная ширина (не % от окна), иначе на широких экранах
             * левая колонка съедает центр и «плывёт» шапка с меню.
             * Чат по центру — flex:1; справа — панель инфо шире, чем было.
             */
            .chat-layout {
                grid-template-columns: 320px minmax(0, 1fr);
            }
            .profile-rail__close {
                display: none !important;
            }
            .chat-info-rail-mount .chat-info-modal__close {
                display: none !important;
            }
        }
    
