As you say, gravity isn't just a measure of sugar dissolved an a liquid, it is the density of that liquid compared to that of pure water at a given temperature.
Before you start fermenting, , your wort is made up primarily of water, sugars, and other stuff. You can ignore anything that isn't dissolved (trub), as this doesn't affect the gravity. You can also ignore just about everything else dissolved in the wort as it either makes such a small difference to the gravity that the typical hydrometer isn't accurate enough to measure it (especially if your eyesight is like mine)
or it is going to remain in the finished beer.
As the wort ferments, the yeasts convert the sugars (heavier than water) into alcohol (lighter than water) and carbon dioxide causing the gravity to drop. (The weight of the beer will be reduced by the weight of the carbon dioxide released. The volume will also probably change slightly.) The yeast also metabolizes other compounds in the wort, but again, the gravity changes caused by this are insignificant.
When fermentation is finished, the change in gravity can give a fairly accurate estimation of the amount of alcohol produced..
Hope this answers your question.