/* ==========================================================================
   1. ЛОГИКА 3D ПЕРЕВОРОТА (ТРАНСФОРМЕР)
   ========================================================================== */
.phone-core {
    perspective: 1500px;
}

.phone-core-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
}

/* Класс для разворота на сторону чата */
.phone-core-inner.is-flipped {
    transform: rotateY(180deg);
}

.side-front,
.side-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
}

.side-back {
    transform: rotateY(180deg);
    background: var(--bg-panel);
    border-radius: 20px;
}

/* ==========================================================================
   2. КОНТЕЙНЕР И ШАПКА (ЛОГО N TRAVEL)
   ========================================================================== */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px;
    box-sizing: border-box;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 15px;
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-logo-wrap {
    display: flex;
    align-items: center;
}

.chat-logo-small {
    height: 18px;
    margin-right: 10px;
    filter: brightness(0) invert(1);
}

#chatWithTitle {
    font-weight: 600;
    font-size: 16px;
    color: #fff;
}

.chat-close-btn {
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    position: relative;
}

.chat-close-btn:hover {
    transform: rotate(90deg);
}

.chat-close-btn::before,
.chat-close-btn::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 2px;
    background: var(--text-muted);
    border-radius: 2px;
    transition: 0.3s;
}

.chat-close-btn::before {
    transform: rotate(45deg);
}

.chat-close-btn::after {
    transform: rotate(-45deg);
}

.chat-close-btn:hover::before,
.chat-close-btn:hover::after {
    background: var(--danger);
}

/* ==========================================================================
   3. ЛЕНТА СООБЩЕНИЙ (МЕССЕНДЖЕР)
   ========================================================================== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 5px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.chat-empty {
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    margin-top: 50px;
    opacity: 0.5;
}

/* СТОРОНЫ: Входящие слева, Исходящие справа */
.msg {
    display: flex;
    max-width: 85%;
}

.msg.incoming {
    align-self: flex-start;
    flex-direction: column;
    align-items: flex-start;
}

.msg.outgoing {
    align-self: flex-end;
    flex-direction: column;
    align-items: flex-end;
}

/* Имя отправителя ВНУТРИ бабла */
.msg-sender {
    font-size: 9px;
    font-weight: 900;
    margin-bottom: 6px;
    color: var(--accent-alt);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    opacity: 0.8;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 4px;
}

/* Контейнер бабла */
.msg-container {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
}

.msg.outgoing .msg-container {
    flex-direction: row-reverse;
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 13px;
    position: relative;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    word-break: break-word;
}

/* Твои сообщения (справа, розовый неон) */
.msg.outgoing .msg-bubble {
    background: rgba(225, 78, 202, 0.05);
    border: 1px solid var(--accent);
    color: #fff;
    box-shadow: 0 0 15px rgba(225, 78, 202, 0.15);
    border-bottom-right-radius: 4px;
}

/* Чужие сообщения (слева, зеленый неон) */
.msg.incoming .msg-bubble {
    background: rgba(0, 242, 195, 0.05);
    border: 1px solid var(--success);
    color: #fff;
    box-shadow: 0 0 15px rgba(0, 242, 195, 0.15);
    border-bottom-left-radius: 4px;
}

.btn-reply {
    opacity: 0;
    cursor: pointer;
    font-size: 14px;
    transition: 0.2s;
    filter: grayscale(1);
}

.msg:hover .btn-reply {
    opacity: 1;
}

.msg-reply-quote {
    font-size: 11px;
    background: rgba(255, 255, 255, 0.05);
    border-left: 2px solid var(--accent);
    padding: 5px 8px;
    margin-bottom: 5px;
    border-radius: 4px;
    color: #bbb;
    font-style: italic;
}

.msg-time {
    font-size: 9px;
    color: var(--text-muted);
    margin-top: 5px;
    opacity: 0.5;
    align-self: flex-end;
}

/* ==========================================================================
   4. ЗОНА ВВОДА (ФИКС ОБРЕЗКИ И ПАНЕЛЬ В ОДНУ СТРОКУ)
   ========================================================================== */
.chat-input-area-v2 {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    padding: 15px;
    margin-top: auto;
    position: relative;
    /* Чтобы смайлы позиционировались относительно этой области */
}

/* ФИКС ОБРЕЗКИ ТЕКСТА */
.chat-input-area-v2 textarea {
    width: 100%;
    background: transparent !important;
    border: none !important;
    height: 60px !important;
    color: white;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    resize: none;
    padding: 10px 15px !important;
    box-sizing: border-box;
    line-height: 1.5;
}

