:root {
    --primary-color: #ff4d4d;
    --primary-hover: #ff7070;
    --bg-color: #f7f7f7;
    --card-bg: #ffffff;
    --text-primary: #2d2d2d;
    --text-secondary: #6b7280;
    --shadow-sm: 0 3px 10px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --header-height: 5rem;
    --input-height: 4.5rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: "Inter", sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overscroll-behavior-y: contain; /* Предотвращает нежелательный скролл на мобильных */
}

.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    padding: 1rem 2rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-lg);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left img {
    width: 40px;
    height: 40px;
    transition: var(--transition);
}

.header-left img:hover {
    transform: scale(1.1) rotate(-5deg);
}

.logo {
    color: white;
    font-size: 1.6rem;
    font-weight: 700;
}

.current-model {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 0.75rem 1.25rem;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.current-model:hover {
    background: rgba(255, 255, 255, 0.3);
}

.model-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 300px;
    max-width: 90vw; /* Ограничение ширины для маленьких экранов */
    max-height: 70vh;
    overflow-y: auto;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 0.75rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--transition);
}

.model-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.model-card {
    background: #f9fafb;
    border-radius: 12px;
    padding: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
}

.model-card:hover {
    background: #f1f5f9;
}

.model-card.selected {
    background: var(--primary-color);
    color: white;
}

.chat-container {
    margin-top: var(--header-height);
    padding: 1.5rem;
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
}

.messages {
    flex-grow: 1;
    padding: 1.5rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Плавный скролл на iOS */
    scroll-behavior: smooth;
}

.message {
    max-width: 75%;
    padding: 1rem 1.25rem;
    border-radius: 20px;
    box-shadow: var(--shadow-sm);
}

.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-hover) 100%);
    color: white;
}

.message.bot {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.input-container {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 1180px;
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

#userInput {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 1rem;
    background: #ffffff;
    resize: none;
    min-height: 44px;
    transition: border-color 0.2s ease;
}

#userInput:focus {
    border-color: var(--primary-color);
    outline: none;
}

#sendButton, .image-upload-button {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
}

#sendButton {
    background: var(--primary-color);
    color: white;
    border: none;
}

#sendButton:hover {
    background: var(--primary-hover);
}

.image-upload-button {
    background: #f1f5f9;
    border: 2px solid #e5e7eb;
    color: var(--text-secondary);
}

.image-upload-button:hover {
    background: #e2e8f0;
    color: var(--primary-color);
}

.image-preview {
    max-width: 200px;
    position: absolute;
    bottom: 80px;
    left: 20px;
    display: none;
}

.preview-container img {
    max-width: 100%;
    max-height: 150px;
    border-radius: 8px;
    border: 2px solid var(--primary-color);
}

.toast {
    position: fixed;
    bottom: 6rem; /* Расположен чуть выше input-container */
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    opacity: 0;
    transition: var(--transition);
    z-index: 1000;
}

.markdown-body {
    font-size: 0.95rem;
    word-break: break-word;
}

.markdown-body pre {
    background: #f6f8fa;
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
}

/* Медиа-запросы для адаптива */
@media (max-width: 768px) {
    .header { padding: 0.75rem 1rem; }
    .chat-container { margin-top: 4rem; padding: 1rem; }
    .messages { padding: 1rem; padding-bottom: 4.5rem; }
    .message { max-width: 80%; }
    .input-container { bottom: 0.75rem; padding: 0.5rem; width: calc(100% - 1.5rem); }
    .model-menu { width: 280px; right: -10px; }
}

@media (max-width: 480px) {
    .header-left img { width: 36px; height: 36px; }
    .logo { font-size: 1.3rem; }
    .current-model { padding: 0.5rem 1rem; font-size: 0.9rem; }
    .chat-container { margin-top: 3.5rem; padding: 0.75rem; }
    .messages { padding: 0.75rem; padding-bottom: 4rem; }
    .message { max-width: 85%; }
    #userInput { font-size: 0.95rem; min-height: 40px; }
    #sendButton, .image-upload-button { width: 40px; height: 40px; }
    .image-preview { bottom: 70px; left: 10px; max-width: 150px; }
}

@media (max-width: 360px) {
    .header { padding: 0.5rem 0.75rem; }
    .header-left img { width: 32px; height: 32px; }
    .logo { font-size: 1.2rem; }
    .current-model { padding: 0.5rem 0.75rem; font-size: 0.85rem; }
    .chat-container { margin-top: 3rem; padding: 0.5rem; }
    .messages { padding: 0.5rem; padding-bottom: 3.5rem; }
    .message { max-width: 90%; font-size: 0.9rem; }
    .input-container { bottom: 0.5rem; width: calc(100% - 1rem); }
    #userInput { font-size: 0.9rem; min-height: 36px; }
    #sendButton, .image-upload-button { width: 40px; height: 40px; }
    .model-menu { width: 240px; right: -8px; }
}

@media (max-width: 320px) {
    .header { padding: 0.4rem 0.5rem; }
    .header-left img { width: 28px; height: 28px; }
    .logo { font-size: 1.1rem; }
    .chat-container { margin-top: 2.5rem; }
    .messages { padding-bottom: 3rem; }
    .input-container { padding: 0.4rem; }
    #userInput { min-height: 32px; }
    #sendButton, .image-upload-button { width: 36px; height: 36px; }
}

.markdown-body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    word-wrap: break-word;
    max-width: 100%;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}

.markdown-body h1 {
    font-size: 2em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e1e4e8;
}

.markdown-body h2 {
    font-size: 1.5em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid #e1e4e8;
}

