Dulce Rivera lived for the one hour a day she was allowed to walk outside on a patch of concrete surrounded by metal fencing.

The 36-year-old transgender woman from Central America was locked in solitary confinement at a New Mexico detention center that housed immigrants in the custody of Immigration and Customs Enforcement. For 23 hours a day, she remained alone in a cell, with no one to talk to and nothing to distract from her increasingly dark thoughts.

"You never know what day it is, what time it is," said Rivera, who has struggled with mental illness. "Sometimes you never see the sun."

Rivera was placed in isolation because of allegations, later determined to be unfounded, that she had kissed and touched other detainees, records show.

Nearly four weeks into her stint in solitary, she lost her will to live. She fashioned a noose from a torn blanket and hanged herself from the cell's ceiling vent — only to be saved by a passing guard.

Rivera was rushed to a hospital. Upon her return to the detention center, she was labeled a suicide threat and placed back in solitary, under even more restrictions.

Rivera's case is not unique.

Thousands of others were outlined in a trove of government documents that shed new light on the widespread use of solitary confinement for immigrant detainees in ICE custody under both the Obama and Trump administrations.

The newly obtained documents paint a disturbing portrait of a system where detainees are sometimes forced into extended periods of isolation for reasons that have nothing to do with violating any rules.

Disabled immigrants in need of a wheelchair or cane. Those who identify as gay. Those who report abuse from guards or other detainees.

Only half of the cases involved punishment for rule violations. The other half were unrelated to disciplinary concerns — they involve the mentally ill, the disabled or others who were sent to solitary largely for what ICE described as safety reasons.

A Guatemalan man spent two months in solitary confinement at a county jail in Maryland. The reason: He had a prosthetic leg.

A mentally ill Ukrainian man was put in isolation for 15 days at a detention facility in Arizona. His offense: putting half a green pepper in one of his socks.

In nearly a third of the cases, segregated detainees were determined by ICE to have a mental illness, a population especially vulnerable to the harmful effects of isolation.

"We have created and continue to support a system that involves widespread abuse of human beings," said Ellen Gallagher, a policy adviser at the Department of Homeland Security.

Gallagher, who is speaking publicly for the first time, has spent the past five years trying to sound the alarm within the federal government about the rampant use of solitary confinement on vulnerable people in ICE custody.

"People were being brutalized," she said.

The data, along with a review of thousands of pages of documents, including detention records and court filings, and interviews with dozens of current and former detainees from across the globe — India to Egypt to Nicaragua — offers an expansive look at how the practice of solitary confinement has been used in the nation's civil immigration detention system.

The bulk of the records, which document solitary cases from March 2012 to March 2017, were obtained under the Freedom of Information Act by the International Consortium of Investigative Journalists and shared through a partnership with NBC News and five other news organizations.

A guard escorts an immigrant detainee from his segregation cell back to general population at the Adelanto Detention Facility in California in 2013. John Moore / Getty Images file

ICE's own directives say that placing detainees in solitary — or "segregated housing," as the agency calls it — is "a serious step that requires careful consideration of alternatives." Vulnerable detainees, such as the mentally ill, should only be placed in segregation as a last resort, according to ICE policy.

But the documents raise questions about whether ICE is following its own guidelines. Gallagher, for her part, is convinced that it is not.

"Solitary confinement was being used as the first resort, not the last resort," she said.

The data documents 8,488 cases of immigrant detainees placed in isolation over the five-year period. But those figures represent only a portion of all the instances of solitary confinement in ICE's vast network of detention centers.

According to ICE, the agency tracks cases only when detainees have a "special vulnerability," such as the mentally ill, or were put in solitary for more than 14 days.

One out of every 200 detainees spend time in isolation for at least two weeks, according to ICE data. In a statement to NBC News, an agency spokesperson defended its use of the practice.

ICE "is firmly committed to the safety and welfare of all those in its custody," the spokesperson said. "The use of restrictive housing in ICE detention facilities is exceedingly rare, but at times necessary, to ensure the safety of staff and individuals in a facility. ICE's policy governing the use of special management units protects detainees, staff, contractors and volunteers from harm by segregating certain detainees from the general population for both administrative and disciplinary reasons."

The spokesperson added that ICE uses such practices to ensure that detainees "reside in safe, secure and humane environments and under appropriate conditions of confinement."

'Can you please help me?'

As the name suggests, solitary confinement separates individuals from the general population, housing them alone in a cell where their movements and privileges are highly restricted.

In isolation, they are typically locked down for at least 22 hours a day, with limited access to recreation or contact with other human beings. Depending on the restrictions, individuals in solitary can be limited or outright denied access to phone calls, visitation, books or personal items, such as photographs of loved ones.

