@layer atoms {
  /* stylelint-disable no-descending-specificity -- complex component with many state combinations */
  .mobius-text-field {
    box-sizing: border-box;
    width: 100%;

    &:where(.--is-optional) > :where(.mobius-label)::after {
      content: " (optional)";
    }

    & .mobius-label {
      display: block;
    }
  }

  .mobius-text-field__inner-container {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
  }

  .mobius-text-field__input-wrapper {
    display: flex;
    flex: 1 1 0;
    align-items: center;
    border-radius: var(--input-border-radius);
    color: var(--color-text);
    overflow: hidden; /* Prevents border-radius from clipping children */
    background-color: var(--color-background-input);

    &:not(.--is-hidden) {
      border: var(--border-default);
    }

    /* If component has Button as suffixOutside */
    &:has(+ .mobius-button) {
      border-radius: var(--input-border-radius);
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }

    /* Focused */
    &:focus-within {
      border-color: var(--color-primary);
      background-color: var(--color-background-input-active);
      box-shadow: var(--box-shadow-default);

      & .mobius-text-field__prefix-inside,
      & .mobius-text-field__suffix-inside {
        color: var(--color-primary);
      }
    }

    /* Hovered */
    &:hover:not(.--is-disabled):not(&.--is-invalid) {
      border-color: var(--color-primary);
      background-color: var(--color-background-input-active);

      & .mobius-text-field__prefix-inside,
      & .mobius-text-field__suffix-inside {
        color: var(--color-primary);
      }
    }

    /* Disabled */
    &.--is-disabled {
      background-color: var(--color-background-light);
      border-color: var(--color-border-medium);
      color: var(--color-text-light);
      cursor: not-allowed;
    }

    /* Invalid */
    &.--is-invalid:not(.--is-disabled) {
      border-color: var(--color-error);
      background-color: var(--color-error-background);
      color: var(--color-error);
    }
  }

  .mobius-text-field__prefix-outside,
  .mobius-text-field__suffix-outside {
    &.mobius-text {
      margin-top: 0;
      margin-bottom: 0;
      align-self: center;
    }
  }

  .mobius-text-field__prefix-outside {
    &.mobius-button {
      border-radius: var(--input-border-radius);
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;

      /* When Button is prefixOutside, input */
      /* container should flatten left borders */
      & + .mobius-text-field__input-wrapper {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
      }
    }

    &.mobius-text {
      padding-right: var(--size-sm);
    }
  }

  .mobius-text-field__suffix-outside {
    &.mobius-button {
      border-radius: var(--input-border-radius);
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }

    &.mobius-text {
      padding-left: var(--size-sm);
    }
  }

  .mobius-text-field__prefix-inside {
    padding-left: var(--size-sm);
  }

  .mobius-text-field__suffix-inside {
    padding-right: var(--size-sm);
  }

  .mobius-text-field__prefix-inside,
  .mobius-text-field__suffix-inside {
    display: flex;

    &:not(.--is-invalid):not(.--is-disabled) {
      color: var(--color-primary);
    }

    &.mobius-button {
      min-height: 100%;
      border-radius: 0;
      align-self: stretch;
    }

    &.mobius-text {
      margin-top: 0;
      margin-bottom: 0;
    }
  }

  .mobius-text-field__input {
    flex: 1 1 0;
    padding: var(--input-field-padding);
    border: none;
    background-color: transparent;
    box-sizing: border-box;
    font-family: var(--font-family);
    font-size: var(--font-size-regular);
    color: currentColor;
    outline: 0;
    margin: 0;
    max-width: var(--text-input-max-width);

    &::placeholder {
      color: var(--color-text-medium);
    }

    &.--is-disabled {
      cursor: not-allowed;
    }
  }
}
