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

:root {
  --bg: #0f0f11;
  --surface: #18181b;
  --surface-alt: #1f1f23;
  --border: #2a2a2e;
  --border-light: #3a3a3e;
  --text: #e4e4e7;
  --text-dim: #71717a;
  --text-muted: #52525b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-bg: rgba(99, 102, 241, 0.1);
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --sidebar-width: 260px;
  --topbar-height: 44px;
  --tab-height: 36px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans SC', sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── 顶部栏 ── */
#topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 16px;
  -webkit-app-region: drag;
}

.topbar-left { display: flex; align-items: center; }
.brand { font-size: 14px; font-weight: 600; letter-spacing: -0.3px; -webkit-app-region: no-drag; }

.topbar-center {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; -webkit-app-region: no-drag; }
.topbar-sep { width: 1px; height: 16px; background: var(--border); }
.topbar-btn { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 4px; transition: 0.15s; }
.topbar-btn:hover { color: var(--text); background: var(--hover-bg); }

/* 连接状态指示 */
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.gray { background: var(--text-muted); }
.dot.green { background: var(--green); box-shadow: 0 0 4px var(--green); }
.dot.yellow { background: var(--yellow); box-shadow: 0 0 4px var(--yellow); }
.dot.red { background: var(--red); box-shadow: 0 0 4px var(--red); }

/* 浏览/编辑切换 */
.mode-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.mode-switch .toggle {
  position: relative;
  width: 30px; height: 16px;
}