The experience, according to those who have lived it, can be harrowing. Some current and former detainees told NBC News that their time in isolation drove them to attempt suicide or commit other acts of self-harm. The detainees described a wide array of suffering, including night terrors, flashbacks, anxiety, depression, insomnia — psychological trauma that lasted long after their release from custody.

"After that first or second week, I lost my mind," Ayo Oyakhire, a 52-year-old Nigerian, said of his nearly seven weeks in isolation at the ICE unit in Atlanta's jail. "Sometimes I feel like someone is choking me. I have flashbacks, like I'm still confined in that little room."

"I am not normal," said Karandeep Singh, a 29-year-old Sikh from northern India who was moved to solitary confinement in the El Paso Processing Center in Texas, after he refused meals to protest his impending deportation.

Singh said that after more than two weeks in isolation, he bashed his head into his cell wall in an attempt to kill himself. "It was mental torture," Singh said.

Several states have enacted restrictions on the practice, or banned it outright for certain populations, including juveniles and the mentally ill. Texas recently banned "punitive" solitary as punishment for breaking the rules. In Colorado, state inmates cannot be held in solitary confinement for longer than 15 days. President Barack Obama banned the use of solitary confinement for juveniles in federal prisons.

Experts say even short stays in isolation can cause severe, and long-lasting, psychological and physical damage. The United Nations special rapporteur on torture has said that solitary confinement can amount to "torture or cruel, inhuman or degrading treatment," and that isolation for more than 15 days should be banned, except in exceptional circumstances.

The number of immigrants in custody has reached historic levels, with a daily average of 50,000 immigrants in more than 200 detention centers across the country, including county jails and facilities operated by private prison providers. Those in ICE custody are not facing criminal charges, and their detention is not intended to be punitive. They are in custody for civil immigration violations such as overstaying their visas or being in the country illegally. Some are awaiting deportation or court dates. Some are asylum-seekers.

Similar to a criminal setting, officers in ICE facilities must sometimes manage detainees who are dangerous, or who fight or otherwise misbehave, or who are at risk of harm to themselves or others if left in general population or not kept under close observation. Some detainees, such as the elderly or disabled, may require special medical care that facilities, such as county jails, are not equipped to handle.

But NBC News found that immigrant detainees are also put in solitary for minor offenses, such as consensual kissing, or for offenses that stem from mental illness, such as acts of self-harm.

Joselin Mendez, a transgender woman from Nicaragua, was twice sent to solitary for minor disciplinary infractions, including an instance when she argued with an officer. Mendez said he refused to speak Spanish to her, and she cannot speak English.

"I felt afraid and anxious, and I would tremble and sweat and I would ask, 'Why is this happening?'" Mendez said of her time in solitary.

Joselin Mendez, who received asylum in 2018, was put into solitary confinement twice for minor disciplinary infractions while detained in ICE custody. "I felt afraid and anxious," she said. "I would tremble and sweat and I would ask, 'Why? What is happening?'" Hannah Rappleye / NBC News

Hunger strikers, LGBT detainees and people with disabilities have been put in isolation — referred to as "protective custody" in these cases — sometimes because they requested it, but sometimes not.

Kelly, a 22-year-old transgender woman from Central America whose last name NBC News is withholding at her request, spent four months in protective custody at the Pine Prairie ICE Processing Center in northern Louisiana, beginning in late 2017.

"The only thing they told me was that it was because of the way I looked," she said in a phone interview from the privately run Cibola County Correctional Center in New Mexico. "They claimed it was for security reasons. … I told them from Day One that I didn't want to be locked up almost 24 hours a day, alone in a cell, without medical attention."

"Every time I closed my eyes, when I was trying to sleep, I began to have nightmares, horrible memories, things that I didn't want to remember," added Kelly. "It's still happening to me."

The Cibola Detention Center in Milan, New Mexico. Hannah Rappleye / NBC News

Detainees with mental illness put in isolation include more than 50 instances of self-harm. In at least 373 instances, those in solitary were on suicide watch, a highly restrictive form of solitary.

A suicidal Iraqi man was placed in solitary at a Michigan detention center after he cut himself with a razor. He was ordered to spend 30 days in isolation — not for his own safety, but as punishment for a "weapons offense and self mutilation."

More than 60 disabled detainees were placed in isolation solely because they required a wheelchair or some other aid.

A Pakistani man who needed a hard cast to heal his injured hand was put in isolation for eight days. His jailers said the cast posed a "security risk."

ICE took alternating views of that risk when justifying the decision to put him in solitary. At one point, it noted that the cast "poses potential danger" and "has potential to be used as a blunt object during altercation." But it also noted that his damaged hand and sling "could also hinder his ability to defend himself in general population."

