/* ========================================================
   CHAT.CSS — Вкладка чата
   ======================================================== */

/* ========== LAYOUT ========== */
.chat-layout {
    display: flex;
    gap: 0;
    height: calc(100vh - 120px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    overflow: hidden;
    background: rgba(13, 17, 30, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 32px rgba(0, 0, 0, 0.3);
}

/* ========== САЙДБАР ========== */
.chat-sidebar {
    width: 260px;
    min-width: 200px;
    background: rgba(5, 8, 18, 0.6);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.chat-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.chat-sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: #e6edf3;
}
.chat-sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.chat-sidebar-list::-webkit-scrollbar { width: 4px; }
.chat-sidebar-list::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.2); border-radius: 4px; }

.chat-empty-hint {
    color: #8b949e;
    font-size: 12px;
    text-align: center;
    padding: 20px 10px;
    line-height: 1.5;
}

/* Кнопка ＋ новый чат — круглая */
.chat-sidebar-header .btn-sm.btn-primary {
    width: 24px;
    height: 24px;
    padding: 0 !important;
    border-radius: 50% !important;
    font-size: 18px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(46, 160, 67, 0.08) !important;
    border: 1px solid rgba(63, 185, 80, 0.25) !important;
    color: #3fb950 !important;
    box-shadow: none !important;
}
.chat-sidebar-header .btn-sm.btn-primary:hover {
    background: rgba(46, 160, 67, 0.15) !important;
    border-color: rgba(63, 185, 80, 0.4) !important;
    box-shadow: 0 0 12px rgba(63, 185, 80, 0.1) !important;
    transform: scale(1.1);
}

/* ========== ПОИСК ЧАТОВ ========== */
.chat-sidebar-search {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.chat-sidebar-search input {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #e6edf3;
    padding: 6px 10px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}
.chat-sidebar-search input:focus { border-color: #8b5cf6; box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.12); }

/* ========== ЭЛЕМЕНТЫ СПИСКА ЧАТОВ ========== */
.chat-item {
    padding: 10px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 4px;
    border: 1px solid transparent;
    position: relative;
    display: flex;
    align-items: center;
}
.chat-item:hover { background: rgba(255, 255, 255, 0.04); }
.chat-item.active {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.25);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.06);
}
.chat-item-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.chat-item-title {
    font-size: 13px;
    font-weight: 500;
    color: #f0f6fc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 20px);
}
.chat-item-meta {
    font-size: 10px;
    color: #656d76;
    margin-top: 2px;
}

/* Меню на чатах */
.chat-item-menu-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #8b949e;
    cursor: pointer;
    font-size: 16px;
    padding: 0;
    display: none;
    border-radius: 6px;
    width: 22px !important;
    height: 22px !important;
    min-width: 22px !important;
    align-items: center;
    justify-content: center;
}
.chat-item:hover .chat-item-menu-btn { display: flex; }
.chat-item-menu-btn:hover { background: rgba(255, 255, 255, 0.06); color: #f0f6fc; }

/* ========== СЕКЦИИ СПИСКА ЧАТОВ ========== */
.chat-list-section {
    margin-bottom: 4px;
}
.chat-list-section-title {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    color: #8b949e;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.chat-list-section-title svg {
    color: #f0c040;
}
.chat-item.pinned {
    border-left: 2px solid rgba(240, 192, 64, 0.3);
}
.chat-pin-icon {
    display: inline-flex;
    margin-right: 4px;
    color: #f0c040;
    vertical-align: -1px;
}
.chat-pin-icon svg {
    width: 11px;
    height: 11px;
}

/* ========== ОСНОВНАЯ ОБЛАСТЬ ========== */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ========== ПРИВЕТСТВИЕ ========== */
.chat-welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #8b949e;
    text-align: center;
    padding: 40px;
}
.chat-welcome-icon {
    margin-bottom: -12px;
}
.chat-welcome h3 {
    color: #f0f6fc;
    margin: 0 0 4px;
}
.chat-welcome p {
    margin: 0 0 2px;
    font-size: 14px;
}

/* ========== АКТИВНЫЙ ЧАТ ========== */
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

