:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #252525;
    --bg-hover: #2a2a2a;
    --accent: #f5a623;
    --accent-hover: #ffb84d;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --border: #333333;
    --success: #4ade80;
    --error: #ef4444;
    --warning: #fbbf24;
    
    --sidebar-width: 280px;
    --header-height: 60px;
    --input-height: auto;
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
}

/* ===== САЙДБАР ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: var(--accent);
}

.btn-new-chat {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-new-chat:hover {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.2s;
    position: relative;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

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

.chat-item-date {
    font-size: 11px;
    color: var(--text-muted);
}

.delete-chat {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.chat-item:hover .delete-chat {
    opacity: 1;
}

.delete-chat:hover {
    color: var(--error);
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.api-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s infinite;
}

.status-dot.online {
    background: var(--success);
    animation: none;
}

.status-dot.offline {
    background: var(--error);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== ОСНОВНАЯ ОБЛАСТЬ ===== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
}

.btn-toggle-sidebar {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
}

.btn-toggle-sidebar:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.chat-header h1 {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--error);
}

/* ===== СООБЩЕНИЯ ===== */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
}

.welcome-content {
    text-align: center;
    max-width: 500px;
}

.welcome-icon {
    color: var(--accent);
    margin-bottom: 24px;
    opacity: 0.8;
}

.welcome-content h2 {
    font-size: 28px;
    margin-bottom: 8px;
    font-weight: 700;
}

.welcome-content p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 16px;
}

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.quick-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 16px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    text-align: left;
    transition: all 0.2s;
}

.quick-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
}

/* Сообщения */
.message {
    display: flex;
    gap: 12px;
    max-width: 90%;
    animation: messageAppear 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--accent);
    color: var(--bg-primary);
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--accent);
    border: 1px solid var(--border);
}

.message-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-width: 100%;
    overflow-x: auto;
}

.message.user .message-content {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.message-header strong {
    color: var(--text-primary);
    font-size: 13px;
}

.message-time {
    font-size: 11px;
}

/* Текст сообщения */
.message-text {
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
}

.message-text p {
    margin-bottom: 12px;
}

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

.message-text code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    color: var(--accent);
}

/* Блоки кода */
.code-block {
    margin: 12px 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.code-header {
    background: var(--bg-primary);
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.code-lang {
    text-transform: uppercase;
    font-weight: 600;
    font-size: 11px;
}

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

.btn-copy-code:hover {
    color: var(--accent);
}

.code-block pre {
    background: var(--bg-primary);
    padding: 16px;
    overflow-x: auto;
    margin: 0;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.5;
}

.code-block code {
    background: none;
    padding: 0;
    color: var(--text-primary);
}

/* Синтаксис подсветка (базовая) */
.code-keyword { color: #c678dd; }
.code-string { color: #98c379; }
.code-comment { color: #5c6370; font-style: italic; }
.code-function { color: #61afef; }
.code-number { color: #d19a66; }

/* Вложения в сообщении */
.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.attachment-preview {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-primary);
}

.attachment-preview.image {
    max-width: 300px;
    max-height: 200px;
}

.attachment-preview.image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: zoom-in;
}

.attachment-preview.file {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
}

.file-icon {
    font-size: 24px;
}

.file-info {
    flex: 1;
    min-width: 0;
}

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

.file-size {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ===== ПОЛЕ ВВОДА ===== */
.input-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 16px 20px;
}

.attachments-bar {
    display: flex;
    gap: 8px;
    padding: 0 20px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
}

.attachment-chip img {
    width: 24px;
    height: 24px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-chip .remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.attachment-chip .remove:hover {
    color: var(--error);
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--accent);
}

.btn-attach {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
    flex-shrink: 0;
}

.btn-attach:hover {
    color: var(--accent);
}

#messageInput {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 200px;
    font-family: inherit;
}

#messageInput::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: var(--accent);
    border: none;
    color: var(--bg-primary);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--accent-hover);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.input-hint {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-muted);
    justify-content: center;
}

/* ===== ИНДИКАТОР ЗАГРУЗКИ ===== */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-10px); }
}

/* ===== МОДАЛКА ===== */
.image-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.image-modal.active {
    opacity: 1;
    pointer-events: all;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    border-radius: var(--radius);
}

/* ===== СКРОЛЛБАР ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== АДАПТИВ ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .btn-toggle-sidebar {
        display: block;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
    
    .message {
        max-width: 95%;
    }
    
    .attachment-preview.image {
        max-width: 100%;
    }
}

/* Drag & drop */
.drag-overlay {
    position: fixed;
    inset: 0;
    background: rgba(245, 166, 35, 0.1);
    border: 3px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.drag-overlay.active {
    opacity: 1;
}