/* Shared theme palette; the original light design remains the baseline. */
:root {
  color-scheme: light;
  --network-label-bg: #fcfdf9;
  --network-dot: #dce5d5;
  --network-mask: #f4f6efb8;
  --network-he: #548776;
  --network-ke: #9380af;
  --network-act: #aa8847;
  --network-related: #8e9e88;
  --network-flow: #6e8b58;
}
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 34px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--subtle); background: var(--paper); font-size: 12px; white-space: nowrap; flex-shrink: 0; }
.theme-toggle .icon { width: 16px; height: 16px; }
.theme-sun { display: none; }
[data-theme="dark"] .theme-moon { display: none; }
[data-theme="dark"] .theme-sun { display: block; }

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e2eae4; --subtle: #b1c1b6; --muted: #97aa9e;
  --bg: #141b18; --paper: #1d2722; --line: #35473b;
  --green: #9bccad; --mint: #293e31; --gold: #ddba79; --purple: #bda8d7; --red: #e2a292;
  --surface-soft: #202d25; --surface-hover: #2a3c30; --selected: #2c4233;
  --he-bg: #253b31; --ke-bg: #302b3b; --act-bg: #3d3525;
  --network-label-bg: #1d2722; --network-dot: #394b3d; --network-mask: #141b18b8;
  --network-he: #8fc5ae; --network-ke: #bda8d7; --network-act: #ddba79;
  --network-related: #a4b69d; --network-flow: #afd08b;
}
/* Surfaces, navigation and selection. */
[data-theme="dark"] :is(.sidebar,.topbar) { background: #18211c; }
[data-theme="dark"] :is(.org-switcher,.overview,.activity-card,.detail,.outline,.graph-node,.network-panel,.history-panel,dialog,.rf-entity,.rf-search-results,.rf-edge-info) { background: var(--paper); border-color: var(--line); }
[data-theme="dark"] :is(.activity-column,.detail-tabs,.context-box,.action-bar,.entity-description,.modal-note,.launch-card,.material-attributes,.rf-node-footer,.rf-layout-note,.rf-filters) { background: var(--surface-soft); border-color: var(--line); }
[data-theme="dark"] :is(.rf-stage,.relation-canvas) { background-color: var(--bg); }
[data-theme="dark"] button:hover:not(:disabled) { background: var(--surface-hover); }
[data-theme="dark"] :is(.nav-item.active,.entity-tabs button.active,.subscription-item.active,.activity-card.selected,.view-toggle button.active,.graph-node.center,.rf-entity.root-entity,.rf-filters button.active,.manage-row button.subscribed) { background: var(--selected); color: var(--green); border-color: #628c6e; }
[data-theme="dark"] .activity-card.selected { box-shadow: inset 3px 0 var(--green); }
[data-theme="dark"] :is(.primary,.brand-mark) { background: #a4cfb0; color: #162c1e; }
[data-theme="dark"] .primary:hover:not(:disabled) { background: #b9ddc3; }
[data-theme="dark"] .brand-mark span { color: #456a3d; }
[data-theme="dark"] :is(.stat-icon,.org-symbol,.avatar,.mini-avatar,.view-toggle,.category-count) { background: var(--surface-hover); color: var(--subtle); border-color: var(--line); }
[data-theme="dark"] .categories button.active .category-count { background: var(--selected); color: var(--green); }
[data-theme="dark"] :is(.stat:first-child .stat-icon,.kind.ACT,.nav-count.attention,.badge-soft) { background: var(--act-bg); color: var(--gold); }
[data-theme="dark"] :is(.stat:nth-child(3) .stat-icon,.kind.HE,.launch-stock) { background: var(--he-bg); color: var(--network-he); }
[data-theme="dark"] :is(.kind.KE,.launch-knowledge,.rf-node-state .rf-version) { background: var(--ke-bg); color: var(--purple); }
[data-theme="dark"] .context-box.knowledge { background: #282630; border-color: #474052; }
[data-theme="dark"] :is(.version-notice,.action-bar.terminal) { background: var(--act-bg); border-color: #5c5035; color: var(--gold); }
[data-theme="dark"] :is(.version-notice button,.end-button) { color: var(--gold) !important; }
[data-theme="dark"] :is(.version-notice.pending,.allocation-total,.approval-rule,.result,.rf-save,.rf-tools .rf-arrange) { background: var(--selected); color: var(--green); border-color: #48674e; }
[data-theme="dark"] .result.failure { background: #432f2b; color: var(--red); }
[data-theme="dark"] .result.cancel { background: #343b35; color: var(--subtle); }

/* Secondary text stays readable without flattening the visual hierarchy. */
[data-theme="dark"] :is(.nav-label,.nav-item,.entity-tabs button,.subscription-item,.discover,.preview-label,.profile>span:nth-child(2)>span,.breadcrumb,.breadcrumb strong,.search,.search input::placeholder,kbd,.notification-button,.eyebrow,.page-heading p,.stat-label,.stat-note,.categories button,.view-toggle button,.list-toolbar,.list-toolbar select,.category-tag,.phase-tag,.card-sub,.card-bottom,.list-foot,.detail-meta,.detail-caption,.section-label small,.context-title,.action-bar p,.graph-foot,.detail-bottom,.page-footer,.page-footer button,.empty,.timeline-item time,.round small,.property dt,.related-row small,.history-row time,.history-type,.manage-row p,.muted,.version-line span,.source-line,.round-version,.mobile-preview,.launch-intro span,.launch-card>header>span,.launch-note,.allocation-row label,.approval-rule span,.approval-summary,.launch-submit>span) { color: var(--muted); }
[data-theme="dark"] :is(.purpose,.context-entity,.timeline-item p,.round p,.entity-description,.property dd,.history-row p,.modal-intro,.modal-body label.field,.modal-note,.about-point,.launch-intro,.launch-check,.material-attributes,.procurement-summary) { color: var(--subtle); }
[data-theme="dark"] :is(.follow-button,.text-button,.categories button.active,.detail-tabs button.active,.phase-step.current,.phase-tag.exec,.detail-bottom button,.history-row button,.about-point strong,.mobile-preview button,.launch-card h3,.launch-stock strong,.approval-summary dd,.procurement-summary strong) { color: var(--green); }
[data-theme="dark"] :is(.context-box.knowledge .context-title,.context-entity small,.launch-knowledge strong) { color: var(--purple); }
[data-theme="dark"] :is(.error,#launch-errors,.rf-node-state .negative) { color: var(--red); }
[data-theme="dark"] :is(.detail-tabs button,.phase-step) { color: var(--muted); }
[data-theme="dark"] :is(.categories button.active:after,.detail-tabs button.active:after) { background: var(--green); }

/* Borders, form controls and feedback. */
[data-theme="dark"] :is(.edition,.discover,kbd,.notification-button i,.stat,.workspace-toolbar,.view-toggle,.follow-button,.phase-track,.phase-circle,.context-box,.action-bar,.relation-canvas,.timeline-item,.round,.entity-description,.property,.related-row,.version-line,.manage-row button,.procurement-summary) { border-color: var(--line); }
[data-theme="dark"] .phase-step:not(:last-child):after { background: var(--line); }
[data-theme="dark"] .phase-step.current .phase-circle { background: var(--green); color: var(--bg); border-color: var(--green); box-shadow: 0 0 0 3px var(--selected); }
[data-theme="dark"] .phase-step.past .phase-circle { background: var(--selected); color: var(--green); border-color: var(--line); }
[data-theme="dark"] .timeline-item:before { border-color: var(--paper); box-shadow: 0 0 0 1px var(--line); }
[data-theme="dark"] .timeline-item:last-child { border-color: transparent; }
[data-theme="dark"] :is(.field input,.field select,.field textarea,.allocation-row select,.allocation-row input,.rf-search-wrap input) { background: var(--bg); color: var(--ink); border-color: var(--line); }
[data-theme="dark"] input::placeholder,[data-theme="dark"] textarea::placeholder { color: var(--muted); opacity: 1; }
[data-theme="dark"] select option { background: var(--paper); color: var(--ink); }
[data-theme="dark"] .launch-submit { background: #1d2722f5; border-color: var(--line); }
[data-theme="dark"] dialog::backdrop { background: #080e0baa; }
[data-theme="dark"] .toast { background: #c1dcc7; color: #1c3323; border-color: #96bb9d; box-shadow: 0 8px 30px #0005; }
[data-theme="dark"] .relation-canvas { background-image: radial-gradient(var(--network-dot) .7px,transparent .7px); }
[data-theme="dark"] .graph-lines path { stroke: #62765d; }
[data-theme="dark"] .graph-lines text { fill: var(--muted); }

/* React Flow chrome, nodes, SVG labels and minimap share the page theme. */
[data-theme="dark"] .rf-explorer { color: var(--ink); --xy-controls-button-background-color: var(--paper); --xy-controls-button-background-color-hover: var(--surface-hover); --xy-controls-button-color: var(--subtle); --xy-controls-button-color-hover: var(--ink); --xy-minimap-background-color: var(--paper); --xy-background-color: var(--bg); --xy-edge-label-color: var(--subtle); }
[data-theme="dark"] :is(.rf-eyebrow,.rf-topline h3>span,.rf-search-results p,.rf-tools button,.rf-filters>span,.rf-filters button,.rf-node-top,.rf-node-grip,.rf-node-state,.rf-node-footer,.rf-stage-hint,.rf-footer,.rf-explain,.rf-edge-info p,.rf-edge-info small,.rf-layout-note) { color: var(--muted); }
[data-theme="dark"] :is(.rf-node-footer button,.rf-edge-info,.rf-edge-info>button) { color: var(--green); }
[data-theme="dark"] .rf-node-title { color: var(--ink); }
[data-theme="dark"] :is(.rf-node-footer,.rf-footer,.rf-stage .react-flow__controls,.rf-stage .react-flow__controls-button,.rf-stage .react-flow__minimap) { border-color: var(--line); }
[data-theme="dark"] .rf-entity { border-top-color: var(--network-act); }
[data-theme="dark"] .rf-entity.HE { border-top-color: var(--network-he); }
[data-theme="dark"] .rf-entity.KE { border-top-color: var(--network-ke); }
[data-theme="dark"] .rf-entity.picked { border-color: var(--green); box-shadow: 0 0 0 3px #9bccad30,0 5px 18px #0003; }
[data-theme="dark"] .rf-stage .react-flow__attribution { background: var(--paper); color: var(--subtle); }
[data-theme="dark"] .rf-stage .react-flow__attribution a { color: inherit; }
[data-theme="dark"] .rf-filters .active i.object { background: var(--network-he); }
[data-theme="dark"] .rf-filters .active i.knowledge { background: var(--network-ke); }
[data-theme="dark"] .rf-filters .active i.parent { background: var(--network-act); }
@media(max-width:760px) {
  .theme-toggle { width: 34px; padding: 7px; }
  .theme-toggle [data-theme-label] { display: none; }
  .topbar-tools { min-width: 0; }
  .search { min-width: 0; }
  .search input { width: clamp(70px,25vw,160px); min-width: 0; }
}