/* ========== ЗАГОЛОВОК ЧАТА ========== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(5, 8, 18, 0.5);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.chat-title-text {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #f0f6fc;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-rename-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    border-radius: 6px;
    opacity: 0.5;
    transition: 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
}
.chat-rename-btn:hover { opacity: 1; background: rgba(255, 255, 255, 0.06); }
.chat-header-right { display: flex; gap: 8px; flex-shrink: 0; }

/* ========== СООБЩЕНИЯ ========== */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.15); border-radius: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.4); }

.chat-msg {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: chatFadeIn 0.3s ease;
}
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.assistant { align-self: flex-start; }
.chat-msg.assistant .chat-msg-body { max-width: 900px; }
.chat-msg.user .chat-msg-body { max-width: 700px; }

@keyframes chatFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== АВАТАРЫ ========== */
.chat-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.chat-msg.user .chat-msg-avatar {
    background: linear-gradient(135deg, rgba(56, 139, 253, 0.15) 0%, rgba(139, 92, 246, 0.2) 100%);
    border: 1px solid rgba(56, 139, 253, 0.2);
    color: #58a6ff;
    box-shadow: 0 0 12px rgba(56, 139, 253, 0.1);
}
.chat-msg.assistant .chat-msg-avatar {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(167, 139, 250, 0.25) 50%, rgba(56, 139, 253, 0.15) 100%);
    border: 1px solid rgba(139, 92, 246, 0.25);
    color: #c4b5fd;
    box-shadow: 0 0 16px rgba(139, 92, 246, 0.15), 0 0 4px rgba(167, 139, 250, 0.1);
    font-size: 16px;
    font-weight: 700;
}

/* ========== ТЕЛО СООБЩЕНИЙ ========== */
.chat-msg-body {
    background: rgba(22, 27, 44, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 14px;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.6;
    color: #e6edf3;
    position: relative;
    min-width: 60px;
}
.chat-msg.user .chat-msg-body {
    background: linear-gradient(135deg, rgba(56, 139, 253, 0.12) 0%, rgba(99, 102, 241, 0.14) 100%) !important;
    border: 1px solid rgba(56, 139, 253, 0.18) !important;
}
.chat-msg.user .chat-msg-body:hover {
    border-color: rgba(56, 139, 253, 0.25);
    box-shadow: 0 2px 16px rgba(56, 139, 253, 0.08);
}
.chat-msg.assistant .chat-msg-body {
    background: linear-gradient(135deg, rgba(22, 27, 44, 0.7) 0%, rgba(30, 35, 55, 0.65) 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.07) !important;
}
.chat-msg.assistant .chat-msg-body:hover {
    border-color: rgba(139, 92, 246, 0.18);
    box-shadow: 0 2px 16px rgba(139, 92, 246, 0.06);
}

/* ========== КОД В СООБЩЕНИЯХ ========== */
.chat-msg-body pre {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 10px;
    overflow-x: auto;
    font-size: 13px;
    white-space: pre;
    margin: 8px 0;
}
.chat-msg-body code {
    background: rgba(139, 92, 246, 0.1);
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 13px;
}
.chat-msg-body pre code {
    padding: 0;
    margin: 0;
    white-space: pre;
    display: block;
}
.chat-msg-body pre code ol,
.chat-msg-body pre code ul,
.chat-msg-body pre code li {
    all: unset;
    display: block;
    margin: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    list-style: none;
}

/* Скроллбар в блоках кода */
.chat-msg-content pre,
.chat-msg-content .code-block-wrap pre {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.3) transparent;
}
.chat-msg-content pre::-webkit-scrollbar,
.chat-msg-content .code-block-wrap pre::-webkit-scrollbar {
    height: 6px;
    width: 6px;
}
.chat-msg-content pre::-webkit-scrollbar-track,
.chat-msg-content .code-block-wrap pre::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}
.chat-msg-content pre::-webkit-scrollbar-thumb,
.chat-msg-content .code-block-wrap pre::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.25);
    border-radius: 3px;
}
.chat-msg-content pre::-webkit-scrollbar-thumb:hover,
.chat-msg-content .code-block-wrap pre::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.45);
}

