/* Чат по прототипу docs/prototypes/chat. Цвета — палитра темы и токены портала: «активное» — тот же
   --accent-light, что в остальных разделах, счётчик непрочитанного — --highlight, как у значка в шапке. */
:root {
    --chat-own: color-mix(in srgb, var(--mud-palette-primary) 16%, var(--mud-palette-surface));
    --chat-radius: 18px;
}

/* ══════ Каркас страницы ══════ */
/* Страница — мессенджер во всю высоту окна под шапкой и полосой свёрнутого звонка
   (--lk-callbar-h задаёт livekit-room.css, пока звонок свёрнут); прокручиваются список и переписка. */
.chat-shell.container {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--header-h) - var(--lk-callbar-h, 0px));
    padding-block: 16px 20px;
}

/* Нижняя граница высоты — только в высоком окне: на телефоне, повёрнутом набок, мессенджер
   остаётся в экране целиком, а не уводит поле ввода под сгиб. */
@media (min-height: 640px) {
    .chat-shell.container {
        min-height: 520px;
    }
}

.chat-page-heading {
    padding: 4px 0 18px;
}

.chat-page-title {
    font-family: var(--font-display);
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--mud-palette-text-primary);
}

.chat-page-sub {
    margin-top: 6px;
    font-size: 13px;
    color: var(--mud-palette-text-secondary);
}

.chat-page {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 306px minmax(0, 1fr);
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: var(--chat-radius);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

/* Кнопка-значок чата: спокойная, со скруглённым квадратом наведения. Класс стоит на самой кнопке
   или на меню MudBlazor, внутри которого она лежит. */
.chat-icon-btn.mud-icon-button,
.chat-icon-btn .mud-icon-button {
    padding: 9px;
    border-radius: 10px;
    color: var(--mud-palette-text-secondary);
}

.chat-icon-btn.mud-icon-button:hover,
.chat-icon-btn .mud-icon-button:hover {
    color: var(--mud-palette-primary);
    background: var(--bg-hover);
}

.chat-icon-btn--soft.mud-icon-button {
    color: var(--mud-palette-primary);
    background: var(--accent-light);
}

/* ══════ Список чатов ══════ */
.chat-sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    border-right: 1px solid var(--mud-palette-lines-default);
    background: var(--mud-palette-surface);
}

.chat-list {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-list-header {
    padding: 20px 18px 14px 20px;
}

.chat-list-title {
    font-size: 18px;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--mud-palette-text-primary);
}

.chat-list-count {
    margin-left: 5px;
    font-size: 13px;
    font-weight: 400;
    color: var(--mud-palette-text-secondary);
}

.chat-list-search {
    padding: 0 18px;
}

.chat-list-search .mud-input-control {
    margin: 0;
}

.chat-list-search .mud-input {
    font-size: 13px;
    background: var(--mud-palette-background);
}

.chat-filters {
    padding: 14px 16px 8px;
}

.chat-filter.mud-button-root {
    min-width: 0;
    padding: 6px 8px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
}

.chat-filter.mud-button-root:hover {
    background: var(--bg-hover);
}

.chat-filter--active.mud-button-root,
.chat-filter--active.mud-button-root:hover {
    font-weight: 500;
    color: var(--mud-palette-primary);
    background: var(--accent-light);
}

.chat-list-items {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px 10px 18px;
    scrollbar-width: thin;
    scrollbar-color: var(--mud-palette-lines-default) transparent;
}

.chat-list-empty {
    flex: 1;
    padding: 40px 20px;
    text-align: center;
    font-size: 13px;
    color: var(--mud-palette-text-secondary);
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    margin-bottom: 3px;
    padding: 13px 10px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-list-item:hover {
    background: var(--bg-hover);
}

.chat-list-item--active,
.chat-list-item--active:hover {
    background: var(--accent-light);
}

.chat-list-item:focus-visible,
.chat-header-target:focus-visible,
.chat-reaction-chip:focus-visible,
.chat-attachment-image:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.chat-list-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-list-item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-list-item-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item-time {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

.chat-list-item-preview {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-item-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border-radius: 6px;
    background: var(--highlight);
    color: var(--text-on-highlight);
    font-size: 11px;
    font-weight: 500;
}

/* ══════ Аватар ══════ */
.chat-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    font-size: 14px;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
    user-select: none;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-avatar-wrap {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    line-height: 0;
}

.chat-avatar-dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--mud-palette-success);
    border: 2px solid var(--mud-palette-surface);
}

.chat-avatar--sm ~ .chat-avatar-dot {
    width: 9px;
    height: 9px;
}

.chat-avatar--sm {
    width: 30px;
    height: 30px;
    min-width: 30px;
    font-size: 11px;
}

