.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92) 0%, rgba(236, 251, 242, 0.92) 100%);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  padding: 1.6rem 1.2rem 1.75rem;
  position: relative;
  z-index: 1002;
  transition: transform 0.3s ease, opacity 0.3s ease, width 0.3s ease, padding 0.3s ease;
}

.sidebar.closed {
  width: 0;
  min-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.5rem;
}

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

.toggle-button {
  background: rgba(51, 197, 122, 0.16);
  color: var(--color-text);
  border: 1px solid rgba(47, 177, 112, 0.18);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.toggle-button:hover {
  background: rgba(51, 197, 122, 0.28);
  transform: translateY(-1px);
}

.toggle-button:active {
  transform: translateY(0);
}

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

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

.loading-spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(51, 197, 122, 0.18);
  border-top: 2px solid var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

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

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

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

.tree-node-content:hover {
  background: rgba(47, 177, 112, 0.12);
  color: var(--color-text);
}

.tree-node-content.selected {
  background: rgba(51, 197, 122, 0.25);
  color: var(--color-text);
  font-weight: 600;
}

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

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

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

.sidebar-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(18, 43, 31, 0.18);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 1001;
}

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

.sidebar-toggle {
  position: fixed;
  top: clamp(1rem, 5vw, 1.5rem);
  left: clamp(1rem, 5vw, 1.5rem);
  z-index: 1200;
}

.sidebar-toggle .toggle-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  box-shadow: 0 16px 32px rgba(31, 58, 44, 0.18);
}

.sidebar-toggle .toggle-button.open {
  background: rgba(47, 177, 112, 0.22);
}

.sidebar.closed ~ .sidebar-toggle .toggle-button {
  background: rgba(255, 255, 255, 0.92);
}

@media (max-width: 1024px) {
  .sidebar {
    position: absolute;
    top: clamp(0.75rem, 3vw, 1.5rem);
    left: clamp(0.75rem, 3vw, 1.5rem);
    height: calc(100% - clamp(1.5rem, 6vw, 3rem));
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
    transform: translateX(calc(-100% - 2.5rem));
    opacity: 0;
    pointer-events: none;
  }

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

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

  .sidebar {
    position: relative;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    height: auto;
  }
}
@media (max-width: 1024px) {
  .sidebar.closed {
    width: var(--sidebar-width);
    padding: 1.6rem 1.2rem 1.75rem;
    opacity: 0;
  }
}
