tag-manager {
  display: flex;
  align-items: center;
  max-width: 100%;
  flex-wrap: wrap;
  margin-top: -4px;
  font-weight: normal;

  label {
    margin: 0;
  }

  ul, li {
    margin: 0;
  }

  .tag-header {
    display: block;
    position: relative;
    text-align: center;
    padding: 5px 12px;
    border: 1px solid #5688E3;
    background-image: linear-gradient(0deg, #F3F3F3 0%, #FFFFFF 100%);
    border-radius: 3px;
    color: inherit;

    &::after {
      border-bottom: 2px solid #F3F3F3;
      position: absolute;
      z-index: 3000;
      bottom: -2px;
      left: 0;
      right: 0;
    }

    .fa {
      color: #719CEA;
    }
  }

  [type=search] {
    border: 1px solid #D0D0D0;
    border-radius: 3px;
  }

  header, footer {
    position: relative;
    margin-top: 4px;
    outline: none;

    .native-focus-within &:not(:focus-within) section {
      display: none;
    }
    .polyfilled-focus-within &:not(.focus-within) section {
      display: none;
    }
  }

  header {
    z-index: 1;

    @mixin open {
      filter: drop-shadow(0 2px 8px rgba(0,0,0,0.15));

      > .tag-header {
        border-radius: 3px 3px 0 0;

        &::after {
          content: "";
        }
      }
    }

    .native-focus-within &:focus-within {
      @include open;
    }
    .polyfilled-focus-within &.focus-within {
      @include open;
    }
  }

  section {
    position: absolute;
    top: 100%;
    left: 0;
    width: 320px;
    padding: 10px 15px;
    z-index: 2000;

    &.align-right {
      left: initial;
      right: 0;

      > .header-dropdown {
        border-radius: 3px 0 3px 3px;
      }
    }

    .tag-list {
      margin-right: -8px;
      flex-wrap: wrap;
    }

    .tag-item {
      margin-top: 10px;
    }
  }

  .header-dropdown {
    border: 1px solid #5688E3;
    border-radius: 0 3px 3px 3px;
    background: #F3F3F3;
  }

  .tag-list {
    display: flex;
    flex-shrink: 1;
    flex-wrap: wrap;
  }

  .tag-item {
    display: flex;
    padding: 1px 8px;
    position: relative;
    font-size: 12px;
    margin-right: 5px;
    border: 1px solid #5688E3;
    border-radius: 1px;
    color: #5688E3;
    user-select: none;
    cursor: default;
    margin-top: 4px;
    max-width: 100%;

    span {
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    &-outside {
      &:not(:first-child):first-of-type {
        margin-left: 5px;
      }

      &:not(:last-child):last-of-type {
        margin-right: 5px;
      }
    }

    &.highlighted {
      border: 1px solid #17AC00;
      color: #17AC00;
    }

    &.active {
      background: #719CEA;
      color: white !important;

      &.highlighted {
        background: #AED982;
      }
    }

    &:last-child {
      margin-right: 0;
    }

    &:not(:hover) .i-close {
      opacity: 0;
    }

    .i-close {
      width: 18px;
      height: 18px;
      display: flex;
      justify-content: center;
      align-items: center;
      border: 2px solid;
      border-radius: 50%;
      position: absolute;
      right: -4px;
      top: -4px;
      color: #5688E3;
      background: white;
      text-align: center;
      transform: scale(.5);
      transform-origin: right top;
      transition: all .2s;

      &:hover {
        color: red !important;
      }
    }

    .fa {
      font-size: 14px;
    }
  }

  .tag-footer {
    display: block;
    font-size: 14px;
    width: 36px;
    text-align: center;
    color: #60A2E0;
    border: 1px dashed #5688E3;
    border-radius: 1px;
  }

  .footer-dropdown {
    background: white;
    border: 1px solid #DBDBDB;
    box-shadow: 0 2px 8px 0 rgba(0,0,0, 0.15);
    border-radius: 3px;
    transform: translateY(2px);
  }

  form {
    display: flex;

    input {
      flex: 1;
      margin-right: 10px;
    }
  }

  @supports (width: var(--wtf-width)) {
    &.new-style {
      .tag-item, .tag-footer {
        border-left: 0;
        margin-left: 8px;
        --wtf-width: 16px; /* FIXME: 尝试找到一种方法让其宽度等于其高度 */

        &::before {
          content: "";
          display: block;
          position: absolute;
          width: var(--wtf-width);
          height: var(--wtf-width);
          top: 0;
          bottom: 0;
          left: 0;
          margin: auto;
          transform: translateX(-50%) scaleX(.75) rotate(-135deg);
          background: inherit;
          border-right: inherit;
          border-top: inherit;
        }
      }

      .tag-item {
        color: #00BBDD;
        border-color: #00BBDD;

        &:not(:first-child):first-of-type {
          margin-left: 13px;
        }

        &::before {
          border-radius: 2px;
        }

        &::after {
          content: "";
          display: block;
          position: absolute;
          width: 6px;
          height: 6px;
          left: -2px;
          top: 0;
          bottom: 0;
          margin: auto;
          background: white;
          border-radius: 50%;
        }

        &:not(.active)::after {
          border: 1px solid;
        }

        &.active {
          background: #00BBDD;
        }

        &.highlighted {
          background: #F8CA1C;
          border-color: #F8CA1C;
        }

        .i-close {
          color: #00BBDD;
        }
      }

      .tag-footer {
        position: relative;
        padding-right: 3px;
        width: 16px;
        border-color: #0085C5;
      }
    }

    &.group-style {
      .i-close {
        right: -2px;
        top: -1px;
        color: #678EF7;
      }

      .tag-item, .tag-footer {
        border-radius: 1000px;
      }

      .tag-footer {
        width: 24px;
        border-color: #5688E3;
        color: #3A83D0;
      }

      .tag-item {
        &.active {
          border-color: #678EF7;
          background: #678EF7;
        }

        &.highlighted {
          border-color: #F8CA1C;
          background: #F8CA1C;
        }
      }
    }

    &.new-style, &.group-style {
      .tag-footer {
        height: 15px;
        --wtf-width: 9px;

        .fa {
          top: -5px;
          position: relative;
          font-size: 12px;
          transform: scale(.75);
        }
      }
    }
  }
}
