/*!
 * This program is free software; you can use it, redistribute it
 * and / or modify it under the terms of the GNU General Public License
 * (GPL) as published by the Free Software Foundation; either version 3
 * of the License or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 *  WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program, in a file called gpl.txt or license.txt.
 *  If not, write to the Free Software Foundation Inc.,
 *  59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
 */
@use "sass:color";

[type=button]:not(:disabled), [type=reset]:not(:disabled), [type=submit]:not(:disabled), button:not(:disabled) {
  cursor: pointer;
}

.form-control {
  display: block;
  width: 100%;
  padding: .375rem .75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ui-body-color);
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--ui-body-bg);
  background-clip: padding-box;
  border: var(--ui-border-width) solid var(--ui-border-color);
  border-radius: var(--ui-border-radius);
  box-shadow: var(--ui-box-shadow-inset);
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;

  &:disabled {
    background-color: var(--ui-secondary-bg);
    opacity: 1;
  }

  &:focus {
    color: var(--ui-body-color);
    background-color: var(--ui-body-bg);
    border-color: var(--ui-form-focus-border-color);
    outline: 0;
    box-shadow: var(--ui-box-shadow-inset), var(--ui-form-focus-box-shadow-inset);
  }

  &.is-invalid {
    $color: toRGB($form-invalid-color);
    $svg: str-replace("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='COLOR'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='COLOR' stroke='none'/%3e%3c/svg%3e", "COLOR", $color);
    border-color: var(--ui-form-invalid-border-color);
    padding-right: calc(1.5em + .75rem);
    background-image: url($svg);
    background-repeat: no-repeat;
    background-position: right calc(.375em + .1875rem) center;
    background-size: calc(.75em + .375rem) calc(.75em + .375rem);
  }
}

.form-check {
  display: block;
  min-height: 1.5rem;
  padding-left: 1.5em;
  margin-bottom: .125rem;

  .form-check-input {
    float: left;
    margin-left: -1.5em;
  }
}

.form-check-inline {
  display: inline-block;
  margin-right: 1rem;
}

.form-check-input {
  flex-shrink: 0;
  width: 1em;
  height: 1em;
  margin-top: .25em;
  vertical-align: top;
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--ui-form-check-bg);
  background-image: var(--ui-form-check-bg-image);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  border: var(--ui-border-width) solid var(--ui-border-color);
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;

  &[type=checkbox] {
    border-radius: .25em;
  }

  &:checked[type=checkbox] {
    $color: toRGB(#fff);
    $svg: str-replace("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='COLOR' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='m6 10 3 3 6-6'/%3e%3c/svg%3e", "COLOR", $color);
    --ui-form-check-bg-image: #{url($svg)};
  }

  &:checked {
    background-color: var(--ui-form-check-checked-bg);
    border-color: var(--ui-form-check-checked-border-color);
  }
}

.form-select {
  $color: toRGB($border-color);
  $svg: str-replace("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='COLOR' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e", "COLOR", $color);
  --ui-form-select-bg-img: #{url($svg)};
  display: block;
  width: 100%;
  padding: .375rem 2.25rem .375rem .75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ui-body-color);
  appearance: none;
  background-color: var(--ui-body-bg);
  background-image: var(--ui-form-select-bg-img), var(--ui-form-select-bg-icon, none);
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: 16px 12px;
  border: var(--ui-border-width) solid var(--ui-border-color);
  border-radius: var(--ui-border-radius);
  box-shadow: var(--ui-box-shadow-inset);
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}

.btn {
  display: inline-block;
  padding: var(--ui-btn-padding-y) var(--ui-btn-padding-x);
  font-family: var(--ui-btn-font-family);
  font-size: var(--ui-btn-font-size);
  font-weight: var(--ui-btn-font-weight);
  line-height: var(--ui-btn-line-height);
  color: var(--ui-btn-color);
  text-align: center;
  text-decoration: none;
  vertical-align: middle;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  border: var(--ui-btn-border-width) solid var(--ui-btn-border-color);
  border-radius: var(--ui-btn-border-radius);
  background-color: var(--ui-btn-bg);
  box-shadow: var(--ui-btn-box-shadow);
  transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;

  &:disabled, &.disabled, fieldset:disabled & {
    color: var(--ui-btn-disabled-color);
    pointer-events: none;
    background-color: var(--ui-btn-disabled-bg);
    border-color: var(--ui-btn-disabled-border-color);
    opacity: var(--ui-btn-disabled-opacity);
    box-shadow: none;
  }

  &:hover {
    color: var(--ui-btn-hover-color);
    background-color: var(--ui-btn-hover-bg);
    border-color: var(--ui-btn-hover-border-color);
  }

  &:focus {
    outline: none;
    color: var(--ui-btn-active-color);
    background-color: var(--ui-btn-active-bg);
    border-color: var(--ui-btn-active-border-color);
  }
}

