/* =========================================================
   VENUS — CHAT PAGE (совместим с текущим chat.html)
   ========================================================= */

.chat-page,
.chat-page * { box-sizing: border-box; }

.chat-page {
    width: 100%;
    min-height: calc(100vh - 110px);
    padding: 34px 24px 70px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background:
        radial-gradient(circle at 8% 8%, rgba(112,76,255,.17), transparent 27%),
        radial-gradient(circle at 92% 85%, rgba(147,92,255,.12), transparent 28%),
        #0d0a1b;
}

.chat-container {
    width: min(1120px, 100%);
    min-width: 0;
    min-height: 740px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #eeeaff;
    background: linear-gradient(145deg, #19142d, #130f24 72%);
    border: 1px solid #35295f;
    border-radius: 24px;
    box-shadow: 0 24px 70px rgba(0,0,0,.36), 0 0 45px rgba(112,76,255,.07);
}

.chat-header {
    min-height: 112px;
    padding: 24px 30px;
    display: flex;
    align-items: center;
    gap: 17px;
    border-bottom: 1px solid rgba(151,115,255,.2);
    background: linear-gradient(120deg, rgba(112,76,255,.13), rgba(24,18,45,.2));
}

.ai-avatar {
    position: relative;
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(190,169,255,.35);
    border-radius: 17px;
    color: white;
    font-size: 27px;
    background: linear-gradient(135deg, #7955ff, #5231c9);
    box-shadow: 0 9px 25px rgba(93,58,220,.3);
}
.avatar-glow {
    position: absolute;
    inset: -5px;
    z-index: 0;
    border-radius: 20px;
    border: 1px solid rgba(151,115,255,.2);
    pointer-events: none;
}
.chat-title { min-width: 0; }
.chat-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.chat-title h1 { margin: 0; color: #f7f3ff; font-size: clamp(21px, 2.4vw, 27px); line-height: 1.25; font-weight: 800; }
.chat-title p { margin: 8px 0 0; color: #aaa1cb; font-size: 14px; line-height: 1.55; }
.online-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 11px;
    border: 1px solid rgba(49,209,128,.2);
    border-radius: 30px;
    color: #8af0b8;
    background: rgba(24,166,91,.12);
    font-size: 11px;
    font-weight: 700;
}
.online-status i { width: 7px; height: 7px; display: block; border-radius: 50%; background: #35d887; box-shadow: 0 0 10px rgba(53,216,135,.65); }

.chat-messages {
    flex: 1 1 auto;
    min-height: 430px;
    max-height: 620px;
    padding: 28px 30px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-x: hidden;
    overflow-y: auto;
    scroll-behavior: smooth;
    background: linear-gradient(180deg, rgba(18,14,34,.12), rgba(20,15,39,.5));
}
.chat-message { display: flex; align-items: flex-start; gap: 11px; max-width: 88%; min-width: 0; }
.ai-message { align-self: flex-start; }
.user-message { align-self: flex-end; justify-content: flex-end; max-width: 76%; }
.message-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    color: #fff;
    background: linear-gradient(135deg, #7955ff, #5231c9);
    box-shadow: 0 6px 16px rgba(92,58,220,.24);
}
.message-content { min-width: 0; max-width: 100%; }
.message-name { margin: 0 0 6px 3px; color: #a99bcf; font-size: 11px; font-weight: 700; }
.message-bubble {
    max-width: 100%;
    padding: 14px 17px;
    border: 1px solid #40336b;
    border-radius: 4px 16px 16px 16px;
    color: #eeeaff;
    background: linear-gradient(135deg, #251d43, #1d1735);
    box-shadow: 0 7px 20px rgba(0,0,0,.16);
    font-size: 14px;
    line-height: 1.7;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.user-message .message-bubble {
    border: 1px solid rgba(174,151,255,.22);
    border-radius: 16px 16px 4px 16px;
    color: #fff;
    background: linear-gradient(135deg, #7650f5, #5935d4);
}

/* Индикатор из старой HTML-разметки не используется: chat-history.js
   создаёт строку "ИИ думает..." прямо внутри .chat-messages. */
.typing-indicator { display: none !important; }
.typing-avatar { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 32px; border-radius: 10px; background: #6845e7; color: white; }
.typing-bubble { display: flex; align-items: center; gap: 5px; padding: 10px 13px; border: 1px solid #40336b; border-radius: 13px; background: #211a3a; }
.typing-bubble span { width: 6px; height: 6px; border-radius: 50%; background: #a991ff; animation: venusTyping 1s infinite ease-in-out; }
.typing-bubble span:nth-child(2) { animation-delay: .15s; }
.typing-bubble span:nth-child(3) { animation-delay: .3s; }
.typing-bubble em { margin-left: 6px; color: #b5a9d8; font-size: 11px; font-style: normal; }
@keyframes venusTyping { 0%, 60%, 100% { transform: translateY(0); opacity: .55; } 30% { transform: translateY(-4px); opacity: 1; } }

.quick-questions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
    padding: 15px 24px;
    border-top: 1px solid rgba(151,115,255,.17);
    border-bottom: 1px solid rgba(151,115,255,.17);
    background: rgba(15,11,29,.55);
}
.quick-questions button {
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid #463775;
    border-radius: 30px;
    color: #d9ceff;
    background: #211a3b;
    font: inherit;
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    transition: .2s ease;
}
.quick-questions button:hover { transform: translateY(-2px); border-color: #8b6aff; background: #302451; }

.chat-input-area { display: flex; align-items: flex-end; gap: 12px; padding: 18px 24px 12px; background: #151127; }
.input-wrapper { flex: 1 1 auto; min-width: 0; }
#chatText {
    display: block;
    width: 100%;
    min-height: 58px;
    max-height: 160px;
    resize: vertical;
    padding: 15px 17px;
    border: 1px solid #493a79;
    border-radius: 14px;
    outline: none;
    color: #f2edff;
    background: #201936;
    font: inherit;
    font-size: 14px;
    line-height: 1.5;
    transition: border-color .2s, box-shadow .2s;
}
#chatText::placeholder { color: #9186b2; }
#chatText:focus { border-color: #8b6aff; box-shadow: 0 0 0 3px rgba(112,76,255,.16); }
#chatText:disabled { opacity: .65; }
.input-bottom { display: flex; justify-content: space-between; gap: 10px; padding: 6px 4px 0; }
.char-counter { color: #81769f; font-size: 10px; }
.secure-text { color: #9c8fc2; font-size: 10px; }
.send-button {
    min-height: 56px;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 20px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #7955ff, #5935d4);
    box-shadow: 0 8px 20px rgba(89,58,222,.25);
    font: inherit;
    font-size: 13px;
    font-weight: 750;
    cursor: pointer;
    transition: .2s ease;
}
.send-button:hover { transform: translateY(-2px); box-shadow: 0 11px 25px rgba(89,58,222,.34); }
.send-button:disabled { opacity: .55; cursor: wait; transform: none; }
.send-icon { font-size: 17px; }
.chat-disclaimer { padding: 0 24px 19px; text-align: center; color: #82799f; background: #151127; font-size: 10px; line-height: 1.5; }
.chat-disclaimer span { margin-right: 5px; color: #a88dff; }

/* Светлая тема — если переключатель снимает тёмный класс */
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-page {
    background: radial-gradient(circle at 8% 8%, rgba(112,76,255,.10), transparent 27%), #f4f1ff;
}
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-container { color: #33406a; background: #fff; border-color: #e3ddff; box-shadow: 0 20px 55px rgba(76,54,180,.12); }
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-header { background: linear-gradient(120deg,#faf8ff,#fff); border-color: #ebe6ff; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-title h1 { color: #19285f; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-title p { color: #858eaf; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-messages { background: linear-gradient(180deg,#faf9ff,#fff); }
body:not(.dark):not(.dark-theme):not(.dark-mode) .message-bubble { color: #33436e; background: #fff; border-color: #e9e5f8; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .message-name { color: #7a85a8; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .quick-questions,
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-input-area,
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-disclaimer { background: #fff; border-color: #eeeaff; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .quick-questions button { color: #5d43d8; background: #faf9ff; border-color: #ded7ff; }
body:not(.dark):not(.dark-theme):not(.dark-mode) #chatText { color: #293764; background: #fff; border-color: #dcd5ff; }
body:not(.dark):not(.dark-theme):not(.dark-mode) .chat-disclaimer { color: #929ab3; }

@media (max-width: 760px) {
    .chat-page { min-height: 0; padding: 22px 12px 42px; }
    .chat-container { min-height: 680px; border-radius: 18px; }
    .chat-header { padding: 19px; min-height: 96px; }
    .ai-avatar { width: 48px; height: 48px; flex-basis: 48px; border-radius: 14px; }
    .chat-title p { font-size: 12px; }
    .chat-messages { min-height: 360px; max-height: 62vh; padding: 20px 16px; }
    .chat-message { max-width: 96%; }
    .user-message { max-width: 88%; }
    .quick-questions { padding: 12px; }
    .chat-input-area { padding: 13px; }
    .send-button { padding: 0 15px; }
}
@media (max-width: 500px) {
    .chat-page { padding: 14px 8px 30px; }
    .chat-header { gap: 11px; padding: 16px 13px; }
    .ai-avatar { width: 42px; height: 42px; flex-basis: 42px; font-size: 22px; }
    .chat-title h1 { font-size: 18px; }
    .online-status { display: none; }
    .chat-messages { min-height: 330px; padding: 16px 12px; }
    .chat-input-area { flex-direction: column; align-items: stretch; }
    .send-button { width: 100%; min-height: 48px; }
    .quick-questions button { font-size: 11px; }
}


/* FINAL OVERRIDES: neutralize global site rules that stretch message bubbles */
.chat-page .chat-messages .chat-message,
.chat-page .chat-messages .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
}
.chat-page .chat-messages .chat-message {
    flex-direction: row;
    align-items: flex-start;
}
.chat-page .chat-messages .message-content {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    max-width: min(680px, 100%);
}
.chat-page .chat-messages .message-bubble {
    display: block !important;
    position: static !important;
    width: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    max-height: none !important;
    flex: 0 0 auto !important;
    align-self: flex-start !important;
    justify-content: initial !important;
    text-align: left !important;
    white-space: pre-wrap;
    line-height: 1.7;
}
.chat-page .chat-messages .ai-message .message-bubble { max-width: 680px; }
.chat-page .chat-messages .user-message { align-self: flex-end; }
.chat-page .chat-messages .user-message .message-content { align-items: flex-end; }
.chat-page .chat-messages .user-message .message-bubble { align-self: flex-end !important; }
.chat-history-controls { display:flex; align-items:center; flex-wrap:wrap; gap:10px; padding:12px 20px; border-bottom:1px solid rgba(151,115,255,.18); background:rgba(16,12,31,.45); }
.chat-history-select, .chat-history-button { min-height:38px; border:1px solid rgba(139,92,246,.42); border-radius:11px; padding:8px 12px; color:#eee9ff; background:#1b1530; font:inherit; font-size:13px; }
.chat-history-select { flex:1 1 220px; min-width:180px; max-width:100%; }
.chat-history-button { cursor:pointer; font-weight:700; transition:background .2s,border-color .2s,transform .2s; }
.chat-history-button:hover { background:#302052; border-color:#8b5cf6; transform:translateY(-1px); }
.chat-history-hint { flex-basis:100%; color:#a99dc9; font-size:11px; }
.chat-history-select[hidden] { display:none !important; }
@media(max-width:600px) { .chat-history-controls {padding:10px;gap:7px;} .chat-history-button {flex:1 1 auto;} }


/* =========================================================
   FINAL FIX — нормальные компактные сообщения без растяжения
   ========================================================= */

/* Сообщения располагаются сверху вниз, без распределения по высоте */
.chat-page .chat-container #chatMessages {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 14px !important;
    min-height: 0 !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
}

/* Строка сообщения не растягивается на всю высоту */
.chat-page .chat-container #chatMessages .chat-message {
    display: flex !important;
    flex: 0 0 auto !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
}

/* Контейнер текста */
.chat-page .chat-container #chatMessages .message-content {
    display: block !important;
    flex: 0 1 auto !important;
    width: auto !important;
    max-width: min(680px, calc(100% - 46px)) !important;
    height: auto !important;
    min-height: 0 !important;
    align-items: initial !important;
    justify-content: initial !important;
}

/* Сам пузырь — обычный блок, высота только по содержимому */
.chat-page .chat-container #chatMessages .message-content .message-bubble {
    display: block !important;
    position: static !important;
    box-sizing: border-box !important;
    width: fit-content !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    flex: none !important;
    align-self: flex-start !important;
    align-items: initial !important;
    justify-content: initial !important;
    text-align: left !important;
    white-space: pre-wrap !important;
    overflow: visible !important;
    padding: 12px 16px !important;
    line-height: 1.55 !important;
    margin: 0 !important;
}

/* Пользовательские сообщения остаются справа */
.chat-page .chat-container #chatMessages .user-message {
    justify-content: flex-end !important;
}

.chat-page .chat-container #chatMessages .user-message .message-content {
    margin-left: auto !important;
    max-width: min(76%, 680px) !important;
}

.chat-page .chat-container #chatMessages .user-message .message-bubble {
    margin-left: auto !important;
    text-align: left !important;
}

/* Область переписки не обрезает пузырь по высоте */
.chat-page .chat-container {
    min-height: 0 !important;
}

.chat-page .chat-container #chatMessages {
    flex: 1 1 0 !important;
}

/* На мобильном сохраняем удобную высоту для чтения */
@media (max-width: 760px) {
    .chat-page .chat-container #chatMessages {
        flex: 0 0 auto !important;
        min-height: 280px !important;
        max-height: 48vh !important;
    }
}