/* ========== КНОПКА КОПИРОВАНИЯ КОДА ========== */
.code-block-wrap {
    position: relative;
    margin: 8px 0;
}
.code-copy-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(22, 27, 44, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px 8px;
    font-size: 12px;
    cursor: pointer;
    color: #8b949e;
    opacity: 0;
    transition: all 0.2s ease;
    z-index: 2;
    line-height: 1;
}
.code-block-wrap:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.3);
    color: #a78bfa;
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.1);
}
.code-copy-btn.copied {
    opacity: 1;
    background: rgba(63, 185, 80, 0.12);
    border-color: rgba(63, 185, 80, 0.3);
    color: #3fb950;
}

/* ========== СВОРАЧИВАНИЕ СООБЩЕНИЙ ========== */
.chat-msg.user .chat-msg-content.collapsed {
    max-height: 200px; overflow: hidden; position: relative;
    mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
}
.chat-msg-expand-btn {
    display: none; margin-top: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px; color: #a78bfa; font-size: 12px;
    padding: 4px 12px; cursor: pointer; transition: all 0.2s;
}
.chat-msg-expand-btn:hover {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.3);
}
.chat-msg-expand-btn.visible { display: inline-block; }

/* ========== КНОПКИ НА СООБЩЕНИИ (ВЕРХ) ========== */
.chat-msg-actions {
    display: none;
    position: absolute;
    top: -8px;
    right: 8px;
    gap: 4px;
}
.chat-msg-body:hover .chat-msg-actions { display: flex; }
.chat-msg-action-btn {
    background: rgba(22, 27, 44, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 0;
    font-size: 11px;
    cursor: pointer;
    color: #8b949e;
    transition: 0.15s;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-msg-action-btn:hover { background: rgba(255, 255, 255, 0.1); color: #f0f6fc; }

/* ========== КНОПКИ ВНИЗУ СООБЩЕНИЯ ========== */
.chat-msg-bottom-actions {
    display: flex;
    gap: 4px;
    position: absolute;
    bottom: -8px;
    right: 8px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s, visibility 0.15s;
    background: none;
    border: none;
    padding: 2px 4px;
    z-index: 2;
}
.chat-msg-body:hover .chat-msg-bottom-actions {
    opacity: 1;
    visibility: visible;
}
.chat-msg-bottom-btn {
    background: rgba(22, 27, 44, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 0;
    font-size: 11px;
    cursor: pointer;
    color: #8b949e;
    transition: 0.15s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
}
.chat-msg-bottom-btn:hover { background: rgba(255, 255, 255, 0.08); color: #f0f6fc; }

/* ========== ВРЕМЯ СООБЩЕНИЯ ========== */
.chat-msg-time {
    font-size: 10px;
    color: #4d5a6c;
    margin-top: 4px;
    margin-bottom: 2px;
    opacity: 0.6;
    transition: opacity 0.2s;
    line-height: 1;
}
.chat-msg:hover .chat-msg-time { opacity: 1; }
.chat-msg.user .chat-msg-time { text-align: right; }
.chat-msg.assistant .chat-msg-time { text-align: left; }

/* ========== TYPING ИНДИКАТОР ========== */
.chat-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.08) 0%, rgba(56, 139, 253, 0.06) 100%) !important;
    border: 1px solid rgba(139, 92, 246, 0.12) !important;
    border-radius: 14px;
    color: #c4b5fd !important;
    font-size: 13px;
    align-items: center;
    gap: 8px;
}
.chat-typing.visible { display: flex; }
.typing-dots span {
    display: inline-block;
    width: 6px; height: 6px;
    background: #a78bfa !important;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
    margin: 0 1px;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ========== STREAMING КУРСОР ========== */
.streaming-cursor::after {
    content: '▌';
    animation: cursorBlink 0.8s infinite;
    color: #a78bfa;
    text-shadow: 0 0 8px rgba(167, 139, 250, 0.5);
}
@keyframes cursorBlink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ========== ФАЙЛЫ В СООБЩЕНИЯХ ========== */
.chat-file-attachment {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(139, 92, 246, 0.06);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: 8px; padding: 3px 10px; font-size: 12px;
    color: #a78bfa; margin: 4px 2px;
}

/* Кликабельный инлайн-код */
.copyable-code {
    cursor: pointer;
    transition: all 0.15s ease;
}

.copyable-code:hover {
    background: #3d444d !important;
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.3);
}

.copyable-code.copied {
    background: rgba(63, 185, 80, 0.2) !important;
}

/* ========== ВВОД ЧАТА ========== */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    background: rgba(5, 8, 18, 0.5);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}
.chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 6px 12px;
    transition: all 0.25s;
    position: relative;
}
.chat-input-wrap:focus-within {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: 0 0 20px rgba(139, 92, 246, 0.08);
}
.chat-input-resize {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 40px; height: 8px; cursor: ns-resize;
    display: flex; align-items: center; justify-content: center;
    z-index: 5; opacity: 0; transition: opacity 0.2s;
}
.chat-input-wrap:hover .chat-input-resize { opacity: 1; }
.chat-input-resize::after {
    content: ''; width: 30px; height: 3px;
    border-radius: 2px; background: rgba(255, 255, 255, 0.1);
}
.chat-input-resize:hover::after { background: #8b5cf6; }

.chat-input-left {
    display: flex;
    align-items: center;
    align-self: flex-end;
    padding-top: 2px;
    padding-bottom: 0;
    margin-bottom: 0px;
}
.chat-attach-btn {
    cursor: pointer; font-size: 18px; opacity: 0.5;
    transition: opacity 0.2s; display: flex; align-items: center;
    justify-content: center; width: 28px; height: 28px; min-width: 28px;
    border-radius: 8px; padding: 0;
}
.chat-attach-btn:hover { opacity: 1; background: rgba(255, 255, 255, 0.04); }

.chat-input-center { flex: 1; min-width: 0; display: flex; flex-direction: column; }

#chatInput {
    width: 100%; background: transparent; border: none;
    color: #e6edf3; font-size: 14px; font-family: inherit;
    line-height: 1.5; padding: 0px 0; outline: none;
    resize: none; min-height: 24px; max-height: 400px; overflow-y: auto;
}
#chatInput::placeholder { color: #484f58; }