Ilyas Muradi, a 30-year-old longtime U.S. resident from Afghanistan, has spent most of the last four months in solitary at ICE's South Texas Detention Complex. He said he was accused of entering a shower without authorization, and threatening a guard.

Muradi denied that he threatened a guard, but acknowledged having gotten into multiple fights with other detainees last year. He said he believes guards are now punishing him simply because they don't like him — and is frustrated because he doesn't know what he can do to be released from solitary. His attorney in early May sent a letter to ICE pleading for his client's release from isolation.

In one way, Muradi is among the lucky ones.

Detainees had lawyers in only 11 percent of the solitary reports. Even for those, in more than 270 instances, ICE did not notify the attorneys that their clients were placed in solitary. This includes six times when detainees were in isolation for more than half a year.

"I don't know what's going on," an anguished Muradi told reporters in a phone call from the detention facility.

At the end of another call, he broke into sobs, asking "Can you please help me?"

'People were being brutalized'

In February 2014, Gallagher, the DHS employee, came across ICE logs detailing the placement of detainees in solitary confinement. She said she couldn't believe her eyes at first: The agency was using the punishing conditions of isolation on civil detainees routinely, and often with little apparent justification.

Her alarm grew as she reviewed cases of the mentally ill placed in isolation for reasons that included attempting suicide, being the victim of a physical attack or exhibiting behavior related to their mental illness.

"I came to believe that many of the fact patterns featured in the segregation reports and in the other documents that I reviewed fell within the description of what had been deemed torture," said Gallagher, who was at the time a policy adviser for DHS's Civil Rights and Civil Liberties office.

In one of the cases, a detainee jumped from the top of his bunk bed onto a cement floor in an attempt to harm himself. He then tried to strangle himself with a towel. He was sentenced to 15 days in solitary. In another, a detainee was sentenced to 45 days in solitary after officials discovered one anti-anxiety pill hidden in a book he was reading.

One of the most troubling cases was that of a man who had so deteriorated during a year in and out of solitary, that he had to be admitted to a psychiatric hospital. Once he returned to the detention center, she said, he threw his own feces at a guard and was subsequently sentenced to more than 13 months in isolation.

Men sit in the sun at the Otay Mesa Detention Center in San Diego in 2010. Gregory Bull / AP file

Over several months, Gallagher tracked individual cases and gathered reams of documentation. She began to lose sleep, plagued by a series of questions: "How can this be happening? What can I do to bring this to someone's attention?"

Now convinced that ICE was violating its own rules and endangering the lives of detainees, she embarked on a yearslong effort to reform the agency's practices.

In a succession of memos first circulated internally at DHS and then sent to the U.S. Office of Special Counsel — an independent agency where federal employees can file complaints of wrongdoing they think have been ignored — Gallagher alleged that abuses of solitary confinement at ICE had become "urgent and at times life-threatening."

In one memo, Gallagher describes seeing records of ICE detainees moving "chronically back and forth from the general population to administrative or disciplinary segregation, with periodic, crisis-oriented admissions to psychiatric hospitals punctuating their return to the same disturbing cycle."

ICE's internal guidelines explicitly require detention officials to document what alternatives to isolation were considered in certain cases. Gallagher often found no evidence that ICE had done so.

In a statement, the Department of Homeland Security said that its Office of Civil Rights and Civil Liberties had examined ICE's use of isolation through complaint investigations, working groups and other advice and feedback. The office has worked with ICE "to improve policy and reduce unnecessary use of segregated housing for ICE detainees," the spokesperson said. The office said that, in 2016, it collaborated with ICE to implement Obama-era recommendations issued by the Justice Department on improving solitary confinement.

DHS's inspector general in recent audits has raised concerns about "improper and overly restrictive" isolation, "multiple violations" of ICE policy leading to needless solitary confinements, and record keeping so sloppy that mentally ill detainees may be subjected to extended stays in isolation that would pose a threat to their health.

Gallagher's memos prompted two top lawmakers from different sides of the aisle — Sen. Charles Grassley, R-Iowa, and then-Sen. Al Franken, D-Minn. — to write a previously unreported letter in 2015 outlining concerns over ICE's use of solitary confinement.

"Recent information obtained by the (Senate Judiciary Committee) suggests that ICE continues to place many detainees with mental health concerns in administrative or disciplinary segregation — also known as solitary confinement — contrary to agency directives that limit the use of segregation for the mentally ill," read the letter to Jeh Johnson, who was Obama's homeland security secretary.

