/* Основные стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* Структура страницы */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    padding: 0;
}

main {
    flex: 1;
}

/* Шапка и подвал */
header {
    background-color: #2c3e50;
    color: white;
    padding: 0.5rem 1rem;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    height: 50px;
    display: flex;
    align-items: center; 
}

header h1 {
    font-size: 1.3rem;
    margin: 0;
    margin-right: auto; /* Прижимаем заголовок к левому краю */
}

footer {
    background-color: #2c3e50;
    color: white;
    padding: 0.5rem 1rem;
    text-align: center;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: auto;
}

footer p {
    margin: 0;
    padding: 0;
}

/* Стили для страницы входа */
.login-container {
    max-width: 400px;
    width: 90%;
    margin: 2rem auto;
    padding: 2rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: white;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.login-container h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

button[type="submit"] {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

button[type="submit"]:hover {
    background-color: #2980b9;
}

.error {
    color: #e74c3c;
    padding: 0.75rem;
    margin-bottom: 1rem;
    background-color: #fde8e8;
    border-radius: 5px;
    text-align: center;
}

/* Стили чата */
.chat-container {
    display: flex;
    height: calc(100vh - 100px);
    width: 100%;
    max-width: 100%;
    margin: 0;
    background-color: white;
}

.models-sidebar {
    width: 25%;
    background-color: #f1f3f6;
    padding: 1rem;
    padding-right: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.models-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #ddd;
    background-color: #f1f3f6;
    position: sticky;
    top: 0;
    z-index: 10;
    margin-bottom: 0;
}

.models-header h2 {
    color: #2c3e50;
    margin: 0;
    font-size: 1.2rem;
}

.models-list {
    margin-top: 1rem;
    overflow-y: auto;
    flex-grow: 1;
}

.model-item {
    padding: 1rem;
    margin-bottom: 1rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    max-width: 100%;
}

.model-item:hover {
    background-color: #f0f7ff;
    border-color: #3498db;
}

.model-item.selected {
    border-color: #3498db;
    background-color: #e6f2ff;
    box-shadow: 0 0 0 2px rgba(52,152,219,0.2);
}

.model-item h3 {
    color: #2c3e50;
    margin-bottom: 0.5rem;
    white-space: normal;
    word-break: break-word;
}

.model-item p {
    color: #555;
    white-space: normal;
    word-break: break-word;
}

.model-stats {
    margin-top: 0.8rem;
    font-size: 0.9rem;
}

.model-stats p {
    margin-bottom: 0.4rem;
}

.chat-main {
    width: 75%;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid #eee;
    margin-bottom: 1rem;
}

.chat-header h2 {
    color: #2c3e50;
    margin: 0;
    font-size: 1.2rem;
}

.context-info-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.context-info {
    font-size: 0.9rem;
    color: #666;
    background-color: #f5f5f5;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
}

/* Стили кнопок */
.save-chat-button {
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 12px;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.3s;
    white-space: nowrap;
    height: 30px;
    display: flex;
    align-items: center;
}

.save-chat-button:hover:not(:disabled) {
    background-color: #218838;
}

.save-chat-button:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
}

.update-models-button,
.clear-context-button {
    background-color: #ffc107;
    color: #333;
    border: none;
    border-radius: 12px;
    padding: 0.4rem 0.8rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background-color 0.3s;
    white-space: nowrap;
    height: 30px;
    display: flex;
    align-items: center;
}

.update-models-button:hover:not(:disabled),
.clear-context-button:hover:not(:disabled) {
    background-color: #e0a800;
}

.update-models-button:disabled,
.clear-context-button:disabled {
    background-color: #cccccc;
    color: #666666;
    cursor: not-allowed;
}

/* Стили сообщений */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 1rem;
    background-color: white;
}

.user-message {
    background-color: #e6f2ff;
    padding: 0.8rem 1rem;
    margin-bottom: 0.8rem;
    border-radius: 8px;
    width: 100%;
    align-self: flex-end;
    word-wrap: break-word;
}

.bot-message {
    background-color: #f0f0f0;
    padding: 0.8rem 1rem;
    margin-bottom: 0.8rem;
    border-radius: 8px;
    width: 100%;
    align-self: flex-start;
    word-wrap: break-word;
}

.error-message {
    color: #e74c3c;
    padding: 0.8rem 1rem;
    margin-bottom: 0.8rem;
    border-radius: 8px;
    background-color: #fde8e8;
    border-left: 3px solid #e74c3c;
}

.info-message {
    color: #2c3e50;
    background-color: #e8f4fc;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.8rem;
    border-left: 3px solid #3498db;
    width: 100%;
}

