.formbox {
  --formbox-font-size: 16px;
  --formbox-radius: 0.25em;
  --formbox-shadow: none;
  --formbox-hr-color: #f5f5f5;
  --formbox-title-weight: 600;
  --formbox-title-size: 1.125em;
  --formbox-title-color: inherit;
  --formbox-title-font: inherit;

  --formbox-field-border-color: #dbdbdb;
  --formbox-field-border-width: 1px;
  --formbox-field-background: transparent;
  --formbox-field-color: inherit;
  --formbox-field-border-hcolor: #007AFF;
  --form-field-height: 2.75em;

  --formbox-field-alert-color: #ff0000;

  --formbox-field-readonly-background: transparent;
  --formbox-field-readonly-color: inherit;

  --formbox-addon-color: inherit;
  --formbox-addon-background: #f5f5f5;
  --formbox-addon-weight: 400;

  --formbox-btn-calc-weight: 500;

  --formbox-btn-calc-color: #ffffff;
  --formbox-btn-calc-bg: #006400;
  --formbox-btn-calc-hcolor: #ffffff;
  --formbox-btn-calc-hbg: #006400;

  --formbox-btn-reset-color: #ffffff;
  --formbox-btn-reset-bg: #383838;
  --formbox-btn-reset-hcolor: #ffffff;
  --formbox-btn-reset-hbg: #383838;

  --formbox-title-result-color: inherit;
  --formbox-title-result-weight: 600;
  --formbox-field-border-result-color: #dbdbdb;
  --formbox-field-result-background: transparent;

  --formbox-result-addon-color: inherit;
  --formbox-result-addon-background: #f5f5f5;
}

.formbox-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  font-size: var(--formbox-font-size);
  margin-block-end: 1.125em;
}

.formbox,
.formbox * {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  border: none;
  font-size: var(--formbox-font-size);
}

.formbox {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  padding: 1em;
  margin: 1em 0;
  box-shadow: var(--formbox-shadow);
  border: none;
  border-radius: var(--formbox-radius);
  gap: 1em;

  hr {
    grid-column: 1/3;
    width: 100%;
    height: 0.125em;
    margin: 0.5em 0;
    background-color: var(--formbox-hr-color);
  }

  .is-hidden {
    display: none;
  }

  .has-result {
    .formbox-title {
      padding: 0;
    }
  }

  textarea[hidden] {
    display: none;
  }

  table {
    width: 100%;
  }

}

.formbox__container {
  display: grid;
  align-items: flex-start;
  grid-gap: 0.75em;

  @media screen and (min-width: 776px) {
    grid-template-columns: 2fr 3fr;
    &.is-vertical {
      grid-template-columns: 1fr;
      .formbox__title {
        padding-top: 0;
      }
    }
  }

  .is-title-only {
    grid-column: 1/3;
  }

}



.formbox__title {
  padding-top: calc(var(--form-field-height)/2 - var(--formbox-title-size));
  color: var(--formbox-title-color);
  font-family: var(--formbox-title-font);
  font-size: var(--formbox-title-size);
  font-weight: var(--formbox-title-weight);

  &.is-spaсe {
    grid-column: 1/3;
  }
}

.formbox__container:has(textarea) .formbox__title{
  padding-top: 0.375em;
}

.formbox__body {

  &:not(.has-group) {
    .formbox__field + .formbox__field {
      margin-block-start: 8px;
    }
  }

  &.has-group {
    display: grid;
    grid-gap: 0.5em;
    @media screen and (min-width: 776px) {
      grid-template-columns: 1fr 1fr;
    }

  }
}

.formbox__field {
  position: relative;

  &-lable {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    border: 0;
    word-wrap: normal;
    overflow: hidden;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);

    &:focus {
      top: 5px;
      left: 5px;
      display: block;
      z-index: 100000;
      width: auto;
      height: auto;
      padding: 15px 23px 14px;
      box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
      background-color: #f1f1f1;
      border-radius: 3px;
      color: #21759b;
      text-decoration: none;
      font-size: 0.875em;
      font-weight: 700;
      line-height: normal;
      clip: auto !important;
      clip-path: none;
    }
  }

  label {
    cursor: pointer;
  }

  &-addon {
    display: flex;
    justify-content: center;
    align-items: center;
    vertical-align: middle;
    height: var(--form-field-height);
    padding: 0.75em 1em;
    background-color: var(--formbox-addon-background);
    border: var(--formbox-field-border-width) solid var(--formbox-field-border-color);
    color: var(--formbox-addon-color);
    font-size: 1em;
    font-weight: var(--formbox-addon-weight);
    line-height: 1;
    white-space: nowrap;
  }

  &.has-addon {
    display: flex;

    &.is-left {
      .formbox__field-result,
      .formbox__field-input {
        border-radius: 0 var(--formbox-radius) var(--formbox-radius) 0;
      }

      .formbox__field-addon {
        border-right: none;
        border-radius: var(--formbox-radius) 0 0 var(--formbox-radius);
      }

    }


    &.is-right {
      flex-direction: row-reverse;

      .formbox__field-result,
      .formbox__field-input {
        border-radius: var(--formbox-radius) 0 0 var(--formbox-radius);
      }

      .formbox__field-addon {
        border-left: none;
        border-radius: 0 var(--formbox-radius) var(--formbox-radius) 0;
      }

    }
  }

}


