.form-element {
  color: var(--gin-color-text);
  line-height: var(--input-line-height);
  padding-block: calc(var(--input-padding-vertical) - 1px);
  padding-inline: var(--input-padding-horizontal);
  min-height: calc((var(--input-padding-vertical) * 2) + var(--input-line-height));
  background-color: var(--gin-bg-input);
  border: 1px solid var(--gin-border-color-form-element);
  border-radius: var(--gin-border-m);
  box-sizing: border-box;
  transition: var(--gin-transition);

  &:hover {
    border-color: var(--gin-color-text);
    box-shadow: inset 0 0 0 1px var(--gin-color-text);
  }

  &--small,
  &--extrasmall {
    font-size: var(--gin-font-size-s);
    line-height: 1.5;
    border-radius: var(--gin-border-s);
  }

  &[disabled],
  &[disabled]:hover {
    cursor: not-allowed;
    color: var(--gin-color-disabled);
    background-color: var(--gin-color-disabled-bg) !important;
    border-color: var(--gin-color-disabled-border);
    box-shadow: none;
  }

  .gin--dark-mode & {
    color-scheme: dark;
  }
}

.form-textarea-wrapper {
  // box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
  border-radius: var(--gin-border-m);

  textarea {
    max-width: 100%;
  }
}

.form-item--editor-format,
.form-element--editor-format {
  width: auto;

  .form-item__label {
    inset-block-start: 3px;
    padding-block-end: 0;
  }
}

// Password
.password-field {
  width: 100%;
}

.password-confirm {
  width: 100%;
  max-width: var(--gin-max-line-length);
}

.password-strength {
  &__title {
    color: var(--gin-color-text-light);
  }

  &__text {
    color: var(--gin-color-title);
  }
}

.password-suggestions {
  color: var(--gin-color-text-light);
  border: 1px solid var(--gin-border-color-layer2);
  background-color: transparent;
}

// Select
.form-element--type-select {
  padding-inline-end: calc(var(--gin-spacing-xs) + var(--gin-spacing-xl) - 1px);

  .gin--dark-mode & {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 14 9'%3E%3Cpath fill='none' stroke-width='1.5' d='M1 1L7 7L13 1' stroke='%23ffffff'/%3E%3C/svg%3E%0A");
  }
}

.form-element--type-select--small {
  font-size: var(--gin-font-size-xs);
  min-height: 2.25rem;
  line-height: 1.4;
  padding-block: .474rem; // 0.79rem * 1.2 / 2
  background-position: 100% 52%;
}

.form-boolean {
  width: 21px;
  height: 21px;
  border-color: var(--gin-border-color-form-element);
  border-radius: var(--gin-border-xs);
}

// Darkmode Checkbox
.form-boolean--type-checkbox {
  &:not(:checked) {
    .gin--dark-mode & {
      background: var(--gin-bg-input);
    }
  }

  &:checked {
    background-color: var(--gin-color-primary);

    &:not(:disabled) {
      .gin--dark-mode & {
        background-image: icon('checked');
      }
    }

    &:hover {
      background-color: var(--gin-color-primary-hover);
    }

    &:active {
      background-color: var(--gin-color-primary-active);
    }
  }
}

