One thing that bothers me is double spending. When it will occur:
1) When A and B try to spend more bitcoin than they have in wallet
2) When A and B try to spend bitcoins at the same moment, even if they don't spend all money in their wallet
Which one is true?
Neither (or both) depending on how you look at it.
At the protocol level, bitcoin separately keeps track of every transaction received. It does not "blend together" these balances. If you receive, at a single bitcoin address, three transactions each for a different balance for example 3 BTC, then 4 BTC, and 6 BTC then the wallet might show you a balance of 13 BTC, but it is actually keeping track of each of those transaction outputs individually.
When spending bitcoins, the protocol requires that you spend one or more outputs in their entirety. If, given the example, you want to send someone 1 BTC, your wallet would have to spend one or more of the listed outputs completely. Assuming for the moment that the wallet chose to spend the 3 BTC output, it would create a transaction that used the 3 BTC output as an input to the transaction. The transaction would then have 2 outputs, an output for 1 BTC sent to the recipient's address, and a separate output for 2 BTC to an address in your wallet as "change". Once this transaction is confirmed, the previous 3 BTC output is considered "spent" and can never be spent again. Any further attempt to spend the 3 BTC output would be considered a failed "double spend" attempt. If you want to spend the remaining 2 BTC, you'd have to know about and spend the new 2 BTC output.
So, a double spend attempt will occur any time two separate attempts are made to spend the same previously received output.
If A spends all the bitcoins in their wallet, then obviously this will mean that they have spent all the outputs that any copy of the wallet might be tracking. If the wallet that B is running hasn't yet been updated with the information that A's wallet already spent those outputs, then B could attempt to "spend more than they have in the wallet" and as such attempt to spend one or more of the already spent outputs. This would be a double spend attempt.
If A and B try to spend bitcoins at the same moment, both wallets could choose to spend one or more of the same previously received unspent outputs. This would be a double spend attempt.
It is generally a bad idea to attempt to run two separate wallets that are both attempting to track and spend bitcoins received at the same addresses. There are many opportunities for one wallet to be unaware that the other wallet already spent some of the outputs. Perhaps in the future someone will come out with a wallet that synchronizes well between multiple instances to avoid such issues, but at the moment, the only wallets that do this, do so by sending all communications through a centralized server that keeps track of each of the unspent outputs in one place. Each "instance" of the wallet is really just a separate connection to the one server that is tracking the balances and addresses.