.container {
  --text: var(--black);
  --border: var(--grey-4);
  --background: var(--grey-1);
}

.container.valid {
  --text: var(--green-6);
  --border: var(--green-4);
  --background: var(--green-1);
}

.container.invalid {
  --text: var(--red-6);
  --border: var(--red-4);
  --background: var(--red-1);
}

/* stylelint-disable-next-line no-duplicate-selectors */
.container {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border: 1px solid var(--border);
  background-color: var(--background);
  border-radius: var(--radius-medium);
  overflow: hidden;
  transition: outline 50ms ease-in-out;
  outline: 0 solid var(--focus-outline);

  @supports selector(:has(.container)) {
    &:has(.input:focus-visible) {
      outline-width: 3px;
    }
  }

  @supports not selector(:has(.container)) {
    .input:focus-within {
      outline-width: 3px;
    }
  }
}

.inputContainer {
  position: relative;
  display: flex;
  margin: -1px;
}

.input {
  flex: 1;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-medium);
  height: 3.375rem;
  padding-inline: 0.8125rem;
  padding-block-start: 0.7rem;
  background-color: var(--input-background);
  color: var(--input-text-color);
  font-family: inherit;
  font-size: 1rem;

  &::placeholder {
    opacity: 0 !important;
    color: transparent;
  }
}

.hasIcon .input:focus {
  padding-inline-end: 50px;
}

.labelContainer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: 1.375rem 0.8125rem;
  display: flex;
  align-items: center;
}

.label {
  overflow: hidden;
  text-align: start;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  transform-origin: 0 0;
  transition: transform 100ms ease-in-out-quad;
  color: var(--grey-5);
}

.input:is(:focus, :not(:placeholder-shown)) ~ .labelContainer {
  /* Invert the scale transform to allow the label to take up the full width */
  width: 167%;
}

.input:is(:focus, :not(:placeholder-shown)) ~ .labelContainer > .label {
  transform: scale(60%) translateY(-0.8rem) translateX(0.1rem);
}

.icon {
  color: var(--border);
  pointer-events: none;
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  inset-block: 0;
  inset-inline-end: 0;
  width: 50px;
  background-image: linear-gradient(
    to right,
    transparent 0%,
    var(--input-background) 25% 100%
  );
  /* Prevent clipping the parent border radius */
  background-clip: content-box;
  padding: var(--radius-medium);

  & > svg {
    transform: scale(1.1);
  }
}

.error {
  padding: 0.5rem 0.8125rem;
  font-size: var(--font-sm);
  position: relative;

  &::before {
    content: ' ';
    position: absolute;
    width: 7px;
    height: 7px;
    inset-inline-end: 25px;
    inset-block-start: -2px;
    background-color: var(--background);
    border-inline-start: 1px solid var(--border);
    border-block-start: 1px solid var(--border);
    transform-origin: 7px 7px;
    transform: rotate(45deg);
  }
}

.invalid .error {
  color: var(--red-6);
}

.valid .error {
  color: var(--green-6);
}
