/* Hand-written dark answers for what scripts/generate-dark-css.mjs cannot decide from a colour alone.
   Loaded last on every themed page, and every rule starts from the dark theme attribute. */

/* Foundation colours, here too because some pages turn dark without main.css. On a dark screen the
   brand colour uses its lighter step, so it reads as text and fills a button under dark ink. */
html[data-theme="dark"] {
  --bp-ui-ink: var(--if-text);
  --bp-ui-muted: var(--if-text-muted);
  --bp-ui-line: var(--if-border);
  --bp-ui-surface: var(--if-surface-card);
  --bp-ui-canvas: var(--if-bg);
  --bp-ui-primary: var(--if-accent);
  --bp-ui-primary-strong: var(--if-accent);
  --bp-ui-primary-soft: var(--if-accent-subtle);
  --bp-ui-focus: var(--if-accent);
  --bp-ui-ai-ink: var(--if-ai);
  --bp-ui-success: var(--if-status-success-fg);
  --bp-ui-warning: var(--if-status-warning-fg);
  --bp-ui-danger: var(--if-status-error-fg);
}

html[data-theme="dark"][data-bp-release-lane] {
  --bp-development-accent: var(--if-accent-light);
  --bp-development-accent-hover: var(--if-accent-light);
  --bp-ui-primary: var(--bp-development-accent);
  --bp-ui-primary-strong: var(--bp-development-accent);
  --bp-ui-focus: var(--bp-development-accent);
}

/* The development environment repaints the accent darker for the light theme; a dark screen needs its lighter step. */
html[data-theme="dark"][data-bp-environment="development"] {
  --if-accent: var(--if-accent-light);
  --if-accent-hover: var(--if-accent-light);
  --if-control-primary-hover-bg: var(--if-accent-light);
  --bp-ui-primary: var(--if-accent-light);
  --bp-ui-primary-strong: var(--if-accent-light);
  --bp-ui-focus: var(--if-accent-light);
}

/* Every control filled with the brand colour carries dark ink on a dark screen. */
html[data-theme="dark"] .ui-foundation .ui-action--primary,
html[data-theme="dark"] .ui-action--primary,
html[data-theme="dark"] .admin-nav-link.is-active,
html[data-theme="dark"] .button-primary,
html[data-theme="dark"] .language-switch a[aria-current="page"],
html[data-theme="dark"] .language-switch a[aria-current=page],
html[data-theme="dark"] .action {
  color: var(--zinc-900);
}
html[data-theme="dark"] .ui-foundation .ui-action--primary:hover,
html[data-theme="dark"] .button-primary:hover {
  color: var(--zinc-900);
}

/* Dark ink on a faded brand fill cannot be read, so a disabled primary control drops the fill instead. */
html[data-theme="dark"] .ui-foundation .ui-action--primary:disabled,
html[data-theme="dark"] .ui-action--primary:disabled {
  background: var(--if-accent-subtle);
  border-color: var(--if-border);
  color: var(--if-text-sub);
  opacity: 1;
}

/* The ribbon's own button rules outrank the one above: a disabled Save stayed white and could not be told from an enabled one. */
html[data-theme="dark"] #appRoot.viewer-shell [data-viewer-ribbon="true"] .viewer-bottom-btn:disabled {
  background: var(--if-state-disabled-bg);
  border-color: var(--if-state-disabled-border);
  color: var(--if-state-disabled-text);
  opacity: var(--if-state-disabled-opacity);
}

/* Focus dims the other rows to 0.3, which on a dark table takes their small coloured text under the reading line. The selected row keeps its fill and its white text. */
html[data-theme="dark"] :is(.desc-table, .if-ops-table).table-focus-active tbody tr:not(.highlight-el, .highlight-row, .phase-active-row, [data-viewer-selected="1"]) {
  opacity: .88;
}

/* These fade for emphasis in the light theme; on a dark surface the fade takes them under the reading line. */
html[data-theme="dark"] .lp-filter-row .lp-tag-radio[aria-checked="true"] .if-filter-chip-count,
html[data-theme="dark"] .if-ai-connection-status-note,
html[data-theme="dark"] .ui-action--primary[aria-busy="true"] {
  opacity: 1;
}
html[data-theme="dark"] #appRoot.viewer-shell .viewer-tab-list .if-tab-item {
  opacity: 1 !important;
}

/* Inline colours client code writes after load: the server cannot see these to answer them. */
html[data-theme="dark"] [style*="color:#475569"]:not(svg *) { color: var(--if-text-sub) !important; }
html[data-theme="dark"] [style*="background-color: rgb(227, 242, 253)"]:not(svg *) { background-color: var(--if-accent-subtle) !important; }

/* A classic drawing has no dark paint of its own: the whole pane is turned over, keeping each hue, including
   the lane titles and the phase strip beside the SVG, which are light on this pane too. */
html[data-theme="dark"] #flowPanel[data-theme="light"] {
  filter: invert(0.92) hue-rotate(180deg);
}

/* The closing band of the landing page is filled with the brand colour. */
html[data-theme="dark"] .final,
html[data-theme="dark"] .final p,
html[data-theme="dark"] .final h2 {
  color: var(--zinc-900);
}

/* A logo marked for a light surface sits on a dark one once the page turns dark. */
html[data-theme="dark"] .nf-brand[data-brand-theme="light"] > .nf-brand-light { display: none; }
html[data-theme="dark"] .nf-brand[data-brand-theme="light"] > .nf-brand-dark { display: block; }

/* The phase column prints in its phase colour, saved for white paper: lightened here, the hue stays. */
html[data-theme="dark"] .phase-cell .phase-name,
html[data-theme="dark"] .if-phase-cell .if-phase-name {
  color: color-mix(in oklab, var(--phase-color, var(--if-text)) 45%, white) !important;
}
