Physiological mechanisms underlying the sensation of pain

Could you elaborate on the physiological mechanisms underlying the sensation of pain and the roles of nociceptors, neurotransmitters, and pain-modulating pathways in the perception and modulation of pain signals? How do specialized sensory neurons called nociceptors detect noxious stimuli such as tissue damage, inflammation, or thermal extremes and transmit pain signals to the spinal cord and brain? Additionally, how do neurotransmitters like substance P, glutamate, and endogenous opioids modulate pain transmission and perception in the spinal cord and brainstem, leading to analgesia or hyperalgesia? Furthermore, how do descending pain inhibition pathways and cortical processes contribute to the cognitive and emotional aspects of pain perception and the regulation of nociceptive responses?