/*
 * Form action width hierarchy.
 *
 * Single primary action fills the row. Wizard-style secondary + primary rows
 * use 25/75 so the next action remains dominant. Opt-in panel/card edit rows
 * use `.form-actions-split-50` for balanced 50/50 actions.
 */

@media (min-width: 640px) {
  .auth-form .form-actions,
  .auth-form-grid .form-actions,
  .auth-card-footer > .form-actions,
  .workspace-form-actions,
  .workspace-panel-footer:not(.btn-row-equal),
  .portal-modal-footer:not(.btn-row-equal),
  .invest-actions,
  .invest-actions-row,
  .invest-actions-wizard {
    width: 100%;
    justify-content: stretch;
    align-items: stretch;
  }

  .auth-form .form-actions > .btn-canonical:only-child,
  .auth-form-grid .form-actions > .btn-canonical:only-child,
  .auth-card-footer > .form-actions > .btn-canonical:only-child,
  .workspace-form-actions > .btn-canonical:only-child,
  .workspace-form-actions > form:only-child,
  .workspace-form-actions > form:only-child > .btn-canonical,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical:only-child,
  .workspace-panel-footer:not(.btn-row-equal) > form:only-child,
  .workspace-panel-footer:not(.btn-row-equal) > form:only-child > .btn-canonical,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical:only-child,
  .portal-modal-footer:not(.btn-row-equal) > form:only-child,
  .portal-modal-footer:not(.btn-row-equal) > form:only-child > .btn-canonical,
  .invest-actions > .btn-canonical:only-child,
  .invest-actions-row > .btn-canonical:only-child,
  .invest-actions-wizard > .btn-canonical:only-child {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .auth-form .form-actions:not(:has(> .btn-canonical-secondary, > .btn-canonical-ghost, > .btn-canonical-success, > .btn-canonical-warning, > .btn-canonical-danger, > form > .btn-canonical)) > .btn-canonical-primary,
  .auth-form-grid .form-actions:not(:has(> .btn-canonical-secondary, > .btn-canonical-ghost, > .btn-canonical-success, > .btn-canonical-warning, > .btn-canonical-danger, > form > .btn-canonical)) > .btn-canonical-primary,
  .auth-card-footer > .form-actions:not(:has(> .btn-canonical-secondary, > .btn-canonical-ghost, > .btn-canonical-success, > .btn-canonical-warning, > .btn-canonical-danger, > form > .btn-canonical)) > .btn-canonical-primary {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .form-actions-primary-only,
  .auth-card-footer > .form-actions-primary-only {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
    justify-content: stretch;
  }

  .form-actions-primary-only > .btn-canonical-primary,
  .auth-card-footer > .form-actions-primary-only > .btn-canonical-primary {
    display: inline-flex;
    flex: 1 1 100%;
    grid-column: 1 / -1;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .form-actions-primary-only > .field-hint,
  .auth-card-footer > .form-actions-primary-only > .field-hint {
    grid-column: 1 / -1;
    width: 100%;
  }

  .auth-form .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2),
  .auth-form .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2),
  .auth-form-grid .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2),
  .auth-form-grid .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2),
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2),
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2),
  .workspace-form-actions > .btn-canonical-secondary:first-child:nth-last-child(2),
  .workspace-form-actions > .btn-canonical-ghost:first-child:nth-last-child(2),
  .workspace-form-actions > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost),
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2),
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2),
  .workspace-panel-footer:not(.btn-row-equal) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost),
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2),
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2),
  .portal-modal-footer:not(.btn-row-equal) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost) {
    flex: 0 1 calc(25% - 0.375rem);
    min-width: 0;
    max-width: none;
  }

  .auth-form .form-actions:not(.form-actions-split-50) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost),
  .auth-form-grid .form-actions:not(.form-actions-split-50) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost),
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost) {
    flex: 0 1 calc(25% - 0.375rem);
    min-width: 0;
    max-width: none;
  }

  .auth-form .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .auth-form .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .auth-form .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .auth-form .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .auth-form-grid .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .auth-form-grid .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .auth-form-grid .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .auth-form-grid .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .workspace-form-actions > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .workspace-form-actions > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .workspace-form-actions > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .workspace-form-actions > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .workspace-form-actions > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost)
    ~ form:last-child:has(.btn-canonical-primary, .btn-canonical-success),
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-warning:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-danger:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-warning:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-danger:last-child,
  .workspace-panel-footer:not(.btn-row-equal) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost)
    ~ form:last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger),
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-warning:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-danger:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-warning:last-child,
  .portal-modal-footer:not(.btn-row-equal) > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-danger:last-child,
  .portal-modal-footer:not(.btn-row-equal) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost)
    ~ form:last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger) {
    flex: 1 1 calc(75% - 0.375rem);
    min-width: 0;
    max-width: none;
  }

  .auth-form .form-actions:not(.form-actions-split-50) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost)
    ~ form:last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger),
  .auth-form-grid .form-actions:not(.form-actions-split-50) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost)
    ~ form:last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger),
  .auth-card-footer > .form-actions:not(.form-actions-split-50) > form:first-child:nth-last-child(2):has(.btn-canonical-secondary, .btn-canonical-ghost)
    ~ form:last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger) {
    flex: 1 1 calc(75% - 0.375rem);
    min-width: 0;
    max-width: none;
  }

  .auth-form .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-secondary:nth-child(-n + 2),
  .auth-form .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-ghost:nth-child(-n + 2),
  .auth-form-grid .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-secondary:nth-child(-n + 2),
  .auth-form-grid .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-ghost:nth-child(-n + 2),
  .auth-card-footer > .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-secondary:nth-child(-n + 2),
  .auth-card-footer > .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-ghost:nth-child(-n + 2) {
    flex: 0 1 calc(25% - 0.5rem);
    min-width: 0;
    max-width: none;
  }

  .auth-form .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-primary:last-child,
  .auth-form .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-success:last-child,
  .auth-form-grid .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-primary:last-child,
  .auth-form-grid .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-success:last-child,
  .auth-card-footer > .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-primary:last-child,
  .auth-card-footer > .form-actions:has(> .btn-canonical:nth-child(3)):not(:has(> .btn-canonical:nth-child(4))) > .btn-canonical-success:last-child {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 0;
    max-width: none;
  }

  .workspace-form-actions:has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(.btn-canonical-secondary, .btn-canonical-ghost):nth-child(-n + 2),
  .workspace-form-actions:has(> :nth-child(3)):not(:has(> :nth-child(4))) > form:nth-child(-n + 2):has(.btn-canonical-secondary, .btn-canonical-ghost),
  .workspace-panel-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(.btn-canonical-secondary, .btn-canonical-ghost):nth-child(-n + 2),
  .workspace-panel-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > form:nth-child(-n + 2):has(.btn-canonical-secondary, .btn-canonical-ghost),
  .portal-modal-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(.btn-canonical-secondary, .btn-canonical-ghost):nth-child(-n + 2),
  .portal-modal-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > form:nth-child(-n + 2):has(.btn-canonical-secondary, .btn-canonical-ghost) {
    flex: 0 1 calc(25% - 0.5rem);
    min-width: 0;
    max-width: none;
  }

  .workspace-form-actions:has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger):last-child,
  .workspace-form-actions:has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(form, .form-actions-inline):last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger),
  .workspace-panel-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger):last-child,
  .workspace-panel-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(form, .form-actions-inline):last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger),
  .portal-modal-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger):last-child,
  .portal-modal-footer:not(.btn-row-equal):has(> :nth-child(3)):not(:has(> :nth-child(4))) > :is(form, .form-actions-inline):last-child:has(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger) {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 0;
    max-width: none;
  }

  .workspace-form-actions > form > .btn-canonical,
  .workspace-panel-footer:not(.btn-row-equal) > form > .btn-canonical,
  .portal-modal-footer:not(.btn-row-equal) > form > .btn-canonical {
    width: 100%;
    min-width: 0;
  }

  .invest-actions > .btn-canonical-primary:first-child:nth-last-child(2),
  .invest-actions > .btn-canonical-success:first-child:nth-last-child(2),
  .invest-actions > .btn-canonical-warning:first-child:nth-last-child(2),
  .invest-actions > .btn-canonical-danger:first-child:nth-last-child(2) {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .invest-actions > .invest-actions-disabled-reason,
  .invest-actions-row > .invest-actions-disabled-reason,
  .invest-actions-wizard > .invest-actions-disabled-reason {
    flex: 1 1 100%;
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
  }

  .invest-actions-wizard {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    grid-auto-columns: unset;
  }

  .invest-actions-wizard > .btn-canonical {
    width: 100%;
    min-width: 0;
    max-width: none;
  }

  .invest-actions-row {
    display: flex;
    flex-wrap: nowrap;
  }

  .invest-actions-row > .btn-canonical-secondary:first-child:nth-last-child(2),
  .invest-actions-row > .btn-canonical-ghost:first-child:nth-last-child(2),
  .invest-actions-row > .btn-canonical-primary:first-child:nth-last-child(2) ~ .btn-canonical-secondary:last-child,
  .invest-actions-row > .btn-canonical-primary:first-child:nth-last-child(2) ~ .btn-canonical-ghost:last-child,
  .invest-actions-row > .btn-canonical-success:first-child:nth-last-child(2) ~ .btn-canonical-secondary:last-child,
  .invest-actions-row > .btn-canonical-success:first-child:nth-last-child(2) ~ .btn-canonical-ghost:last-child {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  .invest-actions-row > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .invest-actions-row > .btn-canonical-secondary:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .invest-actions-row > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-primary:last-child,
  .invest-actions-row > .btn-canonical-ghost:first-child:nth-last-child(2) ~ .btn-canonical-success:last-child,
  .invest-actions-row > .btn-canonical-primary:first-child:nth-last-child(2),
  .invest-actions-row > .btn-canonical-success:first-child:nth-last-child(2) {
    flex: 2 1 0;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  .workspace-panel-footer.btn-row-equal:not(.form-actions-split-50):has(> .btn-canonical-secondary:first-child:nth-last-child(2)):has(> :last-child:is(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger)),
  .workspace-panel-footer.btn-row-equal:not(.form-actions-split-50):has(> .btn-canonical-ghost:first-child:nth-last-child(2)):has(> :last-child:is(.btn-canonical-primary, .btn-canonical-success, .btn-canonical-warning, .btn-canonical-danger)),
  .workspace-panel-footer.btn-row-equal:not(.form-actions-split-50):has(> form:first-child:nth-last-child(2)):has(> form:last-child) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    grid-auto-columns: unset;
  }

  .form-actions-split-50 > :is(.btn-canonical, form, .form-actions-inline),
  .form-actions-split-50 > a.btn-canonical,
  .requirements-editor-actions.form-actions-split-50 > :is(.btn-canonical, form, .form-actions-inline),
  .requirements-editor-actions.form-actions-split-50 > a.btn-canonical {
    flex: 1 1 calc(50% - 0.375rem);
    min-width: 0;
    max-width: none;
  }

  .form-actions-split-50 > form > .btn-canonical,
  .requirements-editor-actions.form-actions-split-50 > form > .btn-canonical {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 767px) {
  .invest-actions,
  .invest-actions-row,
  .invest-actions-wizard {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .invest-actions > .btn-canonical,
  .invest-actions-row > .btn-canonical,
  .invest-actions-wizard > .btn-canonical {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    min-width: 0;
  }
}
