/* ═══════════════════════════════════════════════════════════
   GLM Chat — Светлая тема
   ═══════════════════════════════════════════════════════════ */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-tertiary: #ececf1;
    --bg-hover: #e8e8ed;
    --bg-active: #dfdfe6;
    --bg-input: #ffffff;
    --bg-message-user: #e8edf5;
    --bg-modal: #ffffff;
    --border: #d9d9e3;
    --border-light: #c5c5d2;
    --text-primary: #1a1a2e;
    --text-secondary: #6b6b80;
    --text-muted: #9b9bb0;
    --accent: #5b6ef5;
    --accent-hover: #4a5ce8;
    --accent-glow: rgba(91, 110, 245, 0.12);
    --accent-green: #1a9c5a;
    --danger: #e53e3e;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --font-main: 'Onest', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition: 180ms ease;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

a { color: var(--accent); }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ═══ Sidebar ═══ */
.sidebar {
    width: 280px; min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    transition: transform var(--transition);
    z-index: 100;
}

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

.logo { display: flex; align-items: center; gap: 10px; }

.logo-icon {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, var(--accent), #8b6cf5);
    border-radius: var(--radius-sm); color: white;
}

.logo-text { font-weight: 700; font-size: 17px; letter-spacing: -0.3px; color: var(--text-primary); }

.sidebar-section { padding: 8px 0; border-bottom: 1px solid var(--border); }
.sidebar-section-grow { flex: 1; overflow-y: auto; border-bottom: none; }

.section-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 16px; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-muted);
}

.nav-list { padding: 0 8px; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; border-radius: var(--radius-sm);
    cursor: pointer; transition: all var(--transition);
    font-size: 13.5px; color: var(--text-secondary);
    position: relative;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active { background: var(--bg-active); color: var(--text-primary); font-weight: 500; }
.nav-item .nav-icon { flex-shrink: 0; opacity: 0.5; }
.nav-item.active .nav-icon { opacity: 1; color: var(--accent); }
.nav-item .nav-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nav-actions { display: none; gap: 2px; }
.nav-item:hover .nav-actions { display: flex; }

.nav-item .btn-nav-action {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: none; color: var(--text-muted);
    cursor: pointer; border-radius: 4px; transition: all var(--transition);
}
.nav-item .btn-nav-action:hover { background: var(--bg-tertiary); color: var(--danger); }

.nav-project-item { border-left: 2px solid transparent; margin-left: 4px; }
.nav-project-item.active { border-left-color: var(--accent); }

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

.btn-sidebar-footer {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 10px 12px; background: none; border: none;
    color: var(--text-secondary); font-family: var(--font-main);
    font-size: 13px; cursor: pointer; border-radius: var(--radius-sm);
    transition: all var(--transition);
}
.btn-sidebar-footer:hover { background: var(--bg-hover); color: var(--text-primary); }

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

.mobile-header {
    display: none; align-items: center; gap: 12px;
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}
.mobile-title { font-weight: 600; font-size: 15px; }

/* ═══ Empty state ═══ */
.empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 40px 20px; text-align: center;
}
.empty-hero { max-width: 440px; }
.empty-icon {
    width: 80px; height: 80px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 24px; background: var(--accent-glow);
    border-radius: var(--radius-lg); color: var(--accent);
}
.empty-state h1 { font-size: 28px; font-weight: 700; margin-bottom: 12px; letter-spacing: -0.5px; }
.empty-state p { color: var(--text-secondary); font-size: 15px; line-height: 1.7; }
.empty-actions { display: flex; gap: 12px; margin-top: 32px; }

.btn-action {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 24px; background: var(--accent); color: white;
    border: none; border-radius: var(--radius-md);
    font-family: var(--font-main); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
}
.btn-action:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-action-secondary { background: white; border: 1px solid var(--border); color: var(--text-primary); }
.btn-action-secondary:hover { background: var(--bg-secondary); box-shadow: var(--shadow-sm); }

/* ═══ Chat Area ═══ */
.chat-area { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 24px 0; }

