/* ===== БАЗОВЫЙ СТИЛЬ ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: system-ui, sans-serif; background: #0f0f12; color: #e0e0e0; transition: background 0.3s, color 0.3s; }
#app { display: flex; height: 100vh; }
#sidebar { width: 280px; background: #1c1c24; border-right: 1px solid #2a2a32; padding: 20px; display: flex; flex-direction: column; transition: background 0.3s, border-color 0.3s; }
.logo { font-size: 22px; font-weight: 700; color: #5a7bff; margin-bottom: 16px; }
#chat-list { flex: 1; overflow-y: auto; }
.empty { color: #6a6a7a; }
#user-area { margin-top: 20px; border-top: 1px solid #2a2a32; padding-top: 12px; }
#user-area a { color: #5a7bff; text-decoration: none; }
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#chat-header { padding: 16px 24px; border-bottom: 1px solid #2a2a32; display: flex; justify-content: space-between; align-items: center; transition: border-color 0.3s; }
#chat-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; }

/* ===== ПОЛЕ ВВОДА ===== */
#chat-input {
    padding: 12px 16px !important;
    gap: 12px !important;
    background: #0f0f12;
    border-top: 1px solid #2a2a32;
    display: flex;
    align-items: flex-end;
}

#chat-input textarea {
    flex: 1;
    padding: 14px 18px !important;
    border-radius: 30px !important;
    border: 1.5px solid #2a2a32 !important;
    background: #1c1c24 !important;
    color: #e0e0e0 !important;
    resize: none;
    font-family: inherit;
    font-size: 17px !important;
    min-height: 52px !important;
    max-height: 140px !important;
    overflow-y: auto;
    line-height: 1.5;
    transition: border-color 0.2s;
}

#chat-input textarea:focus {
    border-color: #5a7bff !important;
    outline: none;
}

#chat-input button {
    padding: 12px 24px !important;
    background: #5a7bff !important;
    border: none !important;
    border-radius: 30px !important;
    color: white !important;
    font-weight: 600 !important;
    cursor: pointer;
    height: 52px !important;
    flex-shrink: 0;
    align-self: flex-end;
    font-size: 20px !important;
    min-width: 56px !important;
    transition: background 0.2s;
}

#chat-input button:hover {
    background: #4a6adf !important;
}

/* ===== УБИРАЕМ СИСТЕМНУЮ ПАНЕЛЬ НАД КЛАВИАТУРОЙ (iOS) ===== */
#message-input {
    -webkit-user-select: text !important;
    user-select: text !important;
}

#message-input::-webkit-input-accessory-view {
    display: none !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

#message-input::input-accessory-view {
    display: none !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

input[type="text"]::-webkit-input-accessory-view,
input[type="search"]::-webkit-input-accessory-view,
textarea::-webkit-input-accessory-view {
    display: none !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* ===== СВЕТЛАЯ ТЕМА ДЛЯ ПОЛЯ ВВОДА ===== */
body.light #chat-input textarea {
    background: #ffffff !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
}

body.light #chat-input button {
    background: #046bd2 !important;
}
body.light #chat-input button:hover {
    background: #035aa8 !important;
}

/* ===== ТОНКИЕ СКРОЛЛЫ ===== */
#chat-list::-webkit-scrollbar,
#chat-messages::-webkit-scrollbar,
#message-input::-webkit-scrollbar {
    width: 4px;
}
#chat-list::-webkit-scrollbar-track,
#chat-messages::-webkit-scrollbar-track,
#message-input::-webkit-scrollbar-track {
    background: transparent;
}
#chat-list::-webkit-scrollbar-thumb,
#chat-messages::-webkit-scrollbar-thumb,
#message-input::-webkit-scrollbar-thumb {
    background: #3a3a4a;
    border-radius: 4px;
}
#chat-list::-webkit-scrollbar-thumb:hover,
#chat-messages::-webkit-scrollbar-thumb:hover,
#message-input::-webkit-scrollbar-thumb:hover {
    background: #5a5a6a;
}
#chat-list, #chat-messages, #message-input {
    scrollbar-width: thin;
    scrollbar-color: #3a3a4a transparent;
}

