First, to the title question: No, uncanny dodge does not make a character completely immune to ranged sneak attacks. There are ways to make a creature flat-footed aside from catching them before they act, and ways to deny Dexterity to AC without relying on invisibility.
As for uncanny dodge vs. surprise attack, I agree with your second interpretation: uncanny dodge prevents the character from being flat-footed. It does nothing to prevent the character from being treated as flat-footed by a particular assailant. But it’s definitely ambiguous enough that I wouldn’t rely on this interpretation without discussing it with the DM (or explaining it to players, if I were DM and one of them thought uncanny dodge protected them from surprise attack).
No, because the two conditions do not encompass every possibility.
If the Swashbuckler (S) has interposed himself between an Ally (A) and an Opponent (O). Each occupies a single five by five square.
Such as:
ASO
In this scenario, an ally is within 5 feet from the swashbuckler, but there isn't an ally within 5 feet of the opponent. Lacking an additional effect that will provide advantage to the Swashbuckler, Sneak Attack won't be available.
Similarly, if the Swashbuckler (S) is facing two Opponents (O and X), there are several configurations in which Sneak Attack isn't available.
To summarize, the following conditions will prohibit you from using Sneak Attack, assuming there isn't an external effect providing Advantage.
- Swashbuckler is within 5 feet of more than one hostile creature or character.
- Swashbuckler is attacking the target at melee range and a friendly character or creature is within 5 feet of him but isn't within 5 feet of the target.
Per a twitter post by Jeremy Crawford, Rules as Intended want the Swashbuckler to be within 5 feet of the target. In effect, Rackish Audacity should be written with "except" instead of "other."
Best Answer
Yes.
Improved uncanny dodge says:
The most general rule is that rogues can sneak attack flanked characters.
Next most general is that you cannot sneak attack characters with improved uncanny dodge by flanking them.
Most specific is that characters with uncanny dodge can still be sneak-attacked by characters with a rogue level >= (sum of levels in classes giving uncanny dodge + 4).
Nothing actually requires the rogue doing the flanking to actually have any particular characteristics other than class levels as a rogue.
@Ifusaso correctly adds: Do note that your rogue levels must be 4 higher. So as a Swashbuckler 4/Rogue 4 you would not be able to sneak attack anything with Improved Uncanny Dodge. At S-4/R-5 you would only be able to use it on Imp Uncanny Dodge targets that are level 1.