/* --- Theme Definitions --- */
[data-theme="light"] {
    --bg-color: #f1f5f9;
    --panel-bg: #ffffff;
    --border-color: rgba(0,0,0,0.1);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --user-msg-bg: rgba(59,130,246,0.1);
    --bot-msg-bg: rgba(0,0,0,0.03);
    --session-item-bg: rgba(0,0,0,0.05);
    --session-item-hover: rgba(0,0,0,0.08);
}
[data-theme="cobalt"] {
    --bg-color: #1e293b;
    --panel-bg: #1e293b;
    --border-color: rgba(59,130,246,0.3);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --accent-color: #60a5fa;
    --accent-hover: #3b82f6;
    --danger-color: #f87171;
    --danger-hover: #ef4444;
    --user-msg-bg: rgba(96,165,250,0.2);
    --bot-msg-bg: rgba(15,23,42,0.4);
    --session-item-bg: rgba(255,255,255,0.05);
    --session-item-hover: rgba(255,255,255,0.1);
}
[data-theme="dark"] {
    --bg-color: #0f1115;
    --panel-bg: #191c24;
    --border-color: rgba(255,255,255,0.1);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --user-msg-bg: rgba(59,130,246,0.15);
    --bot-msg-bg: rgba(255,255,255,0.05);
    --session-item-bg: rgba(255,255,255,0.05);
    --session-item-hover: rgba(255,255,255,0.1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100dvh;
    overflow: hidden;
}
button, input, textarea, select { font-family: inherit; font-size: 0.95rem; }
button { cursor: pointer; border: none; }
.glass-panel { background: var(--panel-bg); border-right: 1px solid var(--border-color); }
.hidden { display: none !important; }

/* Login */
.login-overlay {
    position: fixed; inset: 0; background: var(--bg-color);
    z-index: 1000; display: flex; align-items: center; justify-content: center;
}
.login-box {
    padding: 2rem; border-radius: 12px; width: min(90vw, 360px);
    box-shadow: 0 10px 40px rgba(0,0,0,0.2); border: 1px solid var(--border-color);
}
.login-box h2 { margin-bottom: 1rem; text-align: center; }
.login-box input {
    width: 100%; margin-bottom: 0.75rem; padding: 0.6rem; border-radius: 8px;
    border: 1px solid var(--border-color); background: var(--bg-color); color: var(--text-primary);
}
.error-text { color: var(--danger-color); font-size: 0.85rem; margin-top: 0.5rem; }

/* Layout */
.app-layout { display: flex; height: 100dvh; overflow: hidden; }
.icon-sidebar {
    width: 60px; min-width: 60px; height: 100%; display: flex; flex-direction: column;
    justify-content: space-between; align-items: center; padding: 0.75rem 0;
    border-right: 1px solid var(--border-color); z-index: 105;
}
.icon-sidebar-top, .icon-sidebar-bottom {
    display: flex; flex-direction: column; gap: 0.75rem; align-items: center; width: 100%;
}
.icon-sidebar-top { flex: 1; overflow-y: auto; }
.project-icons { display: flex; flex-direction: column; gap: 0.5rem; align-items: center; width: 100%; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 8px; background: transparent;
    color: var(--text-secondary); display: flex; justify-content: center; align-items: center;
    transition: all 0.2s; border: 1px solid transparent; font-size: 1.1rem;
}
.icon-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
.project-icon-btn {
    width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border-color);
    background: transparent; color: var(--text-secondary); font-weight: 600; font-size: 1rem;
    display: flex; justify-content: center; align-items: center; cursor: pointer; transition: all 0.2s;
}
.project-icon-btn:hover, .project-icon-btn.active {
    background: var(--accent-color); color: white; border-color: var(--accent-color);
}