/* ===== СПИСОК ЧАТОВ ===== */
.chat-item { padding: 12px 16px; border-bottom: 1px solid #2a2a32; cursor: pointer; transition: background 0.15s; }
.chat-item:last-of-type { border-bottom: none; }
.chat-item.active { background: #2a2a32; border-left: 3px solid #5a7bff; }
.chat-item:hover { background: #1e1e26; }

.chat-item-title {
    font-weight: 700;
    font-size: 16px;
    color: #e0e0e0;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.chat-item-preview {
    font-size: 13px;
    color: #6a6a7a;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
    max-height: 2.8em;
    word-break: break-word;
}

/* ===== СООБЩЕНИЯ ===== */
.message { 
    padding: 12px 16px; 
    border-radius: 12px; 
    margin-bottom: 8px; 
    max-width: 80%; 
    word-wrap: break-word; 
    word-break: break-word;
    line-height: 1.6; 
    font-size: 15px; 
    position: relative; 
    overflow-wrap: break-word;
    hyphens: auto;
}
.user-msg { 
    background: #5a7bff; 
    color: #ffffff; 
    align-self: flex-end; 
    margin-left: auto;
}
.bot-msg { 
    background: #2a2a32; 
    color: #e0e0e0; 
    align-self: flex-start;
}
.bot-msg br { display: block; margin: 4px 0; }
.bot-msg .msg-content { 
    flex: 1;
    white-space: normal;
    word-wrap: break-word;
    word-break: break-word;
}
.user-msg .msg-content {
    white-space: normal;
    word-wrap: break-word;
    word-break: break-word;
}

/* ===== КНОПКА КОПИРОВАНИЯ ===== */
.copy-msg-btn { background: transparent; border: none; color: #6a6a7a; cursor: pointer; font-size: 14px; padding: 4px 8px; border-radius: 6px; transition: all 0.2s; flex-shrink: 0; }
.copy-msg-btn:hover { background: #3a3a4a; color: #e0e0e0; }

/* ===== РЕАКЦИЯ "CHUDO" ===== */
.chudo-reaction-btn { 
    background: transparent; 
    border: 1px solid #3a3a4a; 
    color: #6a6a7a; 
    cursor: pointer; 
    font-size: 13px; 
    padding: 4px 14px; 
    border-radius: 16px; 
    transition: all 0.2s; 
    display: inline-flex; 
    align-items: center; 
    gap: 6px;
}
.chudo-reaction-btn:hover { 
    background: #3a3a4a; 
    color: #e0e0e0; 
    border-color: #5a5a6a;
}
.chudo-reaction-btn.active { 
    background: rgba(255, 215, 0, 0.25) !important; 
    color: #f5c842 !important; 
    border-color: #f5c842 !important;
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.15) !important;
}
.chudo-reaction-btn.active:hover { 
    background: rgba(255, 215, 0, 0.35) !important; 
}

/* ===== КНОПКИ В ШАПКЕ ===== */
#chat-header button { background: transparent; border: none; cursor: pointer; font-size: 13px; padding: 6px 10px; border-radius: 6px; transition: background 0.2s, color 0.2s; color: #a0a0a0; }
#chat-header button:hover { background: #2a2a32; color: #e0e0e0; }

/* ===== НАСТРОЙКИ ===== */
.settings-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.settings-row select, .settings-row button { padding: 4px 10px; border-radius: 6px; border: 1px solid #2a2a32; background: #1c1c24; color: #e0e0e0; font-size: 12px; cursor: pointer; }
.settings-row select:focus, .settings-row button:focus { outline: none; border-color: #5a7bff; }

/* ===== СТАТИСТИКА (С ФОНОМ) ===== */
#chat-stats {
    font-size: 13px;
    font-weight: 500;
    color: #5a7bff;
    background: rgba(28, 28, 36, 0.85);
    padding: 4px 14px;
    border-radius: 20px;
    border: 1px solid #2a2a32;
    display: inline-block;
    backdrop-filter: blur(4px);
}

/* ===== КНОПКА СОЗДАНИЯ ЧАТА ===== */
#create-chat-btn { margin-top: 12px; background: #5a7bff; color: white; border: none; padding: 12px; border-radius: 8px; width: 100%; cursor: pointer; font-weight: 600; font-size: 15px; transition: background 0.2s; }
#create-chat-btn:hover { background: #4a6adf; }

/* ======================================== */
/* ===== ЗАКРЕПЛЁННОЕ СООБЩЕНИЕ ===== */
/* ======================================== */
.pinned-msg-wrapper {
    position: relative !important;
    z-index: 10 !important;
    background: rgba(15, 15, 18, 0.95);
    backdrop-filter: blur(8px);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 0;
    max-height: 15vh;
    min-height: 60px;
    overflow: hidden !important;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, 0.3)
}
.pinned-msg-wrapper.expanded {
    max-height: 85vh !important;
    min-height: 60px;
    overflow-y: auto !important;
}
.pinned-msg-wrapper .pinned-msg {
    background: transparent !important;
    border: none !important;
    border-radius: 12px !important;
    padding: 12px 14px 44px 14px !important;
    display: flex !important;
    align-items: flex-start !important;
    gap: 8px !important;
    cursor: pointer;
    max-width: 100% !important;
    width: 100% !important;
    box-sizing: border-box !important;
    overflow: visible !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
    flex-wrap: wrap !important;
}
.pinned-msg-wrapper .pinned-msg .pinned-label {
    font-size: 16px !important;
    flex-shrink: 0 !important;
    line-height: 1.4 !important;
    margin-top: 1px;
}
.pinned-msg-wrapper .pinned-msg .msg-content {
    font-size: 14px !important;
    line-height: 1.6 !important;
    max-height: none !important;
    overflow: visible !important;
    text-overflow: unset !important;
    -webkit-line-clamp: unset !important;
    display: block !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    word-break: break-word !important;
    flex: 1;
    min-width: 0;
    max-width: 100%;
    color: #e0e0e0;
    white-space: pre-wrap !important;
}
.pinned-msg-wrapper .pinned-msg .msg-content br {
    display: block;
    content: "";
    margin: 4px 0;
}
.pinned-msg-wrapper .pinned-msg .msg-content .img-wrap {
    display: inline-block !important;
    margin: 2px;
    width: 70px;
    height: 70px;
    vertical-align: top;
    overflow: hidden;
    border-radius: 8px;
    flex-shrink: 0;
}
.pinned-msg-wrapper .pinned-msg .msg-content .img-wrap img {
    width: 70px !important;
    height: 70px !important;
    min-width: 70px !important;
    min-height: 70px !important;
    max-width: 70px !important;
    max-height: 70px !important;
    object-fit: cover !important;
    display: block;
}
.pinned-msg-wrapper .pinned-msg .msg-content iframe {
    max-width: 100% !important;
    max-height: 150px !important;
    border-radius: 8px;
}
.pinned-msg-wrapper .pinned-msg .msg-content a {
    color: #5a7bff !important;
    text-decoration: underline !important;
    word-break: break-all !important;
    display: inline-block;
    max-width: 100%;
}
.pinned-msg-wrapper .pinned-msg .msg-content a:hover {
    color: #7a9bff !important;
}
.pinned-toggle-btn {
    position: absolute !important;
    bottom: 6px !important;
    right: 10px !important;
    background: rgba(30, 30, 40, 0.9) !important;
    backdrop-filter: blur(8px) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    border-radius: 50% !important;
    width: 32px !important;
    height: 32px !important;
    color: #a0a0a0 !important;
    font-size: 14px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 15 !important;
    transition: all 0.25s ease !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4) !important;
    padding: 0 !important;
    line-height: 1 !important;
}
.pinned-toggle-btn:hover {
    background: rgba(60, 60, 80, 0.95) !important;
    transform: scale(1.05) !important;
    color: #e0e0e0 !important;
}
.pinned-toggle-btn .arrow {
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1) !important;
    display: inline-block !important;
    font-size: 12px !important;
}
.pinned-toggle-btn .arrow.down {
    transform: rotate(0deg) !important;
}
.pinned-toggle-btn .arrow.up {
    transform: rotate(180deg) !important;
}

body.light .pinned-msg-wrapper {
    background: rgba(255, 255, 255, 0.95) !important;
    border: 2px solid rgba(4, 107, 210, 0.7) !important;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06) !important;
}
body.light .pinned-msg-wrapper .pinned-msg .msg-content {
    color: #1e293b !important;
}
body.light .pinned-toggle-btn {
    background: rgba(255, 255, 255, 0.92) !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    color: #64748b !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}
body.light .pinned-toggle-btn:hover {
    background: #ffffff !important;
    color: #0f172a !important;
}
body.dark .pinned-msg-wrapper {
    border: 2px solid rgba(255, 255, 255, 0.3) !important;
}
body.dark .pinned-msg-wrapper .pinned-msg .msg-content {
    color: #e0e0e0 !important;
}

/* ======================================== */
/* ===== МОБИЛЬНЫЕ УСТРОЙСТВА ===== */
/* ======================================== */
@media (max-width: 768px) {
    .pinned-msg-wrapper {
        max-height: 12vh !important;
        min-height: 50px !important;
       border: 2px solid rgba(255, 255, 255, 0.3) !important;
    }
    .pinned-msg-wrapper.expanded {
        max-height: 80vh !important;
        min-height: 50px !important;
        overflow-y: auto !important;
    }
    .pinned-msg-wrapper .pinned-msg {
        padding: 10px 12px 40px 12px !important;
    }
    .pinned-msg-wrapper .pinned-msg .msg-content .img-wrap {
        width: 55px !important;
        height: 55px !important;
    }
    .pinned-msg-wrapper .pinned-msg .msg-content .img-wrap img {
        width: 55px !important;
        height: 55px !important;
        min-width: 55px !important;
        min-height: 55px !important;
        max-width: 55px !important;
        max-height: 55px !important;
    }
    .pinned-toggle-btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 12px !important;
        bottom: 4px !important;
        right: 8px !important;
    }
    body.light .pinned-msg-wrapper {
        border: 2px solid rgba(4, 107, 210, 0.7) !important;
    }
}

@media (max-width: 420px) {
    .pinned-msg-wrapper {
        max-height: 10vh !important;
        min-height: 44px !important;
        border: 2px solid rgba(255, 255, 255, 0.3) !important;
    }
    .pinned-msg-wrapper.expanded {
        max-height: 75vh !important;
        min-height: 44px !important;
        overflow-y: auto !important;
    }
    .pinned-msg-wrapper .pinned-msg {
        padding: 8px 10px 36px 10px !important;
    }
    .pinned-msg-wrapper .pinned-msg .msg-content .img-wrap {
        width: 45px !important;
        height: 45px !important;
    }
    .pinned-msg-wrapper .pinned-msg .msg-content .img-wrap img {
        width: 45px !important;
        height: 45px !important;
        min-width: 45px !important;
        min-height: 45px !important;
        max-width: 45px !important;
        max-height: 45px !important;
    }
    .pinned-toggle-btn {
        width: 24px !important;
        height: 24px !important;
        font-size: 10px !important;
        bottom: 3px !important;
        right: 6px !important;
    }
    body.light .pinned-msg-wrapper {
        border: 2px solid rgba(4, 107, 210, 0.75) !important;
    }
}

/* ======================================== */
/* ===== СВЕТЛАЯ ТЕМА ===== */
/* ======================================== */
body.light { background: #f0f4f8; color: #1e293b; }
body.light #sidebar { background: #ffffff; border-color: #e2e8f0; }
body.light #chat-header { background: #ffffff !important; border-color: #e2e8f0 !important; }
body.light #chat-title { color: #0f172a; font-weight: 700; font-size: 18px; }
body.light #chat-input { background: #ffffff !important; border-color: #e2e8f0 !important; }
body.light #chat-input textarea { background: #ffffff !important; border-color: #e2e8f0 !important; color: #1e293b !important; }
body.light #chat-messages { background: #f8fafc !important; }
body.light .chat-item { border-color: #e2e8f0; }
body.light .chat-item-title { color: #0f172a; }
body.light .chat-item-preview { color: #64748b; }
body.light .chat-item.active { background: #e0f2fe; border-left-color: #046bd2; }
body.light .chat-item:hover { background: #f1f5f9; }
body.light .bot-msg { background: #ffffff !important; color: #1e293b !important; border: 1px solid #e2e8f0 !important; }
body.light .user-msg { background: #046bd2; color: #ffffff; }
body.light #chat-header button { color: #64748b; }
body.light #chat-header button:hover { background: #e2e8f0; color: #1e293b; }
body.light .settings-row select, body.light .settings-row button { background: #ffffff; border-color: #e2e8f0; color: #1e293b; }
body.light #chat-stats { background: #e0f2fe !important; color: #046bd2 !important; border-color: #b9d9f0 !important; }
body.light #create-chat-btn { background: #046bd2; }
body.light #create-chat-btn:hover { background: #035aa8; }

body.light .chudo-reaction-btn { color: #94a3b8; border-color: #e2e8f0; }
body.light .chudo-reaction-btn:hover { background: #f1f5f9; color: #1e293b; border-color: #cbd5e1; }
body.light .chudo-reaction-btn.active { background: rgba(255, 215, 0, 0.2) !important; color: #d4a800 !important; border-color: #d4a800 !important; }
body.light .copy-msg-btn { color: #94a3b8; }
body.light .copy-msg-btn:hover { background: #f1f5f9; color: #1e293b; }

body.light #chat-list::-webkit-scrollbar-thumb,
body.light #chat-messages::-webkit-scrollbar-thumb,
body.light #message-input::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}
body.light #chat-list::-webkit-scrollbar-thumb:hover,
body.light #chat-messages::-webkit-scrollbar-thumb:hover,
body.light #message-input::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
body.light #chat-list, body.light #chat-messages, body.light #message-input {
    scrollbar-color: #cbd5e1 transparent;
}

/* ======================================== */
/* ===== ТОНКИЕ КРАСИВЫЕ СКРОЛЛЫ ===== */
/* ======================================== */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #3a3a4a;
    border-radius: 10px;
    transition: background 0.2s ease;
}
::-webkit-scrollbar-thumb:hover {
    background: #5a5a6a;
}
* {
    scrollbar-width: thin;
    scrollbar-color: #3a3a4a transparent;
}

body.light ::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}
body.light ::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
body.light * {
    scrollbar-color: #cbd5e1 transparent;
}

#message-input::-webkit-scrollbar {
    width: 4px;
}
#message-input::-webkit-scrollbar-thumb {
    background: #3a3a4a;
    border-radius: 10px;
}
body.light #message-input::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}

#chat-list::-webkit-scrollbar {
    width: 4px;
}
#chat-list::-webkit-scrollbar-thumb {
    background: #3a3a4a;
    border-radius: 10px;
}
body.light #chat-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}

/* ======================================== */
/* ===== ПОДАВЛЯЕМ СИСТЕМНУЮ СТРЕЛКУ ===== */
/* ======================================== */
textarea:focus {
    -webkit-appearance: none !important;
    appearance: none !important;
    outline: none !important;
}
input:focus {
    -webkit-appearance: none !important;
    appearance: none !important;
    outline: none !important;
}
input, textarea {
    -webkit-user-select: auto !important;
    user-select: auto !important;
}
textarea::-webkit-search-decoration,
input::-webkit-search-decoration,
textarea::-webkit-search-cancel-button,
input::-webkit-search-cancel-button,
textarea::-webkit-search-results-button,
input::-webkit-search-results-button,
textarea::-webkit-search-results-decoration,
input::-webkit-search-results-decoration {
    -webkit-appearance: none !important;
    display: none !important;
}
textarea::-webkit-contacts-auto-fill-button,
input::-webkit-contacts-auto-fill-button {
    visibility: hidden !important;
    display: none !important;
    pointer-events: none !important;
    position: absolute !important;
    right: 0 !important;
}

/* ===== ПЕРЕКЛЮЧАТЕЛЬ ЧАТОВ ===== */
.chat-filter .filter-btn {
    transition: all 0.2s ease;
}
.chat-filter .filter-btn:hover {
    opacity: 0.8;
}
.chat-filter .filter-btn.active {
    background: #5a7bff !important;
    color: #fff !important;
}
body.light .chat-filter {
    background: #e2e8f0 !important;
}
body.light .chat-filter .filter-btn {
    color: #64748b;
}
body.light .chat-filter .filter-btn.active {
    background: #046bd2 !important;
    color: #fff !important;
}

/* ===== ТАРИФЫ ===== */
.tariffs-container .tariff-pay-btn:hover {
    opacity: 0.85;
    transform: translateY(-1px);
    transition: all 0.2s;
}
@media (max-width: 768px) {
    .tariffs-container {
        padding: 12px 8px !important;
    }
    .tariffs-container h1 {
        font-size: 22px !important;
    }
    .tariffs-container .tariff-pay-btn {
        font-size: 14px !important;
        padding: 12px !important;
    }
}

/* ======================================== */
/* ===== МОБИЛЬНЫЕ АДАПТАЦИИ ===== */
/* ======================================== */
@media (max-width: 768px) {
    #chat-input {
        padding: 10px 12px !important;
        padding-bottom: 14px !important;
        gap: 10px !important;
    }
    #chat-input textarea {
        padding: 12px 16px !important;
        font-size: 16px !important;
        min-height: 48px !important;
        max-height: 120px !important;
        border-radius: 24px !important;
    }
    #chat-input button {
        height: 48px !important;
        padding: 10px 20px !important;
        font-size: 18px !important;
        min-width: 50px !important;
        border-radius: 24px !important;
    }
}

@media (max-width: 420px) {
    #chat-input {
        padding: 8px 10px !important;
        padding-bottom: 12px !important;
        gap: 8px !important;
    }
    #chat-input textarea {
        padding: 10px 14px !important;
        font-size: 15px !important;
        min-height: 44px !important;
        max-height: 100px !important;
        border-radius: 22px !important;
    }
    #chat-input button {
        height: 44px !important;
        padding: 8px 16px !important;
        font-size: 16px !important;
        min-width: 44px !important;
        border-radius: 22px !important;
    }
}

@media (max-width: 360px) {
    #chat-input {
        padding: 6px 8px !important;
        padding-bottom: 10px !important;
        gap: 6px !important;
    }
    #chat-input textarea {
        padding: 8px 12px !important;
        font-size: 14px !important;
        min-height: 38px !important;
        max-height: 80px !important;
        border-radius: 18px !important;
    }
    #chat-input button {
        height: 38px !important;
        padding: 6px 12px !important;
        font-size: 14px !important;
        min-width: 38px !important;
        border-radius: 18px !important;
    }
}

