* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #1e1e2e; color: #cdd6f4; }

/* ==================== 滚动条样式 ==================== */

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #45475a transparent;
}

/* Webkit (Chrome/Edge/Safari) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #45475a;
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: #585b70; }
::-webkit-scrollbar-corner { background: transparent; }

/* 头部 */
.header { background: #181825; padding: 10px 16px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #313244; flex-shrink: 0; }
.header h1 { font-size: 16px; color: #cba6f7; }
.header input, .header button { padding: 5px 10px; border: 1px solid #45475a; border-radius: 6px; background: #313244; color: #cdd6f4; font-size: 12px; }
.header button { cursor: pointer; background: #cba6f7; color: #1e1e2e; font-weight: bold; border: none; }
.header button:hover { background: #b4befe; }
.header .status { margin-left: auto; font-size: 11px; padding: 3px 8px; border-radius: 10px; }
.header .status.ok { background: #a6e3a1; color: #1e1e2e; }
.header .status.err { background: #f38ba8; color: #1e1e2e; }

/* 工作区 */
.workspace { display: flex; flex: 1; overflow: hidden; }

/* 最近打开文件 */
#wsRecentFiles {
    background: #11111b;
    flex-shrink: 0;
}
.ws-recent-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 6px;
    border-bottom: 1px solid #1e1e2e;
}
.ws-recent-title {
    font-size: 9px;
    color: #6c7086;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.ws-recent-clear {
    font-size: 9px;
    color: #6c7086;
    cursor: pointer;
    padding: 1px 4px;
    border-radius: 3px;
}
.ws-recent-clear:hover { color: #f38ba8; background: #1e1e2e; }
.ws-recent-list { padding: 2px; }
.ws-recent-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 6px;
    font-size: 10px;
    color: #a6adc8;
    cursor: pointer;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ws-recent-item:hover { background: #1e1e2e; color: #cdd6f4; }
.ws-recent-icon { flex-shrink: 0; }
.ws-recent-name { overflow: hidden; text-overflow: ellipsis; }

/* 左边工具栏 */
.sidebar { width: 240px; display: flex; flex-direction: column; gap: 0; border-right: 1px solid #313244; transition: width 0.15s; overflow: hidden; background: #181825; min-width: 0; }
.sidebar.collapsed { width: 0; overflow: hidden; border-right: none; }

/* 侧栏标签页 */
.sidebar-tab-bar { display: flex; gap: 0; padding: 8px 8px 0 8px; background: #11111b; border-bottom: 1px solid #313244; flex-shrink: 0; }
.sidebar-tab-bar .tab-btn { flex: 1; text-align: center; font-size: 11px; }
.sidebar-tab-panel { display: none; flex: 1; overflow: hidden; }
.sidebar-tab-panel.active { display: flex; }
.sidebar-tab-panel .panel { border: none; border-radius: 0; }

/* 侧栏拖拽手柄 */
.sidebar-resize-handle {
    width: 4px; cursor: col-resize; background: transparent;
    flex-shrink: 0; transition: background 0.15s;
}
.sidebar-resize-handle:hover, .sidebar-resize-handle.dragging { background: #cba6f7; }

/* 右侧工作区 */
.main-area { flex: 1; display: flex; flex-direction: column; gap: 0; padding: 8px; overflow: hidden; }

/* 主工作区（代码编辑器 + Claude） */
.primary-workspace { display: flex; gap: 0; flex: 2; min-height: 0; }

/* 其它工作区（终端 + VSCode） */
.secondary-workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 1; min-height: 0; }

/* 拖拽分隔条 */
.resize-handle {
    width: 6px; cursor: col-resize; background: transparent;
    flex-shrink: 0; transition: background 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.resize-handle::before {
    content: ''; width: 2px; height: 24px; background: #45475a; border-radius: 1px;
}
.resize-handle:hover, .resize-handle.dragging { background: #313244; }
.resize-handle:hover::before, .resize-handle.dragging::before { background: #585b70; }

/* 垂直拖拽手柄（primary / secondary 之间） */
.resize-handle-v {
    height: 6px; cursor: row-resize; background: transparent;
    flex-shrink: 0; transition: background 0.15s;
    display: flex; align-items: center; justify-content: center;
}
.resize-handle-v::before {
    content: ''; width: 24px; height: 2px; background: #45475a; border-radius: 1px;
}
.resize-handle-v:hover, .resize-handle-v.dragging { background: #313244; }
.resize-handle-v:hover::before, .resize-handle-v.dragging::before { background: #585b70; }

/* 面板通用 */
.panel { background: #181825; border: 1px solid #313244; border-radius: 8px; display: flex; flex-direction: column; overflow: hidden; }
.panel-header { padding: 6px 10px; background: #11111b; font-size: 12px; font-weight: bold; color: #89b4fa; border-bottom: 1px solid #313244; display: flex; justify-content: space-between; align-items: center; }
.panel-body { flex: 1; overflow-y: auto; padding: 6px; font-size: 12px; font-family: 'Cascadia Code', 'Fira Code', monospace; }

/* 文件浏览器 */
.panel-body .entry { padding: 2px 4px; cursor: pointer; border-radius: 4px; display: flex; gap: 4px; align-items: center; font-size: 11px; }
.panel-body .entry:hover { background: #313244; }
.panel-body .entry.dir { color: #89b4fa; }
.panel-body .entry.file { color: #a6e3a1; }
.panel-body .entry .size { margin-left: auto; color: #6c7086; font-size: 10px; }
.path-bar { padding: 3px 6px; font-size: 10px; color: #6c7086; border-bottom: 1px solid #313244; display: flex; gap: 3px; flex-wrap: wrap; }
.path-bar span { cursor: pointer; color: #89b4fa; }
.path-bar span:hover { text-decoration: underline; }

/* Git */
.git-item { padding: 1px 0; display: flex; gap: 6px; font-size: 11px; }
.git-item .tag { font-size: 9px; padding: 1px 4px; border-radius: 3px; }
.git-item .tag.M { background: #f9e2af; color: #1e1e2e; }
.git-item .tag.A { background: #a6e3a1; color: #1e1e2e; }
.git-item .tag.D { background: #f38ba8; color: #1e1e2e; }
.git-item .tag.? { background: #6c7086; color: #cdd6f4; }

/* 代码查看器 */
.file-viewer { padding: 6px; white-space: pre-wrap; font-size: 12px; line-height: 1.5; max-height: 100%; overflow: auto; }
.file-viewer .line-num { color: #6c7086; margin-right: 6px; user-select: none; font-size: 11px; }

/* 终端 */
.terminal-output { white-space: pre-wrap; color: #a6e3a1; font-size: 11px; }
.terminal-input { display: flex; gap: 4px; padding: 3px 0; border-top: 1px solid #313244; margin-top: 3px; }
.terminal-input input { flex: 1; background: #1e1e2e; border: 1px solid #45475a; color: #cdd6f4; padding: 3px 6px; border-radius: 4px; font-family: monospace; font-size: 11px; }
.terminal-input button { background: #89b4fa; border: none; color: #1e1e2e; padding: 3px 8px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 11px; }

/* 按钮 */
.btn-sm { font-size: 10px; padding: 2px 6px; background: #45475a; color: #cdd6f4; border: none; border-radius: 4px; cursor: pointer; }
.btn-sm:hover { background: #585b70; }
.btn-primary { font-size: 10px; padding: 2px 6px; background: #89b4fa; color: #1e1e2e; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; }
.btn-primary:hover { background: #b4befe; }

/* 输入框 */
.input-sm { width: 100%; background: #1e1e2e; border: 1px solid #45475a; color: #cdd6f4; padding: 3px 6px; border-radius: 4px; font-size: 11px; margin-bottom: 3px; }

/* 辅助 */
.loading { color: #6c7086; font-style: italic; }
.error { color: #f38ba8; }
.cmd-row { display: flex; gap: 4px; margin-bottom: 4px; }
.cmd-row input { flex: 1; }
.cmd-row button { white-space: nowrap; }

/* 标签页 */
.tab-bar { display: flex; gap: 2px; padding: 4px 8px; background: #11111b; border-bottom: 1px solid #313244; }
.tab-btn { padding: 4px 12px; border: none; border-radius: 4px; background: transparent; color: #6c7086; font-size: 12px; cursor: pointer; }
.tab-btn:hover { color: #cdd6f4; }
.tab-btn.active { background: #313244; color: #89b4fa; font-weight: bold; }
.tab-body { flex: 1; overflow: hidden; position: relative; }
.tab-panel { position: absolute; inset: 0; display: none; overflow-y: auto; padding: 6px; }
.tab-panel.active { display: block; }

/* Markdown 渲染 */
.markdown-body { line-height: 1.5; }
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
    color: #cba6f7; margin: 6px 0 3px; line-height: 1.3;
}
.markdown-body h1 { font-size: 13px; }
.markdown-body h2 { font-size: 12px; }
.markdown-body h3 { font-size: 11px; }
.markdown-body p { margin: 3px 0; }
.markdown-body ul, .markdown-body ol { margin: 3px 0; padding-left: 16px; }
.markdown-body li { margin: 1px 0; }
.markdown-body blockquote {
    margin: 3px 0; padding: 3px 8px; border-left: 2px solid #89b4fa;
    background: #1e1e2e; color: #cdd6f4;
}
.markdown-body code {
    background: #313244; padding: 1px 4px; border-radius: 3px;
    font-size: 11px; color: #f9e2af;
}
.markdown-body pre {
    background: #11111b; padding: 6px; border-radius: 6px;
    overflow-x: auto; margin: 4px 0; position: relative;
}
.markdown-body pre code { background: transparent; padding: 0; font-size: 10px; color: #a6e3a1; }
.copy-btn {
    position: absolute; top: 4px; right: 4px;
    font-size: 9px; padding: 2px 6px;
    background: #45475a; color: #cdd6f4;
    border: none; border-radius: 4px; cursor: pointer;
    opacity: 0; transition: opacity 0.15s;
}
.markdown-body pre:hover .copy-btn { opacity: 1; }
.copy-btn:hover { background: #585b70; }
.markdown-body a { color: #89b4fa; text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body hr { border: none; border-top: 1px solid #313244; margin: 6px 0; }
.markdown-body strong { color: #f9e2af; }
.markdown-body em { color: #cba6f7; font-style: italic; }
.markdown-body del { color: #6c7086; }

/* 代码编辑器 */
.editor-wrapper { display: flex; flex: 1; overflow: hidden; }
.line-gutter {
    background: #11111b; color: #6c7086; padding: 6px 4px;
    font-size: 12px; line-height: 1.5; text-align: right;
    overflow: hidden; user-select: none; min-width: 36px;
    border-right: 1px solid #313244;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    white-space: pre;
}
/* 编辑器叠加容器（overlay + textarea） */
.editor-overlay-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

/* 高亮叠加层（位于 textarea 后方） */
.highlight-overlay {
    position: absolute;
    inset: 0;
    margin: 0;
    padding: 6px;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre;
    overflow-y: auto;
    overflow-x: auto;
    background: #181825;
    border: none;
    pointer-events: none;
    tab-size: 4;
    -moz-tab-size: 4;
    word-spacing: normal;
    letter-spacing: normal;
}
.highlight-overlay code {
    font-family: inherit;
    font-size: inherit;
    background: transparent;
    padding: 0;
    color: inherit;
}

/* 代码编辑器 textarea（透明，叠加在高亮层上方） */
.code-editor {
    position: absolute;
    inset: 0;
    z-index: 1;
    background: transparent;
    color: transparent;
    caret-color: #cdd6f4;
    border: none;
    outline: none;
    padding: 6px;
    font-size: 12px;
    line-height: 1.5;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    resize: none;
    white-space: pre;
    overflow: auto;
    tab-size: 4;
    -moz-tab-size: 4;
    word-spacing: normal;
    letter-spacing: normal;
    width: 100%;
}
.code-editor::selection {
    background: rgba(137, 180, 250, 0.3);
    color: transparent;
}

/* 编辑器状态栏 */
.editor-statusbar {
    display: flex;
    gap: 16px;
    padding: 3px 10px;
    background: #11111b;
    border-top: 1px solid #313244;
    font-size: 11px;
    color: #6c7086;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    flex-shrink: 0;
}
.editor-statusbar span { white-space: nowrap; }

/* 编辑器查找栏 */
.editor-find-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: #11111b;
    border-bottom: 1px solid #313244;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.editor-find-bar .input-sm { width: auto; margin: 0; }
.editor-find-bar .btn-sm { font-size: 10px; padding: 1px 5px; }

/* 语法高亮预览 */
.highlight-preview {
    flex: 1;
    overflow: auto;
    padding: 6px;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    background: #181825;
    white-space: pre;
    counter-reset: hl-line;
}
.highlight-preview .hl-line {
    display: block;
    min-height: 1lh;
}
.highlight-preview .hl-line::before {
    content: counter(hl-line);
    counter-increment: hl-line;
    display: inline-block;
    width: 30px;
    margin-right: 8px;
    text-align: right;
    color: #6c7086;
    user-select: none;
}
/* 语法着色 */
.hl-comment { color: #6c7086; font-style: italic; }
.hl-string  { color: #a6e3a1; }
.hl-number  { color: #fab387; }
.hl-keyword { color: #cba6f7; font-weight: bold; }
.hl-type    { color: #89b4fa; }
.hl-function { color: #89dceb; }
.hl-plain   { color: #cdd6f4; }

/* Toast 通知 */
.toast {
    position: fixed; top: 10px; right: 10px; padding: 8px 16px;
    border-radius: 6px; font-size: 12px; z-index: 1000;
    animation: fadeIn 0.2s;
}
.toast.ok { background: #a6e3a1; color: #1e1e2e; }
.toast.err { background: #f38ba8; color: #1e1e2e; }
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 右键菜单 */
.context-menu {
    position: fixed; background: #181825; border: 1px solid #313244;
    border-radius: 6px; padding: 4px 0; z-index: 100;
    min-width: 120px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.context-menu-item {
    padding: 4px 12px; font-size: 11px; cursor: pointer; color: #cdd6f4;
}
.context-menu-item:hover { background: #313244; }
.context-menu-item.danger { color: #f38ba8; }

/* 离线横幅 */
#offlineBanner {
    display: none;
    background: #f38ba8;
    color: #1e1e2e;
    text-align: center;
    padding: 6px;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

/* 连接状态可点击 */
#connStatus.status.err { cursor: pointer; }

/* 侧边栏切换按钮 */
#sidebarToggle {
    background: transparent;
    color: #cdd6f4;
    font-size: 16px;
    padding: 4px 8px;
    cursor: pointer;
    border: 1px solid #45475a;
    border-radius: 4px;
    line-height: 1;
}
#sidebarToggle:hover { background: #313244; color: #cba6f7; }

/* 移动端：侧边栏默认折叠 + 主布局垂直堆叠 */
@media (max-width: 768px) {
    .sidebar { width: 0; padding: 0; overflow: hidden; border-right: none; }
    .sidebar.expanded { width: 240px; padding: 8px; border-right: 1px solid #313244; }
    .main-area { padding: 4px; }
    /* 编辑器 + Claude 垂直堆叠 */
    .primary-workspace { flex-direction: column; flex: 1.5; }
    .primary-workspace .panel { min-width: auto; }
    /* 终端 + VSCode 垂直堆叠 */
    .secondary-workspace { grid-template-columns: 1fr; flex: 1; }
    .secondary-workspace .panel { grid-column: auto !important; }
    /* 隐藏水平拖拽手柄 */
    .resize-handle { display: none; }
    /* 垂直拖拽手柄缩小 */
    .resize-handle-v { height: 8px; }
    .resize-handle-v::before { width: 32px; height: 2px; }
    /* 头部输入框缩小 */
    .header { padding: 6px 8px; gap: 6px; flex-wrap: wrap; }
    .header h1 { font-size: 14px; }
    .header input { width: auto; flex: 1; min-width: 80px; }
}

/* 滚动到底部浮动按钮 */
.scroll-bottom-btn {
    position: absolute;
    bottom: 8px;
    right: 12px;
    background: #45475a;
    color: #cdd6f4;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10px;
    cursor: pointer;
    display: none;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    transition: background 0.15s;
}
.scroll-bottom-btn:hover { background: #585b70; }

/* Git Diff 预览 */
.diff-preview {
    margin: 2px 0 4px 20px;
    border: 1px solid #313244;
    border-radius: 4px;
    overflow: hidden;
    font-size: 10px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    max-height: 200px;
    overflow-y: auto;
}
.diff-line {
    padding: 1px 6px;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.4;
}
.diff-line.add { background: #1e3a1e; color: #a6e3a1; }
.diff-line.del { background: #3a1e1e; color: #f38ba8; }
.diff-line.ctx { background: transparent; color: #6c7086; }
.diff-line.hdr { background: #1e1e2e; color: #89b4fa; font-weight: bold; }

/* Git 文件操作按钮行 */
.git-file-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.git-stage-btn {
    font-size: 9px;
    padding: 0 4px;
    background: #45475a;
    color: #cdd6f4;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1.4;
}
.git-stage-btn:hover { background: #a6e3a1; color: #1e1e2e; }
.git-file-name {
    cursor: pointer;
    color: #cdd6f4;
}
.git-file-name:hover { text-decoration: underline; color: #89b4fa; }

/* 错误重试按钮 */
.error-retry-btn {
    font-size: 10px;
    padding: 1px 6px;
    background: transparent;
    color: #f38ba8;
    border: 1px solid #f38ba8;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 4px;
}
.error-retry-btn:hover { background: #f38ba8; color: #1e1e2e; }

/* Tool use blocks */
.tool-use-block { margin: 3px 0; border-radius: 4px; overflow: hidden; }
.tool-use-block pre { margin: 0; }

/* Permission denial blocks */
.permission-denial-block { margin: 6px 0; padding: 6px 8px; background: #2a1520; border: 1px solid #f38ba8; border-radius: 6px; }

/* 面板全屏 */
.panel.fullscreen {
    position: fixed; inset: 0; z-index: 99;
    border-radius: 0; border: none;
}
.panel-header .fullscreen-btn {
    background: transparent;
    color: #6c7086;
    border: none;
    font-size: 14px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}
.panel-header .fullscreen-btn:hover { color: #cba6f7; }

/* 拖拽上传 */
.drop-zone {
    border: 2px dashed #45475a;
    border-radius: 6px;
    margin: 4px;
    padding: 20px;
    text-align: center;
    color: #6c7086;
    font-size: 11px;
    transition: border-color 0.2s, background 0.2s;
}
.drop-zone.active {
    border-color: #cba6f7;
    background: rgba(203, 166, 247, 0.08);
    color: #cba6f7;
}

/* Git 提交历史 */
.git-log-section { margin-bottom: 8px; }
.git-log-header { color: #89b4fa; font-size: 10px; margin-bottom: 3px; font-weight: bold; }
.git-log-item {
    padding: 2px 0;
    border-bottom: 1px solid #1e1e2e;
    font-size: 10px;
    line-height: 1.4;
}
.git-log-hash { color: #f9e2af; margin-right: 4px; font-family: monospace; }
.git-log-date { color: #6c7086; margin-right: 4px; font-size: 9px; }
.git-log-author { color: #89b4fa; margin-right: 4px; font-size: 9px; }
.git-log-msg { color: #cdd6f4; word-break: break-all; }

/* xterm.js PTY terminal */
#xterm-container .xterm { height: 100%; }
#xterm-container .xterm-viewport { background-color: #11111b !important; }
#xterm-container .xterm-screen { background-color: #11111b !important; }