.chat-avatar.chat-avatar--xs {
    width: 22px;
    height: 22px;
    min-width: 22px;
    font-size: 11px;
}

/* Аватары без фото — из палитры темы: четыре сплошных тона со своим цветом букв и четыре мягких,
   на которых буквы — цветом основного текста. Контраст букв в обеих темах не ниже 5:1. */
.chat-avatar--c0 { background: var(--mud-palette-primary); color: var(--mud-palette-primary-text); }
.chat-avatar--c1 { background: var(--mud-palette-tertiary-darken); color: var(--mud-palette-tertiary-text); }
.chat-avatar--c2 { background: var(--mud-palette-secondary); color: var(--mud-palette-secondary-text); }
.chat-avatar--c3 { background: var(--mud-palette-dark); color: var(--mud-palette-dark-text); }
.chat-avatar--c4 { background: color-mix(in srgb, var(--mud-palette-primary) 30%, var(--mud-palette-surface)); }
.chat-avatar--c5 { background: color-mix(in srgb, var(--mud-palette-tertiary-darken) 30%, var(--mud-palette-surface)); }
.chat-avatar--c6 { background: color-mix(in srgb, var(--mud-palette-secondary) 35%, var(--mud-palette-surface)); }
.chat-avatar--c7 { background: var(--mud-palette-gray-lighter); }

/* Беседа — скруглённый квадрат цветом акцента: в списке её видно с первого взгляда. */
.chat-avatar--group {
    border-radius: 14px;
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

/* ══════ Переписка ══════ */
.chat-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--mud-palette-background);
}

.chat-empty {
    flex: 1;
    color: var(--mud-palette-text-secondary);
}

.chat-empty-icon.mud-icon-root {
    font-size: 64px;
    opacity: 0.3;
}

.chat-window {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.chat-window-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    background: var(--mud-palette-surface);
}

.chat-window-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.chat-action-divider {
    width: 1px;
    height: 22px;
    margin: 0 7px;
    background: var(--mud-palette-lines-default);
}

.chat-header-target {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
    padding: 2px 6px 2px 2px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: none;
    transition: background 0.15s;
}

a.chat-header-target:hover,
.chat-header-target--clickable:hover {
    background: var(--bg-hover);
}

.chat-header-target--clickable {
    cursor: pointer;
}

.chat-window-header-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.chat-window-header-title {
    font-size: 16px;
    font-weight: 500;
    color: var(--mud-palette-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-window-header-subtitle {
    font-size: 12px;
    color: var(--mud-palette-text-secondary);
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px clamp(20px, 4%, 54px) 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--mud-palette-lines-default) transparent;
}

.chat-sentinel {
    height: 1px;
    flex-shrink: 0;
}

.chat-date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 6px 0 2px;
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
}

.chat-date-separator::before,
.chat-date-separator::after {
    content: "";
    width: 58px;
    height: 1px;
    background: var(--mud-palette-lines-default);
}

/* ══════ Сообщение ══════ */
.chat-msg {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 88%;
    min-width: 0;
    align-self: flex-start;
}

.chat-msg--own {
    align-self: flex-end;
    max-width: 80%;
}

.chat-msg--system {
    align-self: center;
}

.chat-msg-avatar-link {
    display: inline-flex;
    margin-bottom: 2px;
    color: inherit;
    text-decoration: none;
}

.chat-msg-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

.chat-msg--own .chat-msg-body {
    align-items: flex-end;
}

.chat-bubble-sender,
.mud-link.chat-bubble-sender {
    margin: 0 0 5px 2px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--mud-palette-text-secondary);
}

.chat-bubble {
    position: relative;
    min-width: 110px;
    max-width: 100%;
    padding: 11px 15px 7px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 13px 13px 13px 4px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.chat-msg--own .chat-bubble {
    border-color: transparent;
    border-radius: 13px 13px 4px 13px;
    background: var(--chat-own);
}

.chat-bubble-text {
    display: block;
    line-height: 1.6;
    white-space: pre-wrap;
}

.chat-bubble-time {
    display: flex;
    justify-content: flex-end;
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--mud-palette-text-secondary);
}

/* ══════ Печатает ══════ */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 4px;
    color: var(--mud-palette-text-secondary);
    font-size: 12px;
}

.chat-typing-dots {
    display: inline-flex;
    gap: 3px;
}

.chat-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--mud-palette-text-secondary);
    opacity: 0.5;
    animation: chat-typing-bounce 1.2s infinite ease-in-out;
}

.chat-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ══════ Поле ввода ══════ */
/* Поле живёт и на странице чата, и в узкой панели чата комнаты: подсказку и подпись кнопки
   прячет ширина самого поля (container query), а не ширина окна. */
