:root,
[data-theme="dark"] {
    --bg-primary: #0f0f23;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #16213e;
    --bg-input: #1e1e3a;
    --bg-msg-user: #2d2d5e;
    --bg-msg-ai: #1a1a2e;
    --bg-code: #0d0d1a;
    --text-primary: #e0e0ff;
    --text-secondary: #8888aa;
    --text-muted: #555577;
    --accent: #6c63ff;
    --accent-hover: #7f78ff;
    --accent-dim: rgba(108, 99, 255, 0.15);
    --border: #2a2a4a;
    --danger: #ff4757;
    --success: #2ed573;
    --warning: #ffa502;
    --shadow: rgba(0, 0, 0, 0.3);
    --radius: 16px;
    --radius-sm: 10px;
    --transition: 0.2s ease;
    --sidebar-overlay-bg: rgba(0,0,0,0.5);
    --logo-shadow: rgba(108, 99, 255, 0.3);
    --scrollbar-thumb-hover: #555577;
}

[data-theme="light"] {
    --bg-primary: #f5f5fa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef0f6;
    --bg-input: #eef0f6;
    --bg-msg-user: #e0e3ff;
    --bg-msg-ai: #ffffff;
    --bg-code: #f0f1f5;
    --text-primary: #1a1a2e;
    --text-secondary: #6b6b8a;
    --text-muted: #9999aa;
    --accent: #6c63ff;
    --accent-hover: #5a52e0;
    --accent-dim: rgba(108, 99, 255, 0.1);
    --border: #d8dae6;
    --danger: #e03e4d;
    --success: #22b85c;
    --warning: #e09500;
    --shadow: rgba(0, 0, 0, 0.08);
    --sidebar-overlay-bg: rgba(0,0,0,0.3);
    --logo-shadow: rgba(108, 99, 255, 0.2);
    --scrollbar-thumb-hover: #aaaacc;
}

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

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

#app { height: 100%; display: flex; flex-direction: column; }

.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px 32px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
}
.btn-secondary:hover { background: var(--accent-dim); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
}
.btn-danger:hover { background: rgba(255, 71, 87, 0.1); }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
}
.icon-btn:hover { background: var(--accent-dim); }

.input-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.input-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.input-group input[type="text"],
.input-group input[type="password"],
.input-group select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    outline: none;
    transition: border-color var(--transition);
}
.input-group input:focus,
.input-group select:focus { border-color: var(--accent); }

.input-group input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
}
.input-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.input-hint { font-size: 12px; color: var(--text-muted); }

.toggle-group { flex-direction: row; align-items: center; justify-content: space-between; }
.toggle { position: relative; display: inline-block; width: 48px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--border);
    border-radius: 26px;
    transition: var(--transition);
}
.toggle-slider:before {
    content: "";
    position: absolute;
    height: 20px; width: 20px;
    left: 3px; bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(22px); }

.error-msg {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    padding: 8px;
    background: rgba(255, 71, 87, 0.1);
    border-radius: var(--radius-sm);
}

.btn-loader {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Setup Screen */
#setup-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--bg-primary), var(--bg-secondary), var(--bg-tertiary));
}

