/* ═══════════════════════════════════════
   Основной layout
   ═══════════════════════════════════════ */
.chat-layout {
    display: flex;
    height: calc(100vh - var(--navbar-height));
    background-color: var(--bg-app);
}

/* ═══════════════════════════════════════
   Боковая панель — список чатов
   ═══════════════════════════════════════ */
.sidebar {
    width: 300px;
    min-width: 240px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar__header {
    height: 60px;
    min-height: 40px;
    padding: var(--space-lg) var(--space-xl);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.sidebar__header h3 {
    flex: 1;
    margin: 0;
    font-size: var(--font-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar__icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--font-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-base);
}

.sidebar__icon-btn:hover {
    background: var(--bg-active);
}

.sidebar__list {
    flex: 1;
    overflow-y: auto;
}

/* ═══════════════════════════════════════
   Элемент списка чатов
   ═══════════════════════════════════════ */
.chat-item {
    display: flex;
    align-items: center;
    padding: var(--space-lg);
    transition: background var(--transition-base);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item--active {
    background: var(--bg-active);
}

.chat-item__avatar {
    width: 44px;
    height: 44px;
    background: var(--accent);
    color: var(--text-on-accent);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--font-lg);
    margin-right: var(--space-md);
    flex-shrink: 0;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

.chat-item__avatar:hover {
    transform: scale(1.12);
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 2px var(--accent);
}

.chat-item__info {
    flex: 1;
    min-width: 0;
}

.chat-item__title {
    font-size: var(--font-md);
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item__title--bold {
    font-weight: 600;
}

.chat-item__unread-dot {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: var(--radius-full);
    flex-shrink: 0;
    margin-left: var(--space-sm);
}

/* ═══════════════════════════════════════
   Правая панель — переписка
   ═══════════════════════════════════════ */
.conversation {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    outline: none;
}

.conversation__header {
    height: 60px;
    min-height: 40px;
    padding: var(--space-lg) var(--space-xl);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation__header-title {
    font-size: var(--font-lg);
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: color var(--transition-base);
    margin: 0;
}

.conversation__header-title:hover {
    color: var(--accent);
}

.conversation__close-btn {
    background: none;
    border: none;
    width: 32px;
    height: 32px;
    font-size: 24px;
    font-weight: 600;
    color: var(--text-placeholder);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    padding: 0;
    transition: all var(--transition-base);
}

.conversation__close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.conversation__messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* ═══════════════════════════════════════
   Разделитель непрочитанных
   ═══════════════════════════════════════ */
.conversation__unread-divider {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--danger);
    font-size: var(--font-xs);
    font-weight: 500;
    padding: var(--space-xs) 0;
}

.conversation__unread-divider::before,
.conversation__unread-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--danger);
    opacity: 0.4;
}

/* ═══════════════════════════════════════
   Ввод сообщения
   ═══════════════════════════════════════ */
.conversation__composer {
    padding: var(--space-lg);
    border-top: 1px solid var(--border);
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
    background: var(--bg-surface);
}

.conversation__composer-input {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
}

.conversation__composer-input textarea {
    width: 100%;
    padding: var(--space-md);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    resize: none;
    font-family: inherit;
    font-size: var(--font-md);
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color var(--transition-base);
}

.conversation__composer-input textarea::placeholder {
    color: var(--text-placeholder);
}

.conversation__composer-input textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.conversation__composer button {
    padding: var(--space-md) var(--space-xl);
    background: var(--accent);
    color: var(--text-on-accent);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-md);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-base);
    align-self: stretch;
}

.conversation__composer button:hover:not(:disabled) {
    background: var(--accent-hover);
}

.conversation__composer button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════
   Пузырьки сообщений
   ═══════════════════════════════════════ */
.message-bubble {
    max-width: 70%;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    align-self: flex-start;
    background: var(--bg-message-other);
    color: var(--text-primary);
}

.message-bubble--own {
    align-self: flex-end;
    background: var(--accent);
    color: var(--text-on-accent);
}

.message-bubble__header {
    display: flex;
    justify-content: space-between;
    gap: var(--space-md);
    margin-bottom: var(--space-xs);
    font-size: var(--font-xs);
    color: var(--text-muted);
}

.message-bubble--own .message-bubble__header {
    color: rgba(255, 255, 255, 0.75);
}

.message-bubble__text {
    font-size: var(--font-md);
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.5;
}

/* ═══════════════════════════════════════
   Пустое состояние
   ═══════════════════════════════════════ */
.conversation__placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-placeholder);
    background-color: var(--bg-surface);
    font-size: var(--font-lg);
}

