/* Shared controls and early dark paint. Business palettes remain source-owned. */
:root[data-theme="dark"]{color-scheme:dark;--bg:#181a1b;--surface:#202324;--surface-2:#25292b;--ink:#e8e6e3;--text:#e8e6e3;--muted:#aab4bf;--line:#3d4348;--blue-2:#192637;--green-2:#192c24;--amber-2:#30291c;--red-2:#322124;--accent-soft:#1d2142;--shadow:0 8px 24px #0004}
:root[data-theme="dark"] body{background:#181a1b;color:#e8e6e3}
:root[data-theme="dark"] :is(.sidebar,.admin-sidebar,.page-loader,.contextbar){background:#202324;color:#e8e6e3}
:root[data-theme="dark"] :is(input,select,textarea){color-scheme:dark}
:root[data-theme="dark"] :is(a,.text-link){color:#90baff}
:root[data-theme="dark"] :focus-visible{outline-color:#a69cff}
.theme-switcher{position:fixed;z-index:90;right:18px;top:16px;display:inline-flex;width:40px;height:40px;padding:0;background:none;border:0;box-shadow:none;flex:0 0 40px}
.theme-switcher.is-inline{position:static;right:auto;top:auto}
.theme-cycle{display:grid;place-items:center;box-sizing:border-box;width:40px;height:40px;min-width:40px;min-height:40px;padding:0;border:1px solid #dce2ec;border-radius:10px;background:#fff;cursor:pointer;color:#475569;box-shadow:none;line-height:1}
.theme-cycle svg{width:20px;height:20px;pointer-events:none;flex:none}.theme-cycle[data-mode="light"]{color:#a85a08}.theme-cycle[data-mode="system"]{color:#2563eb}
.theme-cycle:hover{border-color:#a5a0e8;background:#f4f3ff}.theme-cycle:focus-visible{outline:3px solid #8c80ef;outline-offset:3px}
:root[data-theme="dark"] .theme-cycle{background:#25292b;border-color:#43494e;color:#c4b5fd}
:root[data-theme="dark"] .theme-cycle[data-mode="system"]{color:#90baff}
:root[data-theme="dark"] .theme-cycle:hover{background:#30313d;border-color:#9488d5}
.map-header .theme-switcher{margin-left:auto}.map-header .theme-switcher+.close{margin-left:0}
.admin-workspace>header>.theme-switcher{align-self:center}
@media(max-width:760px){.theme-switcher:not(.is-inline){right:12px;top:12px}}
@media print{.theme-switcher{display:none!important}}

:root[data-theme="dark"] dialog{background:#202324;color:#e8e6e3;border-color:#3d4348}
:root[data-theme="dark"] dialog::backdrop{background:#0009}
:root[data-theme="dark"] svg text{fill:#cbd5df}

/* Stable dark surfaces before dynamic stylesheet adaptation or late UI mounts. */
html[data-theme="dark"] :is(.workspace,.content,.admin-content){background-color:#181a1b}
html[data-theme="dark"] :is(.bento-card,.ledger-table-card,.ledger-stats,.ops-card,.account-menu,.account-plans,.admin-scroll){background-color:#202324;color:#e8e6e3}
html[data-theme="dark"] :is(.sidebar,.admin-sidebar,.contextbar,.ledger-toolbar){background-color:#202324}
html[data-theme="dark"] :is(.score-tile,.ledger-table thead th){background-color:#25292b}

/* Map framing is dark; choropleth fills and score thresholds remain unchanged. */
html[data-theme="dark"] .map-stage{background:radial-gradient(ellipse at center,#252b32,#171c22)}
html[data-theme="dark"] .map-stage .map-region{stroke:#27323b}
html[data-theme="dark"] .map-stage .map-region:hover{stroke:#c4b5fd}
html[data-theme="dark"] .map-stage .map-region:is(.selected,.mine){stroke:#d6ccff}
html[data-theme="dark"] .map-stage .map-label{fill:#f0f3f6;stroke:#14202ee6}
html[data-theme="dark"] :is(.map-detail,.map-header,.map-stats,.map-footer,.map-view-controls){background-color:#20262c;color:#e8e6e3;border-color:#39434c}
html[data-theme="dark"] .map-stage .legend{background:#20262cf2;border-color:#434d58;color:#e8e6e3}

/* Formula surfaces use color-mix gradients: give them explicit dark surfaces. */
html[data-theme="dark"] .formula-page :is(.formula-equation,.formula-score-equation){background:#202a38!important;background-image:none!important;color:#e4eaf3;border-color:#3b4a60}
html[data-theme="dark"] .formula-page .formula-accordion summary{background:#252b32!important;background-image:none!important;color:#e4eaf3}
html[data-theme="dark"] .formula-page .formula-accordion-calculation summary{background:#1e302d!important}
html[data-theme="dark"] .formula-page .formula-accordion-sources summary{background:#2c2639!important}
html[data-theme="dark"] .formula-page .formula-accordion-notes summary{background:#342c23!important}
html[data-theme="dark"] .formula-page :is(.formula-code,.formula-accordion-icon){background:#2b3440!important}
html[data-theme="dark"] .formula-page .formula-extra{background:#242a30!important}
html[data-theme="dark"] .formula-page .formula-accordion-body{background:#202324;border-color:#3d4348}
/* Daily combo chart: keep gridlines subtle on dark surfaces (generated foreground mapping would brighten them). */
:root[data-theme="dark"] .daily-combo-svg .daily-combo-grid{stroke:#323a42}:root[data-theme="dark"] .daily-combo-svg .daily-combo-zero{stroke:#56616c}

/* "Phân tích theo TTHC": sticky headers must stay opaque while rows scroll beneath them (tinted over a solid base),
   and the two switches need visible tracks, knobs and labels on dark surfaces. */
html[data-theme="dark"] .ledger-panel thead th.ledger-focus{background:linear-gradient(rgba(139,128,249,.34),rgba(139,128,249,.34)),#25292b!important}
html[data-theme="dark"] .ledger-panel thead th.ledger-points-head{background:linear-gradient(rgba(139,128,249,.22),rgba(139,128,249,.22)),#25292b!important}
html[data-theme="dark"] .ledger-switch{color:#c3ccd6}
html[data-theme="dark"] .ledger-switch-track{background:#56616c!important;box-shadow:inset 0 0 0 1px #8a96a3}
html[data-theme="dark"] .ledger-switch-track i{background:#f3f4f6!important;box-shadow:0 1px 3px #0009}
html[data-theme="dark"] .ledger-switch input:checked+.ledger-switch-track{background:#8b7cf6!important;box-shadow:inset 0 0 0 1px #c4b8ff}
html[data-theme="dark"] .ledger-switch input:focus-visible+.ledger-switch-track{outline-color:#c4b8ff}
html[data-theme="dark"] .ledger-switch-text b{color:#aab4bf}
html[data-theme="dark"] .ledger-switch input:checked~.ledger-switch-text b{color:#d6cfff}
html[data-theme="dark"] .ledger-switch.is-disabled{opacity:.6}
