$backdrop-horizontal-spacing: spacing(tighter) * 1.5;
$addon-horizontal-spacing: 0.25em;
$spinner-icon-size: 1.2rem;

$stacking-order: (
  contents: 20,
  backdrop: 10,
);

.TextField {
  @include text-style-input;
  position: relative;
  display: flex;
  align-items: baseline;
  padding: 0 $backdrop-horizontal-spacing;
  color: color(ink, lightest);
}

.multiline {
  padding: 0;

  > .Input {
    overflow: auto;
    padding-left: $backdrop-horizontal-spacing;
    padding-right: $backdrop-horizontal-spacing;
    resize: none;
  }
}

.hasValue {
  .Input {
    color: color(ink);
  }
}

.error {
  
  .Input::placeholder {
    // This is the only place this color is used.
    // stylelint-disable-next-line color-no-hex
    color: #9c9798;
  }

  > .Input ~ .Backdrop {
    background-color: color(red, lighter);
    border-color: color(red);
    box-shadow: none;
  }

  // We need this to override the box-shadow in the focus state.
  // stylelint-disable-next-line selector-max-specificity
  > .Input:focus ~ .Backdrop {
    border-color: color(indigo);
    box-shadow:
      inset shadow(transparent),
      0 0 0 1px color(indigo);
  }
}

.readOnly > .Backdrop {
  background-color: color(sky, lighter);
}

.disabled > .Backdrop {
  background-color: color(sky, lighter);
  border: border();
  box-shadow: none;
}

.Input {
  @include text-style-input;
  position: relative;
  z-index: z-index(contents, $stacking-order);
  display: block;
  flex: 1 1 0%;
  width: 100%;
  min-height: control-height();
  margin: 0;
  padding: control-vertical-padding() 0;
  background: none;
  border: border(transparent);
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  appearance: none;

  &:disabled {
    color: color(ink, lightest);
  }

  &:focus {
    outline: none;

    ~ .Backdrop {
      border-color: color(indigo);
      box-shadow:
        inset shadow(transparent),
        0 0 0 1px color(indigo);
    
    }
  }

  &::placeholder {
    color: color(ink, lightest);
  }

  // These properties are used to remove the default "spinner" controls
  // for number fields, since we add our own, custom versions instead.
  &[type='number'] {
    appearance: textfield;

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
      appearance: none;
      margin: 0;
    }
  }
}

.Backdrop {
  position: absolute;
  z-index: z-index(backdrop, $stacking-order);
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: color(white);
  border: border(dark);
  box-shadow: inset 0 1px 0 0 rgba(color(ink, lighter), 0.05);
  border-radius: border-radius();
  will-change: box-shadow;
  transition: box-shadow duration() easing();
}

.Prefix {
  position: relative;
  z-index: z-index(contents, $stacking-order);
  flex: 0 0 auto;
  margin-right: $addon-horizontal-spacing;
  color: currentColor;
}

.Suffix {
  position: relative;
  z-index: z-index(contents, $stacking-order);
  flex: 0 0 auto;
  margin-left: $addon-horizontal-spacing;
  color: currentColor;
}

.Spinner {
  z-index: z-index(contents, $stacking-order);
  display: flex;
  align-self: stretch;
  flex-direction: column;
  width: 2.2rem;
  margin: 0.1rem calc(-#{$backdrop-horizontal-spacing} + 0.1rem) 0.1rem $backdrop-horizontal-spacing;
  color: color(ink);
}

.SpinnerIcon {
  height: $spinner-icon-size;
  width: $spinner-icon-size;
}

.Resizer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0;
  visibility: hidden;
}

.DummyInput {
  @include text-style-input;
  padding: control-vertical-padding() $backdrop-horizontal-spacing;
  border: border(transparent);

  // We need the following properties in order to have long, unbroken
  // strings wrap in the same way they do in textareas.
  white-space: pre-wrap;
  word-wrap: break-word;
  color:color(black);
  background-color:color(white);
}

.Segment {
  display: flex;
  flex: 1 1 0%;
  justify-content: center;
  align-items: center;
  appearance: none;
  background: linear-gradient(to bottom, color(white), color(sky, lighter));
  border: none;
  border-left: border(dark);
  will-change: background, box-shadow;
  transition:
    background duration(fast) easing(),
    box-shadow duration(fast) easing();

  &:focus {
    outline: none;
  }

  &:active {
    background: linear-gradient(to bottom, color(sky, light), color(sky, light));
    box-shadow:
      inset 0 1px 1px 0 rgba(color(ink, lighter), 0.1),
      inset 0 1px 4px 0 rgba(color(ink, lighter), 0.2);
  }

  &:not(:first-child) {
    margin-top: -0.1rem;
    border-top: border(dark);
  }

  &:first-child {
    border-top-right-radius: border-radius();
  }

  &:last-child {
    border-bottom-right-radius: border-radius();
  }
}
