//  Copyright (c) 2012-2013, Jungwacht Blauring Schweiz. This file is part of
//  hitobito and licensed under the Affero General Public License version 3
//  or later. See the COPYING file at the top-level directory or at
//  https://github.com/hitobito/hitobito.

/* Forms & Buttons */
// -------------------------
.btn-toolbar {
  margin-top: 0;
  margin-bottom: $v-space;
}

.btn {
  color: $blue-dark;

  &:hover,
  &:focus,
  &:active {
    color: $white;
    background: $purple;
    text-shadow: 0 -1px 1px false $purple-dark;
    border-color: $purple-dark;

    .icon,
    [class^="icon-"],
    [class*=" icon-"] {
      background-image: url("../../images/glyphicons-halflings-white.png");
    }

    .caret {
      border-top-color: $white;
    }
  }

  .icon,
  [class^="icon-"],
  [class*=" icon-"] {
    background-image: url("../../images/glyphicons-halflings-green.png");
  }

  .caret {
    border-top-color: $blue-dark;
  }

  &.btn-primary,
  &.btn-primary:hover,
  &.btn-warning,
  &.btn-warning:hover,
  &.btn-danger,
  &.btn-danger:hover,
  &.btn-success,
  &.btn-success:hover,
  &.btn-info,
  &.btn-info:hover,
  &.btn-inverse,
  &.btn-inverse:hover {
    color: $white;

    .icon,
    [class^="icon-"],
    [class*=" icon-"] {
      background-image: url("../../images/glyphicons-halflings-white.png");
    }
  }
}

.btn-primary {
  color: $white;
  background: $blue;
  border-color: $blue;
  text-shadow: 0 -1px 1px false $blue-dark;
}

.btn-group.open .btn.dropdown-toggle {
  background: $purple-dark;
  color: $white;
  border-color: $purple-dark;
}

.table-display-dropdown li {
  display: flex;
  padding-left: 5px;
}

.table-display-dropdown label {
  padding-left: 5px;
  padding-right: 10px;
}

.dropdown-menu .dropdown-menu-subtitle {
  padding: 0px 20px;
}

a.btn.disabled,
a.btn[disabled="disabled"] {
  pointer-events: none;
}

a.green {
  .icon,
  [class^="icon-"],
  [class*=" icon-"] {
    background-image: url("../../images/glyphicons-halflings-green.png");
  }
}

.form-horizontal .control-group {
  margin-bottom: 0;
}

.form-inline-search .control-group {
  display: inline-block;
}
@include responsive(mediaPhone) {
  .form-horizontal .btn-toolbar {
    margin-left: 180px;
  }
  .form-horizontal.form-noindent .btn-toolbar,
  .form-horizontal.tabbed .btn-toolbar.top {
    margin-left: 0;
  }
}

@-webkit-keyframes highlight {
  0% {
    background: $green;
  }
  100% {
    background: none;
  }
}
@keyframes highlight {
  0% {
    background: $green;
  }
  100% {
    background: none;
  }
}

fieldset {
  margin-bottom: 9px;

  $content-padding: 10px;
  padding-top: calc($content-padding / 2);
  padding-bottom: calc($content-padding / 2);
  margin-left: -$content-padding;
  margin-right: -$content-padding;
  padding-left: $content-padding;
  padding-right: $content-padding;

  @include responsive(mediaTablet) {
    $content-padding: 20px;
    padding-top: calc($content-padding / 2);
    padding-bottom: calc($content-padding / 2);
    margin-left: -$content-padding;
    margin-right: -$content-padding;
    padding-left: $content-padding;
    padding-right: $content-padding;
  }
}

.tab-content fieldset {
  // fieldset in tab must not draw outside its area
  // drawing outside would trigger scrollbars
  margin-left: 0;
  margin-right: 0;
  padding-left: 0;
  padding-right: 0;
}

.form-striped {
  fieldset:nth-of-type(2n) {
    background-color: $gray-lighter;
  }
}

legend {
  margin-bottom: 10px;
}

legend + * {
  -webkit-margin-top-collapse: separate;
  margin-top: 10px;
}

td {
  select,
  input[type="text"],
  input[type="number"] {
    margin-bottom: 0 !important;
  }
}

