/*
 * SPDX-FileCopyrightText: 2024-present Tobias Kunze
 * SPDX-License-Identifier: Apache-2.0
 */

/* form-level styles */
.form-inline {
  display: flex;
  flex-wrap: wrap;
}

/* row-level styles */
.form-group {
  margin-bottom: var(--size-spacer);
  display: flex;
  .col-md-9,
  .col-md-3 {
    padding-left: 15px;
    padding-right: 15px;
  }
  &.form-group-inline {
    flex-direction: column;
    label {
      text-align: left;
    }
  }
}
.hide-label {
  label {
    display: none;
  }
  .form-group > .col-md-9 {
    max-width: 100%;
    flex: 0 0 100%;
    label {
      display: inline-block;
    }
  }
}
.hide-optional .optional {
  display: none;
}
.row {
  display: flex;
  flex-wrap: wrap;
  margin-right: -15px;
  margin-left: -15px;
}

/* non-input styles */
label {
  display: inline-flex;
  flex-direction: column;
  padding-top: 4px;
  padding-bottom: calc(0.375rem + 1px);
  margin-bottom: 0;
  font-size: inherit;
  text-align: right;
  user-select: none;
  font-weight: bold;
  .optional {
    font-weight: normal;
    color: var(--color-grey);
  }
  &.col-form-label.col-md-3 {
    padding-top: 8px;
    padding-right: 0;
  }
  &.inline-form-label {
    flex-direction: row;
    .optional {
      padding-left: 0.25rem;
      &:before {
        content: "(";
      }
      &:after {
        content: ")";
      }
    }
  }
}

small.form-text {
  font-size: inherit;
  margin-top: 0.25rem;
  display: block;
}
.invalid-feedback {
  font-size: 0.875rem;
  color: var(--color-danger);
  font-weight: normal;
  font-family: var(--font-family);
}

fieldset {
  min-width: 0;
  padding: 0;
  margin: 0;
  border: 0;
}
legend {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  width: 100%;

  padding: 0;
  font-size: 22px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 20px;
}

/* input level styles */

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
  display: block;
  width: 100%;
  padding: 0.375rem 0.75rem;
  color: var(--color-text-input);
  caret-color: var(--color-text-input);
  font-size: 1rem;

  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;

  background-color: var(--color-bg);
  background-clip: padding-box;
  border: 1px solid var(--color-border);
  border-radius: var(--size-border-radius);
  transition:
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;

  &.small {
    height: calc(1.5em + 0.5rem + 2px);
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: 0.2rem;
  }

  &.is-valid {
    border-color: var(--color-success);
  }

  &[aria-invalid],
  &:user-invalid {
    border-color: var(--color-danger);
  }

  &:-moz-focusring {
    color: transparent;
    text-shadow: 0 0 0 var(--color-text-input);
  }

  &:focus {
    border-color: var(--color-primary-light);
    outline: 0;
    box-shadow: var(--shadow-focus);
  }

  &::placeholder {
    color: var(--color-grey);
    opacity: 1;
  }

  &:disabled,
  &[readonly] {
    background-color: var(--color-grey-lightest);
    opacity: 1;
  }

  &::-webkit-datetime-edit {
    display: block;
    padding: 0;
  }
}

input[type="file"] {
  overflow: hidden;
  &:not(:disabled):not([readonly]) {
    cursor: pointer;
  }
}
::file-selector-button {
  margin-left: -6px;
  color: white;
  background-color: var(--color-secondary);
  pointer-events: none;
  border-width: 0;
  border-radius: var(--size-border-radius);
}
.form-group-inline {
  input[type="file"] {
    padding: 0.15rem 0.5rem;
  }
  ::file-selector-button {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    margin-top: -3px;
    margin-left: -5px;
    font-size: 0.875rem;
    border-radius: 0.2rem;
  }
}

input[type="checkbox"],
input[type="radio"] {
  -moz-appearance: none;
  -webkit-appearance: none;

  width: 24px;
  height: 24px;
  background: var(--color-offwhite);
  box-shadow: var(--shadow-checkbox);
  background-image: none !important;
  cursor: pointer;
  font-size: 1rem;

  &:checked {
    background: var(--color-primary);
    border: 4px solid var(--color-offwhite);
  }

  &:disabled,
  &[readonly] {
    filter: grayscale(100%);
    cursor: normal;
    pointer-events: none;
  }

  & + label {
    cursor: pointer;
    font-weight: normal;
    padding-left: 8px;
    vertical-align: super;
    font-size: 1rem;
    & ~ a .badge,
    & ~ .badge {
      /* This is primarily for the multi_languages_widget.html badges */
      vertical-align: super;
    }
  }
}

