I am a bit confused as to what the bass note of a chord is. Isn't it the first note of the chord (or any of its inversions)? Or it can be any note that not necessarily belongs to the chord, as long as it's the lowest note played? So a C chord can have D as a bass?
The bass note of a chord is simply the lowest pitched note that is part of the harmony. If you are looking at the notes of a chord bottom up then yes it is the "first" note. The bass note of a chord in general is very important in defining how the chord functions so we make note of it in the form of inversions and slash chords to notate exactly what note is in the bass.
In your example, yes you could have a C major chord with a D in the bass and you would see it written as the slash chord C/D. Notice how the D is not a chord tone of a C major chord. When you see this it typically alludes to a chromatic bass line that is taking you somewhere while the overall harmony is getting you there in a slightly different manner. You may also see the chord written as a Cadd9/D which means almost the same thing, but now we are directly considering the bass note as a chord tone.
The bass note is the lowest note being played. It's not an analytical term, merely a description of what's happening.
In harmony theory, the root of a chord is the letter-name that gives it it's name. It may be at the bottom (root position). 3rd at the bottom gives first inversion, 5th at the bottom gives second inversion. We could logically extend this to call a 7th chord with the 7th underneath as "third inversion", a 9th with the 9th underneath as "fourth inversion"... but we generally don't!
When we get into chords like C/D, let go of the theory book a bit! It MIGHT be useful to call this a third inversion of C(add9), but almost certainly isn't. More likely C/D refers to a quite specific voicing where the D HAS to be the bass note and shouldn't be included in the upper structure.