form,
.block-facets,
.form-area {
  background: $color-bg-form;

  > .form--inline,
  > .form-item,
  > .form-wrapper,
  > details.form-wrapper,
  > p,
  > [id*="ajax-wrapper"],
  > [class*="facets-widget"] {
    width: auto !important;
    margin-right: $grid-gutter;

    // Padding without adding padding to FORM Tag (which would mess up button positioning).
    margin-left: $grid-gutter;

    &:first-child {
      padding-top: $grid-gutter;
    }

    &:last-of-type {
      padding-bottom: $grid-gutter;
    }
  }
}

.description {
  @extend %small;
}

// .js-hide {
//  display: none !important;
// }

.form-textarea-wrapper,
.filter-wrapper {
  background: $color-bg-fieldset;

  .cke_top,
  .cke_contents,
  .cke_bottom {
    background: $color-bg-fieldset;
  }
  .filter-guidelines-item {
    margin: 0;
  }
}

.field-suffix .button {
  margin-bottom: $grid-gutter;
}

fieldset {
  padding: $grid-gutter;
  background: $color-bg-fieldset;

  summary,
  legend {
    @extend %allcaps;
  }

  &.error {
    border: 2px solid $color-danger;
    > legend {
      color: $color-danger;
    }
  }
}

fieldset fieldset {
  padding: 0;
  border-width: 0;
  background: transparent;
}

.form-required::after {
  content: "*";
  vertical-align: text-top;
  color: $color-danger;
  background-image: none;
}

.form--inline {
  .form-item {
    margin-top: 0;
  }
}

label {
  display: block;
  padding: 0.25rem;
  &.option {
    display: inline-block;
  }
}

input,
select,
textarea {
  padding: 0.5rem 1rem;
  border: 1px solid $color-divider-dark;
  background: $color-bg-light;
  &:focus {
    border-bottom-color: $color-info;
    box-shadow: 0 3px 2px 0 $color-info;
  }

  &.error {
    border-bottom-color: $color-danger;
    box-shadow: 0 3px 2px 0 $color-info;
  }
}

*::placeholder {
  text-align: right;
  color: $color-text-muted;
}

.form-autocomplete {
  padding-right: 2rem;
  background-position: right 0.5rem center !important;
}

.ui-autocomplete li.ui-menu-item {
  background-color: var(--color-bg-light);
  font-size: var(--font-size-s);
}

// Responsive forms.
input[size] {
  width: 100%;
  max-width: 100%;

  // @include breakpoint(m) {
  //  width: auto;
  // }
}

input[size="30"] {
  @include breakpoint(l) {
    max-width: 15rem;
  }
}

input.bef-datepicker {
  max-width: 10rem;
}

.view-search input[size="30"] {
  @include breakpoint(l) {
    max-width: 30rem;
  }
}

select {
  position: relative;
  padding-right: 2rem;
  background: $color-bg-light url(../images/chevron-down.svg) right 0.5em top 0.5em no-repeat;
  background-size: 1em;
  appearance: none;
  &[multiple].slimselect:not([data-once]) {
    height: 2.48rem;
    background: $color-bg-light;
    optgroup,
    option {
      visibility: hidden;
    }
  }
}

input[type="checkbox"],
input[type="radio"] {
  position: relative;
  top: 0.1rem;
  width: 1em;
  height: 1em;
  margin-right: 0.5rem;
  vertical-align: baseline;
}

// Autocomplete widget select.
.ui-menu .ui-menu-item-wrapper {
  display: block;
  color: $color-text;
  border: 0;
  background-color: transparent;

  &:hover,
  &:focus {
    color: $color-text-inverted;
    border: 0;
    background-color: $color-link;
  }
}

// Autocomplete widget select Focus.
.ui-autocomplete,
.ui-dialog .ui-autocomplete {
  .ui-menu-item-wrapper.ui-state-active {
    margin: 0;
    color: $color-text-inverted;
    background-color: $color-interaction;
  }
}

*[disabled] {
  pointer-events: none;
  opacity: 0.5;
}

// Views exposed forms

.bef-exposed-form {
  margin-top: $grid-gutter;
  padding-bottom: 0.75rem;
  border-width: 1px 0 1px;

  .form--inline .details-wrapper,
  > div {
    display: flex;
    flex-flow: row wrap;
    gap: 0.25rem 1rem;

    // align-items: last baseline;
    padding-bottom: 0.5rem;
  }

  // checkbox has no label above
  .form-type-checkbox {
    input {
      margin-right: 0.125em;
      font-size: 1.5em;
    }
    @include breakpoint(m) {
      align-self: flex-end;
      padding-bottom: 0.25rem;
    }
  }

  .form-submit {
    margin-bottom: 0;
  }

  // submit button alignment
  .form--inline .form-actions {
    display: flex;
    flex-flow: row wrap;
    align-self: flex-end;
    justify-content: space-between;
    gap: 0.75rem 1rem;

    button {
      margin: 0;
    }
  }

  // /* Secondary filters above default exposed form */
  //  .bef--secondary {
  //    order: -1;
  //  }

  .bef--secondary .details-title {
    color: var(--color-interaction);
  }
}

// Views exposed form in displays with "compact" css class

// .path-user .views-exposed-form,
div#block-oc-search-input,
.form--compact {
  .form--inline {
    &:first-child {
      padding-top: 0.25rem;
    }
    &:last-of-type {
      padding-bottom: 1rem;
    }
    .form-type-textfield {
      flex: 2 2 auto;
    }
    .form-actions {
      flex: 1 1 auto;
    }

    @include breakpoint(m) {
      display: flex;
      align-items: flex-end;
      gap: 1.25rem;

      * {
        margin: 0;
      }
    }
  }
  .form-text {
    max-width: 100%;
  }
  .details-wrapper {
    padding: 0;
  }
}

