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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 95%;
    /* max-width: 1200px; */
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

header {
    background: #2c3e50;
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 1.5em;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 80vh;
}

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

.message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.4;
    max-width: 100%;
    animation: fadeIn 0.3s ease-in;
}

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

.message.user {
    background: #007bff;
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
    max-width: 80%;
}

.message.assistant {
    background: #e9ecef;
    color: #333;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

.message.system {
    background: #ffc107;
    color: #333;
    margin: 0 auto;
    text-align: center;
    max-width: 60%;
    font-size: 0.9em;
}

/* Стили для контента сообщений */
.message-content {
    word-wrap: break-word;
}

.message-content p {
    margin-bottom: 8px;
}

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

/* Стили для блока рассуждений */
.reasoning-section {
    margin-top: 10px;
    border-left: 3px solid #ffc107;
    padding-left: 10px;
    background: #fff3cd;
    border-radius: 4px;
    padding: 8px 12px;
}

.reasoning-header {
    display: flex;
    align-items: center;
    justify-content: between;
    margin-bottom: 5px;
}

.reasoning-toggle {
    background: none;
    border: none;
    color: #856404;
    cursor: pointer;
    font-size: 0.8em;
    padding: 2px 6px;
    border-radius: 3px;
}

.reasoning-toggle:hover {
    background: rgba(0,0,0,0.1);
}

.reasoning-content {
    font-size: 0.9em;
    color: #856404;
}

.reasoning-content.hidden {
    display: none;
}

/* Стили для кода */
.message-content code {
    background: #f4f4f4;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.message-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid #444;
}

.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.85em;
}

/* Стили для блоков кода с языком */
.code-block {
    position: relative;
    margin: 10px 0;
}

.code-header {
    background: #2d2d2d;
    color: #ccc;
    padding: 6px 12px;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    font-size: 0.8em;
    font-family: 'Courier New', monospace;
    border-bottom: 1px solid #444;
}

.code-content {
    margin: 0;
}

/* Стили для списков */
.message-content ul,
.message-content ol {
    margin: 8px 0;
    padding-left: 20px;
}

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

/* Стили для цитат */
.message-content blockquote {
    border-left: 3px solid #007bff;
    padding-left: 12px;
    margin: 8px 0;
    color: #666;
    font-style: italic;
}

.input-container {
    padding: 20px;
    border-top: 1px solid #dee2e6;
    background: white;
}

.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

#message-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
}

#message-input:focus {
    outline: none;
    border-color: #007bff;
}

.btn-primary {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
}

.btn-primary:hover:not(:disabled) {
    background: #0056b3;
}

.btn-primary:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

.btn-secondary {
    background: #6c757d;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
}

.btn-secondary:hover {
    background: #545b62;
}

.controls {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.controls label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9em;
    color: #666;
}

.controls input[type="number"] {
    width: 80px;
    padding: 4px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    background: #f8f9fa;
}

.hidden {
    display: none !important;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #007bff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Полоса прокрутки */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Адаптивность */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .message {
        max-width: 90%;
    }
    
    .input-group {
        flex-direction: column;
    }
    
    .controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
}

/* Добавим эти стили в существующий CSS */

/* Стили для блока рассуждений в начале сообщения */
.reasoning-section {
    margin-bottom: 12px;
    border: 1px solid #ffc107;
    border-radius: 8px;
    background: #fffbf0;
    overflow: hidden;
}

.reasoning-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #fff3cd;
    border-bottom: 1px solid #ffc107;
}

.reasoning-toggle {
    background: none;
    border: 1px solid #856404;
    color: #856404;
    cursor: pointer;
    font-size: 0.8em;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.reasoning-toggle:hover {
    background: #856404;
    color: white;
}

.reasoning-content {
    padding: 12px;
    font-size: 0.9em;
    color: #856404;
    line-height: 1.4;
    background: white;
}

.reasoning-content.hidden {
    display: none;
}

/* Улучшим стили для контента сообщения */
.message-content {
    word-wrap: break-word;
}

.message-content > *:first-child {
    margin-top: 0;
}

.message-content > *:last-child {
    margin-bottom: 0;
}

/* Убедимся, что основной контент выглядит хорошо после рассуждений */
.message.assistant .message-content:has(.reasoning-section) {
    padding-top: 0;
}

/* Стили для кода в рассуждениях */
.reasoning-content code {
    background: #f8f9fa;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    color: #e83e8c;
}

.reasoning-content pre {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    margin: 8px 0;
}

.reasoning-content pre code {
    background: none;
    padding: 0;
}

/* Анимация для плавного появления */
.reasoning-content:not(.hidden) {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

/* Остальные существующие стили остаются без изменений */

/* Улучшенная анимация для рассуждений */
.reasoning-content {
    padding: 12px;
    font-size: 0.9em;
    color: #856404;
    line-height: 1.4;
    background: white;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
}

.reasoning-content:not(.hidden) {
    max-height: 1000px; /* Достаточно большое значение для контента */
    padding: 12px;
}

.reasoning-content.hidden {
    display: block;
    max-height: 0;
    padding: 0 12px;
}

/* Стили для панели статистики */
.stats-panel {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    margin: 0 20px 15px 20px;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #e9ecef;
    border-bottom: 1px solid #dee2e6;
    border-radius: 8px 8px 0 0;
}

.stats-header h3 {
    margin: 0;
    font-size: 1em;
    color: #495057;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.2em;
    cursor: pointer;
    color: #6c757d;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px;
}

.btn-close:hover {
    background: #dc3545;
    color: white;
}

.stats-content {
    padding: 16px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid #f1f3f4;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-label {
    font-weight: 500;
    color: #495057;
    font-size: 0.9em;
}

.stat-value {
    font-weight: 600;
    color: #007bff;
    font-size: 0.9em;
}

/* Стили для статистики в сообщениях */
.message-stats {
    margin-top: 8px;
    padding: 6px 8px;
    background: rgba(0, 123, 255, 0.1);
    border-radius: 4px;
    font-size: 0.8em;
    color: #495057;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: white;
    border-radius: 3px;
    border: 1px solid #dee2e6;
}

.stat-badge .label {
    font-weight: 500;
    color: #6c757d;
}

.stat-badge .value {
    font-weight: 600;
    color: #007bff;
}

/* Анимация для появления статистики */
@keyframes slideInStats {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stats-panel:not(.hidden) {
    animation: slideInStats 0.3s ease-out;
}

/* Остальные существующие стили остаются без изменений */