.mode-switch .toggle input { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-track {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 8px;
  transition: 0.2s;
}

.toggle-knob {
  position: absolute;
  width: 12px; height: 12px;
  left: 2px; top: 2px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked ~ .toggle-track { background: var(--accent); }
.toggle input:checked ~ .toggle-knob { left: 16px; }
.mode-switch input:checked ~ #modeLabelEdit { color: var(--accent); }

/* ── 主体 ── */
#body {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

/* ── 左侧栏 ── */
#sidebar {
  width: var(--sidebar-width);
  min-width: 120px;
  max-width: 60vw;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

/* ── 拖动条 ── */
.splitter {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.splitter:hover,
.splitter.active {
  background: var(--accent);
}

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

.sidebar-title { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── 会话选择栏 ── */
.chat-header {
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px 10px;
}
.chat-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.session-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}
.session-select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  padding: 3px 6px;
  cursor: pointer;
  outline: none;
}
.session-select:focus { border-color: var(--accent); }

/* 上下文统计 */
.session-stats {
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 0 4px;
  text-align: center;
  line-height: 1.4;
}
.session-stats .stat-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.session-stats .stat-dot.ok { background: #22c55e; }
.session-stats .stat-dot.warn { background: #eab308; }
.icon-btn {
  background: none; border: none;
  color: var(--text-dim); cursor: pointer;
  font-size: 16px; line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: 0.15s;
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }

/* ── 搜索栏 ── */
.search-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.search-icon { flex-shrink: 0; }
.search-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s;
  min-width: 0;
}
.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-dim); opacity: 0.6; }
.search-clear {
  background: none; border: none;
  color: var(--text-dim); cursor: pointer;
  font-size: 12px; padding: 2px 4px;
  border-radius: 3px;
  flex-shrink: 0;
}
.search-clear:hover { color: var(--text); background: var(--surface-alt); }
.search-results {
  flex: 1;
  overflow: auto;
  padding: 4px 0;
  display: none;
}
.search-results:not([hidden]) { display: block; }
.search-result-item {
  padding: 6px 12px 6px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  transition: background 0.1s;
}
.search-result-item:hover { background: var(--surface-alt); }
.search-result-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-result-path { color: var(--text-dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; max-width: 40%; }
.search-result-type {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 6px;
  flex-shrink: 0;
}
.search-result-type.dir { background: #6366f122; color: #818cf8; }
.search-result-type.file { background: #22c55e22; color: #4ade80; }
.search-empty {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
}
.search-truncated {
  padding: 4px 16px 8px;
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  opacity: 0.7;
}

/* ── 文件树 ── */
.file-tree {
  flex: 1;
  overflow: auto;
  padding: 4px 0;
}

.file-tree::-webkit-scrollbar { width: 4px; height: 4px; }
.file-tree::-webkit-scrollbar-track { background: transparent; }
.file-tree::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.tree-node {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  transition: 0.1s;
  position: relative;
}

.tree-node:hover { background: var(--surface-alt); color: var(--text); }
.tree-node.active { background: var(--accent-bg); color: var(--accent); }

/* ── 引导线 ── */
.tree-node {
  position: relative;
}

/* 子容器竖线，位置由 --guide-left 控制 */
.tree-children[data-guide]::before {
  content: '';
  position: absolute;
  left: var(--guide-left);
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border-light);
  pointer-events: none;
}

/* 每个子节点的横线，位置由 --branch-left 控制 */
.tree-node[data-branch]::after {
  content: '';
  position: absolute;
  left: var(--branch-left);
  top: 50%;
  height: 1px;
  width: 9px;
  background: var(--border-light);
  pointer-events: none;
}

/* 最后一项竖线只画一半 */
.tree-children[data-guide] > div:last-child::before {
  content: '';
  position: absolute;
  left: var(--guide-left);
  top: 0;
  width: 1px;
  height: 50%;
  background: var(--border-light);
  pointer-events: none;
}

.tree-node .chevron {
  width: 16px;
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
  text-align: center;
}

.tree-node .chevron.expanded {
  transform: rotate(90deg);
}

.tree-node .chevron.empty {
  visibility: hidden;
}

.tree-node .icon {
  width: 16px;
  flex-shrink: 0;
  font-size: 12px;
}

.tree-node .name {
  flex: 1;
}

.tree-children { display: none; }
.tree-children.open { display: block; position: relative; }
.tree-children > div { position: relative; }

/* ── 右侧聊天面板 ── */
#chatPanel {
  width: 300px;
  min-width: 200px;
  max-width: 50vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#chatPanel .sidebar-badge {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── 中间内容区 ── */
#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ── 标签栏 ── */
.tab-bar {
  display: flex;
  align-items: center;
  height: var(--tab-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}

.tab-bar::-webkit-scrollbar { height: 2px; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 1px; }

.tabs {
  display: flex;
  height: 100%;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 100%;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  user-select: none;
  transition: 0.1s;
}

.tab:hover { color: var(--text); background: var(--surface-alt); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.tab .tab-close {
  font-size: 14px; color: var(--text-muted);
  display: none; padding: 0 2px;
}
.tab:hover .tab-close { display: inline; }
.tab .tab-close:hover { color: var(--text); }

/* ── 面板 ── */
#panels {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.panel {
  display: none;
  width: 100%; height: 100%;
  overflow-y: auto;
}

.panel.active { display: flex; flex-direction: column; }

/* ── 欢迎页 ── */
.welcome-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--text-dim);
  font-size: 14px;
}

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

/* ── 聊天面板 ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── 思考过程（可折叠） ── */
.chat-thinking {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  margin-bottom: 4px;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  flex-shrink: 0;
}
.chat-thinking summary {
  padding: 4px 10px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 11px;
  user-select: none;
  opacity: 0.7;
  transition: opacity 0.15s;
  display: list-item;
  list-style: disclosure-closed inside;
}
.chat-thinking[open] summary {
  list-style: disclosure-open inside;
  border-bottom: 1px solid var(--border);
}
.chat-thinking summary:hover { opacity: 1; }
.chat-thinking pre {
  margin: 0;
  padding: 4px 10px 8px;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.chat-msg {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  flex-shrink: 0;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 2px;
}

.chat-msg.hanako {
  align-self: flex-start;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}

.chat-msg.hanako.error {
  align-self: center;
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 12px;
  max-width: 100%;
}

.chat-msg.hanako p { margin: 4px 0; }
.chat-msg.hanako code {
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus { border-color: var(--accent); }
.chat-input:disabled { opacity: 0.4; }

.btn-primary {
  padding: 8px 16px;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── 文件编辑器 ── */
.file-editor-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.file-editor-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
}

.file-editor-header .file-path {
  font-family: var(--font-mono);
  font-size: 12px;
}

.file-editor-header .file-info {
  margin-left: auto;
  color: var(--text-muted);
}

.file-editor-header .save-btn {
  display: none;
  padding: 4px 12px;
  background: var(--accent);
  border: none;
  border-radius: 4px;
  color: white;
  font-size: 12px;
  cursor: pointer;
}

.file-editor-header .save-btn.show { display: block; }
.file-editor-header .save-btn:hover { background: var(--accent-hover); }

.file-editor-header .clip-btn,
.file-editor-header .paste-btn {
  background: none; border: 1px solid var(--border);
  color: var(--text-dim); cursor: pointer;
  font-size: 14px; padding: 2px 8px;
  border-radius: 4px;
  transition: 0.15s;
  line-height: 1.4;
}
.file-editor-header .clip-btn:hover,
.file-editor-header .paste-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--accent);
}

.monaco-container {
  flex: 1;
  min-height: 0;
}

/* ── 二进制/错误提示 ── */
.file-info-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 40px;
  text-align: center;
}

.file-info-card .file-detail {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── 加载提示 ── */
.loading { color: var(--text-dim); font-size: 12px; padding: 8px 12px; }

/* ── 响应式 ── */
@media (max-width: 640px) {
  #sidebar { width: 180px; }
  .topbar-center { font-size: 11px; }
}