.setup-container {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.logo-area { text-align: center; }
.logo-icon {
    width: 80px; height: 80px;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    border-radius: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    font-weight: 800;
    color: white;
    margin-bottom: 16px;
    box-shadow: 0 8px 32px var(--logo-shadow);
}
.logo-area h1 { font-size: 28px; font-weight: 700; }
.subtitle { color: var(--text-secondary); margin-top: 4px; font-size: 14px; }

.setup-form {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.setup-modes h3 {
    font-size: 14px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.mode-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.mode-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px 10px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.mode-icon { font-size: 24px; }
.mode-name { font-weight: 600; font-size: 14px; }
.mode-desc { font-size: 11px; color: var(--text-muted); }

/* Chat Screen */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 56px;
    position: relative;
    z-index: 10;
}
.header-left, .header-right { display: flex; align-items: center; gap: 4px; }
.header-title h2 { font-size: 16px; font-weight: 600; line-height: 1.2; }
.mode-label {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 88%;
    padding: 12px 16px;
    border-radius: var(--radius);
    line-height: 1.6;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.message.user {
    background: var(--bg-msg-user);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.message.assistant {
    background: var(--bg-msg-ai);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.message.system {
    background: var(--bg-tertiary);
    align-self: center;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 90%;
    border-radius: var(--radius-sm);
}

.message.assistant pre {
    background: var(--bg-code);
    border-radius: 8px;
    padding: 12px;
    overflow-x: auto;
    margin: 8px 0;
    position: relative;
    border: 1px solid var(--border);
}
.message.assistant code {
    font-family: 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
    font-size: 13px;
    line-height: 1.5;
}
.message.assistant :not(pre) > code {
    background: var(--bg-code);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}
.message.assistant p { margin: 6px 0; }
.message.assistant ul, .message.assistant ol { margin: 6px 0; padding-left: 20px; }
.message.assistant li { margin: 3px 0; }
.message.assistant h1, .message.assistant h2, .message.assistant h3, .message.assistant h4 {
    margin: 12px 0 6px;
}
.message.assistant blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}
.message.assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}
.message.assistant th, .message.assistant td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    font-size: 13px;
}
.message.assistant th { background: var(--bg-tertiary); }

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px 8px 0 0;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: -8px;
    margin-top: 8px;
    border: 1px solid var(--border);
    border-bottom: none;
}
.code-header + pre { border-top-left-radius: 0; border-top-right-radius: 0; }
.code-header-actions { display: flex; gap: 4px; align-items: center; }
.copy-btn, .download-btn {
    background: var(--accent-dim);
    border: none;
    color: var(--accent);
    padding: 3px 10px;
    border-radius: 4px;
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition);
}
.copy-btn:hover, .download-btn:hover { background: var(--accent); color: white; }

.msg-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.msg-action-btn {
    background: var(--accent-dim);
    border: none;
    color: var(--accent);
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition);
}
.msg-action-btn:hover { background: var(--accent); color: white; }
.msg-action-btn.copied { background: var(--success); color: white; }

.filepath-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-dim);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
    word-break: break-all;
}
.filepath-badge:hover { background: var(--accent); color: white; }
.filepath-badge::before { content: '📁'; font-size: 11px; }

.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 4px 0;
}
.thinking-dots span {
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.4s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.6); } 40% { transform: scale(1); } }

/* Chat Input */
.chat-input-area {
    padding: 8px 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}

.mode-selector {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.mode-selector::-webkit-scrollbar { display: none; }
.mode-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition);
}
.mode-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}
.mode-btn:hover:not(.active) {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
#message-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: 24px;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 44px;
    line-height: 1.4;
    transition: border-color var(--transition);
    font-family: inherit;
}
#message-input:focus { border-color: var(--accent); }

.send-btn, .stop-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.stop-btn { background: var(--danger); }
.stop-btn:hover { background: #ff6b7a; }

/* Sidebar */
.sidebar {
    position: fixed;
    left: -300px;
    top: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: left 0.3s ease;
}
.sidebar.open { left: 0; }
.sidebar-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--sidebar-overlay-bg);
    z-index: 99;
    display: none;
}
.sidebar-overlay.active { display: block; }
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 16px; }

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.conv-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition);
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}
.conv-item:hover { background: var(--accent-dim); }
.conv-item.active { background: var(--accent-dim); border: 1px solid var(--accent); }
.conv-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 4px;
    display: none;
}
.conv-item:hover .conv-delete { display: block; }
.conv-delete:hover { color: var(--danger); background: rgba(255,71,87,0.1); }

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

/* Settings Screen */
.settings-container {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.settings-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}
.settings-header h2 { font-size: 18px; }

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}
.settings-section {
    margin-bottom: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.settings-section:last-child { border-bottom: none; }
.settings-section h3 {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}
.settings-section .btn-secondary,
.settings-section .btn-danger { margin-top: 8px; }

.about-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

.theme-toggle-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
}
.theme-toggle-btn:hover { background: var(--accent-dim); }

