/* ─── CSS Variables (from landing page) ─── */
:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #dbeafe;
    --primary-50: #eff6ff;
    --accent: #f59e0b;
    --accent-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fef2f2;
    --success: #16a34a;
    --success-light: #f0fdf4;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-lg: 16px;
    --sidebar-width: 300px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--gray-800);
    line-height: 1.6;
    background: var(--gray-50);
    height: 100vh;
    overflow: hidden;
}

/* ─── Auth Screen ─── */
.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-50) 0%, var(--white) 50%, var(--accent-light) 100%);
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo h1 {
    font-size: 2rem;
    font-weight: 800;
    color: var(--gray-900);
    margin-top: 12px;
}

.auth-logo p {
    color: var(--gray-500);
    margin-top: 4px;
}

.logo-icon {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}

.auth-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}

.auth-card h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 24px;
    text-align: center;
}

.auth-divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    color: var(--gray-400);
    font-size: 0.85rem;
}

.auth-divider::before, .auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-200);
}

.auth-divider span { padding: 0 12px; }

.auth-switch {
    text-align: center;
    margin-top: 16px;
    color: var(--gray-500);
    font-size: 0.9rem;
}

.auth-switch a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.auth-switch a:hover { text-decoration: underline; }

/* ─── Forms ─── */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s;
    outline: none;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* ─── Buttons ─── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: var(--white);
}

.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-vk {
    background: #0077FF;
    color: var(--white);
}

.btn-vk:hover { background: #0066dd; }

.btn-full { width: 100%; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--gray-500);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

/* ─── App Layout ─── */
.app-screen {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--white);
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--gray-900);
    font-weight: 800;
    font-size: 1.1rem;
}

.logo .logo-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    font-size: 1rem;
}

.new-chat-btn {
    margin: 12px 16px;
    flex-shrink: 0;
}

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

.chat-item {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    gap: 10px;
}

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

.chat-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.chat-item-icon {
    width: 36px; height: 36px;
    background: var(--gray-100);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
}

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

.chat-item-title {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-date {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.sidebar-footer {
    border-top: 1px solid var(--gray-100);
    padding: 12px 16px;
    flex-shrink: 0;
}

.token-balance {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--accent-light);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    cursor: pointer;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.token-balance:hover { background: #fde68a; }

.token-icon { font-size: 1rem; }

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info span {
    font-size: 0.85rem;
    color: var(--gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Main Content ─── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ─── Chat View ─── */
.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--gray-200);
    background: var(--white);
    flex-shrink: 0;
}

.chat-header h2 {
    flex: 1;
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ─── Messages ─── */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.welcome-message {
    text-align: center;
    max-width: 500px;
    margin: auto;
    padding: 40px 20px;
}

.welcome-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.welcome-icon.large { font-size: 4rem; }

.welcome-message h3 {
    font-size: 1.3rem;
    margin-bottom: 8px;
}

.welcome-message p {
    color: var(--gray-500);
    margin-bottom: 20px;
}

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.welcome-suggestions button {
    padding: 8px 16px;
    border: 1.5px solid var(--gray-200);
    border-radius: 20px;
    background: var(--white);
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--gray-700);
}

.welcome-suggestions button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-50);
}

.message {
    display: flex;
    gap: 10px;
    max-width: 80%;
}

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

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

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

.message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    color: var(--white);
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.93rem;
    line-height: 1.6;
    word-break: break-word;
}

.message.user .message-bubble {
    background: var(--primary);
    color: var(--white);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.message-bubble strong { font-weight: 700; }

.message-bubble code {
    background: var(--gray-100);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.message-meta {
    font-size: 0.7rem;
    color: var(--gray-400);
    margin-top: 4px;
}

.message.user .message-meta { text-align: right; }

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--gray-300);
    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); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Input Area ─── */
.input-area {
    padding: 12px 20px 16px;
    border-top: 1px solid var(--gray-200);
    background: var(--white);
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--gray-50);
    border: 1.5px solid var(--gray-200);
    border-radius: 12px;
    padding: 8px 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.attach-btn {
    position: relative;
    color: var(--gray-400);
}

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

.attach-btn input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    max-height: 120px;
    outline: none;
    padding: 4px 0;
}

.send-btn {
    color: var(--primary);
    background: var(--primary-light);
    border-radius: 8px;
}

.send-btn:hover {
    background: var(--primary);
    color: var(--white);
}

.file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--gray-100);
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--gray-700);
}

.file-chip button {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
}

.file-chip button:hover { color: var(--danger); }

/* ─── Empty State ─── */
.empty-view {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 20px;
    color: var(--gray-500);
}

.empty-view h2 {
    font-size: 1.5rem;
    color: var(--gray-900);
    margin: 12px 0 4px;
}

.empty-view .btn { margin-top: 20px; }

/* ─── Files Panel ─── */
.files-panel {
    width: 320px;
    background: var(--white);
    border-left: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.files-panel-header h3 { font-size: 1rem; }

.files-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    transition: background 0.15s;
}

.file-item:hover { background: var(--gray-50); }

.file-item-icon {
    width: 36px; height: 36px;
    background: var(--gray-100);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

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

.file-item-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-item-size {
    font-size: 0.75rem;
    color: var(--gray-400);
}

.no-files {
    text-align: center;
    color: var(--gray-400);
    padding: 40px 20px;
    font-size: 0.9rem;
}

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--gray-100);
}

.modal-header h3 { font-size: 1.1rem; }

.modal-body { padding: 24px; }

.current-balance {
    text-align: center;
    margin-bottom: 20px;
    color: var(--gray-600);
}

.package-card {
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.package-card:hover {
    border-color: var(--primary);
    background: var(--primary-50);
}

.package-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.package-name {
    font-weight: 700;
    font-size: 1rem;
}

.package-price {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--primary);
}

.package-tokens {
    font-size: 0.85rem;
    color: var(--gray-500);
}

/* ─── Loading ─── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Mobile ─── */
.mobile-only { display: none !important; }

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        z-index: 1500;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open { transform: translateX(0); }

    .mobile-only { display: flex !important; }

    .message { max-width: 90%; }

    .files-panel {
        position: fixed;
        right: 0; top: 0; bottom: 0;
        z-index: 1500;
        box-shadow: var(--shadow-lg);
    }

    .welcome-suggestions { flex-direction: column; }
    .welcome-suggestions button { width: 100%; }

    .modal { margin: 10px; }
}

/* ─── Sidebar overlay for mobile ─── */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 1400;
    display: none;
}

.sidebar-overlay.show { display: block; }

/* ─── Markdown rendering in messages ─── */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
    font-size: 1em;
    font-weight: 700;
    margin: 12px 0 6px;
}

.message-bubble h1 { font-size: 1.15em; }
.message-bubble h2 { font-size: 1.08em; }

.message-bubble blockquote {
    border-left: 3px solid var(--gray-300);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--gray-600);
}

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

.message-error {
    background: var(--danger-light);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    max-width: 80%;
    align-self: center;
}
