/**
 * Modern Chat Sidebar Styles
 * Полная переработка chat-sidebar для современного UX
 */

/* ============================================
   OVERLAY - Затемнение фона при открытом чате
   ============================================ */
.chat-sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1049;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.chat-sidebar-opened .chat-sidebar-overlay {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   ОСНОВНОЙ КОНТЕЙНЕР ЧАТА
   ============================================ */
.chat-sidebar {
    position: fixed;
    top: 0;
    right: -750px;
    /* Скрыт за пределами экрана */
    width: 750px;
    /* Увеличено в 3 раза с ~250px */
    height: 100vh;
    background: linear-gradient(180deg, #1a1f2e 0%, #0f1419 100%);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
    z-index: 1050;
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

/* Открытое состояние */
.chat-sidebar-opened .chat-sidebar {
    right: 0;
}

/* ============================================
   КОНТЕНТ ЧАТА
   ============================================ */
.chat-sidebar-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ============================================
   HEADER ЧАТА
   ============================================ */
.chat-sidebar-header {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    padding: 30px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    position: relative;
    flex-shrink: 0;
    /* Не сжимается */
}

.chat-sidebar-title {
    color: #ffffff;
    font-size: 28px;
    /* Увеличено в 2 раза */
    font-weight: 600;
    margin: 0 0 20px 0;
    letter-spacing: 0.5px;
    padding-right: 50px;
    /* Место для кнопки закрытия */
}

/* Треугольник для сообщений */
.message-body::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    border-style: solid;
}

.message.from-me .message-body::before {
    right: -8px;
    top: 10px;
    border-width: 8px 0 8px 8px;
    border-color: transparent transparent transparent rgba(255, 255, 255, 0.08);
    /* Цвет противоположного блока (для входящих) */
}

.message:not(.from-me) .message-body::before {
    left: -8px;
    top: 10px;
    border-width: 8px 8px 8px 0;
    /* Цвет противоположного блока (для исходящих) */
}

.message-body {
    position: relative;
    /* Нужно для позиционирования треугольника */
}

/* Кнопка закрытия чата */
.chat-sidebar-close {
    position: absolute;
    top: 30px;
    right: 24px;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.8);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 10;
}

.chat-sidebar-close:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
    transform: rotate(90deg);
}

.chat-sidebar-close:active {
    transform: rotate(90deg) scale(0.95);
}

/* ============================================
   ПОИСК
   ============================================ */
.chat-sidebar-header .form-group {
    margin-bottom: 0;
}

.chat-sidebar-header .input-group {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
}

.chat-sidebar-header .input-group:focus-within {
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.3);
}

#chat-sidebar-search {
    background: transparent !important;
    border: none !important;
    color: #ffffff !important;
    font-size: 18px !important;
    /* Увеличено в 2 раза */
    padding: 16px 20px !important;
    height: auto !important;
}

#chat-sidebar-search::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.chat-sidebar-header .input-group-text {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    padding: 16px 20px;
}

.chat-sidebar-header .input-group-text i {
    font-size: 20px;
}

/* ============================================
   СПИСОК КОНТАКТОВ
   ============================================ */
.chat-sidebar-contacts {
    flex: 1;
    /* Занимает всё доступное пространство */
    overflow-y: auto;
    background: #1a1f2e;
    min-height: 0;
    /* Важно для правильной работы flex */
}

.sidebar-nav-title {
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 20px 24px 12px;
    margin: 0;
}

.chat-sidebar-user-group {
    padding: 0 12px;
}

.chat-sidebar-user-group .list-group-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 20px;
    transition: all 0.3s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.chat-sidebar-user-group .list-group-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(66, 153, 225, 0.4);
    transform: translateX(-4px);
}

.chat-sidebar-user-group .list-group-item.active {
    background: linear-gradient(135deg, rgba(66, 153, 225, 0.2) 0%, rgba(49, 130, 206, 0.2) 100%);
    border-color: rgba(66, 153, 225, 0.6);
}

/* Непрочитанные диалоги: отдельная подсветка (не конфликтует с .active выбранного диалога) */
.chat-sidebar-user-group .list-group-item.is-unread {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.18);
    box-shadow: inset 4px 0 0 rgba(251, 191, 36, 0.95);
}

.chat-sidebar-user-group .list-group-item.is-unread .message-sender {
    font-weight: 800;
}

.chat-sidebar-user-group .list-group-item.is-unread::after {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 999px;
    margin-left: auto;
    background: rgba(251, 191, 36, 0.95);
    box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.15);
}

.chat-sidebar-user-group .list-group-item.active.is-unread {
    /* При выборе диалога оставляем "selected" стиль приоритетным, но сохраняем индикатор непрочитанного */
    box-shadow: inset 4px 0 0 rgba(251, 191, 36, 0.95);
}

/* Аватар */
.chat-sidebar-user-group .thumb-sm {
    width: 56px !important;
    height: 56px !important;
    margin-right: 16px !important;
}

