/* Orbit dark theme is loaded after page-level styles so mobile workspace rules
   cannot accidentally restore light backgrounds or dark-on-dark text. */
html[data-theme="dark"] body.member-portal-app,
html[data-theme="dark"] body.member-portal-app .content,
html[data-theme="dark"] body.member-portal-app .content > .p-3,
html[data-theme="dark"] body.member-portal-app .app-shell,
html[data-theme="dark"] body.member-portal-app .main-content,
html[data-theme="dark"] body.member-portal-app .member-portal-panel,
html[data-theme="dark"] body.member-portal-app .member-portal-sections,
html[data-theme="dark"] body.member-portal-app .member-dashboard-section,
html[data-theme="dark"] body.member-portal-app [data-member-home-summary],
html[data-theme="dark"] body.member-portal-app #member-profile,
html[data-theme="dark"] body.member-portal-app .member-profile-workspace {
    color: #e8eef7 !important;
    background: #07111f !important;
}

html[data-theme="dark"] body.member-portal-app .member-mobile-welcome h2,
html[data-theme="dark"] body.member-portal-app .member-home-section-heading h3,
html[data-theme="dark"] body.member-portal-app .member-section-title h1,
html[data-theme="dark"] body.member-portal-app .member-section-title h2,
html[data-theme="dark"] body.member-portal-app .member-section-title h3,
html[data-theme="dark"] body.member-portal-app .member-profile-page-title,
html[data-theme="dark"] body.member-portal-app .member-profile-hero h2,
html[data-theme="dark"] body.member-portal-app .member-profile-hero h3,
html[data-theme="dark"] body.member-portal-app .member-profile-hero strong {
    color: #f8fafc !important;
}

html[data-theme="dark"] body.member-portal-app .member-mobile-welcome p,
html[data-theme="dark"] body.member-portal-app .member-profile-hero-email,
html[data-theme="dark"] body.member-portal-app .member-profile-menu-label,
html[data-theme="dark"] body.member-portal-app .member-profile-collapse > summary small,
html[data-theme="dark"] body.member-portal-app .member-profile-security-link small,
html[data-theme="dark"] body.member-portal-app .text-muted {
    color: #9fb0c4 !important;
}

html[data-theme="dark"] body.member-portal-app .member-mobile-welcome-actions a,
html[data-theme="dark"] body.member-portal-app .member-mobile-welcome-actions button,
html[data-theme="dark"] body.member-portal-app .member-home-quick-actions,
html[data-theme="dark"] body.member-portal-app .member-service-grid,
html[data-theme="dark"] body.member-portal-app .member-home-metric,
html[data-theme="dark"] body.member-portal-app .member-profile-hero,
html[data-theme="dark"] body.member-portal-app .member-profile-form-section,
html[data-theme="dark"] body.member-portal-app .member-profile-kyc-panel,
html[data-theme="dark"] body.member-portal-app .member-profile-collapse,
html[data-theme="dark"] body.member-portal-app .member-profile-security-link,
html[data-theme="dark"] body.member-portal-app .member-section-card,
html[data-theme="dark"] body.member-portal-app .member-savings-workspace,
html[data-theme="dark"] body.member-portal-app .member-savings-plan-card,
html[data-theme="dark"] body.member-portal-app .member-loan-workspace,
html[data-theme="dark"] body.member-portal-app .card,
html[data-theme="dark"] body.member-portal-app .modal-content,
html[data-theme="dark"] body.member-portal-app .offcanvas,
html[data-theme="dark"] body.member-portal-app .dropdown-menu {
    color: #e8eef7 !important;
    border-color: #26364a !important;
    background: #101d2d !important;
    box-shadow: none !important;
}

html[data-theme="dark"] body.member-portal-app .member-home-quick-actions a,
html[data-theme="dark"] body.member-portal-app .member-home-quick-actions button,
html[data-theme="dark"] body.member-portal-app .member-service-grid a,
html[data-theme="dark"] body.member-portal-app .member-service-grid button,
html[data-theme="dark"] body.member-portal-app .member-profile-quick-links > a,
html[data-theme="dark"] body.member-portal-app .member-profile-setting-button,
html[data-theme="dark"] body.member-portal-app .member-profile-collapse > summary,
html[data-theme="dark"] body.member-portal-app .member-profile-collapse > summary > span > i,
html[data-theme="dark"] body.member-portal-app .member-profile-security-link {
    color: #e8eef7 !important;
    border-color: #26364a !important;
}

