I responded to comments on this thread or on other threads but just in case you think this is a US thing only, it is not.
The UK border agents (technically counter-terrorism) can stop you at the border, force you into a room, ask for your passwords to all your devices and you don't have the right to refuse.
You also don't have the right to have a lawyer be in a room with you and you are compelled to answer all their questions and finally they do not need to tell you why they stopped you.
Then, if you are lucky they return your devices 7 days later after they have been through everything or they can keep them forever if they find something suspicious.
This guy (who is a British citizen) went through it last year and talks about the whole procedure: https://youtu.be/991kRp8KUmo?si=-5S1uLE7K9KG_gNj