/* ======================================== */
/* ===== MARKDOWN-СТИЛИ ДЛЯ ОТВЕТОВ ИИ ===== */
/* ======================================== */

.msg-content .md-p {
    margin: 0 0 10px 0;
    line-height: 1.65;
}
.msg-content .md-p:last-child {
    margin-bottom: 0;
}

.msg-content strong {
    font-weight: 700;
    color: #ffffff;
}

.msg-content em {
    font-style: italic;
    color: #d0d0d8;
}

.msg-content .md-ul {
    list-style: none;
    padding-left: 4px;
    margin: 8px 0 10px 0;
    white-space: normal;
}
.msg-content .md-ul li {
    position: relative;
    padding-left: 18px;
    margin-bottom: 2px;
    line-height: 1.55;
    white-space: normal;
    display: block;
}
.msg-content .md-ul li::before {
    content: "•";
    position: absolute;
    left: 2px;
    top: 0;
    color: #5a7bff;
    font-weight: 700;
    font-size: 15px;
}

.msg-content .md-ol {
    list-style: none;
    padding-left: 4px;
    margin: 8px 0 10px 0;
    counter-reset: md-counter;
    white-space: normal;
}
.msg-content .md-ol li {
    position: relative;
    padding-left: 26px;
    margin-bottom: 2px;
    line-height: 1.55;
    counter-increment: md-counter;
    white-space: normal;
    display: block;
}
.msg-content .md-ol li::before {
    content: counter(md-counter) ".";
    position: absolute;
    left: 4px;
    top: 0;
    color: #5a7bff;
    font-weight: 700;
    font-size: 14px;
    min-width: 18px;
}

