/*
 * kCube UI enhancements — filter block layout and a select2 skin that matches
 * Redmine's own form controls. Theme-neutral: colours come from the
 * --kc-* variables when the kcube theme is active, with plain fallbacks.
 */

/* ---- filter block layout --------------------------------------------- */

/* "Add filter" sits top-right, on the same row as the first filter */
#filters > div, #filters > div[style] {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 4px 16px;
}

#filters-table {
  float: none;
  flex: 1 1 520px;
  min-inline-size: 0;
}

.add-filter {
  float: none;
  inline-size: auto;
  flex: 0 0 auto;
  margin-inline-start: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-block-start: 8px;
  padding: 0;
}

#filters-table .filter {
  align-items: flex-start;
  flex-wrap: nowrap;
  gap: 6px 10px;
  margin-block: 8px 0;
}

#filters-table .filter .field {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 150px;
  inline-size: 150px;
  min-block-size: 28px;
}

#filters-table .filter .field label { cursor: pointer; }

#filters-table .filter .operator { flex: 0 0 auto; }

#filters-table .filter .operator select {
  inline-size: 120px;
  block-size: 28px;
}

#filters-table .filter .values {
  flex: 1 1 auto;
  min-inline-size: 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* each values <span> lays its select, the +/- toggle and any extra control out in a row;
   the "include closed projects" checkbox drops to its own line under the dropdown */
#filters-table .filter .values > span {
  display: flex !important;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  flex: 1 1 auto;
  min-inline-size: 0;
}

#filters-table .filter .values > span[style*="display: none"],
#filters-table .filter .values > span[style*="display:none"] {
  display: none !important;
}

/* select2 writes width:100% inline; the row decides the width instead */
#filters-table .filter .values .select2-container {
  inline-size: auto !important;
  flex: 1 1 180px;
  min-inline-size: 180px;
  max-inline-size: 340px;
}

#filters-table .filter .values .select2-container:has(.select2-selection--multiple) {
  max-inline-size: 520px;
}

#filters-table .filter .values input.value { block-size: 28px; }

.toggle-multiselect {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 3px;
  margin-inline-end: 0;
}

.toggle-multiselect:hover { background: var(--kc-blue-tint, #eef3f8); }

.kcube-include-closed {
  flex-basis: 100%;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--kc-ink-soft, #495057);
  white-space: nowrap;
  cursor: pointer;
  margin-block-start: 2px;
}

.kcube-include-closed input { margin: 0; }

/* ---- select2 skin ------------------------------------------------------- */

body .select2-container--default .select2-selection--single,
body .select2-container--default .select2-selection--multiple {
  border: 1px solid var(--kc-input-border, #c9d1da);
  border-radius: 3px;
  background: #fff;
  min-block-size: 28px;
  box-sizing: border-box;
}

body .select2-container--default .select2-selection--single {
  block-size: 28px;
}

body .select2-container--default .select2-selection--single .select2-selection__rendered {
  line-height: 26px;
  padding-inline: 8px 26px;
  color: inherit;
  font-size: 0.875rem;
}

body .select2-container--default .select2-selection--single .select2-selection__arrow {
  block-size: 26px;
  inline-size: 24px;
}

body .select2-container--default .select2-selection--single .select2-selection__arrow b {
  border-color: #6b7480 transparent transparent transparent;
}

body .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
  border-color: transparent transparent #6b7480 transparent;
}

body .select2-container--default .select2-selection--multiple {
  padding: 1px 4px;
}

body .select2-container--default .select2-selection--multiple .select2-selection__rendered {
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}

body .select2-container--default .select2-selection--multiple .select2-selection__choice {
  margin: 0;
  padding: 1px 6px 1px 4px;
  border: 1px solid var(--kc-blue-light, #9fc3e2);
  background: var(--kc-blue-tint, #e6f4fb);
  border-radius: 3px;
  font-size: 0.8125rem;
  line-height: 18px;
}

body .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
  margin-inline-end: 4px;
  color: #6b7480;
}

body .select2-container--default .select2-search--inline .select2-search__field {
  margin: 0;
  block-size: 22px;
  font-size: 0.875rem;
}

body .select2-container--default.select2-container--focus .select2-selection--multiple,
body .select2-container--default.select2-container--open .select2-selection--single,
body .select2-container--default.select2-container--open .select2-selection--multiple {
  border-color: var(--kc-blue-light, #5b9bd5);
  box-shadow: 0 0 0 2px var(--kc-blue-tint, #e6f4fb);
}

body .select2-container--default .select2-selection__placeholder {
  color: #8a94a3;
}

body .select2-dropdown {
  border: 1px solid var(--kc-input-border, #c9d1da);
  border-radius: 3px;
  box-shadow: 0 6px 18px rgba(22, 28, 36, 0.12);
  font-size: 0.875rem;
}

body .select2-container--default .select2-search--dropdown .select2-search__field {
  border: 1px solid var(--kc-input-border, #c9d1da);
  border-radius: 3px;
  padding: 4px 8px;
  block-size: 28px;
  box-sizing: border-box;
}

body .select2-container--default .select2-results__group {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6b7480;
  padding: 8px 8px 4px;
}

body .select2-container--default .select2-results__option {
  padding: 5px 10px;
}

body .select2-container--default .select2-results__option--highlighted[aria-selected] {
  background: var(--kc-blue, #2f6fb3);
  color: #fff;
}

body .select2-container--default .select2-results__option[aria-selected="true"] {
  background: var(--kc-blue-tint, #e6f4fb);
  color: inherit;
}

body .select2-container--default .select2-results__option--highlighted[aria-selected="true"] {
  background: var(--kc-blue, #2f6fb3);
  color: #fff;
}

body .select2-container .select2-results > .select2-results__options {
  max-block-size: 320px;
}
