* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Скрытие скроллбара для главных контейнеров */
html {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE и Edge */
    -webkit-overflow-scrolling: touch; /* iOS */
}

html::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--tg-theme-bg-color, #ffffff);
    color: var(--tg-theme-text-color, #000000);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE и Edge */
    -webkit-overflow-scrolling: touch; /* iOS */
}

body::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
}

.chat-header-wrapper {
    background-color: rgba(250, 245, 250, 0.5);
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 2000;
}

.chat-header {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    max-width: 1000px;
    margin: 0 auto;
}

.avatar {
    width: 36px;
    height: 36px;
    min-width: 36px; /* Предотвращаем сжатие */
    min-height: 36px; /* Предотвращаем сжатие */
    flex-shrink: 0; /* Не сжимается в flex-контейнере */
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-image: url('/assets/images/gpt.png');
    background-size: cover;
    background-position: center;
}

.chat-info {
    flex: 1; /* Занимает доступное пространство */
    min-width: 0; /* Позволяет сжиматься меньше контента */
    overflow: hidden; /* Необходимо для работы text-overflow в дочерних элементах */
}

.chat-info h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
    color: var(--tg-theme-text-color, #000000);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-info p {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    white-space: nowrap; /* Запрещаем перенос строки */
    overflow: hidden; /* Обрезаем лишнее */
    text-overflow: ellipsis; /* Добавляем многоточие */
}

