/* Общие стили для чата */
.chat-container {
    width: 100%;
    max-width: 900px;
    height: 85vh;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    margin: 20px;
}

.chat-header {
    background: linear-gradient(120deg, var(--primary-light), var(--primary-dark));
    color: white;
    padding: 20px;
    text-align: center;
    position: relative;
}

.chat-header h3 {
    font-size: 1.5rem;
    margin: 0;
}

.chat-messages {
    flex: 1;
    padding: 25px;
    overflow-y: auto;
    background: #f8f9fa;
}

.message {
    margin-bottom: 18px;
    max-width: 78%;
    padding: 14px 20px;
    border-radius: 20px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word;
}

.user-message {
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 8px;
}

.bot-message {
    background: white;
    color: var(--text-dark);
    border: 1px solid var(--border-color);
    margin-right: auto;
    border-bottom-left-radius: 8px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.04);
    line-height: 1.6;
}

/* Стили для Markdown внутри сообщений бота */
.bot-message h1,
.bot-message h2,
.bot-message h3 {
    font-size: 1.2rem;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text-dark);
}

.bot-message h1:first-child,
.bot-message h2:first-child,
.bot-message h3:first-child {
    margin-top: 0;
}

.bot-message ul,
.bot-message ol {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
}

.bot-message li {
    margin-bottom: 0.25rem;
}

.bot-message strong {
    color: var(--primary-light);
    font-weight: 600;
}

.bot-message em {
    font-style: italic;
    color: var(--text-light);
}

.bot-message p {
    margin-bottom: 0.75rem;
}

.bot-message p:last-child {
    margin-bottom: 0;
}

.bot-message code {
    background: #f1f3f5;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9rem;
}

/* --- СТИЛИ ДЛЯ ФОРМУЛ LATEX ВНУТРИ .bot-message --- */

/* KaTeX: инлайновые формулы */
.bot-message .katex {
    font-size: 1.1em;
    display: inline-block;
    margin: 0 0.2em;
    vertical-align: middle;
}

/* KaTeX: блочные формулы */
.bot-message .katex-display {
    display: block;
    text-align: center;
    margin: 1.2em 0;
    overflow-x: auto;
    padding: 0.8em;
    background-color: #f0f8ff;
    border: 1px solid var(--primary-light);/*#bee1f4;*/
    border-radius: 6px;
}

.bot-message .katex-display > .katex {
    text-align: left;
}

/* Подсветка инлайновых формул */
.bot-message span.math-inline {
    background-color: rgba(231, 76, 60, 0.1);
    border-radius: 4px;
    padding: 0.1em 0.4em;
}

/* Кастомные обёртки для формул (если нужно) */
.bot-message div.math-display {
    text-align: center;
    margin: 1.2em 0;
    padding: 12px;
    background-color: #f0f8ff;
    border: 1px solid var(--primary-light); /*#bee1f4;*/
    border-radius: 8px;
    overflow-x: auto;
}

.chat-input-area {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background: white;
}


.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.input-toolbar {
    display: flex;
    gap: 8px;
}

.input-toolbar .btn {
    padding: 10px 16px;
    border-radius: 30px;
    background: #f8f9fa;
    border: 2px solid #e1e5ea;
    color: var(--text-dark);
}

.input-toolbar .btn:hover {
    border-color: var(--primary-light);
    color: var(--primary-light);
}

#user-input {
    flex: 1;
    min-width: 200px;
}

#send-button {
    white-space: nowrap;
}

.input-wrapper input {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid var(--border-color);
    border-radius: 30px;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s;
}

.input-wrapper input:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.2);
}

.input-wrapper button {
    background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
    color: white;
    border: none;
    padding: 12px 28px;
    border-radius: 30px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.input-wrapper button:hover {
    transform: translateY(-3px);
    box-shadow: 0 7px 14px rgba(52, 199, 89, 0.25);
}

.model-info {
    text-align: center;
    padding: 12px;
    background: #f1f3f5;
    font-size: 14px;
    color: var(--text-light);
    border-top: 1px solid var(--border-color);
}

.message.thinking {
    font-style: italic;
    color: var(--text-light);
    background: #f1f3f5;
    border: 1px dashed var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.thinking .dots {
    display: inline-flex;
    gap: 4px;
}

.thinking .dots span {
    width: 8px;
    height: 8px;
    background-color: var(--accent-dark);
    border-radius: 50%;
    animation: pulse 1.4s infinite ease-in-out;
}

.thinking .dots span:nth-child(2) {
    animation-delay: 0.2s;
}
.thinking .dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 60%, 100% { transform: scale(0.6); opacity: 0.4; }
    30% { transform: scale(1); opacity: 1; }
}

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

@media (max-width: 768px) {
    .chat-container {
        height: 90vh;
        margin: 10px;
        border-radius: 15px;
    }
    .message {
        max-width: 90%;
    }
    .input-wrapper button {
        padding: 12px 20px;
    }
}