/* Sidebar */
.sidebar {
    width: 260px; min-width: 260px; height: 100%; display: flex; flex-direction: column;
    padding: 1rem; border-right: 1px solid var(--border-color); transition: margin-left 0.3s ease;
    z-index: 100;
}
.sidebar.collapsed { margin-left: -260px; }
.sidebar-header { margin-bottom: 1rem; }
.sidebar-header h2 { font-size: 1.25rem; }
.sidebar-section h3 { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.5rem; }
.session-list { list-style: none; overflow-y: auto; flex: 1; }
.session-list li {
    padding: 0.6rem 0.75rem; border-radius: 8px; margin-bottom: 0.4rem;
    background: var(--session-item-bg); cursor: pointer; font-size: 0.9rem;
    display: flex; justify-content: space-between; align-items: center;
}
.session-list li:hover, .session-list li.active { background: var(--session-item-hover); }
.session-list li .del { opacity: 0; }
.session-list li:hover .del { opacity: 1; color: var(--danger-color); }

/* Main chat */
.chat-container { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
    height: 56px; padding: 0 1rem; display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid var(--border-color); flex-shrink: 0;
}
.header-right { display: flex; gap: 0.5rem; align-items: center; }
.chat-body { flex: 1; display: flex; overflow: hidden; }
.chat-main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-history { flex: 1; overflow-y: auto; padding: 1rem; }
.welcome-message { text-align: center; margin-top: 20%; color: var(--text-secondary); }
.message { max-width: 90%; margin-bottom: 1rem; padding: 0.9rem 1rem; border-radius: 12px; line-height: 1.55; }
.message.user { background: var(--user-msg-bg); margin-left: auto; }
.message.bot { background: var(--bot-msg-bg); }
.message code { background: rgba(0,0,0,0.15); padding: 0.15rem 0.3rem; border-radius: 4px; }
.message pre { background: rgba(0,0,0,0.15); padding: 0.75rem; border-radius: 8px; overflow-x: auto; }
.tool-outputs { margin-top: 0.75rem; padding: 0.5rem 0.75rem; background: rgba(0,0,0,0.08); border-radius: 6px; font-size: 0.85rem; }
.tool-outputs ul { margin-left: 1.2rem; }
.tool-outputs li { margin-top: 0.2rem; }

/* Input */
.chat-input-container { padding: 0.75rem 1rem; border-top: 1px solid var(--border-color); }
.chat-form { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-form textarea {
    flex: 1; resize: none; min-height: 44px; max-height: 180px; border-radius: 10px;
    border: 1px solid var(--border-color); background: var(--bg-color); color: var(--text-primary);
    padding: 0.7rem 0.9rem; outline: none;
}
.send-btn {
    width: 44px; height: 44px; border-radius: 10px; background: var(--accent-color); color: white;
    display: flex; justify-content: center; align-items: center;
}
.send-btn:hover { background: var(--accent-hover); }
.composer-hints { display: flex; gap: 1rem; margin-top: 0.5rem; align-items: center; }
.custom-dropdown { position: relative; }
.dropdown-trigger {
    background: var(--session-item-bg); color: var(--text-secondary); border: 1px solid var(--border-color);
    border-radius: 6px; padding: 0.35rem 0.6rem; display: flex; align-items: center; gap: 0.3rem; font-size: 0.85rem;
}
.dropdown-menu {
    position: absolute; bottom: 100%; left: 0; margin-bottom: 8px; min-width: 200px;
    background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2); z-index: 200;
}
.dropdown-search input {
    width: 100%; padding: 0.5rem; border: none; border-bottom: 1px solid var(--border-color);
    background: transparent; color: var(--text-primary);
}
.dropdown-list { max-height: 240px; overflow-y: auto; }
.dropdown-item { padding: 0.5rem 0.75rem; cursor: pointer; font-size: 0.85rem; }
.dropdown-item:hover, .dropdown-item.active { background: var(--accent-color); color: white; }

/* Terminal */
.shell-terminal-panel {
    width: 45%; min-width: 320px; border-left: 1px solid var(--border-color);
    display: flex; flex-direction: column; background: var(--panel-bg);
}
.shell-terminal-header {
    height: 44px; padding: 0 0.75rem; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center; font-size: 0.9rem; font-weight: 600;
}
.shell-terminal-controls { display: flex; gap: 0.4rem; }
.shell-terminal-container { flex: 1; padding: 0.5rem; overflow: hidden; }

