/* === COMPONENT: base.css === */
/* --- Переменные и системные настройки --- */
:root {
    --bg-dark: #0f111a;
    --bg-sidebar: #ffffff;
    --chat-received: #f1f3f9;
    --chat-sent: #0d6efd;
    --top-nav-height: 60px;
    --sidebar-width: 320px;
}

body {
    background: #f8f9fa;
    font-family: Inter, -apple-system, sans-serif;
    height: 100dvh;
    overflow: hidden;
    margin: 0;
}

.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
}

/* --- Вспомогательные утилиты (Helpers) --- */
.cursor-pointer {
    cursor: pointer;
}

.bg-dark-soft {
    background: #232735 !important;
}

.smaller {
    font-size: 0.8rem;
}

.hover-bg:hover {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
}

/* --- Общие элементы интерфейса --- */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    flex-shrink: 0;
}

.logo-circle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: #0d6efd;
    color: #fff;
    border-radius: 30%;
    overflow: hidden;
    z-index: 1000;
}

.nav-logo-img {
    width: 130%;
    height: 130%;
    object-fit: contain;
}

/* --- Верхняя панель (Header) --- */
.top-nav {
    height: var(--top-nav-height);
    background: var(--bg-dark);
    z-index: 1000;
}

.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* --- Кастомные скроллбары --- */
.custom-scrollbar::-webkit-scrollbar {
    width: 5px;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #eee;
    border-radius: 10px;
}


/* === COMPONENT: sidebar.css === */
/* --- Структура сайдбара --- */
.sidebar {
    width: var(--sidebar-width);
    background: #fff;
    display: flex;
    flex-direction: column;
}

.chat-list {
    flex-grow: 1;
    overflow-y: auto;
}

/* --- Элемент списка чатов (Элемент диалога) --- */
.chat-item {
    cursor: pointer;
    transition: 0.2s;
    border-radius: 12px;
    margin: 0 8px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.chat-item:hover {
    background: #f8f9fa;
}

.chat-item.active {
    background: #eef2ff;
    color: #0d6efd;
}

/* --- Логика непрочитанных чатов --- */
.chat-item.unread-chat .text-truncate {
    color: var(--chat-sent) !important;
    font-weight: 600 !important;
}

.unread-chat .smaller {
    color: #007bff !important;
}

.unread-dot {
    width: 8px;
    height: 8px;
    background-color: #007bff;
    border-radius: 50%;
    flex-shrink: 0;
}

/* --- Аватары и Онлайн-статусы --- */
.avatar,
.avatar-sm {
    background: #ddd;
    border-radius: 12px;
    flex-shrink: 0;
}

.avatar {
    width: 45px;
    height: 45px;
    position: relative;
}

.avatar-sm {
    width: 32px;
    height: 32px;
}

.online::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border: 2px solid #fff;
    border-radius: 50%;
}

/* --- Глобальный поиск в сайдбаре --- */
#search-results {
    max-height: 400px;
    overflow-y: auto;
    scrollbar-width: thin;
}

/* --- Анимации --- */
@keyframes statusPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.4);
    }
}


/* === COMPONENT: chat_window.css === */
/* --- Общая структура окна --- */
.chat-window {
    flex-grow: 1;
    background: #fff;
}

.chat-header {
    height: 64px;
}

.chat-body {
    background: #fdfdfd;
    overflow-y: auto;
}

/* --- Разделитель дат в истории переписки --- */
.chat-date-separator {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 20px 0;
    color: #888;
    font-size: 0.85rem;
}

.chat-date-separator::before,
.chat-date-separator::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #eee;
}

.chat-date-separator:not(:empty)::before {
    margin-right: 1em;
}

.chat-date-separator:not(:empty)::after {
    margin-left: 1em;
}

/* --- Футер и Зона ввода сообщения --- */
.input-wrapper {
    background: #f8f9fa;
    border-radius: 20px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
}

.chat-footer {
    background: #fff;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
}

/* --- Кнопка быстрой прокрутки вниз --- */
.scroll-down-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 20px;
    bottom: 80px;
    width: 40px;
    height: 40px;
    background-color: #fff;
    color: #007bff;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: pointer;
    z-index: 1000;
    transition: 0.3s;
    opacity: 1;
}

.scroll-down-btn:hover {
    background-color: #f8f9fa;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.scroll-down-btn.d-none {
    display: none !important;
}

.scroll-down-btn i {
    font-size: 1.2rem;
    line-height: 0;
}

/* --- Контекстное меню действий (например, удаление) --- */
#contextMenu {
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 8px;
    min-width: 200px;
    max-width: 90vw;
    font-size: 1rem;
}

#contextMenu a {
    display: block;
    padding: 8px 12px;
    color: #333;
    text-decoration: none;
    border-radius: 6px;
}

#contextMenu a:hover {
    background-color: #f5f5f5;
}