html[data-theme="dark"] body.member-portal-app .member-home-quick-actions > * {
    border-right-color: #26364a !important;
}

html[data-theme="dark"] body.member-portal-app .member-profile-collapse[open] > summary,
html[data-theme="dark"] body.member-portal-app .member-profile-collapse > summary:hover,
html[data-theme="dark"] body.member-portal-app .member-profile-security-link:hover,
html[data-theme="dark"] body.member-portal-app .member-profile-quick-links > a:hover {
    color: #f8fafc !important;
    border-color: #36506b !important;
    background: #15263a !important;
}

html[data-theme="dark"] body.member-portal-app .member-profile-setting-button:disabled {
    color: #aab8c9 !important;
    opacity: 1 !important;
}

html[data-theme="dark"] body.member-portal-app .member-profile-setting-button:disabled > i,
html[data-theme="dark"] body.member-portal-app .member-profile-setting-button:disabled strong {
    color: #aab8c9 !important;
}

html[data-theme="dark"] body.member-portal-app .member-profile-collapse > summary > i:last-child,
html[data-theme="dark"] body.member-portal-app .member-profile-quick-links > a > i:last-child,
html[data-theme="dark"] body.member-portal-app .member-home-metric .card-body > i:last-child {
    color: #8fa2b8 !important;
}

html[data-theme="dark"] body.member-portal-app .member-home-metric .h4,
html[data-theme="dark"] body.member-portal-app .member-home-metric strong,
html[data-theme="dark"] body.member-portal-app .member-home-metric span {
    color: #e8eef7 !important;
}

html[data-theme="dark"] body.member-portal-app .form-control,
html[data-theme="dark"] body.member-portal-app .form-select,
html[data-theme="dark"] body.member-portal-app .input-group-text,
html[data-theme="dark"] body.member-portal-app .list-group-item,
html[data-theme="dark"] body.member-portal-app .table {
    color: #e8eef7 !important;
    border-color: #314158 !important;
    background-color: #0c1928 !important;
}

html[data-theme="dark"] body.member-portal-app .table {
    --bs-table-bg: #0c1928;
    --bs-table-color: #e8eef7;
    --bs-table-border-color: #314158;
    --bs-table-striped-bg: #132236;
    --bs-table-hover-bg: #192b42;
}

html[data-theme="dark"] body.member-portal-app .bg-white,
html[data-theme="dark"] body.member-portal-app .bg-light {
    color: #e8eef7 !important;
    background-color: #101d2d !important;
}

html[data-theme="dark"] body.member-portal-app .mobile-bottom-nav {
    color: #b8c5d4 !important;
    border-top-color: #26364a !important;
    background: #0b1726 !important;
}

html[data-theme="dark"] body.member-portal-app .mobile-bottom-nav a,
html[data-theme="dark"] body.member-portal-app .mobile-bottom-nav button {
    color: #b8c5d4 !important;
}

