﻿.ai-msg-user {
    align-self: flex-end;
    background: #3699FF;
    color: #fff;
    border-radius: 16px 16px 4px 16px;
    max-width: 75%;
    padding: 10px 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.ai-msg-assistant {
    align-self: flex-start;
    background: #e5e5e5;
    color: #1e2129;
    border-radius: 16px 16px 16px 4px;
    max-width: 75%;
    padding: 10px 14px;
    word-break: break-word;
    min-width: 0;
    overflow-x: auto;
}

/* Wide answers scroll inside their bubble instead of squeezing table columns. */
#kt_modal_ai_salyk .modal-content > .flex-grow-1,
#kt_modal_ai_salyk_public .modal-content > .flex-grow-1,
.ai-msg-wrapper-assistant {
    min-width: 0;
}

.ai-msg-assistant table {
    width: max-content;
    min-width: 100%;
    max-width: none;
    border-collapse: collapse;
}

.ai-msg-assistant th,
.ai-msg-assistant td {
    white-space: nowrap;
    word-break: normal;
    padding: 6px 10px;
    vertical-align: top;
}

.ai-msg-assistant p {
    margin-bottom: 0.5rem;
}

.ai-msg-assistant p:last-child {
    margin-bottom: 0;
}

.ai-msg-assistant ul,
.ai-msg-assistant ol {
    padding-left: 1.2rem;
    margin-bottom: 0.5rem;
}

.ai-msg-assistant li {
    margin-bottom: 0.2rem;
}

.ai-msg-assistant code {
    background: #d0d0d0;
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.85em;
    font-family: monospace;
}

.ai-msg-assistant pre {
    background: #d0d0d0;
    border-radius: 8px;
    padding: 10px 12px;
    overflow-x: auto;
    margin-bottom: 0.5rem;
}

.ai-msg-assistant pre code {
    background: none;
    padding: 0;
}

.ai-msg-assistant h1,
.ai-msg-assistant h2,
.ai-msg-assistant h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0.5rem 0 0.25rem;
}

.ai-msg-assistant strong {
    font-weight: 600;
}

.ai-msg-assistant a {
    color: #3699FF;
}

.ai-msg-wrapper-user {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.ai-msg-wrapper-assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.ai-msg-time {
    font-size: 0.8rem;
    color: #9aa0a6;
    margin-top: 2px;
    padding: 0 4px;
}

.ai-typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin: 0 2px;
    background: #aaa;
    border-radius: 50%;
    animation: ai-bounce 1.2s infinite;
}

    .ai-typing-indicator span:nth-child(2) {
        animation-delay: .2s;
    }

    .ai-typing-indicator span:nth-child(3) {
        animation-delay: .4s;
    }

.ai-star {
    font-size: 2rem;
    color: #ccc;
    cursor: pointer;
    transition: color 0.1s;
    line-height: 1;
}

