/* Attached AI panel only; variables never inherit into its sibling Stage. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel {
  --ps-ia-voice-surface: var(--ps-bg-soft);
  --ps-ia-voice-soft: var(--ps-surface-soft);
  --ps-ia-voice-text: var(--ps-text);
  --ps-ia-voice-ink: var(--ps-ink);
  --ps-ia-voice-muted: var(--ps-muted);
  --ps-ia-voice-line: var(--ps-line);
  --ps-ia-voice-line-hover: var(--ps-gold);
  --ps-ia-voice-accent: var(--ps-gold-light);
  --ps-ia-voice-accent-bg: var(--ps-surface-solid);
  --ps-ia-voice-shadow: none;
  --ps-ia-voice-error: #fca5a5;
  --ps-ia-voice-warning: #fbbf24;
  background: var(--ps-surface-solid);
  border-color: var(--ps-line);
  color: var(--ps-text);
  font-family: var(--ps-font-ui);
  box-shadow: 0 8px 24px #0003;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel:hover {
  box-shadow: 0 16px 40px #0004;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel > .admin-subcard-heading > h3 {
  color: var(--ps-ink);
  line-height: 21px;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel > .admin-subcard-heading > .admin-subcard-icon {
  background: var(--ps-bg-soft);
  color: var(--ps-gold);
}

/* Text wrapping and native controls preserve their historical metrics. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel > :not(.admin-subcard-heading) {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  scrollbar-color: var(--ps-line-strong) var(--ps-surface-soft);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel .muted {
  color: var(--ps-muted);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel :is(select, input[type="range"]) {
  color-scheme: dark;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel input[type="range"] {
  background-color: var(--ps-surface-soft);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel select option {
  background: var(--ps-bg-soft);
  color: var(--ps-text);
}

/* index.html textarea:focus is more specific than the injected editor class.
   Scope this to the real temporary editor; no priority or geometry change. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel [data-iadubbing-performance-editor] {
  background: var(--ps-bg);
  color: var(--ps-text);
  border-color: var(--ps-line);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel .btn-primary {
  background: var(--ps-button-bg);
  border-color: var(--ps-button-border);
  color: var(--ps-button-text);
  box-shadow: var(--ps-button-shadow);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel .btn-primary:hover:not(:disabled) {
  background: var(--ps-button-hover);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel .btn-secondary {
  background: var(--ps-bg-soft);
  color: var(--ps-text);
  border-color: var(--ps-line);
}

/* The state-derived inline History expressions remain byte-for-byte intact.
   These three priorities override their paint only, using the existing active
   disabled state and a presentation-only marker. No version state is changed. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel [data-ps-ia-voice-history] {
  background: var(--ps-ia-voice-history-bg, var(--ps-surface-soft)) !important;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel [data-ps-ia-voice-history="active"] {
  --ps-ia-voice-history-bg: var(--ps-surface-solid);
  box-shadow: inset 0 0 0 1px var(--ps-line-strong);
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel [data-iadubbing-use-generation] {
  background: var(--ps-bg-soft) !important;
  color: var(--ps-text) !important;
}

/* Existing inline warning colours are semantic state expressions. Keep them
   in JS; the scoped foreground gives their amber meaning contrast on dark UI. */
:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel :is([data-iadubbing-performance-status]:not(:empty), [data-iadubbing-history-warning="true"]) {
  color: var(--ps-ia-voice-warning) !important;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel button:hover:not(:disabled) {
  --ps-ia-voice-line: var(--ps-gold);
  box-shadow: none;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel :is(button, input, select, textarea, [role="textbox"]):focus-visible {
  outline-color: var(--ps-focus);
  box-shadow: none;
}

:where(html[data-ps-theme="studio"][data-ps-window="hub"][data-ps-screen="app"] #section-project-detail:not(.hidden) #projectDynamicZone > [data-ps-ia-dubbing="workspace"],
  html[data-ps-theme="studio"][data-ps-window="workspace"][data-ps-screen="window"] .iadubbing-detached-root[data-ps-ia-dubbing="detached-ai"]) #tr-ai-panel :is(textarea, input[type="text"])::selection {
  background: var(--ps-gold);
  color: var(--ps-bg);
}