// Single Checkbox: show as toggle
:not(.form-checkboxes):not(td):not(.tabledrag-cell-content__item):not(.media-library-item__click-to-select-checkbox):not(.field-content):not(.ajax-new-content):not(.tablesaw-cell-content) > .form-type--checkbox {
  position: relative;
  margin-inline-start: 0;

  input {
    all: unset;
    appearance: none;
    cursor: pointer;
    display: inline-block;
    vertical-align: top;
    width: 2.5rem;
    height: 1.5rem;
    position: relative;
    overflow: hidden;
    clip-path: circle(var(--gin-spacing-l) at 50% 50%); // Fix Safari bug
    background-color: var(--gin-color-disabled);
    border: 3px solid transparent;
    border-radius: var(--gin-border-l);
    box-sizing: border-box;

    .gin--dark-mode & {
      background-color: var(--gin-bg-input);
    }

    @media (forced-colors: active) {
      border-width: 2px;
    }

    &::before {
      position: absolute;
      content: "";
      width: 100%;
      height: 100%;
      background-color: #fff;
      border-radius: 21px;
      transform: translateX(-16px);
      transition: transform .3s;

      .gin--dark-mode & {
        background-color: var(--gin-border-color-form-element);
      }

      @media (forced-colors: active) {
        background-color: CanvasText;
      }
    }

    @media (forced-colors: active) {
      &::after {
        position: absolute;
        content: '';
        width: 100%;
        height: 100%;
        background-color: Canvas;
        mask-image: icon('toggle-unchecked');
        mask-size: 16px 16px;
        mask-position: 17px 2px;
        mask-repeat: no-repeat;
        transform: translateX(-16px);
        transition: transform .3s;
      }
    }

    // Disabled state: set cursor to not-allowed
    &:disabled {
      cursor: not-allowed;
    }

    // Hover state
    &:hover {
      opacity: .9;
      box-shadow: 0 0 2px rgba(0, 0, 0, .2);
    }

    // Hover/Focus state
    &:active,
    &:focus {
      box-shadow: 0 0 0 1px var(--gin-color-focus-border), 0 0 0 4px var(--gin-color-focus);
    }

    // Active state
    &:checked {
      background-color: var(--gin-switch);

      .gin--dark-mode & {
        background-color: var(--gin-color-primary-light-active);
      }

      &::before {
        transform: translateX(16px);
        background-color: #fff;

        .gin--dark-mode & {
          background-color: var(--gin-color-primary-hover);
        }

        .gin--high-contrast-mode & {
          background-color: var(--gin-border-color);
        }

        @media (forced-colors: active) {
          padding-inline-start: var(--gin-spacing-xs);
          background-color: LinkText !important;
        }
      }

      @media (forced-colors: active) {
        &::after {
          transform: translateX(16px);
          mask-image: icon('checked');
          mask-position: 2px 2px;
        }
      }
    }

    // Disabled state
    &:disabled {
      opacity: 0.75;
      background-color: var(--gin-color-disabled);
      box-shadow: none;

      &::before {
        background-color: #fff;
        opacity: .6;
      }
    }
  }

  label {
    z-index: 1;
    position: relative;
    padding-inline-start: var(--gin-spacing-xxs);
    padding-block-end: 0;
    color: var(--gin-color-text);
  }
}

// Correctly align bulk action checkboxes when used in combination with tabledrag
table:has(.tabledrag-cell-content__item .form-checkbox) th.select-all .form-checkbox {
  margin-inline-start: calc(var(--tabledrag-handle-icon-size, calc(17rem / 16)) + var(--gin-spacing-m));
}

.form-boolean {
  &:hover, &:active {
    .gin--dark-mode & {
      box-shadow: none;
      border-color: var(--gin-color-text);
    }
  }
}

.form-boolean--type-radio {
  &, &:hover, &:active, &:focus, &:hover:focus {
    background-image: none;
    background-color: var(--gin-bg-input);
    border-color: var(--gin-border-color-form-element);
    border-radius: 50%;
  }

  &:hover {
    box-shadow: inset 0 0 0 1px var(--gin-border-color-layer2);

    &, .gin--dark-mode & {
      border-color: var(--gin-color-text);
    }
  }

  &:active, &:focus {
    box-shadow: inset 0 0 0 1px var(--gin-border-color-layer2),
                0 0 0 1px var(--gin-color-focus-border),
                0 0 0 4px var(--gin-color-focus);
  }

  &:checked:not(:disabled) {
    &, &:hover {
      background-image: none;
      background-color: var(--gin-bg-layer);
      box-shadow: inset 0 0 0 5px var(--gin-color-primary);
    }

    &:active, &:focus, &:hover:focus {
      box-shadow: inset 0 0 0 5px var(--gin-color-primary),
                  0 0 0 1px var(--gin-color-focus-border),
                  0 0 0 4px var(--gin-color-focus);
      border-color: var(--gin-color-focus-border);
    }
  }

  &:disabled {
    &, &:hover {
      cursor: not-allowed;
      background: var(--gin-color-disabled-bg);
      border-color: var(--gin-color-disabled-border);
    }
  }

  &:checked:disabled {
    &, &:hover {
      background: var(--gin-color-disabled);
      box-shadow: inset 0 0 0 5px var(--gin-color-disabled-bg);
    }
  }
}

