/* mysite/chat/static/chat/css/base.css */

html {

    -webkit-text-size-adjust: 100%;
    /*
        Safari НЕ будет сам увеличивать/уменьшать текст
    */

    text-size-adjust: 100%;
    /*
        Стандартное свойство
    */
}

/* Дефолтные перемнные темы */
:root {
    --chat-bg-image: none;           /* По умолчанию без изображения */
    --chat-bg-overlay: rgba(0,0,0,0); /* Затемнение поверх изображения */

    /* ===== ОСНОВА ===== */
    --bg: #0E1621;                /* Общий фон всего приложения (body) */
    --chat-bg: #0f0f0f;           /* Фон области сообщений (чат) */

    /* ===== ТЕКСТ ===== */
    --text-color: #e1e1e1;        /* Основной цвет текста */
    --text-muted: #ace5ff;        /* Вторичный текст (подсказки, контакты) */
    --accent-color: #147ff1;      /* Акцент (ссылки, выделения, активные элементы) */

    /* ===== INPUT ===== */
    --input-bg: #17212B;          /* Фон поля ввода */
    --input-border: #2b2b2b96;    /* Граница поля ввода */
    --input-focus: #18426b25;     /* Цвет границы/эффекта при фокусе */
    --input-text: #e1e1e1;        /* Цвет текста в поле ввода */

    /* ===== ИКОНКИ ===== */
    --icon-color: #8e8e93;        /* Цвет иконок по умолчанию */
    --icon-hover: #3390ec;        /* Цвет иконок при наведении */

    /* ===== HOVER ===== */
    --hover-bg: #2b2b2b;          /* Универсальный фон при hover */

    /* ===== МЕНЮ ===== */
    --menu-bg: #1f1f1f;           /* Фон выпадающих меню */
    --menu-text: #e1e1e1;         /* Цвет текста в меню */
    --menu-hover: #2b2b2b;        /* Фон пункта меню при наведении */

    /* ===== HEADER ===== */
    --header-bg: #1d2735;         /* Фон верхней панели (header) */
    --header-text: #e1e1e1;       /* Цвет текста в header */
    --header-border: #2b2b2b;     /* Нижняя граница header */

    /* ===== СООБЩЕНИЯ ===== */
    --msg-user-bg: #3390ec;       /* Фон сообщений пользователя */
    --msg-user-text: #ffffff;     /* Текст сообщений пользователя */
    --msg-bot-bg: #182533;        /* Фон сообщений бота */
    --msg-bot-text: #e1e1e1;      /* Текст сообщений бота */

    /* ===== КНОПКИ ===== */
    --chat-btn-bg: #1D2B3A;       /* Фон кнопок (inline / клавиатура) */
    --chat-btn-text: #ADB4BA;     /* Цвет текста кнопок */

    /* ===== КНОПКА ПРОКРУТКИ ⬇ ===== */
    --scroll-btn-bg: #1D2B3A;     /* Фон кнопки "вниз" */
    --scroll-btn-text: #ADB4BA;   /* Цвет стрелки и текста */

    /* ===== BADGE ===== */
    --val-btn-bg: #3390ec;        /* Фон бейджа (+N сообщений) */

    /* ===== REACTIONS ===== */
    --reaction-btn-bg: rgba(255,255,255,0.12);   /* Фон кнопки реакции */
    --reaction-btn-hover: rgba(255,255,255,0.25);/* Hover фон реакции */
    --reaction-btn-color: #ffffff;               /* Цвет эмодзи/иконки */
    --reaction-bg: rgba(0,0,0,0.12);             /* Фон выбранных реакций */

    /* ===== ССЫЛКИ ===== */
    --link-color: #4da6ff;       /* Цвет ссылок */

    /* ===== DROPDOWN ===== */
    --dropdown-bg: #1e1e1e;      /* Фон dropdown-меню */

    /* ===== AVATAR ===== */
    --avatar-bg: #4a90e2;        /* Фон аватарки */
    --avatar-text: #ffffff;      /* Цвет текста/буквы в аватарке */

    /* ===== SHADOW ===== */
    --shadow-color: rgba(0, 0, 0, 0.3); /* Универсальная тень */

    /* ===== SCROLLBAR ===== */
    --scrollbar-thumb: rgba(120,120,120,0.35);       /* Ползунок скролла */
    --scrollbar-thumb-hover: rgba(120,120,120,0.6);  /* Ползунок при hover */
    
    --header-height: 44px;
    --input-height: 58px;

    /* Круглая стрелка перезагрузки */
    --header-btn-size: 2.3rem;
    --theme-button-bg: rgba(255,255,255,0.08);
    --theme-button-hover-bg: rgba(255,255,255,0.18);
    --theme-button-color: rgb(172, 172, 172);

    /* УВета заголовка выбора темы */
    --theme-background-color: #1e1e1e;     /* тёмный фон */ 
    --theme-color: #f0f0f0;                /* светлый читаемый текст */
    --theme-padding: 20px 15px;
    --theme-margin: 0 0 20px 0;
    --theme-border-radius: 8px;            /* скругление по желанию */
    --theme-font-weight: 600;
    
}