.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1em; }
.markdown-body h5 { font-size: 0.875em; }
.markdown-body h6 { font-size: 0.85em; color: #6a737d; }

.markdown-body p {
    margin-top: 0;
}

.markdown-body blockquote {
    margin: 16px 0;
    padding: 0 1em;
    color: #6a737d;
    border-left: 0.25em solid #0366d6;
}

.markdown-body strong { font-weight: 600; }
.markdown-body em { font-style: italic; }
.markdown-body del { text-decoration: line-through; }

.markdown-body ul,
.markdown-body ol {
    margin-top: 0;
    margin-bottom: 16px;
    padding-left: 2em;
}

.markdown-body ul { list-style-type: disc; }
.markdown-body ol { list-style-type: decimal; }

.markdown-body li {
    margin: 0.25em 0;
}

.markdown-body li + li {
    margin-top: 0.25em;
}

.markdown-body dl dt {
    margin-top: 16px;
    font-weight: 600;
    font-style: italic;
}

.markdown-body dl dd {
    padding-left: 16px;
    margin-bottom: 16px;
}

.markdown-body code {
    padding: 0.2em 0.4em;
    font-size: 90%;
    background-color: #f6f8fa;
    border-radius: 4px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.markdown-body pre {
    margin: 16px 0;
    padding: 16px;
    background-color: #f6f8fa;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 90%;
    line-height: 1.45;
    max-width: 100%;
}

.markdown-body pre code {
    padding: 0;
    background-color: transparent;
    border-radius: 0;
}

.markdown-body table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
    margin: 1rem 0;
    -webkit-overflow-scrolling: touch;
}

.markdown-body table th,
.markdown-body table td {
    min-width: 120px;
    padding: 0.75rem;
    border: 1px solid #e0e0e0;
    background: #fff;
    text-align: left;
    white-space: nowrap;
}

.markdown-body table th {
    background: #f5f5f5;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.markdown-body table::-webkit-scrollbar {
    height: 6px;
}

.markdown-body table::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.markdown-body table::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 3px;
    opacity: 0.8;
}

.markdown-body table::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

.markdown-body a {
    color: #0366d6;
    text-decoration: none;
}

.markdown-body a:hover {
    text-decoration: underline;
}

.markdown-body img {
    max-width: 100%;
    border-radius: 4px;
    box-sizing: border-box;
}

.markdown-body hr {
    height: 1px;
    margin: 24px 0;
    background-color: #e1e4e8;
    border: none;
}

.markdown-body input[type="checkbox"] {
    margin-right: 0.5em;
    vertical-align: middle;
}

@media (max-width: 768px) {
    .markdown-body {
        font-size: 15px;
        padding: 8px;
    }

    .markdown-body pre {
        margin: 16px -8px;
        padding: 12px;
        border-radius: 0;
    }

    .markdown-body table {
        margin: 0.75rem -0.5rem;
        width: calc(100% + 1rem);
    }

    .markdown-body table td,
    .markdown-body table th {
        min-width: 100px;
        padding: 0.625rem;
        font-size: 0.9rem;
    }
}

/* Основные стили */
.header {
    background: linear-gradient(135deg, #ff4d4d 0%, #ff7070 100%);
    padding: 1rem 2rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-left img {
    width: 40px;
    height: 40px;
}

.arrow-icon {
    width: 16px;
    height: 16px;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 1rem; /* Отступ между сообщениями */
    padding: 1rem;
}

.message {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 20px;
    background-color: #ffffff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    word-wrap: break-word;
}

.message.user {
    align-self: flex-end; /* Сообщения пользователя справа */
    background-color: #dcf8c6; /* Светло-зелёный фон */
    border-bottom-right-radius: 5px; /* Убираем скругление внизу справа */
}

.message.bot {
    align-self: flex-start; /* Сообщения бота слева */
    background-color: #ffffff; /* Белый фон */
    border-bottom-left-radius: 5px; /* Убираем скругление внизу слева */
}

.logo {
    color: white;
    font-size: 1.6rem;
    font-weight: 700;
}

.current-model {
    padding: 0.75rem 1.25rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.current-model img {
    width: 48px;
    height: 48px;
}

.chat-container {
    margin-top: 5rem;
    padding: 1.5rem;
    max-width: 1200px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    height: calc(100vh - 5rem);
    display: flex;
    flex-direction: column;
}

.messages {
    flex-grow: 1;
    padding: 1.5rem;
    padding-bottom: 6rem; /* Чтобы инпут не перекрывал сообщения */
    overflow-y: auto;
}

.input-container {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 1180px;
}

/* Адаптивка для мобилок */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1.5rem;
    }
    .header-left img {
        width: 32px;
        height: 32px;
    }
    .logo {
        font-size: 1.4rem;
    }
    .current-model {
        padding: 0.5rem 1rem;
    }
    .current-model img {
        width: 36px;
        height: 36px;
    }
    .chat-container {
        margin-top: 4rem;
        height: calc(100vh - 4rem);
    }
    .messages {
        padding: 1rem;
        padding-bottom: 5rem;
    }
    .input-container {
        bottom: 0.75rem;
    }
}

@media (max-width: 480px) {
    .header {
        padding: 0.5rem 1rem;
    }
    .header-left img {
        width: 28px;
        height: 28px;
    }
    .logo {
        font-size: 1.2rem;
    }
    .current-model {
        padding: 0.25rem 0.75rem;
    }
    .current-model img {
        width: 28px;
        height: 28px;
    }
    .chat-container {
        margin-top: 3.5rem;
        height: calc(100vh - 3.5rem);
    }
    .messages {
        padding: 0.75rem;
        padding-bottom: 4.5rem;
    }
    .input-container {
        bottom: 0.5rem;
    }
}