/* Sidebar: brand, grouped nav, collapse footer. Becomes a drawer under 900px. */

.sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: var(--topbar-h);
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar__logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.sidebar__name {
  font-weight: 600;
  font-size: var(--fs-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.nav-group + .nav-group {
  margin-top: var(--s-4);
}

.nav-group__label {
  padding: var(--s-1) var(--s-3);
  margin-bottom: var(--s-1);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  height: 34px;
  padding: 0 var(--s-3);
  border-radius: var(--r-md);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 500;
  white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item--active {
  background: var(--surface-3);
  color: var(--text);
}

.nav-item--active .nav-item__icon {
  color: var(--brand);
}

.nav-item__icon {
  display: flex;
  flex-shrink: 0;
}

.nav-item__label {
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* collapsed: icons only (user toggle on desktop) */
.shell--collapsed .sidebar__name,
.shell--collapsed .nav-item__label,
.shell--collapsed .sidebar__footer .btn__label {
  display: none;
}

.shell--collapsed .sidebar__brand {
  justify-content: center;
  padding: 0;
}

.shell--collapsed .nav-group__label {
  height: 1px;
  padding: 0;
  margin: var(--s-2) var(--s-3);
  background: var(--border);
  font-size: 0;
}

.shell--collapsed .nav-item {
  justify-content: center;
  padding: 0;
}

.shell--collapsed .sidebar__footer .btn {
  width: 100%;
  padding: 0;
}

/* tablet and small laptop: the shell forces a 64px icon rail (see shell.css), so the
   sidebar must look collapsed regardless of the saved user preference */
@media (min-width: 901px) and (max-width: 1100px) {
  .sidebar__name,
  .nav-item__label,
  .sidebar__footer .btn__label {
    display: none;
  }

  .sidebar__brand {
    justify-content: center;
    padding: 0;
  }

  .nav-group__label {
    height: 1px;
    padding: 0;
    margin: var(--s-2) var(--s-3);
    background: var(--border);
    font-size: 0;
  }

  .nav-item {
    justify-content: center;
    padding: 0;
  }

  /* the collapse toggle has no effect on the forced rail, so hide it */
  .sidebar__footer {
    display: none;
  }
}

/* ---------- mobile drawer ---------- */

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: min(var(--sidebar-w), 86vw);
    padding-left: var(--safe-left);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform var(--dur) var(--ease), visibility 0s linear var(--dur);
  }

  .shell--drawer-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--dur) var(--ease), visibility 0s;
  }

  .sidebar__brand {
    height: calc(var(--topbar-h) + var(--safe-top));
    padding-top: var(--safe-top);
  }

  .sidebar__nav {
    overscroll-behavior: contain;
    padding-bottom: calc(var(--s-3) + var(--safe-bottom));
  }

  /* the drawer always shows full labels, even if collapsed on desktop */
  .shell--collapsed .sidebar__name,
  .shell--collapsed .nav-item__label {
    display: revert;
  }

  .shell--collapsed .sidebar__brand {
    justify-content: flex-start;
    padding: var(--safe-top) var(--s-4) 0;
  }

  .shell--collapsed .nav-item {
    justify-content: flex-start;
    padding: 0 var(--s-3);
  }

  .shell--collapsed .nav-group__label {
    height: auto;
    padding: var(--s-1) var(--s-3);
    margin: 0 0 var(--s-1);
    background: none;
    font-size: var(--fs-xs);
  }

  .sidebar__footer {
    display: none;
  }
}

/* touch screens: comfortable tap targets in the nav */
@media (pointer: coarse) {
  .nav-item {
    height: var(--tap);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}
