/* Shared surfaces preserve the existing light palette and opt into dark mode. */
:root {
    --site-surface: #fafafa;
    --site-surface-muted: #e8f1f5;
    --site-surface-soft: #f8f9fa;
    --site-text: #212529;
    --site-muted: #6c757d;
    --site-border: #dee2e6;
    --site-control-border: #dee2e6;
    --site-selection-bg: #e7f3ff;
    --site-danger: #dc3545;
    --site-link: #3f72af;
    --site-skeleton-base: #f6f7f8;
    --site-skeleton-highlight: #edeef1;
}
:root[data-bs-theme="dark"] {
    color-scheme: dark;
    --site-surface: #172332;
    --site-surface-muted: #213246;
    --site-surface-soft: #1c2b3c;
    --site-text: #e5edf5;
    --site-muted: #a8b8ca;
    --site-border: #3a4b60;
    --site-control-border: #75869b;
    --site-selection-bg: #263f5b;
    --site-danger: #ff91a2;
    --site-link: #8dbbf0;
    --site-skeleton-base: #24364a;
    --site-skeleton-highlight: #31465e;
    --bs-body-bg: #101924;
    --bs-body-bg-rgb: 16, 25, 36;
    --bs-body-color: #e5edf5;
    --bs-body-color-rgb: 229, 237, 245;
    --bs-secondary-color: #a8b8ca;
    --bs-secondary-bg: #213246;
    --bs-tertiary-bg: #1c2b3c;
    --bs-border-color: #3a4b60;
    --bs-link-color: #8dbbf0;
    --bs-link-color-rgb: 141, 187, 240;
    --bs-link-hover-color: #b9d7fa;
    --bs-link-hover-color-rgb: 185, 215, 250;
    --bs-emphasis-color: #f5f8fc;
    --bs-emphasis-color-rgb: 245, 248, 252;
}
.site-theme-control { display: inline-flex; align-items: center; margin: 0 .5rem; }
.press-mentions .hero-logo { filter: grayscale(1); opacity: .4; }
[data-bs-theme="dark"] .hero-logo {
    filter: grayscale(1) invert(1) !important;
    opacity: .8 !important;
}
#desktop-topbar > .desktop-topbar-search { flex: 1 1 0; width: auto; min-width: 0; }
#desktop-topbar > .desktop-topbar-actions { flex: 0 0 auto; width: auto; }
#dropdown-feedback { display: inline-flex; align-items: center; white-space: nowrap; }
.site-preference-select {
    appearance: auto;
    color: var(--site-text);
    background-color: var(--site-surface);
    border: 1px solid var(--site-border);
    border-radius: .25rem;
    padding: .125rem .25rem;
    font: inherit;
    height: 1.75rem;
    width: auto;
    max-width: 7rem;
}
.site-theme-control select:focus-visible,
.site-panel-toggle:focus-visible { outline: 2px solid var(--site-link); outline-offset: 2px; }
.site-panel-toggle {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
}
.site-panel-toggle.panel-title-left::after {
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    line-height: 0;
}

/* Enhanced selects render buttons instead of the native select element. */
.bootstrap-select > .dropdown-toggle,
.multiselect.dropdown-toggle {
    --bs-btn-bg: var(--site-surface);
    --bs-btn-hover-bg: var(--site-surface);
    --bs-btn-active-bg: var(--site-surface);
    --bs-btn-disabled-bg: var(--site-surface);
    background-color: var(--site-surface);
}