html[data-theme="dark"] body.member-portal-app .mobile-bottom-nav .active {
    color: var(--tenant-primary, #2dd4bf) !important;
}

html[data-theme="dark"] body.member-portal-app .border,
html[data-theme="dark"] body.member-portal-app .border-top,
html[data-theme="dark"] body.member-portal-app .border-bottom,
html[data-theme="dark"] body.member-portal-app hr {
    border-color: #314158 !important;
}

html[data-theme="dark"] body.member-portal-app input::placeholder,
html[data-theme="dark"] body.member-portal-app textarea::placeholder {
    color: #74869c !important;
}

html[data-theme="dark"] body.member-portal-app .member-investment-risk-confirmation {
    color: #e8eef7 !important;
    border-color: #9a6700 !important;
    background: #2a210d !important;
}

html[data-theme="dark"] body.member-portal-app .member-investment-risk-confirmation-head span {
    color: #dbc58b !important;
}

html[data-theme="dark"] body.member-portal-app .member-investment-risk-check {
    border-top-color: rgba(245, 158, 11, .3) !important;
}

/* Neutral theme tokens shared by member, staff, and administration screens.
   Keep colored hero headers, status badges, and receipt exports independent. */
html[data-theme="dark"] {
    --orbit-dark-page: #07111f;
    --orbit-dark-panel: #101d2d;
    --orbit-dark-inset: #15263b;
    --orbit-dark-border: #40546e;
    --orbit-dark-text: #e8eef7;
    --orbit-dark-muted: #aebfd3;
    --bs-body-color: #e8eef7;
    --bs-body-bg: #07111f;
    --bs-secondary-color: #aebfd3;
    --bs-tertiary-color: #aebfd3;
    --bs-emphasis-color: #f8fafc;
    --bs-border-color: #40546e;
    --bs-secondary-bg: #15263b;
    --bs-tertiary-bg: #101d2d;
    --bs-link-color: #93c5fd;
    --bs-link-hover-color: #bfdbfe;
    color-scheme: dark;
}

/* Pop-ups live outside the dashboard sections. Theme their bodies explicitly. */
html[data-theme="dark"] body :is(
    .modal-body, .modal-footer, .offcanvas-body, .card-header, .card-footer,
    .member-create-modal-header, .member-create-tab-body,
    .member-wallet-funding-modal .modal-body, .member-wallet-bank-card,
    .member-bank-card, .member-bank-picker-menu, .member-bank-picker-option,
    .member-transfer-source, .member-transfer-review > div,
    .member-bill-extra, .member-bill-selected, .member-bill-credit-option,
    .member-autodebit-box, .member-save-now-panel, .member-source-pill,
    .member-more-menu-grid a, .member-create-option, .member-loan-extra-box,
    .member-savings-money-modal .modal-body, .member-target-initial-card,
    .member-target-stat-grid > section, .member-loan-schedule-item,
    .member-loan-schedule-list, .member-loan-history-card-meta > div,
    .member-transaction-item, .member-transaction-detail,
    .member-transaction-detail-grid > div, .member-visible-balance-summary,
    .member-transaction-empty, .member-notification-history,
    .member-notification-history-head, .member-notification-item,
    .member-dashboard-notifications, .member-dashboard-notification-item,
    .member-profile-status-grid > div, .member-profile-photo-card,
    .member-profile-tab-panel, .member-profile-help, .member-savings-history-item,
    .member-savings-product-card, .member-report-panel, .member-report-head,
    .member-report-body, .member-report-summary > div,
    .member-table-shell, .member-side-panel, .member-action-panel,
    .member-directory-card, .member-directory-head, .member-filter-strip,
    .member-form-summary, .member-form-summary > div,
    .app-filter-collapse, .app-filter-body, .finance-workspace,
    .finance-filter-panel, .finance-form-panel, .finance-editor-card,
    .finance-guide-card, .finance-product-card, .finance-product-section,
    .finance-table-shell, .customer-form-card, .customer-form-option,
    .customer-submit-bar, .customer-bulk-panel, .loan-security-panel,
    .coa-workspace, .coa-tree, .coa-create-panel, .coa-company-picker,
    .ledger-detail-card, .ledger-detail-card > div, .journal-balance-panel,
    .journal-balance-panel > div, .journal-line-toolbar, .balance-sheet-summary-card,
    .notification-inbox-layout, .notification-side-kpi, .notification-side-note,
    .approval-bell-item, .operations-focus-card, .operations-link-card,
    .super-report-card, .super-detail-tile, .merchant-command-card,
    .merchant-command-metric, .aging-bucket-card, .billing-summary > div,
    .automation-channel-option, .automation-template-summary
) {
    background: var(--orbit-dark-panel) !important;
    color: var(--orbit-dark-text) !important;
    border-color: var(--orbit-dark-border) !important;
    box-shadow: none !important;
}

/* Text on custom neutral cards must not retain the light theme's ink colors. */
html[data-theme="dark"] body :is(
    .modal-body, .modal-footer, .member-wallet-bank-card, .member-bank-card,
    .member-transfer-review, .member-more-menu-grid, .member-create-option,
    .member-loan-extra-box, .member-loan-schedule-item,
    .member-target-initial-card, .member-target-stat-grid,
    .member-visible-balance-summary, .member-transaction-detail-grid,
    .member-notification-item, .member-dashboard-notification-item,
    .member-profile-status-grid, .member-savings-history-item,
    .member-report-panel, .finance-workspace, .customer-form-card,
    .coa-workspace, .ledger-detail-card, .journal-balance-panel,
    .notification-inbox-layout, .operations-focus-card, .operations-link-card
) :is(h1, h2, h3, h4, h5, h6, p, label, dt, dd, strong) {
    color: var(--orbit-dark-text) !important;
}

html[data-theme="dark"] body :is(
    .form-label, .form-check-label, .col-form-label, .modal-title,
    .member-transaction-title, .member-wallet-bank-card p,
    .member-bank-picker-copy strong, .member-transfer-source strong,
    .member-funding-account strong, .member-target-stat-grid strong,
    .member-savings-target-main strong, .member-notification-title,
    .member-report-summary strong, .member-product-catalog-head strong,
    .member-product-catalog-stats strong, .member-loan-history-card-head strong
) {
    color: var(--orbit-dark-text) !important;
}

html[data-theme="dark"] body :is(
    .form-text, .member-form-hint, .member-transaction-meta,
    .member-transaction-detail-grid span, .member-visible-balance-summary small,
    .member-visible-balance-summary > span, .member-wallet-bank-card span,
    .member-bank-picker-copy small, .member-notification-item small,
    .member-dashboard-notification-item small, .member-product-catalog-head small,
    .member-product-catalog-stats span, .member-product-catalog-meta span,
    .member-loan-history-card-meta span, .approval-bell-item span
) {
    color: var(--orbit-dark-muted) !important;
}

html[data-theme="dark"] body :is(input, textarea)::placeholder {
    color: #aebfd3 !important;
    opacity: 1;
}

html[data-theme="dark"] body :is(.form-control, .form-select):disabled,
html[data-theme="dark"] body .form-control[readonly] {
    background-color: #1b2c40 !important;
    color: #bac9db !important;
    opacity: 1;
}

html[data-theme="dark"] body :is(
    .member-wallet-funding-tabs, .member-create-tabs, .member-profile-main-tabs,
    .member-report-tabs, .notification-tabs, .finance-tabs
) {
    background: #0c1928 !important;
    border-color: var(--orbit-dark-border) !important;
}

html[data-theme="dark"] body :is(
    .member-wallet-funding-tabs .nav-link, .member-create-tabs button,
    .member-profile-main-tabs button, .member-report-tabs button,
    .member-report-tabs a, .notification-tabs .nav-link, .finance-tabs .nav-link
) {
    color: #c6d4e5 !important;
    background: #15263b !important;
    border-color: var(--orbit-dark-border) !important;
}

html[data-theme="dark"] body :is(
    .member-wallet-funding-tabs .nav-link, .member-create-tabs button,
    .member-profile-main-tabs button, .member-report-tabs button,
    .member-report-tabs a, .notification-tabs .nav-link, .finance-tabs .nav-link
).active {
    color: #fff !important;
    background: #1d4ed8 !important;
    border-color: #608cff !important;
}

html[data-theme="dark"] body :is(
    .member-notification-item.unread, .member-dashboard-notification-item.unread,
    .member-bank-picker-option:hover, .approval-bell-item:hover
) {
    background: #1b3049 !important;
}

html[data-theme="dark"] body :is(
    .member-notifications-close, .member-notification-clear,
    .member-savings-back, .member-savings-more, .member-loan-back,
    .member-create-target-back, .member-target-date-open
) {
    color: #e8eef7 !important;
    background: #15263b !important;
    border-color: var(--orbit-dark-border) !important;
}

html[data-theme="dark"] body .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
    opacity: .9;
}