/* Скроллбар textarea чата */
#chatInput::-webkit-scrollbar { width: 6px; }
#chatInput::-webkit-scrollbar-track { background: transparent; }
#chatInput::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.25); border-radius: 10px; }
#chatInput::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.45); }
#chatInput {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.25) transparent;
}

/* Автозаполнение */
#chatInput:-webkit-autofill,
#chatInput:-webkit-autofill:hover,
#chatInput:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px transparent inset !important;
    -webkit-text-fill-color: #e6edf3 !important;
    transition: background-color 5000s ease-in-out 0s !important;
}

/* Превью файлов */
.chat-file-preview { display: none; flex-wrap: wrap; gap: 6px; padding: 4px 0 8px; }
.chat-file-preview.has-files { display: flex; }
.chat-file-chip {
    display: inline-flex; align-items: center; gap: 4px;
    background: rgba(139, 92, 246, 0.06);
    border: 1px solid rgba(139, 92, 246, 0.15);
    border-radius: 8px; padding: 3px 8px; font-size: 12px;
    color: #a78bfa; max-width: 200px;
}
.chat-file-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-chip-remove {
    cursor: pointer; color: #f85149; font-size: 14px; line-height: 1;
    opacity: 0.7; transition: opacity 0.15s; background: none; border: none; padding: 0 2px;
}
.chat-file-chip-remove:hover { opacity: 1; }
.chat-input-hint { font-size: 11px; color: #484f58; padding: 4px 4px 0; text-align: center; }

/* ========== КНОПКИ ОТПРАВКИ/СТОП ========== */
.chat-send-btn,
.chat-stop-btn {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
    padding: 0 !important;
    border-radius: 10px !important;
    font-size: 15px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    align-self: flex-end;
    margin-top: 2px;
    margin-bottom: 6px;
    transition: all 0.2s ease;
}
.chat-stop-btn { display: none; }
.chat-stop-btn.visible { display: flex; }
.chat-send-btn.hidden { display: none; }

.chat-send-btn {
    background: rgba(46, 160, 67, 0.1) !important;
    border: 1px solid rgba(63, 185, 80, 0.3) !important;
    color: #3fb950 !important;
    box-shadow: none !important;
}
.chat-send-btn:hover {
    background: rgba(46, 160, 67, 0.2) !important;
    border-color: rgba(63, 185, 80, 0.5) !important;
    box-shadow: 0 0 14px rgba(63, 185, 80, 0.15) !important;
    transform: scale(1.05) !important;
}
.chat-stop-btn {
    background: rgba(248, 81, 73, 0.08) !important;
    border: 1px solid rgba(248, 81, 73, 0.3) !important;
    color: #f85149 !important;
    box-shadow: none !important;
    animation: stopPulse 1s infinite;
}
.chat-stop-btn:hover {
    background: rgba(248, 81, 73, 0.15) !important;
    box-shadow: 0 0 14px rgba(248, 81, 73, 0.15) !important;
    transform: scale(1.05) !important;
}
@keyframes stopPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.6; } }