Ellen Gallagher, a former policy advisor at the Office for Civil Rights and Civil Liberties at the Department of Homeland Security, said that records she reviewed indicated that ICE was using solitary confinement "as the first resort, not the last resort." Hannah Rappleye / NBC News

Believing she has exhausted her options for sounding the alarm within the government, Gallagher agreed to share her story with NBC News. Without public action, "this same set of circumstances will not stop," Gallagher said. "And I think it will actually get worse."

"I tend to think that staying silent does not honor the pain of the people who have been treated in this inhumane way," she added. "If I were to stay silent given what I know, that I would in effect be giving up on the people that are stuck in those cells."

'He wanted to die'

At least 13 detainees who later died in ICE detention have spent time in solitary, according to records dating back to 2011.

An NBC News analysis of ICE death reports shows that the agency acknowledged missteps for at least eight of them. Seven of those committed suicide while in solitary. The eighth died after he wasn't given his anti-seizure medication.

Clemente Ntangola Mponda, a 27-year-old man from Mozambique, was put in solitary at the Houston Contract Detention Facility in Texas for more than half of 2012. "Mponda told mental health staff he was tired of being in segregation and that he wanted to die," according to an ICE detainee death report.

Mponda continued to be held in isolation, though the justification would remain murky, ICE later determined. For three months, prison officials violated rules by not providing justifications or details for why he continued to be held in solitary. In August 2013, he was back in isolation for more than two weeks because of a fight. Prison staff didn't notice he grabbed extra medication pills. Although he had previously talked about killing himself, officials did not check on him. With no one watching, Mponda killed himself by swallowing the pills.

Moises Tino‐Lopez, 23, from Guatemala, died in 2016 in an isolation cell in the Hall County Department of Corrections, in central Nebraska. ICE would later determine that "no justification was documented for charging Tino with disciplinary violations and placing him in" solitary. Once in isolation, the facility did not ensure he got needed anti-seizure medication. He then died from a seizure.

'A long time behind those walls'

Even before she landed in solitary at the Cibola County Correctional Center in New Mexico last June, Dulce Rivera's life was marked by tumult.

She said her mother abandoned her when she was 10, leaving her homeless. Rivera spent her early teens on the streets of violence-ravaged cities in Honduras and elsewhere, battling drug addiction and mental illness. She arrived in the U.S. at age 16 and was granted permanent residency in 2000.

The transgender woman was placed in ICE custody in 2017 after a criminal conviction in California for second-degree robbery violated her residency in the U.S.

Dulce Rivera, a 36-year-old transgender woman from Central America, was released from immigration detention in April 2019. She spent about eleven months in segregation, also known as solitary confinement. "You have no hope," she said. Hannah Rappleye / NBC News

Her suicide bid came in June. After she was transported back from the hospital, Rivera was outfitted with a heavy green smock that couldn't be fashioned into a noose. She was still locked alone for nearly all day in conditions that further ate away at her fragile mental state. "They take off all your clothes, and they put you in a cell that is more terrible," Rivera said.

CoreCivic, which runs the Cibola facility, said that it is contractually required to follow ICE's detention standards. "We're committed, as we have been for three decades, to creating a safe environment for the individuals ICE entrusts to our care," CoreCivic spokesperson Amanda Gilchrist said, "and to following all federal guidelines on the appropriate accommodation of transgender detainees."

Rivera was abruptly released from ICE custody last April after her lawyer filed a legal action challenging her detention. No country would accept Rivera, who had no birth certificate or identifying information from any nation, and ICE couldn't hold her indefinitely.

By then, Rivera had been moved to the El Paso Processing Center in Texas. In all, she spent roughly 11 months in solitary confinement at the two facilities, records show.

"They just tell me, 'Miss Rivera, we gotta let you go,'" she said of that day of her release. "And I just start crying. It has been such a long time behind those walls."

Rivera is now living at her sponsor's home, a modest one-story house a few minutes drive from New Mexico's Organ Mountains. Her bedroom is a far cry from the isolation cells she lived in for nearly a year. The desert sunlight filters through her window and spills over the soft comforter on her bed.

Most of the time, Rivera can barely contain her sunny, upbeat personality. As she settles into her new life, she's been spending time with a network of supporters, including a close circle of transgender friends.

But a small part of her, she said, remains broken. Nightmares still plague her.

In one, she sees an officer looming over her in the dark.

"You think you're still living there," Rivera said.

This story was produced by NBC News as part of a collaboration with the International Consortium of Investigative Journalists, a nonprofit organization based in Washington. The partnership includes five other news organizations: Univision and The Intercept in the United States; Grupo SIN of Dominican Republic, Mexicanos Contra la Corrupción in Mexico and Plaza Publica in Guatemala.