/* Theme tokens used by app.css; literal fallbacks preserve the light palette. */
:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg: #101722;
  --color-surface: #192332;
  --color-text: #e5edf7;
  --color-text-secondary: #acbbcf;
  --color-text-weak: #93a4bb;
  --color-border: #344257;
  --color-divider: #2a3648;
  --color-primary: #8ab4ff;
  --color-primary-dark: #a7c7ff;
  --color-primary-soft: #203553;
  --color-success: #65d99b;
  --color-success-soft: #173c2e;
  --color-warning: #f6c56c;
  --color-warning-soft: #43351d;
  --color-danger: #ff939a;
  --color-danger-soft: #452630;
  --color-purple: #c4a5ff;
  --shadow-soft: 0 1px 3px rgba(0, 0, 0, .18);
  --theme-surface: var(--color-surface);
  --theme-surface-muted: #141e2c;
  --theme-surface-rgb: 25, 35, 50;
  --theme-text: var(--color-text);
  --theme-text-secondary: var(--color-text-secondary);
  --theme-border: var(--color-border);
  --theme-blue-soft: var(--color-primary-soft);
  --theme-blue-text: var(--color-primary);
  --theme-blue-border: #3c5b87;
  --theme-green-soft: var(--color-success-soft);
  --theme-green-text: #72dfad;
  --theme-green-border: #30664c;
  --theme-red-soft: var(--color-danger-soft);
  --theme-red-text: var(--color-danger);
  --theme-red-border: #82414d;
  --theme-amber-soft: var(--color-warning-soft);
  --theme-amber-text: var(--color-warning);
  --theme-amber-border: #80623a;
  --theme-purple-soft: #34284d;
  --theme-purple-text: var(--color-purple);
  --theme-purple-border: #665086;
}

/* Bottom right of the sidebar, immediately above the account divider. */
.sidebar-theme-control {
  display: flex;
  justify-content: flex-end;
  flex: 0 0 auto;
  padding: 0 2px;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 78px;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}
.theme-toggle:hover {
  color: var(--color-primary);
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
}
.theme-toggle:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 3px; }
.theme-toggle svg { width: 16px; height: 16px; flex: 0 0 auto; }
.theme-toggle .theme-icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-sun { display: block; }
html.sidebar-collapsed .sidebar-theme-control { justify-content: center; padding: 0; }
html.sidebar-collapsed .sidebar-theme-control .theme-toggle { min-width: 38px; padding: 0; }
html.sidebar-collapsed .sidebar-theme-control [data-theme-label] { display: none; }
.mobile-theme-toggle { margin-left: auto; min-width: 48px; flex: 0 0 auto; }
.mobile-topbar > .user-menu { margin-left: 0; }

/* Bright status fills need dark foregrounds for readable labels and checkmarks. */
[data-theme="dark"] :is(.button-primary, .button-danger, .progress-scroll-toggle),
[data-theme="dark"] .order-process-node:is(.done, .current, .returned) .order-node-mark,
[data-theme="dark"] .suborder-mini-track li:is(.done, .current) > span,
[data-theme="dark"] .outcome-choice:has(input:checked) .outcome-choice-icon,
[data-theme="dark"] .suborder-image-action.is-primary {
  color: #101722;
}
[data-theme="dark"] dialog { color: var(--color-text); background-color: var(--color-surface); }
[data-theme="dark"] .lightbox-stage,
[data-theme="dark"] .craft-card-mark,
[data-theme="dark"] .inline-callout,
[data-theme="dark"] .current-stage-panel,
[data-theme="dark"] .task-paused-banner,
[data-theme="dark"] .order-progress-card.task-is-paused,
[data-theme="dark"] .pool-task-card.task-is-paused {
  background: var(--theme-surface-muted);
}
[data-theme="dark"] :is(.task-paused-banner, .status-tag-paused, .order-status-badge.is-paused) {
  color: var(--color-text-secondary) !important;
}
[data-theme="dark"] .task-paused-banner :is(strong, span) { color: inherit; }
[data-theme="dark"] .login-page { background: var(--color-bg); }
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--color-text-weak); opacity: 1; }
[data-theme="dark"] .order-process-node::after,
[data-theme="dark"] .suborder-mini-track li::after { background: var(--color-border); }
[data-theme="dark"] .order-process-node.done::after,
[data-theme="dark"] .suborder-mini-track li.done::after { background: #30664c; }
[data-theme="dark"] .order-process-node.returned::after { background: #80623a; }
[data-theme="dark"].sfs-soft-refresh-restoring body::before,
[data-theme="dark"].sfs-soft-refresh-leaving body::before { background: rgba(16, 23, 34, .82); }
[data-theme="dark"] :is(.order-return-summary, .suborder-card.is-returned) {
  background: var(--color-warning-soft);
  border-color: var(--theme-amber-border);
}
@media (prefers-reduced-motion: reduce) {
  .theme-toggle { transition: none; }
}
