*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; width: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg-primary); color: var(--text-primary); transition: background 0.2s, color 0.2s; }

/* Login */
.login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--bg-primary); }
.login-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; width: 360px; max-width: 90vw; }
.login-logo { height: 64px; margin: 0 auto 20px; display: block; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); padding: 10px 14px; font-size: 15px; font-family: var(--font); }
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card input::placeholder { color: var(--text-muted); }
.login-card button { background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); padding: 10px 16px; font-size: 15px; cursor: pointer; font-family: var(--font); }
.login-card button:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.login-card a { display: block; text-align: center; margin-top: 16px; color: var(--accent); text-decoration: none; font-size: 14px; }

/* App layout */
#app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { width: var(--sidebar-w); background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; transition: width 0.2s, transform 0.2s; flex-shrink: 0; }
.sidebar.collapsed { width: 0; border-right: none; overflow: hidden; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--border); height: var(--header-h); }
.sidebar-logo { height: var(--logo-h); transition: opacity 0.2s; }
.sidebar-toggle { background: none; border: none; color: var(--text-secondary); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.new-session-btn { margin: 12px 12px 8px; padding: 10px 14px; background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius-sm); color: var(--accent); font-size: 14px; cursor: pointer; font-family: var(--font); text-align: center; }
.new-session-btn:hover { background: var(--accent); color: #fff; }
.session-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.session-item { display: flex; align-items: center; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; color: var(--text-secondary); font-size: 14px; gap: 8px; margin-bottom: 2px; transition: background 0.1s; }
.session-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.session-item.active { background: var(--accent-soft); color: var(--accent); }
.session-item .session-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .session-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 0 4px; border-radius: var(--radius-sm); opacity: 0; transition: opacity 0.1s; }
.session-item:hover .session-close { opacity: 1; }
.session-item .session-close:hover { color: var(--danger); }
.sidebar-footer { display: flex; align-items: center; padding: 8px 12px; border-top: 1px solid var(--border); gap: 8px; }
.user-info { flex: 1; font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.settings-btn, .logout-btn { background: none; border: none; color: var(--text-secondary); font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm); }
.settings-btn:hover, .logout-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.logout-btn:hover { color: var(--danger); }

/* Main area */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top-bar { height: var(--header-h); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); font-size: 14px; color: var(--text-secondary); }
.theme-toggle { background: none; border: none; cursor: pointer; font-size: 20px; padding: 4px 8px; border-radius: var(--radius-sm); }
.theme-toggle:hover { background: var(--bg-hover); }
:root[data-theme="dark"] .theme-icon-dark { display: inline; }
:root[data-theme="dark"] .theme-icon-light { display: none; }
:root[data-theme="light"] .theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-icon-light { display: inline; }

/* Chat area */
.chat-area { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-output { flex: 1; overflow-y: auto; padding: 16px 20px; font-family: var(--font-mono); font-size: 14px; line-height: 1.6; color: var(--text-primary); white-space: pre-wrap; word-break: break-word; }
.chat-output .ansi-bold { font-weight: 700; }
.chat-output .ansi-dim { opacity: 0.6; }
.chat-output .ansi-red { color: #f85149; }
.chat-output .ansi-green { color: #3fb950; }
.chat-output .ansi-yellow { color: #d29922; }
.chat-output .ansi-blue { color: #58a6ff; }
.chat-output .ansi-magenta { color: #bc8cff; }
.chat-output .ansi-cyan { color: #39c5cf; }
.chat-output .ansi-underline { text-decoration: underline; }
.chat-input-bar { display: flex; align-items: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-secondary); }
#chat-input { flex: 1; background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text-primary); padding: 10px 14px; font-size: 14px; font-family: var(--font); resize: none; max-height: 120px; line-height: 1.5; }
#chat-input:focus { outline: none; border-color: var(--accent); }
#chat-input::placeholder { color: var(--text-muted); }
#chat-send { background: var(--accent); color: #fff; border: none; border-radius: var(--radius); padding: 10px 14px; font-size: 16px; cursor: pointer; flex-shrink: 0; }
#chat-send:hover { background: var(--accent-hover); }
#chat-send:disabled { opacity: 0.4; cursor: default; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; width: 400px; max-width: 90vw; max-height: 80vh; overflow-y: auto; }
.modal-card h2 { font-size: 18px; margin-bottom: 16px; }
.settings-section { margin-bottom: 20px; }
.settings-section h3 { font-size: 15px; margin-bottom: 12px; color: var(--text-secondary); }
.settings-section form { display: flex; flex-direction: column; gap: 10px; }
.settings-section input { background: var(--bg-tertiary); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text-primary); padding: 9px 12px; font-size: 14px; font-family: var(--font); }
.settings-section input:focus { outline: none; border-color: var(--accent); }
.settings-section button { background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); padding: 9px 16px; font-size: 14px; cursor: pointer; font-family: var(--font); }
.settings-section button:hover { background: var(--accent-hover); }
.modal-close { background: var(--bg-tertiary); color: var(--text-secondary); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 16px; font-size: 14px; cursor: pointer; font-family: var(--font); margin-top: 8px; width: 100%; }
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Responsive */
@media (max-width: 768px) {
	.sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; width: var(--sidebar-w); }
	.sidebar.collapsed { transform: translateX(-100%); width: var(--sidebar-w); }
	.main-area { width: 100%; }
}

/* Resize handle */
.resize-handle {
	width: 6px;
	cursor: col-resize;
	background: transparent;
	flex-shrink: 0;
	position: relative;
	z-index: 10;
}
.resize-handle:hover, .resize-handle.dragging {
	background: var(--accent);
}

/* Chat messages */
.chat-msg { margin-bottom: 16px; }
.chat-msg-user {
	text-align: right;
}
.chat-msg-user .chat-msg-content {
	display: inline-block;
	background: var(--accent-soft);
	border: 1px solid var(--accent);
	border-radius: var(--radius);
	padding: 8px 14px;
	max-width: 80%;
	text-align: left;
}
.chat-msg-assistant .chat-msg-content {
	max-width: 90%;
}
.chat-msg-content p { margin: 0 0 8px; }
.chat-msg-content p:last-child { margin-bottom: 0; }
.chat-msg-content pre {
	background: var(--bg-tertiary);
	border-radius: var(--radius-sm);
	padding: 12px;
	overflow-x: auto;
	font-size: 13px;
	margin: 8px 0;
}
.chat-msg-content code {
	font-family: var(--font-mono);
	font-size: 13px;
}
.chat-msg-content pre code { background: none; padding: 0; }
.chat-msg-content code { background: var(--bg-tertiary); padding: 2px 6px; border-radius: 3px; }
.chat-msg-content ul, .chat-msg-content ol { margin: 8px 0; padding-left: 24px; }
.chat-msg-content h1, .chat-msg-content h2, .chat-msg-content h3 { margin: 12px 0 6px; }
