.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(320px, 88vw);
  z-index: 45;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  transform: translateX(-100%);
  transition: transform 0.28s var(--theme-easing);
  padding-left: env(safe-area-inset-left);
  padding-bottom: env(safe-area-inset-bottom);
}

.sidebar.is-open {
  transform: translateX(0);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background-color: rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s var(--theme-easing);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-height);
  padding: 0 var(--space-2) 0 var(--space-4);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--accent-blue);
  flex-shrink: 0;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.01em;
  color: var(--text-primary);
}

.brand-accent {
  color: var(--accent-yellow);
}

.sidebar-close {
  flex-shrink: 0;
}

.sidebar-section {
  padding: var(--space-4) var(--space-3) var(--space-2) var(--space-4);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section-actions {
  display: flex;
  gap: var(--space-1);
}

.file-tree {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--space-2) var(--space-3);
}

.tree-node {
  display: flex;
  flex-direction: column;
}

.tree-children {
  padding-left: var(--space-4);
}

.folder-row,
.file-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 34px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.folder-row:hover,
.file-row:hover {
  background-color: var(--bg-hover);
}

.file-row.is-active {
  background-color: var(--bg-active);
  color: var(--text-primary);
}

.file-row.is-active .file-icon {
  color: var(--accent-blue);
}

.tree-toggle {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: 3px;
}

.tree-toggle:hover {
  color: var(--accent-blue);
  background-color: var(--bg-active);
}

.tree-toggle svg {
  width: 10px;
  height: 10px;
}

.tree-node.is-collapsed > .tree-children {
  display: none;
}

.file-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.file-icon.type-html {
  color: var(--accent-blue);
}

.file-icon.type-css {
  color: var(--accent-cyan);
}

.file-icon.type-js {
  color: var(--accent-yellow);
}

.file-icon.type-json {
  color: var(--accent-green);
}

.file-icon.type-image {
  color: var(--accent-violet);
}

.file-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-mono);
}

.rename-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  border: 1px solid var(--accent-blue);
  border-radius: var(--radius-sm);
  padding: 3px var(--space-2);
}

.row-actions {
  flex-shrink: 0;
  display: none;
  align-items: center;
  gap: 2px;
}

.file-row:hover .row-actions,
.folder-row:hover .row-actions {
  display: flex;
}

.row-action {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.row-action:hover {
  color: var(--accent-blue);
  background-color: var(--bg-active);
}

.row-action:last-child:hover {
  color: var(--accent-red);
}

.row-action svg {
  width: 13px;
  height: 13px;
}

@media (max-width: 860px) {
  .row-actions {
    display: flex;
  }

  .folder-row,
  .file-row {
    min-height: 40px;
  }

  .row-action {
    width: 28px;
    height: 28px;
  }

  .tree-toggle {
    width: 20px;
    height: 20px;
  }

  .sidebar-section {
    padding: var(--space-3) var(--space-2) var(--space-2) var(--space-3);
  }

  .sidebar-actions {
    padding: var(--space-2) var(--space-2) max(var(--space-3), env(safe-area-inset-bottom));
  }
}

.sidebar-actions {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.sidebar-actions .action-btn.full-width {
  grid-column: 1 / -1;
}

.new-file-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  height: 34px;
}

.new-file-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--text-primary);
  background-color: var(--bg-canvas);
  border: 1px solid var(--accent-blue);
  border-radius: var(--radius-sm);
  padding: 3px var(--space-2);
}
