@use 'variables' as v;
@use 'mixins' as m;

// ─────────────────────────────────────────────
// Sidebar shell
// ─────────────────────────────────────────────
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: v.$sidebar-width;
  height: 100vh;
  background: v.$white;
  border-right: 1px solid v.$border-color;
  display: flex;
  flex-direction: column;
  z-index: v.$z-sidebar;
  overflow: hidden;
  transition: width v.$transition-slow, transform v.$transition-slow;

  @include m.max-lg {
    transform: translateX(-100%);
    width: v.$sidebar-width;

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

  .sidebar-collapsed & {
    width: v.$sidebar-collapsed;
    overflow: visible;

    .sidebar-brand-name,
    .nav-group-label,
    .nav-item span,
    .sidebar-user-info { display: none; }

    .nav-item {
      justify-content: center;
      padding: 10px;

      svg { flex-shrink: 0; }
    }
  }
}

// ─────────────────────────────────────────────
// Brand / Logo area
// ─────────────────────────────────────────────
.sidebar-brand {
  @include m.flex-start;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid v.$border-color;
  flex-shrink: 0;
  min-height: v.$topbar-height;
  text-decoration: none;

  &:hover { text-decoration: none; }
}

.sidebar-brand-icon {
  width: 32px;
  height: 32px;
  background: transparent;
  border-radius: v.$radius-md;
  @include m.flex-center;
  flex-shrink: 0;

  svg { width: 28px; height: 28px; }
}

.sidebar-brand-name {
  font-size: v.$font-size-lg;
  font-weight: 700;
  color: v.$gray-900;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

// ─────────────────────────────────────────────
// Scrollable nav area
// ─────────────────────────────────────────────
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  @include m.scrollbar-thin;
}

// ─────────────────────────────────────────────
// Navigation group
// ─────────────────────────────────────────────
.nav-group {
  margin-bottom: 4px;

  & + & { margin-top: 8px; }
}

.nav-group-label {
  display: block;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  color: v.$gray-400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 18px 4px;
  white-space: nowrap;
}

// ─────────────────────────────────────────────
// Nav item
// ─────────────────────────────────────────────
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 18px;
  border-radius: 0;
  font-size: v.$font-size-sm;
  font-weight: 500;
  color: v.$gray-600;
  text-decoration: none;
  transition: background v.$transition-base, color v.$transition-base;
  position: relative;
  white-space: nowrap;

  svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: v.$gray-400;
    transition: color v.$transition-base;
  }

  &:hover {
    background: v.$gray-50;
    color: v.$gray-800;
    text-decoration: none;

    svg { color: v.$gray-600; }
  }

  &.is-active,
  &[aria-current="page"] {
    background: v.$primary-light;
    color: v.$primary;
    font-weight: 600;

    &::before {
      content: '';
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 3px;
      background: v.$primary;
      border-radius: 0 v.$radius-sm v.$radius-sm 0;
    }

    svg { color: v.$primary; }
  }

  // Single top-level item (Home)
  &.nav-item--top {
    padding: 9px 18px;
    font-size: v.$font-size-base;
  }
}

// Nav badge (e.g. count)
.nav-badge {
  margin-left: auto;
  background: v.$primary-light;
  color: v.$primary;
  font-size: v.$font-size-2xs;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: v.$radius-full;
  border: 1px solid v.$primary-border;
}

// ─────────────────────────────────────────────
// Sidebar footer (user info)
// ─────────────────────────────────────────────
.sidebar-footer {
  border-top: 1px solid v.$border-color;
  padding: 12px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: v.$radius;
  cursor: pointer;
  transition: background v.$transition-base;

  &:hover { background: v.$gray-50; }
}

.sidebar-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: v.$radius-full;
  background: v.$primary-light;
  border: 2px solid v.$primary-border;
  @include m.flex-center;
  flex-shrink: 0;
  overflow: hidden;
  font-size: v.$font-size-sm;
  font-weight: 600;
  color: v.$primary;

  img { width: 100%; height: 100%; object-fit: cover; }
}

.sidebar-user-info {
  min-width: 0;
  flex: 1;
}

.sidebar-user-name {
  font-size: v.$font-size-sm;
  font-weight: 600;
  color: v.$gray-800;
  @include m.truncate;
}

.sidebar-user-email {
  font-size: v.$font-size-xs;
  color: v.$gray-400;
  @include m.truncate;
}

// ─────────────────────────────────────────────
// Mobile overlay
// ─────────────────────────────────────────────
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(v.$gray-900, 0.4);
  z-index: v.$z-sidebar - 1;

  @include m.max-lg {
    .sidebar-open & { display: block; }
  }
}