/* ========== ГОЛОСОВАЯ КНОПКА ========== */
#chatVoiceBtn.recording {
    animation: voice-pulse 1s ease-in-out infinite;
}
@keyframes voice-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
#chatVoiceBtn:disabled {
    opacity: 0.5;
    pointer-events: none;
}




/* ========== КНОПКА СКРОЛЛА ВНИЗ ========== */
.chat-scroll-bottom-btn {
    position: fixed;
    z-index: 200;
    background: rgba(139, 92, 246, 0.92);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: none;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    transition: opacity 0.2s;
    pointer-events: auto;
}
.chat-scroll-bottom-btn:hover {
    background: rgba(139, 92, 246, 1);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}
.chat-scroll-bottom-btn.visible {
    display: flex;
}
@keyframes scrollBtnAppear {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
    .chat-sidebar { width: 200px; min-width: 160px; }
    .chat-msg { max-width: 95%; }
}
/* ========== ОБЁРТКА СООБЩЕНИЙ ========== */
.chat-messages-wrapper {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-messages-wrapper .chat-messages {
    flex: 1;
    overflow-y: auto;
}

/* ========== КНОПКА СКРОЛЛА ВНИЗ (СТРЕЛКА) ========== */
.chat-scroll-arrow-btn {
    position: absolute;
    bottom: 12px;
    right: 16px;
    z-index: 100;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid rgba(139, 92, 246, 0.2);
    background: rgba(22, 27, 44, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #a78bfa;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(8px) scale(0.9);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.chat-scroll-arrow-btn.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.chat-scroll-arrow-btn:hover {
    background: rgba(139, 92, 246, 0.12);
    border-color: rgba(139, 92, 246, 0.4);
    color: #c4b5fd;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.15);
    transform: translateY(-2px) scale(1.05);
}

.chat-scroll-arrow-btn:active {
    transform: translateY(0) scale(0.95);
}

.chat-scroll-arrow-btn svg {
    width: 16px;
    height: 16px;
}
/* ═══ Вкладки папок ═══ */
.chat-folder-tabs {
    display: flex;
    align-items: center;
    position: relative;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    min-height: 34px;
}

.chat-folder-tabs-scroll {
    display: flex;
    gap: 2px;
    padding: 5px 12px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    width: 100%;
}
.chat-folder-tabs-scroll::-webkit-scrollbar { display: none; }

.chat-folder-tabs-arrow {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 22px;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(5, 8, 18, 0.85);
    border: none;
    color: #8b949e;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    z-index: 2;
    transition: opacity 0.15s;
}
.chat-folder-tabs-arrow:hover {
    color: #d29922;
}
.chat-folder-tabs-arrow.left {
    left: 0;
    border-right: 1px solid rgba(255,255,255,0.06);
}
.chat-folder-tabs-arrow.right {
    right: 0;
    border-left: 1px solid rgba(255,255,255,0.06);
}


.chat-folder-tab {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 11px;
    color: #8b949e;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-folder-tab:hover {
    background: rgba(210,153,34,0.08);
    border-color: rgba(210,153,34,0.2);
    color: #d29922;
}
.chat-folder-tab.active {
    background: rgba(210,153,34,0.15);
    border-color: rgba(210,153,34,0.4);
    color: #d29922;
    font-weight: 600;
}
.chat-folder-tab-badge {
    display: inline-block;
    font-size: 9px;
    background: rgba(210,153,34,0.2);
    color: #d29922;
    padding: 0 4px;
    border-radius: 4px;
    margin-left: 4px;
    vertical-align: middle;
}
/* ═══ Контекстное меню чата ═══ */
#chatContextMenu {
    min-width: 170px;
}
#chatContextMenu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: none;
    padding: 8px 12px;
    color: #c9d1d9;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    transition: 0.15s;
    text-align: left;
}
#chatContextMenu button:last-child {
    border-bottom: none;
}
#chatContextMenu button:hover {
    background: rgba(139,92,246,0.08);
}
#chatContextMenu button.ctx-danger {
    color: #f85149;
}
#chatContextMenu button.ctx-danger:hover {
    background: rgba(248,81,73,0.08);
}
#chatContextMenu .ctx-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    min-width: 16px;
    height: 16px;
    flex-shrink: 0;
}
#chatContextMenu .ctx-icon svg {
    width: 16px;
    height: 16px;
}

