/* ============================================================
   /chat-room/css/chat-room.css
   Общий чат — 3 колонки, как в Telegram / Max
   ============================================================ */

/* ---------- Сброс ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body.cr-body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.cr-link { color: #4f46e5; text-decoration: underline; word-break: break-all; }
.cr-inline-smile {
    width: 22px; height: 22px;
    display: inline-block; vertical-align: middle;
    margin: 0 2px;
}

/* ---------- Общий каркас ---------- */
.chat-room-app {
    display: grid;
    grid-template-columns: 280px 1fr 300px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ============================================================
   ЛЕВАЯ КОЛОНКА (САЙДБАР)
   ============================================================ */
.cr-sidebar {
    background: #fff;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cr-sidebar-section {
    padding: 12px 8px;
    border-bottom: 1px solid #f3f4f6;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.cr-sidebar-section-title {
    font-size: 11px;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: 4px 8px 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cr-badge-online {
    background: #10b981;
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.cr-sidebar-empty {
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
    padding: 12px 8px;
}

/* Комната в сайдбаре */
.cr-room-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    text-decoration: none;
    color: inherit;
    transition: background .15s;
}
.cr-room-item:hover { background: #f3f4f6; }
.cr-room-item.is-active {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    padding: 7px 9px;
}

.cr-room-icon {
    width: 40px; height: 40px;
    background: #e0e7ff;
    color: #4f46e5;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.cr-room-info { min-width: 0; flex: 1; }
.cr-room-name {
    font-size: 14px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cr-room-desc {
    font-size: 12px; color: #6b7280;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}

/* Онлайн-участники */
.cr-members { display: flex; flex-direction: column; gap: 2px; }

.cr-member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 8px;
    border-radius: 8px;
}
.cr-member-item:hover { background: #f9fafb; }

.cr-member-avatar {
    position: relative;
    width: 34px; height: 34px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex; align-items: center; justify-content: center;
    overflow: visible;
    flex-shrink: 0;
}
.cr-member-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.cr-member-avatar i { color: #9ca3af; font-size: 14px; }

.cr-dot-online {
    position: absolute;
    bottom: 0; right: 0;
    width: 10px; height: 10px;
    background: #10b981;
    border: 2px solid #fff;
    border-radius: 50%;
}

.cr-member-name {
    font-size: 13.5px;
    color: #374151;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ============================================================
   ЦЕНТР (ОСНОВНОЙ ЧАТ)
   ============================================================ */
.cr-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
    overflow: hidden;
    position: relative;   /* ← добавили, чтобы absolute-кнопки считались от .cr-main */
}

.cr-icon-btn {
    background: transparent;
    border: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    color: #6b7280;
    cursor: pointer;
    transition: background .15s;
    display: flex; align-items: center; justify-content: center;
}
.cr-icon-btn:hover { background: #f3f4f6; color: #374151; }

/* ---------- Лента сообщений ---------- */
.cr-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: #f9fafb;
    scroll-behavior: smooth;
}

#messagesContainer {
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
}

.cr-messages::-webkit-scrollbar { width: 8px; }
.cr-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.cr-messages::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

.cr-empty {
    text-align: center;
    color: #9ca3af;
    padding: 60px 20px;
}
.cr-empty i { font-size: 48px; margin-bottom: 12px; display: block; opacity: .5; }
.cr-empty p { margin: 0; font-size: 14px; }

/* Разделитель дней */
.cr-day {
    text-align: center;
    margin: 16px 0 12px;
}
.cr-day span {
    display: inline-block;
    background: #fff;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 11.5px;
    padding: 4px 12px;
    border-radius: 12px;
}

/* ---------- Пост ---------- */
.cr-post {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    width: 100%;
}

.cr-post__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #e5e7eb;
    margin-top: 2px;
}

/* Карточка — ширина по содержимому, но не больше 60ch */
.cr-post__card {
    width: fit-content;
    max-width: 60ch;
    background: #ffffff;
    border-radius: 10px;
    padding: 8px 14px 6px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
    box-sizing: border-box;
}

.cr-post__head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 2px;
}
.cr-post__author {
    font-size: 14.5px;
    font-weight: 500;
    color: #5a7a9a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cr-post__author--own {
    color: #c0392b;
}
.cr-post__label {
    font-size: 11px;
    color: #b0b8c1;
    margin-left: auto;
}

.cr-post__quote {
    border-left: 2px solid #4a90d9;
    background: #eef3f8;
    padding: 6px 10px;
    border-radius: 4px;
    margin: 4px 0 6px;
}
.cr-post__quote-name {
    font-size: 12px;
    font-weight: 500;
    color: #4a90d9;
    margin-bottom: 2px;
}
.cr-post__quote-text {
    font-size: 13px;
    color: #5a6a7a;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.cr-post__text {
    font-size: 16px;
    line-height: 1.45;
    color: #1f2937;
    word-break: break-word;
    margin-top: 2px;
}

.cr-post__image-wrap {
    display: block;
    margin: 6px 0;
    border-radius: 8px;
    overflow: hidden;
}
.cr-post__image {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

/* Кнопки — в строку, справа от карточки, при hover */
.cr-post__actions {
    display: flex;
    flex-direction: row;
    gap: 6px;
    flex-shrink: 0;
    align-self: flex-start;
    padding-top: 4px;
    opacity: 0;
    transition: opacity .15s;
    pointer-events: none;
}
.cr-post:hover .cr-post__actions {
    opacity: 1;
    pointer-events: auto;
}

.cr-post__btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: #ffffff;
    background: rgba(74, 144, 217, 0.65);
    backdrop-filter: blur(4px);
    transition: background .15s, transform .1s;
}
.cr-post__btn:hover {
    background: rgba(74, 144, 217, 0.95);
    transform: scale(1.05);
}
/* Пустое место под аватар у сгруппированных сообщений */
.cr-post__avatar-placeholder {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

/* Группировка: подряд идущие сообщения одного автора */
.cr-post--grouped {
    margin-top: -4px;          /* склеиваем блоки */
}
.cr-post--grouped .cr-post__card {
    border-top-left-radius: 4px;   /* лёгкое скругление сверху */
    border-top-right-radius: 4px;
}
.cr-post__btn:active {
    transform: scale(.95);
}

/* ---------- Форма ввода ---------- */
.cr-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}

.cr-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.cr-attach, .cr-send {
    width: 44px; height: 44px;
    border-radius: 50%;
    border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    transition: background .15s, transform .1s;
    flex-shrink: 0;
    font-size: 16px;
}

.cr-attach {
    background: #f3f4f6;
    color: #6b7280;
}
.cr-attach:hover { background: #e5e7eb; color: #374151; }

.cr-send {
    background: #4f46e5;
    color: #fff;
}
.cr-send:hover { background: #4338ca; transform: scale(1.05); }
.cr-send:active { transform: scale(.95); }

.cr-input {
    flex: 1;
    min-height: 44px;
    max-height: 200px;
    padding: 12px 16px;
    border-radius: 22px;
    border: none;
    background: #f3f4f6;
    font-size: 14.5px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    overflow-y: auto;
    outline: none;
}
.cr-input:focus { background: #fff; box-shadow: 0 0 0 2px rgba(99,102,241,.3); }

/* Ответ (цитата над формой) */
.cr-reply-info:not([hidden]) {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f3f4f6;
    border-left: 4px solid #3b82f6;
    border-radius: 8px;
    margin-bottom: 8px;
    position: relative;
}

/* Это правило гарантирует, что при наличии hidden блок скроется,
   даже если Tailwind попытается его показать */
.cr-reply-info[hidden] {
    display: none;
}

.cr-reply-info__icon {
    color: #3b82f6;
    font-size: 16px;
    flex-shrink: 0;
}
.cr-reply-info__body { flex: 1; min-width: 0; }
.cr-reply-info__label { font-size: 11px; color: #6b7280; }
.cr-reply-info__label span {
    font-weight: 700;
    color: #3b82f6;
}
.cr-reply-info__preview {
    font-size: 13px; color: #374151;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cr-reply-info__close {
    background: transparent; border: none;
    color: #9ca3af; cursor: pointer;
    padding: 4px; font-size: 14px;
}
.cr-reply-info__close:hover { color: #ef4444; }

/* Плашка для гостей */
.cr-guest-lock {
    padding: 16px 20px;
    background: #fef3c7;
    border-top: 1px solid #fde68a;
    color: #78350f;
    font-size: 14px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-shrink: 0;
}
.cr-guest-lock a { color: #4f46e5; font-weight: 600; text-decoration: underline; }

/* ============================================================
   ПРАВАЯ КОЛОНКА
   ============================================================ */
.cr-right {
    background: #fff;
    border-left: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cr-right-card {
    padding: 16px;
    border-bottom: 1px solid #e5e7eb;
}
.cr-right-card__row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}
.cr-right-icon {
    width: 52px; height: 52px;
    background: #e0e7ff;
    color: #4f46e5;
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.cr-right-card__info {
    min-width: 0;
    flex: 1;
}
.cr-right-name {
    font-size: 15px; font-weight: 700; color: #111827;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cr-right-desc {
    font-size: 12.5px; color: #6b7280; margin-top: 3px;
    line-height: 1.3;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.cr-right-card__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.cr-right-count {
    font-size: 12.5px;
    color: #6b7280;
}

.cr-invite-btn {
    background: #eef2ff;
    color: #4f46e5;
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.cr-invite-btn:hover { background: #e0e7ff; }
.cr-invite-btn i { font-size: 11px; }

.cr-right-section {
    padding: 16px;
    border-bottom: 1px solid #f3f4f6;
}
.cr-right-title {
    font-size: 11px;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.cr-right-members { display: flex; flex-direction: column; gap: 4px; }
.cr-right-empty { text-align: center; color: #9ca3af; font-size: 13px; padding: 8px; }

.cr-right-member {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    border-radius: 8px;
}
.cr-right-member:hover { background: #f9fafb; }
.cr-right-member-info { min-width: 0; flex: 1; }
.cr-right-member-name {
    font-size: 13.5px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cr-right-member-status {
    font-size: 11.5px;
    color: #10b981;
    margin-top: 1px;
}

.cr-right-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    font-size: 13.5px;
    color: #374151;
    border-radius: 8px;
}
.cr-right-row:hover { background: #f9fafb; }
.cr-right-row i:first-child { color: #6b7280; width: 18px; text-align: center; }
.cr-right-row span { flex: 1; }
.cr-right-row-arrow { color: #d1d5db !important; font-size: 11px; }

.cr-toggle {
    position: relative;
    display: inline-block;
    width: 34px; height: 18px;
}
.cr-toggle input { display: none; }
.cr-toggle span {
    position: absolute;
    inset: 0;
    background: #10b981;
    border-radius: 10px;
    transition: .2s;
}
.cr-toggle span::after {
    content: '';
    position: absolute;
    top: 2px; left: 18px;
    width: 14px; height: 14px;
    background: #fff;
    border-radius: 50%;
    transition: .2s;
}

.cr-toggle input:not(:checked) + span {
    background: #d1d5db;
}
.cr-toggle input:not(:checked) + span::after {
    left: 2px;
}

/* ---------- Верхняя часть правой колонки (скроллится) ---------- */
.cr-right-top {
    flex: 1;
    overflow-y: auto;
    min-height: 0;   /* важно для flex, иначе не скроллится */
}

/* ---------- Нижняя часть правой колонки (прижата к низу) ---------- */
.cr-right-bottom {
    flex-shrink: 0;
    padding: 14px 16px;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
}
.cr-right-bottom .cr-right-title {
    margin-bottom: 8px;
}
.cr-right-bottom .cr-right-row {
    padding: 8px 4px;
}
.cr-right-bottom .cr-right-row:last-child {
    padding-bottom: 0;
}

/* Тонкий скроллбар в правой колонке */
.cr-right-top::-webkit-scrollbar { width: 6px; }
.cr-right-top::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 4px;
}
.cr-right-top::-webkit-scrollbar-thumb:hover { background: #d1d5db; }

/* ---------- Превью выбранного файла ---------- */
.cr-file-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 8px;
    background: #f3f4f6;
    border-left: 4px solid #10b981;
    border-radius: 8px;
}
.cr-file-preview__thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
    background: #e5e7eb;
}
.cr-file-preview__info {
    flex: 1;
    min-width: 0;
}
.cr-file-preview__name {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cr-file-preview__size {
    font-size: 11.5px;
    color: #6b7280;
    margin-top: 2px;
}
.cr-file-preview__remove {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 6px;
    font-size: 14px;
    border-radius: 50%;
    transition: background .15s, color .15s;
}
.cr-file-preview__remove:hover {
    color: #ef4444;
    background: #fee2e2;
}

.cr-file-preview[hidden] { display: none; }

/* Серая точка для офлайн-участников */
.cr-dot-online.cr-dot-offline {
    background: #9ca3af;
}

/* Приглушённый статус */
.cr-right-member-status.offline {
    color: #9ca3af;
}


/* ---------- Выпадающее меню поста ---------- */
.cr-menu {
    position: fixed;
    z-index: 10000;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
    padding: 6px;
    min-width: 260px;
    max-width: 300px;
    max-height: calc(100vh - 20px);   /* ← не выше экрана */
    overflow-y: auto;                  /* ← скролл если не влезает */
    font-size: 14px;
    color: #1f2937;
}

.cr-menu[hidden] { display: none; }

/* Блок реакций сверху */
.cr-menu__reactions {
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    background: #f3f4f6;
    border-radius: 20px;
    margin-bottom: 6px;
    align-items: center;
}

.cr-menu__reaction {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .1s, background .15s;
}
.cr-menu__reaction:hover {
    background: #e5e7eb;
    transform: scale(1.15);
}
.cr-menu__reaction--more {
    color: #6b7280;
    font-size: 12px;
}

/* Пункты меню */
.cr-menu__items {
    display: flex;
    flex-direction: column;
}
.cr-menu__items[hidden] { display: none; }

.cr-menu__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 14px;
    color: #1f2937;
    cursor: pointer;
    border-radius: 8px;
    transition: background .15s;
}
.cr-menu__item:hover {
    background: #f3f4f6;
}
.cr-menu__item i {
    width: 18px;
    color: #6b7280;
    font-size: 14px;
    text-align: center;
}
.cr-menu__item--danger {
    color: #ef4444;
}
.cr-menu__item--danger i {
    color: #ef4444;
}
.cr-menu__item--danger:hover {
    background: #fee2e2;
}

/* ---------- Модалка редактирования ---------- */
.cr-edit-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20000;
}
.cr-edit-modal[hidden] { display: none; }

.cr-edit-modal__box {
    background: #fff;
    width: 90%;
    max-width: 480px;
    border-radius: 12px;
    padding: 18px 20px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .25);
}

.cr-edit-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}
.cr-edit-modal__close {
    background: transparent;
    border: none;
    font-size: 16px;
    color: #9ca3af;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.cr-edit-modal__close:hover {
    color: #ef4444;
    background: #fee2e2;
}

.cr-edit-modal__text {
    width: 100%;
    min-height: 90px;
    max-height: 300px;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14.5px;
    font-family: inherit;
    line-height: 1.45;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}
.cr-edit-modal__text:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, .2);
}

.cr-edit-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}
.cr-btn {
    padding: 8px 18px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.cr-btn--ghost {
    background: #f3f4f6;
    color: #374151;
}
.cr-btn--ghost:hover {
    background: #e5e7eb;
}
.cr-btn--primary {
    background: #4f46e5;
    color: #fff;
}
.cr-btn--primary:hover {
    background: #4338ca;
}

/* Метка «изменено» в посте */
.cr-post__edited {
    font-size: 11px;
    color: #b0b8c1;
    margin-left: 4px;
    font-style: italic;
}

/* ---------- Низ поста: реакции + время ---------- */
.cr-post__bottom {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* Реакции */
.cr-post__reactions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    margin: 0;
}

.cr-reaction {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: #f3f4f6;
    border: 1px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    font-size: 12.5px;
    color: #374151;
    transition: background .15s, border-color .15s, transform .1s;
    line-height: 1;
    font-family: inherit;
}
.cr-reaction:hover {
    background: #e5e7eb;
    transform: scale(1.05);
}
.cr-reaction--mine {
    background: #eef2ff;
    border-color: #6366f1;
    color: #4f46e5;
}
.cr-reaction--mine:hover {
    background: #e0e7ff;
}
.cr-reaction__emoji {
    font-size: 14px;
    line-height: 1;
}
.cr-reaction__count {
    font-weight: 600;
}

/* Время поста — справа */
.cr-post__time {
    font-size: 12px;
    color: #b0b8c1;
    white-space: nowrap;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    height: 16px;
}

/* Обёртка левых кнопок ввода */
.cr-input-left {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
    transition: width .2s ease, opacity .15s ease;
    overflow: hidden;
}

/* =========================================================
   МОБИЛЬНЫЕ УСТРОЙСТВА
   ========================================================= */

@media (max-width: 900px) {

    /* ---- Общий каркас ---- */
    .chat-room-app {
        grid-template-columns: 1fr;
        width: 100%;
        flex: 1;
        min-height: 0;
    }

    /* =====================================================
       ЛЕВАЯ КОЛОНКА — выдвижная
       ===================================================== */

    .cr-sidebar {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;

        width: min(85vw, 340px);
        height: 100dvh;
        max-height: 100dvh;

        z-index: 100;

        transform: translate3d(-100%, 0, 0);
        transition: transform .25s ease;

        box-shadow: 2px 0 12px rgba(0, 0, 0, .15);

        /* iPhone / iPad */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);

        box-sizing: border-box;

        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .cr-sidebar.is-open {
        transform: translate3d(0, 0, 0);
    }


    /* =====================================================
       ПРАВАЯ КОЛОНКА — выдвижная
       ===================================================== */

    .cr-right {
        display: flex !important;
        position: fixed;
        top: 0;
        right: 0;

        width: min(85vw, 340px);
        height: 100dvh;
        max-height: 100dvh;

        z-index: 100;

        transform: translate3d(100%, 0, 0);
        transition: transform .25s ease;

        box-shadow: -2px 0 12px rgba(0, 0, 0, .15);

        /* iPhone / iPad */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);

        box-sizing: border-box;

        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .cr-right.is-open {
        transform: translate3d(0, 0, 0);
    }


    /* =====================================================
       ЗАТЕМНЕНИЕ
       ===================================================== */

    .cr-mobile-overlay {
        display: block;

        position: fixed;
        inset: 0;

        width: 100%;
        height: 100dvh;

        z-index: 99;

        background: rgba(0, 0, 0, .45);

        opacity: 0;
        visibility: hidden;
        pointer-events: none;

        transition:
            opacity .25s ease,
            visibility .25s ease;
    }

    .cr-mobile-overlay.is-open {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    /* =====================================================
       ЛЕНТА СООБЩЕНИЙ
       ===================================================== */

    .cr-messages {
        padding: 12px 14px;

        /*
         * Место под фиксированную форму ввода.
         * Значение достаточно большое, чтобы последнее
         * сообщение не перекрывалось полем.
         */
        padding-bottom:
            calc(
                90px +
                env(safe-area-inset-bottom)
            );

        overflow-x: hidden;

        overscroll-behavior-y: contain;
    }
    
    
    .cr-input-left {
        width: 50px;   /* ширина одной кнопки + gap */
    }
    
    /* Скрываем при печати */
    .cr-input-area.is-typing .cr-input-left {
        width: 0;
        opacity: 0;
        margin-right: 0;
    }


    /* =====================================================
       ФОРМА ВВОДА
       ===================================================== */

    .cr-input-area {
        position: fixed;

        left: 0;
        right: 0;
        bottom: 0;

        width: 100%;

        z-index: 50;

        box-sizing: border-box;

        padding:
            8px
            10px
            calc(8px + env(safe-area-inset-bottom));

        border-top: 1px solid #e5e7eb;

        background: #fff;

        /*
         * Не даём содержимому вылезать за пределы
         * маленьких экранов.
         */
        max-width: 100vw;

        /*
         * Учитываем горизонтальный safe-area
         * на устройствах с вырезами.
         */
        padding-left:
            max(10px, env(safe-area-inset-left));

        padding-right:
            max(10px, env(safe-area-inset-right));
    }

    .cr-input {
        font-size: 16px;
        min-width: 0;
    }


    /* ---- ПОСТЫ ---- */
    .cr-post {
        gap: 6px;
        margin-bottom: 8px;
        max-width: 100%;
        width: 100%;
        position: relative;
    }

    .cr-post__avatar {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .cr-post__avatar-placeholder {
        width: 32px;
        height: 32px;
        min-width: 32px;
    }

    /* Карточка — на всю ширину */
    .cr-post__card {
        min-width: 0;
        max-width: 100%;
        width: 100%;
        padding: 8px 10px;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    /* Кнопки — ВНУТРИ карточки, скрыты по умолчанию */
    .cr-post__actions {
        position: absolute;
        top: 6px;
        right: 6px;

        display: none;
        flex-direction: row;
        gap: 4px;

        padding: 0;
        opacity: 1;
        pointer-events: auto;
    }

    /* Кнопки — показываются, когда на посте .is-active */
    .cr-post.is-active .cr-post__actions {
        display: flex;
    }

    .cr-post__btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        font-size: 12px;
        background: rgba(74, 144, 217, 0.9);
    }

    /* Скрываем блок реакций под постом, если не активен */
    .cr-post__bottom {
        margin-top: 6px;
    }
}


/* ===== Глазик просмотров ===== */
.cr-post__meta {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-left: auto;
    line-height: 1;
    height: 18px;
}

.cr-post__views {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    line-height: 1;
    height: 16px;
    color: #8a93a6;
    cursor: default;
    user-select: none;
    white-space: nowrap;
}

.cr-post__views i {
    font-size: 13px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.cr-post__views-count {
    font-size: 12px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

/* ===== Кнопка «вниз» ===== */
.cr-scroll-bottom {
    position: fixed;
    right: 320px;      /* 300px правая колонка + 20px отступ */
    bottom: 100px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: #4a90e2;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,.25);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    transition: transform .15s ease, background .15s ease;
}

.cr-scroll-bottom:not([hidden]) {
    display: flex;
}

.cr-scroll-bottom:hover { background: #357ab8; transform: translateY(-2px); }
.cr-scroll-bottom__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e74c3c;
    color: #fff;
    font-size: 11px;
    line-height: 20px;
    text-align: center;
    font-weight: 600;
}

/* =========================================================
   ОЧЕНЬ МАЛЕНЬКИЕ ТЕЛЕФОНЫ
   ========================================================= */

@media (max-width: 380px) {

    .cr-sidebar,
    .cr-right {
        width: 90vw;
        max-width: none;
    }

    .cr-messages {
        padding-left: 12px;
        padding-right: 12px;
    }

    .cr-post__card {
        padding: 9px 10px;
    }

    .cr-post__text {
        font-size: 16px;
    }
}


/* =========================================================
   ТЕЛЕФОН В АЛЬБОМНОЙ ОРИЕНТАЦИИ
   ========================================================= */

@media (max-width: 900px) and (orientation: landscape) {
    .cr-scroll-bottom {
        right: 20px;   /* на мобильном правая колонка скрыта */
        bottom: 90px;
    }

    .cr-sidebar,
    .cr-right {
        height: 100dvh;
        max-height: 100dvh;
    }

    .cr-messages {
        padding-top: 8px;
        padding-bottom:
            calc(
                75px +
                env(safe-area-inset-bottom)
            );
    }

    .cr-input-area {
        padding-top: 6px;
        padding-bottom:
            calc(
                6px +
                env(safe-area-inset-bottom)
            );
    }
}


/* ============================================================
   МОБИЛЬНЫЕ КНОПКИ — прижаты к верхним углам центральной колонки
   ============================================================ */

.cr-mobile-btn {
    display: none;              /* по умолчанию скрыты (десктоп) */
    position: absolute;
    top: 8px;
    z-index: 20;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, .08);   /* ← светло-серый полупрозрачный */
    color: #374151;                     /* ← белая иконка на тёмном */
    font-size: 18px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: background .15s;
    backdrop-filter: blur(4px);        /* ← лёгкое размытие фона под кнопкой */
    -webkit-backdrop-filter: blur(4px);
}

.cr-mobile-btn--back    { left: 8px; }
.cr-mobile-btn--members { right: 8px; }

.cr-mobile-btn:hover  { background: rgba(0, 0, 0, .6); }
.cr-mobile-btn:active { background: rgba(0, 0, 0, .75); }

@media (max-width: 900px) {
    .cr-mobile-btn {
        display: flex;
    }
    
    .cr-scroll-bottom {
        right: 16px;
    }
}