/* Shared controls for Formula editors and their dialogs. */
@scope (.formula-creative-surface) {
  .neuro-app { line-height: 1.5; }
  :is(h2, h3, h4, h5) { color: var(--text); line-height: 1.25; }
  h2, .h2 { font-size: 1.6rem; }
  h3, .h3 { font-size: 1.3rem; }
  h4, .h4 { font-size: 1.15rem; }
  small { font-size: .875em; }

  .card {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border: 1px solid var(--editor-line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
  }
  .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px clamp(12px, 2vw, 24px);
    border-bottom: 1px solid var(--editor-line);
  }
  .card-title { margin: 0; font-size: 1.15rem; font-weight: 700; }
  .card-title.flex-column { display: flex; }
  .card-body { flex: 1 1 auto; min-width: 0; padding: clamp(12px, 2vw, 24px); }
  .card-flush > .card-header { border-bottom: 0; }
  .separator { border-top: 1px solid var(--editor-line); }

  .btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: auto;
    min-height: 40px;
    height: auto;
    padding: 8px 14px;
    border: 1px solid var(--editor-line);
    border-radius: var(--radius-sm);
    background: var(--bg-card-2);
    color: var(--text);
    font: 600 1em/1.35 var(--font-body);
    text-decoration: none;
  }
  a.btn { color: var(--text); }
  .btn:is(:hover, :focus-visible):not(:disabled, .disabled) {
    border-color: var(--accent-line);
    background: var(--editor-hover);
    color: var(--accent);
  }
  .btn:active { transform: none; }
  .btn:disabled, .btn.disabled { opacity: .5; cursor: default; }
  .btn.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-foreground); }
  .btn.btn-primary:hover:enabled { background: var(--accent-2); color: var(--accent-foreground); }
  .btn.btn-light-primary { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
  .btn:is(.btn-danger, .btn-light-danger) { background: var(--danger-soft); border-color: var(--danger-line); color: var(--editor-danger); }
  .btn:is(.btn-danger, .btn-light-danger):hover:enabled { background: var(--danger-line); color: var(--text); }
  .btn.btn-sm { min-height: 34px; padding: 6px 10px; }
  .btn.btn-icon { flex: none; width: 36px; height: 36px; min-height: 0; padding: 0; }
  .btn-close { display: grid; place-items: center; width: 28px; height: 28px; color: var(--text-muted); border-radius: var(--radius-sm); }
  .btn-close::before { content: '×'; font-size: 20px; line-height: 1; }
  .btn-close:hover { color: var(--text); background: var(--editor-hover); }

  .form-label { display: inline-block; margin-bottom: 6px; color: var(--text); font-weight: 600; }
  .form-text { margin-top: 4px; color: var(--text-muted); font-size: .82rem; }
  :is(.form-control, .form-select) {
    display: block;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 7px 10px;
    border: 1px solid var(--editor-line);
    border-radius: var(--radius-sm);
    background: var(--bg-card-2);
    color: var(--text);
    font: inherit;
  }
  :is(.form-control, .form-select):disabled { opacity: .55; cursor: default; }
  :is(.form-control-sm, .form-select-sm) { min-height: 34px; }
  .form-control-color { width: 42px; padding: 4px; }
  .form-control::file-selector-button {
    margin-inline-end: 8px;
    padding: 5px 8px;
    border: 1px solid var(--editor-line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
  }
  textarea.form-control { resize: vertical; }
  .form-select option { color: var(--text); background: var(--surface); }
  .input-group { display: flex; flex-wrap: wrap; align-items: stretch; gap: 4px; min-width: 0; }
  .input-group > :is(.form-control, .form-select) { flex: 1 1 100px; width: auto; }
  .input-group-text { display: inline-grid; place-items: center; padding-inline: 10px; color: var(--text-muted); }
  .form-check { display: flex; align-items: center; gap: 8px; }
  .form-check-input { flex: 0 0 auto; width: 17px; height: 17px; accent-color: var(--accent); }
  .form-switch .form-check-input {
    appearance: none;
    position: relative;
    width: 34px;
    height: 20px;
    border: 1px solid var(--editor-line);
    border-radius: 999px;
    background: var(--bg-card-2);
    cursor: pointer;
  }
  .form-switch .form-check-input::before {
    content: '';
    position: absolute;
    inset: 3px auto 3px 3px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--text-muted);
    transition: transform var(--editor-motion), background-color var(--editor-motion);
  }
  .form-switch .form-check-input:checked { border-color: var(--accent-line); background: var(--accent-soft); }
  .form-switch .form-check-input:checked::before { transform: translateX(14px); background: var(--accent); }
  .form-switch .form-check-input:disabled { opacity: .55; cursor: default; }

  .badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--bg-card-2);
    color: var(--text);
    font-size: .75rem;
    font-weight: 600;
  }
  .alert {
    display: block;
    position: relative;
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--editor-line);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text);
  }
  .alert-dismissible { padding-inline-end: 44px; }
  .alert-dismissible .btn-close { position: absolute; top: 8px; right: 8px; }
  :is(.alert-primary, .alert-info, .bg-light-primary, .bg-light-info, .badge-light-primary, .badge-light-info) { background-color: var(--accent-soft); color: var(--accent); }
  :is(.alert-warning, .bg-light-warning, .badge-light-warning) { background-color: var(--editor-warning-bg); color: var(--editor-warning); }
  :is(.alert-danger, .bg-light-danger, .badge-light-danger) { background-color: var(--danger-soft); color: var(--editor-danger); }
  :is(.alert-success, .bg-light-success, .badge-light-success) { background-color: var(--success-soft); color: var(--success); }
  :is(.alert-primary, .alert-info, .border-primary, .border-info) { border-color: var(--accent-line); }
  :is(.alert-warning, .border-warning) { border-color: var(--editor-warning-line); }
  :is(.alert-danger, .border-danger) { border-color: var(--danger-line); }

  .symbol { display: inline-flex; flex: 0 0 auto; }
  .symbol-label, .symbol img { display: grid; place-items: center; width: 42px; height: 42px; object-fit: cover; border-radius: var(--radius-sm); }
  .symbol-70px :is(.symbol-label, img) { width: 70px; height: 70px; }
  .symbol-circle :is(.symbol-label, img) { border-radius: 50%; }
  .list-group { display: grid; gap: 1px; }
  .list-group-item { display: block; padding: 10px 12px; border-bottom: 1px solid var(--editor-line); color: var(--text); text-align: start; }
  .list-group-item-action:is(:hover, .active) { background: var(--accent-soft); color: var(--accent); }
  .table { width: 100%; border-collapse: collapse; text-align: start; }
  .table :is(th, td) { padding: 8px; border-bottom: 1px solid var(--editor-line); text-align: start; }
  .table-responsive { overflow-x: auto; }
  .progress { display: flex; overflow: hidden; border-radius: 999px; background: var(--bg-card-2); }
  .progress-bar { background: var(--accent); }
  .spinner-border { display: inline-block; width: 1.5em; height: 1.5em; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: creative-spinner .75s linear infinite; }
  .spinner-border-sm { width: 1em; height: 1em; }
  @keyframes creative-spinner { to { transform: rotate(1turn); } }
  @media (prefers-reduced-motion: reduce) { .spinner-border { animation-duration: 1.5s; } }
  .neuro-toast-host { position: fixed; z-index: 2300; bottom: max(16px, env(safe-area-inset-bottom)); right: 16px; display: grid; gap: 8px; width: min(360px, calc(100vw - 32px)); }
  .neuro-toast { overflow: hidden; border: 1px solid var(--editor-line); border-radius: var(--radius-md); background: var(--surface); color: var(--text); transition: opacity var(--editor-motion); }
  .neuro-toast-hide { opacity: 0; }
  .toast-header { display: flex; align-items: center; gap: 4px; padding: 8px 12px; }
  .toast-body { padding: 10px 12px; overflow-wrap: anywhere; }
  .modal-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 12px; }
  .sheet .sheet__close-text { color: var(--sheet-accent); }

  /* Layout utilities used in existing cabinet and editor markup. */
  .d-flex { display: flex; }
  .d-grid { display: grid; }
  .d-block { display: block; }
  .d-none { display: none !important; }
  .flex-column { flex-direction: column; }
  .flex-wrap { flex-wrap: wrap; }
  .flex-grow-1 { flex-grow: 1; }
  .flex-shrink-0 { flex-shrink: 0; }
  .align-items-center { align-items: center; }
  .align-items-start { align-items: flex-start; }
  .align-items-end { align-items: flex-end; }
  .justify-content-between { justify-content: space-between; }
  .justify-content-end { justify-content: flex-end; }
  .justify-content-center { justify-content: center; }
  .text-start { text-align: start; }
  .text-end { text-align: end; }
  .text-center { text-align: center; }
  .fw-semibold { font-weight: 600; }
  .fw-bold { font-weight: 700; }
  .text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .text-break { overflow-wrap: anywhere; }
  .cursor-pointer { cursor: pointer; }
  .w-auto { width: auto; }
  .w-150px { width: min(150px, 100%); }
  .min-w-150px { min-width: min(150px, 100%); }
  .min-w-175px { min-width: min(175px, 100%); }
  .min-w-200px { min-width: min(200px, 100%); }
  .h-8px { height: 8px; }
  .h-100 { height: 100%; }
  .border { border: 1px solid var(--editor-line); }
  .border-0 { border: 0; }
  .border-dashed { border-style: dashed; }
  .bg-light { background: var(--bg-card-2); }
  .bg-primary { background: var(--accent); }
  .text-primary, .text-info { color: var(--accent); }
  .text-warning { color: var(--editor-warning); }
  .text-danger { color: var(--editor-danger); }
  .text-success { color: var(--success); }
  .text-muted, .text-gray-400, .text-gray-500, .text-gray-600 { color: var(--text-muted); }
  .text-gray-700, .text-gray-800, .text-gray-900 { color: var(--text); }
  .shadow-sm { box-shadow: 0 4px 16px #0003; }
  .row { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--editor-grid-gap, 16px); }
  .row > * { grid-column: span 12; min-width: 0; }
  .mb-0 { margin-bottom: 0px; }
  .mb-1 { margin-bottom: 4px; }
  .mb-2 { margin-bottom: 8px; }
  .mb-3 { margin-bottom: 12px; }
  .mb-4 { margin-bottom: 16px; }
  .mb-5 { margin-bottom: 20px; }
  .mb-6 { margin-bottom: 24px; }
  .mb-7 { margin-bottom: 28px; }
  .me-2 { margin-inline-end: 8px; }
  .me-3 { margin-inline-end: 12px; }
  .me-4 { margin-inline-end: 16px; }
  .me-auto { margin-inline-end: auto; }
  .ms-1 { margin-inline-start: 4px; }
  .ms-2 { margin-inline-start: 8px; }
  .ms-3 { margin-inline-start: 12px; }
  .mt-1 { margin-top: 4px; }
  .mt-2 { margin-top: 8px; }
  .mt-3 { margin-top: 12px; }
  .mt-4 { margin-top: 16px; }
  .mt-5 { margin-top: 20px; }
  .mt-6 { margin-top: 24px; }
  .mt-7 { margin-top: 28px; }
  .mt-8 { margin-top: 32px; }
  .mt-auto { margin-top: auto; }
  .my-7 { margin-block: 28px; }
  .my-8 { margin-block: 32px; }
  .p-3 { padding: 12px; }
  .p-4 { padding: 16px; }
  .p-5 { padding: 20px; }
  .p-6 { padding: 24px; }
  .p-7 { padding: 28px; }
  .p-8 { padding: 32px; }
  .ps-4 { padding-inline-start: 16px; }
  .pt-0 { padding-top: 0px; }
  .pt-4 { padding-top: 16px; }
  .pt-6 { padding-top: 24px; }
  .px-3 { padding-inline: 12px; }
  .px-5 { padding-inline: 20px; }
  .py-2 { padding-block: 8px; }
  .gap-1 { gap: 4px; }
  .gap-2 { gap: 8px; }
  .gap-3 { gap: 12px; }
  .gap-4 { gap: 16px; }
  .gap-5 { gap: 20px; }
  .g-2 { --editor-grid-gap: 8px; }
  .g-3 { --editor-grid-gap: 12px; }
  .g-4 { --editor-grid-gap: 16px; }
  .g-5 { --editor-grid-gap: 20px; }
  .g-6 { --editor-grid-gap: 24px; }
  .g-7 { --editor-grid-gap: 28px; }
  .w-25 { width: 25%; }
  .w-50 { width: 50%; }
  .w-75 { width: 75%; }
  .w-100 { width: 100%; }
  .fs-2 { font-size: 20px; }
  .fs-3 { font-size: 18px; }
  .fs-4 { font-size: 16px; }
  .fs-5 { font-size: 14px; }
  .fs-6 { font-size: 13px; }
  .fs-7 { font-size: 12px; }
  .fs-8 { font-size: 11px; }
  .fs-9 { font-size: 10px; }
  .fs-2x { font-size: 26px; }
  .fs-2hx { font-size: 30px; }
  .fs-3x { font-size: 34px; }
  .row > .col-4 { grid-column: span 4; }
  .row > .col-6 { grid-column: span 6; }
  @media (min-width: 576px) {
    .row > .col-sm-6 { grid-column: span 6; }
  }
  @media (min-width: 768px) {
    .row > .col-md-3 { grid-column: span 3; }
    .row > .col-md-4 { grid-column: span 4; }
    .row > .col-md-5 { grid-column: span 5; }
    .row > .col-md-6 { grid-column: span 6; }
    .row > .col-md-7 { grid-column: span 7; }
  }
  @media (min-width: 992px) {
    .row > .col-lg-2 { grid-column: span 2; }
    .row > .col-lg-4 { grid-column: span 4; }
    .row > .col-lg-5 { grid-column: span 5; }
    .row > .col-lg-7 { grid-column: span 7; }
  }
  @media (min-width: 1200px) {
    .row > .col-xl-3 { grid-column: span 3; }
    .row > .col-xl-4 { grid-column: span 4; }
    .row > .col-xl-5 { grid-column: span 5; }
    .row > .col-xl-6 { grid-column: span 6; }
    .row > .col-xl-7 { grid-column: span 7; }
    .row > .col-xl-8 { grid-column: span 8; }
  }

  /* Formula tokens for the existing workflow, character controls, CULT UI and BSM. */
  .neuro-app {
      --pd-accent: var(--bs-primary);
      --pd-accent-hover: var(--bs-primary-active);
      --pd-accent-ink: var(--bs-primary-inverse);
      --pd-accent-soft: var(--bs-primary-light);
      --pd-canvas: var(--bs-page-bg);
      --pd-surface: var(--bs-body-bg);
      --pd-raised: var(--bs-gray-100);
      --pd-inset: var(--bs-gray-100);
      --pd-text: var(--bs-gray-900);
      --pd-muted: var(--bs-gray-600);
      --pd-subtle: var(--bs-gray-500);
      --pd-line: var(--bs-gray-200);
      --pd-line-strong: var(--bs-gray-300);
      --pd-data-text: var(--bs-primary);
      --pd-data-image: var(--bs-success);
      --pd-data-video: var(--bs-danger);
      --pd-data-audio: var(--bs-info);
      --pd-data-json: var(--bs-info);
      --pd-data-memory: var(--bs-primary);
      --cult-primary: var(--bs-primary);
      --cult-primary-fg: var(--bs-primary-inverse);
      --cult-ring: var(--bs-primary);
      --cult-accent: var(--bs-primary-light);
      --cult-bg: var(--bs-body-bg);
      --cult-card: var(--bs-body-bg);
      --cult-popover: var(--bs-body-bg);
      --cult-fg: var(--bs-gray-900);
      --cult-muted: var(--bs-gray-600);
      --cult-subtle: var(--bs-gray-100);
      --cult-border: var(--bs-gray-200);
      --cult-input: var(--bs-gray-200);
      --cult-destructive: var(--bs-danger);
      --cult-font-sans: var(--bs-body-font-family);
  }
  .neuro-app .formula-studio-host .influencer-studio-page {
      --ins-bg: var(--pd-surface);
      --ins-panel: var(--pd-surface);
      --ins-raised: var(--pd-raised);
      --ins-text: var(--pd-text);
      --ins-muted: var(--pd-muted);
      --ins-line: var(--pd-line);
  }
  .neuro-app .formula-studio-host .wf-studio {
      --wf-bg: var(--pd-surface);
      --wf-card: var(--pd-raised);
      --wf-text: var(--pd-text);
      --wf-muted: var(--pd-muted);
      --wf-line: var(--pd-line);
  }
  .neuro-app .formula-studio-host .wf-projects {
      --wf-library-bg: var(--pd-surface);
      --wf-library-card: var(--pd-raised);
      --wf-library-text: var(--pd-text);
      --wf-library-muted: var(--pd-muted);
      --wf-library-border: var(--pd-line);
  }
  .neuro-app .sheet-layer,
  .neuro-app .sheet-layer .sheet {
      --sheet-bg: var(--pd-surface);
      --sheet-color: var(--pd-text);
      --sheet-muted: var(--pd-muted);
      --sheet-accent: var(--pd-accent);
      --sheet-close-icon: var(--pd-muted);
      --sheet-close-bg: var(--pd-raised);
      --sheet-close-bg-hov: var(--pd-line);
  }
  .neuro-app .influencer-studio-sheet,.neuro-app .workflow-sheet {
      color: var(--pd-text);
  }
  .neuro-app .sheet-layer:is(.influencer-studio-layer,.workflow-layer) .sheet:not(.wf-model-window) {
      background-color: var(--pd-surface) !important;
      background-image: none !important;
      color: var(--pd-text) !important;
      border-color: var(--pd-line) !important;
  }
  .neuro-app .influencer-studio-layer {
      --ins-text: var(--pd-text);
      --ins-muted: var(--pd-muted);
      --ins-accent: var(--pd-accent);
  }
  .neuro-app .sheet-layer :is(.sheet__title,.sheet__close-icon) {
      color: var(--pd-muted) !important;
  }
  .neuro-app .formula-studio-host :is(.ins-mode-tabs, .ins-photo-preview),
  .neuro-app .influencer-studio-layer :is(.ins-sheet-details, .ins-sheet-actions, .ins-sheet-parameters),
  .neuro-app .workflow-layer :is(.wf-model-families, .wf-model-options, .wf-model-tabs, .wf-model-logo, .wf-assistant-compose) {
      background: var(--pd-raised);
      border-color: var(--pd-line);
  }
  .neuro-app .formula-studio-host .ins-hero h1,
  .neuro-app .influencer-studio-layer :is(.ins-panel, .ins-character-sheet, .ins-sheet-heading h2, .ins-sheet-direction, .ins-sheet-actions a),
  .neuro-app .workflow-layer :is(.wf-panel, .wf-model-tabs button, .wf-model-families [data-family], .wf-model-options button) {
      color: var(--pd-text);
  }
  .neuro-app .influencer-studio-layer :is(.ins-panel label,.ins-sheet-parameters h3,.ins-sheet-parameters h4),
  .neuro-app .workflow-layer :is(.wf-panel p,.wf-model-families small,.wf-model-caret,.wf-model-search svg) {
      color: var(--pd-muted);
  }
  .neuro-app .sheet-layer :is(.ins-panel input,.ins-panel textarea,.ins-panel select,.wf-panel input:not([type=checkbox]),.wf-panel select,.wf-panel textarea) {
      background: var(--pd-inset);
      color: var(--pd-text);
      border-color: var(--pd-line-strong);
  }
  .neuro-app .formula-studio-host :is(.ins-mode-tabs, .ins-workspace-tabs) button[aria-selected="true"],
  .neuro-app .workflow-layer :is(.wf-model-tabs button[aria-pressed="true"], .wf-model-families [data-family]:hover, .wf-model-families [aria-expanded="true"], .wf-model-options button:hover) {
      background: var(--pd-accent-soft);
      color: var(--pd-accent);
      border-color: var(--pd-line);
  }
  .neuro-app .formula-studio-host :is(.ins-workspace,.ins-mode-tabs) { border-color: var(--pd-line); }
  .neuro-app .formula-studio-host .ins-upload-photo {
      background: var(--pd-raised) !important;
      border-color: var(--pd-line-strong) !important;
  }
  .neuro-app .formula-studio-host .ins-type-grid .ins-option { background: var(--pd-raised) !important; }
  .neuro-app .formula-studio-host :is(.ins-chip,.ins-soon-grid div) { background: var(--pd-raised); color: var(--pd-muted); }
  .neuro-app .formula-studio-host .ins-type-grid .ins-option-name { color: var(--pd-text); }
  .neuro-app .formula-studio-host .wf-project-draft { background: var(--pd-accent-soft); border-color: var(--pd-line); color: var(--pd-text) !important; }
  .neuro-app .formula-studio-host :is(.wf-project-hero-node,.wf-project-preview,.wf-project-delete,.wf-pill,.wf-selection,.wf-minimap-panel) {
      background: var(--pd-surface);
      border-color: var(--pd-line);
      color: var(--pd-text);
  }
  .neuro-app .formula-studio-host .wf-node:not(.wf-note) .wf-node-card { background: var(--pd-raised); }
  .neuro-app .formula-studio-host :is(.wf-node-footer,.wf-prompt,.wf-media .wf-prompt) { background: var(--pd-inset); }
  .neuro-app .formula-studio-host :is(.wf-result pre,.wf-prompt textarea,.wf-markdown) { color: var(--pd-text); }
  .neuro-app .formula-studio-host .wf-prompt textarea::placeholder { color: var(--pd-muted); }
  .formula-studio-host { min-width: 0; width: 100%; }
  .neuro-app :is(.cult-pro, .cult-pro[data-pro-theme]) {
    font-family: inherit;
    --pro-card: var(--pd-surface);
    --pro-foreground: var(--pd-text);
    --pro-muted: var(--pd-muted);
    --pro-border: var(--pd-line);
    --pro-primary: var(--pd-accent);
    --pro-soft: var(--pd-accent-soft);
  }
  .neuro-app .cult-pro-input-wrap { width: 100%; min-width: 0; }
  .neuro-app .cult-pro-blob-1 { background: linear-gradient(90deg, var(--accent), var(--accent-2), var(--bs-gray-400)); }
  .neuro-app .cult-pro-blob-2 { background: linear-gradient(90deg, var(--text-muted), var(--accent), var(--bs-gray-300)); }
  .neuro-app .cult-pro-blob-3 { background: linear-gradient(90deg, var(--text-muted), var(--accent-2), var(--accent)); }
  .neuro-app .cult-pro-field { opacity: .16; }
  .neuro-app .cult-pro-rim:hover > .cult-pro-glow .cult-pro-field { opacity: .35; }
}