@keyframes ai-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Маскот AI Salyk: ролик поверх ленты сообщений, слева над полем ввода.
   Фон ролика (244,246,247) практически совпадает с .ai-salyk-bg (#f7f8fa),
   поэтому подложка и обрезка не нужны — видео показываем целым кадром.
   Кадрировать нельзя: по 24 кадрам объединённый bbox движения — x 4..239
   из 270 (белка машет хвостом в обе стороны), любой обрез срезал бы хвост. */
.ai-salyk-mascot {
    position: absolute;
    left: 12px;
    bottom: 8px;
    width: 120px;
    height: 120px;
    pointer-events: none;
    z-index: 2;
    opacity: 1;
    visibility: visible;
    transition: opacity .2s ease, visibility .2s ease;
}

    /* Прячем маскота, когда пользователь прокручивает переписку вверх. */
    .ai-salyk-mascot.ai-salyk-mascot-hidden {
        opacity: 0;
        visibility: hidden;
    }

    .ai-salyk-mascot img {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    /* До первого ролика у картинки нет src, а Chrome обводит рамкой пустой <img>
       с заданными размерами — она мелькала, пока модалка выезжает и до greet()
       (CHATBOT-33). Ролик всегда ставится через новый узел уже с src. */
    .ai-salyk-mascot img:not([src]) {
        visibility: hidden;
    }

    /* Пока модель обрабатывает вопрос, белки нет: в чате играет видео (CHATBOT-30).
       Отдельный класс, чтобы не спорить с ai-salyk-mascot-hidden от прокрутки. */
    .ai-salyk-mascot.ai-salyk-mascot-off {
        opacity: 0;
        visibility: hidden;
    }

/* Переход между анимациями: белая "пиксельная" шторка поверх ролика или видео.
   Показывается только на время перехода, содержимое под ней меняется в середине. */
.ai-salyk-mascot-wipe {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

    /* Вне перехода шторка спрятана. Селектор с тегом, чтобы перебить
       `.ai-salyk-mascot img { display: block }`: из-за него шторка над белкой
       оставалась на экране всегда — до первого перехода без src, и Chrome рисовал
       её рамку (тот самый "квадрат", CHATBOT-33), а после — зациклённый GIF
       повторял пробег поверх белки без всякого перехода (CHATBOT-31). */
    img.ai-salyk-mascot-wipe:not(.ai-salyk-mascot-wipe-active) {
        display: none;
    }

/* Видео "раздумий" вместо пузыря с точками, пока готовится ответ (CHATBOT-30).
   Карточка на всю ширину ленты, пропорции ролика (1616x1078, то есть 3:2);
   шторка перехода растянута на всю карточку и обрезается по краям
   (object-fit: cover). Скрипт ограничивает карточке max-width, чтобы она вместе
   с вопросом над ней помещалась в видимую часть ленты (CHATBOT-31). */
.ai-thinking-video {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 2;
    border-radius: 16px 16px 16px 4px;
    overflow: hidden;
    background: #e5e5e5;
}

    .ai-thinking-video video {
        display: block;
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .ai-thinking-video video.ai-thinking-video-pending {
        visibility: hidden;
    }

    .ai-thinking-video .ai-salyk-mascot-wipe {
        object-fit: cover;
    }

/* .p-4 задаёт padding с !important, поэтому перебиваем по id:
   нижний отступ, чтобы последнее сообщение не уходило под маскота.
   Оба чата: публичный (#ai-public-messages) и внутренний (#ai-chat-messages). */
#ai-public-messages,
#ai-chat-messages {
    padding-bottom: 140px !important;
}

    /* Пока в ленте карточка с видео, белки нет — и отступ под неё не нужен:
       с ним карточка и вопрос не помещались на экран вместе (CHATBOT-31).
       Значение как у .p-4 остальных сторон. */
    #ai-public-messages.ai-thinking,
    #ai-chat-messages.ai-thinking {
        padding-bottom: 1rem !important;
    }

/* Белка вместо эмодзи 🐿️ перед дисклеймером под полем ввода (CHATBOT-28).
   Картинка вертикальная, поэтому задаём высоту, ширина подстраивается. */
.ai-salyk-disclaimer-icon {
    display: inline-block;
    height: 2rem;
    width: auto;
    vertical-align: middle;
    margin-right: .25rem;
}
/* Actions wrap below the input when the composer is too narrow for one row. */
.ai-composer { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem; background: var(--bs-body-bg, #fff); }
.ai-composer .ai-composer-input {
    flex: 1 1 16rem;
    min-width: 0;
    width: auto;
    max-width: 100%;
    field-sizing: content;
    resize: none;
    max-height: 200px;
    overflow-y: auto;
}
.ai-voice-buttons { display: flex; flex: 0 0 auto; gap: .25rem; margin-left: auto; }
.ai-voice-buttons button { flex-shrink: 0; }
.ai-voice-status:empty { display: none; }
.ai-voice-settings[hidden], .ai-voice-settings [hidden] { display: none !important; }
.ai-voice-replay { align-self: flex-start; margin-top: 4px; }
.ai-voice-replay[hidden] { display: none !important; }