.form-subtitle {
  margin-left: 245px;
}
/*
select,
textarea,
input[type="text"],
input[type="password"],
input[type="datetime"],
input[type="datetime-local"],
input[type="date"],
input[type="month"],
input[type="time"],
input[type="week"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="color"],
.uneditable-input {
  display: inline-block;
  height: 30px;
  padding: 4px 6px;
  margin-bottom: 9px !important;
  font-size: 14px;
  line-height: 20px;
  color: $black;

  &::placeholder,
  &::-webkit-input-placeholder
  {
    color: $gray;
  }

  &:-ms-input-placeholder, &:-moz-placeholder {
    color: $gray;
  }


  &:focus {
    border-color: $focusColor;
    @include box-shadow(inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px $focusColor);
  }
}
*/
.input-append .add-on,
.input-prepend .add-on {
  height: 30px;
}

.input-loading {
  background-image: url("../../images/spinner.gif");
  background-size: 16px;
  background-position: right 5px center;
  background-repeat: no-repeat;
}

select {
  height: 30px;
  line-height: 30px;
}

.form-inline {
  select,
  textarea,
  input[type="text"],
  input[type="password"],
  input[type="datetime"],
  input[type="datetime-local"],
  input[type="date"],
  input[type="month"],
  input[type="time"],
  input[type="week"],
  input[type="number"],
  input[type="email"],
  input[type="url"],
  input[type="search"],
  input[type="tel"],
  input[type="color"],
  .uneditable-input {
    margin-bottom: 0px !important;
  }

  .control-group {
    display: inline-block;
  }
}

select.time {
  width: 80px;
  height: 30px;
  margin: 0 4px 0 4px;
}

select[class*="span"][multiple] {
  height: 120px;
}

label.checkbox,
label.radio {
  margin-right: 10px;
}

.label-columns .controls {
  label {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    margin-left: 0 !important;

    &:hover {
      background: $gray-lighter;
    }
  }
}

.label-columns .control-group + .control-group {
  margin-top: 2em;
}

// Browsers without CSS Grid support
.label-columns .controls {
  overflow: hidden; // clearfix

  label {
    float: left;
    width: 200px;
  }
}

// Browsers with CSS Grid support
@supports (display: grid) {
  .label-columns .controls {
    display: grid;
    grid-template-columns: repeat(auto-fit, 200px);

    label {
      width: auto;
    }
  }
}

.col-form-label {
  word-break: break-word;
}

.controls div.inline {
  display: inline-block;
  padding-top: 5px;
}

.controls p.inline {
  display: inline-block;
}

.controls .help-inline {
  margin-left: 10px;
  padding-bottom: 8px;
}

.controls .inline + .help-inline {
  padding-bottom: 0;
}

textarea {
  height: auto;
}

.fields-separation hr {
  margin: 7px 0 15px;
  border-top-color: $gray-light;
}

.control-group.required > label {
  transform: translate(5pt);
  &::after {
    content: "*";
    color: $orange;
    font-size: 9pt;
  }

  @media all and (max-width: $media-phone) {
    transform: none;
  }
}

.required-asterisk {
  &::before {
    content: "*";
    color: $orange;
    font-size: 9pt;
  }
}

.fields {
  .controls-row {
    border-bottom: 1px solid $gray-light;
    margin-bottom: 10px;
    padding-top: 10px;
    padding-bottom: 5px;
  }

  .help-inline {
    float: right;
  }
}

.form-horizontal .controls .help-block {
  margin: -8px 0 10px 0;
  font-size: 90%;
}

.controls > .text {
  line-height: 29px;
  padding-top: 4.5px;
  padding-bottom: 8px;
  vertical-align: middle;
  display: inline-block;
}

.remove_nested_fields {
  color: $red;
  margin: 0;
  padding: 0;
  i {
    margin: 5px;
  }
  &:hover {
    color: darken($red, 10%);
  }
}

.hp {
  position: absolute;
  left: -9999px;
  height: 30px;
}

td.issue,
td.revoke {
  width: 25px;
}
.disabled {
  opacity: 0.3;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=30)";
  filter: alpha(opacity=30);
}
.popover {
  max-width: 650px;
  width: 650px;
}
.popover-small {
  .popover {
    max-width: 350px;
    width: 350px;
  }
}

