/* Input Fields & Input Groups - Bootstrap Compatible */

.input-field() {
  padding: ~"calc(var(--input-padding-y))" ~"calc(var(--input-padding-x))";
  position: relative;
  color: var(--input-text-color);
  background: var(--input-background-color);
  border: 1px solid var(--input-border-color);
  //box-shadow: 0px 1px 0px 0px rgba(0, 0, 0, .10);
  border-radius: var(--border-radius);
  &:focus {
    border-color: var(--input-border-color-focus);
  }
}

fieldset {
  padding: ~"calc(var(--gutter-size) / 2)" var(--gutter-size);
  border: 1px solid var(--input-border-color);
  border-radius: var(--border-radius);
  > legend {
    padding: .25em .5em;
  }
  &:disabled {
    opacity: 0.5;
  }
}

input, button, select, textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: var(--input-line-height);
  outline: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  text-align: end;

  &::-webkit-outer-spin-button,
  &::-webkit-inner-spin-button {
    display: none;
  }
}

.form-group {
  margin-bottom: 1em;
  &.required label::after {
    content: ' *';
    color: #f00;
  }
  > label:not(.form-check) {
    display: block;
    font-size: .9em;
    padding: .25em 0;
  }
}

label.form-check {
  display: block;
  user-select: none;
  line-height: 250%;
}

.form-check, label.form-check > input {
  &:is(input), &:is(label) > input {
    display: inline-block;
    position: relative;
    margin-inline-end: .25em;
    background: var(--input-background-color);
    border: 1px solid var(--input-border-color);
    //box-shadow: 0 1px 2px rgba(0,0,0,0.15), inset 0px -15px 10px -12px rgba(0,0,0,0.05);
    vertical-align: text-bottom;
    height: 1.25em;
    width: 1.25em;
    appearance: none;

    &:checked {
      background-color: #0066bb;
    }
    &:hover:not([disabled]) {
      box-shadow: 0 0 0 0.25rem #ccc;
    }
    &:disabled {
      opacity: .5;
    }
  }

  &:is([type="checkbox"]) {
    border-radius: var(--border-radius);
    &:checked {
      background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'><path fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/></svg>");
    }
  }

  &:is([type="radio"]) {
    border-radius: 50%;
    &:checked {
      background-image: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'><circle r='2' fill='%23fff'/></svg>");
    }
  }
}

.table tr:hover td:first-child > .form-check:not([disabled]),
.table tr:hover td:first-child > .form-check:not([disabled]) {
  box-shadow: 0 0 0 .25rem #ccc;
}

.form-control {
  .input-field();
  display: block;
  width: 100%;
  color: var(--input-text-color);
  vertical-align: middle;
  overflow-y: auto;
  transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s;
  //transition: all 50ms;
  &[type="color"] {
    height: 37px;
  }
  &[type="file"] {
    font-size: .7em;
  }
  &[disabled] {
    background: #f3f3f3;
    opacity: 0.5;
  }
  &[readonly] {
    color: #999;
  }
}

select.form-control {
  .input-field();
  display: block;
  width: 100%;
  padding-inline-end: 2.5em;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 1em center;
  background-size: 16px 12px;
  cursor: default;
  user-select: none;
  appearance: none;

  + .dropdown-menu {
    min-width: 100%;
    > li > label:hover {
      background: #efefef;
    }
  }

  option {
    background: var(--input-background-color);
  }
}

html[dir="rtl"] select.form-control {
  background-position: left 1em center;
}

.form-switch {
  width: 2em;
  height: 1em;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 -4 8 8"><circle r="3" fill="rgba%280, 0, 0, 0.25%29"/></svg>');
  background-position: left center;
  border-radius: 2em;
  margin-top: .25em;
  vertical-align: top;
  background-color: var(--whitespace-color);
  background-repeat: no-repeat;
  background-size: contain;
  border: 1px solid rgba(0, 0, 0, .25);
  transition: background-color .15s ease-in-out,background-position .15s ease-in-out,border-color .15s ease-in-out,box-shadow .15s ease-in-out;
  appearance: none;
  color-adjust: exact;

  &:active {
    filter: brightness(90%);
  }
  &:checked {
    background-position: right center;
    background-color: #666;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="-4 -4 8 8"><circle r="3" fill="%23fff"/></svg>');
  }
  &:focus {
    outline: 0;
    box-shadow: 0 0 0 .25rem #ccc;
  }
  &:disabled {
    opacity: .5;
  }
}

