/* The account control and its accessible name always describe the next action. */
.rb-account-nav { gap: .75rem; }
.rb-account-name {
    max-width: min(32vw, 20rem);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rb-theme-toggle {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--bs-body-color);
}
.rb-theme-toggle:hover { background: var(--bs-tertiary-bg); }
.rb-theme-toggle:focus-visible { outline: 2px solid var(--bs-link-color); outline-offset: 2px; }
.rb-theme-toggle svg { width: 19px; height: 19px; }
.rb-theme-moon, html[data-theme="dark"] .rb-theme-sun { display: grid; place-items: center; }
.rb-theme-sun, html[data-theme="dark"] .rb-theme-moon { display: none; }
@media (max-width: 575.98px) {
    .rb-account-nav { gap: .25rem; }
    header #mobile-nav-toggle { margin: .5rem .5rem .5rem 0 !important; }
    .rb-account-name { max-width: clamp(3rem, calc(100vw - 260px), 12rem); }
}

/* The portal uses Bootstrap's native dark color scheme, with Red Bull-specific contrast. */
html[data-theme="dark"] {
    color-scheme: dark;
    --rb-bg: #101621;
    --rb-surface: #192231;
    --rb-surface-raised: #253247;
    --rb-text: #f0f4fa;
    --rb-muted: #b2bfd1;
    --rb-border: #415168;
    --rb-grid: #364357;
    --rb-accent: #ff7195;
    --rb-link: #9dccff;
    --rb-positive: #73dfae;
    --rb-negative: #ff939c;
    --rb-warning: #ffd185;
    --bs-body-color: var(--rb-text);
    --bs-body-color-rgb: 240, 244, 250;
    --bs-body-bg: var(--rb-bg);
    --bs-body-bg-rgb: 16, 22, 33;
    --bs-secondary-color: var(--rb-muted);
    --bs-secondary-color-rgb: 178, 191, 209;
    --bs-secondary-bg: var(--rb-surface-raised);
    --bs-tertiary-bg: var(--rb-surface-raised);
    --bs-border-color: var(--rb-border);
    --bs-border-color-translucent: var(--rb-grid);
    --bs-link-color: var(--rb-link);
    --bs-link-color-rgb: 157, 204, 255;
    --bs-link-hover-color: #c7e3ff;
    --bs-link-hover-color-rgb: 199, 227, 255;
    --bs-primary: var(--rb-link);
    --bs-secondary: var(--rb-muted);
    --bs-primary-text-emphasis: var(--rb-link);
    --bs-secondary-text-emphasis: var(--rb-muted);
    --bs-success-text-emphasis: var(--rb-positive);
    --bs-danger-text-emphasis: var(--rb-negative);
    --bs-warning-text-emphasis: var(--rb-warning);
    --bs-info-text-emphasis: #a4daef;
    --bs-primary-bg-subtle: #203752;
    --bs-secondary-bg-subtle: #2a3547;
    --bs-info-bg-subtle: #1b3647;
    --bs-danger-bg-subtle: #452a38;
    --bs-success-bg-subtle: #193c33;
    --bs-warning-bg-subtle: #403429;
    --bs-focus-ring-color: rgba(157, 204, 255, .5);
}