/* Заголовок выбора темы */
.theme-header {
    background-color: var(--theme-background-color);     /* тёмный фон */
    color: var(--theme-color);                /* светлый читаемый текст */
    padding: var(--theme-padding);
    margin: var(--theme-margin);
    border-radius: var(--theme-border-radius);
    font-weight: var(--theme-font-weight);
}

/* ===== 1. КОМПОНЕНТЫ ТЕМЫ И ВЫПАДАЮЩИЕ СПИСКИ ===== */
.theme-dropdown {
    position: relative;
    display: inline-block;
}

/* ===== 2. БЛОК ПОЛЬЗОВАТЕЛЯ ===== */
.user-block {
    margin-right: 10px;
}

html,
body {
    margin: 0;
    padding: 0;

    width: 100%;
    height: 100%;

    overflow: hidden;
}

/* ===== 6. ОКНО ЧАТА (ОСНОВНОЙ ФОН) ===== */
/* .chat-window {
    background: var(--chat-bg);
} */

/* ===== 7. МЕНЮ ТЕМ (ВЫБОР ЦВЕТОВОЙ СХЕМЫ) ===== */
.theme-menu {
    opacity: 0;
    transform: translateY(-5px);
    transition: 0.2s;
    
    position: absolute;

    top: calc(100%);  /* 👈 ключевое исправление */
    right: 0;

    background: var(--menu-bg);
    color: var(--menu-text);

    border-radius: 10px;
    padding: 8px;

    box-shadow: 0 8px 25px rgba(0,0,0,0.2);

    display: flex;
    flex-direction: column;
    gap: 4px;

    min-width: 180px;
    z-index: 9999;

    max-height: 80vh;      /* 👈 ограничение по высоте (70% экрана) */
    overflow-y: auto;      /* 👈 включает вертикальный скролл */
    overflow-x: hidden;    /* 👈 на всякий случай */
}
/* Красивая прокрутка */
.theme-menu::-webkit-scrollbar {
    width: 6px;
}
.theme-menu::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 6px;
}
.theme-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.6);
}

.theme-menu:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
}

.menu-btn {
    display: flex;
    gap: 6px;
    align-items: center; /* center;*/
}

/* по умолчанию показываем текст */
.menu-text {
    display: inline;
    font-size: 12px;
    margin-left: 4px;
}

/* ===== 10. ТЕЛО ЧАТА (ОБЛАСТЬ С СООБЩЕНИЯМИ) ===== */
/* .chat-body {
    background: var(--chat-bg);
    padding: 15px;
    overflow-y: auto;
    height: calc(100vh - 120px);
} */

.chat-body {
    background: var(--chat-bg);
    padding: 15px;
}

/* ===== 11. СТИЛИ "ПУЗЫРЕЙ" СООБЩЕНИЙ ===== */
/* реакции внутри пузыря */
.msg-bubble .msg-reaction-bubble {
    margin-top: 6px;
    margin-left: 0;
    background: rgba(0,0,0,0.15);
}

@keyframes reaction-pop {
    0% {
        transform: scale(0.5) translateY(6px);
        opacity: 0;
    }
    60% {
        transform: scale(1.2) translateY(-2px);
        opacity: 1;
    }
    100% {
        transform: scale(1);
    }
}

.msg-reaction-bubble span {
    animation: reaction-pop 0.25s ease;
}

/* 🔥 пузырь реакций */
.msg-reaction-bubble {
    position: absolute;
    bottom: -18px;
    left: 12px;

    display: inline-flex;
    gap: 4px;

    padding: 2px 6px;
    border-radius: 999px;

    background: var(--val-btn-bg);
    color: var(--text-color);

    font-size: 12px;
}

.msg-reaction-bubble:empty {
    display: none;
}

.msg-reaction-bubble span {
    font-size: 13px;
    cursor: default;
}

.reaction-item.active {
    padding: 2px 5px;
    border-radius: 8px;

    background: transparent;
}

/* 👤 USER (твои сообщения) */
.msg-row.user .msg-reaction-controls {
    right: 100%;
}
/* 🤖 BOT (ответы) */
.msg-row.bot .msg-reaction-controls {
    left: 100%;
}

.msg-row.user .msg-reactions {
    right: calc(100% + 8px);
}
.msg-row.bot .msg-reactions {
    left: calc(100% + 8px);
}

.msg-row.bot .msg-reactions {
    left: calc(100% + 8px);
}

/* .msg-reaction-controls {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
} */