.changelog-list {
    list-style: none;
    padding: 0;
}
.changelog-list li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    line-height: 1.5;
}
.changelog-list li:last-child { border-bottom: none; }
.changelog-version {
    font-weight: 700;
    color: var(--accent);
    font-size: 14px;
}
.changelog-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 8px;
}
.changelog-list li ul {
    margin: 4px 0 0 16px;
    padding: 0;
    list-style: disc;
}
.changelog-list li ul li {
    border-bottom: none;
    padding: 2px 0;
    color: var(--text-secondary);
    font-size: 12px;
}

.terminal-panel {
    display: none;
    flex-direction: column;
    background: var(--bg-code);
    border-top: 1px solid var(--border);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    flex-shrink: 0;
}
.terminal-panel.open {
    max-height: 45vh;
}
.terminal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.terminal-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
}
.terminal-info {
    font-size: 11px;
    color: var(--text-muted);
    font-family: monospace;
}
.terminal-body {
    overflow-y: auto;
    padding: 8px;
    font-family: 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
    font-size: 12px;
    line-height: 1.5;
    flex: 1;
    min-height: 60px;
    max-height: calc(45vh - 40px);
}
.term-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
    font-size: 12px;
}
.term-entry {
    margin-bottom: 8px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.term-tool {
    background: var(--bg-secondary);
}
.term-tool-header {
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 700;
    font-family: monospace;
    background: var(--bg-tertiary);
}
.term-action {
    font-weight: 800;
    letter-spacing: 0.5px;
}
.term-target {
    color: var(--text-secondary);
    font-weight: 400;
    margin-left: 4px;
    word-break: break-all;
}
.term-code-block {
    background: var(--bg-secondary);
}
.term-file-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.term-lang {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
}
.term-copy-btn {
    background: var(--accent-dim);
    border: none;
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 10px;
    cursor: pointer;
    font-family: inherit;
}
.term-copy-btn:hover { background: var(--accent); color: white; }
.term-code {
    padding: 8px 10px;
    margin: 0;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
    overflow-x: auto;
    max-height: 200px;
    overflow-y: auto;
    background: transparent;
}

.retry-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 8px 24px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}
.retry-btn:hover { background: var(--accent-hover); transform: scale(1.05); }

.terminal-toggle-btn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px;
    background: var(--bg-tertiary);
    border: none;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.terminal-toggle-btn:hover {
    background: var(--accent-dim);
    color: var(--accent);
}
.terminal-icon {
    font-size: 10px;
}
.terminal-label {
    font-family: 'Fira Code', monospace;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 11px;
}

/* File Tree Panel */
.file-tree-panel {
    position: fixed;
    right: -300px;
    top: 0;
    bottom: 0;
    width: 280px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}
.file-tree-panel.open { right: 0; }
.file-tree-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--sidebar-overlay-bg);
    z-index: 99;
    display: none;
}
.file-tree-overlay.active { display: block; }
.file-tree-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.file-tree-header h3 { font-size: 16px; }
.file-tree-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}
.file-tree-footer {
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}
.ftree-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 40px 20px;
    line-height: 1.6;
}
.ftree-folder { }
.ftree-folder .ftree-children {
    display: none;
}
.ftree-folder.open > .ftree-children {
    display: block;
}
.ftree-node {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    cursor: pointer;
    transition: background var(--transition);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ftree-node:hover {
    background: var(--accent-dim);
}
.ftree-dir {
    color: var(--text-primary);
    font-weight: 600;
}
.ftree-arrow {
    font-size: 8px;
    color: var(--text-muted);
    width: 10px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.ftree-dirname {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ftree-file {
    color: var(--text-secondary);
}
.ftree-ext {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--accent-dim);
    color: var(--accent);
    padding: 1px 5px;
    border-radius: 3px;
    flex-shrink: 0;
    letter-spacing: 0.3px;
}
.ftree-fname {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* File Viewer */
.file-viewer {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
    flex-direction: column;
    background: var(--bg-primary);
}
.file-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 52px;
    gap: 8px;
}
.file-viewer-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}
#file-viewer-name {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.fv-lang {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--accent-dim);
    color: var(--accent);
    padding: 2px 6px;
    border-radius: 3px;
    flex-shrink: 0;
}
.file-viewer-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.fv-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 5px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.fv-btn:active { background: var(--accent-dim); }
.fv-btn-save {
    background: var(--success);
    color: white;
    border-color: var(--success);
}
.fv-btn-save:active { opacity: 0.8; }
.file-viewer-body {
    flex: 1;
    overflow: auto;
    padding: 0;
}
.file-viewer-body pre {
    margin: 0;
    padding: 16px;
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-break: break-all;
    background: transparent;
}
.file-viewer-editor {
    flex: 1;
    display: flex;
}
.file-viewer-editor textarea {
    flex: 1;
    width: 100%;
    padding: 16px;
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-code);
    border: none;
    outline: none;
    resize: none;
    -webkit-overflow-scrolling: touch;
}