/* Legacy utilities intentionally describe light surfaces, so map them by mode. */
[data-bs-theme="dark"] .bg-white { background-color: var(--site-surface) !important; }
[data-bs-theme="dark"] .bg-light { background-color: var(--site-surface-muted) !important; }
[data-bs-theme="dark"] .table-light {
    --bs-table-color: var(--site-text);
    --bs-table-bg: var(--site-surface-muted);
    --bs-table-border-color: var(--site-border);
    --bs-table-striped-color: var(--site-text);
    --bs-table-striped-bg: var(--site-surface-soft);
    --bs-table-hover-color: var(--site-text);
    --bs-table-hover-bg: var(--site-surface-soft);
    --bs-table-active-color: var(--site-text);
    --bs-table-active-bg: var(--site-surface-soft);
}
[data-bs-theme="dark"] .text-dark,
[data-bs-theme="dark"] .text-black,
[data-bs-theme="dark"] .text-body { color: var(--site-text) !important; }
[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-secondary { color: var(--site-muted) !important; }
[data-bs-theme="dark"] .text-primary { color: var(--site-link) !important; }
[data-bs-theme="dark"] .border-light,
[data-bs-theme="dark"] .border-dark { border-color: var(--site-border) !important; }
[data-bs-theme="dark"] .btn-light,
[data-bs-theme="dark"] .btn-outline-light {
    --bs-btn-color: var(--site-text);
    --bs-btn-bg: var(--site-surface-soft);
    --bs-btn-border-color: var(--site-border);
    --bs-btn-hover-color: var(--site-text);
    --bs-btn-hover-bg: var(--site-surface-muted);
    --bs-btn-hover-border-color: var(--site-border);
    --bs-btn-active-color: var(--site-text);
    --bs-btn-active-bg: var(--site-surface-muted);
    --bs-btn-active-border-color: var(--site-link);
}
[data-bs-theme="dark"] .bootstrap-select > .dropdown-toggle,
[data-bs-theme="dark"] .multiselect.dropdown-toggle,
[data-bs-theme="dark"] .selectpicker {
    color: var(--site-text) !important;
    background-color: var(--site-surface) !important;
}
[data-bs-theme="dark"] .bootstrap-select .dropdown-menu .notify,
[data-bs-theme="dark"] .bootstrap-select .no-results,
[data-bs-theme="dark"] .ui-widget-content,
[data-bs-theme="dark"] .ui-autocomplete,
[data-bs-theme="dark"] .ui-menu-item-wrapper {
    color: var(--site-text) !important;
    background: var(--site-surface) !important;
    border-color: var(--site-border) !important;
}
[data-bs-theme="dark"] .ui-state-active,
[data-bs-theme="dark"] .ui-state-focus,
[data-bs-theme="dark"] .multiselect-container .multiselect-option:hover {
    color: var(--site-text) !important;
    background-color: var(--site-surface-muted) !important;
}
[data-bs-theme="dark"] .navbar-brand img,
[data-bs-theme="dark"] img[alt="Logo"] { filter: brightness(1.8); }
[data-bs-theme="dark"] .panel-title::after,
[data-bs-theme="dark"] .panel-title-left::after,
[data-bs-theme="dark"] .panel-btn::after { filter: brightness(0) invert(1); }
@media print {
    :root[data-bs-theme="dark"] {
        --site-surface: #fff;
        --site-surface-muted: #eee;
        --site-surface-soft: #f8f9fa;
        --site-text: #212529;
        --site-muted: #6c757d;
        --site-border: #dee2e6;
        --site-link: #3f72af;
        --bs-body-bg: #fff;
        --bs-body-color: #212529;
    }
    .site-theme-control { display: none !important; }
}

[data-bs-theme="dark"] .mobile-transaction-type-pill.positive { background: #193d2b; color: #8bdfab; }
[data-bs-theme="dark"] .mobile-transaction-type-pill.negative { background: #49272f; color: #f5a4b2; }
[data-bs-theme="dark"] .mobile-transaction-type-pill.neutral { background: var(--site-surface-muted); color: var(--site-muted); }

[data-bs-theme="dark"] .text-success { color: #77d69a !important; }
[data-bs-theme="dark"] .text-danger { color: #ff91a2 !important; }
[data-bs-theme="dark"] .mobile-transaction-value.negative,
[data-bs-theme="dark"] .mobile-transaction-type.negative { color: #ff91a2; }
[data-bs-theme="dark"] .mobile-transaction-value.positive,
[data-bs-theme="dark"] .mobile-transaction-type.positive { color: #77d69a; }
[data-bs-theme="dark"] .popular-badge {
    color: #8bdfab;
    background: #193d2b;
}
[data-bs-theme="dark"] .llt-live { color: #8bdfab; }
[data-bs-theme="dark"] .llt-live-dot { background: #77d69a; }
[data-bs-theme] :is(p, td, dd, label, h6) a:not(.btn):not(.badge) {
    text-decoration: underline;
    text-underline-offset: .15em;
}
[data-bs-theme="dark"] .site-score-value {
    color: var(--site-text) !important;
    color: color-mix(in srgb, var(--site-score-color, var(--site-text)) 45%, var(--site-text)) !important;
}

/* Keep primary actions distinct from dark surfaces, including legacy navy buttons. */
[data-bs-theme="dark"] .btn-primary,
[data-bs-theme="dark"] .btn-dark {
    --bs-btn-color: #101924;
    --bs-btn-bg: #8dbbf0;
    --bs-btn-border-color: #8dbbf0;
    --bs-btn-hover-color: #101924;
    --bs-btn-hover-bg: #b9d7fa;
    --bs-btn-hover-border-color: #b9d7fa;
    --bs-btn-active-color: #101924;
    --bs-btn-active-bg: #74a9e6;
    --bs-btn-active-border-color: #74a9e6;
    --bs-btn-disabled-color: #101924;
    --bs-btn-disabled-bg: #8dbbf0;
    --bs-btn-disabled-border-color: #8dbbf0;
    --bs-btn-focus-shadow-rgb: 141, 187, 240;
    border-color: var(--bs-btn-border-color) !important;
}
[data-bs-theme="dark"] .btn-outline-primary {
    --bs-btn-color: #8dbbf0;
    --bs-btn-border-color: #8dbbf0;
    --bs-btn-hover-color: #101924;
    --bs-btn-hover-bg: #8dbbf0;
    --bs-btn-hover-border-color: #8dbbf0;
    --bs-btn-active-color: #101924;
    --bs-btn-active-bg: #74a9e6;
    --bs-btn-active-border-color: #74a9e6;
    --bs-btn-disabled-color: #8dbbf0;
    --bs-btn-disabled-border-color: #8dbbf0;
    --bs-btn-focus-shadow-rgb: 141, 187, 240;
}
[data-bs-theme="dark"] .btn-outline-danger {
    --site-outline-tone: var(--site-danger);
    --bs-btn-focus-shadow-rgb: 255, 145, 162;
}
[data-bs-theme="dark"] .btn-outline-secondary {
    --site-outline-tone: var(--site-muted);
    --bs-btn-focus-shadow-rgb: 168, 184, 202;
}
[data-bs-theme="dark"] .btn-outline-danger,
[data-bs-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--site-outline-tone);
    --bs-btn-border-color: var(--site-outline-tone);
    --bs-btn-hover-color: #101924;
    --bs-btn-hover-bg: var(--site-outline-tone);
    --bs-btn-hover-border-color: var(--site-outline-tone);
    --bs-btn-active-color: #101924;
    --bs-btn-active-bg: var(--site-outline-tone);
    --bs-btn-active-border-color: var(--site-outline-tone);
    --bs-btn-disabled-color: var(--site-outline-tone);
    --bs-btn-disabled-border-color: var(--site-outline-tone);
}

/* Outline actions need a light foreground even when their light-mode class is dark. */
[data-bs-theme="dark"] .btn-outline-dark {
    --bs-btn-color: var(--site-text);
    --bs-btn-border-color: var(--site-control-border);
    --bs-btn-hover-color: var(--site-text);
    --bs-btn-hover-bg: var(--site-surface-muted);
    --bs-btn-hover-border-color: var(--site-muted);
    --bs-btn-active-color: var(--site-text);
    --bs-btn-active-bg: var(--site-surface-muted);
    --bs-btn-active-border-color: var(--site-muted);
    --bs-btn-disabled-color: var(--site-muted);
    --bs-btn-disabled-border-color: var(--site-border);
}
/* Control boundaries and keyboard focus must remain visible on every dark surface. */
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] .form-check-input,
[data-bs-theme="dark"] .site-preference-select,
[data-bs-theme="dark"] .bootstrap-select > .dropdown-toggle,
[data-bs-theme="dark"] .multiselect.dropdown-toggle,
[data-bs-theme="dark"] .btn-light,
[data-bs-theme="dark"] .btn-outline-light {
    border-color: var(--site-control-border) !important;
}
[data-bs-theme="dark"] :is(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--site-link) !important;
    outline-offset: 3px;
}
[data-bs-theme="dark"] #icp-input:focus-visible {
    outline-offset: -2px;
}
[data-bs-theme="dark"] .icp-item.active,
[data-bs-theme="dark"] .icp-load-more.active {
    box-shadow: inset 3px 0 0 var(--site-link);
}
[data-bs-theme="dark"] hr { color: var(--site-border); opacity: 1; }
[data-bs-theme="dark"] #screener_form .border,
[data-bs-theme="dark"] #insider-purchases .border-bottom {
    border-color: var(--site-border) !important;
}
/* Keep these rules more specific than mobile CSS, including cached older files. */
[data-bs-theme="dark"] .mobile-task-actions {
    background: var(--site-surface-muted);
    border-color: var(--site-border);
}
[data-bs-theme="dark"] .mobile-task-action {
    color: var(--site-text);
    border-color: var(--site-border);
}
[data-bs-theme="dark"] .mobile-task-action:hover,
[data-bs-theme="dark"] .mobile-task-action:focus,
[data-bs-theme="dark"] .mobile-task-action:active { background: var(--site-surface-soft); color: var(--site-text); }
[data-bs-theme="dark"] .mobile-task-action i { color: var(--site-link); }
[data-bs-theme="dark"] .mobile-result-card,
[data-bs-theme="dark"] .mobile-transaction-card {
    background: var(--site-surface);
    border-color: var(--site-border);
}
/* Loading fragments share one palette; bg-light does not override the shimmer image. */
[data-bs-theme] .placeholder-text {
    background-color: var(--site-skeleton-base) !important;
    background-image: linear-gradient(to right, var(--site-skeleton-base) 0%, var(--site-skeleton-highlight) 20%, var(--site-skeleton-base) 40%, var(--site-skeleton-base) 100%) !important;
}
@media (prefers-reduced-motion: reduce) {
    .placeholder-text { animation: none !important; }
}

/* Native dark-mode input backgrounds must not form a separate block in the palette. */
[data-bs-theme] #icp-input { background: transparent; }
