.av {
  user-select: none;
  box-sizing: border-box;
  display: flex;
  max-width: 100%;

  &__container {
    overflow: auto;
  }

  &__pulse {
    width: 70%;
    height: 23px;
    display: block;
    position: relative;
    overflow: hidden;
    background: var(--b3-border-color);
    border-radius: var(--b3-border-radius);

    &:after {
      content: " ";
      border-radius: var(--b3-border-radius);
      position: absolute;
      z-index: 1;
      animation: 1s linear infinite keyframes-pulse;
      background: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, .4) 50%, transparent 100%);
      display: block;
      height: 100%;
      width: 100%;
    }
  }

  &__header {
    top: -43px;
    z-index: 2;

    .layout-tab-bar {
      background-color: transparent;
      font-size: 87.5%;

      .item {
        line-height: normal;
      }
    }
  }

  &__title {
    outline: none;

    &:empty::after {
      color: var(--b3-theme-on-surface);
      content: attr(data-tip);
    }
  }

  &__counter {
    position: absolute;
    bottom: 0;
    height: 30px;
    padding: 0 5px;
    background-color: var(--av-background);
  }

  &__gutters {
    @extend .protyle-gutters;
    position: fixed;
    top: 0;
    left: -44px;
    opacity: 0;
    display: flex;

    svg {
      height: 25px;
    }
  }

  &__mask {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    left: 0;
  }

  &__scroll {
    overflow: auto hidden;
    cursor: pointer;
  }

  &__row {
    display: flex;
    border-bottom: 1px solid var(--b3-theme-surface-lighter);
    position: relative;
    font-size: 87.5%;

    &.dragover__bottom {
      border-bottom-color: var(--b3-theme-primary-lighter);
    }

    &.dragover__top {
      box-shadow: 0 -3px 0 var(--b3-theme-primary-lighter), inset 0 2px 0 var(--b3-theme-primary-lighter) !important;
    }

    &:hover {
      [data-type="block-ref"],
      [data-type="block-more"] {
        display: block;
      }

      .av__gutters {
        opacity: 1;
      }
    }

    &--select {
      &:not(.av__row--header) .av__cell,
      &:not(.av__row--header) .av__firstcol {
        background-color: var(--b3-av-background-hl);
      }

      .av__firstcol svg {
        opacity: 1;
      }
    }

    &--header {
      z-index: 3;

      .av__cell {
        padding: 0;
        transition: background 20ms ease-in 0s;
        display: flex;
        overflow: inherit; // 保证列宽和顺序调整的拖拽点样式

        &:hover {
          background-color: var(--b3-av-hover);
        }
      }
    }

    &--header,
    &--footer {
      background-color: var(--av-background);
    }

    &--footer {
      display: flex;
      border-top: 1px solid var(--b3-theme-surface-lighter);
      color: var(--b3-theme-on-surface);
      position: relative;
      z-index: 2;

      &:hover .av__calc,
      &.av__row--show .av__calc {
        opacity: 1;
      }

      .av__colsticky {
        background-color: var(--av-background); // 保证盯住时无计算结果的列不被覆盖
      }

      .av__calc {
        display: flex;
        align-items: center;
        padding: 5px;
        border-right: 1px;
        flex-direction: row-reverse;
        box-sizing: border-box;
        opacity: 0;
        overflow: hidden;
        font-size: 75%;

        &.av__calc--ashow {
          opacity: 1;
        }

        svg {
          height: 8px;
          width: 8px;
          margin-left: 5px;
        }

        span {
          font-size: 116%;
          color: var(--b3-theme-on-background);
          margin-left: 5px;
        }

        &:hover {
          background-color: var(--b3-av-hover);
        }
      }
    }

    &--add {
      color: var(--b3-theme-on-surface);
      transition: background 20ms ease-in 0s;
      font-size: 87.5%;
      align-items: center;
      display: flex;

      .av__colsticky {
        align-items: center;

        svg {
          height: 14px;
          width: 14px;
          color: var(--b3-theme-on-surface);
          padding: 10px 10px 10px 5px;
          flex-shrink: 0;
        }
      }

      &:hover {
        background-color: var(--b3-av-hover);
      }
    }
  }

  &__cell {
    box-sizing: border-box;
    position: relative;
    padding: 5px;
    flex-shrink: 0;
    border-right: 1px solid var(--b3-theme-surface-lighter);
    overflow: hidden;
    //  display: flex; 不需要使用，否则 av__celltext 会占满单元格，导致链接列点击空白无法进行编辑

    [data-type="block-ref"],
    [data-type="block-more"] {
      display: none;
      position: absolute;
      right: 5px;
      font-size: 85%;
      top: 5.5px;
    }

    &.dragover__right {
      border-right-color: var(--b3-theme-primary-lighter);
    }

    &--select {
      background-color: var(--b3-theme-primary-lightest);
      box-shadow: 2px 2px 0 var(--b3-theme-primary-lighter) inset, -2px -2px 0px var(--b3-theme-primary-lighter) inset;
      border-radius: var(--b3-border-radius);
    }

    .block__icon {
      position: absolute;
      right: 5px;
      top: 5px;
    }

    &:hover .block__icon {
      opacity: 1;
      background-color: var(--b3-theme-background-light) !important;
    }

    .b3-chip {
      margin: 1px 2px;
      padding: 2px 6px;
    }
  }

  &__cellheader {
    padding: 5px;
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
  }

  &__cellheadericon {
    height: 1em;
    width: 1em;
    color: var(--b3-theme-on-surface);
    margin: 0 5px 0 0;
    flex-shrink: 0;
    line-height: 1em;
  }

  &__celltext {
    overflow: hidden;

    &--url {
      text-decoration: underline var(--b3-border-color);
    }

    & > .av__cellicon {
      margin: 0 5px;
      height: 10px;
      width: 10px;
    }
  }

  &__checkbox {
    color: var(--b3-theme-on-surface);
    height: 14px;
    width: 14px;
    float: left;
    padding: 4.5px 0;

    &:hover {
      color: var(--b3-theme-on-background);
    }
  }

  &__firstcol {
    svg {
      @extend .av__checkbox;
      opacity: 0;
      padding: 9.5px 5px;
    }

    &:hover svg {
      opacity: 1;
    }
  }

  &__colsticky {
    position: sticky;
    left: 0;
    z-index: 1;
    display: flex;

    &.av__firstcol,
    & > div {
      background-color: var(--av-background);
    }
  }

  &__widthdrag {
    position: absolute;
    cursor: col-resize;
    width: 5px;
    height: 100%;
    right: -2.5px;
    transition: background 20ms ease-in 0s;
    z-index: 1;

    &:hover {
      background-color: var(--b3-theme-primary);
    }
  }

  &__panel {
    position: relative;

    .b3-menu {
      min-width: 200px;

      &__item .b3-chip {
        max-width: 196px;
        margin: 3px 0;
        padding-top: 4px;
        padding-bottom: 4px;
        float: left;

        .icon {
          width: 12px;
          flex-shrink: 0;
          margin-right: 6px;
          margin-left: -5px;
        }
      }

      .b3-chips {
        padding: 0;

        input {
          outline: none;
          border: 0;
          background-color: var(--b3-menu-background);
          flex: 1;
          height: 30px;
          color: var(--b3-theme-on-background);
        }
      }

      .block__icon {
        line-height: 20px;
        padding: 0 4px;
        font-size: 12px;
        align-self: center;
        opacity: 1;
      }

      &__label {
        overflow: hidden;
      }

      &__item {
        transition: margin .2s cubic-bezier(0, 0, .2, 1) 0ms;
      }

      &__item:hover .b3-menu__action {
        opacity: 1;
      }

      &__item[data-type="nobg"] .b3-menu__label {
        cursor: auto;
      }

      &__item:not([data-type="nobg"]):hover {
        background-color: var(--b3-list-hover);
      }
    }
  }
}

.protyle-wysiwyg--select,
.protyle-wysiwyg--hl {
  .av__row--header,
  .av__row--footer,
  .av__row--footer .av__colsticky,
  .av__row--select .av__cell,
  .av__colsticky.av__firstcol,
  .av__colsticky > div,
  .av__counter {
    background-color: var(--b3-av-background-hl);
  }
}

.dragover__top,
.dragover__bottom {
  .av__colsticky {
    z-index: 0;

    & > div {
      background-color: transparent;
    }
  }
}

.dragover__bottom + .av__row,
.av__row:has(+ .dragover__top) {
  .av__colsticky > div {
    background-color: transparent;
  }
}

img.av__cellassetimg {
  max-height: 20px;
  border-radius: var(--b3-border-radius);
  margin: 1px 2px;
  max-width: none;
  vertical-align: top;
}

html[data-theme-mode="dark"] .av__panel .b3-menu__item {
  mix-blend-mode: lighten;
}

html[data-theme-mode="light"] .av__panel .b3-menu__item {
  mix-blend-mode: darken;
}