/* ═══════════════════════════════════════
   Модалки (специфичные стили chat)
   ═══════════════════════════════════════ */
.modal-content__users-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-xl);
}

.modal-content__no-results {
    text-align: center;
    padding: var(--space-3xl);
    color: var(--text-placeholder);
    font-size: var(--font-md);
}

.user-item {
    display: flex;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
    transition: background var(--transition-base);
}

.user-item:last-child {
    border-bottom: none;
}

.user-item:hover {
    background: var(--bg-hover);
}

.user-item--clickable {
    cursor: pointer;
}

.user-item--selectable {
    cursor: pointer;
}

.user-item--selectable:hover {
    background: var(--bg-active);
}

.user-item__checkbox {
    margin-right: var(--space-md);
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

.user-item__avatar {
    width: 40px;
    height: 40px;
    background: var(--accent);
    color: var(--text-on-accent);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--font-md);
    margin-right: var(--space-md);
    flex-shrink: 0;
    border: 2px solid transparent;
    transition: transform var(--transition-base), border-color var(--transition-base), box-shadow var(--transition-base);
}

.user-item--clickable .user-item__avatar:hover,
.user-item--selectable .user-item__avatar:hover {
    transform: scale(1.12);
    border-color: var(--accent-hover);
    box-shadow: 0 0 0 2px var(--accent);
}

.group-chat-modal__members-list .user-item__avatar {
    border: 2px solid transparent;
    transition: none;
}

.group-chat-modal__members-list .user-item__avatar:hover {
    transform: none;
    border-color: transparent;
    box-shadow: none;
}

.user-item__info {
    flex: 1;
    min-width: 0;
}

.user-item__name {
    font-weight: 600;
    font-size: var(--font-md);
    color: var(--text-primary);
}

.user-item__email {
    font-size: var(--font-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* ═══════════════════════════════════════
   Модалка группового чата
   ═══════════════════════════════════════ */
.group-chat-modal__members-header {
    margin-top: var(--space-xl);
    margin-bottom: var(--space-md);
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--text-secondary);
}

.group-chat-modal__members-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.group-chat-modal__member-badge {
    font-size: var(--font-xs);
    color: var(--text-muted);
    margin-left: var(--space-xs);
}

/* ═══════════════════════════════════════
   Toast-уведомления о новых сообщениях
   ═══════════════════════════════════════ */
.toast-container {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column-reverse;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    background: var(--bg-toast);
    color: var(--text-toast);
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 320px;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
}

.toast__body {
    flex: 1;
    min-width: 0;
}

.toast__sender {
    font-weight: 600;
    font-size: var(--font-sm);
    margin-bottom: 2px;
}

.toast__text {
    font-size: var(--font-sm);
    opacity: 0.85;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toast__close {
    background: none;
    border: none;
    color: var(--text-toast);
    font-size: var(--font-lg);
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: background var(--transition-base);
    flex-shrink: 0;
    line-height: 1;
}

.toast__close:hover {
    background: rgba(255, 255, 255, 0.15);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* ═══════════════════════════════════════
   Адаптивность
   ═══════════════════════════════════════ */
@media (max-width: 600px) {
    /* Сайдбар на мобильном — на всю ширину */
    .chat-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: 0;
        flex: 1;
        border-right: none;
    }

    .sidebar__list {
        max-height: calc(100vh - var(--navbar-height) - 60px);
    }

    /* Плейсхолдер скрыт на мобильном */
    .conversation__placeholder {
        display: none !important;
    }

    /* Когда чат выбран — сайдбар скрывается, переписка на весь экран */
    .chat-layout--chat-open .sidebar {
        display: none;
    }

    .chat-layout--chat-open .conversation {
        height: calc(100vh - var(--navbar-height));
        max-height: calc(100vh - var(--navbar-height));
        overflow: hidden;
    }

    /* Сообщения — компактнее */
    .message-bubble {
        max-width: 85%;
    }

    .conversation__composer {
        padding: var(--space-md);
    }

    .conversation__composer button {
        padding: var(--space-md) var(--space-lg);
        font-size: var(--font-sm);
    }

    /* Предотвращаем auto-zoom при фокусе на iOS (font-size >= 16px) */
    .conversation__composer-input textarea {
        font-size: 16px;
    }

    .modal-content__form-group input,
    .modal-content__form-group select {
        font-size: 16px;
    }

    .toast-container {
        top: 60px;
        bottom: auto;
        right: var(--space-md);
        left: var(--space-md);
        flex-direction: column-reverse;
    }

    .toast {
        width: 100%;
    }
}
