If you sell shares out of your demat account, there is no additional margin charged on the sell leg, since the shares are meant for delivery, and they are eventually delivered in the form of Early Pay-in.
Instead, as per guidelines issued by SEBI in December 2020, if you sell shares from your demat account, 80% of the sale proceeds gets available on the same day that you can use to enter into another trade or take another position, and the balance 20% gets available to trade on the next day.
If you buy back the same shares on the same day of sale, it becomes an intraday trade, and the delivery gets withheld, resulting in forfeiture of margins against 80% of the sell value, as previously mentioned.
There is no margin shortfall if -
80% of the value of shares sold is bought back
80% of the sell value is used as margins to take any other position
In case you intend to do both, or if you wish to buy back the same shares beyond 80% of the value of shares sold, you will need to bring in additional margin in the form of cash / pledging of stocks, otherwise this will lead to margin shortfall.