// @todo: add more robust identifier to fieldset
fieldset[id^="edit-radius-wrapper"] {
  // width: 100%;
  width: auto;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;

  legend {
    overflow: hidden;
    width: 0;
    height: 0;
  }

  .fieldset-wrapper {
    display: flex;
  }

  .form-item-radius-value {
    order: +1;
    max-width: 9rem;
  }

  .address-input {
    @include breakpoint(l) {
      max-width: 31.25rem;
    }
  }

  .form--inline:last-of-type {
    padding-bottom: 0;
  }
}

.block-facets {
  h4 {
    margin-bottom: 0 $grid-gutter $grid-gutter;
    padding: 0.5em 1rem;
  }
  ul {
    margin: 0;
    padding: 0;
    list-style: none outside;
  }
  li {
    display: inline-block;
    margin: 0;
    padding: 0;
    list-style: none;
  }
}

.region-content > .block-facets {
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

// View password module fix

button:not([disabled]).shwpd {
  position: absolute;
  top: 2.75rem;
  right: 1rem;
  left: auto;
  display: block;
  padding: 0.5rem 0.25rem;

  &:focus,
  &:hover {
    background-color: var(--color-bg-light);
  }
  &:focus,
  &:active {
    border: 2px dashed var(--color-interaction);
  }
}

input[type="password"],
.form-type-password input[type="text"] {
  padding-right: 3rem;
}

// Workflow moderation form

.content-moderation-entity-moderation-form {
  margin-bottom: (2 * $grid-gutter);
  padding: $grid-gutter (2 * $grid-gutter) $grid-gutter;
  background-color: $color-bg-warning;
}

.entity-moderation-form {
  margin: 0 $grid-gutter $grid-gutter;
  border: 0 none;
  background-color: transparent;

  li {
    margin-bottom: 0;
  }

  .form-item label {
    @extend %label;

    padding-left: 0;
  }
}

// Password indicator (@todo check back with contrib classy theme)

.password-strength__indicator {
  border: 1px solid transparent;

  &.is-weak {
    border-color: var(--color-danger);
    background-color: var(--color-danger);
  }
  &.is-fair {
    border-color: var(--color-warning-dark);
    background-color: var(--color-warning);
  }
  &.is-good {
    border-color: var(--color-info);
    background-color: var(--color-info);
  }
  &.is-strong {
    border-color: var(--color-success);
    background-color: var(--color-success);
  }
}

.password-suggestions {
  padding: 0.5rem 1rem 1rem;
  color: var(--color-info);
  border-color: var(--color-info);
  background-color: var(--color-bg-info);
}

// Date picker widget

.ui-datepicker.ui-widget {
  padding: 0.5em 0.5em 0;
  border-color: transparent;
  box-shadow: 0 0 1rem -0.5rem var(--color-text);
  font-family: var(--font-base);
}

.ui-datepicker {
  .ui-datepicker-prev,
  .ui-datepicker-next {
    display: inline-block;
    text-align: center;
    border-radius: 3px;

    &::before {
      content: "\f053";
      color: var(--color-interaction);
      font-family: "Font Awesome 6 Free"; // stylelint-disable-line font-family-no-missing-generic-family-keyword
      line-height: 1.75;
    }

    .ui-icon {
      background-image: none;
    }

    &:focus,
    &:hover,
    .ui-state-hover {
      color: var(--color-text-inverted);
      border-width: 0;
      background-color: var(--color-interaction);
    }
  }

  .ui-datepicker-next::before {
    content: "\f054";
  }

  .ui-datepicker-header {
    border-width: 0;
    background-color: unset;
  }

  tr {
    border: 0 none;
  }

  .ui-datepicker-calendar {
    background-color: var(--color-bg-form);
  }

  .ui-state-default,
  .ui-widget-content .ui-state-default,
  .ui-widget-header .ui-state-default,
  .ui-button {
    color: var(--color-text);
    border: 1px solid var(--color-divider-dark);
    background: var(--color-bg-light);
    font-weight: normal;

    &:focus,
    &:hover {
      color: var(--color-text-inverted);
      background: var(--color-interaction);
    }
  }

  .ui-state-highlight,
  .ui-widget-content .ui-state-highlight,
  .ui-widget-header .ui-state-highlight {
    color: var(--color-text);
    border-color: var(--color-divider-dark);
    background-color: var(--color-warning);
  }

  .ui-state-active,
  .ui-widget-content .ui-state-active {
    color: var(--color-info);
  }

  .ui-state-disabled {
    color: var(--color-text-muted) !important;
  }
}

// Native dialog replacing jquery modals

dialog.modal {
  padding: 1.25rem;
  border: 1px solid var(--color-interaction);
  border-radius: 0 0 var(--button-border-radius) var(--button-border-radius);
  background: var(--color-bg-light);

  &:has(.dialog-titlebar, .dialog-content) {
    padding: 0;
  }

  .dialog-titlebar {
    padding: 0.5rem 1.25rem;
    color: var(--color-text-inverted);
    background-color: var(--color-interaction);
  }

  .dialog-content {
    padding: 1.25rem;
    font-size: var(--font-size-default);
    font-weight: normal;
  }

  &::backdrop {
    opacity: 0.8;
    background: var(--color-neutral-canvas);
  }
}
