Going into further detail, I can honestly say that, beyond battle facilities, I've never lost a battle to an NPC. I also never use items during battle, except during wild battles when attempting to catch Pokémon. When I play Pokémon, I typically EV train my Pokémon. If I don't EV train my Pokémon during the beginning of my adventure, then it's because I transferred young newly hatched Pokémon to my new game that are already EV trained in the previous game using vitamins. I always EV train my starter though if I don't breed it. Doing that usually results in me mowing down practically every NPC, including gym leaders and the Elite Four. I also ensure that my Pokémon have nearly perfect IVs as well, thus making my Pokémon even stronger than normal. This is usually done by breeding constantly. When you have maxed EVs and (nearly) perfect IVs, losing is (almost) impossible, but you're not invincible either.
For example, my greatest near losses, which was to Steven Stone in the generation III remakes, and Ultra Necrozma, happened despite my method for training my Pokémon. The battle started out pretty easy enough, but later on, Steven Stone's Mega Metagross boosted its stats in some way and almost swept my entire team, but I was able to finally take it down with my Gengar though. Ultra Necrozma almost swept my entire team because I didn't do any research on its typing and it outspeed pretty much all my Pokémon, but I was able to get rid of it using priority moves and prevent myself from losing. The primary reason I have lost to NPCs in the battle facilities is because I mainly use them to test out a crazy strategy that I thought of. If it doesn't work and fails miserable, usually the NPC wins the battle. Sometimes, but on rarer occasions, a battle facility NPC could take me by complete surprise. However, for the most part, I very rarely lose in the battle facilities when I'm actually taking it seriously and grinding for BP.