.msg-content .md-blockquote {
    border-left: 3px solid #5a7bff;
    background: rgba(90, 123, 255, 0.06);
    padding: 8px 12px;
    margin: 10px 0;
    border-radius: 0 8px 8px 0;
    color: #c8c8d0;
    font-style: italic;
    font-size: 14.5px;
    line-height: 1.6;
}

.msg-content .md-hr {
    border: none;
    border-top: 1px solid #2a2a32;
    margin: 14px 0;
}

.msg-content .md-code-block {
    background: #0a0a0e;
    border: 1px solid #2a2a32;
    border-radius: 8px;
    margin: 10px 0;
    overflow: hidden;
    font-family: 'SF Mono', 'Monaco', 'Consolas', 'Courier New', monospace;
}

.msg-content .md-code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: #16161c;
    border-bottom: 1px solid #2a2a32;
}

.msg-content .md-code-lang {
    color: #6a6a7a;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.msg-content .md-code-copy {
    background: transparent;
    border: none;
    color: #6a6a7a;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    line-height: 1;
}
.msg-content .md-code-copy:hover {
    background: #2a2a32;
    color: #e0e0e0;
}

.msg-content .md-code-pre {
    margin: 0;
    padding: 12px 14px;
    overflow-x: auto;
    color: #e0e0e0;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre;
    font-family: inherit;
}