.messages-container {
    padding: 80px 16px 160px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 18px; /* Увеличенный отступ между сообщениями */
    height: 100vh; /* Фиксированная высота для внутреннего скролла */
    background-color: var(--tg-chat-bg-color, var(--tg-theme-bg-color, #ffffff));
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
    /* Скрытие скроллбара для всех браузеров */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE и Edge */
    /* iOS Safari - принудительное скрытие скроллбара */
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 80%;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-out;
    position: relative;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: transform 0.2s ease;
}

/* Разрешаем выделение текста на устройствах с мышью */
@media (hover: hover) and (pointer: fine) {
    .message {
        -webkit-user-select: text;
        user-select: text;
    }
}

.message.sent {
    align-self: flex-end;
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
    border-radius: 18px 18px 4px 18px;
    padding: 8px 12px;
    margin-left: 40px;
}

/* Голосовые сообщения с padding */
.message.sent.has-audio {
    padding: 8px 12px;
    overflow: hidden;
}

.message.received.has-audio {
    padding: 8px 12px;
    overflow: hidden;
}

/* Специальные стили для сообщений с изображениями */
.message.sent.has-image {
    padding: 0;
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
    border-radius: 18px 18px 4px 18px;
    overflow: hidden;
    width: fit-content;
    max-width: 400px;
}

.message.sent.has-image .image-container {
    display: flex;
    justify-content: center;
    background-color: rgba(0,0,0,0.1);
}

.message.sent.has-image .image-container img {
    display: block;
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 0;
    flex-shrink: 0;
}

.message.sent.has-image .text-container {
    background-color: transparent;
    color: var(--tg-theme-button-text-color, #ffffff);
    padding: 8px 12px;
    border-radius: 0;
    margin-top: 0;
    width: 100%;
    box-sizing: border-box;
}

.message.sent.has-image.image-only {
    background-color: transparent;
}

.message.sent.has-image.image-only .image-container {
    border-radius: 18px 18px 4px 18px;
    background-color: transparent;
}

.message.sent.has-image.image-only .image-container img {
    border-radius: 18px 18px 4px 18px;
}

/* Стили для полученных сообщений с изображениями */
.message.received.has-image {
    padding: 0;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
    border-radius: 18px 18px 18px 4px;
    overflow: visible; /* Изменено на visible, чтобы не обрезать круглый фон кнопок скачать/удалить при hover */
    width: fit-content;
    max-width: 400px;
}

.message.received.has-image .image-container {
    display: flex;
    justify-content: center;
    background-color: rgba(0,0,0,0.05);
    overflow: hidden; /* Сохраняем hidden для изображений, чтобы они корректно обрезались по border-radius */
}

.message.received.has-image .image-container img {
    display: block;
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 0;
    flex-shrink: 0;
}

/* Стили для video-container аналогично image-container */
.message.received.has-image .video-container {
    display: flex;
    justify-content: center;
    background-color: rgba(0,0,0,0.05);
    overflow: hidden; /* Обрезаем видео по border-radius */
}

.message.received.has-image .video-container video {
    display: block;
    width: 100%;
    max-width: 400px;
    height: auto;
    border-radius: 0;
    flex-shrink: 0;
}

.message.received.has-image .text-container {
    background-color: transparent;
    color: var(--tg-theme-text-color, #000000);
    padding: 8px 12px;
    border-radius: 0;
    margin-top: 0;
    width: 100%;
    box-sizing: border-box;
}

.message.received.has-image.image-only {
    background-color: transparent;
}

.message.received.has-image.image-only .image-container {
    border-radius: 18px 18px 18px 4px;
    background-color: transparent;
}

.message.received.has-image.image-only .image-container img {
    border-radius: 18px 18px 18px 4px;
}

.message.received {
    align-self: flex-start;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
    border-radius: 18px 18px 18px 4px;
    padding: 8px 12px;
    margin-right: 40px;
    max-width: 78%;
}

body.dialog-style-active .message.received {
    max-width: 100%;
    align-self: stretch;
    background-color: transparent !important;
    border-radius: 0;
    margin-left: 0;
    margin-right: 0;
    padding-left: 0;
    padding-right: 0;
    position: relative;
    padding-bottom: 30px;
    -webkit-user-select: text; /* Разрешаем выделение текста */
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Markdown-элементы внутри сообщения */
.message div h1,
.message div h2,
.message div h3,
.message div h4,
.message div h5,
.message div h6 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    font-weight: 600;
}

.message div > p {
    margin-bottom: 0.8em;
}

.message div > p:last-child {
    margin-bottom: 0;
}
.message div > ul, .message div > ol {
    padding-left: 30px;
    margin: 1em 0;
}

/* Стили для таблиц, чтобы они не вылезали за пределы сообщения */
.message div table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
    border-collapse: collapse;
    margin: 1em 0;
}

.message th,
.message td {
    padding: 8px 12px;
    border: 1px solid rgba(128, 128, 128, 0.3);
    text-align: left;
    vertical-align: top;
    white-space: normal;
    font-size: 14px;
}

.message th {
    font-weight: 600;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    white-space: nowrap;
}

body[data-theme="dark"] .message th,
body[data-theme="dark"] .message td {
     border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Медиа-запрос ДОЛЖЕН быть в конце, чтобы переопределить все остальные стили */
@media (max-width: 600px) {
    .message th,
    .message td {
        font-size: 12px !important;
        padding: 6px 8px !important;
        line-height: 1.4 !important;
        -webkit-text-size-adjust: 100% !important;
        text-size-adjust: 100% !important;
    }
}

.message div > li {
    margin-bottom: 4px;
}

.message div br + span, .message div br + a {
    display: inline-block;
    margin-left: 1em;
}

.message div a {
    display: inline-flex;
    align-items: center;
    background-color: #f0f0f0;
    color: #333;
    padding: 4px 8px;
    padding-left: 4px;
    border-radius: 12px;
    text-decoration: none;
    font-size: 0.9em;
    font-weight: 500;
    margin: 0 2px;
    transition: all 0.2s ease;
    gap: 6px;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border: none;
}

.message div a::before {
    content: "";
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    background-color: #ffffff;
    border-radius: 50%;
    background-size: 24px 24px; /* Увеличили с 16px до 24px, чтобы квадрат обрезался кругом */
    background-position: center;
    background-repeat: no-repeat;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    overflow: hidden; /* Обрезаем фавиконку по границе круга */
}

/* Для ссылок с фавиконом используем его URL из data-атрибута */
.message div a[data-favicon]::before {
    background-image: var(--favicon-url);
    background-color: var(--favicon-bg, #ffffff);
    border-radius: 50% !important; /* Усиливаем круглую форму */
    /* Плавная загрузка иконки */
    transition: opacity 0.2s ease;
}

/* Пока фавикон загружается, показываем серый фон */
.message div a[data-favicon]:not([style*="--favicon-url"])::before {
    background-color: #f0f0f0;
    opacity: 0.5;
}

/* Скрываем фавиконки во время анимации печатания */
.message.animating a[data-favicon]::before {
    opacity: 0 !important;
    visibility: hidden;
}

/* Плавное появление фавиконок после завершения анимации */
.message:not(.animating) a[data-favicon]::before {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.3s ease, visibility 0s;
}

.message div a:hover {
    background-color: #e0e0e0;
    transform: translateY(-1px);
    text-decoration: none;
}

.message div a::after {
    content: "";
}

body[data-theme="dark"] .message div a {
    background-color: #2c2c2e;
    color: #ffffff;
}

body[data-theme="dark"] .message div a::before {
    background-color: #2c2c2e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] .message div a:hover {
    background-color: #3a3a3c;
}

.message div strong, .message div b {
    font-weight: 600;
    margin: 0;
}

.message div em, .message div i {
    font-style: italic;
    margin: 0;
}

.message div code {
    font-family: monospace;
    background-color: rgba(0,0,0,0.05);
    padding: 2px 4px;
    border-radius: 4px;
    font-size: 0.9em;
}

.message div pre {
    background-color: #f6f8fa; /* Цвет фона как на GitHub */
    padding: 16px;
    padding-right: 80px; /* Добавляем место для кнопки копирования */
    border-radius: 8px;
    margin: 8px 0;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    position: relative;
}

.message div pre code {
    background-color: transparent;
    padding: 0;
    font-size: inherit;
}

.message div hr {
    border: none;
    height: 1px;
    margin: 2em 0;
    background-image: linear-gradient(to right, transparent, var(--tg-theme-hint-color), transparent);
    opacity: 0.3;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

body.dialog-style-active .message.received .message-time {
    text-align: right;
}

.input-container-wrapper {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: transparent;
    z-index: 4000; /* Поверх всего по умолчанию */
    padding-bottom: max(11px, env(safe-area-inset-bottom));
    overflow: visible; /* Allow dropdowns to extend above */
}

/* Когда меню открыто — опускаем нижний блок ниже меню/оверлея */
body.menu-open-global .input-container-wrapper {
    z-index: 700 !important;
}

.input-container {
    padding: 6px 12px;
    border: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 50px;
    transition: all 0.3s ease;
    max-width: 1000px;
    margin: 0 auto;
    padding-top: 12px;
    overflow: visible; /* Allow dropdowns to extend above */
}

.suggestion-chips-container {
    display: flex !important;
    gap: 8px;
    overflow-x: auto;
    overflow-y: visible;
    padding: 6px;
    margin: -6px;
    -ms-overflow-style: none;
    scrollbar-width: none;
    pointer-events: auto;
}

.suggestion-chips-container::-webkit-scrollbar {
    display: none;
}

.suggestion-chip {
    flex-shrink: 0;
    height: auto;
    padding: 6px 12px;
    border-radius: 16px;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px 0 rgba(31, 38, 135, 0.1);
    transform: scale(1) translateY(0);
}

.suggestion-chip:active {
    transform: scale(0.85) translateY(2px);
}

.suggestion-chip.chip-active {
    background-color: #007AFF;
    border: 1px solid #007AFF;
}

/* Цвета для кнопок во включенном состоянии - полная заливка */
.suggestion-chip[data-color="red"].chip-active { background-color: #ff3b30; border-color: #ff3b30; }
.suggestion-chip[data-color="blue"].chip-active { background-color: #007aff; border-color: #007aff; }
.suggestion-chip[data-color="purple"].chip-active { background-color: #af52de; border-color: #af52de; }
.suggestion-chip[data-color="green"].chip-active { background-color: #34c759; border-color: #34c759; }
.suggestion-chip[data-color="orange"].chip-active { background-color: #ff9500; border-color: #ff9500; }
.suggestion-chip[data-color="teal"].chip-active { background-color: #5ac8fa; border-color: #5ac8fa; }

.suggestion-chip svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
    color: #000000;
    opacity: 0.85;
    pointer-events: none;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.suggestion-chip.chip-active svg {
    opacity: 1;
    color: #ffffff;
}

.suggestion-chip[data-color="red"].chip-active svg { color: #ffffff; }
.suggestion-chip[data-color="blue"].chip-active svg { color: #ffffff; }
.suggestion-chip[data-color="purple"].chip-active svg { color: #ffffff; }
.suggestion-chip[data-color="green"].chip-active svg { color: #ffffff; }
.suggestion-chip[data-color="orange"].chip-active svg { color: #ffffff; }
.suggestion-chip[data-color="teal"].chip-active svg { color: #ffffff; }

.suggestion-chip span {
    font-size: 14px;
    font-weight: 500;
    color: #000000;
    opacity: 0.85;
    white-space: nowrap;
}

.suggestion-chip.chip-active span {
    opacity: 1;
    color: #ffffff;
}

.suggestion-chip[data-color="red"].chip-active span { color: #ffffff; }
.suggestion-chip[data-color="blue"].chip-active span { color: #ffffff; }
.suggestion-chip[data-color="purple"].chip-active span { color: #ffffff; }
.suggestion-chip[data-color="green"].chip-active span { color: #ffffff; }
.suggestion-chip[data-color="orange"].chip-active span { color: #ffffff; }
.suggestion-chip[data-color="teal"].chip-active span { color: #ffffff; }

/* Темная тема для suggestion chips */
body[data-theme="dark"] .suggestion-chip {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2);
}

body[data-theme="dark"] .suggestion-chip svg {
    filter: invert(1);
}

body[data-theme="dark"] .suggestion-chip span {
    filter: invert(1);
}

body[data-theme="dark"] .suggestion-chip.chip-active {
    background-color: #0a84ff;
    border: 1px solid #0a84ff;
}

body[data-theme="dark"] .suggestion-chip.chip-active svg {
    filter: none;
    color: #ffffff;
}

body[data-theme="dark"] .suggestion-chip.chip-active span {
    filter: none;
    color: #ffffff;
}

body[data-theme="dark"] .suggestion-chip[data-color="red"].chip-active { background-color: #ff453a; border-color: #ff453a; }
body[data-theme="dark"] .suggestion-chip[data-color="blue"].chip-active { background-color: #0a84ff; border-color: #0a84ff; }
body[data-theme="dark"] .suggestion-chip[data-color="purple"].chip-active { background-color: #bf5af2; border-color: #bf5af2; }
body[data-theme="dark"] .suggestion-chip[data-color="green"].chip-active { background-color: #30d158; border-color: #30d158; }
body[data-theme="dark"] .suggestion-chip[data-color="orange"].chip-active { background-color: #ff9f0a; border-color: #ff9f0a; }
body[data-theme="dark"] .suggestion-chip[data-color="teal"].chip-active { background-color: #64d2ff; border-color: #64d2ff; }

body[data-theme="dark"] .suggestion-chip[data-color="red"].chip-active svg { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="blue"].chip-active svg { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="purple"].chip-active svg { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="green"].chip-active svg { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="orange"].chip-active svg { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="teal"].chip-active svg { color: #ffffff; }

body[data-theme="dark"] .suggestion-chip[data-color="red"].chip-active span { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="blue"].chip-active span { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="purple"].chip-active span { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="green"].chip-active span { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="orange"].chip-active span { color: #ffffff; }
body[data-theme="dark"] .suggestion-chip[data-color="teal"].chip-active span { color: #ffffff; }

.files-preview {
    display: none;
    flex-wrap: wrap;
    gap: 2px;
    padding: 2px;
    max-height: 120px;
    overflow-y: auto;
    margin: -6px;
}

.files-preview.has-files {
    display: flex;
}

.file-preview {
    position: relative;
    width: 60px;
    height: 60px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
    flex-shrink: 0;
    margin: 6px;
}

.file-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.file-preview .file-icon {
    font-size: 24px;
    color: var(--tg-theme-hint-color, #8e8e93);
}

.file-preview .remove-file {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background-color: var(--tg-theme-button-color, #007aff);
    border: 2px solid var(--tg-theme-bg-color, #ffffff);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    color: var(--tg-theme-button-text-color, #ffffff);
    font-weight: normal;
    line-height: 0;
    z-index: 1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.file-preview .remove-file::before {
    content: '×';
    margin-top: -2px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0;
}

.input-container.keyboard-open .clip-button {
    opacity: 0;
    transform: translateX(-20px);
    visibility: hidden;
    transition: all 0.3s ease;
}

.input-container.keyboard-open .input-wrapper {
    margin-left: -45px;
    transition: all 0.3s ease;
}

.input-wrapper {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-simple');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-simple');
    border-radius: 18px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    outline: none;
    padding: 6px 12px;
    min-height: 40px;
    max-height: 200px;
    transition: all 0.3s ease;
    margin-left: 6px;
    margin-right: 6px;
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

#messageInput {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-size: 15px;
    line-height: 18px;
    background: transparent;
    color: var(--tg-theme-text-color, #000000);
    font-family: inherit;
    max-height: 180px;
    overflow-y: auto;
    padding: 3px 0;
    transform: translateZ(0);
}

/* Возвращаем анимацию мигания курсора для iOS */
#messageInput:focus {
    caret-color: #007aff !important;
    animation: caret-blink 1.2s ease-in-out infinite;
}

/* Специально для iOS/Safari */
@supports (-webkit-appearance: none) {
    #messageInput {
        caret-color: #007aff !important;
        -webkit-appearance: textfield;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Анимация мигания курсора - более плавная для iOS */
@keyframes caret-blink {
    0%, 45% {
        caret-color: #007aff;
    }
    50%, 95% {
        caret-color: transparent;
    }
    100% {
        caret-color: #007aff;
    }
}

#messageInput::placeholder {
    color: var(--tg-theme-hint-color, #8e8e93);
    font-size: 15px;
}

@keyframes text-glow-animation {
    from {
        text-shadow: 0 0 0px transparent;
    }
    to {
        text-shadow: 0 0 5px var(--tg-theme-link-color, #007aff);
    }
}

#messageInput.animated-glow {
    animation: text-glow-animation 0.4s ease-out;
}

.stars-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 6px;
    color: var(--tg-theme-link-color, #007aff);
    opacity: 0;
    transform: scale(0.5);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.input-wrapper.has-text .stars-icon {
    opacity: 1;
    transform: scale(1);
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background-color: var(--tg-theme-button-color, #007aff);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    outline: none;
}

.send-button:active {
    transform: scale(0.95);
}

.send-button.record-mode:active {
    transform: scale(0.85) translateY(2px);
}

.send-button svg {
    width: 24px;
    height: 24px;
    color: var(--tg-theme-button-text-color, #ffffff);
    transition: all 0.2s ease;
}

.send-button:not(.record-mode) svg {
     transform: translateY(1px);
}

.send-button.record-mode {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    transform: scale(1) translateY(2px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.send-button.record-mode svg {
    color: var(--tg-theme-hint-color, #8e8e93);
    width: 27px;
    height: 27px;
    pointer-events: none;
    transform: none;
}

.send-button.record-mode svg path {
    fill: currentColor;
}

.send-button.record-mode .microphone-icon {
    width: 27px;
    height: 27px;
    opacity: 0.85;
}

body[data-theme="dark"] .send-button.record-mode .microphone-icon {
    filter: invert(1);
}

.send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-button:disabled:active {
    transform: none;
}

.clip-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    transform: scale(1) translateY(2px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.clip-button:active {
    transform: scale(0.85) translateY(2px);
}

.clip-button svg {
    width: 24px;
    height: 24px;
    color: #000000;
    opacity: 0.85;
    pointer-events: none;
}

.clip-button svg path {
    fill: currentColor;
}

/* Кнопка микрофона - идентична clip-button */
.microphone-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    transform: scale(1) translateY(2px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.microphone-button:active {
    transform: scale(0.85) translateY(2px);
}

.microphone-button svg,
.microphone-button img {
    width: 24px;
    height: 24px;
    color: #000000;
    opacity: 0.85;
    pointer-events: none;
}

.microphone-button svg path {
    fill: currentColor;
}

.microphone-button .microphone-icon {
    width: 24px;
    height: 24px;
    opacity: 0.85;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes clipPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.clip-button.animate-pulse svg {
    animation: clipPulse 0.3s ease;
}

@keyframes newChatPulse {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scale(0.95);
    }
    60% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.new-chat-button.animate-pulse {
    animation: newChatPulse 0.4s ease;
}

/* Эффект мерцания для текста "печатает..." */
@keyframes shimmer {
    0% {
        background-position: -250px 0;
    }
    100% {
        background-position: 250px 0;
    }
}

.typing-text {
    animation: shimmer 2s linear infinite;
    background: linear-gradient(to right, var(--tg-theme-text-color, #000000) 40%, var(--tg-theme-hint-color, #8e8e93) 50%, var(--tg-theme-text-color, #000000) 60%);
    background-size: 250px 100%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 500; /* Немного уплотняем шрифт для лучшей читаемости */
}

/* Обработка клавиатуры */
@media screen and (max-height: 600px) {
    .messages-container {
        padding-bottom: 160px;
    }
}

/* Стили для мобильных устройств */
@media screen and (max-width: 768px) {
    .message.sent {
        margin-left: 10px;
        max-width: 90%;
    }
    .message.received {
        margin-right: 10px;
        max-width: 90%;
    }
    
    #messageInput {
        caret-color: #007aff !important;
        -webkit-text-fill-color: var(--tg-theme-text-color, #000000);
        -webkit-opacity: 1;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Дополнительные стили для iOS */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    #messageInput {
        caret-color: #007aff !important;
        -webkit-user-select: text;
        user-select: text;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Специальные стили для iOS Safari */
@supports (-webkit-touch-callout: none) {
    #messageInput {
        caret-color: #007aff !important;
        -webkit-appearance: textfield;
        -webkit-text-fill-color: var(--tg-theme-text-color, #000000);
        opacity: 1 !important;
        -webkit-opacity: 1 !important;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Адаптация для разных тем Telegram */

/* Тёмная тема */
body[data-theme="dark"] {
    --tg-theme-bg-color: #060607;
    --tg-chat-bg-color: var(--tg-theme-bg-color);
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #888888;
    --tg-theme-link-color: #007aff;
    --tg-theme-button-color: #007aff;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #2c2c2e;
}

body[data-theme="dark"] .input-container-wrapper {
    background-color: transparent;
}

body[data-theme="dark"] .input-wrapper {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] .clip-button {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] .clip-button svg {
    filter: invert(1);
}

body[data-theme="dark"] .microphone-button {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    transform: scale(1) translateY(2px);
}

body[data-theme="dark"] .microphone-button svg,
body[data-theme="dark"] .microphone-button img,
body[data-theme="dark"] .microphone-button .microphone-icon {
    filter: invert(1);
}

body[data-theme="dark"] .send-button.record-mode {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    transform: scale(1) translateY(2px);
}

body[data-theme="dark"] .chat-header-wrapper {
    background-color: rgba(0, 0, 0, 0.8);
}

body[data-theme="dark"] .file-preview {
    background-color: #2c2c2e;
}

body[data-theme="dark"] .copy-button {
    background-color: rgba(28, 28, 30, 0.95);
}

body[data-theme="dark"] #messageInput {
    caret-color: #0A84FF !important;
}

body[data-theme="dark"] #messageInput:focus {
    animation: caret-blink-dark 1.2s ease-in-out infinite;
}

/* Анимация мигания курсора для темной темы */
@keyframes caret-blink-dark {
    0%, 45% {
        caret-color: #0A84FF;
    }
    50%, 95% {
        caret-color: transparent;
    }
    100% {
        caret-color: #0A84FF;
    }
}

/* Зелёная тема */
body[data-theme="green"] {
    --tg-theme-bg-color: #f0f7ff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #34c759;
    --tg-theme-button-color: #34c759;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #e8f5e8;
}

/* Фиолетовая тема */
body[data-theme="purple"] {
    --tg-theme-bg-color: #f8f7ff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #af52de;
    --tg-theme-button-color: #af52de;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0eaff;
}

/* Оранжевая тема */
body[data-theme="orange"] {
    --tg-theme-bg-color: #fffaf0;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #ff9500;
    --tg-theme-button-color: #ff9500;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #ffe8cc;
}

/* Красная тема */
body[data-theme="red"] {
    --tg-theme-bg-color: #fff5f5;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #ff3b30;
    --tg-theme-button-color: #ff3b30;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #ffe0e0;
}

/* Скрытие скроллбара в webkit (Chrome, Safari, Edge, iOS) - полное скрытие */
.messages-container::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
    background: transparent !important;
}

.messages-container::-webkit-scrollbar-track {
    display: none !important;
    background: transparent !important;
}

.messages-container::-webkit-scrollbar-thumb {
    display: none !important;
    background: transparent !important;
}

.messages-container::-webkit-scrollbar-corner {
    display: none !important;
    background: transparent !important;
}

.new-chat-button {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
    border: none;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 0; /* Предотвращаем сжатие кнопки */
}

.new-chat-button:active {
    transform: scale(0.95);
    opacity: 0.8;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px;
    background-color: var(--tg-theme-secondary-bg-color, rgba(0, 0, 0, 0.05));
    border-radius: 20px;
    flex-shrink: 0;
}

.lang-button {
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
}

.lang-button.active {
    background-color: var(--tg-theme-button-color, #007aff);
}

.lang-button:active {
    transform: scale(0.95);
}

.flag-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0; /* Предотвращаем сжатие контейнера с кнопками */
}

.header-icon-button {
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text-color);
    transition: background-color 0.2s ease;
    flex-shrink: 0; /* Предотвращаем сжатие кнопки */
}
.header-icon-button:active {
    background-color: rgba(0,0,0,0.1);
}
.header-icon-button svg {
    width: 22px;
    height: 22px;
}

.plus-icon {
    width: 10px;
    height: 10px;
    color: currentColor;
    flex-shrink: 0;
}

.button-text {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Эффект нажатия на сообщение (кроме уже выделенного) - только для мобильных */
@media (hover: none), (pointer: coarse) {
    body:not(.dialog-style-active) .message:not(.copy-selected):active,
    body.dialog-style-active .message.sent:not(.copy-selected):active {
        transform: scale(0.98);
    }
}

.message-copy-icon {
    position: absolute;
    bottom: 8px; /* Опускаем иконку вниз */
    width: 28px;
    height: 28px;
    padding: 4px;
    border-radius: 50%;
    color: var(--tg-theme-hint-color, #8e8e93);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    pointer-events: none;
    display: none; /* Скрыто по умолчанию */
}

.message.sent .message-copy-icon {
    left: -36px;
}

.message.received .message-copy-icon {
    right: -36px;
}

/* Показываем иконку на устройствах с мышью постоянно */
@media (hover: hover) and (pointer: fine) {
    .message-copy-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0.5;
        pointer-events: auto;
    }

    .message-copy-icon:hover {
        opacity: 1;
        background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    }
}

body.dialog-style-active .message-copy-icon {
    display: none !important;
}

/* Блюр-оверлей поверх всего экрана */
.copy-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.1);
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

.copy-overlay.show {
    opacity: 1;
}

/* Выделенное сообщение поверх блюра */
.message.copy-selected {
    position: relative;
    z-index: 60;
    transform: scale(1.05);
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    pointer-events: auto;
}

.message.received.copy-selected {
    transform-origin: left center;
}

.message.sent.copy-selected {
    transform-origin: right center;
}

/* Контент выделенного сообщения должен быть интерактивным */
.message.copy-selected > div:first-child {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    pointer-events: auto;
}

/* Убираем изменение цветов - сообщения остаются как есть */

.message-actions-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: rgba(250, 245, 250, 0.95);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    cursor: default;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    width: auto;
    margin-top: 8px;
    z-index: 61;
    opacity: 0;
    transform: translateY(-10px) scale(0.8);
    overflow: hidden; /* To apply border-radius to children */
    -webkit-tap-highlight-color: transparent;
}

/* Выравнивание меню для отправленных сообщений */
.message.sent .message-actions-menu {
    right: 0;
    left: auto;
}

.message-actions-menu.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.message-actions-menu .action-item {
    background: none;
    border: none;
    color: var(--tg-theme-text-color, #000000);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    width: 100%;
    white-space: nowrap;
}

.message-actions-menu .action-item:active {
    background-color: rgba(0,0,0,0.05);
}

body[data-theme="dark"] .message-actions-menu .action-item:active {
    background-color: rgba(255,255,255,0.08);
}

body[data-theme="dark"] .message-actions-menu {
    background-color: rgba(44, 44, 46, 0.95);
}

.message-actions-menu .action-item .action-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--tg-theme-text-color, #000000);
}

.message-actions-menu .action-icon svg {
    display: block;
}

.message-actions-menu .separator {
    height: 1px;
    background-color: var(--tg-theme-hint-color, #8e8e93);
    opacity: 0.15;
    margin: 0 8px;
}

.message-actions-menu .action-item.delete {
    color: #ff3b30;
}

.message-actions-menu .action-item.delete .action-icon {
    color: #ff3b30;
}

/* Поп-ап уведомление "Скопировано" */
.copy-notification {
    position: fixed;
    /* bottom позиция устанавливается через JS */
    left: 16px;
    right: 16px;
    margin: 0 auto;
    max-width: 400px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
    border-radius: 14px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 100;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    pointer-events: none;
}

.copy-notification.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.copy-notification-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.checkmark__circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2.5;
    stroke-miterlimit: 10;
    stroke: var(--tg-theme-link-color, #007aff);
    fill: none;
    animation: copy-notification-stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark__check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    stroke-width: 3;
    stroke-linecap: round;
    stroke: var(--tg-theme-link-color, #007aff);
    fill: none;
    animation: copy-notification-stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.5s forwards;
}

@keyframes copy-notification-stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

/* Дополнительно для мобильных в тёмной теме */
@media screen and (max-width: 768px) {
    body[data-theme="dark"] #messageInput {
        caret-color: #007aff !important;
    }
}

.model-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.model-menu-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

/* Шапка всегда поверх и остаётся fixed даже при открытом меню */
.chat-header-wrapper.menu-open {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 20;
}

/* Унифицируем фон страницы с цветом чата (исправляет разные цвета по бокам) */
body {
    background-color: var(--tg-theme-bg-color, #ffffff) !important;
}

main.content {
    background-color: var(--tg-theme-bg-color, #ffffff) !important;
}

/* Жёстко фиксируем цвет контейнера чата в тёмной теме */
body[data-theme="dark"] .messages-container {
    background-color: var(--tg-theme-bg-color) !important;
}

/* Убираем агрессивную синхронизацию фона, оставляем только контейнер */

.model-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(250, 245, 250, 0.8);
    z-index: 19;
    padding: 8px 16px 16px;
    padding-top: 82px; /* Отступ для шапки */
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    max-height: 100vh;
}

.model-menu.show {
    transform: translateY(0);
}

.model-menu-content {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.model-menu-content > * {
    opacity: 0;
    transform: translateY(15px) scale(0.95);
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1), transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.model-menu.show .model-menu-content > * {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.model-menu.show .model-menu-content > *:nth-child(1) { transition-delay: 0.1s; }
.model-menu.show .model-menu-content > *:nth-child(2) { transition-delay: 0.16s; }
.model-menu.show .model-menu-content > *:nth-child(3) { transition-delay: 0.22s; }
.model-menu.show .model-menu-content > *:nth-child(4) { transition-delay: 0.28s; }
.model-menu.show .model-menu-content > *:nth-child(5) { transition-delay: 0.34s; }

.model-menu .menu-block {
    background-color: transparent;
    border-radius: 12px;
    padding: 0;
}

.model-list-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, padding-bottom 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 8px;
    transform: translateZ(0);
}

.model-list-container::-webkit-scrollbar {
    display: none;
}

.model-list-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.model-menu .model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
}

.model-menu .model-option.active {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
}

.model-menu .model-option .model-info strong {
    font-size: 15px;
    font-weight: 600;
}

.model-menu .model-option .model-info span:not(.free-badge) {
    font-size: 11px;
    display: block;
    opacity: 0.7;
}
.model-menu .model-option.active .model-info span:not(.free-badge) {
    opacity: 0.9;
}

.model-menu .model-option .model-check {
    font-size: 20px;
    font-weight: bold;
}

.model-menu .quick-actions {
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    background-color: transparent;
}

.model-menu .action-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-text-color, #000000);
    width: 80px;
}

.model-menu .action-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.model-menu .action-button:active .action-icon {
    background-color: rgba(0,0,0,0.1);
}

.model-menu .action-button.pulse {
    animation: actionButtonPulse 0.3s ease-out;
}

@keyframes actionButtonPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.model-menu .action-icon svg {
    width: 26px;
    height: 26px;
}

.model-menu .user-profile {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 40px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 8px;
    padding-right: 16px;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.profile-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-grow: 1;
}

.subscription-info {
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-link-color, #007aff);
    margin-top: 2px;
}

.model-menu .profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 2px solid var(--tg-theme-bg-color, #ffffff);
    flex-shrink: 0;
}

.model-menu .profile-name {
    font-size: 16px;
    font-weight: 600;
}

.profile-action-buttons {
    display: flex;
    gap: 8px;
}

.profile-action-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.profile-action-btn:active {
    background-color: rgba(0,0,0,0.15);
}

.model-menu .profile-id {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-top: -4px;
}

.model-menu .other-ais {
    background: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-category {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 16px;
    padding: 16px 0 16px 16px;
}

.ai-category-header {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color, #000000);
}

.ai-list-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-right: 16px; /* Add some padding to the right end */
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Поддержка прокрутки на тачпаде */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.ai-list-scroller::-webkit-scrollbar {
    display: none;
}

.model-menu .ai-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 80px;
    flex-shrink: 0;
}

.model-menu .ai-avatar {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

.model-selection-wrapper {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 12px;
    transition: all 0.3s ease;
}

.selected-model-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
}

.dropdown-arrow {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: rotate(0deg);
    color: var(--tg-theme-hint-color, #8e8e93);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.model-selection-wrapper.expanded .dropdown-arrow {
    transform: rotate(180deg);
}

.model-menu .menu-block {
    background-color: transparent;
    border-radius: 12px;
    padding: 0;
}

.model-list-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, padding-bottom 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 8px;
    transform: translateZ(0);
}

.model-selection-wrapper.expanded .model-list-container {
    max-height: 250px; /* или любая другая подходящая высота */
    overflow-y: auto;
    padding-bottom: 8px;
}

#selectedModelInfo strong {
    font-size: 16px;
    font-weight: 600;
    display: block;
}

#selectedModelInfo span:not(.free-badge) {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    display: block;
    margin-top: 2px;
}

/* Плашка FREE в выбранной модели меньше */
#selectedModelInfo .free-badge {
    font-size: 7px;
    padding: 1px 5px;
    opacity: 1;
}

.model-list-container::-webkit-scrollbar {
    display: none;
}

.model-list-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.model-menu .model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
}

.model-menu .model-option.active {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
}

.model-menu .model-option .model-info strong {
    font-size: 15px;
    font-weight: 600;
}

.model-menu .model-option .model-info span:not(.free-badge) {
    font-size: 11px;
    display: block;
    opacity: 0.7;
}
.model-menu .model-option.active .model-info span:not(.free-badge) {
    opacity: 0.9;
}

.model-menu .model-option .model-check {
    font-size: 20px;
    font-weight: bold;
}

.model-menu .quick-actions {
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    background-color: transparent;
}

.model-menu .action-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-text-color, #000000);
    width: 80px;
}

.model-menu .action-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.model-menu .action-button:active .action-icon {
    background-color: rgba(0,0,0,0.1);
}

.model-menu .action-button.pulse {
    animation: actionButtonPulse 0.3s ease-out;
}

@keyframes actionButtonPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.model-menu .action-icon svg {
    width: 26px;
    height: 26px;
}

.model-menu .user-profile {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    width: 100%;
}

.profile-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.model-menu .profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 22px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

.model-menu .profile-name {
    font-size: 16px;
    font-weight: 600;
}

.model-menu .profile-id {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-top: -4px;
}

.model-menu .other-ais {
    background: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-category {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 16px;
    padding: 16px 0 16px 16px;
}

.ai-category-header {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color, #000000);
}

.ai-list-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-right: 16px; /* Add some padding to the right end */
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Поддержка прокрутки на тачпаде */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.ai-list-scroller::-webkit-scrollbar {
    display: none;
}

.model-menu .ai-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 80px;
    flex-shrink: 0;
}

.model-menu .ai-avatar {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

.user-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
}

.model-menu .user-profile {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 40px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 8px;
    padding-right: 16px;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.model-menu .user-profile:active {
    background-color: rgba(0,0,0,0.1);
}

.profile-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-grow: 1;
}

.subscription-info {
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-link-color, #007aff);
    margin-top: 2px;
}

.model-menu .profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 2px solid var(--tg-theme-bg-color, #ffffff);
    flex-shrink: 0;
}

.model-menu .profile-name {
    font-size: 16px;
    font-weight: 600;
}

.profile-action-buttons {
    display: flex;
    gap: 8px;
}

.profile-action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.profile-action-btn:active {
    background-color: rgba(0,0,0,0.15);
}

.model-menu .profile-id {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-top: -4px;
}

.model-menu .other-ais {
    background: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-category {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 16px;
    padding: 16px 0 16px 16px;
}

.ai-category-header {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color, #000000);
}

.ai-list-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-right: 16px; /* Add some padding to the right end */
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Поддержка прокрутки на тачпаде */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.ai-list-scroller::-webkit-scrollbar {
    display: none;
}

.model-menu .ai-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 80px;
    flex-shrink: 0;
}

.model-menu .ai-avatar {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

/* Светлая тема (принудительная) */
body[data-theme="light"] {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #007aff;
    --tg-theme-button-color: #007aff;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0f0f0;
}

body[data-theme="light"] .input-container-wrapper {
    background-color: transparent;
}

body[data-theme="light"] .input-wrapper {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

body[data-theme="light"] .clip-button {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

body[data-theme="light"] .microphone-button {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    transform: scale(1) translateY(2px);
}

body[data-theme="light"] .send-button.record-mode {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    transform: scale(1) translateY(2px);
}

body[data-theme="light"] .chat-header-wrapper {
    background-color: rgba(250, 245, 250, 0.5);
}

body[data-theme="light"] .file-preview {
    background-color: #f0f0f0;
}

body[data-theme="light"] .copy-button {
    background-color: rgba(250, 245, 250, 0.95);
}

body[data-theme="light"] #messageInput {
    caret-color: #007aff !important;
}

body[data-theme="light"] #messageInput:focus {
    animation: caret-blink 1.2s ease-in-out infinite;
}

body[data-theme="dark"] #messageInput {
    caret-color: #0A84FF !important;
}

.model-menu .user-profile:active {
    background-color: rgba(0,0,0,0.1);
}

.selected-model-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
}

.dropdown-arrow {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: rotate(0deg);
    color: var(--tg-theme-hint-color, #8e8e93);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.model-selection-wrapper.expanded .dropdown-arrow {
    transform: rotate(180deg);
}

.model-selection-wrapper.expanded .model-list-container {
    max-height: 250px; /* или любая другая подходящая высота */
    overflow-y: auto;
    padding-bottom: 8px;
}

#selectedModelInfo strong {
    font-size: 16px;
    font-weight: 600;
    display: block;
}

#selectedModelInfo span:not(.free-badge) {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    display: block;
    margin-top: 2px;
}

/* Плашка FREE в выбранной модели меньше */
#selectedModelInfo .free-badge {
    font-size: 7px;
    padding: 1px 5px;
    opacity: 1;
}

.model-list-container::-webkit-scrollbar {
    display: none;
}

.copy-code-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #e1e4e8;
    color: #24292e;
    border: 1px solid rgba(27, 31, 35, 0.15);
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    opacity: 0.7; /* Уменьшаем прозрачность для лучшей видимости */
    transition: opacity 0.2s ease-in-out;
    z-index: 1;
}

.message div pre:hover .copy-code-button {
    opacity: 1;
}

.copy-code-button.copied {
    background-color: #4CAF50;
    color: white;
    opacity: 1;
}

.recording-indicator {
    display: none;
    align-items: center;
    justify-content: space-between;
    background-color: var(--tg-theme-bg-color, #ffffff);
    border-radius: 18px;
    padding: 6px 16px;
    min-height: 40px;
    flex: 1;
    margin-right: 6px;
}

.recording-indicator.active {
    display: flex;
}

.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ff3b30;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

.recording-time {
    font-size: 15px;
    color: var(--tg-theme-text-color, #000000);
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}

.recording-cancel {
    font-size: 15px;
    font-weight: 500;
    color: var(--tg-theme-link-color, #007aff);
    cursor: pointer;
}

/* Custom User Audio Player */
.user-audio-player {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    padding: 8px;
    max-width: 280px;
}
body[data-theme="dark"] .message.sent .user-audio-player {
     background-color: rgba(255, 255, 255, 0.15);
}
.user-audio-player-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background-color: var(--tg-theme-button-text-color, #ffffff);
    color: var(--tg-theme-button-color, #007aff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.user-audio-player-button:active {
    transform: scale(0.9);
}
.user-audio-player-button svg {
    width: 18px;
    height: 18px;
    margin-left: 2px; /* Optical alignment for play icon */
}
.user-audio-player-button .pause-icon {
    display: none;
}
.user-audio-player.playing .play-icon {
    display: none;
}
.user-audio-player.playing .pause-icon {
    display: block;
    margin-left: 0; /* Reset alignment */
}
.user-audio-waveform-container {
    flex-grow: 1;
    height: 32px;
    position: relative;
}
.user-audio-waveform-canvas {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

#history-section {
    padding-right: 16px;
    background: none;
}

.history-list-container {
    padding: 16px 0;
    text-align: center;
}

.empty-history-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--tg-theme-hint-color, #8e8e93);
    padding: 16px 0;
    opacity: 0.8;
}

.empty-history-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background-color: var(--tg-theme-bg-color, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

body[data-theme="dark"] .empty-history-icon {
    background-color: #2c2c2e;
}

.empty-history-placeholder p {
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-theme-text-color, #000000);
    margin: 0;
}

.empty-history-placeholder span {
    font-size: 13px;
    max-width: 250px;
    line-height: 1.4;
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

.dialog-message-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

body.dialog-style-active .dialog-message-actions {
    position: absolute;
    bottom: -5px;
    left: 0px;
}

.dialog-action-btn {
    background: transparent;
    border: none;
    padding: 6px; /* Увеличен padding для корректного отображения кругового фона */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-hint-color, #8e8e93);
    opacity: 0.7;
    border-radius: 50%;
    transition: all 0.2s ease;
}
.dialog-action-btn:hover {
    opacity: 1;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
}
body[data-theme="dark"] .dialog-action-btn:hover {
    background-color: rgba(255,255,255,0.1);
}

.dialog-action-btn svg {
    width: 16px;
    height: 16px;
}

body.dialog-style-active .message-time {
    text-align: right;
    padding-left: 0;
    padding-right: 5px;
}

.message.sent.has-image.image-only .image-container img {
    border-radius: 18px 18px 4px 18px;
}

.message.sent.has-image .files-container {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
    padding: 8px 12px;
    border-radius: 0 0 4px 18px;
    margin-top: -4px;
}

.message.sent.has-image .message-time {
    padding: 5px 12px 8px 12px;
    margin-top: 0;
}

.message.sent.has-image.image-only .message-time {
    position: absolute;
    bottom: 8px;
    right: 12px;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
}

/* Когда есть текст под изображением - убираем скругление снизу у контейнера */
.message.sent.has-image:not(.image-only) .image-container img {
   border-radius: 0 !important;
}

/* Стили для кнопки повтора */
.retry-button {
    position: absolute;
    left: -35px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background-color: #ff4444;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.retry-button:hover {
    background-color: #ff6666;
}

.retry-button svg {
    width: 12px;
    height: 12px;
    fill: white;
    transform: rotate(180deg);
}

.message.sent.has-retry .retry-button {
    opacity: 1;
}

/* Анимация при наведении на сообщение с кнопкой повтора */
.message.sent.has-retry:hover .retry-button {
    opacity: 1;
}

.sources-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.sources-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--tg-theme-text-color, #000000);
}

.sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.source-link-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
    padding: 4px 10px 4px 4px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.source-link-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body[data-theme="dark"] .source-link-chip {
     background-color: #2c2c2e;
}

.source-favicon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    background-color: #fff;
    border: 1px solid rgba(0,0,0,0.05);
}

body.dialog-style-active .message-time {
    text-align: right;
    padding-left: 0;
    padding-right: 5px;
}

.sources-header-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-left: auto; /* Прижимаем вправо */
}

.overlapping-favicons {
    display: flex;
    align-items: center;
    height: 24px;
}

.overlapping-favicons .source-favicon {
    margin-left: -10px;
    border: 2px solid var(--tg-theme-bg-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.overlapping-favicons .source-favicon:first-child {
    margin-left: 0;
}

body.dialog-style-active .sources-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 8px;
    padding: 0 8px;
    border-top: none;
}

body.dialog-style-active .sources-list {
    margin-top: 8px;
    flex-grow: 1;
    justify-content: flex-end;
    display: none; /* Скрываем по умолчанию, пока не используется */
}

.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 4px 8px 12px; /* Увеличен нижний отступ до 12px для полного отображения кругового фона кнопок при hover */
    margin-top: 8px; /* Добавим отступ сверху */
}

body.dialog-style-active .message.received {
    padding-bottom: 8px; /* Уменьшим нижний отступ */
}

.message.sent.has-image.image-only .image-container img {
    border-radius: 18px 18px 4px 18px;
}

/* Стили для встроенных в текст ссылок */
.inline-source-chip {
    display: inline-flex;
    flex-direction: row; /* Явно указываем направление */
    align-items: center;
    /* gap: 6px; */ /* Заменен на margin */
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-link-color, #007aff);
    padding: 2px 8px 2px 6px; /* Скорректируем отступы T, R, B, L */
    border-radius: 16px;
    font-size: 0.8em; /* Делаем шрифт чуть меньше основного */
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    vertical-align: middle; /* Лучшее выравнивание с текстом */
    margin: 0 2px;
}
body[data-theme="dark"] .inline-source-chip {
     background-color: #3a3a3c;
}
.inline-source-chip:hover {
    background-color: var(--tg-theme-hint-color, #8e8e93);
    color: var(--tg-theme-bg-color, #ffffff);
    transform: translateY(-1px);
}
.inline-source-chip .source-favicon {
     width: 16px;
     height: 16px;
     border-radius: 50%;
     flex-shrink: 0;
     display: block; /* Убедимся, что иконка является блоком */
     margin-right: 8px; /* Отступ между иконкой и текстом */
}

/* Анимация копирования */
@keyframes fadeInSlideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Специальная анимация для первого сообщения */
.message.first-message {
    animation: firstMessageSlideUp 0.6s ease-out;
}

@keyframes firstMessageSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Анимация мерцания для улучшения текста */
@keyframes improving-shimmer {
    0% {
        background-color: var(--tg-theme-bg-color, #ffffff);
    }
    50% {
        background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    }
    100% {
        background-color: var(--tg-theme-bg-color, #ffffff);
    }
}

.input-wrapper.improving-text {
    animation: improving-shimmer 1s ease-in-out infinite;
    pointer-events: none;
}

.input-wrapper.improving-text #messageInput {
    color: var(--tg-theme-hint-color, #8e8e93);
    cursor: not-allowed;
}

.stars-icon {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.stars-icon:hover {
    transform: scale(1.1);
}

.stars-icon:active {
    transform: scale(0.95);
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background-color: var(--tg-theme-button-color, #007aff);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    outline: none;
}

.send-button:active {
    transform: scale(0.95);
}

.send-button.record-mode:active {
    transform: scale(0.85) translateY(2px);
}

.send-button svg {
    width: 24px;
    height: 24px;
    color: var(--tg-theme-button-text-color, #ffffff);
    transition: all 0.2s ease;
}

.send-button:not(.record-mode) svg {
     transform: translateY(1px);
}

.send-button.record-mode {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    transform: scale(1) translateY(2px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.send-button.record-mode svg {
    color: var(--tg-theme-hint-color, #8e8e93);
    width: 27px;
    height: 27px;
    pointer-events: none;
    transform: none;
}

.send-button.record-mode svg path {
    fill: currentColor;
}

.send-button.record-mode .microphone-icon {
    width: 27px;
    height: 27px;
    opacity: 0.85;
}

body[data-theme="dark"] .send-button.record-mode .microphone-icon {
    filter: invert(1);
}

.send-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.send-button:disabled:active {
    transform: none;
}

.clip-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    transform: scale(1) translateY(2px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.clip-button:active {
    transform: scale(0.85) translateY(2px);
}

.clip-button svg {
    width: 24px;
    height: 24px;
    color: #000000;
    opacity: 0.85;
    pointer-events: none;
}

.clip-button svg path {
    fill: currentColor;
}

/* Кнопка микрофона - идентична clip-button */
.microphone-button {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    transition: all 0.2s ease;
    transform: scale(1) translateY(2px);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

.microphone-button:active {
    transform: scale(0.85) translateY(2px);
}

.microphone-button svg,
.microphone-button img {
    width: 24px;
    height: 24px;
    color: #000000;
    opacity: 0.85;
    pointer-events: none;
}

.microphone-button svg path {
    fill: currentColor;
}

.microphone-button .microphone-icon {
    width: 24px;
    height: 24px;
    opacity: 0.85;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes clipPulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
    }
}

.clip-button.animate-pulse svg {
    animation: clipPulse 0.3s ease;
}

@keyframes newChatPulse {
    0% {
        transform: scale(1);
    }
    30% {
        transform: scale(0.95);
    }
    60% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

.new-chat-button.animate-pulse {
    animation: newChatPulse 0.4s ease;
}

/* Эффект мерцания для текста "печатает..." */
@keyframes shimmer {
    0% {
        background-position: -250px 0;
    }
    100% {
        background-position: 250px 0;
    }
}

.typing-text {
    animation: shimmer 2s linear infinite;
    background: linear-gradient(to right, var(--tg-theme-text-color, #000000) 40%, var(--tg-theme-hint-color, #8e8e93) 50%, var(--tg-theme-text-color, #000000) 60%);
    background-size: 250px 100%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 500; /* Немного уплотняем шрифт для лучшей читаемости */
}

/* Обработка клавиатуры */
@media screen and (max-height: 600px) {
    .messages-container {
        padding-bottom: 160px;
    }
}

/* Стили для мобильных устройств */
@media screen and (max-width: 768px) {
    .message.sent {
        margin-left: 10px;
        max-width: 90%;
    }
    .message.received {
        margin-right: 10px;
        max-width: 90%;
    }
    
    #messageInput {
        caret-color: #007aff !important;
        -webkit-text-fill-color: var(--tg-theme-text-color, #000000);
        -webkit-opacity: 1;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Дополнительные стили для iOS */
@media screen and (-webkit-min-device-pixel-ratio: 2) {
    #messageInput {
        caret-color: #007aff !important;
        -webkit-user-select: text;
        user-select: text;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Специальные стили для iOS Safari */
@supports (-webkit-touch-callout: none) {
    #messageInput {
        caret-color: #007aff !important;
        -webkit-appearance: textfield;
        -webkit-text-fill-color: var(--tg-theme-text-color, #000000);
        opacity: 1 !important;
        -webkit-opacity: 1 !important;
    }
    
    #messageInput:focus {
        caret-color: #007aff !important;
        animation: caret-blink 1.2s ease-in-out infinite;
    }
}

/* Адаптация для разных тем Telegram */

/* Тёмная тема */
body[data-theme="dark"] {
    --tg-theme-bg-color: #1c1c1e;
    --tg-theme-text-color: #ffffff;
    --tg-theme-hint-color: #888888;
    --tg-theme-link-color: #007aff;
    --tg-theme-button-color: #007aff;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #2c2c2e;
}

body[data-theme="dark"] .input-container-wrapper {
    background-color: transparent;
}

body[data-theme="dark"] .input-wrapper {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] .clip-button {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] .clip-button svg {
    filter: invert(1);
}

body[data-theme="dark"] .microphone-button {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    transform: scale(1) translateY(2px);
}

body[data-theme="dark"] .microphone-button svg,
body[data-theme="dark"] .microphone-button img,
body[data-theme="dark"] .microphone-button .microphone-icon {
    filter: invert(1);
}

body[data-theme="dark"] .send-button.record-mode {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    transform: scale(1) translateY(2px);
}

body[data-theme="dark"] .chat-header-wrapper {
    background-color: rgba(28, 28, 30, 0.5);
}

body[data-theme="dark"] .file-preview {
    background-color: #2c2c2e;
}

body[data-theme="dark"] .copy-button {
    background-color: rgba(28, 28, 30, 0.95);
}

body[data-theme="dark"] #messageInput {
    caret-color: #0A84FF !important;
}

body[data-theme="dark"] #messageInput:focus {
    animation: caret-blink-dark 1.2s ease-in-out infinite;
}

/* Анимация мигания курсора для темной темы */
@keyframes caret-blink-dark {
    0%, 45% {
        caret-color: #0A84FF;
    }
    50%, 95% {
        caret-color: transparent;
    }
    100% {
        caret-color: #0A84FF;
    }
}

/* Зелёная тема */
body[data-theme="green"] {
    --tg-theme-bg-color: #f0f7ff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #34c759;
    --tg-theme-button-color: #34c759;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #e8f5e8;
}

/* Фиолетовая тема */
body[data-theme="purple"] {
    --tg-theme-bg-color: #f8f7ff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #af52de;
    --tg-theme-button-color: #af52de;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0eaff;
}

/* Оранжевая тема */
body[data-theme="orange"] {
    --tg-theme-bg-color: #fffaf0;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #ff9500;
    --tg-theme-button-color: #ff9500;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #ffe8cc;
}

/* Красная тема */
body[data-theme="red"] {
    --tg-theme-bg-color: #fff5f5;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #ff3b30;
    --tg-theme-button-color: #ff3b30;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #ffe0e0;
}

/* Скрытие скроллбара в webkit (Chrome, Safari, Edge, iOS) - полное скрытие */
.messages-container::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
    background: transparent !important;
}

.messages-container::-webkit-scrollbar-track {
    display: none !important;
    background: transparent !important;
}

.messages-container::-webkit-scrollbar-thumb {
    display: none !important;
    background: transparent !important;
}

.messages-container::-webkit-scrollbar-corner {
    display: none !important;
    background: transparent !important;
}

.new-chat-button {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
    border: none;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    white-space: nowrap;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-shrink: 0; /* Предотвращаем сжатие кнопки */
}

.new-chat-button:active {
    transform: scale(0.95);
    opacity: 0.8;
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px;
    background-color: var(--tg-theme-secondary-bg-color, rgba(0, 0, 0, 0.05));
    border-radius: 20px;
    flex-shrink: 0;
}

.lang-button {
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    width: 32px;
    height: 32px;
}

.lang-button.active {
    background-color: var(--tg-theme-button-color, #007aff);
}

.lang-button:active {
    transform: scale(0.95);
}

.flag-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    object-fit: cover;
}

.header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0; /* Предотвращаем сжатие контейнера с кнопками */
}

.header-icon-button {
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text-color);
    transition: background-color 0.2s ease;
    flex-shrink: 0; /* Предотвращаем сжатие кнопки */
}
.header-icon-button:active {
    background-color: rgba(0,0,0,0.1);
}
.header-icon-button svg {
    width: 22px;
    height: 22px;
}

.plus-icon {
    width: 10px;
    height: 10px;
    color: currentColor;
    flex-shrink: 0;
}

.button-text {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* Эффект нажатия на сообщение (кроме уже выделенного) - только для мобильных */
@media (hover: none), (pointer: coarse) {
    body:not(.dialog-style-active) .message:not(.copy-selected):active,
    body.dialog-style-active .message.sent:not(.copy-selected):active {
        transform: scale(0.98);
    }
}

.message-copy-icon {
    position: absolute;
    bottom: 8px; /* Опускаем иконку вниз */
    width: 28px;
    height: 28px;
    padding: 4px;
    border-radius: 50%;
    color: var(--tg-theme-hint-color, #8e8e93);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    pointer-events: none;
    display: none; /* Скрыто по умолчанию */
}

.message.sent .message-copy-icon {
    left: -36px;
}

.message.received .message-copy-icon {
    right: -36px;
}

/* Показываем иконку на устройствах с мышью постоянно */
@media (hover: hover) and (pointer: fine) {
    .message-copy-icon {
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 0.5;
        pointer-events: auto;
    }

    .message-copy-icon:hover {
        opacity: 1;
        background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    }
}

body.dialog-style-active .message-copy-icon {
    display: none !important;
}

/* Блюр-оверлей поверх всего экрана */
.copy-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.1);
    z-index: 50;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

.copy-overlay.show {
    opacity: 1;
}

/* Выделенное сообщение поверх блюра */
.message.copy-selected {
    position: relative;
    z-index: 60;
    transform: scale(1.05);
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    pointer-events: auto;
}

.message.received.copy-selected {
    transform-origin: left center;
}

.message.sent.copy-selected {
    transform-origin: right center;
}

/* Контент выделенного сообщения должен быть интерактивным */
.message.copy-selected > div:first-child {
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
    user-select: text !important;
    pointer-events: auto;
}

/* Убираем изменение цветов - сообщения остаются как есть */

.message-actions-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: rgba(250, 245, 250, 0.95);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    cursor: default;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 180px;
    width: auto;
    margin-top: 8px;
    z-index: 61;
    opacity: 0;
    transform: translateY(-10px) scale(0.8);
    overflow: hidden; /* To apply border-radius to children */
    -webkit-tap-highlight-color: transparent;
}

/* Выравнивание меню для отправленных сообщений */
.message.sent .message-actions-menu {
    right: 0;
    left: auto;
}

.message-actions-menu.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.message-actions-menu .action-item {
    background: none;
    border: none;
    color: var(--tg-theme-text-color, #000000);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    width: 100%;
    white-space: nowrap;
}

.message-actions-menu .action-item:active {
    background-color: rgba(0,0,0,0.05);
}

body[data-theme="dark"] .message-actions-menu .action-item:active {
    background-color: rgba(255,255,255,0.08);
}

body[data-theme="dark"] .message-actions-menu {
    background-color: rgba(44, 44, 46, 0.95);
}

.message-actions-menu .action-item .action-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--tg-theme-text-color, #000000);
}

.message-actions-menu .action-icon svg {
    display: block;
}

.message-actions-menu .separator {
    height: 1px;
    background-color: var(--tg-theme-hint-color, #8e8e93);
    opacity: 0.15;
    margin: 0 8px;
}

.message-actions-menu .action-item.delete {
    color: #ff3b30;
}

.message-actions-menu .action-item.delete .action-icon {
    color: #ff3b30;
}

/* Поп-ап уведомление "Скопировано" */
.copy-notification {
    position: fixed;
    /* bottom позиция устанавливается через JS */
    left: 16px;
    right: 16px;
    margin: 0 auto;
    max-width: 400px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
    border-radius: 14px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
    z-index: 100;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    pointer-events: none;
}

.copy-notification.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.copy-notification-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.checkmark__circle {
    stroke-dasharray: 166;
    stroke-dashoffset: 166;
    stroke-width: 2.5;
    stroke-miterlimit: 10;
    stroke: var(--tg-theme-link-color, #007aff);
    fill: none;
    animation: copy-notification-stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark__check {
    transform-origin: 50% 50%;
    stroke-dasharray: 48;
    stroke-dashoffset: 48;
    stroke-width: 3;
    stroke-linecap: round;
    stroke: var(--tg-theme-link-color, #007aff);
    fill: none;
    animation: copy-notification-stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.5s forwards;
}

@keyframes copy-notification-stroke {
    100% {
        stroke-dashoffset: 0;
    }
}

/* Дополнительно для мобильных в тёмной теме */
@media screen and (max-width: 768px) {
    body[data-theme="dark"] #messageInput {
        caret-color: #007aff !important;
    }
}

.model-menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    z-index: 15;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.model-menu-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.chat-header-wrapper.menu-open {
    z-index: 20;
}

.model-menu {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(250, 245, 250, 0.8);
    z-index: 19;
    padding: 8px 16px 16px;
    padding-top: 82px; /* Отступ для шапки */
    border-bottom-left-radius: 20px;
    border-bottom-right-radius: 20px;
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
    max-height: 100vh;
}

.model-menu.show {
    transform: translateY(0);
}

.model-menu-content {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.model-menu-content > * {
    opacity: 0;
    transform: translateY(15px) scale(0.95);
    transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1), transform 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.model-menu.show .model-menu-content > * {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.model-menu.show .model-menu-content > *:nth-child(1) { transition-delay: 0.1s; }
.model-menu.show .model-menu-content > *:nth-child(2) { transition-delay: 0.16s; }
.model-menu.show .model-menu-content > *:nth-child(3) { transition-delay: 0.22s; }
.model-menu.show .model-menu-content > *:nth-child(4) { transition-delay: 0.28s; }
.model-menu.show .model-menu-content > *:nth-child(5) { transition-delay: 0.34s; }

.model-menu .menu-block {
    background-color: transparent;
    border-radius: 12px;
    padding: 0;
}

.model-list-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, padding-bottom 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 8px;
    transform: translateZ(0);
}

.model-list-container::-webkit-scrollbar {
    display: none;
}

.model-list-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.model-menu .model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
}

.model-menu .model-option.active {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
}

.model-menu .model-option .model-info strong {
    font-size: 15px;
    font-weight: 600;
}

.model-menu .model-option .model-info span:not(.free-badge) {
    font-size: 11px;
    display: block;
    opacity: 0.7;
}
.model-menu .model-option.active .model-info span:not(.free-badge) {
    opacity: 0.9;
}

.model-menu .model-option .model-check {
    font-size: 20px;
    font-weight: bold;
}

.model-menu .quick-actions {
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    background-color: transparent;
}

.model-menu .action-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-text-color, #000000);
    width: 80px;
}

.model-menu .action-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.model-menu .action-button:active .action-icon {
    background-color: rgba(0,0,0,0.1);
}

.model-menu .action-button.pulse {
    animation: actionButtonPulse 0.3s ease-out;
}

@keyframes actionButtonPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.model-menu .action-icon svg {
    width: 26px;
    height: 26px;
}

.model-menu .user-profile {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 40px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 8px;
    padding-right: 16px;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.profile-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-grow: 1;
}

.subscription-info {
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-link-color, #007aff);
    margin-top: 2px;
}

.model-menu .profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 2px solid var(--tg-theme-bg-color, #ffffff);
    flex-shrink: 0;
}

.model-menu .profile-name {
    font-size: 16px;
    font-weight: 600;
}

.profile-action-buttons {
    display: flex;
    gap: 8px;
}

.profile-action-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.profile-action-btn:active {
    background-color: rgba(0,0,0,0.15);
}

.model-menu .profile-id {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-top: -4px;
}

.model-menu .other-ais {
    background: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-category {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 16px;
    padding: 16px 0 16px 16px;
}

.ai-category-header {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color, #000000);
}

.ai-list-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-right: 16px; /* Add some padding to the right end */
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Поддержка прокрутки на тачпаде */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.ai-list-scroller::-webkit-scrollbar {
    display: none;
}

.model-menu .ai-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 80px;
    flex-shrink: 0;
}

.model-menu .ai-avatar {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

.model-selection-wrapper {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 12px;
    transition: all 0.3s ease;
}

.selected-model-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
}

.dropdown-arrow {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: rotate(0deg);
    color: var(--tg-theme-hint-color, #8e8e93);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.model-selection-wrapper.expanded .dropdown-arrow {
    transform: rotate(180deg);
}

.model-menu .menu-block {
    background-color: transparent;
    border-radius: 12px;
    padding: 0;
}

.model-list-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out, padding-bottom 0.4s ease-in-out;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 8px;
    transform: translateZ(0);
}

.model-selection-wrapper.expanded .model-list-container {
    max-height: 250px; /* или любая другая подходящая высота */
    overflow-y: auto;
    padding-bottom: 8px;
}

#selectedModelInfo strong {
    font-size: 16px;
    font-weight: 600;
    display: block;
}

#selectedModelInfo span:not(.free-badge) {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    display: block;
    margin-top: 2px;
}

/* Плашка FREE в выбранной модели меньше */
#selectedModelInfo .free-badge {
    font-size: 7px;
    padding: 1px 5px;
    opacity: 1;
}

.model-list-container::-webkit-scrollbar {
    display: none;
}

.model-list-container {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.model-menu .model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
}

.model-menu .model-option.active {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
}

.model-menu .model-option .model-info strong {
    font-size: 15px;
    font-weight: 600;
}

.model-menu .model-option .model-info span:not(.free-badge) {
    font-size: 11px;
    display: block;
    opacity: 0.7;
}
.model-menu .model-option.active .model-info span:not(.free-badge) {
    opacity: 0.9;
}

.model-menu .model-option .model-check {
    font-size: 20px;
    font-weight: bold;
}

.model-menu .quick-actions {
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    background-color: transparent;
}

.model-menu .action-button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-text-color, #000000);
    width: 80px;
}

.model-menu .action-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.model-menu .action-button:active .action-icon {
    background-color: rgba(0,0,0,0.1);
}

.model-menu .action-button.pulse {
    animation: actionButtonPulse 0.3s ease-out;
}

@keyframes actionButtonPulse {
    0% { transform: scale(1); }
    50% { transform: scale(0.92); }
    100% { transform: scale(1); }
}

.model-menu .action-icon svg {
    width: 26px;
    height: 26px;
}

.model-menu .user-profile {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 20px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    width: 100%;
}

.profile-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.model-menu .profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 22px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

.model-menu .profile-name {
    font-size: 16px;
    font-weight: 600;
}

.model-menu .profile-id {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-top: -4px;
}

.model-menu .other-ais {
    background: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-category {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 16px;
    padding: 16px 0 16px 16px;
}

.ai-category-header {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color, #000000);
}

.ai-list-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-right: 16px; /* Add some padding to the right end */
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Поддержка прокрутки на тачпаде */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.ai-list-scroller::-webkit-scrollbar {
    display: none;
}

.model-menu .ai-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 80px;
    flex-shrink: 0;
}

.model-menu .ai-avatar {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

.user-section {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 8px;
}

.model-menu .user-profile {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 40px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    padding: 8px;
    padding-right: 16px;
    width: 100%;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.model-menu .user-profile:active {
    background-color: rgba(0,0,0,0.1);
}

.profile-details {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex-grow: 1;
}

.subscription-info {
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-link-color, #007aff);
    margin-top: 2px;
}

.model-menu .profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 2px solid var(--tg-theme-bg-color, #ffffff);
    flex-shrink: 0;
}

.model-menu .profile-name {
    font-size: 16px;
    font-weight: 600;
}

.profile-action-buttons {
    display: flex;
    gap: 8px;
}

.profile-action-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--tg-theme-text-color, #000000);
    transition: background-color 0.2s ease;
}

.profile-action-btn:active {
    background-color: rgba(0,0,0,0.15);
}

.model-menu .profile-id {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-top: -4px;
}

.model-menu .other-ais {
    background: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ai-category {
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    border-radius: 16px;
    padding: 16px 0 16px 16px;
}

.ai-category-header {
    font-size: 17px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--tg-theme-text-color, #000000);
}

.ai-list-scroller {
    display: flex;
    gap: 16px;
    overflow-x: auto;
    padding-right: 16px; /* Add some padding to the right end */
    -ms-overflow-style: none;
    scrollbar-width: none;
    scroll-behavior: smooth;
    /* Поддержка прокрутки на тачпаде */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.ai-list-scroller::-webkit-scrollbar {
    display: none;
}

.model-menu .ai-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    width: 80px;
    flex-shrink: 0;
}

.model-menu .ai-avatar {
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(0,0,0,0.05);
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

/* Светлая тема (принудительная) */
body[data-theme="light"] {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #8e8e93;
    --tg-theme-link-color: #007aff;
    --tg-theme-button-color: #007aff;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f0f0f0;
}

body[data-theme="light"] .input-container-wrapper {
    background-color: transparent;
}

body[data-theme="light"] .input-wrapper {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

body[data-theme="light"] .clip-button {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
}

body[data-theme="light"] .microphone-button {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    transform: scale(1) translateY(2px);
}

body[data-theme="light"] .send-button.record-mode {
    background-color: rgba(253, 253, 253, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
    transform: scale(1) translateY(2px);
}

body[data-theme="light"] .chat-header-wrapper {
    background-color: rgba(250, 245, 250, 0.5);
}

body[data-theme="light"] .file-preview {
    background-color: #f0f0f0;
}

body[data-theme="light"] .copy-button {
    background-color: rgba(250, 245, 250, 0.95);
}

body[data-theme="light"] #messageInput {
    caret-color: #007aff !important;
}

body[data-theme="light"] #messageInput:focus {
    animation: caret-blink 1.2s ease-in-out infinite;
}

body[data-theme="dark"] #messageInput {
    caret-color: #0A84FF !important;
}

.model-menu .user-profile:active {
    background-color: rgba(0,0,0,0.1);
}

.selected-model-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    cursor: pointer;
}

.dropdown-arrow {
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: rotate(0deg);
    color: var(--tg-theme-hint-color, #8e8e93);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.model-selection-wrapper.expanded .dropdown-arrow {
    transform: rotate(180deg);
}

.model-selection-wrapper.expanded .model-list-container {
    max-height: 250px; /* или любая другая подходящая высота */
    overflow-y: auto;
    padding-bottom: 8px;
}

#selectedModelInfo strong {
    font-size: 16px;
    font-weight: 600;
    display: block;
}

#selectedModelInfo span:not(.free-badge) {
    font-size: 13px;
    color: var(--tg-theme-hint-color, #8e8e93);
    display: block;
    margin-top: 2px;
}

/* Плашка FREE в выбранной модели меньше */
#selectedModelInfo .free-badge {
    font-size: 7px;
    padding: 1px 5px;
    opacity: 1;
}

.model-list-container::-webkit-scrollbar {
    display: none;
}

.copy-code-button {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #e1e4e8;
    color: #24292e;
    border: 1px solid rgba(27, 31, 35, 0.15);
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    opacity: 0.7; /* Уменьшаем прозрачность для лучшей видимости */
    transition: opacity 0.2s ease-in-out;
    z-index: 1;
}

.message div pre:hover .copy-code-button {
    opacity: 1;
}

.copy-code-button.copied {
    background-color: #4CAF50;
    color: white;
    opacity: 1;
}

.recording-indicator {
    display: none;
    align-items: center;
    justify-content: space-between;
    background-color: var(--tg-theme-bg-color, #ffffff);
    border-radius: 18px;
    padding: 6px 16px;
    min-height: 40px;
    flex: 1;
    margin-right: 6px;
}

.recording-indicator.active {
    display: flex;
}

.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ff3b30;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { opacity: 1; }
    50% { opacity: 0.3; }
    100% { opacity: 1; }
}

.recording-time {
    font-size: 15px;
    color: var(--tg-theme-text-color, #000000);
    font-family: inherit;
    font-variant-numeric: tabular-nums;
}

.recording-cancel {
    font-size: 15px;
    font-weight: 500;
    color: var(--tg-theme-link-color, #007aff);
    cursor: pointer;
}

/* Custom User Audio Player */
.user-audio-player {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 20px;
    padding: 8px;
    max-width: 280px;
}
body[data-theme="dark"] .message.sent .user-audio-player {
     background-color: rgba(255, 255, 255, 0.15);
}
.user-audio-player-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background-color: var(--tg-theme-button-text-color, #ffffff);
    color: var(--tg-theme-button-color, #007aff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.user-audio-player-button:active {
    transform: scale(0.9);
}
.user-audio-player-button svg {
    width: 18px;
    height: 18px;
    margin-left: 2px; /* Optical alignment for play icon */
}
.user-audio-player-button .pause-icon {
    display: none;
}
.user-audio-player.playing .play-icon {
    display: none;
}
.user-audio-player.playing .pause-icon {
    display: block;
    margin-left: 0; /* Reset alignment */
}
.user-audio-waveform-container {
    flex-grow: 1;
    height: 32px;
    position: relative;
}
.user-audio-waveform-canvas {
    width: 100%;
    height: 100%;
    cursor: pointer;
}

#history-section {
    padding-right: 16px;
    background: none;
}

.history-list-container {
    padding: 16px 0;
    text-align: center;
}

.empty-history-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--tg-theme-hint-color, #8e8e93);
    padding: 16px 0;
    opacity: 0.8;
}

.empty-history-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background-color: var(--tg-theme-bg-color, #ffffff);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

body[data-theme="dark"] .empty-history-icon {
    background-color: #2c2c2e;
}

.empty-history-placeholder p {
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-theme-text-color, #000000);
    margin: 0;
}

.empty-history-placeholder span {
    font-size: 13px;
    max-width: 250px;
    line-height: 1.4;
}

body[data-theme="dark"] .model-menu {
    background-color: rgba(28, 28, 30, 0.85);
}

.dialog-message-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

body.dialog-style-active .dialog-message-actions {
    position: absolute;
    bottom: -5px;
    left: 0px;
}

.dialog-action-btn {
    background: transparent;
    border: none;
    padding: 6px; /* Увеличен padding для корректного отображения кругового фона */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tg-theme-hint-color, #8e8e93);
    opacity: 0.7;
    border-radius: 50%;
    transition: all 0.2s ease;
}
.dialog-action-btn:hover {
    opacity: 1;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
}
body[data-theme="dark"] .dialog-action-btn:hover {
    background-color: rgba(255,255,255,0.1);
}

.dialog-action-btn svg {
    width: 16px;
    height: 16px;
}

body.dialog-style-active .message-time {
    text-align: right;
    padding-left: 0;
    padding-right: 5px;
}

.message.sent.has-image.image-only .image-container img {
    border-radius: 18px 18px 4px 18px;
}

.message.sent.has-image .files-container {
    background-color: var(--tg-theme-button-color, #007aff);
    color: var(--tg-theme-button-text-color, #ffffff);
    padding: 8px 12px;
    border-radius: 0 0 4px 18px;
    margin-top: -4px;
}

.message.sent.has-image .message-time {
    padding: 5px 12px 8px 12px;
    margin-top: 0;
}

.message.sent.has-image.image-only .message-time {
    position: absolute;
    bottom: 8px;
    right: 12px;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
}

/* Когда есть текст под изображением - убираем скругление снизу у контейнера */
.message.sent.has-image:not(.image-only) .image-container img {
   border-radius: 0 !important;
}

/* Стили для кнопки повтора */
.retry-button {
    position: absolute;
    left: -35px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background-color: #ff4444;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 5;
}

.retry-button:hover {
    background-color: #ff6666;
}

.retry-button svg {
    width: 12px;
    height: 12px;
    fill: white;
    transform: rotate(180deg);
}

.message.sent.has-retry .retry-button {
    opacity: 1;
}

/* Анимация при наведении на сообщение с кнопкой повтора */
.message.sent.has-retry:hover .retry-button {
    opacity: 1;
}

.sources-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(128, 128, 128, 0.2);
}

.sources-header {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--tg-theme-text-color, #000000);
}

.sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.source-link-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-text-color, #000000);
    padding: 4px 10px 4px 4px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
}

.source-link-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

body[data-theme="dark"] .source-link-chip {
     background-color: #2c2c2e;
}

.source-favicon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    flex-shrink: 0;
    background-color: #fff;
    border: 1px solid rgba(0,0,0,0.05);
}

body.dialog-style-active .message-time {
    text-align: right;
    padding-left: 0;
    padding-right: 5px;
}

.sources-header-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--tg-theme-hint-color, #8e8e93);
    margin-left: auto; /* Прижимаем вправо */
}

.overlapping-favicons {
    display: flex;
    align-items: center;
    height: 24px;
}

.overlapping-favicons .source-favicon {
    margin-left: -10px;
    border: 2px solid var(--tg-theme-bg-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.overlapping-favicons .source-favicon:first-child {
    margin-left: 0;
}

body.dialog-style-active .sources-section {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 8px;
    padding: 0 8px;
    border-top: none;
}

body.dialog-style-active .sources-list {
    margin-top: 8px;
    flex-grow: 1;
    justify-content: flex-end;
    display: none; /* Скрываем по умолчанию, пока не используется */
}

.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 4px 8px 12px; /* Увеличен нижний отступ до 12px для полного отображения кругового фона кнопок при hover */
    margin-top: 8px; /* Добавим отступ сверху */
}

body.dialog-style-active .message.received {
    padding-bottom: 8px; /* Уменьшим нижний отступ */
}

.message.sent.has-image.image-only .image-container img {
    border-radius: 18px 18px 4px 18px;
}

/* Стили для встроенных в текст ссылок */
.inline-source-chip {
    display: inline-flex;
    flex-direction: row; /* Явно указываем направление */
    align-items: center;
    /* gap: 6px; */ /* Заменен на margin */
    background-color: var(--tg-theme-secondary-bg-color, #f0f0f0);
    color: var(--tg-theme-link-color, #007aff);
    padding: 2px 8px 2px 6px; /* Скорректируем отступы T, R, B, L */
    border-radius: 16px;
    font-size: 0.8em; /* Делаем шрифт чуть меньше основного */
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
    cursor: pointer;
    vertical-align: middle; /* Лучшее выравнивание с текстом */
    margin: 0 2px;
}
body[data-theme="dark"] .inline-source-chip {
     background-color: #3a3a3c;
}
.inline-source-chip:hover {
    background-color: var(--tg-theme-hint-color, #8e8e93);
    color: var(--tg-theme-bg-color, #ffffff);
    transform: translateY(-1px);
}
.inline-source-chip .source-favicon {
     width: 16px;
     height: 16px;
     border-radius: 50%;
     flex-shrink: 0;
     display: block; /* Убедимся, что иконка является блоком */
     margin-right: 8px; /* Отступ между иконкой и текстом */
}

/* Анимация копирования */
@keyframes fadeInSlideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Специальная анимация для первого сообщения */
.message.first-message {
    animation: firstMessageSlideUp 0.6s ease-out;
}

@keyframes firstMessageSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========== VOICE RECORDING STYLES ========== */

/* Режим записи голоса - скрываем textarea */
.input-wrapper.recording-mode {
    padding: 0 16px;
}

/* Контейнер элементов управления записью */
.recording-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

/* Красная точка (мигающая) */
.recording-dot {
    width: 12px;
    height: 12px;
    background-color: #ff3b30;
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse 1.5s ease-in-out infinite;
}

/* Когда на паузе - точка не мигает */
.recording-dot.paused {
    animation: none;
    opacity: 0.5;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.4;
        transform: scale(0.85);
    }
}

/* Таймер записи */
.recording-time {
    font-size: 16px;
    font-weight: 600;
    color: var(--tg-theme-text-color, #000000);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

/* Кнопка отмены */
.recording-cancel {
    font-size: 15px;
    color: var(--tg-theme-link-color, #007aff);
    cursor: pointer;
    margin-left: auto;
    padding: 4px 8px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.recording-cancel:active {
    opacity: 0.5;
}

/* Контейнер кнопок записи (паузы и отправки) */
.recording-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

/* Кнопка паузы/продолжить */
.pause-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(253, 253, 253, 0.7);
    backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    -webkit-backdrop-filter: blur(1px) saturate(180%) url('/assets/filters/liquid-glass.svg#liquid-glass-border');
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px 0 rgba(31, 38, 135, 0.1);
}

.pause-button:active {
    transform: scale(0.85);
}

.pause-button svg {
    width: 20px;
    height: 20px;
    color: #000000;
    opacity: 0.85;
}

/* Темная тема для кнопки паузы */
body[data-theme="dark"] .pause-button {
    background-color: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 16px 0 rgba(0, 0, 0, 0.3);
}

body[data-theme="dark"] .pause-button svg {
    filter: invert(1);
}

/* Кнопка отправить в режиме записи (синяя) */
.send-button.recording-send {
    background: linear-gradient(135deg, #007aff 0%, #0051d5 100%) !important;
    width: 40px;
    height: 40px;
}

.send-button.recording-send:active {
    transform: scale(0.85);
}

.send-button.recording-send svg {
    color: #ffffff !important;
    filter: none !important;
}
/* ========== AUDIO PLAYER STYLES ========== */

.audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    min-width: 280px; /* Prevent shrinking when transcription opens */
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

body[data-theme="dark"] .audio-player {
    background-color: rgba(255, 255, 255, 0.05);
}

.audio-player .play-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.audio-player .play-button:active {
    transform: scale(0.9);
}

.audio-player .play-button svg {
    color: #007aff;
    width: 18px;
    height: 18px;
}

.audio-player .audio-waveform {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    justify-content: center;
}

.audio-player .waveform-bars {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Равномерное распределение баров по ширине */
    height: 32px;
    overflow: hidden;
    min-width: 120px; /* Ensure bars don't shrink too much */
    flex-shrink: 0; /* Prevent shrinking */
}

.audio-player .waveform-bars .bar {
    flex: 0 0 auto; /* Фиксированная ширина баров */
    width: 2px; /* Фиксированная ширина бара */
    background-color: #ffffff;
    border-radius: 1px;
    transition: opacity 0.1s ease;
    opacity: 1;
    align-self: center;
}

.audio-player .waveform-bars .bar.played {
    opacity: 0.3;
}

body[data-theme="dark"] .audio-player .waveform-bars .bar {
    background-color: #ffffff;
}

body[data-theme="dark"] .audio-player .waveform-bars .bar.played {
    opacity: 0.3;
}

.audio-player .audio-time {
    font-size: 12px;
    color: #ffffff;
    font-weight: 500;
    opacity: 0.6;
}

.audio-player .transcribe-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.1);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

body[data-theme="dark"] .audio-player .transcribe-button {
    background-color: rgba(255, 255, 255, 0.1);
}

.audio-player .transcribe-button:active {
    transform: scale(0.9);
}

.audio-player .transcribe-button svg {
    color: #ffffff;
    width: 16px;
    height: 16px;
    opacity: 0.6;
}

body[data-theme="dark"] .audio-player .transcribe-button svg {
    color: #ffffff;
}

.audio-player .transcribe-button.active {
    background-color: var(--tg-theme-button-color, #007aff);
}

body[data-theme="dark"] .audio-player .transcribe-button.active {
    background-color: var(--tg-theme-button-color, #0a84ff);
}

.audio-player .transcribe-button.active svg {
    opacity: 1;
    color: #ffffff;
}

.audio-player .transcribe-button svg.rotated {
    transform: rotate(90deg);
}

/* ========== TRANSCRIPTION CONTAINER STYLES ========== */

.transcription-container {
    padding: 12px 16px;
    margin-top: 8px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    animation: fadeIn 0.3s ease-out;
    width: 100%;
    box-sizing: border-box;
}

body[data-theme="dark"] .transcription-container {
    background-color: rgba(255, 255, 255, 0.05);
}

.transcription-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #ffffff;
    font-size: 14px;
}

.transcription-loading span {
    color: #ffffff;
}

.transcription-loading .spinner-small {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--tg-theme-button-color, #007aff);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

body[data-theme="dark"] .transcription-loading .spinner-small {
    border-color: rgba(255, 255, 255, 0.1);
    border-top-color: var(--tg-theme-button-color, #0a84ff);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.transcription-text {
    font-size: 14px;
    line-height: 1.5;
    color: #ffffff;
    white-space: pre-wrap;
    word-wrap: break-word;
}

body[data-theme="dark"] .transcription-text {
    color: #ffffff;
}

.transcription-error {
    font-size: 14px;
    color: #ff3b30;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* === Темная тема для Shared Chat === */
body[data-theme="dark"] .chat-info h3 {
    color: #ffffff;
}

body[data-theme="dark"] .chat-info p {
    color: #98989d;
}

body[data-theme="dark"] .messages-container {
    background-color: #1c1c1e;
}

body[data-theme="dark"] .message.received {
    background-color: #2c2c2e;
    color: #ffffff;
}

body[data-theme="dark"] .message.sent {
    color: #ffffff;
}

body[data-theme="dark"] main.content {
    background-color: #000000;
}

/* ===== DESKTOP LAYOUT WITH SIDEBAR (> 1025px) ===== */
/* Сдвигаем header и input-bar вправо, чтобы они не перекрывали sidebar */
@media (min-width: 1025px) {
    .chat-header-wrapper {
        left: 300px !important;
        transition: left 0.3s ease;
    }

    .input-container-wrapper {
        left: 300px !important;
        transition: left 0.3s ease;
    }
}

/* ===== LARGE SCREENS (> 2000px) ===== */
/* Увеличиваем отступ для увеличенного sidebar */
@media (min-width: 2000px) {
    .chat-header-wrapper {
        left: 350px !important;
    }

    .input-container-wrapper {
        left: 350px !important;
    }
}