.filter_toggle,
.filter-toggle {
  cursor: pointer;
  cursor: hand;
}

#attachments:has(tr) {
  margin-bottom: 5px;
}

.custom-file {
  display: inline-block;
  position: relative;
  overflow: hidden;

  input[type="file"] {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 100%;
    min-height: 100%;
    font-size: 10px;
    text-align: right;
    filter: alpha(opacity=0);
    opacity: 0;
    outline: none;
    cursor: pointer;
    display: block;
  }
}

@media screen and (max-width: 480px) {
  .input-append-fix {
    .input-append {
      width: calc(100vw - 120px);
      input {
        width: 100%;
      }
    }
  }

  dt.muted.float-start.text-end {
    margin-right: 100%;
  }

  .bottom.align-with-form {
    margin-left: 0 !important;
  }
}

@media screen and (min-width: 480px) and (max-width: 768px) {
  .input-append-fix {
    .input-append {
      white-space: normal;
      width: 80vw;
      input {
        width: 60%;
      }
    }
  }

  dt.muted.float-start.text-end {
    margin-right: 100%;
  }

  .align-with-form {
    margin-left: 0 !important;
  }
}

@media screen and (min-width: 768px) and (max-width: 980px) {
  input.col-6,
  textarea.col-6,
  .uneditable-input.col-6,
  .col-6.input-span6 {
    width: calc(100vw - 550px);
  }

  .align-with-form {
    margin-left: 26% !important;
  }

  .labeled .align-with-form {
    margin-left: 0 !important;
  }
}

@media screen and (min-width: 981px) and (max-width: 1199px) {
  input.col-6,
  textarea.col-6,
  .uneditable-input.col-6,
  .col-6.input-span6 {
    width: 446px;
  }

  .align-with-form {
    margin-left: 26% !important;
  }

  .labeled .align-with-form {
    margin-left: 0 !important;
  }
}

@media screen and (min-width: 1200px) {
  input.col-6,
  textarea.col-6,
  .uneditable-input.col-6,
  .col-6.input-span6 {
    width: 570px;
  }

  #course-filter div.d-grid {
    grid-template-columns: 1fr 1fr 9fr;
  }

  .align-with-form {
    margin-left: 17% !important;
  }

  .labeled .align-with-form {
    margin-left: 0 !important;
  }
}

.input-span6[class*="span"] {
  float: none;
}

input.switcher {
  max-height: 0;
  max-width: 0;
  opacity: 0;

  & + label {
    display: inline-block;
    position: relative;
    box-shadow: inset 0 0 0px 1px #d5d5d5;
    text-indent: -5000px;
    height: 20px;
    width: 40px;
    top: 10px;
    border-radius: 10px;
  }

  // switcher active background
  & + label:before {
    content: "";
    position: absolute;
    display: block;
    height: 20px;
    width: 20px;
    top: 0;
    left: 0;
    border-radius: 10px;
    background: $green;
    -moz-transition: 0.25s ease-in-out;
    -webkit-transition: 0.25s ease-in-out;
    transition: 0.25s ease-in-out;
  }

  // switcher knob
  & + label:after {
    content: "";
    position: absolute;
    display: block;
    height: 20px;
    width: 20px;
    top: 0;
    left: 0px;
    border-radius: 10px;
    background: $white;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.2);
    -moz-transition: 0.25s ease-in-out;
    -webkit-transition: 0.25s ease-in-out;
    transition: 0.25s ease-in-out;
  }

  &:checked + label:before {
    width: 40px;
    background: $green;
  }

  &:checked + label:after {
    left: 20px;
    box-shadow: inset 0 0 0 1px $green, 0 1px 2px rgba(0, 0, 0, 0.2);
  }
}

.accordion-heading {
  .header {
    font-size: 1.2em;
    font-weight: 600;
  }

  a {
    color: $black;
  }

  a:hover {
    text-decoration: none;
  }
}

.accordion-body {
  legend {
    border-bottom: 0;
    font-size: 1.12em;
  }

  fieldset:last-child {
    margin-bottom: 0;
  }
  &.in.shown {
    overflow: visible;
  }
}
.chosen-drop {
  height: 0;
  overflow: hidden;
}
.shown .chosen-drop {
  height: auto;
}

