:root {
  // Colors
  --ss-primary-color: #5897fb;
  --ss-bg-color: #ffffff;
  --ss-font-color: #4d4d4d;
  --ss-font-placeholder-color: #8d8d8d;
  --ss-disabled-color: #dcdee2;
  --ss-border-color: #dcdee2;
  --ss-highlight-color: #fffb8c;
  --ss-success-color: #00b755;
  --ss-error-color: #dc3545;
  --ss-focus-color: #5897fb;

  // Heights
  --ss-main-height: 30px;
  --ss-content-height: 300px;

  // Spacing
  --ss-spacing-l: 7px;
  --ss-spacing-m: 5px;
  --ss-spacing-s: 3px;

  // Misc
  --ss-animation-timing: 0.2s;
  --ss-border-radius: 4px;
}

// Animation keyframes
@keyframes ss-valueIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes ss-valueOut {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0);
    opacity: 0;
  }
}

// Misc classes
.ss-hide {
  display: none !important;
}

// Main container
.ss-main {
  display: flex;
  flex-direction: row;
  position: relative;
  user-select: none;
  color: var(--ss-font-color);
  min-height: var(--ss-main-height);
  width: 100%;
  padding: var(--ss-spacing-s);
  cursor: pointer;
  border: 1px solid var(--ss-border-color);
  border-radius: var(--ss-border-radius);
  background-color: var(--ss-bg-color);
  outline: 0;
  box-sizing: border-box;
  transition: background-color var(--ss-animation-timing);
  overflow: hidden;

  &:focus {
    box-shadow: 0 0 5px var(--ss-focus-color);
  }

  &.ss-disabled {
    background-color: var(--ss-disabled-color);
    cursor: not-allowed;

    .ss-values {
      .ss-disabled {
        color: var(--ss-font-color);
      }

      .ss-value {
        .ss-value-delete {
          cursor: not-allowed;
        }
      }
    }
  }

  &.ss-open-above {
    border-top-left-radius: 0px;
    border-top-right-radius: 0px;
  }
  &.ss-open-below {
    border-bottom-left-radius: 0px;
    border-bottom-right-radius: 0px;
  }

  .ss-values {
    display: inline-flex;
    flex-wrap: wrap;
    gap: var(--ss-spacing-m);
    flex: 1 1 100%;

    .ss-placeholder {
      display: flex;
      padding: var(--ss-spacing-s) var(--ss-spacing-m) var(--ss-spacing-s) var(--ss-spacing-m);
      margin: auto 0px auto 0px;
      line-height: 1em;
      align-items: center;
      width: 100%;
      color: var(--ss-font-placeholder-color);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    // Max is used to display max number of values
    .ss-max {
      display: flex;
      user-select: none;
      align-items: center;
      width: fit-content;
      font-size: 12px;
      color: var(--ss-bg-color);
      line-height: 1;
      padding: var(--ss-spacing-s) var(--ss-spacing-m);
      background-color: var(--ss-primary-color);
      border-radius: var(--ss-border-radius);
    }

    // Used for single select selected value
    .ss-single {
      display: flex;
      margin: auto 0px auto var(--ss-spacing-s);
    }

    // Used for the selected values
    .ss-value {
      display: flex;
      user-select: none;
      align-items: center;
      width: fit-content;
      background-color: var(--ss-primary-color);
      border-radius: var(--ss-border-radius);
      animation-name: ss-valueIn;
      animation-duration: var(--ss-animation-timing);
      animation-timing-function: ease-out;
      animation-fill-mode: both;

      &.ss-value-out {
        animation-name: ss-valueOut;
        animation-duration: var(--ss-animation-timing);
        animation-timing-function: ease-out;
      }

      .ss-value-text {
        font-size: 12px;
        color: var(--ss-bg-color);
        line-height: 1;
        padding: var(--ss-spacing-s) var(--ss-spacing-m);
      }

      .ss-value-delete {
        display: flex;
        align-items: center;
        height: var(--ss-spacing-l);
        width: var(--ss-spacing-l);
        padding: var(--ss-spacing-s) var(--ss-spacing-m);
        cursor: pointer;
        border-left: solid 1px var(--ss-bg-color);
        box-sizing: content-box;

        svg {
          height: var(--ss-spacing-l);
          width: var(--ss-spacing-l);

          path {
            fill: none;
            stroke: var(--ss-bg-color);
            stroke-width: 18;
            stroke-linecap: round;
            stroke-linejoin: round;
          }
        }
      }
    }
  }

  .ss-deselect {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: fit-content;
    height: auto;
    padding: 0 var(--ss-spacing-m) 0 var(--ss-spacing-m);

    svg {
      width: 8px;
      height: 8px;

      path {
        fill: none;
        stroke: var(--ss-font-color);
        stroke-width: 20;
        stroke-linecap: round;
        stroke-linejoin: round;
      }
    }
  }

  .ss-arrow {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    width: 12px;
    height: 12px;
    margin: auto var(--ss-spacing-m) auto var(--ss-spacing-m);

    path {
      fill: none;
      stroke: var(--ss-font-color);
      stroke-width: 18;
      stroke-linecap: round;
      stroke-linejoin: round;
      transition-timing-function: ease-out;
      transition: var(--ss-animation-timing);
    }
  }
}

// Content container
.ss-content {
  position: absolute; // default position
  display: flex;
  height: auto;
  flex-direction: column;
  width: auto;
  max-height: var(--ss-content-height);
  box-sizing: border-box;
  border: solid 1px var(--ss-border-color);
  background-color: var(--ss-bg-color);
  transition:
    transform var(--ss-animation-timing),
    opacity var(--ss-animation-timing);
  opacity: 0;
  transform: scaleY(0);
  transform-origin: center top;
  overflow: hidden;
  z-index: 10000;

  &.ss-relative {
    position: relative;
    height: 100%;
  }

  &.ss-fixed {
    position: fixed;
  }

  &.ss-open-above {
    flex-direction: column-reverse;
    opacity: 1;
    transform: scaleY(1);
    transform-origin: center bottom;
    border-top-left-radius: var(--ss-border-radius);
    border-top-right-radius: var(--ss-border-radius);
  }

  &.ss-open-below {
    opacity: 1;
    transform: scaleY(1);
    transform-origin: center top;
    border-bottom-left-radius: var(--ss-border-radius);
    border-bottom-right-radius: var(--ss-border-radius);
  }

  .ss-search {
    flex: 0 1 auto;
    display: flex;
    flex-direction: row;
    padding: var(--ss-spacing-l) var(--ss-spacing-l) var(--ss-spacing-m) var(--ss-spacing-l);

    input {
      display: inline-flex;
      font-size: inherit;
      line-height: inherit;
      flex: 1 1 auto;
      width: 100%;
      min-width: 0px;
      padding: var(--ss-spacing-m) var(--ss-spacing-l);
      margin: 0;
      border: 1px solid var(--ss-border-color);
      border-radius: var(--ss-border-radius);
      background-color: var(--ss-bg-color);
      outline: 0;
      text-align: left;
      box-sizing: border-box;

      &::placeholder {
        color: var(--ss-font-placeholder-color);
        vertical-align: middle;
      }

      &:focus {
        box-shadow: 0 0 5px var(--ss-focus-color);
      }
    }

    .ss-addable {
      display: inline-flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      flex: 0 0 auto;
      height: auto;
      margin: 0 0 0 var(--ss-spacing-m);
      border: 1px solid var(--ss-border-color);
      border-radius: var(--ss-border-radius);

      svg {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        flex: 0 1 auto;
        width: 12px;
        height: 12px;
        margin: auto var(--ss-spacing-m) auto var(--ss-spacing-m);

        path {
          fill: none;
          stroke: var(--ss-font-color);
          stroke-width: 18;
          stroke-linecap: round;
          stroke-linejoin: round;
        }
      }
    }
  }

  .ss-list {
    flex: 1 1 auto;
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;

    .ss-error {
      color: var(--ss-error-color);
      padding: var(--ss-spacing-l);
    }

    .ss-searching {
      color: var(--ss-font-color);
      padding: var(--ss-spacing-l);
    }

    .ss-optgroup {
      // If optgroup has close, hide all options
      &.ss-close {
        .ss-option {
          display: none !important;
        }
      }

      .ss-optgroup-label {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: var(--ss-spacing-m) var(--ss-spacing-l) var(--ss-spacing-m) var(--ss-spacing-l);

        .ss-optgroup-label-text {
          flex: 1 1 auto;
          font-weight: bold;
          color: var(--ss-font-color);
        }

        // If optgroup has arrow, make label clickable
        &:has(.ss-arrow) {
          cursor: pointer;
        }

        .ss-optgroup-actions {
          flex: 0 1 auto;
          display: flex;
          flex-direction: row;
          align-items: center;
          justify-content: center;
          gap: var(--ss-spacing-m);

          .ss-selectall {
            flex: 0 0 auto;
            display: flex;
            flex-direction: row;
            cursor: pointer;

            &:hover {
              opacity: 0.5;
            }

            &.ss-selected {
              svg {
                path {
                  stroke: var(--ss-error-color);
                }
              }
            }

            span {
              flex: 0 1 auto;
              display: flex;
              align-items: center;
              justify-content: center;
              font-size: calc(100% * 0.6);
              text-align: center;
              padding: 0 var(--ss-spacing-s) 0 0;
            }

            svg {
              flex: 0 1 auto;
              width: 13px;
              height: 13px;

              path {
                fill: none;
                stroke: var(--ss-success-color);
                stroke-linecap: round;
                stroke-linejoin: round;
              }

              &:first-child {
                stroke-width: 5;
              }
              &:last-child {
                stroke-width: 11;
              }
            }
          }

          .ss-closable {
            flex: 0 1 auto;
            display: flex;
            flex-direction: row;
            cursor: pointer;

            .ss-arrow {
              flex: 1 1 auto;
              width: 10px;
              height: 10px;

              path {
                fill: none;
                stroke: var(--ss-font-color);
                stroke-width: 18;
                stroke-linecap: round;
                stroke-linejoin: round;
                transition-timing-function: ease-out;
                transition: var(--ss-animation-timing);
              }
            }
          }
        }
      }

      .ss-option {
        padding: var(--ss-spacing-s) var(--ss-spacing-s) var(--ss-spacing-s) calc(var(--ss-spacing-l) * 3);
      }
    }

    .ss-option {
      display: block; // Important for text with mark element highlight
      padding: var(--ss-spacing-m) var(--ss-spacing-l) var(--ss-spacing-m) var(--ss-spacing-l);
      white-space: normal;
      color: var(--ss-font-color);
      cursor: pointer;
      user-select: none;

      &:hover {
        color: var(--ss-bg-color);
        background-color: var(--ss-primary-color);
      }

      &.ss-highlighted,
      &:not(.ss-disabled).ss-selected {
        color: var(--ss-bg-color);
        background-color: var(--ss-primary-color);
      }

      &.ss-disabled {
        cursor: not-allowed;
        background-color: var(--ss-disabled-color);

        &:hover {
          color: var(--ss-font-color);
        }
      }

      // Sub div wrapper for highlighting text
      .ss-search-highlight {
        display: inline-block;
        background-color: var(--ss-highlight-color);
      }
    }
  }
}
