/* === Sidebar === */

/* ==================== 侧边栏 - Console 风格 ==================== */
.sidebar {
  width: fit-content;
  min-width: 220px;
  max-width: 400px;
  background: var(--neutral-900);
  color: var(--neutral-300);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
}

.sidebar.collapsed {
  width: 64px;
  min-width: 64px;
  max-width: 64px;
}

.sidebar-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--neutral-800);
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
  padding: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-logo svg {
  flex-shrink: 0;
}

.sidebar-logo span {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-logo span {
  display: none;
}

.sidebar.collapsed .toggle-btn-header {
  display: none;
}

.toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 6px;
  background: none;
  border: none;
  border-radius: 4px;
  color: var(--neutral-400);
  cursor: pointer;
  transition: all 0.15s;
}

.toggle-btn:hover {
  background: var(--neutral-800);
  color: var(--neutral-200);
}

.toggle-btn svg {
  width: 18px;
  height: 18px;
}

/* 折叠时的展开按钮 */
.collapsed-toggle {
  display: none;
  width: 100%;
  padding: 12px 0;
  justify-content: center;
  border-bottom: 1px solid var(--neutral-800);
}

.sidebar.collapsed .collapsed-toggle {
  display: flex;
}

/* 新建按钮区域 */
.sidebar-actions {
  padding: 16px;
  border-bottom: 1px solid var(--neutral-800);
}

.sidebar.collapsed .sidebar-actions {
  padding: 8px;
}

/* 新建按钮 - 中性色 */
.new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: var(--neutral-800);
  color: var(--neutral-300);
  border: 1px solid var(--neutral-700);
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.new-btn:hover {
  background: var(--neutral-700);
  color: #fff;
  border-color: var(--neutral-600);
}

.new-btn svg {
  width: 18px;
  height: 18px;
}

.new-btn span {
  white-space: nowrap;
}

.sidebar.collapsed .new-btn {
  padding: 10px;
}

.sidebar.collapsed .new-btn span {
  display: none;
}

/* 下拉菜单 */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 4px;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  min-width: 160px;
  z-index: 100;
  display: none;
}

.sidebar.collapsed .dropdown-menu {
  left: 100%;
  top: 0;
  margin-top: 0;
  margin-left: 4px;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--neutral-300);
  cursor: pointer;
  transition: background 0.15s;
}

.dropdown-item:first-child {
  border-radius: 7px 7px 0 0;
}

.dropdown-item:last-child {
  border-radius: 0 0 7px 7px;
}

.dropdown-item:hover {
  background: var(--neutral-700);
  color: #fff;
}

.dropdown-item svg {
  width: 16px;
  height: 16px;
  color: var(--neutral-500);
}

/* 文件树 */
.file-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
}

.sidebar.collapsed .file-tree {
  display: none;
}

.tree-item {
  display: flex;
  align-items: center;
  padding: 4px 6px 4px 4px;
  margin: 1px 2px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
  color: var(--neutral-400);
  transition: all 0.15s;
}

.tree-item:hover {
  background: var(--neutral-800);
  color: var(--neutral-200);
}

.tree-item.selected {
  background: var(--primary-600);
  color: #fff;
}

.tree-item.drop-target {
  background: var(--primary-500);
  outline: 2px solid var(--primary-400);
}

.tree-item .chevron {
  width: 14px;
  height: 14px;
  margin-right: 4px;
  color: var(--neutral-600);
  flex-shrink: 0;
  transition: transform 0.15s;
}

.tree-item:hover .chevron {
  color: var(--neutral-500);
}

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

.tree-item .chevron.hidden {
  visibility: hidden;
}

.tree-item .icon {
  width: 14px;
  height: 14px;
  margin-right: 6px;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  flex-shrink: 0;
}

.tree-item .icon.folder {
  color: #fbbf24;
}

.tree-item .icon.file {
  color: var(--neutral-500);
}

.tree-item .icon.file-md {
  color: #60a5fa;
}

.tree-item .name {
  flex: 1;
  white-space: nowrap;
}

.tree-item .name-input {
  flex: 1;
  padding: 2px 6px;
  border: 1px solid var(--primary-500);
  border-radius: 4px;
  font-size: 14px;
  outline: none;
  background: var(--neutral-800);
  color: #fff;
}

.tree-children {
  margin-left: 16px;
}

.tree-children.collapsed {
  display: none;
}

/* ==================== 侧边栏底部 ==================== */
.sidebar-footer {
  border-top: 1px solid var(--neutral-800);
  padding: 8px 12px;
}
.sidebar-footer-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  background: transparent;
  color: var(--neutral-400);
  font-size: 13px;
  cursor: pointer;
  border-radius: 4px;
}
.sidebar-footer-btn:hover { background: var(--neutral-800); color: var(--neutral-200); }
.sidebar.collapsed .sidebar-footer-btn span { display: none; }

/* ==================== 搜索 ==================== */
.search-wrapper { position: relative; padding: 0 12px 8px; }
.search-input {
  width: 100%;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--neutral-700);
  background: var(--neutral-800);
  color: var(--neutral-200);
  font-size: 13px;
  outline: none;
}
.search-input:focus { border-color: var(--primary-500); }
.search-input::placeholder { color: var(--neutral-500); }
.search-results {
  position: absolute;
  top: 100%;
  left: 12px;
  right: 12px;
  background: var(--neutral-800);
  border: 1px solid var(--neutral-700);
  border-radius: 8px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.search-results.hidden { display: none; }
.search-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--neutral-700);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--neutral-700); }
.search-item-title { font-size: 13px; font-weight: 500; color: var(--neutral-100); }
.search-item-snippet { font-size: 12px; color: var(--neutral-400); margin-top: 2px; }
.search-item-snippet mark { background: #fbbf2440; color: inherit; border-radius: 2px; }
.search-empty { padding: 16px; text-align: center; color: var(--neutral-500); font-size: 13px; }

/* ==================== 侧边栏拖拽调宽 ==================== */
.sidebar-resize-handle {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  flex-shrink: 0;
  transition: background 0.2s;
  z-index: 10;
}
.sidebar-resize-handle:hover { background: var(--primary-500); }