/* Задержка появление меню реакций */
.msg-bubble:hover .msg-reaction-trigger {
    opacity: 1;
    pointer-events: auto;

    transition-delay: 1s; /* 👈 ВОТ ТВОЯ ЗАДЕРЖКА */
}

.msg-reaction-trigger:hover {
    background: var(--reaction-btn-hover);
    transform: translateY(-50%) scale(1.1);
}

.msg-row:hover .msg-reaction-trigger {
    opacity: 1;
    pointer-events: auto;
    transition-delay: 1s;
}

.msg-text {
    display: block;
}

/* USER (слева от пузыря) */
.msg-row.user .msg-bubble .msg-reaction-trigger {
    left: -32px;
}
/* BOT (справа от пузыря) */
.msg-row.bot .msg-bubble .msg-reaction-trigger {
    right: -32px;
}


.msg-row.show-reactions .msg-reactions {
    display: flex;
}

.msg-reactions span {
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: 0.15s;
}

.msg-reactions span:hover {
    background: var(--hover-bg);
    transform: scale(1.2);
}

.msg-reactions span.active {
    opacity: 1;
    background: rgba(255, 200, 0, 0.3);
    transform: scale(1.1);
}

/* ===== 13. КНОПКА ВЫБОРА ТЕМЫ ===== */
#theme-btn {
    background: linear-gradient(135deg, #5f9cff00, #7c5fff00);
    color: var(--text-color);
    border: none;
    border-radius: 12px;
    padding: 6px 10px;
    cursor: pointer;
}

/* ===== 14. КНОПКА АВТОРИЗАЦИИ ===== */
#auth-btn {
    background: transparent;
    border: none;
    font-size: 17px;
    cursor: pointer;
    color: var(--icon-color);
}

#auth-btn:hover {
    color: var(--icon-hover);
}

/* ===== 15. КНОПКИ ПАНЕЛИ ВВОДА ===== */
.chat-input-panel button {
    background: transparent;
    border: none;
    font-size: 18px;
    color: var(--icon-color);
    cursor: pointer;
    transition: 0.2s;
}

.chat-input-panel button:hover {
    color: var(--icon-hover);
    background: var(--hover-bg);
    border-radius: 8px;
}

/* ===== 16. ПИКЕР ЭМОДЗИ (ВЫПАДАЮЩЕЕ ОКНО) ===== */
.emoji-picker {
    position: fixed;
    bottom: 70px;      /* над инпутом */
    right: 10px;          /* привязка к правому краю */
    
    max-width: calc(100vw - 20px); /* никогда не выйдет за экран */
    width: 320px;

    box-sizing: border-box;   /* ВАЖНО */
    overflow: hidden;         /* ВАЖНО */

    z-index: 9999;
}
.emoji-picker em-emoji-picker,
.emoji-picker .emoji-mart {
    width: 100% !important;
    max-width: 100% !important;
}
/* адаптивность пикера эмодзи */
@media (max-width: 500px) {
    .emoji-picker {
        right: 4;
        left: 4;
        margin: auto;
        width: auto;             /* убираем фикс */
        max-width: calc(100vw - 8px);

        bottom: 80px;
    }
}
/* Надпись внутри окна Эмодзи "Pick an emoji…" */
.emoji-picker {
    --font-size: 10px;
    --category-label-font-size: 10px;
}

/* ========================================= */
/* ===== 19. ДЕЙСТВИЯ ВНУТРИ ПОЛЯ ВВОДА ===== */
/* ========================================= */
.input-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.chat-input-panel {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px;
    width: 100%;
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
}