.chat-input-wrap {
    container: chat-composer / inline-size;
    padding: 12px 24px 20px;
}

.chat-composer {
    padding: 12px 14px 9px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 13px;
    background: var(--mud-palette-surface);
    transition: border-color 0.15s;
}

.chat-composer:focus-within {
    border-color: var(--mud-palette-primary);
}

.chat-input-field { margin: 0; }
.chat-input-field .mud-input-control-input-container { margin: 0; }
.chat-input-field .mud-input { margin: 0; color: var(--mud-palette-text-primary); font: inherit; }
.chat-input-field textarea {
    padding: 2px 2px 8px;
    font-size: 14px;
    line-height: 1.5;
    max-height: 150px;
    scrollbar-width: thin;
    scrollbar-color: var(--mud-palette-lines-default) transparent;
}

.chat-composer-tools {
    min-width: 0;
}

.chat-input-hint {
    margin-left: 7px;
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-send-btn.mud-button-root {
    flex-shrink: 0;
    min-width: 40px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
}

.chat-send-btn .mud-button-icon-end {
    margin-left: 10px;
    margin-right: 0;
}

@container chat-composer (max-width: 520px) {
    .chat-input-hint,
    .chat-send-label {
        display: none;
    }

    .chat-send-btn .mud-button-icon-end {
        margin-left: 0;
    }
}

.chat-attach-upload {
    display: inline-flex;
}

.chat-paste-input {
    display: none;
}

/* ══════ Вложения — в сообщении ══════ */
.chat-bubble--media-only {
    padding: 0;
    border: 0;
    overflow: hidden;
}

.chat-attachments-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin: 0 0 8px;
}

.chat-bubble--media-only .chat-attachments-images {
    margin: 0;
}

.chat-attachment-image {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    line-height: 0;
    cursor: pointer;
}

.chat-attachment-image img {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 9px;
}

.chat-bubble--media-only .chat-attachment-image img {
    border-radius: inherit;
}

.chat-bubble--media-only .chat-bubble-time {
    position: absolute;
    right: 6px;
    bottom: 6px;
    margin: 0;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--mud-palette-overlay-dark);
    color: var(--mud-palette-white);
    pointer-events: none;
}

.chat-attachment-file {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    max-width: 100%;
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: 9px;
    background: var(--mud-palette-background);
    color: inherit;
    text-decoration: none;
}

.chat-msg--own .chat-attachment-file {
    background: rgba(var(--mud-palette-surface-rgb), 0.6);
}

.chat-attachment-file:hover {
    filter: brightness(1.05);
}

.chat-attachment-icon {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 38px;
    height: 44px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 6px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-tertiary);
}

.chat-attachment-meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.chat-attachment-name {
    font-size: 12px;
    font-weight: 500;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.chat-attachment-size {
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
}

.chat-attachment-download.mud-icon-root {
    color: var(--mud-palette-text-secondary);
}

/* ══════ Вложения — перед отправкой ══════ */
.chat-input-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.chat-attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 240px;
    padding: 6px 6px 6px 12px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--accent-light);
}

.chat-attachment-chip--error {
    border-color: var(--mud-palette-error);
}

.chat-attachment-chip-meta {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

.chat-attachment-chip-name {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-attachment-chip-size {
    font-size: 11px;
    color: var(--mud-palette-text-secondary);
}

/* ══════ Реакции ══════ */
.chat-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 6px;
}

.chat-reaction-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font-size: 12px;
    line-height: 1.5;
    cursor: pointer;
    transition: border-color 0.1s, background 0.1s;
}

.chat-reaction-chip:hover {
    background: var(--bg-hover);
}

.chat-reaction-chip--mine,
.chat-reaction-chip--mine:hover {
    border-color: var(--mud-palette-primary);
    background: var(--accent-light);
}

.chat-reaction-count {
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-text-secondary);
}

/* «Добавить реакцию» всплывает над правым верхним углом сообщения по наведению и по фокусу с клавиатуры. */
.chat-reaction-add {
    position: absolute;
    top: -14px;
    right: 4px;
    z-index: 1;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 8px;
    background: var(--mud-palette-surface);
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-reaction-add .mud-icon-button {
    padding: 4px 5px;
    border-radius: 6px;
    color: var(--mud-palette-text-secondary);
}

.chat-reaction-add .mud-icon-button:hover {
    color: var(--mud-palette-primary);
}

.chat-msg:hover .chat-reaction-add,
.chat-reaction-add:focus-within {
    opacity: 1;
}

/* Пальцем навести нельзя: кнопка реакции стоит рядом с сообщением постоянно. */
@media (hover: none), (pointer: coarse) {
    .chat-reaction-add {
        position: static;
        align-self: flex-end;
        border: 0;
        background: transparent;
        opacity: 1;
    }
}

.chat-reaction-popover.mud-popover {
    padding: 0;
    border-radius: 12px;
}

.chat-reaction-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    padding: 8px;
}