/* ФУТЕР В ОДНУ СТРОКУ */
.chat-footer-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 10px 10px 10px;
}

.target-picker,
.channel-picker-v2 {
    flex-shrink: 0;
}

.target-picker {
    display: flex;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 3px;
    gap: 2px;
}

.btn-target {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 800;
    padding: 6px 10px;
    font-size: 9px;
    border-radius: 9px;
    cursor: pointer;
    transition: 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-target.active[data-target="client"] {
    background: rgba(29, 140, 248, 0.15);
    color: var(--accent-alt);
}

.btn-target.active[data-target="team"] {
    background: rgba(225, 78, 202, 0.15);
    color: var(--accent);
}

.channel-picker-v2 {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    padding: 5px 12px;
    border-radius: 30px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.channel-picker-v2.disabled {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(1);
}

.picker-label {
    font-size: 11px;
    color: var(--text-muted);
}

.picker-btns {
    display: flex;
    gap: 8px;
}

.btn-channel {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-channel.active {
    color: var(--accent-alt);
    filter: drop-shadow(0 0 5px var(--accent-alt));
}

/* КНОПКИ СПРАВА (Смайл и Отправить) */
.emoji-trigger {
    margin-left: auto;
    /* Толкает смайл вправо */
    cursor: pointer;
    font-size: 20px;
    transition: 0.2s;
    padding: 5px;
}

.emoji-trigger:hover {
    transform: scale(1.2);
}

/* ПАНЕЛЬ СМАЙЛОВ — ТЕПЕРЬ ПРИЖАТА К ПРАВОМУ КРАЮ */
.emoji-picker {
    position: absolute;
    bottom: 80px;
    /* Над футером */
    right: 15px;
    /* ТЕПЕРЬ ТУТ: Прижимаем к правому краю, где кнопка отправить */
    background: #2b2b3d;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 15px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.emoji-picker span {
    font-size: 20px;
    cursor: pointer;
    transition: 0.2s;
}

.emoji-picker span:hover {
    transform: scale(1.3);
}

.btn-send-v2 {
    background: transparent;
    border: none;
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-send-v2:hover {
    transform: translateX(3px) scale(1.1);
}

/* ==========================================================================
   5. УВЕДОМЛЕНИЯ И СКРОЛЛ
   ========================================================================== */
.notif-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 15px;
    border-radius: 30px;
    background: linear-gradient(to right, var(--danger), #ff8d72);
    box-shadow: 0 4px 15px rgba(253, 93, 147, 0.4);
    animation: notif-pulse 2s infinite;
}

.notif-badge.hidden {
    display: none;
}

.notif-count {
    background: white;
    color: var(--danger);
    font-weight: 800;
    font-size: 12px;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

@keyframes notif-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(253, 93, 147, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(253, 93, 147, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(253, 93, 147, 0);
    }
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.btn-email-reply {
    font-size: 10px;
    color: var(--accent-alt);
    cursor: pointer;
    margin-top: 8px;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    font-weight: 700;
    text-transform: uppercase;
    transition: 0.2s;
    display: inline-block;
}

.btn-email-reply:hover {
    color: #fff;
    text-shadow: 0 0 5px var(--accent-alt);
}

/* Выделяем email-сообщения легким цветом, чтобы отличать от Telegram */
.incoming .msg-bubble {
    position: relative;
}

/* Контейнер для вложений над текстом */
.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 10px 10px 10px;
}

/* Красивый чип файла */
.file-chip {
    display: flex;
    align-items: center;
    background: rgba(29, 140, 248, 0.1);
    border: 1px solid var(--accent-alt);
    color: #fff;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 11px;
    gap: 8px;
    animation: fadeIn 0.2s ease;
}

.file-chip .file-name {
    max-width: 150px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Крестик удаления на чипе */
.file-remove {
    cursor: pointer;
    color: var(--danger);
    font-weight: bold;
    font-size: 14px;
    line-height: 1;
    transition: 0.2s;
}

.file-remove:hover {
    transform: scale(1.3);
    color: #fff;
}

/* Кнопка скрепки */
.btn-attachment {
    color: var(--text-muted);
    cursor: pointer;
    transition: 0.3s;
    display: flex;
    align-items: center;
}

.btn-attachment:hover {
    color: var(--accent-alt);
    filter: drop-shadow(0 0 5px var(--accent-alt));
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Обновленный список вложений для строки */
.attachment-list {
    display: flex;
    flex-wrap: nowrap;
    /* Не переносим на новую строку, пускай скроллится вбок если надо */
    gap: 6px;
    overflow-x: auto;
    max-width: 300px;
    /* Ограничим ширину, чтобы не вытеснила смайлы */
}

/* Убираем лишние скроллбары в списке файлов */
.attachment-list::-webkit-scrollbar {
    height: 0px;
}

/* Делаем чипы файлов более мелкими для футера */
.file-chip {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #ccc;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 10px;
    gap: 5px;
    white-space: nowrap;
    flex-shrink: 0;
    /* Чтобы файлы не сжимались */
}

.file-chip:hover {
    border-color: var(--accent-alt);
    color: #fff;
}

.file-name {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-remove {
    cursor: pointer;
    color: var(--danger);
    font-size: 14px;
    font-weight: bold;
}

.chat-footer-row {
    display: flex;
    align-items: center;
    justify-content: baseline;
    /* Элементы по краям */
    gap: 15px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0 0 20px 20px;
}

/* Центральная группа со скрепкой и файлами */
.footer-center-group {
    flex: 1;
    /* РАСТЯГИВАЕМ на всё свободное пространство */
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    /* Важно для работы overflow внутри flex */
}

/* Список вложений */
.attachment-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    /* Скролл вбок, если файлов много */
    white-space: nowrap;
    padding-bottom: 2px;
    flex: 1;
}

/* Скрываем скроллбар списка файлов для эстетики */
.attachment-list::-webkit-scrollbar {
    height: 4px;
}

.attachment-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

/* Чип файла (компактный) */
.file-chip {
    display: inline-flex;
    align-items: center;
    background: rgba(29, 140, 248, 0.15);
    border: 1px solid var(--accent-alt);
    color: #fff;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 10px;
    gap: 5px;
    flex-shrink: 0;
    /* Не даем файлам сжиматься в кашу */
}

.file-name {
    max-width: 80px;
    /* Ограничиваем длину имени одного файла */
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-remove {
    cursor: pointer;
    color: var(--danger);
    font-weight: bold;
    font-size: 14px;
}

/* Кнопки справа не должны сжиматься */
.footer-right-group {
    flex-shrink: 0;
}

.msg-attachments {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 8px;
}

.attachment-link {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--accent-alt);
    text-decoration: none;
    background: rgba(255, 255, 255, 0.03);
    padding: 5px 8px;
    border-radius: 4px;
}

.attachment-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

/* Разделитель даты в чате */
.chat-date-divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 25px 0 15px 0;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.6;
}

.chat-date-divider::before,
.chat-date-divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.chat-date-divider span {
    padding: 0 15px;
}

.msg-image-wrap img {
    max-width: 100%;
    border-radius: 8px;
    transition: transform 0.2s;
}

.msg-image-wrap img:hover {
    transform: scale(1.02);
}

.msg-attachments {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 8px;
}

.chat-img {
    max-width: 100%;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}

.chat-img:hover {
    filter: brightness(1.1);
}

.chat-file-link {
    color: var(--accent-alt);
    text-decoration: none;
    font-size: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 5px 10px;
    border-radius: 5px;
    display: inline-block;
}

.chat-file-link:hover {
    background: rgba(255, 255, 255, 0.1);
}

.attachment-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 5px 15px;
}

.file-chip {
    background: var(--accent-alt);
    color: white;
    padding: 3px 8px;
    border-radius: 15px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.file-remove {
    cursor: pointer;
    font-weight: bold;
}

/* Поиск в чате */
.search-wrap {
    display: flex;
    align-items: center;
    transition: all 0.3s ease;
}

.search-wrap input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--accent-alt);
    border-radius: 8px;
    color: white;
    padding: 5px 12px;
    font-size: 12px;
    outline: none;
    width: 150px;
    box-shadow: 0 0 10px rgba(29, 140, 248, 0.2);
}

.btn-search-trigger {
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    display: flex;
    align-items: center;
}

.btn-search-trigger:hover {
    color: var(--accent-alt);
    transform: scale(1.1);
}

/* Подсветка найденного текста */
.search-highlight {
    background: rgba(255, 215, 0, 0.3);
    color: #fff;
    border-radius: 2px;
    padding: 0 2px;
}

/* Скрытие сообщений, не подошедших под поиск */
.msg.search-hidden {
    display: none !important;
}

/* Скрытие разделителей дат при поиске */
.chat-date-divider.search-hidden {
    display: none !important;
}