/* Shell, navigation and the supplied brand artwork. */
html[data-theme="dark"] .bg-white { background-color: var(--rb-surface) !important; }
html[data-theme="dark"] :is(main.bg-light, main.bg-white) { background-color: var(--rb-bg) !important; }
html[data-theme="dark"] .bg-light { background-color: var(--rb-surface-raised) !important; }
html[data-theme="dark"] header.sticky-top,
html[data-theme="dark"] :is(#sidebar, #mobile-sidebar, .sidebar-toggle-middle) { border-color: var(--rb-border); }
html[data-theme="dark"] #sidebar .page-link { background: transparent; }
html[data-theme="dark"] :is(#sidebar, #mobile-sidebar) .nav-link,
html[data-theme="dark"] #profileDropdown { color: var(--rb-text); }
html[data-theme="dark"] :is(#sidebar, #mobile-sidebar) .nav-link:is(:hover, :focus-visible),
html[data-theme="dark"] #profileDropdown:hover { color: var(--rb-link); }
html[data-theme="dark"] :is(#sidebar, #mobile-sidebar) .nav-link.active {
    background: var(--rb-surface-raised);
    color: var(--rb-link);
}
html[data-theme="dark"] #mobile-sidebar-overlay,
html[data-theme="dark"] .fp-overlay { background: rgba(4, 8, 15, .68) !important; }
html[data-theme="dark"] .portal-footer .logo {
    background: #eaf0f7;
    border-radius: .35rem;
}
html[data-theme="dark"] .dropdown-menu {
    --bs-dropdown-bg: var(--rb-surface-raised);
    --bs-dropdown-link-hover-bg: #35445a;
    --bs-dropdown-link-active-bg: #354c69;
}

/* The compiled brand stylesheet has fixed light utilities and card colors. */
html[data-theme="dark"] .card {
    --bs-card-bg: var(--rb-surface);
    background-color: var(--rb-surface) !important;
    box-shadow: 0 2px 9px rgba(0, 0, 0, .22) !important;
}
html[data-theme="dark"] :is(.card-header, .card-footer) { color: var(--rb-text) !important; }
html[data-theme="dark"] .card-header .lucide-icon { color: var(--rb-muted) !important; }
html[data-theme="dark"] .info-card .card .card-footer { background-color: var(--rb-surface) !important; }
html[data-theme="dark"] .info-card .content-container :is(.card-title, .description),
html[data-theme="dark"] .info-card .card-footer :is(small, .small) { color: var(--rb-muted); }
html[data-theme="dark"] .info-card .card .card-body .content-container .main-value { color: var(--rb-text) !important; }
html[data-theme="dark"] :is(.text-dark, .text-black) { color: var(--rb-text) !important; }
html[data-theme="dark"] :is(.text-primary, .text-info),
html[data-theme="dark"] .info-card .card .card-body .icon-container .icon-wrapper .lucide:is(.text-info, .text-primary) { color: var(--rb-link) !important; }
html[data-theme="dark"] .text-secondary,
html[data-theme="dark"] .info-card .card .card-body .icon-container .icon-wrapper .lucide.text-secondary { color: var(--rb-muted) !important; }
html[data-theme="dark"] :is(.text-success, .trend-caption.trend-up),
html[data-theme="dark"] .info-card .card .card-body .content-container .main-value.text-success,
html[data-theme="dark"] .info-card .card .card-body .icon-container .icon-wrapper .lucide.text-success { color: var(--rb-positive) !important; }
html[data-theme="dark"] :is(.text-danger, .trend-caption.trend-down) { color: var(--rb-negative) !important; }
html[data-theme="dark"] .text-tertiary { color: var(--rb-accent) !important; }
html[data-theme="dark"] .text-warning,
html[data-theme="dark"] .info-card .card .card-body .icon-container .icon-wrapper .lucide.text-warning { color: var(--rb-warning) !important; }

html[data-theme="dark"] .bg-primary-subtle { background-color: var(--bs-primary-bg-subtle) !important; }
html[data-theme="dark"] .bg-secondary-subtle { background-color: var(--bs-secondary-bg-subtle) !important; }
html[data-theme="dark"] .bg-info-subtle { background-color: var(--bs-info-bg-subtle) !important; }
html[data-theme="dark"] .bg-success-subtle { background-color: var(--bs-success-bg-subtle) !important; }
html[data-theme="dark"] .bg-warning-subtle { background-color: var(--bs-warning-bg-subtle) !important; }
html[data-theme="dark"] :is(.bg-danger-subtle, .bg-tertiary-subtle) { background-color: var(--bs-danger-bg-subtle) !important; }
html[data-theme="dark"] .badge.bg-warning { background-color: var(--bs-warning-bg-subtle) !important; color: var(--rb-warning) !important; }
html[data-theme="dark"] .badge.bg-info { background-color: var(--bs-info-bg-subtle) !important; color: var(--bs-info-text-emphasis) !important; }
html[data-theme="dark"] .badge.bg-success { background-color: var(--bs-success-bg-subtle) !important; color: var(--rb-positive) !important; }
html[data-theme="dark"] .badge.bg-danger { background-color: var(--bs-danger-bg-subtle) !important; color: var(--rb-negative) !important; }
html[data-theme="dark"] .lucide-icon:is(.green, .red, .grey, .orange, .blue) { stroke: currentColor; }
html[data-theme="dark"] .table {
    --bs-table-color: var(--rb-text);
    --bs-table-striped-color: var(--rb-text);
    --bs-table-striped-bg: rgba(170, 196, 232, .06);
    --bs-table-hover-color: var(--rb-text);
    --bs-table-hover-bg: rgba(170, 196, 232, .12);
    --bs-table-border-color: var(--rb-grid);
}
html[data-theme="dark"] .table-light {
    --bs-table-bg: var(--rb-surface-raised);
    --bs-table-color: var(--rb-text);
    --bs-table-border-color: var(--rb-border);
}
html[data-theme="dark"] :is(.modal-content, .offcanvas, .popover) {
    --bs-modal-bg: var(--rb-surface);
    --bs-offcanvas-bg: var(--rb-surface);
    --bs-popover-bg: var(--rb-surface-raised);
}
html[data-theme="dark"] :is(.btn-outline-primary, .btn-outline-secondary, .btn-outline-danger, .btn-outline-success, .btn-outline-warning) {
    --bs-btn-color: var(--rb-button-ink, var(--rb-link));
    --bs-btn-border-color: var(--rb-button-ink, var(--rb-link));
    --bs-btn-hover-bg: var(--rb-button-ink, var(--rb-link));
    --bs-btn-active-bg: var(--rb-button-ink, var(--rb-link));
    --bs-btn-hover-color: var(--rb-bg);
    --bs-btn-active-color: var(--rb-bg);
    --bs-btn-active-border-color: var(--rb-button-ink, var(--rb-link));
    --bs-btn-hover-border-color: var(--rb-button-ink, var(--rb-link));
}
html[data-theme="dark"] .btn-outline-secondary { --rb-button-ink: var(--rb-muted); }
html[data-theme="dark"] .btn-outline-danger { --rb-button-ink: var(--rb-negative); }
html[data-theme="dark"] .btn-outline-success { --rb-button-ink: var(--rb-positive); }
html[data-theme="dark"] .btn-outline-warning { --rb-button-ink: var(--rb-warning); }
html[data-theme="dark"] .btn-primary {
    --bs-btn-bg: #265680;
    --bs-btn-hover-bg: #326b98;
    --bs-btn-active-bg: #315f8b;
    --bs-btn-border-color: #557ba2;
}
html[data-theme="dark"] .btn-light {
    --bs-btn-bg: var(--rb-surface-raised);
    --bs-btn-color: var(--rb-text);
    --bs-btn-border-color: var(--rb-border);
    --bs-btn-hover-bg: #36475f;
    --bs-btn-hover-color: var(--rb-text);
    --bs-btn-active-bg: #405672;
    --bs-btn-active-color: var(--rb-text);
}
html[data-theme="dark"] :is(.form-control, .form-select, .input-group-text) {
    background-color: var(--rb-surface-raised);
    color: var(--rb-text);
    border-color: var(--rb-border);
}
html[data-theme="dark"] :is(.form-control, .form-select):disabled { background-color: var(--rb-bg); color: var(--rb-muted); }
html[data-theme="dark"] :is(.form-control, .form-select):focus { border-color: var(--rb-link); box-shadow: 0 0 0 3px var(--bs-focus-ring-color); }
html[data-theme="dark"] :focus-visible { outline-color: var(--rb-link); }

html[data-theme="dark"] .wn-kicker { color: var(--rb-accent); }
html[data-theme="dark"] :is(.wn-new, .wn-count) { color: #fff; background: #b82552; }
html[data-theme="dark"] .sidebar.minimized .wn-count { border-color: var(--rb-surface); }
html[data-theme="dark"] .wn-type-data { background: var(--bs-primary-bg-subtle); }

/* These menus and calendars can be mounted directly under body. */
html[data-theme="dark"] .fpanel {
    --fp-border: var(--rb-grid);
    --fp-ctl: var(--rb-border);
    --fp-muted: var(--rb-muted);
    --fp-tint: var(--bs-primary-bg-subtle);
    background: var(--rb-surface);
    color: var(--rb-text);
    border-color: var(--rb-border);
}
html[data-theme="dark"] :is(.fp-foot, .fp-collapse) { background: var(--rb-surface); border-color: var(--rb-border); }
html[data-theme="dark"] .fp-count { background: #345879; }
html[data-theme="dark"] .fp-count.zero { background: var(--rb-surface-raised); color: var(--rb-muted); }
html[data-theme="dark"] .fpanel .fp-field.is-set :is(.select2-selection, .form-control) { background-color: var(--bs-primary-bg-subtle); border-color: #6c8cab; }
html[data-theme="dark"] :is(.select2-dropdown, .select2-container--default .select2-selection, .select2-search--dropdown .select2-search__field, .choices__inner, .choices__list--dropdown, .choices__list[aria-expanded], .choices__input) {
    background-color: var(--rb-surface-raised);
    border-color: var(--rb-border);
    color: var(--rb-text);
}
html[data-theme="dark"] .select2-container--default :is(.select2-selection__rendered, .select2-search__field, .select2-selection__choice__remove) { color: var(--rb-text); }
html[data-theme="dark"] .select2-container--default :is(.select2-selection__choice, .select2-results__option--selected, .select2-results__option[aria-selected=true]) {
    color: var(--rb-link);
    background-color: var(--bs-primary-bg-subtle);
    border-color: var(--rb-border);
}
html[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected],
html[data-theme="dark"] .choices__list--dropdown .choices__item--selectable.is-highlighted { background-color: #345678; color: #fff; }
html[data-theme="dark"] .select2-container--default .select2-selection__placeholder { color: var(--rb-muted); }
html[data-theme="dark"] .flatpickr-calendar {
    background: var(--rb-surface-raised);
    color: var(--rb-text);
    box-shadow: 0 4px 18px rgba(0,0,0,.45);
    border: 1px solid var(--rb-border);
}
html[data-theme="dark"] .flatpickr-calendar :is(.flatpickr-month, .flatpickr-prev-month, .flatpickr-next-month, .flatpickr-weekday, .flatpickr-day, .flatpickr-monthSelect-month) { color: var(--rb-text); fill: currentColor; }
html[data-theme="dark"] .flatpickr-calendar :is(.flatpickr-day, .flatpickr-monthSelect-month):hover { background: var(--rb-surface); border-color: var(--rb-link); }
html[data-theme="dark"] .flatpickr-calendar :is(.flatpickr-day, .flatpickr-monthSelect-month).selected { background: #345e86; border-color: var(--rb-link); color: white; }
html[data-theme="dark"] .flatpickr-calendar :is(.flatpickr-disabled, .prevMonthDay, .nextMonthDay) { color: #8591a3; }
html[data-theme="dark"] .flatpickr-monthDropdown-months option { background: var(--rb-surface-raised); }
html[data-theme="dark"] div.swal2-container {
    --swal2-background: var(--rb-surface);
    --swal2-color: var(--rb-text);
    --swal2-input-background: var(--rb-surface-raised);
    --swal2-input-border: 1px solid var(--rb-border);
    --swal2-footer-border-color: var(--rb-border);
    --swal2-validation-message-background: var(--rb-surface-raised);
    --swal2-validation-message-color: var(--rb-text);
}