.form-boolean--type-checkbox[disabled] {
  &, &:hover {
    cursor: not-allowed;
    background-color: var(--gin-color-disabled-bg);
    border-color: var(--gin-color-disabled-border);

    &:checked {
      border-color: var(--gin-color-disabled-border);
      background-color: var(--gin-color-disabled-bg);
      box-shadow: none;
    }
  }
}

.form-radios,
.form-checkboxes {
  .form-type--boolean {
    margin-block: var(--gin-spacing-xs);
  }
}

.form-actions {
  margin-block-end: 0;
}

.form-edit .form-actions {
  padding: 0;
  margin-block-end: 0;
  border: 0 none;
  background-color: transparent;
}

// Fieldgroup
fieldset:not(.fieldgroup) {
  color: var(--gin-color-text-light);
  padding-block-start: var(--gin-spacing-xs);
  padding-inline: 0;
  background: transparent;
  border-color: var(--gin-border-color);
  border-radius: var(--gin-border-m);
  box-shadow: none;

  > legend {
    inset-block-start: 20px;
  }

  > .fieldset-wrapper {
    margin-block-start: 20px;
  }

  &.error {
    border: 2px solid var(--gin-color-danger);
  }
}

.fieldset__label,
.fieldset__label--group,
.form-item__label {
  font-size: var(--gin-font-size-s);
  font-weight: var(--gin-font-weight-semibold);
  color: var(--gin-color-title);
  margin-block-start: 0;
  margin-block-end: var(--gin-spacing-xs);
}

.form-item__label.has-error,
.form-item__error-message {
  color: var(--gin-color-danger);
}

.form-item__description,
.fieldset__description,
.filter-guidelines__item {
  max-width: var(--gin-max-line-length);
  color: var(--gin-color-text-light);
}

.form-item__label.form-required::after,
.fieldset__label.form-required::after,
.form-required > .fieldset__label::after,
.horizontal-tab-button .form-required::after,
.vertical-tabs__menu-link .form-required::after {
  content: "*";
  color: var(--gin-color-danger);
  line-height: 1;
  margin-inline: .15em;
  vertical-align: text-top;
  background: none;
}

.claro-details.error {
  border: 2px solid var(--gin-color-danger);
}

.claro-details__summary:not(.form-required) {
  .required-mark {
    display: none;
  }
}

.form-item__warning {
  display: inline-block;
  margin-block-start: var(--gin-spacing-xs);
}

html.js .form-autocomplete {
  padding-inline-end: 36px;
}

.entity-form-display-form {
  > .form-actions {
    margin-block: 0;
  }
}

.required-mark {
  &::after {
    background: var(--gin-color-danger);
    mask-image: icon('asterisk');
    mask-position: center center;
    mask-size: 100% 100%;
  }
}

.form-wrapper,
.form-composite {
  .form-item__label {
    position: relative;
  }
}

.field--type-text-with-summary,
.field--widget-text-textarea {
  .form-item {
    margin-block-end: 0;
  }

  .filter-wrapper {
    border: 0 none;
    padding-inline: 0;
  }
}

// Autocomplete field
html.js input.form-linkit-autocomplete {
  padding-inline-end: var(--gin-spacing-xl);
  background-position: right 8px center;
}

.claro-autocomplete {
  width: calc(100% - var(--gin-spacing-m));

  .form-autocomplete {
    width: 100%;
  }
}

.no-touchevents .form-element--type-select.form-element--extrasmall {
  font-size: var(--gin-font-size-s);
  line-height: 1.5;
  min-height: 1.75rem;
}

// Special case, form starts with a form item, remove margin-block-start.
#block-gin-content > form > .form-item:first-of-type {
  margin-block-start: 0;
}

.image-style-new {
  .form-item {
    margin-inline-end: var(--gin-spacing-xxs);
  }
}

tr .form-item {
  margin-block: 0;
}

.container-inline .form-item {
  margin-block: var(--gin-spacing-density-s);
}

.field-plugin-settings-edit-form {
  margin-block-start: var(--gin-spacing-s);

  .form-item {
    margin-block: var(--gin-spacing-m);
  }

  .form-boolean-group .form-item {
    margin-block: var(--gin-spacing-xs);
  }
}

// Length indicator
.length-indicator {
  margin-block-end: var(--gin-spacing-l);
}