html[data-theme="dark"] body :is(.text-dark, .text-body, .text-black) {
    color: #e8eef7 !important;
}
html[data-theme="dark"] body :is(.text-muted, .text-secondary) {
    color: #aebfd3 !important;
}
html[data-theme="dark"] body .text-primary { color: #93c5fd !important; }
html[data-theme="dark"] body .text-success { color: #6ee7b7 !important; }
html[data-theme="dark"] body .text-danger { color: #fda4af !important; }
html[data-theme="dark"] body .text-warning { color: #fcd34d !important; }
html[data-theme="dark"] body .text-info { color: #67e8f9 !important; }

html[data-theme="dark"] body .btn-outline-primary {
    --bs-btn-color: #93c5fd;
    --bs-btn-border-color: #6092cf;
    --bs-btn-hover-bg: #1d4ed8;
    --bs-btn-hover-color: #fff;
}
html[data-theme="dark"] body .btn-outline-success {
    --bs-btn-color: #6ee7b7;
    --bs-btn-border-color: #409e80;
    --bs-btn-hover-bg: #14634e;
    --bs-btn-hover-color: #fff;
}
html[data-theme="dark"] body .btn-outline-secondary {
    --bs-btn-color: #c6d4e5;
    --bs-btn-border-color: #647b96;
    --bs-btn-hover-bg: #314158;
    --bs-btn-hover-color: #fff;
}

html[data-theme="dark"] body :is(.member-table, .member-report-table, .finance-table, .table) {
    --bs-table-bg: #101d2d;
    --bs-table-color: #e8eef7;
    --bs-table-striped-bg: #15263b;
    --bs-table-striped-color: #e8eef7;
    --bs-table-hover-bg: #1b3049;
    --bs-table-hover-color: #f8fafc;
    color: #e8eef7 !important;
    border-color: #40546e !important;
}
html[data-theme="dark"] body :is(.member-table, .member-report-table, .finance-table) :is(th, td) {
    background: #101d2d !important;
    color: #e8eef7 !important;
    border-color: #40546e !important;
}

html[data-theme="dark"] body .mobile-bottom-nav .active {
    color: #93c5fd !important;
}
html[data-theme="dark"] body :is(button, a, input, select, textarea):focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}

html[data-theme="dark"] body.member-portal-app :is(input, textarea)::placeholder {
    color: #aebfd3 !important;
    opacity: 1;
}
html[data-theme="dark"] body :is(
    .member-transfer-review span, .member-transfer-source span,
    .member-loan-selected-product span, .member-bank-card small,
    .member-loan-extra-summary small, .member-profile-status-grid span,
    .member-savings-target-main small, .member-report-summary span
) {
    color: #aebfd3 !important;
}
/* Status utilities must remain distinct even inside a themed form or card. */
html[data-theme="dark"] body [class].text-success { color: #6ee7b7 !important; }
html[data-theme="dark"] body [class].text-danger { color: #fda4af !important; }
html[data-theme="dark"] body [class].text-warning { color: #fcd34d !important; }
html[data-theme="dark"] body [class].text-info { color: #67e8f9 !important; }

/* Remaining shared neutral surfaces used by bills, targets, and staff tools. */
html[data-theme="dark"] body :is(
    .bg-white, .bg-light, .member-bill-service-card, .member-beneficiary-save,
    .member-collapsible-panel, .member-collapsible-stack, .member-profile-accordion,
    .member-notification-empty, .member-savings-action-empty,
    .member-savings-target-number, .member-savings-view-target,
    .member-loan-bill-repay-row, .member-bank-verification,
    .member-transfer-action:not(.primary), .member-profile-kyc-panel.muted,
    .member-table thead th, .member-report-table thead th,
    .member-picker-action, .member-pagination-buttons a,
    .member-pagination-buttons > span, .notification-cost-item,
    .notification-audience-card > strong, .aging-limit-note,
    .balance-sheet-equation, .finance-guide-list > div,
    .finance-guide-item, .finance-pane-title, .expense-top-card,
    .expense-category-list > div, .accounting-quick-filter,
    .automation-channel-summary, .automation-template-grid,
    .automation-channel-grid-open, .automation-channel-grid-collapsed,
    .bill-service-tile, .bill-status-form, .operations-action,
    .merchant-funding-detail, .merchant-incentive-card,
    .super-assignment-stat, .super-company-mini-stat
) {
    background: #101d2d !important;
    color: #e8eef7 !important;
    border-color: #40546e !important;
}
html[data-theme="dark"] body :is(
    .member-bill-service-card, .member-beneficiary-save, .member-profile-kyc-panel.muted,
    .member-savings-action-empty, .member-loan-bill-repay-row,
    .member-bank-verification, .member-transfer-action:not(.primary),
    .member-collapsible-panel, .member-report-panel
) :is(strong, p, h3, h4) {
    color: #e8eef7 !important;
}
html[data-theme="dark"] body :is(
    .member-bill-service-card.active, .member-bill-service-card:hover,
    .member-create-option.active, .member-savings-product-card.active,
    .member-savings-product-card:hover
) {
    background: #1b3049 !important;
    border-color: #93c5fd !important;
}

/* Page-local support and product styles also participate in the shared theme. */
html[data-theme="dark"] body :is(
    .member-support-header, .member-support-item, .member-support-close,
    .member-product-card, .member-loan-interest-detail-popout,
    .member-loan-rate-basis-toggle, #member-charges article
) {
    background: #101d2d !important;
    color: #e8eef7 !important;
    border-color: #40546e !important;
}
html[data-theme="dark"] body :is(
    .member-support-title, .member-support-item-value, .member-product-card strong,
    .member-loan-interest-detail-popout strong
) { color: #e8eef7 !important; }
html[data-theme="dark"] body :is(
    .member-support-eyebrow, .member-support-item-label, .member-product-card small,
    .member-product-card-meta span, .member-loan-interest-detail-popout span
) { color: #aebfd3 !important; }
html[data-theme="dark"] body .member-product-card.active {
    background: #1b3049 !important;
    border-color: #93c5fd !important;
}