/* ═══ Контекстное меню папки ═══ */
#folderContextMenu {
    min-width: 170px;
}
#folderContextMenu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: none;
    border: none;
    padding: 8px 12px;
    color: #c9d1d9;
    font-size: 13px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    transition: 0.15s;
    text-align: left;
}
#folderContextMenu button:last-child {
    border-bottom: none;
}
#folderContextMenu button:hover {
    background: rgba(210,153,34,0.08);
}
#folderContextMenu button.ctx-danger {
    color: #f85149;
}
#folderContextMenu button.ctx-danger:hover {
    background: rgba(248,81,73,0.08);
}
#folderContextMenu .ctx-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    min-width: 16px;
    height: 16px;
    flex-shrink: 0;
}
#folderContextMenu .ctx-icon svg {
    width: 16px;
    height: 16px;
}
/* ═══ Фикс субпиксельного рендеринга иконок при масштабировании ═══ */

/* Все SVG в кнопках сообщений — фиксированные целочисленные размеры */
.chat-msg-action-btn svg,
.chat-msg-bottom-btn svg {
    width: 14px !important;
    height: 14px !important;
    min-width: 14px;
    min-height: 14px;
    display: block;
}

/* Аватары — SVG внутри */
.chat-msg-avatar svg {
    width: 18px !important;
    height: 18px !important;
    display: block;
}

/* Кнопки в хедере чата */
.chat-header-right .btn svg,
.chat-rename-btn svg {
    width: 14px !important;
    height: 14px !important;
    display: block;
}

/* Кнопка меню на элементе списка чатов */
.chat-item-menu-btn svg {
    width: 14px !important;
    height: 14px !important;
    display: block;
}

/* Иконки ввода (скрепка, микрофон, отправить, стоп) */
.chat-attach-btn svg,
#chatVoiceBtn svg,
.chat-send-btn svg,
.chat-stop-btn svg {
    width: 14px !important;
    height: 14px !important;
    display: block;
}

/* Стрелка скролла */
.chat-scroll-arrow-btn svg {
    width: 16px !important;
    height: 16px !important;
    display: block;
}

/* Пин-иконка */
.chat-pin-icon svg {
    width: 11px !important;
    height: 11px !important;
    display: block;
}

/* Секция списка (звёздочка Избранное) */
.chat-list-section-title svg {
    width: 12px !important;
    height: 12px !important;
    display: block;
}

/* Контекстные меню */
#chatContextMenu .ctx-icon svg,
#folderContextMenu .ctx-icon svg {
    width: 16px !important;
    height: 16px !important;
    display: block;
}
/* Выравнивание иконок в кнопках формата скачивания */
#downloadFormatButtons .btn {
    display: flex;
    align-items: center;
}


/* Увеличить иконки форматов скачивания */
#downloadFormatButtons .btn svg {
    width: 36px;
    height: 36px;
}

#downloadFormatButtons .btn > div {
    padding-top: 8px !important;
}
.chat-file-chip {
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
    padding: 4px 10px !important;
    background: rgba(88,166,255,0.08) !important;
    border: 1px solid rgba(88,166,255,0.2) !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    color: #58a6ff !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.chat-file-chip span:nth-child(2) {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
}

/* Адаптивно для мобильных */
@media (max-width: 600px) {
    .chat-file-chip span:nth-child(2) {
        max-width: 150px;
    }
}
.field-error {
    border-color: #f85149 !important;
    box-shadow: 0 0 0 2px rgba(248, 81, 73, 0.15) !important;
}
/* ═══ ИСПРАВЛЕНИЕ МЕРЦАНИЯ ═══ */