.msg-content .md-code-pre code {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: transparent;
    padding: 0;
    white-space: pre;
}

.msg-content .md-code-pre::-webkit-scrollbar {
    height: 6px;
}
.msg-content .md-code-pre::-webkit-scrollbar-thumb {
    background: #3a3a4a;
    border-radius: 3px;
}

body.light .msg-content strong {
    color: #0f172a;
}
body.light .msg-content em {
    color: #475569;
}
body.light .msg-content .md-ul li::before,
body.light .msg-content .md-ol li::before {
    color: #046bd2;
}
body.light .msg-content .md-blockquote {
    border-left-color: #046bd2;
    background: rgba(4, 107, 210, 0.05);
    color: #475569;
}
body.light .msg-content .md-hr {
    border-top-color: #e2e8f0;
}
body.light .msg-content .md-code-block {
    background: #f8fafc;
    border-color: #e2e8f0;
}
body.light .msg-content .md-code-header {
    background: #f1f5f9;
    border-bottom-color: #e2e8f0;
}
body.light .msg-content .md-code-lang {
    color: #64748b;
}
body.light .msg-content .md-code-copy {
    color: #64748b;
}
body.light .msg-content .md-code-copy:hover {
    background: #e2e8f0;
    color: #0f172a;
}
body.light .msg-content .md-code-pre {
    color: #1e293b;
}
body.light .msg-content .md-code-pre::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}

