.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface-alt);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.25rem 1.75rem;
  color: var(--color-text);
}

.sidebar.closed {
  width: 0;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
  font-weight: 600;
  color: var(--color-text);
}

.toggle-button {
  background: var(--color-surface);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 0.4rem 0.8rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 12px 24px rgba(86, 105, 141, 0.12);
}

.toggle-button:hover {
  color: var(--color-accent);
  border-color: rgba(58, 122, 254, 0.6);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.directory-tree {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.tree-node {
  user-select: none;
}

.tree-node-content {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.65rem;
  border-radius: 12px;
  color: var(--color-muted);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.tree-node-content:hover {
  background: var(--color-accent-soft);
  color: var(--color-accent);
}

.tree-node-content.selected {
  background: rgba(58, 122, 254, 0.16);
  color: var(--color-accent);
  font-weight: 600;
}

.tree-node-icon {
  font-size: 1rem;
  opacity: 0.9;
  transition: transform 0.2s ease;
}

.tree-node-content.selected .tree-node-icon {
  transform: scale(1.06);
}

.tree-node-children {
  margin-top: 0.25rem;
}

.loading,
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.7rem;
  padding: 2.5rem 1rem;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(111, 123, 146, 0.25);
  border-top: 2px solid var(--color-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 23, 35, 0.35);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 50;
}

.sidebar-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar-toggle {
  position: fixed;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 120;
}

.sidebar-toggle .toggle-button {
  padding: 0.45rem 0.9rem;
}

.toggle-button.open {
  color: var(--color-accent);
  border-color: rgba(58, 122, 254, 0.55);
}

@media (max-width: 1024px) {
  .sidebar {
    position: absolute;
    top: clamp(1rem, 5vw, 2rem);
    left: clamp(1rem, 5vw, 2rem);
    height: calc(100% - clamp(2rem, 10vw, 4rem));
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
    transform: translateX(calc(-100% - 2.5rem));
    transition: transform 0.3s ease, opacity 0.3s ease;
    opacity: 0;
    pointer-events: none;
  }

  .sidebar.open {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
  }
}

@media (min-width: 1025px) {
  .sidebar-backdrop,
  .sidebar-toggle {
    display: none;
  }

  .sidebar {
    position: relative;
    transform: none;
    opacity: 1;
    pointer-events: auto;
  }
}