.form-code {
  .input-field();
  background: var(--input-code-background-color);
  width: 100%;
  height: 640px;
  font-size: .85em;
  color: var(--input-code-text-color);
  overflow-y: auto;
  font-family: Lucida Console, Monospace;
  white-space: pre-wrap;
}

.input-group {
  .input-field();
  display: flex;
  padding: 0;
  overflow: hidden;

  .form-control, .input-group {
    display: inline-block;
    flex: 1 1 auto;
    box-shadow: none;
    border-radius: 0;
    border: none;
    + .form-select {
      width: auto;
    }
  }
  .form-select {
    display: inline-block;
    flex: 1 1 auto;
    box-shadow: none;
    background-color: transparent;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    &[disabled] {
      opacity: .5;
    }
  }
  .input-group-text {
    flex: 0 1 auto;
    padding: var(--input-padding-y) var(--input-padding-x);
    background-color: var(--input-addon-background-color);
    border-inline-start: 1px solid var(--input-border-color);
    border-inline-end: 1px solid var(--input-border-color);
    color: var(--input-text-color);
    align-self: stretch;
    font-weight: normal;
    text-align: center;
    white-space: nowrap;
  }
  .input-group-icon {
    flex: 0 1 auto;
    padding: .5em 1em;
  }
  .btn {
    border-right: 0;
    border-top: 0;
    border: 0;
  }
  > *:not(:first-child) {
    border-left: 1px solid var(--input-border-color);
  }
  //> *:first-child:is(.btn, .form-select, .form-control) {
  > *:first-child {
    border-start-end-radius: 0;
    border-end-end-radius: 0;
  }
  //> *:last-child:is(.btn, .form-select, .form-control) {
  > *:last-child {
    border-start-start-radius: 0;
    border-end-start-radius: 0;
  }
  *:first-child:is(.form-control),
  *:first-child:is(.form-select),
  *:first-child:is(.input-group-text),
  *:first-child:is(.input-group) {
    border-inline-start: none;
  }
  *:last-child:is(.form-control),
  *:last-child:is(.form-select),
  *:last-child:is(.input-group-text),
  *:last-child:is(.input-group) {
    border-inline-end: none;
  }

/*
  .form-control + .form-control,
  .form-control + .form-select,
  .form-control + .input-group,
  .form-select + .form-control,
  .form-select + .form-select,
  .form-select + .input-group,
  .input-group + .form-control,
  .input-group + .form-select,
  .input-group + .input-group {
    border-inline-start: 1x solid var(--input-border-color);
  }
*/
}

.form-group > .form-control + .form-control,
.form-group > .form-control + .form-select,
.form-group > .form-control + .input-group,
.form-group > .form-select + .form-control,
.form-group > .form-select + .form-select,
.form-group > .form-select + .input-group,
.form-group > .input-group + .form-control,
.form-group > .input-group + .form-select,
.form-group > .input-group + .input-group {
  margin-top: -1px; // Compensate for border
}

.table-striped .form-control,
.table-striped .form-select {
  background-color: var(--whitespace-color);
}

fieldset[disabled] > :not(legend),
:input[disabled],
.form-control[disabled],
.form-select[disabled] {
  opacity: .5;
}

[data-toggle="buttons"] input[type="checkbox"],
[data-toggle="buttons"] input[type="radio"] {
  display: none;
}

.form-group .check,
.form-group .radio {
  padding: ~"calc(var(--input-padding-y) / 2)" 0;
}

.input-group .trumbowyg-box {
  --trumbowyg-pane-background-color: var(--input-addon-background-color);
  border-start-start-radius: 0;
  border-end-start-radius: 0;
  border-end-end-radius: 0;
  margin: -1px;
  margin-bottom: -2px;
  .trumbowyg-button-pane {
    border-start-start-radius: 0;
    .trumbowyg-button-group:first-child {
      border-start-start-radius: 0;
      button {
        border-start-start-radius: 0;
      }
    }
  }
  .trumbowyg-editor, .trumbowyg-textarea {
    border-end-start-radius: 0;
  }
}