@media (max-width: 768px) {
    .msg-content .md-code-pre {
        font-size: 12px;
        padding: 10px 12px;
    }
    .msg-content .md-blockquote {
        font-size: 14px;
        padding: 6px 10px;
    }
    .msg-content .md-ul li,
    .msg-content .md-ol li {
        font-size: 15px;
    }
}

@media (max-width: 420px) {
    .msg-content .md-code-pre {
        font-size: 11.5px;
        padding: 8px 10px;
    }
    .msg-content .md-code-header {
        padding: 5px 10px;
    }
    .msg-content .md-code-lang {
        font-size: 10px;
    }
    .msg-content .md-blockquote {
        font-size: 13.5px;
    }
}

.md-code-block {
    position: relative;
    z-index: 1;
}
.md-code-copy {
    position: relative;
    z-index: 10;
    pointer-events: auto !important;
}
.md-code-header {
    position: relative;
    z-index: 2;
}

/* ===== ССЫЛКИ В ПОЛЬЗОВАТЕЛЬСКИХ СООБЩЕНИЯХ ===== */
.user-msg a,
.user-msg .msg-content a {
    color: #ffffff !important;
    text-decoration: underline !important;
    word-break: break-all;
}
.user-msg a:hover,
.user-msg .msg-content a:hover {
    color: #e0e0ff !important;
}

