#code-view {
  display: none;
  height: calc(100vh - 56px);
}

#code-view.active {
  display: flex;
}

.code-sidebar {
  width: 280px;
  min-width: 280px;
  border-right: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-primary);
}

.project-selector {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.project-selector:focus {
  outline: none;
  border-color: var(--border-focus);
}

.sidebar-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.sidebar-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 2;
  color: var(--text-tertiary);
  font-size: 13px;
  font-weight: 500;
  transition: opacity var(--transition-normal);
}

.sidebar-overlay svg {
  width: 40px;
  height: 40px;
  fill: var(--text-tertiary);
  opacity: 0.4;
}

.sidebar-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.sidebar-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.sidebar-actions {
  padding: 8px 16px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-primary);
}

.sidebar-btn {
  flex: 1;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-primary);
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.sidebar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.sidebar-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-primary);
  position: relative;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  transition: border-color var(--transition-fast);
}

.search-input-wrap:focus-within {
  border-color: var(--border-focus);
}

.search-input-wrap svg {
  width: 14px;
  height: 14px;
  fill: var(--text-tertiary);
  flex-shrink: 0;
}

.search-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-sans);
  outline: none;
  min-width: 0;
}

.search-input-wrap input::placeholder {
  color: var(--text-tertiary);
}

.search-input-wrap input:disabled {
  opacity: 0.5;
}

.search-results {
  display: none;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 4px;
}

.search-results.active {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-result-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.search-result-item svg {
  width: 14px;
  height: 14px;
  fill: var(--text-tertiary);
  flex-shrink: 0;
}

.search-result-path {
  color: var(--text-tertiary);
  font-size: 11px;
  margin-left: auto;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-no-results {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.file-tree {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 0;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px calc(12px + var(--depth, 0) * 16px);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background-color var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.tree-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tree-item.active {
  background: var(--accent-light);
  color: var(--accent-primary);
}

.tree-item.loading {
  opacity: 0.5;
}

.tree-chevron {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform 200ms ease;
  border-radius: var(--radius-sm);
}

.tree-chevron svg {
  width: 10px;
  height: 10px;
  fill: var(--text-tertiary);
}

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

.tree-chevron-spacer {
  width: 16px;
  flex-shrink: 0;
}

.tree-icon {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.tree-icon svg {
  width: 16px;
  height: 16px;
  fill: var(--text-tertiary);
}

.tree-item.directory .tree-icon svg {
  fill: var(--accent-primary);
}

.tree-item.active .tree-icon svg {
  fill: var(--accent-primary);
}

.tree-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-children {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 200ms ease;
}

.tree-children.expanded {
  grid-template-rows: 1fr;
}

.tree-children-inner {
  overflow: hidden;
}

.tree-loading {
  padding: 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

.code-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.code-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  flex-shrink: 0;
  transition: background-color var(--transition-normal);
}

.code-toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 0;
}

.code-toolbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 1 auto;
  min-width: 0;
}

.toolbar-project-info {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.toolbar-project-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
}

.toolbar-project-lang {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.nav-buttons {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.nav-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.code-breadcrumb {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-wrap: wrap;
  min-width: 0;
}

.code-breadcrumb span {
  cursor: pointer;
  transition: color var(--transition-fast);
}

.code-breadcrumb span:hover {
  color: var(--accent-primary);
}

.code-breadcrumb .sep {
  color: var(--text-tertiary);
  cursor: default;
}

.code-breadcrumb .sep:hover {
  color: var(--text-tertiary);
}

.code-breadcrumb .current {
  color: var(--text-primary);
  font-weight: 500;
}

.code-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  margin-left: 16px; /* space between project/lang and file actions */
}

.file-actions {
  display: flex;
  align-items: center;
  gap: 3px;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-primary);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
}

.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.toolbar-btn:active {
  background: var(--bg-active);
}

.toolbar-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.toolbar-sep {
  width: 1px;
  height: 18px;
  background: var(--border-primary);
  margin: 0 5px;
  flex-shrink: 0;
}

.font-size-value {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  min-width: 22px;
  text-align: center;
  user-select: none;
}

.file-checksum {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  padding: 3px 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  position: relative;
  /* Smooth expand: must animate to a numeric max-width (not `none`) */
  transition: max-width 0.95s cubic-bezier(0.22, 1, 0.36, 1),
              background-color 0.45s ease,
              color 0.45s ease,
              box-shadow 0.45s ease;
}

.file-checksum:hover {
  max-width: min(920px, calc(100vw - 140px));
  background: var(--bg-hover);
  color: var(--text-secondary);
  box-shadow: 0 0 0 1px var(--border-secondary);
}

@media (prefers-reduced-motion: reduce) {
  .file-checksum {
    transition-duration: 0.01ms;
  }
}

.copy-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px) scale(0.96);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: rgba(15, 15, 20, 0.92);
  color: #f0f0f5;
  border: 1px solid rgba(139, 92, 246, 0.25);
  border-radius: var(--radius-xl);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: opacity 300ms cubic-bezier(0.16, 1, 0.3, 1),
              transform 300ms cubic-bezier(0.16, 1, 0.3, 1);
  white-space: nowrap;
}

.copy-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
  pointer-events: auto;
}

