.sidebar {
  position: sticky;
  top: 0;
  left: 0;
  z-index: var(--z-sidebar);
  max-height: 100vh;
  width: 16rem;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar__header {
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
  justify-content: flex-start;
  border-bottom: 1px solid var(--border);
  height: 4rem;
  flex-shrink: 0;
}

.sidebar__brandmark {
  width: 2rem;
  height: 2rem;
  border-radius: .5rem;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #10b981;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
}

.sidebar__brandmark svg {
  width: 1.25rem;
  height: 1.25rem;
}
.sidebar__brandmark--has-logo,
.sidebar__brandmark:has(img) {
  background: none; border: none; border-radius: 0;
}

.sidebar__brandtext {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Close button — hidden on desktop */
.sidebar__close {
  display: none;
  margin-left: auto;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: .375rem;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.sidebar__close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.sidebar__close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.sidebar__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem .75rem;
  display: grid;
  gap: 1.5rem;
}

.sidebar-group__title {
  padding: 0 .75rem;
  margin-bottom: .5rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.sidebar-group__items {
  display: grid;
  gap: .25rem;
}

.sidebar-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  border: 0;
  border-radius: .5rem;
  background: transparent;
  color: var(--text-secondary);
  font-size: .875rem;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease;
}

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

.sidebar-item--active {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

.sidebar-item__icon {
  width: 1.25rem;
  height: 1.25rem;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.sidebar-item__icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.sidebar-item--active .sidebar-item__icon {
  color: #059669;
}

.sidebar-item__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-item--footer {
  color: var(--text-secondary);
}

.sidebar-item--footer:hover {
  background: #fef2f2;
  color: #dc2626;
}

.sidebar-item--footer:hover .sidebar-item__icon {
  color: #dc2626;
}

/* Overlay */
.sidebar-overlay {
  display: none;
}

[data-theme="dark"] .sidebar__brandmark { background: rgba(16,185,129,.1); border-color: rgba(16,185,129,.2); }
[data-theme="dark"] .sidebar__brandmark--has-logo,
[data-theme="dark"] .sidebar__brandmark:has(img) { background: none; border: none; }
[data-theme="dark"] .sidebar-item--active { background: rgba(16,185,129,.12); color: #34d399; }
[data-theme="dark"] .sidebar-item--active .sidebar-item__icon { color: #34d399; }
[data-theme="dark"] .sidebar-item--footer:hover { background: rgba(220,38,38,.1); color: #f87171; }
[data-theme="dark"] .sidebar-item--footer:hover .sidebar-item__icon { color: #f87171; }

/* ── Mobile: slide-out drawer ── */
@media (max-width: 920px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 17rem;
    height: 100vh;
    z-index: var(--z-overlay);
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
    box-shadow: none;
  }

  .sidebar--open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }

  .sidebar__close {
    display: flex;
  }

  .sidebar__footer {
    border-top: 1px solid var(--border);
    border-bottom: 0;
  }

  /* Overlay behind sidebar */
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-overlay) - 1);
    background: rgba(0,0,0,.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
  }
  .sidebar-overlay--visible {
    opacity: 1;
    pointer-events: auto;
  }

  /* Larger touch targets on mobile */
  .sidebar-item {
    padding: .625rem .75rem;
    font-size: .9375rem;
  }
}