.loading-message {
    color: #666;
    font-style: italic;
    padding: 0.8rem 1rem;
    margin-bottom: 0.8rem;
    border-left: 3px solid #3498db;
    background-color: #f8f9fa;
}

/* Поле ввода */
.message-input {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.message-input input {
    flex: 1;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
}

.message-input button {
    padding: 0.8rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: background-color 0.3s;
}

#send-button {
    background-color: #3498db;
    color: white;
    min-width: 100px;
}

#send-button:hover:not(:disabled) {
    background-color: #2980b9;
}

#attach-image-button {
    background-color: #f1f1f1;
    color: #333;
    padding: 0.8rem 0.8rem; /* Уменьшаем горизонтальные отступы */
    min-width: auto; /* Убираем фиксированную минимальную ширину */
    width: auto; /* Позволяем кнопке сжиматься по содержимому */
}

#attach-image-button:hover:not(:disabled) {
    background-color: #e0e0e0;
}

.message-input button:disabled {
    background-color: #95a5a6;
    color: white;
    cursor: not-allowed;
}

.message-input input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

/* Фильтр моделей */
.model-filter-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 10px 0;
    padding: 10px;
    background-color: #f5f5f5;
    border-radius: 8px;
    position: sticky;
    top: 60px;
    z-index: 10;
    background-color: #f1f3f6;
}

.model-filter-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.model-filter-label {
    font-size: 0.9rem;
    color: #333;
    white-space: nowrap;
}

.model-filter-input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.model-filter-checkbox {
    margin-right: 5px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.model-filter-checkbox-label {
    cursor: pointer;
    font-size: 0.9rem;
    color: #333;
}

/* Выход из системы */
.logout-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-left: auto; /* Прижимаем к правому краю */
}

.logout-container span {
    font-size: 0.9rem;
    color: #ecf0f1;
}

.logout-button {
    color: white;
    background-color: #e74c3c;
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.9rem;
    transition: background-color 0.3s;
}

.logout-button:hover {
    background-color: #c0392b;
}

/* Превью изображения */
#image-preview-container {
    display: none;
    margin: 10px 0;
}

#image-preview-container div {
    display: flex;
    align-items: center;
    background: #f5f5f5;
    padding: 8px;
    border-radius: 8px;
}

#preview-image {
    max-width: 200px;
    max-height: 200px;
}

#remove-image-button {
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 10px;
}

#remove-image-button:hover {
    background-color: #c0392b;
}

/* Markdown стили */
.message-content {
    line-height: 1.6;
}

.message-content h1, 
.message-content h2, 
.message-content h3, 
.message-content h4 {
    margin: 1em 0 0.5em 0;
    font-weight: 600;
}

.message-content p {
    margin: 0 0 1em 0;
}

.message-content ul, 
.message-content ol {
    margin: 0 0 1em 1em;
    padding-left: 1.5em;
}

.message-content li {
    margin-bottom: 0.5em;
}

.message-content code {
    background-color: rgba(175, 184, 193, 0.2);
    border-radius: 4px;
    padding: 0.2em 0.4em;
    font-family: monospace;
}

.message-content pre {
    background-color: #f6f8fa;
    border-radius: 6px;
    padding: 1em;
    overflow-x: auto;
    margin: 1em 0;
}

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

.message-content blockquote {
    border-left: 4px solid #dfe2e5;
    color: #6a737d;
    padding: 0 1em;
    margin: 0 0 1em 0;
}

.message-content a {
    color: #0366d6;
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

.message-content table {
    border-collapse: collapse;
    margin: 1em 0;
    width: 100%;
}

.message-content th, 
.message-content td {
    border: 1px solid #dfe2e5;
    padding: 6px 13px;
}

.message-content th {
    background-color: #f6f8fa;
    font-weight: 600;
}

/* Анимации */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.user-message, 
.bot-message, 
.error-message, 
.info-message {
    animation: fadeIn 0.3s ease-out;
}

/* Скроллбар */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

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

/* Адаптивность */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
        height: auto;
    }
    
    .models-sidebar {
        width: 100%;
        height: 300px;
    }
    
    .chat-main {
        width: 100%;
    }
    
    .message-input {
        flex-direction: column;
    }
    
    .message-input button {
        width: 100%;
    }
}

/* Добавим в конец файла: */
.model-stats p {
    margin: 0;
    padding: 0;
    font-size: 0.85rem;
    color: #666;
    white-space: nowrap;
}

.model-stats {
    display: flex;
    gap: 10px;
    margin-top: 0.8rem;
    font-size: 0.9rem;
    color: #666;
    border-top: 1px solid #eee;
    padding-top: 0.5rem;
    flex-wrap: wrap;
}