// Redesigned sidebar — premium feel with left accent bar, refined spacing
.sidebar {
  width: var(--sidebar-width, 260px);
  background: var(--bg-sidebar, var(--bg-secondary));
  display: flex;
  flex-direction: column;
  padding: 0;
  transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  overflow: hidden;
  border-right: 1px solid var(--border-color);

  &.collapsed {
    width: 68px;

    .sidebar-user-card-wrap {
      margin: 0 8px 8px;
    }

    .sidebar-user-card {
      padding: 8px 0;
      justify-content: center;

      .user-meta {
        display: none;
      }

      .user-menu-caret {
        display: none;
      }
    }

    .nav-menu {
      padding: 0 8px;
    }

    .sidebar-footer {
      padding: 0 8px;
      padding-top: 8px;
    }

    .nav-label {
      display: none;
    }

    .nav-badge:not(.icon-badge) {
      display: none;
    }

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

      &::before {
        display: none;
      }
    }
  }
}

// ---- Navigation ----
.nav-menu {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 12px 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  margin: 1px 0;

  // Left accent bar for active state
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 16px;
    border-radius: 0 2px 2px 0;
    background: var(--primary);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }

  &:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
  }

  &.active {
    background: var(--bg-hover);
    color: var(--text-primary);
    font-weight: 600;

    &::before {
      transform: translateY(-50%) scaleY(1);
    }

    .nav-icon {
      color: var(--primary);
    }
  }
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: color 0.15s ease;
}

.nav-icon-with-badge {
  position: relative;
}

.nav-label {
  font-size: 14px;
  font-weight: 500;
}

.nav-badge {
  margin-left: auto;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  padding: 0 6px;
  background: #ef4444;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.nav-badge.icon-badge {
  position: absolute;
  top: -7px;
  right: -10px;
  margin-left: 0;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  box-shadow: 0 0 0 2px var(--bg-sidebar, var(--bg-secondary));
}

// ---- Footer ----
.sidebar-footer {
  padding: 4px 10px;
  border-top: 1px solid var(--border-color);
  padding-top: 8px;
  margin-top: 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

// ---- User card ----
.sidebar-user-card-wrap {
  position: relative;
  margin: 0 10px 10px;
  --sidebar-user-menu-width: 172px;
}

.sidebar-user-menu {
  position: absolute;
  left: 0;
  right: auto;
  bottom: calc(100% + 8px);
  width: max(100%, var(--sidebar-user-menu-width));
  z-index: 12;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: var(--bg-secondary-solid, var(--bg-secondary));
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;

  &.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }
}

.sidebar-user-menu-item {
  width: 100%;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;

  &:hover {
    background: var(--bg-hover);
  }

  &.danger {
    color: #ef4444;

    &:hover {
      background: rgba(239, 68, 68, 0.08);
    }
  }
}

.sidebar-user-card {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  cursor: pointer;
  border: none;
  transition: background 0.15s ease;

  &:hover {
    background: var(--bg-hover);
  }

  &.menu-open {
    background: var(--bg-hover);
  }

  .user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px var(--bg-sidebar, var(--bg-secondary));

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

    span {
      color: var(--on-primary);
      font-size: 13px;
      font-weight: 600;
    }
  }

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

  .user-name {
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-wxid {
    margin-top: 1px;
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .user-menu-caret {
    color: var(--text-tertiary);
    display: inline-flex;
    transition: transform 0.15s ease;

    &.open {
      transform: rotate(180deg);
    }
  }
}