.formbox__container {

  .formbox__field-radio,
  .formbox__field-checkbox {
    display: flex;
    align-items: flex-start;
    line-height: 1;
    gap: 0.5em;

    label {
      flex: 1;
    }
  }

  .formbox__field-radio + .formbox__field-radio {
    margin-block-start: 8px;
  }

  input[type='checkbox'],
  input[type='radio'] {
    box-shadow: none;
    border: var(--formbox-field-border-width) solid var(--formbox-field-border-color);
    border-radius: var(--formbox-radius);
    outline: none;

    &:focus {
      box-shadow: none;
      border-color: var(--formbox-field-border-hcolor);
    }
  }

  input.formbox__field-text,
  input.formbox__field-range,
  textarea.formbox__field-textarea,
  input.formbox__field-input,
  select.formbox__field-select,
  input.formbox__field-result,
  textarea.formbox__field-result,
  select,
  textarea {
    vertical-align: middle;
    width: 100%;
    height: var(--form-field-height);
    max-width: 100%;
    padding: 0.75em 1em;
    margin: 0;
    box-shadow: none;
    background-color: var(--formbox-field-background);
    border: var(--formbox-field-border-width) solid var(--formbox-field-border-color);
    border-radius: var(--formbox-radius);
    outline: none;
    color: var(--formbox-field-color);
    font-size: 1em;
    line-height: 1;


    &:focus {
      box-shadow: none;
      border-color: var(--formbox-field-border-hcolor);
      outline: none;
    }

    &[readonly],
    &[disabled] {
      background-color: (--formbox-field-readonly-background);
      outline: none;
      color: var(--formbox-field-readonly-color);
    }
  }

  select.formbox__field-select,
  select {
    padding: 0.75em 1.5em 0.75em 1em;
    background: var(--formbox-field-background) url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20width%3D%2220%22%20height%3D%2220%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M5%206l5%205%205-5%202%201-7%207-7-7%202-1z%22%20fill%3D%22%23555%22%2F%3E%3C%2Fsvg%3E') no-repeat right 5px top 55%;
    background-size: 1em 1em;
    cursor: pointer;
    font-size: 1em;
    -webkit-appearance: none;

  }



  input.formbox__field-range {
    height: auto;
    padding: 0;
  }

  textarea.formbox__field-textarea,
  textarea.formbox__field-result {
    height: 10em;
    resize: vertical;
  }

}

.formbox__field-range-value {
  position: absolute;
  right: 0;
  font-size: 0.75em;
  transform: translateY(-50%);
  font-weight: 500;
}
.field-range-text {
  display: flex;
  justify-content: space-between;
  padding-inline: 5px;
  option {
    flex: 1;
    text-align: center;
    font-size: 0.75rem;
    &:first-child {
      text-align: left;
    }
    &:last-child {
      text-align: right;
    }
  }
}

.formbox__btn {
  display: flex;
  grid-gap: 0.5em;

  @media screen and (max-width: 776px) {
    text-align: center;
  }

  input[type=submit],
  input[type=reset],
  button {
    justify-content: center;
    height: var(--form-field-height);
    padding-inline: 1em;
    border: var(--formbox-field-border-width) solid transparent;
    border-radius: var(--formbox-radius);
    cursor: pointer;
    user-select: none;
    text-align: center;
    font-size: var(--formbox-font-size);
    font-weight: var(--formbox-btn-calc-weight);
    white-space: nowrap;
  }

  button:not(:hover):not(:active).formbox__btn-calc {
    background-color: var(--formbox-btn-calc-bg);
    color: var(--formbox-btn-calc-color);

  }

  button.formbox__btn-calc:hover {
    background-color: var(--formbox-btn-calc-hbg);
    color: var(--formbox-btn-calc-hcolor);
  }

  button:not(:hover):not(:active).formbox__btn-reset {
    background-color: var(--formbox-btn-reset-bg);
    color: var(--formbox-btn-reset-color);

  }

  button.formbox__btn-reset:hover {
    background-color: var(--formbox-btn-reset-hbg);
    color: var(--formbox-btn-reset-hcolor);
  }
}

.formbox__container.has-result {

  .formbox__title {
    color: var(--formbox-title-result-color);
    font-weight: var(--formbox-title-result-weight);
  }

  input.formbox__field-result {
    background-color: var(--formbox-field-result-background);
    border-color: var(--formbox-field-border-result-color);
  }

  .formbox__field-addon {
    background-color: var(--formbox-result-addon-background);
    border-color: var(--formbox-field-border-result-color);
    color: var(--formbox-result-addon-color);
  }

}

.formbox__field-alert {
  color: var(--formbox-field-alert-color);
}