/* ========================================= */
/*    ===== ОФОРМЛЕНИЕ ПОЛЯ ВВОДА =====      */
/* ========================================= */
#message-input {
    width: 100%;
    background: var(--input-bg, #ffffff);
    border: 1px solid var(--input-border, #ccc);
    border-radius: 20px;
    /* padding: 6px 15px; */
    font-family: inherit;
    font-size: 16px;
    color: var(--input-text, #333);

    resize: none;
    overflow: hidden;

    max-height: 120px;
    min-height: 38px;

    line-height: 1.4;

    box-sizing: border-box;

    transition: height 0.12s ease;
}

#message-input:focus {
    outline: none;
    border-color: var(--input-focus, #5f9cff);
}


/* Контейнеры для групп кнопок (левых и правых) */
.left-actions,
.right-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    position: relative;
}

/* ========================================= */
/* ===== 20. ВЕРХНИЙ ХЕДЕР ЧАТА (ФИКСИРОВАННЫЙ) ===== */
/* ========================================= */
.chat-header {
    position: sticky;

    top: 0;

    z-index: 1000;

    height: var(--header-height);

    display: flex;
    justify-content: space-between;
    align-items: center;

    padding: 0 12px;

    background: var(--hover-bg);
    color: var(--text-color);

    flex-shrink: 0;
}

/* Оформление кнопок внизу */
.chat-input-bar button {
    font-size: 16px;      /* было больше */
    padding: 6px;
    background: var(--input-bg);
    border: none;
    color: var(--text-color);

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;
    border-radius: 8px;
}
/* Подложка под кнопки под курсором */
.chat-input-bar button:hover {
    background: var(--input-border);
    transform: scale(1.1);
    transition: 0.15s;
}


.msg-bubble:hover .msg-reaction-button {
    opacity: 1;
    pointer-events: auto;
    transition-delay: 1s;
}

.msg-row.user {
    justify-content: flex-end;
}

.msg-row.bot {
    justify-content: flex-start;
}

/* ===== 22. ЦВЕТА ПУЗЫРЕЙ В ЗАВИСИМОСТИ ОТ ОТПРАВИТЕЛЯ ===== */
.msg-row.user .msg-bubble {
    background: var(--msg-user-bg);
    color: var(--msg-user-text);
}

.msg-row.bot .msg-bubble {
    background: var(--msg-bot-bg);
    color: var(--msg-bot-text);
}

/* МЕНЮ СТИЛЕЙ */
.theme-option {
    display: block;
    width: 100%;
    margin-bottom: 6px;

    padding: 8px 10px;

    border: none;
    border-radius: 8px;

    text-align: left;
    cursor: pointer;

    /* ✨ база */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.575);
    transition: all 0.2s ease;
}
.theme-option:hover {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 6px 18px rgba(214, 206, 206, 0.25);
    filter: brightness(1.08);
}