body.light .user-msg a,
body.light .user-msg .msg-content a {
    color: #ffffff !important;
}
body.light .user-msg a:hover,
body.light .user-msg .msg-content a:hover {
    color: #e0f2fe !important;
}

/* ======================================== */
/* ===== КАРТОЧКА ССЫЛКИ ===== */
/* ======================================== */
.link-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0 10px 0;
    padding: 8px 12px;
    background: #1c1c24;
    border: 1px solid #2a2a32;
    border-radius: 10px;
    text-decoration: none !important;
    transition: all 0.2s ease;
    max-width: 100%;
    word-break: break-all;
    vertical-align: middle;
}

.link-card:hover {
    background: #24242e;
    border-color: #5a7bff;
    transform: translateY(-1px);
}

.link-card-favicon {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
    background: #2a2a32;
    object-fit: contain;
}

.link-card-domain {
    color: #e0e0e0;
    font-size: 13px;
    font-weight: 500;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-card-arrow {
    color: #6a6a7a;
    font-size: 12px;
    flex-shrink: 0;
    transition: color 0.2s;
}

.link-card:hover .link-card-arrow {
    color: #5a7bff;
}

.user-msg .msg-content a,
.user-msg a {
    color: #ffffff !important;
    text-decoration: underline !important;
    word-break: break-all;
}

.user-msg .link-card {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
}
.user-msg .link-card:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}
.user-msg .link-card-domain {
    color: #ffffff;
}
.user-msg .link-card-arrow {
    color: rgba(255, 255, 255, 0.6);
}

body.light .link-card {
    background: #ffffff;
    border-color: #e2e8f0;
}
body.light .link-card:hover {
    background: #f8fafc;
    border-color: #046bd2;
}
body.light .link-card-domain {
    color: #0f172a;
}
body.light .link-card-arrow {
    color: #94a3b8;
}
body.light .link-card:hover .link-card-arrow {
    color: #046bd2;
}
body.light .user-msg .link-card {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
}
body.light .user-msg .link-card-domain {
    color: #ffffff;
}

@media (max-width: 480px) {
    .link-card {
        padding: 6px 10px;
        gap: 6px;
        margin: 4px 0 8px 0;
    }
    .link-card-favicon {
        width: 16px;
        height: 16px;
    }
    .link-card-domain {
        font-size: 12px;
    }
}

.msg-link {
    color: #5a7bff;
    text-decoration: underline;
    word-break: break-all;
}
.msg-link:hover {
    color: #7a9bff;
}

.user-msg .msg-link {
    color: #ffffff !important;
}
.user-msg .msg-link:hover {
    color: #e0e0ff !important;
}

body.light .msg-link {
    color: #046bd2;
}
body.light .msg-link:hover {
    color: #035aa8;
}
body.light .user-msg .msg-link {
    color: #ffffff !important;
}