.copy-toast .toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  background: rgba(34, 197, 94, 0.15);
  flex-shrink: 0;
}

.copy-toast .toast-icon svg {
  width: 13px;
  height: 13px;
  fill: #4ade80;
}

.copy-toast .toast-hash {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: rgba(240, 240, 245, 0.5);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.code-content {
  flex: 1;
  overflow: auto;
  position: relative;
}

.code-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-tertiary);
  font-size: 15px;
  flex-direction: column;
  gap: 12px;
}

.code-empty svg {
  width: 48px;
  height: 48px;
  fill: var(--text-tertiary);
  opacity: 0.5;
}

.source-view {
  display: flex;
  min-height: 100%;
  font-size: var(--code-font-size, 14px);
  line-height: 1.5;
}

.line-numbers {
  padding: 16px 0;
  text-align: right;
  user-select: none;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-secondary);
  position: sticky;
  left: 0;
  z-index: 1;
  transition: background-color var(--transition-normal);
}

.line-numbers span {
  display: block;
  padding: 0 12px 0 16px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}

.source-code {
  flex: 1;
  padding: 16px 20px;
  overflow-x: auto;
  min-width: 0;
}

.source-code pre {
  margin: 0;
  background: transparent !important;
  tab-size: 4;
}

.source-code code {
  background: transparent !important;
}

.directory-listing {
  padding: 20px;
}

.dir-table {
  width: 100%;
  border-collapse: collapse;
}

.dir-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-primary);
}

.dir-table td {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border-secondary);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.dir-table tr:hover td {
  background: var(--bg-hover);
}

.dir-entry-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
}

.dir-entry-name svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.dir-entry-name.directory svg { fill: var(--accent-primary); }
.dir-entry-name.file svg { fill: var(--text-tertiary); }

.dir-entry-size {
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  font-size: 12px;
}

.commit-panel {
  width: 320px;
  min-width: 320px;
  border-left: 1px solid var(--border-primary);
  background: var(--bg-secondary);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transition: background-color var(--transition-normal);
}

.commit-panel.open {
  display: flex;
}

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

.commit-panel-header h3 {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.commit-panel-header h3 svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.commit-close {
  padding: 4px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}

.commit-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.commit-close svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.commit-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.commit-item {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 4px;
  transition: background-color var(--transition-fast);
}

.commit-item:hover {
  background: var(--bg-hover);
}

.commit-message {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
  line-height: 1.4;
  color: var(--text-primary);
}

.commit-meta {
  font-size: 11px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.commit-hash {
  font-family: var(--font-mono);
  padding: 1px 6px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 11px;
}

.commit-no-history {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 13px;
}

@media (max-width: 1024px) {
  .code-sidebar { width: 240px; min-width: 240px; }
  .commit-panel { width: 280px; min-width: 280px; }
}

@media (max-width: 768px) {
  #code-view.active { flex-direction: column; height: auto; min-height: calc(100vh - 56px); }
  .code-sidebar { width: 100%; min-width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border-primary); }
  .commit-panel { width: 100%; min-width: 100%; border-left: none; border-top: 1px solid var(--border-primary); max-height: 40vh; }

  .code-toolbar {
    position: sticky;
    top: 56px;
    z-index: 10;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
  }
  .code-toolbar-left { order: 1; width: 100%; }
  .code-toolbar-center { order: 2; width: 100%; justify-content: flex-start; }
  .code-toolbar-right { order: 3; width: 100%; }
  .nav-buttons { display: none; }
  .file-checksum { display: none !important; }
  .file-actions { flex-wrap: wrap; }
}