/* Сообщения изначально скрыты при загрузке, появляются после расчёта */
.chat-msg.user .chat-msg-content.collapsed {
    max-height: 200px;
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
    /* 🔥 Плавный переход при раскрытии */
    transition: max-height 0.3s ease;
}

/* Раскрытое состояние */
.chat-msg.user .chat-msg-content:not(.collapsed) {
    max-height: none;
    mask-image: none;
    -webkit-mask-image: none;
}

/* Кнопка "Показать полностью" — скрыта по умолчанию */
.chat-msg-expand-btn {
    display: none;
    margin-top: 6px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #a78bfa;
    font-size: 12px;
    padding: 4px 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.chat-msg-expand-btn.visible {
    display: inline-block;
}

/* Pending-сообщения — визуальная индикация */
.chat-msg[data-pending-id] {
    opacity: 0.85;
}

.chat-msg[data-pending-id]::after {
    content: '';
    position: absolute;
    top: 8px;
    right: 8px;
    width: 8px;
    height: 8px;
    background: #d29922;
    border-radius: 50%;
    animation: pendingPulse 1.5s ease-in-out infinite;
}

@keyframes pendingPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

.chat-sending {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    font-size: 13px;
    color: #58a6ff;
}

.chat-sending.visible {
    display: flex;
}
/* ========== МОДАЛКА СИСТЕМНОГО ПРОМПТА — СКРОЛЛБАР ========== */
#systemPromptModal .modal-content {
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

#systemPromptModal textarea,
#systemPromptModal [contenteditable],
#systemPromptModal .system-prompt-input {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.3) transparent;
}

#systemPromptModal textarea::-webkit-scrollbar,
#systemPromptModal [contenteditable]::-webkit-scrollbar,
#systemPromptModal .system-prompt-input::-webkit-scrollbar {
    width: 6px;
}

#systemPromptModal textarea::-webkit-scrollbar-track,
#systemPromptModal [contenteditable]::-webkit-scrollbar-track,
#systemPromptModal .system-prompt-input::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}

#systemPromptModal textarea::-webkit-scrollbar-thumb,
#systemPromptModal [contenteditable]::-webkit-scrollbar-thumb,
#systemPromptModal .system-prompt-input::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.25);
    border-radius: 3px;
}

#systemPromptModal textarea::-webkit-scrollbar-thumb:hover,
#systemPromptModal [contenteditable]::-webkit-scrollbar-thumb:hover,
#systemPromptModal .system-prompt-input::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.45);
}
/* ═══ Модалка системного промпта ═══ */
/* ТЕСТ — удалить после проверки */
#systemPromptModal {
    align-items: center !important;
    justify-content: center !important;
}

#systemPromptModal .modal-box {
    max-width: 750px !important;
    width: 90% !important;
    overflow: visible !important;
}

#systemPromptInput {
    display: block !important;
    flex: none !important;
    resize: vertical !important;
    box-sizing: border-box !important;
	min-height: 150px;
    height: 150px;
}

/* Скроллбар textarea */
#systemPromptInput {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.3) transparent;
}
#systemPromptInput::-webkit-scrollbar { width: 6px; }
#systemPromptInput::-webkit-scrollbar-track { background: transparent; }
#systemPromptInput::-webkit-scrollbar-thumb { background: rgba(139, 92, 246, 0.25); border-radius: 3px; }
#systemPromptInput::-webkit-scrollbar-thumb:hover { background: rgba(139, 92, 246, 0.45); }
/* ═══ Ошибка в чате ═══ */
.chat-error-block {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(248, 81, 73, 0.08);
    border: 1px solid rgba(248, 81, 73, 0.25);
    border-radius: 10px;
    color: #f85149;
    font-size: 13px;
    line-height: 1.5;
}