.chat-reaction-pick-btn {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.1s;
}

.chat-reaction-pick-btn:hover {
    background: var(--bg-hover);
}

/* ══════ Звонок строкой (без модуля звонков) ══════ */
.chat-call-bubble {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 16px;
    background: rgba(var(--mud-palette-text-secondary-rgb), 0.12);
    color: var(--mud-palette-text-secondary);
    font-size: 13px;
}

.chat-call-bubble--missed {
    background: rgba(var(--mud-palette-error-rgb), 0.12);
    color: var(--mud-palette-error);
}

/* ══════ Всплывающее сообщение ══════ */
.chat-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 2px 4px;
}

.mud-snackbar:has(.chat-toast),
.mud-snackbar:has(.chat-toast) .mud-snackbar-content-message {
    cursor: pointer;
}

.mud-snackbar:has(.chat-toast) .mud-snackbar-icon {
    display: none !important;
}

.chat-toast-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-toast-name {
    font-size: 0.95rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}

.chat-toast-text {
    font-size: 0.8rem;
    opacity: 0.75;
}

/* ══════ Окно участников ══════ */
.chat-dialog-name {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.chat-dialog-name > .mud-input-control {
    flex: 1;
}

.chat-name-pencil {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: transparent;
    border: 1px solid transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s;
    flex-shrink: 0;
    vertical-align: middle;
}

.chat-name-pencil .mud-icon-root {
    font-size: 16px;
    color: var(--mud-palette-text-secondary);
}

.chat-name-pencil:hover {
    background: var(--mud-palette-action-default-hover);
    border-color: var(--mud-palette-lines-default);
}

.chat-name-pencil:hover .mud-icon-root {
    color: var(--mud-palette-primary);
}

.chat-participant-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.chat-participant-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ══════ Просмотр картинки ══════ */
.chat-image-preview-content {
    padding: 0 !important;
    background: transparent !important;
}

.chat-image-preview-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.chat-image-preview {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.chat-image-preview-name {
    color: var(--mud-palette-text-primary);
    font-size: 0.85rem;
    opacity: 0.8;
    word-break: break-all;
    text-align: center;
    padding: 0 12px;
}

.chat-image-preview-close {
    position: absolute !important;
    top: 8px;
    right: 8px;
    z-index: 2;
    background: rgba(0, 0, 0, 0.45) !important;
    color: #fff !important;
}

.chat-image-preview-close:hover {
    background: rgba(0, 0, 0, 0.65) !important;
}

/* ══════ По ширине ══════ */
/* Ниже 1280px шапка портала в две строки, высота нужнее переписке: заголовок раздела не виден,
   но остаётся заголовком первого уровня для скринридера. */
@media (max-width: 1279.98px) {
    .chat-page-heading {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

@media (max-width: 959.98px) {
    .chat-page {
        grid-template-columns: 280px minmax(0, 1fr);
    }

    .chat-window-header {
        padding: 14px 16px;
    }

    .chat-action-divider {
        margin: 0 2px;
    }
}

/* Телефон: мессенджер на весь экран, сначала список, выбранная переписка — вместо него. */
@media (max-width: 599.98px) {
    .chat-shell.container {
        padding: 0;
    }

    .chat-page {
        grid-template-columns: minmax(0, 1fr);
        border: 0;
        border-radius: 0;
        box-shadow: none;
    }

    .chat-sidebar {
        border-right: 0;
    }

    .chat-main,
    .chat-page--active .chat-sidebar {
        display: none;
    }

    .chat-page--active .chat-main {
        display: flex;
    }

    /* Действия переписки уходят во вторую строку шапки: название чата не обрезается до трёх букв. */
    .chat-window-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }

    .chat-header-target {
        flex: 1;
    }

    .chat-window-header-actions {
        width: 100%;
        justify-content: flex-end;
        margin-left: 0;
        padding-top: 6px;
        border-top: 1px solid var(--mud-palette-lines-default);
    }

    .chat-messages {
        padding: 18px 12px;
    }

    .chat-msg,
    .chat-msg--own {
        max-width: 94%;
    }

    .chat-msg-avatar-link {
        display: none;
    }

    .chat-bubble {
        padding: 10px 12px 7px;
    }

    .chat-input-wrap {
        padding: 10px 12px 14px;
    }

    /* Меньше 16px — Safari приближает страницу при фокусе в поле. */
    .chat-list-search .mud-input,
    .chat-input-field textarea {
        font-size: 16px;
    }
}