/* Right panel / File manager */
.right-panel {
    width: 320px; min-width: 320px; border-left: 1px solid var(--border-color);
    display: flex; flex-direction: column; background: var(--panel-bg);
}
.right-panel-header {
    height: 48px; padding: 0 0.75rem; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center; font-weight: 600;
}
.file-manager-breadcrumb { padding: 0.5rem 0.75rem; font-size: 0.85rem; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); }
.file-manager-container { flex: 1; overflow-y: auto; padding: 0.5rem; }
.file-item {
    display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem; border-radius: 6px; cursor: pointer;
}
.file-item:hover { background: var(--session-item-hover); }
.file-item .actions { margin-left: auto; display: flex; gap: 0.3rem; opacity: 0; }
.file-item:hover .actions { opacity: 1; }
.file-viewer {
    position: absolute; inset: 0; background: var(--panel-bg); display: flex; flex-direction: column; z-index: 50;
}
.file-viewer-header {
    height: 44px; padding: 0 0.75rem; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
}
.file-viewer pre { flex: 1; padding: 1rem; overflow: auto; font-size: 0.85rem; }

/* Buttons */
.primary-btn {
    background: var(--accent-color); color: white; padding: 0.55rem 1rem; border-radius: 8px; font-weight: 500;
}
.primary-btn:hover { background: var(--accent-hover); }
.secondary-btn {
    background: var(--session-item-bg); color: var(--text-primary); padding: 0.5rem 0.9rem;
    border-radius: 8px; border: 1px solid var(--border-color); transition: all 0.2s;
}
.secondary-btn:hover { background: var(--session-item-hover); }
.secondary-btn.active { background: var(--accent-color); color: white; border-color: var(--accent-color); }
.danger-btn { background: var(--danger-color); color: white; padding: 0.5rem 0.9rem; border-radius: 8px; }
.danger-btn:hover { background: var(--danger-hover); }
.w-full { width: 100%; }
.mb-4 { margin-bottom: 1rem; }

/* Settings Modal */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500;
    display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-content {
    width: min(900px, 95vw); height: min(85vh, 800px); border-radius: 12px;
    display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border-color);
}
.modal-header {
    height: 56px; padding: 0 1rem; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-body { display: flex; flex: 1; overflow: hidden; }
.settings-tabs {
    width: 180px; border-right: 1px solid var(--border-color); display: flex; flex-direction: column; padding: 0.75rem;
}
.settings-tab {
    text-align: left; padding: 0.6rem 0.75rem; border-radius: 6px; background: transparent;
    color: var(--text-secondary); margin-bottom: 0.25rem;
}
.settings-tab.active, .settings-tab:hover { background: var(--session-item-hover); color: var(--text-primary); }
.settings-panels { flex: 1; overflow-y: auto; padding: 1rem; }
.settings-panel { display: none; }
.settings-panel.active { display: block; }
.settings-panel h3 { margin-bottom: 1rem; }
.settings-panel label { display: block; margin-bottom: 0.75rem; color: var(--text-secondary); font-size: 0.9rem; }
.settings-panel input, .settings-panel select, .settings-panel textarea {
    width: 100%; margin-top: 0.35rem; padding: 0.55rem; border-radius: 6px;
    border: 1px solid var(--border-color); background: var(--bg-color); color: var(--text-primary);
}
.provider-row {
    display: grid; grid-template-columns: 1fr 2fr 80px 60px 40px; gap: 0.5rem; align-items: center;
    margin-bottom: 0.5rem; padding: 0.5rem; background: var(--session-item-bg); border-radius: 6px;
}
.provider-row input[type="number"] { width: 100%; }
.model-list { max-height: 240px; overflow-y: auto; margin: 1rem 0; }
.model-row { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border-color); font-size: 0.85rem; }
/* note: generic .hidden rule already exists above */
.task-form { display: grid; gap: 0.5rem; margin-top: 1rem; }
.task-form input, .task-form select { margin: 0; }
.record-row {
    display: flex; justify-content: space-between; align-items: center; padding: 0.5rem;
    background: var(--session-item-bg); border-radius: 6px; margin-bottom: 0.5rem; font-size: 0.9rem;
}
.mcp-box { background: var(--session-item-bg); padding: 1rem; border-radius: 8px; margin: 1rem 0; }