.message { padding: 12px 0; animation: msg-in 0.3s ease; }
@keyframes msg-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

.message-inner { max-width: 780px; margin: 0 auto; padding: 0 24px; display: flex; gap: 16px; }

.message-avatar {
    width: 32px; height: 32px; flex-shrink: 0;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; margin-top: 2px;
}
.message-user .message-avatar { background: var(--bg-message-user); color: var(--accent); }
.message-assistant .message-avatar { background: linear-gradient(135deg, var(--accent), #8b6cf5); color: white; }

.message-body { flex: 1; min-width: 0; }
.message-role { font-size: 11px; font-weight: 600; margin-bottom: 4px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

.message-content { font-size: 14.5px; line-height: 1.75; word-wrap: break-word; }
.message-content p { margin-bottom: 10px; }
.message-content p:last-child { margin-bottom: 0; }

.message-content pre {
    background: var(--bg-secondary); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px 16px;
    overflow-x: auto; margin: 10px 0;
    font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
}
.message-content code {
    background: var(--bg-tertiary); padding: 2px 6px;
    border-radius: 4px; font-family: var(--font-mono); font-size: 13px;
}
.message-content pre code { background: none; padding: 0; }
.message-content ul, .message-content ol { padding-left: 24px; margin: 8px 0; }
.message-content li { margin: 4px 0; }
.message-content blockquote { border-left: 3px solid var(--accent); padding-left: 14px; color: var(--text-secondary); margin: 10px 0; }
.message-content h1 { font-size: 20px; margin: 16px 0 8px; }
.message-content h2 { font-size: 17px; margin: 16px 0 8px; }
.message-content h3 { font-size: 15px; margin: 16px 0 8px; }
.message-content table { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 13px; }
.message-content th, .message-content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.message-content th { background: var(--bg-secondary); font-weight: 600; }

.message-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.file-badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; background: var(--bg-secondary);
    border: 1px solid var(--border); border-radius: 6px;
    font-size: 12px; color: var(--text-secondary);
}
.file-badge svg { color: var(--accent); }

.typing-indicator { display: flex; gap: 4px; padding: 4px 0; }
.typing-indicator span {
    width: 7px; height: 7px; background: var(--accent);
    border-radius: 50%; animation: typing 1.4s infinite; opacity: 0.4;
}
.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% { opacity: 0.4; } 30% { opacity: 1; transform: translateY(-4px); } }

/* ═══ Chat Input ═══ */
.chat-input-wrapper { padding: 0 24px 20px; max-width: 828px; margin: 0 auto; width: 100%; }
.attached-files { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 8px; }

.attached-file {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 6px 10px; background: var(--bg-secondary);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 12px; color: var(--text-secondary);
}
.attached-file .remove-file {
    width: 16px; height: 16px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; border-radius: 50%; transition: all var(--transition);
}
.attached-file .remove-file:hover { color: var(--danger); }

.chat-input-container {
    display: flex; align-items: flex-end; gap: 8px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 6px 8px;
    transition: border-color var(--transition);
    box-shadow: var(--shadow-sm);
}
.chat-input-container:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

#message-input {
    flex: 1; background: none; border: none; color: var(--text-primary);
    font-family: var(--font-main); font-size: 14.5px; line-height: 1.5;
    padding: 8px 4px; resize: none; max-height: 200px; outline: none;
}
#message-input::placeholder { color: var(--text-muted); }

.btn-icon {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none; color: var(--text-secondary);
    cursor: pointer; border-radius: var(--radius-sm);
    transition: all var(--transition); flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-tiny { width: 26px; height: 26px; }
.btn-attach { color: var(--text-muted); }
.btn-attach:hover { color: var(--accent); }

.btn-send {
    width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent); border: none; color: white;
    cursor: pointer; border-radius: var(--radius-sm);
    transition: all var(--transition); flex-shrink: 0;
}
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-send:not(:disabled):hover { background: var(--accent-hover); transform: scale(1.05); }

/* ═══ Modal ═══ */
.modal {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    animation: modal-in 0.2s ease;
}
@keyframes modal-in { from { opacity: 0; } }

