/* Keep the selector beside the user, including narrow screens. */
.app-header-tools {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    margin-inline-start: auto;
}
.app-header-tools .app-user { flex-basis: auto; }
.portal-theme-selector { flex-shrink: 0; }
/* The head script resolves this attribute before the first paint, not after modules load. */
html[data-portal-theme] #portal-theme-toggle [data-portal-theme-icon] {
    display: none;
}
html[data-portal-theme="auto"] #portal-theme-toggle [data-portal-theme-icon="auto"],
html[data-portal-theme="light"] #portal-theme-toggle [data-portal-theme-icon="light"],
html[data-portal-theme="dark"] #portal-theme-toggle [data-portal-theme-icon="dark"] {
    display: inline-block;
}
@media (max-width: 575.98px) {
    .app-header-tools { flex-basis: 100%; justify-content: flex-end; }
}

/* Authenticated frontend only: EasyAdmin and login never receive this marker. */
html[data-portal-theme][data-bs-theme="dark"] {
    --portal-dark-surface: #212529;
    --portal-dark-heading: #b8d2fe;
    --portal-dark-accent: #6ea8fe;
}
html[data-portal-theme][data-bs-theme="dark"] .app-main .text-primary {
    color: var(--portal-dark-accent) !important;
}
html[data-portal-theme][data-bs-theme="dark"] .table-summary-heading h1,
html[data-portal-theme][data-bs-theme="dark"] .portal-footer-title {
    color: var(--portal-dark-heading);
}
html[data-portal-theme][data-bs-theme="dark"] .app-footer {
    color: var(--bs-body-color);
    background-color: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .portal-footer-mark,
html[data-portal-theme][data-bs-theme="dark"] .portal-footer-version,
html[data-portal-theme][data-bs-theme="dark"] .table-summary-count {
    color: var(--portal-dark-heading);
    background-color: #253750;
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .portal-footer-copyright a { color: var(--portal-dark-accent); }
html[data-portal-theme][data-bs-theme="dark"] .table-summary-meta,
html[data-portal-theme][data-bs-theme="dark"] .table-summary-table tbody .table-summary-id,
html[data-portal-theme][data-bs-theme="dark"] .table-summary-table .table-summary-empty td {
    color: var(--bs-secondary-color);
}
html[data-portal-theme][data-bs-theme="dark"] .table-summary-scroll {
    background-color: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .table-summary-table {
    --bs-table-bg: var(--bs-body-bg);
    --bs-table-striped-bg: #2a3038;
    --bs-table-hover-bg: #303e50;
    --bs-table-striped-color: var(--bs-body-color);
    --bs-table-hover-color: var(--bs-body-color);
    color: var(--bs-body-color);
}
html[data-portal-theme][data-bs-theme="dark"] .table-summary-table > :not(caption) > * > * {
    border-bottom-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .table-summary-table > tfoot > tr > * {
    color: var(--portal-dark-heading);
    background-color: #243954;
    border-top-color: #6b8bb5;
}
html[data-portal-theme][data-bs-theme="dark"] .table-summary-table .table-summary-warning {
    color: #f5c2c7;
    background-color: #44282e;
}
/* These headers carry existing per-column inline colors in the light layout. */
html[data-portal-theme][data-bs-theme="dark"] #table-data-id thead > tr:first-child > th {
    color: #e2edff;
    background-color: #23456f !important;
}
html[data-portal-theme][data-bs-theme="dark"] #table-data-id thead > tr:not(:first-child) > th {
    color: var(--portal-dark-heading);
    background-color: #243954;
}

/* Tabulator's installed Bootstrap theme contains fixed light colors. */
html[data-portal-theme][data-bs-theme="dark"] .tabulator,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-tableholder .tabulator-table,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row,
html[data-portal-theme][data-bs-theme="dark"] .tabulator-popup-container {
    color: var(--bs-body-color);
    background: var(--portal-dark-surface);
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-header,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-header .tabulator-col,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-footer,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row.tabulator-group,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row .tabulator-cell.tabulator-row-header {
    color: var(--bs-body-color);
    background: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row .tabulator-cell {
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row.tabulator-row-even {
    background: #2a3038;
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row.tabulator-selectable:hover,
html[data-portal-theme][data-bs-theme="dark"] .tabulator-menu .tabulator-menu-item:hover {
    color: #e2edff;
    background: #304662;
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row.tabulator-selected,
html[data-portal-theme][data-bs-theme="dark"] .tabulator-edit-list .tabulator-edit-list-item.active {
    color: #fff;
    background: #365d90;
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-tableholder .tabulator-placeholder span,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-row.tabulator-group span,
html[data-portal-theme][data-bs-theme="dark"] .tabulator-edit-list .tabulator-edit-list-item,
html[data-portal-theme][data-bs-theme="dark"] .tabulator-edit-list .tabulator-edit-list-group {
    color: var(--bs-body-color);
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-header-filter input,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-footer .tabulator-page {
    color: var(--bs-body-color);
    background: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-footer .tabulator-page.active {
    color: #fff;
    background: #365d90;
}
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-footer .tabulator-calcs-holder,
html[data-portal-theme][data-bs-theme="dark"] .tabulator .tabulator-footer .tabulator-calcs-holder .tabulator-row {
    color: var(--portal-dark-heading) !important;
    background: #243954 !important;
    border-color: var(--bs-border-color) !important;
}

/* Tom Select popups can be appended directly to the document body. */
html[data-portal-theme][data-bs-theme="dark"] .ts-control,
html[data-portal-theme][data-bs-theme="dark"] .ts-dropdown {
    color: var(--bs-body-color);
    background: var(--bs-body-bg);
    border-color: var(--bs-border-color);
}
html[data-portal-theme][data-bs-theme="dark"] .ts-control input,
html[data-portal-theme][data-bs-theme="dark"] .ts-control .item {
    color: var(--bs-body-color);
}
html[data-portal-theme][data-bs-theme="dark"] .ts-dropdown .active,
html[data-portal-theme][data-bs-theme="dark"] .ts-wrapper.multi .ts-control > div {
    color: #e2edff;
    background: #304662;
}
html[data-portal-theme][data-bs-theme="dark"] .ts-wrapper.disabled .ts-control {
    background: var(--bs-secondary-bg);
}
