div[class^="form-row"] {
  margin-bottom: $ds-form-row-spacing;
}

input,
textarea {
  &.simple-input {
    border-radius: $ds-form-input-border-radius;
    border: $ds-form-input-border-width solid $ds-form-input-border-color;
    width: 100%;
    line-height: $ds-form-input-height;
    padding: 0 $ds-form-input-padding 0 $ds-form-input-padding;
    height: $ds-form-input-height;
    &:focus {
      border: $ds-form-input-border-width * 2 solid $ds-form-input-border-color-active;
    }
  }
}

.search-submit {
  color: $ds-form-input-border-color;
}

.form-row-text {
  position: relative;

  input,
  textarea {
    border-radius: $ds-form-input-border-radius;
    border: $ds-form-input-border-width solid $ds-form-input-border-color;
    width: 100%;
    line-height: $ds-form-input-height;
    padding: 0 $ds-form-input-padding 0 $ds-form-input-padding;
    height: $ds-form-input-height;
    transition: all 0.1s ease-in-out;
    caret-color: $ds-form-input-border-color-active;
  }

  input {
    height: $ds-form-input-height;
  }

  textarea {
    height: auto;
    padding-top: $ds-form-input-padding;
  }

  label {
    position: absolute;
    cursor: text;
    line-height: 4rem;
    top: -13px;
    transition: color, line-height 0.2s ease-in-out;
    width: 100%;
    display: flex;

    &:after,
    &:before {
      border: $ds-form-input-border-width solid transparent;
      border-top: $ds-form-input-border-width solid $ds-form-input-border-color;
      content: "";
      display: block;
      box-sizing: border-box;
      flex-grow: 1;
      transition: box-shadow 0.1s ease-in-out;
    }

    &:after {
      margin: 13px 0 0 4px;
      border-radius: 0 $ds-form-input-border-radius;
    }

    &:before {
      max-width: 8px;
      margin: 13px 4px 0 0;
      border-radius: $ds-form-input-border-radius 0;
    }
  }

  input::-webkit-datetime-edit,
  input::-webkit-calendar-picker-indicator,
  input::-webkit-clear-button,
  input::-webkit-inner-spin-button {
    visibility: hidden;
  }

  &.active,
  &.filled {
    input,
    textarea {
      border-top-color: transparent;
    }

    label {
      line-height: 1.5em;

      &:after,
      &:before {
        border-top: $ds-form-input-border-width solid $ds-form-input-border-color;
      }
    }

    input::-webkit-datetime-edit,
    input::-webkit-calendar-picker-indicator,
    input::-webkit-clear-button,
    input::-webkit-inner-spin-button {
      visibility: visible;
    }
  }

  &.active:not(.field-with-errors) {
    input,
    textarea {
      border-color: $ds-form-input-border-color-active;
      border-top-color: transparent;
      box-shadow: inset 1px -1px 0 0 $ds-form-input-border-color-active,
        inset -1px 0 0 0 $ds-form-input-border-color-active;
    }

    label {
      color: $ds-form-input-border-color-active;
      &:after,
      &:before {
        border-top: $ds-form-input-border-width solid $ds-form-input-border-color-active;
        box-shadow: inset 0 1px 0 0 $ds-form-input-border-color-active;
      }
    }
  }

  label abbr {
    border: none;
    text-decoration: none;
    padding-right: 0.2em;
    cursor: inherit;
  }
}

.form-row {
  select {
    border-radius: $ds-form-input-border-radius;
    border: $ds-form-input-border-width solid $ds-form-input-border-color;
    height: $ds-form-input-height;
    padding: 0 20px 0 $ds-form-input-padding;
    background-color: inherit;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='32' height='24' viewBox='0 0 32 24'><polygon points='0,0 32,0 16,24' style='fill: rgb%28102, 102, 102%29'></polygon></svg>");
    background-size: 9px 6px;
    background-position: right -15px center;
    background-repeat: no-repeat;
    background-origin: content-box;
    width: 100%;
  }

  label {
    cursor: default;

    & + select {
      display: block;
      margin-top: $ds-form-row-spacing / 2;
    }

    & abbr {
      border: none;
      text-decoration: none;
      padding-right: 0.2em;
      cursor: inherit;
    }
  }

  .radio-button {
    &.inline {
      display: inline-block;
    }

    input[type="radio"] {
      display: none;
      &:checked + label:before {
        border-color: $ds-form-input-border-color;
        animation: radio-ripple 0.2s linear forwards;
      }
      &:checked + label:after {
        transform: scale(1);
      }
    }

    label {
      display: inline-block;
      height: $ds-radio-size;
      position: relative;
      padding: 0 ($ds-radio-size + 0.5rem);
      margin-bottom: 0;
      cursor: pointer;
      vertical-align: bottom;

      &:before,
      &:after {
        position: absolute;
        content: "";
        border-radius: 50%;
        transition: all 0.3s ease;
        transition-property: transform, border-color;
      }

      &:before {
        left: 0;
        top: 0;
        width: $ds-radio-size;
        height: $ds-radio-size;
        border: 2px solid $ds-form-input-border-color;
      }

      &:after {
        top: $ds-radio-size / 2 - $ds-radio-checked-size / 2;
        left: $ds-radio-size / 2 - $ds-radio-checked-size / 2;
        width: $ds-radio-checked-size;
        height: $ds-radio-checked-size;
        transform: scale(0);
        background: $ds-form-input-border-color-active;
      }
    }
  }
}

.form-row.field-with-errors, .form-row-text.field-with-errors {
  &.active, &.filled {
    input {
      border-top-color: transparent;
    }
  }
  input {
    border-color: message-scale(error);
  }
  label:after, label:before {
    border-top: 1px solid message-scale(error);
  }
  label, span {
    color: message-scale(error);
  }
}