.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(4px); }

.modal-content {
    position: relative; background: var(--bg-modal);
    border: 1px solid var(--border); border-radius: var(--radius-xl);
    width: 90%; max-width: 500px; box-shadow: var(--shadow-lg);
    animation: modal-slide 0.25s ease;
}
@keyframes modal-slide { from { transform: translateY(20px) scale(0.97); opacity: 0; } }

.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 24px 20px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

.field-input, .field-textarea {
    background: var(--bg-primary); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 10px 14px;
    color: var(--text-primary); font-family: var(--font-main);
    font-size: 14px; outline: none; transition: border-color var(--transition);
}
.field-input:focus, .field-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.field-textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: 11px; color: var(--text-muted); line-height: 1.5; }

select.field-input { cursor: pointer; }
select.field-input option { background: var(--bg-modal); color: var(--text-primary); }

.field-range { -webkit-appearance: none; height: 4px; background: var(--border); border-radius: 2px; outline: none; }
.field-range::-webkit-slider-thumb {
    -webkit-appearance: none; width: 18px; height: 18px;
    background: var(--accent); border-radius: 50%; cursor: pointer;
    border: 2px solid white; box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

.btn-primary {
    padding: 10px 24px; background: var(--accent); color: white;
    border: none; border-radius: var(--radius-sm);
    font-family: var(--font-main); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    padding: 10px 24px; background: var(--bg-secondary); color: var(--text-secondary);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: var(--font-main); font-size: 14px; cursor: pointer;
    transition: all var(--transition);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }

.settings-status {
    padding: 10px 14px; border-radius: var(--radius-sm);
    font-size: 13px; display: none;
}
.settings-status.success { display: block; background: rgba(26,156,90,0.08); color: var(--accent-green); border: 1px solid rgba(26,156,90,0.2); }
.settings-status.error { display: block; background: rgba(229,62,62,0.08); color: var(--danger); border: 1px solid rgba(229,62,62,0.2); }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 99; }

/* ═══ Model Dropdown ═══ */
.model-dropdown { position: relative; padding-bottom: 8px; }

.model-dropdown-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--bg-secondary);
    color: var(--text-secondary); font-family: var(--font-main);
    font-size: 12.5px; font-weight: 500; cursor: pointer;
    transition: all var(--transition);
}
.model-dropdown-btn:hover { border-color: var(--accent); color: var(--text-primary); }

.model-dropdown-menu {
    display: none; position: absolute; bottom: 100%; left: 0;
    margin-bottom: 6px; min-width: 300px;
    background: var(--bg-modal); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
    z-index: 50; overflow: hidden;
    animation: dropdown-in 0.15s ease;
}
.model-dropdown-menu.open { display: block; }
@keyframes dropdown-in { from { opacity: 0; transform: translateY(8px); } }

.model-option {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 14px; cursor: pointer;
    transition: background var(--transition);
}
.model-option:hover { background: var(--bg-hover); }
.model-option.active { background: var(--accent-glow); }
.model-option-icon { font-size: 18px; width: 28px; text-align: center; flex-shrink: 0; }
.model-option-info { display: flex; flex-direction: column; }
.model-option-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.model-option-desc { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

/* ═══ Mic Button ═══ */
.btn-mic { color: var(--text-muted); }
.btn-mic:hover { color: var(--accent); }
.btn-mic.recording {
    color: #e53e3e;
    animation: mic-pulse 1s infinite;
}
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.btn-mic.recording svg { filter: drop-shadow(0 0 4px rgba(229,62,62,0.4)); }

/* ═══ Responsive ═══ */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.visible { display: block; }
    .mobile-header { display: flex; }
    .message-inner { padding: 0 16px; }
    .chat-input-wrapper { padding: 0 16px 12px; }
    .empty-actions { flex-direction: column; }
}

@media (max-width: 480px) {
    .sidebar { width: 85vw; min-width: 85vw; }
}

/* ═══ Stop Button ═══ */
.btn-send rect { transition: all 0.2s; }
