/* Align ForeignKey select with its related-object action icons on one row */
.related-widget-wrapper {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
}

table[id*="schemafield_set"] select {
    min-width: 160px !important;
    width: auto !important;
}

/* Readonly field tables (e.g. pandas DataFrames, auditlog changes) */
.readonly table,
.readonly table.dataframe {
    border-collapse: collapse;
    width: 100%;
    margin-top: 4px;
    border: 1px solid var(--ae-border);
}

.readonly table th,
.readonly table td {
    padding: 4px 10px;
    border: 1px solid var(--ae-border);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

.readonly table th {
    background-color: var(--ae-bg-muted);
    font-weight: 600;
}

.readonly table tr:nth-child(odd) td {
    background-color: var(--ae-bg-subtle);
}

.readonly table tr:nth-child(even) td {
    background-color: var(--ae-bg-row-alt);
}

/* Definition lists (e.g. waffle flag help text) */
.readonly dl,
.leading-relaxed dl {
    display: grid;
    grid-template-columns: minmax(200px, max-content) 1fr;
    gap: 0;
    margin-top: 4px;
    border: 1px solid var(--ae-border);
    border-radius: 4px;
    overflow: hidden;
    width: 100%;
}

.readonly dl dt,
.readonly dl dd,
.leading-relaxed dl dt,
.leading-relaxed dl dd {
    padding: 5px 12px;
    border-bottom: 1px solid var(--ae-border);
    margin: 0;
    vertical-align: top;
    align-content: center;
}

.readonly dl dt:last-of-type,
.readonly dl dd:last-of-type,
.leading-relaxed dl dt:last-of-type,
.leading-relaxed dl dd:last-of-type {
    border-bottom: none;
}

.readonly dl dt,
.leading-relaxed dl dt {
    background-color: var(--ae-bg-muted);
    font-weight: 900;
    font-family: monospace;
    white-space: nowrap;
    border-right: 1px solid var(--ae-border);
}

.readonly dl dd,
.leading-relaxed dl dd {
    color: var(--ae-text-muted);
}

.readonly dl dt:nth-child(4n+1),
.readonly dl dd:nth-child(4n+2),
.leading-relaxed dl dt:nth-child(4n+1),
.leading-relaxed dl dd:nth-child(4n+2) {
    background-color: var(--ae-bg-subtle);
}

.readonly dl dt:nth-child(4n+3),
.readonly dl dd:nth-child(4n+4),
.leading-relaxed dl dt:nth-child(4n+3),
.leading-relaxed dl dd:nth-child(4n+4) {
    background-color: var(--ae-bg-row-alt);
}


/* Style Django's historylink to match Unfold actions_detail pill buttons */
.object-tools li:has(> a.historylink) {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--ae-border);
    border-radius: var(--radius-default, 4px);
    margin-left: -1px;
}

a.historylink {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
    font-size: 0.875rem;
}

a.historylink:hover {
    color: var(--ae-primary);
}

/* Django history table (#change-history) */
#change-history {
    border-collapse: collapse;
    width: 100%;
    margin-top: 0.5rem;
    border: 1px solid var(--ae-border);
    border-radius: var(--radius-default, 4px);
    overflow: hidden;
}

#change-history th,
#change-history td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--ae-border);
    border-right: 1px solid var(--ae-border);
    text-align: left;
    font-size: 0.875rem;
}

#change-history th:last-child,
#change-history td:last-child {
    border-right: none;
}

#change-history thead th {
    background-color: var(--ae-bg-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ae-text-muted);
}

#change-history tbody tr:last-child th,
#change-history tbody tr:last-child td {
    border-bottom: none;
}

#change-history tbody tr:nth-child(odd) {
    background-color: var(--ae-bg-subtle);
}

#change-history tbody tr:nth-child(even) {
    background-color: var(--ae-bg-row-alt);
}

#change-history tbody tr:hover {
    background-color: var(--ae-bg-muted);
}
