/* ---------------------------------- */
/* СООБЩЕНИЯ (ЕДИНЫЙ ФАЙЛ)            */
/* ---------------------------------- */

/* Базовый контейнер сообщения */
.message {
    display: flex;
    max-width: 70%;
    gap: 10px;
    position: relative;
    animation: fadeSlideUp var(--animation-duration) ease-out;
}

.message.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Аватар */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    background-size: cover;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

/* Пузырь сообщения */
.message-bubble {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    border-radius: 22px;
    padding: 10px 16px;
    position: relative;
    word-break: break-word;
    overflow-wrap: break-word;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast);
}

.message.own .message-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-bottom-right-radius: 6px;
}

.message:not(.own) .message-bubble {
    border-bottom-left-radius: 6px;
}

/* Текст сообщения */
.message-text {
    font-size: 14px;
    line-height: 1.45;
}

/* Мета-информация (время, статус) */
.message-meta {
    font-size: 10px;
    margin-top: 6px;
    text-align: right;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

/* Удалённое сообщение */
.deleted-message {
    font-style: italic;
    opacity: 0.6;
}

/* Сообщение на отправке (pending) */
.pending-message .message-bubble {
    opacity: 0.7;
    background: var(--bg-elevated);
}
.pending-message .message-meta {
    color: var(--text-secondary);
    font-style: italic;
}

/* ========================================================= */
/* ПОДСВЕТКА ОТВЕТА (REPLY) — ПРЯМО НА ПУЗЫРЕ              */
/* ========================================================= */

/* Для чужих сообщений */
.message.highlight-reply .message-bubble {
    animation: replyBubbleGlow 1.2s ease-out forwards !important;
}

/* Для своих сообщений (ярче, чтобы перебить градиент) */
.message.own.highlight-reply .message-bubble {
    animation: replyBubbleGlowOwn 1.2s ease-out forwards !important;
}

@keyframes replyBubbleGlow {
    0% {
        box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(76, 154, 255, 0.5), 0 0 16px 6px rgba(76, 154, 255, 0.6);
    }
    30% {
        box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(76, 154, 255, 0.3), 0 0 12px 4px rgba(76, 154, 255, 0.4);
    }
    60% {
        box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(76, 154, 255, 0.15), 0 0 8px 2px rgba(76, 154, 255, 0.2);
    }
    100% {
        box-shadow: var(--shadow-sm);
    }
}

@keyframes replyBubbleGlowOwn {
    0% {
        box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(76, 154, 255, 0.6), 0 0 18px 6px rgba(76, 154, 255, 0.7);
    }
    30% {
        box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(76, 154, 255, 0.35), 0 0 12px 4px rgba(76, 154, 255, 0.45);
    }
    60% {
        box-shadow: 0 0 0 2px var(--primary), 0 0 0 4px rgba(76, 154, 255, 0.15), 0 0 6px 2px rgba(76, 154, 255, 0.2);
    }
    100% {
        box-shadow: var(--shadow-sm);
    }
}

/* Реакции */
.message-reactions {
    margin-top: 8px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.reaction-badge {
    background: var(--bg-elevated);
    padding: 4px 10px;
    border-radius: 30px;
    font-size: 13px;
    transition: all var(--transition-fast);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.reaction-badge:hover {
    transform: scale(1.05);
    background: var(--primary);
    color: white;
}
.reaction-badge:active {
    transform: scale(0.95);
}
.reaction-count {
    font-size: 11px;
    font-weight: 500;
}

/* Пересланное сообщение */
.forward-marker {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.forward-marker i {
    font-size: 10px;
}
.forward-avatar {
    transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.forward-avatar:hover {
    transform: scale(1.1);
    opacity: 0.9;
}

/* Фантомное сообщение "Печатает" */
.message.typing-message {
    opacity: 0.7;
    animation: fadeSlideUp var(--animation-duration) ease-out;
}
.message.typing-message .message-avatar {
    visibility: hidden;
}
.message.typing-message .message-bubble.typing-bubble {
    background: var(--bg-surface);
    backdrop-filter: blur(12px);
    border-radius: 22px;
    padding: 10px 16px;
    box-shadow: var(--shadow-sm);
}
.message.typing-message .typing-text {
    font-size: 14px;
    font-style: italic;
    color: var(--text-secondary);
}
.typing-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    margin: 0 2px;
    animation: typingDot 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}
.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

/* Текст + время в одной строке */
.message-text-inline {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}
.message-text-inline .message-content-text {
    flex: 1;
    word-break: break-word;
}
.message-meta-inline {
    flex-shrink: 0;
    font-size: 10px;
    opacity: 0.7;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    align-self: flex-end;
}
.message.own .message-meta-inline {
    color: rgba(255, 255, 255, 0.8);
}
.message:not(.own) .message-meta-inline {
    color: var(--text-secondary);
}
.message.own .message-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
    color: white !important;
}

/* Увеличиваем ширину сообщений с видео */
.message:has(.custom-video-player) {
    max-width: 90%;
}
.message:has(.custom-video-player) .message-bubble {
    width: 100%;
}

/* Выделение сообщений (выбор нескольких) */
.message.selected .message-bubble {
    background: var(--primary-glow);
    box-shadow: 0 0 0 2px var(--primary);
    transition: all var(--transition-fast);
}
.message.selected.own .message-bubble {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    box-shadow: 0 0 0 2px var(--primary);
}
.message-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    flex-shrink: 0;
    cursor: pointer;
    font-size: 20px;
    color: var(--primary);
    transition: transform var(--transition-fast);
}
.message-checkbox i {
    pointer-events: none;
}
.message-checkbox:active {
    transform: scale(0.9);
}

/* Панель выбора (SelectionBar) */
.selection-bar {
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    z-index: var(--z-sticky);
    animation: fadeSlideUp var(--animation-duration) ease;
}
.selection-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.selection-bar-cancel {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
}
.selection-count {
    font-size: 14px;
    font-weight: 500;
}
.selection-bar-actions {
    display: flex;
    gap: 12px;
}
.selection-action-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition-fast);
}
.selection-action-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.05);
}

