:root {
    --bg-main: #212121;
    --bg-sidebar: #171717;
    --bg-card: #2f2f2f;
    --bg-input: #2f2f2f;
    --border-color: #383838;
    --text-main: #ececec;
    --text-muted: #b4b4b4;
    --accent-green: #10a37f;
    --code-bg: #181818;
    --code-header-bg: #262626;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body, html {
    height: 100%;
    background-color: var(--bg-main);
    color: var(--text-main);
    overflow: hidden;
}

/* ChatGPT Layout */
.chatgpt-app {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 90;
    transition: opacity 0.25s ease;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    height: 100%;
    border-right: 1px solid #282828;
    transition: transform 0.25s ease, margin-left 0.25s ease;
    z-index: 100;
    flex-shrink: 0;
}

.sidebar.closed {
    margin-left: -260px;
}

.sidebar-header {
    padding: 12px;
}

.new-chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}

.new-chat-btn:hover {
    background: #242424;
}

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-main);
}

.chat-item:hover, .chat-item.active {
    background: #212121;
}

.chat-item .title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.chat-item .del-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 12px;
}

.chat-item:hover .del-btn {
    display: block;
}

.sidebar-footer {
    padding: 14px;
    border-top: 1px solid #282828;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-link {
    color: var(--text-muted);
}
.logout-link:hover { color: #fff; }

/* Main Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background: var(--bg-main);
    overflow: hidden;
    min-width: 0;
}

.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    height: 56px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.top-left, .top-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toggle-sidebar {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.2s, color 0.2s;
}

.toggle-sidebar:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

/* Красивый и стильный селектор моделей (Кастомная Капсула) */
.model-select-wrapper {
    position: relative;
    display: inline-block;
}

.model-select-wrapper select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: rgba(255, 255, 255, 0.05);
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='[http://www.w3.org/2000/svg](http://www.w3.org/2000/svg)' viewBox='0 0 24 24' fill='none' stroke='%23b4b4b4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 15px;
    color: var(--text-main);
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 7px 34px 7px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.model-select-wrapper select:hover {
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
}

.model-select-wrapper select:focus {
    border-color: var(--accent-green);
}

.model-select-wrapper select option {
    background: #2a2a2a;
    color: var(--text-main);
    padding: 8px;
}

.btn-secondary {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-main);
    padding: 7px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-secondary.has-key {
    border-color: var(--accent-green);
    color: var(--accent-green);
}

/* Chat Messages */
.messages-scroll {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.empty-state {
    margin: auto;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
}

.logo-circle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
}

.messages-flow {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.message-row {
    display: flex;
    gap: 16px;
    line-height: 1.6;
    font-size: 15px;
}

.message-row.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 18px;
    border-radius: 18px;
    word-break: break-word;
}

.message-row.user .message-bubble {
    background: #2f2f2f;
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.message-row.assistant .message-bubble {
    background: transparent;
    max-width: 100%;
    padding: 0;
    width: 100%;
    color: var(--text-main);
}

/* Обычный текст ответа без маркдаун выделений */
.plain-text-block {
    white-space: pre-wrap;
    line-height: 1.65;
    margin-bottom: 8px;
}

/* Специальное окно для копирования (Код / Текст / Файлы) */
.copy-block {
    background: var(--code-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    margin: 12px 0;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.copy-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--code-header-bg);
    padding: 8px 14px;
    font-size: 12px;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    user-select: none;
}

.copy-header-title {
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-size: 11px;
    color: #a0a0a0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.copy-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.copy-btn.copied {
    color: var(--accent-green);
}

.copy-content {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-family: "Fira Code", "Cascadia Code", Consolas, Monaco, "Courier New", monospace;
    font-size: 13.5px;
    line-height: 1.5;
    color: #e6e6e6;
    white-space: pre;
    tab-size: 4;
}

/* Bottom Input Area */
.chat-input-wrapper {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    padding: 0 16px 16px;
}

.input-box {
    background: var(--bg-input);
    border-radius: 24px;
    border: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    padding: 8px 12px;
    gap: 8px;
    position: relative;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.input-box:focus-within {
    border-color: #555;
}

.input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    resize: none;
    font-size: 15px;
    line-height: 24px;
    min-height: 24px;
    max-height: 144px; /* 6 строк */
    overflow-y: hidden;
    padding: 4px 6px;
}

.send-btn {
    background: #fff;
    color: #000;
    border: none;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.2s, background-color 0.2s;
    margin-bottom: 2px;
}

.send-btn:disabled {
    background: #424242;
    color: #888;
    cursor: not-allowed;
}

.input-footer {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Modal Window */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(2px);
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #212121;
    border: 1px solid var(--border-color);
    padding: 24px;
    border-radius: 12px;
    max-width: 460px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.modal h3 { margin-bottom: 8px; font-size: 18px; }
.modal p { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; line-height: 1.4; }

.modal input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: #171717;
    color: #fff;
    font-size: 14px;
    margin-bottom: 20px;
    outline: none;
}

.modal input:focus {
    border-color: var(--accent-green);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-cancel {
    background: transparent;
    border: 1px solid var(--border-color);
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
}

.btn-primary {
    background: var(--accent-green);
    border: none;
    color: #fff;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
}

.btn-primary:hover {
    opacity: 0.9;
}

/* --- Мобильная адаптация (Mobile Responsive) --- */
@media (max-width: 768px) {
    /* Мобильный сайдбар выезжает поверх интерфейса */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        box-shadow: 6px 0 20px rgba(0, 0, 0, 0.6);
        transform: translateX(0);
        margin-left: 0;
    }

    .sidebar.closed {
        transform: translateX(-100%);
        margin-left: 0;
    }

    /* Включаем полупрозрачную подложку при открытом меню */
    .sidebar-overlay.active {
        display: block;
    }

    .top-nav {
        padding: 8px 12px;
    }

    #keyStatusText {
        display: none; /* Прячем текст на мобильных, оставляем иконку */
    }

    .btn-secondary {
        padding: 7px 10px;
        border-radius: 50%;
    }

    .messages-flow {
        padding: 16px 12px;
        gap: 16px;
    }

    .message-bubble {
        max-width: 90%;
        font-size: 14.5px;
    }

    .chat-input-wrapper {
        padding: 0 10px 10px;
    }

    .input-box textarea {
        font-size: 16px; /* Предотвращает автоматический зум на iOS */
    }

    .copy-content {
        font-size: 12.5px;
        padding: 10px 12px;
    }
}