#roles {
  legend + .layer {
    margin-top: 0;
  }

  .layer {
    + .layer {
      margin-top: 2em;
    }

    .control-group {
      margin-top: 0;
    }

    h4,
    h5 {
      cursor: pointer;
    }
  }
}

.has-clear {
  position: relative;
  input::-ms-clear {
    display: none;
  }

  [data-clear] {
    cursor: pointer;
    opacity: 0.3;
    pointer-events: auto;
    position: absolute;
    right: 5px;
    top: 30px;

    &:hover {
      opacity: 0.5;
    }
  }

  &.has-empty-value {
    [data-clear] {
      display: none;
    }
  }
}

.controls-row [class*="span"] + ul.typeahead + [class*="span"] {
  margin-left: 30px;
}

.chosen-container-multi .chosen-choices .search-field input {
  margin: 4px 0 !important;
}

.course-group-filter .control-group {
  width: 100%;

  .controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;
  }

  .select {
    max-width: 370px;
    flex-grow: 1;
    margin-right: 0.5rem;
  }

  .group-filter-quick-add-tags {
    margin: 0;
    flex-grow: 1;

    button {
      margin-right: 0.5rem;
      margin-bottom: 0.5rem;
    }
  }
}

.hide-last:last-child {
  display: none;
}

// New rules since Bootstrap 5 upgrade

.labeled .form-check {
  padding-top: calc(0.375rem + 1px);
}

label.required::after {
  content: "*";
  color: $orange;
}

.form-select {
  width: 250px;
  min-height: 31px !important; // Make selects as height as normal text fields (use min-height since multi item tom-selects can grow to multiple lines)
  display: initial;
}

.ts-wrapper.form-select.single .ts-control {
  // Fix alignment of selected item in single selects
  // Example: http://0.0.0.0:3000/en/groups/1/roles/new → "Role" select when group "Geschäftsstelle" is selected
  padding-top: calc((1.5em + 0.5rem + 2px - 1.3125rem - 4px) / 2 - 2px);
  padding-left: 1rem;
}
.ts-wrapper.form-select:not(.has-items) .ts-control {
  // Adjust padding to make sure the select field is always 31px height, also when no item is selected
  // Examples: http://0.0.0.0:3000/en/list_courses → "Organizer" field
  // and http://0.0.0.0:3000/en/groups/1/roles/new → "Role" select when group "Geschäftsstelle" is selected
  padding-top: calc((31px - 1.5 * 1rem) / 2 - 1px);
  padding-bottom: calc((31px - 1.5 * 1rem) / 2 - 1px);
}

.has-items .ts-control > input {
  // Fix vertical centering of text input within tom-select's wrapper
  // Example: http://0.0.0.0:3000/en/list_courses → "Organizer" field
  margin-top: calc(
    (1.5em + 0.5rem + 2px - 1.3125rem - 4px) / 2 * -1
  ) !important;
}

#custom_content_body,
#help_text_body,
#invoice_config_custom_content_attributes_body {
  min-height: 5em !important;
}

#invoice_items_fields div div,
#invoice_items_fields ~ div > p > div > div {
  display: flex;
}

.form-horizontal fieldset div .hide {
  display: none;
}

.form-horizontal .controls div .trix-content {
  margin-left: 245px;
}

#message_body {
  height: 250px;
}

.clear-both {
  clear: both;
}

.fields > div > .inline > input,
.fields > div > .inline > div > input {
  width: 90%;
}

.popover-body #role_label {
  height: 90px;
}
.hidden {
  display: none;
  visibility: hidden;
}

.width-60 {
  width: 60px;
}

.w-150-px {
  width: 150px;
}

.btn-link {
  border: 0;
}

.btn-link:hover,
.btn-link:focus,
.btn-link:active,
.btn-link:focus-visible {
  background-color: inherit;
  color: inherit;
  border: 0;
  box-shadow: inherit;
}

.edit_event_participation label {
  overflow-wrap: break-word;
}

fieldset > div > div.labeled {
  > div.controls,
  > p.inline {
    padding-top: calc(0.375rem + 1px);
  }
}

.mw-63ch {
  max-width: 63ch;
}

form[aria-busy=true] {
  .fa-spinner {
    display: block !important;
  }

  .fa-times {
    display: none;
  }
}