/* ==========================================================================
   АДАПТИВНОСТЬ И МОБИЛЬНАЯ ВЕРСИЯ (Media Queries)
   ========================================================================== */

@media (max-height: 500px) {
    .top-nav {
        display: none;
    }
}

/* Общий фикс для скрытия лишних панелей, когда на мобильном открыт чат */
body.chat-opened .sidebar .sidebar-footer,
body.chat-opened .top-nav {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    border: none !important;
    opacity: 0 !important;
    min-height: 0 !important;
}

body.chat-opened .chat-window {
    top: 0 !important;
    margin-top: 0 !important;
}

/* Специфика для смартфонов */
@media (max-width: 767.98px) {
    .sidebar {
        width: 100% !important;
        display: flex;
    }

    .chat-window,
    .search-bar {
        display: none !important;
    }

    .chat-window {
        position: fixed;
        top: var(--top-nav-height);
        left: 0;
        width: 100%;
        height: calc(100dvh - var(--top-nav-height));
        z-index: 1050;
        background: #fff;
    }

    .chat-window.mobile-active {
        display: flex !important;
    }

    .chat-body {
        flex: 1;
        overflow-y: auto;
    }

    .chat-footer {
        flex-shrink: 0;
        padding-bottom: calc(15px + env(safe-area-inset-bottom)) !important;
    }

    body.chat-opened .chat-window.mobile-active {
        top: 0 !important;
        height: 100dvh !important;
    }
}

/* Оптимизация для мобильных PWA в автономном режиме (Standalone) */
@media (max-width: 767.98px) and (display-mode: standalone) {
    body.chat-opened .chat-window.mobile-active {
        height: 100vh !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
    }
}


/* === COMPONENT: message_status.css === */
/* ==========================================
   КОНТЕЙНЕРЫ СООБЩЕНИЙ (Ряды в чате)
   ========================================== */
.msg-received,
.msg-sent {
    display: flex;
    width: 100%;
    margin-bottom: 12px;
}

.msg-sent {
    justify-content: flex-end;
}

.msg-received {
    justify-content: flex-start;
}

/* ==========================================
   БАББЛЫ (Пузыри сообщений)
   ========================================== */
.msg-bubble {
    display: inline-flex;
    flex-direction: column;
    position: relative;
    max-width: 75%;
    /* Оптимально для мобильных и десктопов */
    min-width: 90px;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    word-break: break-word;
    box-sizing: border-box;
}

/* Специфика отправленных (ваших) сообщений */
.msg-sent .msg-bubble {
    background: var(--chat-sent, #0d6efd);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 3px 10px rgba(13, 110, 253, 0.15);
}

/* Специфика полученных сообщений */
.msg-received .msg-bubble {
    background: var(--chat-received, #f1f3f9);
    color: #000000;
    border-bottom-left-radius: 4px;
}

/* Элемент самого текста внутри баббла */
.msg-text {
    display: block;
    width: 100%;
    padding-bottom: 2px;
    /* Небольшой зазор перед временем */
}

/* ==========================================
   БЛОК СТАТУСА И ВРЕМЕНИ (Внизу справа)
   ========================================== */
.msg-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    align-self: flex-end;
    /* Всегда прижимает блок к правому нижнему углу */
    font-size: 0.7rem;
    margin-top: 2px;
    margin-left: auto;
    /* Сдвигает блок вправо, если текст короткий */
    padding-left: 15px;
    /* Защитный отступ, чтобы текст не слипался со временем */
    opacity: 0.75;
    user-select: none;
    line-height: 1;
    pointer-events: none;
    /* Чтобы галочки не мешали выделять текст */
}

/* Цвета статусов для отправленных сообщений */
.msg-sent .msg-status {
    color: rgba(255, 255, 255, 0.75);
}

/* Цвета статусов для полученных сообщений */
.msg-received .msg-status {
    color: #6c757d;
}

/* Иконки статуса внутри блока */
.status-icon {
    font-size: 0.95rem;
    line-height: 1;
    margin-left: 3px;
    display: inline-block;
    vertical-align: middle;
}

/* Специфический цвет для прочитанных синих галочек */
.status-read {
    color: #4fc3f7 !important;
    /* Светло-голубой, отлично виден на синем фоне */
}

/* ==========================================
   ДОПОЛНИТЕЛЬНЫЕ ЭЛЕМЕНТЫ (Анимации и Меню)
   ========================================== */
/* Иконка ожидания (спиннер) */
.spin-icon {
    animation: rotation 1s infinite linear;
}

@keyframes rotation {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Контекстное меню повторной отправки */
#chat-context-menu {
    min-width: 130px;
    background: #ffffff;
    border-radius: 8px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#chat-context-menu .dropdown-item {
    cursor: pointer;
    transition: background 0.2s;
}

#chat-context-menu .dropdown-item:hover {
    background-color: #f8f9fa;
}