.chat-error-icon {
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

.chat-error-text {
    white-space: pre-line;
    word-break: break-word;
}
/* ═══ Retry кнопка в ошибке ═══ */
.chat-error-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 6px 14px;
    background: rgba(88,166,255,0.1);
    border: 1px solid rgba(88,166,255,0.3);
    border-radius: 8px;
    color: #58a6ff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.chat-error-retry-btn:hover {
    background: rgba(88,166,255,0.2);
    border-color: rgba(88,166,255,0.5);
}
.chat-error-retry-btn svg {
    width: 14px;
    height: 14px;
}
/* ═══ Метка прерывания в сообщении ═══ */
.chat-interrupt-mark {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin-top: 4px;
    background: rgba(210,153,34,0.08);
    border: 1px solid rgba(210,153,34,0.25);
    border-radius: 8px;
    color: #d29922;
    font-size: 12px;
    font-style: italic;
}
.chat-interrupt-mark svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}
/* ═══ Метка остановки в сообщении ═══ */
.chat-stopped-mark {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    margin-top: 4px;
    background: rgba(248,81,73,0.08);
    border: 1px solid rgba(248,81,73,0.25);
    border-radius: 8px;
    color: #f85149;
    font-size: 12px;
    font-style: italic;
}
.chat-stopped-mark svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}
/* ═══ RAG бейдж в списке чатов ═══ */
.chat-rag-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-right: 5px;
    opacity: 0.85;
}

.chat-item.rag .chat-item-title {
    display: flex;
    align-items: center;
}

/* ═══ RAG бейдж в заголовке чата ═══ */
.chat-header-rag-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 18px;
    background: rgba(88, 166, 255, 0.12);
    border: 1px solid rgba(88, 166, 255, 0.35);
    border-radius: 5px;
    color: #58a6ff;
    font-size: 11px;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    margin-right: 8px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

/* ═══ Кнопка R (новый RAG-чат) ═══ */
.btn-rag {
    background: rgba(88, 166, 255, 0.08) !important;
    border: 1px solid rgba(88, 166, 255, 0.3) !important;
    color: #58a6ff !important;
    transition: all 0.2s;
}

.btn-rag:hover {
    background: rgba(88, 166, 255, 0.18) !important;
    border-color: rgba(88, 166, 255, 0.5) !important;
    box-shadow: 0 0 8px rgba(88, 166, 255, 0.15);
}
/* ═══ ПРЕВЬЮ КАРТИНОК В ЧАТЕ — УМЕНЬШЕННЫЕ ═══ */
.chat-msg-image {
    max-width: 120px !important;
    max-height: 90px !important;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.chat-msg-image:hover {
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.15);
    transform: scale(1.03);
}

/* ═══ МОДАЛКА ПРОСМОТРА С ЗУМОМ ═══ */
.image-viewer-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 8, 18, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    overflow: hidden;
}

.image-viewer-modal.visible {
    display: flex;
}

.image-viewer-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.image-viewer-modal img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.6);
    transition: transform 0.15s ease-out;
    cursor: grab;
    user-select: none;
    -webkit-user-drag: none;
}

.image-viewer-modal img.dragging {
    cursor: grabbing;
    transition: none;
}

/* Контролы зума */
.image-viewer-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    background: rgba(22, 27, 44, 0.9);
    backdrop-filter: blur(12px);
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10001;
}

.image-viewer-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: #e6edf3;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all 0.15s;
}

.image-viewer-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
}

.image-viewer-zoom-level {
    display: flex;
    align-items: center;
    padding: 0 12px;
    font-size: 13px;
    color: #8b949e;
    min-width: 50px;
    justify-content: center;
}

/* Кнопка закрытия */
.image-viewer-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(22, 27, 44, 0.9);
    backdrop-filter: blur(12px);
    border-radius: 10px;
    color: #e6edf3;
    cursor: pointer;
    font-size: 20px;
    z-index: 10001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.image-viewer-close:hover {
    background: rgba(248, 81, 73, 0.2);
    color: #f85149;
}
/* ═══ КЛИКАБЕЛЬНЫЕ КАВЫЧКИ ═══ */
.copyable-quote {
    background: rgba(139, 92, 246, 0.08);
    padding: 1px 4px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px dashed rgba(139, 92, 246, 0.3);
}

.copyable-quote:hover {
    background: rgba(139, 92, 246, 0.15);
    border-bottom-color: rgba(139, 92, 246, 0.5);
    color: #c4b5fd;
}

.copyable-quote.copied {
    background: rgba(63, 185, 80, 0.12) !important;
    border-bottom-color: rgba(63, 185, 80, 0.4) !important;
    color: #3fb950 !important;
}
/* ═══ RAG — убрать отступы и подписи ═══ */
div.rag-system-image[style] {
    margin: 4px 0 !important;
}

div.rag-system-image > div[style*="font-size"] {
    display: none !important;
}