.chat-sidebar-user-group .thumb-sm img {
    width: 56px !important;
    height: 56px !important;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

/* Имя отправителя */
.message-sender {
    color: #ffffff;
    font-size: 20px !important;
    /* Увеличено в 2 раза */
    font-weight: 600;
    margin: 0 0 6px 0 !important;
}

/* Превью сообщения */
.message-preview {
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px !important;
    /* Увеличено в 2 раза */
    margin: 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 600px;
}

/* ============================================
   ОКНО ДИАЛОГА
   ============================================*/
/* Панели (список контактов и окна диалогов) */
.chat-sidebar-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

.chat-sidebar-contacts.open {
    padding-top: 120px !important;
    /* Список контактов без отступа при открытии */
    transform: translateX(0);
}

.chat-sidebar-chat {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1a1f2e;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    padding-top: 100px !important;
    /* Чат всегда с отступом 100px */
}

.chat-sidebar-chat.open {
    transform: translateX(0);
}

/* Заголовок диалога */
.chat-sidebar-chat .title {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    padding: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    position: relative;
    /* Для позиционирования крестика */
}

.chat-sidebar-chat .title h6 {
    margin: 0;
    font-size: 24px;
    /* Увеличено в 2 раза */
    font-weight: 600;
    padding-right: 50px;
    /* Место для крестика */
}

.chat-sidebar-chat .title a {
    color: #ffffff;
    text-decoration: none;
    display: flex;
    align-items: center;
    transition: color 0.3s ease;
}

.chat-sidebar-chat .title a:hover {
    color: rgba(66, 153, 225, 1);
}

.chat-sidebar-chat .title i {
    font-size: 28px;
    margin-right: 12px;
}

/* Крестик в окне диалога */
.chat-sidebar-chat .title .chat-sidebar-close {
    position: absolute;
    top: 20px;
    right: 24px;
}

/* ============================================
   СПИСОК СООБЩЕНИЙ
   ============================================ */
.message-list {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    padding-bottom: 54px;
    /* Отступ снизу чтобы последнее сообщение не было под input box (24px + 30px) */
    list-style: none;
    margin: 0;
    min-height: 0;
    /* Важно для правильной работы flex */
}

.message-list .message {
    margin-bottom: 24px;
    display: flex;
    align-items: flex-start;
    flex-direction: row;
}

.message-list .message.from-me {
    flex-direction: row-reverse;
}

.message-list .message .thumb-sm {
    width: 56px;
    height: 56px;
    flex-shrink: 0;
}

.message-list .message .thumb-sm img {
    width: 48px !important;
    height: 48px !important;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.message-list .message.from-me .thumb-sm {
    margin-left: 16px;
}

.message-list .message:not(.from-me) .thumb-sm {
    margin-right: 16px;
}

/* Контейнер для текста и даты */
.message-content {
    display: flex;
    flex-direction: column;
    max-width: 500px;
}

.message.from-me .message-content {
    align-items: flex-end;
}

.message:not(.from-me) .message-content {
    align-items: flex-start;
}

/* Тело сообщения */
.message-body {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    padding: 16px 20px;
    border-radius: 16px;
    font-size: 18px !important;
    /* Увеличено в 2 раза */
    line-height: 1.5;
    max-width: 500px;
    word-wrap: break-word;
    margin-bottom: 8px;
    /* Отступ для даты */
}

.message.from-me .message-body {
    background: linear-gradient(135deg, #3a4556 0%, #2d3748 100%);
    color: #ffffff !important;
    border-bottom-right-radius: 4px;
}

.message:not(.from-me) .message-body {
    border-bottom-left-radius: 4px;
}

/* Дата сообщения */
.message-date-left,
.message-date-right {
    font-size: 14px !important;
    color: rgba(255, 255, 255, 0.5);
    padding-top: 4px;
}

/* ============================================
   FOOTER - ПОЛЕ ВВОДА
   ============================================ */
.chat-sidebar-footer {
    background: linear-gradient(135deg, #2d3748 0%, #1a202c 100%);
    padding: 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    /* Не сжимается - всегда виден внизу */
}

#chat-sidebar-input {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 2px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 12px !important;
    color: #ffffff !important;
    font-size: 18px !important;
    /* Увеличено в 2 раза */
    padding: 24px 20px !important;
    /* Увеличена высота в 2 раза */
    height: auto !important;
    min-height: 80px !important;
    transition: all 0.3s ease;
}

#chat-sidebar-input:focus {
    background: rgba(255, 255, 255, 0.12) !important;
    border-color: rgba(66, 153, 225, 0.6) !important;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.2) !important;
    outline: none;
}

#chat-sidebar-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
    font-size: 18px;
}

/* ============================================
   SCROLLBAR СТИЛИЗАЦИЯ
   ============================================ */
.chat-sidebar-contacts::-webkit-scrollbar,
.message-list::-webkit-scrollbar {
    width: 8px;
}

.chat-sidebar-contacts::-webkit-scrollbar-track,
.message-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-sidebar-contacts::-webkit-scrollbar-thumb,
.message-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.chat-sidebar-contacts::-webkit-scrollbar-thumb:hover,
.message-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   АДАПТИВНОСТЬ
   ============================================ */
@media (max-width: 768px) {
    .chat-sidebar {
        width: 100%;
        right: -100%;
    }
}

/* ============================================
   УТИЛИТЫ
   ============================================ */
.chat-sidebar-user-group .list-group-item.hide {
    display: none;
}

.message-list .message.hide {
    display: none;
}

/* Убираем старые стили slimScroll */
.chat-sidebar .slimScrollDiv,
.chat-sidebar .slimScrollBar,
.chat-sidebar .slimScrollRail {
    display: none !important;
}