/* ===== КНОПКИ ВЫПАДАЮЩЕГО МЕНЮ ТЕМЫ */
.theme-default {
    background: linear-gradient(135deg, #ffffff, #8f8f8f);
    color: #222;
}
.theme-dark {
    background: linear-gradient(135deg, #2a2a2a, #1a1a1a);
    color: #eee;
}
.theme-ocean {
    background: linear-gradient(135deg, #0284c7, #035683);
    color: var(--text-color);
}
.theme-sunset{
    background: linear-gradient(135deg, #f97316, #c04a0a);
    color: var(--text-color);
}
.theme-forest{
    background: linear-gradient(135deg, #059669, #02503a);
    color: var(--text-color);
}
.theme-midnight{
    background: linear-gradient(135deg, #8b5cf6, #541faa);
    color: var(--text-color);
}
.theme-cherry{
    background: linear-gradient(135deg, #9e1331, #57071b);
    color: var(--text-color);
}
.theme-mint{
    background: linear-gradient(135deg, #10b981, #046647);
    color: var(--text-color);
}
.theme-lavender{
    background: linear-gradient(135deg, #8b5cf6, #5e2cb4);
    color: var(--text-color);
}
.theme-coffee{
    background: linear-gradient(135deg, #92400e, #52240a);
    color: var(--text-color);
}
.theme-neon{
    background: linear-gradient(135deg, #00ff88, #01944d);
    color: #4e4e4e;
}
.theme-pastel{
    background: linear-gradient(135deg, #f0abfc, #b860c5);
    color: #575757;
}
.theme-grayscale{
    background: linear-gradient(135deg, #404040, #1d1b1b);
    color: var(--text-color);
}
.theme-royal{
    background: linear-gradient(135deg, #fbbf24, #c58009);
    color: #ffffff;
}
.theme-sakura{
    background: linear-gradient(135deg, #ec4899, #ac1f5e);
    color: var(--text-color);
}
.theme-arctic{
    background: linear-gradient(135deg, #0ea5e9, #036a9e);
    color: var(--text-color);
}
.theme-autumn{
    background: linear-gradient(135deg, #ea580c, #923009);
    color: var(--text-color);
}
.theme-matrix{
    background: linear-gradient(135deg, #00cc00, #016b01);
    color: #ffffff;
}
.theme-telegram{
    background: linear-gradient(135deg, #0E1621, #455e83);
    color: #b1b1b1;
}
.theme-twilight{
    background: linear-gradient(135deg, #c084fc, #8a46ca);
    color: #fcfcfc;
}
.theme-coral{
    background: linear-gradient(135deg, #f43f5e, #b9183b);
    color: var(--text-color);
}
.theme-glassmorphism{
    background: linear-gradient(135deg,#7f37dd,#4f46e5);
    color:#fff;
}
.theme-aurora{
    background: linear-gradient(135deg,#14b8a6,#2563eb);
    color:#fff;
}
.theme-bordeaux_rose{
    background: linear-gradient(135deg,#7f1d1d,#be185d);
    color:#fff;
}
.theme-mint_frost{
    background: linear-gradient(135deg,#10b981,#34d399);
    color:#fff;
}
.theme-ember_glow{
    background: linear-gradient(135deg,#ea580c,#fb923c);
    color:#fff;
}
.theme-sakura_dream{
    background: linear-gradient(135deg,#ec4899,#f472b6);
    color:#fff;
}
.theme-amethyst_haze{
    background: linear-gradient(135deg,#7c3aed,#a78bfa);
    color:#fff;
}
.theme-oceanic_abyss{
    background: linear-gradient(135deg,#1e3a8a,#0f172a);
    color:#fff;
}
.theme-sunset_soda{
    background: linear-gradient(135deg,#f97316,#fb7185);
    color:#fff;
}
.theme-dark_frost{
    background: linear-gradient(135deg,#111827,#475569);
    color:#fff;
}
.theme-forest_whisper{
    background: linear-gradient(135deg,#166534,#10b981);
    color:#fff;
}


/**/
.theme-option {
    transition: all 0.2s ease;
    border-radius: 8px;
}
.theme-option:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.theme-dark:hover {
    background: linear-gradient(135deg, #2a2a2a, #444);
}

.theme-ocean:hover {
    background: linear-gradient(135deg, #0284c7, #38bdf8);
}

.theme-forest:hover {
    background: linear-gradient(135deg, #059669, #34d399);
}

/* Оформление нижнего бара по темам */
.chat-input-bar {

    position: fixed;

    left: 0;
    right: 0;
    bottom: 0;

    z-index: 1000;

    padding-top: 4px;
    padding-left: 6px;
    padding-right: 6px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));

    height: var(--input-height);

    display: flex;
    align-items: center;
}


.chat-input-panel button {
    color: var(--icon-color);
}

.chat-input-panel button:hover {
    color: var(--icon-hover);
    background: var(--hover-bg);
}

.chat-header .left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-input-bar.typing .input-wrapper {
    flex: 1;
}

.left-actions,
.right-actions {
    transition: all 0.2s ease;
}

/* КНОПКА ПРОКРУТКИ ⬇  */
.scroll-down {
    position: fixed;
    right: 20px;
    bottom: 80px;
    padding: 8px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 4px 10px var(--shadow-color);
    z-index: 9999;

    display: flex;
    align-items: center;
    gap: 6px;

    background: var(--scroll-btn-bg, #436080);
    color: var(--scroll-btn-text, #fff);

    transition: 0.2s ease;
}
/* бейдж (цифра на стрелке вниз)*/
.scroll-badge {
    background: var(--val-btn-bg);
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 12px;
    min-width: 18px;
    text-align: center;
    
    background: var(--val-btn-bg);
    color: var(--text-color);
}

.scroll-down:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.scroll-down.hidden {
    display: none;
    
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
}

#new-msg-count {
    font-size: 12px;
    font-weight: 500;
}

/* Соообщения в чате */
#messages { 
            /* height: calc(100vh - 120px);  */
            overflow-y: auto;
            scroll-behavior: smooth;
          }

/* Красивый бар */
.tg-chat::-webkit-scrollbar {
    width: 6px;
}

.tg-chat::-webkit-scrollbar-track {
    background: transparent;
}

.tg-chat::-webkit-scrollbar-thumb {
    background: rgba(120, 120, 120, 0.35);
    border-radius: 10px;
    transition: 0.2s;
}

.tg-chat::-webkit-scrollbar-thumb:hover {
    background: rgba(120, 120, 120, 0.6);
}

.msg-row.hover .msg-reaction-button {
    opacity: 1;
    pointer-events: auto;
}

.msg-reaction-bar:empty {
    display: none;
}

/* Поле сообщения */
.msg-bubble {
    position: relative;
    max-width: 85%;         /* Ширина поля сообщения */
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;

    display: flex;
    width: fit-content;

    padding: 10px 14px;     /* одинаково сверху/снизу */
    white-space: pre-line;  /* Перенос строк в чате по \n */

    flex-direction: column;
}

/* 👤 USER — слева от пузыря */
.msg-reaction-button {
    position: absolute;
    top: 4px;

    width: 26px;
    height: 26px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    cursor: pointer;

    opacity: 0;
    pointer-events: none;

    background: var(--reaction-btn-bg);
    color: var(--reaction-btn-color);

    transition: 0.2s ease;
}

.msg-row {
    display: flex;
    margin-bottom: 4px; /* Растояние между полями сообщений */
}

/* 👤 USER (слева от сообщения) */
.msg-row.user .msg-reaction-button {
    right: 100%;
    margin-right: 6px;
}

/* 🤖 BOT (справа от сообщения) */
.msg-row.bot .msg-reaction-button {
    left: 100%;
    margin-left: 6px;
}

.msg-reaction-button.visible {
    opacity: 1;
}

.msg-reaction-bar {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.reaction-item {
    background: var(--reaction-bg);
    padding: 2px 6px;
    border-radius: 12px;
}

/* POPUP */
.msg-reaction-popup {
    position: fixed;

    display: flex;
    flex-direction: column;

    height: 130px;          /* 🔥 фикс: ровно ~5 эмодзи */
    overflow-y: auto;       /* скролл внутри */

    padding: 6px 4px;
    gap: 6px;

    border-radius: 12px;
    background: var(--menu-bg);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);

    z-index: 99999;

    overscroll-behavior: contain; /* 🔥 важно */

    overflow-y: auto;
    overflow-x: hidden;
}

.msg-reaction-popup::before,
.msg-reaction-popup::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 20px;
    pointer-events: none;
    z-index: 2;
}

.msg-reaction-popup::before {
    top: 0;
    background: linear-gradient(to bottom, var(--menu-bg), transparent);
}

.msg-reaction-popup::after {
    bottom: 0;
    background: linear-gradient(to top, var(--menu-bg), transparent);
}

.msg-reaction-popup::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

.msg-reaction-popup span {
    cursor: pointer;
    font-size: 18px;
    transition: 0.15s;
}

.msg-reaction-popup span:hover {
    transform: scale(1.3);
}

.hidden {
    display: none !important;
}

.msg-row:hover .msg-reaction-button {
    opacity: 1;
    pointer-events: auto;
}

/* Оформление: Авторизация */
.auth-wrapper {
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 10px;
    transition: 0.2s;
}

.auth-display {
    display: flex;
    align-items: center;
    gap: 6px;
}
.auth-menu {
    position: absolute;
    top: 100%;
    left: 0;   /* 🔥 фикс — меню влево */
    background: rgb(92, 92, 92);
    border-radius: 10px;
    padding: 8px;
    min-width: 160px;
    z-index: 999;
    transition: all 0.2s ease;
}
.auth-menu.hidden {
    display: none;
}
.auth-item {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--text-color);
}
.auth-item:hover {
    background: rgba(255,255,255,0.1);
}

/* Аватар */
.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--avatar-bg);
    color: var(--text-color);

    display: flex;
    align-items: center;
    justify-content: center;

    font-weight: bold;
    font-size: 14px;
}
#auth-btn {
    transition: transform 0.2s ease;
}
#auth-btn:hover {
    transform: scale(1.1);
}

/*   TELEGRAM STYLE BUTTONS */
.msg-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 👈 2 колонки */
    gap: 8px;
    margin-top: 8px;
}
.msg-btn {
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s ease;

    /* 👇 ТЕМА */
    background: var(--chat-btn-bg);
    color: var(--chat-btn-text);
}
/* hover */
.msg-btn:hover {
    filter: brightness(0.95);
}
/* click */
.msg-btn:active {
    transform: scale(0.96);
}
/* как у Telegram — растягивание */
.msg-btn {
    flex: 1 1 auto;
    min-width: 100px;
    text-align: center;
}

/* Отображение профиля */
.profile-block {
    line-height: 1.5;
    color: var(--text-color);
}

.profile-title {
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--accent-color);
}

.profile-contact {
    margin-left: 10px;
    color: var(--text-muted);
}

.profile-contact.primary {
    color: var(--accent-color);
    font-weight: 500;
}

.profile-primary {
    color: var(--accent-color);
    font-weight: 600;
}

/* Фон и цвет значка вместо аватарки */
.avatar-fallback {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--chat-btn-bg);
    color: var(--chat-btn-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

/* Оформление нижнего меню */
.menu-wrapper {
    position: relative;
}
/* Выпадение нижнего меню */
.dropdown-menu {
    position: absolute;
    bottom: 50px;
    left: 0;

    background: var(--dropdown-bg);
    border-radius: 12px;
    
    min-width: 250px; 
    padding: 10px;

    display: flex;
    flex-direction: column;
    gap: 4px;

    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 999;
    
    opacity: 0;
    
    transform: translateY(10px) scale(0.95);
    pointer-events: none;

    transition: all 0.2s ease;
}
/* Выравнивание меню footer */
.dropdown-menu .menu-item {
    text-align: left;
    display: flex;
    justify-content: flex-start;
}

.dropdown-menu.hidden {
    display: none;
}

.menu-item {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 10px 14px;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;           /* 🔥 растянуть */
    /* justify-content: flex-start; 👈 ключ */
    padding: 10px 12px;
    border-radius: 8px;

    cursor: pointer;
}

.menu-item:hover {
    background: rgba(255,255,255,0.1);
}

.dropdown-menu:not(.hidden) {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Свойства изображения в сообщении */
/* .chat-image {
    width: auto;
    height: auto;

    max-width: 320px;
    max-height: 500px;

    border-radius: 10px;
    margin-bottom: 8px;

    cursor: pointer;
    display: block;
} */
.chat-image {
    display: block;

    max-width: min(320px, 70vw);

    border-radius: 12px;
    cursor: pointer;
}

.chat-video {
    width: 100%;
    max-width: 260px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.chat-link {
    display: block;
    color: var(--link-color);
    margin-top: 6px;
    text-decoration: none;
}

.chat-file {
    display: block;
    margin-top: 6px;
}

.msg-attachments {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

/* Обработка кнопки записи голоса и отображение анимации звуковой волны */
.mic-record-ui {
    display: flex;
    align-items: center;
    gap: 10px;

    padding: 6px 10px;

    border-radius: 14px;

    background: rgba(255,255,255,0.08);

    backdrop-filter: blur(10px);

    margin-right: 8px;
}
.mic-record-ui.hidden {
    display: none;
}
.mic-wave {
    display: flex;
    align-items: flex-end;
    gap: 3px;

    height: 20px;
}
.mic-wave span {
    width: 3px;

    background: #4ade80;

    border-radius: 999px;

    animation: micWave 1s infinite ease-in-out;
}
.mic-wave span:nth-child(1) {
    animation-delay: 0s;
}
.mic-wave span:nth-child(2) {
    animation-delay: 0.1s;
}
.mic-wave span:nth-child(3) {
    animation-delay: 0.2s;
}
.mic-wave span:nth-child(4) {
    animation-delay: 0.3s;
}
.mic-wave span:nth-child(5) {
    animation-delay: 0.4s;
}
@keyframes micWave {

    0%, 100% {
        height: 4px;
    }

    50% {
        height: 20px;
    }
}
.mic-timer {

    min-width: 46px;

    font-size: 13px;

    font-weight: 600;

    color: white;

    letter-spacing: 1px;
}

/* Кнопки оценок */
.llm-grade-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    width: 100%;
}

.llm-grade-row button {
    flex: 1;
    min-width: 0;
} 

/* LLM GRADE BUTTONS */
.msg-buttons-grade {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    width: 100%;
    margin-top: 8px;
}

.msg-btn-grade {
    flex: 1;
    min-width: 0;
    padding: 6px 4px;
    font-size: 18px;
}

/* Кнопка перезагрузки страницы */
.reload-btn {
    /* Размеры */
    width: var(--header-btn-size, 2.2rem);
    height: var(--header-btn-size, 2.2rem);

    /* Форма */
    border: none;
    border-radius: 50%;

    /* Выравнивание */
    display: flex;
    align-items: center;
    justify-content: center;

    /* Отступ */
    margin-right: clamp(6px, 1vw, 12px);

    /* Курсор */
    cursor: pointer;

    /* Шрифт */
    font-size: calc(var(--header-btn-size, 2.2rem) * 0.55);
    font-weight: 300;
    line-height: 1;

    /* Цвета от темы */
    background: var(--theme-button-bg, rgba(255, 255, 255, 0));
    color: var(--theme-button-color, inherit);

    /* Эффекты */
    transition:
        transform 0.25s ease,
        background 0.25s ease,
        opacity 0.25s ease;

    /* Чтобы не ломалось */
    flex-shrink: 0;
}

.reload-btn:hover {
    transform: rotate(180deg);
    background: var(--theme-button-hover-bg, rgba(255,255,255,0.18));
}

.reload-btn:active {
    transform: scale(0.92);
}


.header-left {
    display: flex;
    align-items: center;
}

.user-name {
    font-size: 16px;   /* уменьшаешь/увеличиваешь тут */
    line-height: 1;
}



/* =====================================================
   ATTACHMENTS
   ===================================================== */

.attachment-wrapper {

    display: flex;
    flex-direction: column;

    gap: 8px;

    margin-top: 10px;
}

.attachment-download-btn,
.attachment-open-btn {

    width: fit-content;

    padding: 8px 14px;

    border: none;

    border-radius: 10px;

    cursor: pointer;

    text-decoration: none;

    background: var(--accent);

    color: var(--text);

    font-size: 14px;
}

.attachment-download-btn:hover,
.attachment-open-btn:hover {

    opacity: .9;
}

.chat-file {

    font-size: 14px;

    word-break: break-word;
}

/* =====================================================
   HTML VIEWER
   ===================================================== */

#html-viewer-modal {

    position: fixed;

    inset: 0;

    background: rgba(0,0,0,.7);

    z-index: 999999;

    display: none;
}

#html-viewer-modal.active {

    display: flex;
}

.html-viewer-content {

    width: 95%;
    height: 95%;

    margin: auto;

    background: var(--bg);

    border-radius: 14px;

    overflow: hidden;

    display: flex;
    flex-direction: column;
}

.html-viewer-header {

    height: 50px;

    display: flex;

    justify-content: flex-end;

    align-items: center;

    padding: 0 10px;

    border-bottom: 1px solid var(--border-color);
}

.html-viewer-close {

    border: none;

    background: transparent;

    color: var(--text);

    font-size: 24px;

    cursor: pointer;
}

#html-viewer-frame {

    flex: 1;

    width: 100%;

    border: none;

    background: white;
}

video {
    display: block;
}

.attachment-video-wrapper {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}



/* HTML MODAL */
.html-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
}

.html-modal-content {
    width: 90%;
    height: 90%;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.html-frame {
    width: 100%;
    height: 100%;
    border: none;
}

.html-close-btn {
    height: 50px;
    border: none;
    cursor: pointer;
}


/* =========================
   Модальное окно тем
   ========================= */

.theme-modal.hidden {
    display: none;
}

.theme-modal {

    position: fixed;

    inset: 0;

    background: rgba(0,0,0,.7);

    display: flex;

    justify-content: center;

    align-items: center;

    z-index: 999999;
}


.theme-modal-close {

    position: sticky;

    top: 10px;

    float: right;

    z-index: 100000;

    width: 42px;
    height: 42px;

    cursor: pointer;

    border: none;

    border-radius: 50%;

    backdrop-filter: blur(6px);

    background: rgba(30, 30, 30, 0.75);

    color: white;

    font-size: 20px;
}

.theme-modal-body {

    margin-top: 50px;
}

/* Затемнение модального окна сверху */
.theme-modal-content {

    position: relative;

    width: 95vw;
    height: 100vh;

    overflow: auto;

    background: var(--bg);

    border-radius: 12px;

    padding: 20px;
}
.theme-modal-content::before {

    content: "";

    position: sticky;

    top: 0;

    display: block;

    height: 60px;

    margin: -20px -20px 0 -20px;

    z-index: 99999;

    pointer-events: none;

    background:
        linear-gradient(
            to bottom,
            rgba(0,0,0,.55),
            rgba(0,0,0,.25),
            rgba(0,0,0,0)
        );
}

.theme-modal-header {

    position: sticky;

    top: 0;

    height: 60px;

    display: flex;

    justify-content: flex-end;

    align-items: center;

    z-index: 100000;

    background:
        linear-gradient(
            to bottom,
            rgba(0,0,0,.55),
            rgba(0,0,0,.20),
            rgba(0,0,0,0)
        );

    backdrop-filter: blur(8px);
}





/* =====================================================
   ФОН ЧАТА С ПОДДЕРЖКОЙ ИЗОБРАЖЕНИЙ
   ===================================================== */

/* Базовый цвет фона */
.chat-window {
    background: var(--chat-bg);
}

/* Если указано изображение — оно перекрывает цвет */
.chat-window {
    background-image: var(--chat-bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    position: relative;
    min-height: 100vh;
}

/* Затемнение поверх фона */
.chat-window::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--chat-bg-overlay);
    pointer-events: none;
    z-index: 0;
}

/* Убедиться, что содержимое поверх затемнения */
.tg-app,
.chat-header,
.tg-chat,
.chat-input-bar {
    position: relative;
    z-index: 1;
}


/* ===== АВТОРИЗАЦИЯ / МЕНЮ ПОЛЬЗОВАТЕЛЯ ===== */

/* Родительский контейнер - нужен для позиционирования */
.auth-wrapper {
    position: relative;  /* КЛЮЧЕВОЙ момент - якорь для абсолютного позиционирования */
    display: inline-block;
    cursor: pointer;
}

/* Кнопка авторизации */
#auth-btn {
    background: transparent;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: var(--icon-color);
    padding: 6px 10px;
    border-radius: 10px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
}

#auth-btn:hover {
    color: var(--icon-hover);
    background: var(--hover-bg);
}

/* Отображение информации о пользователе */
.auth-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    border-radius: 20px;
    transition: background 0.2s ease;
}

.auth-display:hover {
    background: var(--hover-bg);
}

/* МЕНЮ АВТОРИЗАЦИИ - позиционирование */
.auth-menu {
    position: absolute;
    top: 100%;           /* Будет сразу под кнопкой */
    left: 0;             /* Привязываем к ЛЕВОМУ краю кнопки (не к центру!) */
    background: var(--menu-bg);
    border-radius: 10px;
    padding: 8px;
    min-width: 180px;
    z-index: 9999;
    box-shadow: 0 8px 25px var(--shadow-color);
    
    /* Анимация */
    opacity: 0;
    transform: translateY(-5px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    pointer-events: none;  /* Скрытое меню не перехватывает клики */
}

.auth-menu:not(.hidden) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;  /* Открытое меню перехватывает клики */
}

.auth-menu.hidden {
    display: none !important;
}

/* Элементы меню */
.auth-item {
    padding: 10px 15px;
    cursor: pointer;
    color: var(--menu-text);
    border-radius: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.auth-item:hover {
    background: var(--menu-hover);
    transform: translateX(2px);
}



