.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--current-sidebar-width);
  background-color: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  padding:
    calc(var(--space-md) + env(safe-area-inset-top))
    12px
    calc(12px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  z-index: 10;
  transition: width 180ms ease;
}

.sidebar-upper {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.sidebar-top {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 32px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.nav-item {
  width: 100%;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  text-align: left;
  transition: background-color 150ms ease, color 150ms ease;
}

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

.nav-item.is-active {
  background-color: var(--bg-subtle);
  color: var(--accent-primary);
  font-weight: 600;
}

.nav-item:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.nav-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 120ms ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

.brand-logo-btn {
  position: relative;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  overflow: hidden;
  pointer-events: none;
  transition: background-color 150ms ease;
}

.brand-logo-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.brand-mark {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  background: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-soft);
  flex-shrink: 0;
  transition: opacity 150ms ease;
}

.brand-expand-icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background-color: rgba(17, 18, 22, 0.58);
  color: var(--bg-base);
  opacity: 0;
  transition: opacity 150ms ease;
}

.brand-expand-icon svg {
  width: 16px;
  height: 16px;
}

.brand-name {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  transition: opacity 120ms ease;
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  transition: right 180ms ease, background-color 150ms ease, color 150ms ease;
}

.sidebar-toggle svg {
  width: 16px;
  height: 16px;
  transition: transform 180ms ease;
}

.sidebar-footer {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 32px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
  padding-right: 40px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background-color: var(--accent-primary);
  color: var(--bg-base);
  font-size: 0.75rem;
  font-weight: 600;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity 120ms ease;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 150ms ease, color 150ms ease;
}

.icon-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--accent-primary);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

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

.sidebar-footer .icon-btn {
  position: absolute;
  right: 0;
  bottom: 0;
}

/* Collapsed sidebar state: keep logo mark, nav icons, and avatar stationary */
.app-layout.is-collapsed .brand-name,
.app-layout.is-collapsed .nav-label,
.app-layout.is-collapsed .user-name {
  opacity: 0;
  pointer-events: none;
}

.app-layout.is-collapsed .sidebar-toggle {
  opacity: 0;
  pointer-events: none;
}

.app-layout.is-collapsed .brand-logo-btn {
  pointer-events: auto;
  cursor: pointer;
}

.app-layout.is-collapsed .brand-logo-btn:hover .brand-mark,
.app-layout.is-collapsed .brand-logo-btn:focus-visible .brand-mark {
  opacity: 0.45;
}

.app-layout.is-collapsed .brand-logo-btn:hover .brand-expand-icon,
.app-layout.is-collapsed .brand-logo-btn:focus-visible .brand-expand-icon {
  opacity: 1;
}

.app-layout.is-collapsed .sidebar-footer {
  padding-top: 52px;
}

.app-layout.is-collapsed .sidebar-footer .icon-btn {
  right: auto;
  left: 0;
  bottom: 40px;
}