/* Выделенное сообщение – зелёная обводка (кастомный цвет, можно заменить на var(--success)) */
.message.selected .message-bubble {
    box-shadow: 0 0 0 2px var(--success);
    background: rgba(76, 175, 80, 0.1);
}
.message.selected.own .message-bubble {
    box-shadow: 0 0 0 2px var(--success);
    background: linear-gradient(135deg, rgba(76, 175, 80, 0.2), rgba(76, 175, 80, 0.05));
}
.message-checkbox {
    color: var(--success);
}

/* Специфичные правки для сообщений, содержащих медиа (видео, аудио) — фон прозрачный */
.message:has(.custom-video-player) .message-bubble,
.message:has(.voice-container) .message-bubble,
.message:has(.custom-audio-player) .message-bubble,
.message:has(.image-message-container) .message-bubble,
.message:has(.document-preview) .message-bubble,
.message:has(.file-preview-card) .message-bubble,
.message:has(.text-preview) .message-bubble {
    background: transparent !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    box-shadow: none !important;
}

/* ========================================================= */
/* НОВЫЕ ПРАВИЛА ДЛЯ СВЕТЛОЙ ТЕМЫ:                           */
/* текстовые сообщения – СИНИЙ ФОН (как в тёмной теме)       */
/* медиа-сообщения – без фона                               */
/* ========================================================= */

/* 1. По умолчанию для СВОИХ сообщений в СВЕТЛОЙ теме – синий градиент и белый текст */
body.light-theme .message.own .message-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark)) !important;
    color: white !important;
}

/* 2. Сбрасываем фон, отступы и тени для сообщений, которые содержат МЕДИА-КОНТЕНТ */
body.light-theme .message.own:has(.custom-video-player) .message-bubble,
body.light-theme .message.own:has(.voice-container) .message-bubble,
body.light-theme .message.own:has(.image-message-container) .message-bubble,
body.light-theme .message.own:has(.document-preview) .message-bubble,
body.light-theme .message.own:has(.file-preview-card) .message-bubble,
body.light-theme .message.own:has(.text-preview) .message-bubble {
    background: transparent !important;
    padding: 0 !important;
    box-shadow: none !important;
    color: inherit !important;
}

/* ========================================================= */
/* ПОДСВЕТКА НАЙДЕННОГО СООБЩЕНИЯ (ПОИСК) — БЛАГОРОДНОЕ СВЕЧЕНИЕ */
/* ========================================================= */

.message.highlight-search::before,
.message.highlight-search::after,
.message.highlight-search .message-bubble::before,
.message.highlight-search .message-bubble::after {
    display: none !important;
    content: none !important;
}

.message .message-bubble {
    transition: box-shadow 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1);
}

.message.highlight-search .message-bubble {
    animation: nobleGlow 1.4s ease-out forwards;
}

@keyframes nobleGlow {
    0% {
        box-shadow: 0 0 0 2px var(--primary),
        0 0 0 4px rgba(76, 154, 255, 0.4),
        0 0 16px 6px rgba(76, 154, 255, 0.5);
    }
    25% {
        box-shadow: 0 0 0 2px var(--primary),
        0 0 0 4px rgba(76, 154, 255, 0.3),
        0 0 12px 4px rgba(76, 154, 255, 0.35);
    }
    50% {
        box-shadow: 0 0 0 2px var(--primary),
        0 0 0 4px rgba(76, 154, 255, 0.15),
        0 0 8px 2px rgba(76, 154, 255, 0.2);
    }
    100% {
        box-shadow: none;
    }
}

.message.own.highlight-search .message-bubble {
    animation: nobleGlowOwn 1.4s ease-out forwards;
}

@keyframes nobleGlowOwn {
    0% {
        box-shadow: 0 0 0 2px var(--primary),
        0 0 0 4px rgba(76, 154, 255, 0.5),
        0 0 18px 6px rgba(76, 154, 255, 0.6);
    }
    25% {
        box-shadow: 0 0 0 2px var(--primary),
        0 0 0 4px rgba(76, 154, 255, 0.3),
        0 0 12px 4px rgba(76, 154, 255, 0.4);
    }
    50% {
        box-shadow: 0 0 0 2px var(--primary),
        0 0 0 4px rgba(76, 154, 255, 0.15),
        0 0 6px 2px rgba(76, 154, 255, 0.2);
    }
    100% {
        box-shadow: none;
    }
}