/* Shared presentation only. Light and printed/exported reports retain their existing styles. */
@media screen {
    html[data-theme="light"] {
        color-scheme: light;
        --ri-bg: #ffffff;
        --ri-panel: #ffffff;
        --ri-raised: #f3f4f6;
        --ri-hover: #eef2ff;
        --ri-text: #111827;
        --ri-muted: #6b7280;
        --ri-border: #d1d5db;
        --ri-link: #2563eb;
        --ri-teal: #043436;
        --ri-success: #065f46;
        --ri-danger: #b91c1c;
        --ri-warning: #92400e;
    }
    html[data-theme="dark"] {
        color-scheme: dark;
        --ri-bg: #10181d;
        --ri-panel: #19252d;
        --ri-raised: #23343e;
        --ri-hover: #304852;
        --ri-text: #edf3f5;
        --ri-muted: #b5c4cc;
        --ri-border: #526a76;
        --ri-link: #8bc9ff;
        --ri-teal: #80d4cf;
        --ri-success: #83dfad;
        --ri-danger: #ffaaaa;
        --ri-warning: #ffd28a;
        --bg: var(--ri-bg);
        --panel: var(--ri-panel);
        --text: var(--ri-text);
        --muted: var(--ri-muted);
        --border: var(--ri-border);
        --link: var(--ri-link);
        --wm-panel: var(--ri-panel);
        --wm-text: var(--ri-text);
        --wm-muted: var(--ri-muted);
        --wm-border: var(--ri-border);
        --wm-link: var(--ri-link);
        background-color: var(--ri-bg);
        color: var(--ri-text);
    }

    html[data-theme="dark"] body { background-color: var(--ri-bg); color: var(--ri-text); }
    html[data-theme="dark"] body:is(.ri-home, .ri-auth) { background-color: transparent; }
    html[data-theme="dark"] a[href] { color: var(--ri-link); }
    html[data-theme="dark"] .banner {
        background-image: linear-gradient(to bottom, #043436, #23494a);
    }
    html[data-theme="dark"] :is(.ri-userblock, .linkbutton) { color: var(--ri-text); }
    html[data-theme="dark"] :is(.titlestyle, .bodystyle, .bodystylesub, .thirdstyle, .thirdsubstyle) { color: var(--ri-teal); }
    html[data-theme="dark"] .sectionbackground { background-color: rgba(16,24,29,.92); }
    html[data-theme="dark"] :is(.ri-auth-card table, nav ul, nav #login, nav #login-content, nav #login-trigger, nav #signup a) {
        background: var(--ri-panel) !important;
        color: var(--ri-text);
        border-color: var(--ri-border);
    }
    html[data-theme="dark"] .ri-auth-card a { color: var(--ri-teal) !important; }

    /* Existing inline neutral labels in the six pages; semantic status colors are handled separately. */
    html[data-theme="dark"] :is([style*="color: #043436"], [style*="color: #525451"], [style*="color: #2f302f"]) { color: var(--ri-text) !important; }
    html[data-theme="dark"] :is([style*="color: #6b7280"], [style*="color: #555"], [style*="color: #666"], [style*="color: #777"], [style*="color:gray"]) { color: var(--ri-muted) !important; }
    html[data-theme="dark"] :is(.buttontypecheckUsers, .buttontypecheckAccess):hover,
    html[data-theme="dark"] :is(.buttontypecheckUsers, .buttontypecheckAccess) input:checked + span {
        background-color: var(--ri-hover);
        border-left-color: var(--ri-teal);
    }
    /* Compact navigation uses dark surfaces; desktop artwork keeps a light backing. */
    html[data-theme="dark"] :is(.buttontypecheck, .buttontypecheckUsers, .buttontypecheckAccess) label { color: var(--ri-text); }
    html[data-theme="dark"] .buttontypecheck label span { background-color: rgba(16,24,29,.82); }
    html[data-theme="dark"] .buttontypecheck input:checked + span { background-color: rgba(35,73,74,.9); border-color: var(--ri-teal); }
    @media (min-width: 1101px) {
        html[data-theme="dark"] .buttontypecheck { background-color: #edf3f5; }
        html[data-theme="dark"] .buttontypecheck label span,
        html[data-theme="dark"] .buttontypecheck input:checked + span { background-color: transparent; }
        html[data-theme="dark"] .buttontypecheck label span a { background-color: var(--ri-panel); color: var(--ri-text); }
        html[data-theme="dark"] .buttontypecheck input:checked + span a { background-color: #23494a; }
    }

    html[data-theme="dark"] :is(input[type="text"], input[type="password"], input[type="date"], input[type="number"], input[type="email"], input[type="search"], input[type="tel"], select, textarea) {
        background-color: var(--ri-panel) !important;
        color: var(--ri-text) !important;
        border-color: var(--ri-border) !important;
    }
    html[data-theme="dark"] input::placeholder,
    html[data-theme="dark"] textarea::placeholder { color: var(--ri-muted); opacity: 1; }
    html[data-theme="dark"] :is(input, select, textarea):disabled { color: var(--ri-muted) !important; }
    html[data-theme="dark"] :is(input[type="checkbox"], input[type="radio"]) { accent-color: var(--ri-teal); }
    html[data-theme="dark"] :is(a, button, input, select, textarea):focus-visible {
        outline: 2px solid var(--ri-teal) !important;
        outline-offset: 2px;
    }
    html[data-theme="dark"] :is(.buttonstyle, .smallbuttonstyle, .wm-button-secondary, .wm-button-small, .wm-button-site, .wm-button-ghost, .wm-icon-btn, .wm-chip-x, .carousel-nav, .asset-order-btn, .asset-order-x, .asset-image-modal-close, .invdetail-admin-btn, .invdetail-close-btn, .invdetail-images-nav) {
        background-color: var(--ri-raised);
        color: var(--ri-text) !important;
        border-color: var(--ri-border);
    }
    html[data-theme="dark"] :is(.buttonstyle, .smallbuttonstyle, .wm-button-secondary, .wm-button-small, .wm-button-site, .wm-button-ghost, .wm-icon-btn, .wm-chip-x, .carousel-nav, .asset-order-btn, .asset-image-modal-close, .invdetail-admin-btn, .invdetail-close-btn, .invdetail-images-nav):hover {
        background-color: var(--ri-hover);
        border-color: var(--ri-teal);
    }
    html[data-theme="dark"] :is(.wm-button-primary, .invdetail-tab.invdetail-tab-active) { color: #111827; }

    /* Shared GridViews, COA, distributions/import preview and financial report tables. */
    html[data-theme="dark"] :is(.userlistcells, .docslistcells, .userlistcellsheader, .userlistcellsfooter, .invdetail-docs-table th, .invdetail-docs-table td, .invdetail-org-table th, .invdetail-org-table td, .table.investments tr td) { border-color: var(--ri-border); }
    html[data-theme="dark"] .userlistcellsmenu { background-color: #23494a; color: var(--ri-text); }
    html[data-theme="dark"] .userlistcellsmenu a[href] { color: var(--ri-text); }
    html[data-theme="dark"] :is(.grid-compact th, .diagnostic-compact thead th, .balance-table th, .group-header, .section-header, .table.investments thead th, .table-row.alt td) {
        background-color: var(--ri-raised) !important;
        color: var(--ri-text);
    }
    html[data-theme="dark"] .balance-table tbody tr:nth-child(even) { background-color: var(--ri-panel); }
    html[data-theme="dark"] :is(.total-row, .total-row.wrapper-total, .total-row.section-total, .total-row.grand-total, .grand-total, .footer-row) { border-color: var(--ri-muted); }
    html[data-theme="dark"] .gridviewFinancialReports a { color: var(--ri-link); }
    html[data-theme="dark"] .table { color: var(--ri-text); }
    html[data-theme="dark"] .table.investments .details { background-color: var(--ri-panel); }
    html[data-theme="dark"] .table.investments .details::before { background-color: var(--ri-border); }
    html[data-theme="dark"] .table.investments .table-row:hover,
    html[data-theme="dark"] .table.investments .table-row:hover td { background-color: var(--ri-hover); }
    html[data-theme="dark"] .FDscope {
        --fd-text: var(--ri-text);
        --fd-muted: var(--ri-muted);
        --fd-bg: var(--ri-panel);
        --fd-surface: var(--ri-raised);
        --fd-border: var(--ri-border);
        --fd-border-strong: var(--ri-border);
        --fd-row-alt: var(--ri-raised);
        --fd-row-hover: var(--ri-hover);
        --fd-focus: var(--ri-teal);
    }

    html[data-theme="dark"] :is(.activity-item, .activity-day-header, .invdetail-perf-kpi, .ri-loading-card, .asset-upload-progress-inner, .asset-order-panel, .wm-to-chips) { background-color: var(--ri-panel); color: var(--ri-text); border-color: var(--ri-border); }
    html[data-theme="dark"] :is(.invdetail-tabs, .invdetail-kpi-pill, .invdetail-type-pill, .invdetail-image-thumb, .asset-order-item, .asset-order-placeholder, .kpi-card-placeholder, .wm-root, .wm-chip, .wm-attachment-chip, .wm-detail-headerband, .wm-detail-headerband .wm-detail-actions-top) { background-color: var(--ri-raised); color: var(--ri-text); border-color: var(--ri-border); }
    html[data-theme="dark"] :is(.ai-title, .wm-detail-meta, .wm-attachment-item) { color: var(--ri-text); }
    html[data-theme="dark"] :is(.ai-sub, .kpi-group-header, .ri-loading-sub, .asset-upload-area .subtitle, .asset-order-subtitle, .wm-folder-count, .wm-msg-snippet, .wm-msg-when, .wm-msg-bottom) { color: var(--ri-muted); }
    html[data-theme="dark"] :is(.badge, .badge.badge-closed) { color: var(--ri-muted); border-color: var(--ri-border); }
    html[data-theme="dark"] .badge.badge-closed { background-color: var(--ri-raised); }
    html[data-theme="dark"] .invdetail-tab:not(.invdetail-tab-active):hover { background-color: var(--ri-hover); color: var(--ri-text); }
    html[data-theme="dark"] .invdetail-docs-back { color: var(--ri-link); }
    html[data-theme="dark"] .asset-upload-area { background: var(--ri-raised); border-color: var(--ri-border); }
    html[data-theme="dark"] .asset-upload-progress { background-color: rgba(16,24,29,.8); }
    html[data-theme="dark"] :is(.asset-order-header, .asset-order-actions, .wm-card, .wm-detail-actions) { border-color: var(--ri-border); }
    html[data-theme="dark"] :is(.ri-loading-spinner, .spinner-circle) { border-color: var(--ri-border); border-top-color: #ffb020; }

    /* Messages use explicit legacy !important link colors and separate selection states. */
    html[data-theme="dark"] :is(.wm-folders a.wm-folder-link, .wm-listpane a.wm-msg-row-link, .wm-readingpane a.wm-link) { color: var(--ri-text) !important; }
    html[data-theme="dark"] :is(.wm-folder-link:hover, .wm-msg-row-link:hover, .wm-msg-row.wm-msg-active, .wm-msg-row.wm-msg-unread.wm-msg-active) { background-color: var(--ri-hover); box-shadow: inset 0 0 0 1px var(--ri-border); }
    html[data-theme="dark"] :is(.wm-msg-row.wm-msg-unread, .wm-recipient-unread, .wm-folder-link.wm-folder-active) { background-color: #193950; }
    html[data-theme="dark"] .wm-msg-row-selectable.wm-msg-selected { background-color: #25485f !important; outline-color: var(--ri-link) !important; }
    html[data-theme="dark"] :is(.money.in, .wm-alert-info, [style*="color:Green"], [style*="color:green"], [style*="color: #006400"], [style*="color:#2d6a2d" i]) { color: var(--ri-success) !important; }
    html[data-theme="dark"] :is(.money.out, .wm-alert-error, .diagnostic-compact tbody td, [style*="color:Red"], [style*="color:red"]) { color: var(--ri-danger) !important; }
    html[data-theme="dark"] .activity-transfer { color: var(--ri-warning); }

    /* Live organization tree only: export clones sit outside this wrapper. Keep type hue semantics. */
    html[data-theme="dark"] .orgchart-wrapper { background-color: var(--ri-bg); border-color: var(--ri-border); }
    html[data-theme="dark"] .orgchart-wrapper .org-node { background-color: var(--ri-panel); border-color: var(--ri-border); }
    html[data-theme="dark"] .orgchart-wrapper .org-node-type-Asset .org-node { background-color: #193950; border-color: #60a5fa; }
    html[data-theme="dark"] .orgchart-wrapper .org-node-type-Entity .org-node { background-color: #163d35; border-color: #34d399; }
    html[data-theme="dark"] .orgchart-wrapper .org-node-type-Investor .org-node { background-color: #453719; border-color: #fbbf24; }
    html[data-theme="dark"] .orgchart-wrapper .org-node-title { color: var(--ri-text); }
    html[data-theme="dark"] .orgchart-wrapper :is(.org-node-header, .org-node-sub) { color: var(--ri-muted); }
    html[data-theme="dark"] .orgchart-wrapper .org-tree li::before,
    html[data-theme="dark"] .orgchart-wrapper .org-tree li::after,
    html[data-theme="dark"] .orgchart-wrapper .org-node-wrapper::before,
    html[data-theme="dark"] .orgchart-wrapper .org-node-wrapper::after { border-color: var(--ri-border); }

    /* Opaque server-rendered financial PNGs remain white chart cards, with their original pixels. */
    html[data-theme="dark"] :is(.perf-chart-inner, .perf-chart-inner-large, .perf-chart-modal-content) { background-color: #fff; color: #111827; color-scheme: light; }
    html[data-theme="dark"] .perf-chart-btn { background-color: #fff; color: #111827; }
    /* Status artwork is already transparent; do not add a canvas behind it. */
    html[data-theme="dark"] :is(img, input[type="image"]):is([src$="/greendot.png"], [src$="/reddot.png"], [src$="/greydot.png"]) { background-color: transparent; border-radius: 2px; }
    /* Only these two monochrome message glyphs need a light Dark-mode foreground. */
    html[data-theme="dark"] :is(.wm-attach-icon, .wm-trashicon-btn) { filter: brightness(0) invert(1); }
    .wm-trashicon-btn:focus-visible { outline: 2px solid var(--ri-link, #2563eb); outline-offset: 2px; }
    .ri-sort-indicator { width: 14px; height: 14px; background: transparent; border: 0; vertical-align: middle; cursor: pointer; }
    html[data-theme="dark"] .ri-sort-indicator { filter: brightness(0) invert(1); background: transparent; }
    .ri-sort-indicator:focus-visible { outline: 2px solid var(--ri-link, #2563eb); outline-offset: 2px; }

    html[data-theme="dark"] :is(.ui-widget-content, .ui-widget-header, .ui-datepicker, .ui-datepicker .ui-state-default) { background: var(--ri-panel); color: var(--ri-text); border-color: var(--ri-border); }
    html[data-theme="dark"] .ui-datepicker :is(.ui-state-hover, .ui-state-active) { background: var(--ri-hover); color: var(--ri-text); }
    html[data-theme="dark"] .ui-datepicker .ui-icon { background-color: transparent; filter: brightness(0) invert(1); }
}