.link-card-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}
/* ===== МОБИЛЬНЫЙ КАРКАС (#app) ===== */
@media (max-width: 768px) {
    #app {
        height: 96vh;
        max-height: 96vh;
    }
}
/* ======================================== */
/* ===== ПОИСК ЧАТОВ ===== */
/* ======================================== */
#chat-search-wrapper {
    position: relative;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    background: #1c1c24;
    border: 1px solid #2a2a32;
    border-radius: 10px;
    padding: 0 12px;
    transition: border-color 0.2s;
}
#chat-search-wrapper:focus-within {
    border-color: #5a7bff;
}
.chat-search-icon {
    font-size: 14px;
    color: #6a6a7a;
    margin-right: 8px;
    flex-shrink: 0;
}
#chat-search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #e0e0e0;
    font-size: 14px;
    padding: 10px 0;
    font-family: inherit;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}
#chat-search-input::placeholder {
    color: #6a6a7a;
}
.chat-search-clear {
    display: none;
    background: transparent;
    border: none;
    color: #6a6a7a;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    flex-shrink: 0;
    border-radius: 4px;
    transition: all 0.15s;
}
.chat-search-clear:hover {
    background: #2a2a32;
    color: #e0e0e0;
}
.chat-search-clear.visible {
    display: block;
}

.chat-search-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6a6a7a;
    padding: 12px 4px 6px;
    margin-top: 4px;
    border-top: 1px solid #2a2a32;
}

.chat-search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}
.chat-search-item:hover {
    background: #24242e;
}
.chat-search-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #ffffff;
    flex-shrink: 0;
    text-transform: uppercase;
}
.chat-search-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.chat-search-title {
    font-weight: 600;
    font-size: 14px;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-search-slug {
    font-size: 12px;
    color: #6a6a7a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-search-stats {
    font-size: 11px;
    color: #8a8a9a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}
.chat-search-empty {
    color: #6a6a7a;
    text-align: center;
    padding: 20px;
    font-size: 13px;
}

body.light #chat-search-wrapper {
    background: #ffffff;
    border-color: #e2e8f0;
}
body.light #chat-search-wrapper:focus-within {
    border-color: #046bd2;
}
body.light #chat-search-input {
    color: #1e293b;
}
body.light .chat-search-section-title {
    color: #94a3b8;
    border-top-color: #e2e8f0;
}
body.light .chat-search-item:hover {
    background: #f1f5f9;
}
body.light .chat-search-title {
    color: #0f172a;
}
body.light .chat-search-slug {
    color: #64748b;
}
body.light .chat-search-stats {
    color: #94a3b8;
}
body.light .chat-search-empty {
    color: #64748b;
}
/* ======================================== */
/* ===== ЛОГОТИП ЧАТА (avatar) ===== */
/* ======================================== */

/* Общий контейнер аватара — круглый */
.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #ffffff;
    text-transform: uppercase;
    background: #5a7bff;
    user-select: none;
    -webkit-user-select: none;
}
.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Аватар в шапке чата */
.chat-avatar-header {
    width: 36px;
    height: 36px;
    font-size: 15px;
}
@media (max-width: 768px) {
    .chat-avatar-header {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
}
@media (max-width: 420px) {
    .chat-avatar-header {
        width: 28px;
        height: 28px;
        font-size: 13px;
    }
}

/* Аватар в списке чатов (сайдбар) */
.chat-item {
    display: flex !important;
    align-items: center;
    gap: 10px;
}
.chat-item-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Превью логотипа в модалке */
#chat-logo-preview {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    background: #2a2a32;
    border: 2px solid #2a2a32;
    display: block;
    flex-shrink: 0;
}
#chat-logo-preview.error {
    border-color: #ff4444;
}
body.light #chat-logo-preview {
    background: #f1f5f9;
    border-color: #e2e8f0;
}
body.light #chat-logo-preview.error {
    border-color: #ef4444;
}

/* Обёртка превью + поле */
.chat-logo-row {
    display: flex;
    align-items: center;
    gap: 12px;
}
.chat-logo-row .chat-logo-input-wrap {
    flex: 1;
    min-width: 0;
}

/* ===== Мобильные адаптации ===== */
@media (max-width: 480px) {
    #chat-logo-preview {
        width: 52px;
        height: 52px;
    }
}
/* ======================================== */
/* ===== ЛОГОТИП ЧАТА (avatar) — v3 ===== */
/* ======================================== */

/* Аватары: буква/эмодзи — по центру через flex, img — на весь контейнер */
.chat-avatar,
.chat-avatar-header,
.chat-search-avatar {
    overflow: hidden;
    text-align: center;
    line-height: 1;
}

.chat-avatar > span,
.chat-avatar-header > span,
.chat-search-avatar > span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    user-select: none;
    -webkit-user-select: none;
}

.chat-avatar > img,
.chat-avatar-header > img,
.chat-search-avatar > img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}