input[type="checkbox"] {
  border-radius: var(--size-border-radius);
}
input[type="radio"] {
  border-radius: 50%;
}
input[type="radio"] + label {
  line-height: 2;
}

.checkbox-group-legend {
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--color-border);

  span {
    background-color: var(--color-bg);
    padding-right: 0.5rem;
    position: relative;
    top: 0.5em;
  }
}

textarea {
  resize: vertical;
  height: auto;
  field-sizing: content;
}

select,
input[type="file"],
input [type="range"] {
  display: block;
  width: 100%;
}

select {
  padding: 0.375rem 2.25rem 0.375rem 0.75rem;
  background-color: var(--color-bg);
  background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path fill='none' stroke='var(--color-text-input)' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 12px;
  word-wrap: normal;

  &[multiple],
  &[size]:not([size="1"]) {
    height: auto;
    background-image: none;
    padding-right: 0.75rem;
  }

  &:disabled {
    background-color: var(--color-grey-lighter);
  }
}

input[type="search"] {
  -webkit-appearance: textfield;
  outline-offset: -2px; /* Safari */
  height: fit-content;
  &.form-control.is-valid {
    border-color: var(--color-border);
  }
}
::-webkit-search-decoration {
  -webkit-appearance: none;
}

input[type="number"] {
  -moz-appearance: textfield !important;

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

::-webkit-file-upload-button,
::file-selector-button {
  -webkit-appearance: button;
}
::-webkit-datetime-edit-fields-wrapper,
::-webkit-datetime-edit-text,
::-webkit-datetime-edit-minute,
::-webkit-datetime-edit-hour-field,
::-webkit-datetime-edit-day-field,
::-webkit-datetime-edit-month-field,
::-webkit-datetime-edit-year-field,
::-webkit-color-swatch-wrapper {
  padding: 0;
}

.input-group {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  width: 100%;

  & > input:not([type="checkbox"]):not([type="radio"]),
  & > select,
  & > button {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
    margin-bottom: 0;

    & + & {
      margin-left: -1px;
    }

    &:focus {
      z-index: 3;
    }
    &:not(:first-child) {
      border-top-left-radius: 0;
      border-bottom-left-radius: 0;
    }
    &:not(:last-child) {
      border-top-right-radius: 0;
      border-bottom-right-radius: 0;
    }
  }
}

.input-group-prepend,
.input-group-append {
  display: flex;

  button {
    position: relative;
    z-index: 2;

    &:focus {
      z-index: 3;
    }
  }

  button + button,
  button + .input-group-text,
  .input-group-text + .input-group-text,
  .input-group-text + button {
    margin-left: -1px;
  }
}

.input-group-prepend {
  margin-right: -1px;
}
.input-group-append {
  margin-left: -1px;
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: 0.375rem 0.75rem;
  margin-bottom: 0;
  color: var(--color-text-input);
  text-align: center;
  white-space: nowrap;
  background-color: var(--color-grey-lighter);
  border: 1px solid var(--color-border);
  border-radius: var(--size-border-radius);
}

.input-group > .input-group-prepend > button,
.input-group > .input-group-prepend > .input-group-text,
.input-group:not(.has-validation)
  > .input-group-append:not(:last-child)
  > button,
.input-group:not(.has-validation)
  > .input-group-append:not(:last-child)
  > .input-group-text,
.input-group.has-validation
  > .input-group-append:nth-last-child(n + 3)
  > button,
.input-group.has-validation
  > .input-group-append:nth-last-child(n + 3)
  > .input-group-text,
.input-group
  > .input-group-append:last-child
  > button:not(:last-child):not(.dropdown-toggle),
.input-group
  > .input-group-append:last-child
  > .input-group-text:not(:last-child) {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-group > .input-group-append > button,
.input-group > .input-group-append > .input-group-text,
.input-group > .input-group-prepend:not(:first-child) > button,
.input-group > .input-group-prepend:not(:first-child) > .input-group-text,
.input-group > .input-group-prepend:first-child > button:not(:first-child),
.input-group
  > .input-group-prepend:first-child
  > .input-group-text:not(:first-child) {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.submit-group,
.filter-group {
  display: flex;
  justify-content: space-between;
  flex-grow: 1;
  flex-wrap: wrap;
  background-color: var(--color-grey-lightest);
  padding: 16px;
  margin-bottom: 16px;
  border-radius: var(--size-border-radius);

  button,
  a[role="button"] {
    align-self: flex-end;

    i.fa {
      padding-right: 8px;
    }
  }
}

@media (max-width: 768px) {
  .submit-group {
    flex-direction: column;
    button,
    .btn {
      width: 100%;
      margin-bottom: 8px;
    }
  }
}