/* Dev Tools Banner */
.dev-tools-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    margin: 8px 12px;
    background: rgba(255, 165, 2, 0.1);
    border: 1px solid var(--warning);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    animation: fadeIn 0.3s ease;
}
.dtb-icon {
    font-size: 16px;
    flex-shrink: 0;
}
.dtb-msg {
    flex: 1;
    line-height: 1.4;
}
.dtb-install-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
}
.dtb-install-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.dtb-dismiss-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0 4px;
    flex-shrink: 0;
}

/* Responsive */
@media (max-width: 480px) {
    .message { max-width: 92%; }
    .setup-container { gap: 24px; }
    .mode-cards { gap: 8px; }
    .mode-card { padding: 10px 8px; }
}

/* Terminal Full Screen */
.term-screen-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #0d0d0d;
}
.term-screen-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    min-height: 52px;
}
.term-screen-header h2 { font-size: 16px; flex: 1; }
.term-screen-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}
.term-cwd-display {
    font-family: 'Fira Code', 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--success);
    background: rgba(46, 213, 115, 0.1);
    padding: 3px 8px;
    border-radius: 4px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.term-output {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    font-family: 'Fira Code', 'JetBrains Mono', 'Cascadia Code', monospace;
    font-size: 13px;
    line-height: 1.5;
    color: #e0e0e0;
    background: #0d0d0d;
    -webkit-overflow-scrolling: touch;
    word-break: break-all;
    white-space: pre-wrap;
}
.term-output .term-line { margin-bottom: 1px; }
.term-output .term-cmd { color: var(--success); font-weight: 700; }
.term-output .term-err { color: var(--danger); }
.term-output .term-info { color: var(--accent); }
.term-output .term-success { color: var(--success); }
.term-output .term-warning { color: var(--warning); }
.term-output .term-path { color: var(--accent); text-decoration: underline; }
.term-input-area {
    padding: 8px 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
}
.term-quick-actions {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.term-quick-actions::-webkit-scrollbar { display: none; }
.term-quick-btn {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-family: 'Fira Code', monospace;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.term-quick-btn:active { background: var(--accent-dim); color: var(--accent); }
.term-input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.term-prompt {
    color: var(--success);
    font-family: 'Fira Code', monospace;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}
.term-input {
    flex: 1;
    background: #0d0d0d;
    border: 1px solid var(--border);
    color: #e0e0e0;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Fira Code', monospace;
    outline: none;
}
.term-input:focus { border-color: var(--accent); }
.term-run-btn, .term-stop-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--success);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.term-stop-btn { background: var(--danger); }

.mode-btn-term {
    flex-shrink: 0;
}

/* Deploy button in messages */
.deploy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, var(--success), var(--accent));
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 6px;
    transition: all var(--transition);
}
.deploy-btn:hover { opacity: 0.9; transform: scale(1.02); }
.deploy-btn:active { transform: scale(0.98); }

.install-apk-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 4px;
    margin-left: 6px;
}

/* Dev Setup Screen */
.devsetup-status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
    margin-bottom: 16px;
}
.devsetup-status p { margin-bottom: 6px; }
.devsetup-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}
.devsetup-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}
.devsetup-progress-text {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Command history popup */
.term-history {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 10;
    display: none;
}
.term-history.visible { display: block; }
.term-history-item {
    padding: 8px 12px;
    font-size: 12px;
    font-family: 'Fira Code', monospace;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.term-history-item:hover { background: var(--accent-dim); color: var(--text-primary); }