.btn-group {
  border-radius: var(--ui-border-radius);
  position: relative;
  display: inline-flex;
  vertical-align: middle;

  & > .btn-group:not(:last-child) > .btn, & > .btn.dropdown-toggle-split:first-child, & > .btn:not(:last-child):not(.dropdown-toggle) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  & > .btn {
    position: relative;
    flex: 1 1 auto;
  }
}

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

  .btn {
    position: relative;
    z-index: 2;
  }

  & > .form-control,
  & > .form-floating,
  & > .form-select {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
  }

  & > .form-control:focus,
  & > .form-select:focus {
    z-index: 5;
  }

  & > :not(:first-child):not(.dropdown-menu):not(.valid-tooltip):not(.valid-feedback):not(.invalid-tooltip):not(.invalid-feedback) {
    margin-left: calc(-1 * var(--ui-border-width));
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  &:not(.has-validation) > .dropdown-toggle:nth-last-child(n+3),
  &:not(.has-validation) > :not(:last-child):not(.dropdown-toggle):not(.dropdown-menu):not(.form-floating) {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  & > .form-control:not(:focus).is-invalid,
  & > .form-floating:not(:focus-within).is-invalid,
  & > .form-select:not(:focus).is-invalid {
    z-index: 4;
  }
}

.input-group-text {
  display: flex;
  align-items: center;
  padding: .375rem .75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ui-body-color);
  text-align: center;
  white-space: nowrap;
  background-color: var(--ui-tertiary-bg);
  border: var(--ui-border-width) solid var(--ui-border-color);
  border-radius: var(--ui-border-radius);
}

.btn-primary {
  --ui-btn-color: #fff;
  --ui-btn-bg: #{$primary};
  --ui-btn-border-color: #{$primary};
  --ui-btn-hover-color: #fff;
  --ui-btn-hover-bg: #{color.adjust($primary, $lightness: 15%)};
  --ui-btn-hover-border-color: #{color.adjust($primary, $lightness: 10%)};
  --ui-btn-focus-shadow-rgb: 58, 96, 154;
  --ui-btn-active-color: #fff;
  --ui-btn-active-bg: #{color.adjust($primary, $lightness: 10%)};
  --ui-btn-active-border-color: #{color.adjust($primary, $lightness: 5%)};
  --ui-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
  --ui-btn-disabled-color: #fff;
  --ui-btn-disabled-bg: #{$primary};
  --ui-btn-disabled-border-color: #{$primary};
}

.btn-secondary {
  --ui-btn-color: #fff;
  --ui-btn-bg: #{$secondary};
  --ui-btn-border-color: #{$secondary};
  --ui-btn-hover-color: #fff;
  --ui-btn-hover-bg: #{color.adjust($secondary, $lightness: 15%)};
  --ui-btn-hover-border-color: #{color.adjust($secondary, $lightness: 10%)};
  --ui-btn-focus-shadow-rgb: 58, 96, 154;
  --ui-btn-active-color: #fff;
  --ui-btn-active-bg: #{color.adjust($secondary, $lightness: 10%)};
  --ui-btn-active-border-color: #{color.adjust($secondary, $lightness: 5%)};
  --ui-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
  --ui-btn-disabled-color: #fff;
  --ui-btn-disabled-bg: #{$secondary};
  --ui-btn-disabled-border-color: #{$secondary};
}

.btn-outline-secondary {
  --ui-btn-color: var(--ui-body-color);
  --ui-btn-border-color: var(--ui-border-color);
  --ui-btn-hover-color: #fff;
  --ui-btn-hover-bg: #{color.adjust($secondary, $lightness: 15%)};
  --ui-btn-hover-border-color: #{color.adjust($secondary, $lightness: 10%)};
  --ui-btn-focus-shadow-rgb: 58, 96, 154;
  --ui-btn-active-color: #fff;
  --ui-btn-active-bg: #{color.adjust($secondary, $lightness: 10%)};
  --ui-btn-active-border-color: #{color.adjust($secondary, $lightness: 5%)};
  --ui-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
  --ui-btn-disabled-color: #{$secondary};
  --ui-btn-disabled-bg: transparent;
  --ui-btn-disabled-border-color: #{$secondary};
  --ui-gradient: none;
}

.visually-hidden {
  visibility: hidden;
}