@use 'variables' as *;

.table {
  width: 100%;
  max-width: 100%;
  border-spacing: 0;
  border-collapse: collapse;

  th,
  td {
    padding: 8px;
    line-height: 18px;
    vertical-align: top;
    border-bottom: 1px solid var(--color-border-primary);
    text-align: start;
    background: var(--color-bg-primary);

    .critical {
      font-weight: 700;
      color: var(--color-text-warning);
    }

    .unsupported {
      color: var(--color-text-error);
    }
  }

  .align-end {
    text-align: end;
  }

  .valign-middle {
    vertical-align: middle;
  }

  .avatar-column {
    width: 24px;

    .avatar {
      border-radius: 8px;
      border: 1px solid var(--color-border-primary);
      background: var(--color-background-secondary);
    }
  }

  & > thead > tr > th {
    vertical-align: bottom;
    font-weight: 500;
  }

  & > tbody > tr > th {
    font-weight: 500;
  }

  & > tbody > tr:nth-child(odd) > td,
  & > tbody > tr:nth-child(odd) > th {
    background: var(--color-bg-primary);
  }

  & > tbody > tr:last-child > td,
  & > tbody > tr:last-child > th {
    border-bottom: 0;
  }

  a {
    color: var(--color-text-secondary);
    text-decoration: none;

    &:hover {
      color: var(--color-text-brand);
    }
  }

  strong {
    font-weight: 500;

    @each $lang in $cjk-langs {
      &:lang(#{$lang}) {
        font-weight: 700;
      }
    }
  }

  &.inline-table {
    & > tbody > tr:nth-child(odd) {
      & > td,
      & > th {
        background: transparent;
      }
    }

    & > tbody > tr:first-child {
      & > td,
      & > th {
        border-top: 0;
      }
    }
  }

  &.horizontal-table {
    border-collapse: collapse;
    border-style: hidden;

    & > tbody > tr > th,
    & > tbody > tr > td {
      padding: 11px 10px;
      background: transparent;
      border: 1px solid var(--color-border-primary);
      color: var(--color-text-primary);
    }

    & > tbody > tr > th {
      color: var(--color-text-secondary);
      font-weight: 600;
    }
  }

  &.mini-table {
    border-top: 1px solid var(--color-border-primary);
    width: 50%;

    & > tbody > tr > th,
    & > tbody > tr > td {
      padding: 12px 0;
    }

    & > tbody > tr > th {
      color: var(--color-text-secondary);
      font-weight: 400;
    }

    & > tbody > tr > td {
      color: var(--color-text-primary);
      font-weight: 600;
    }

    .status-badge {
      padding: 0;
    }
  }

  &.batch-table {
    & > thead > tr > th {
      background: var(--color-bg-primary);
      border-top: 1px solid var(--color-border-primary);
      border-bottom: 1px solid var(--color-border-primary);

      &:first-child {
        border-radius: 4px 0 0;
        border-inline-start: 1px solid var(--color-border-primary);
      }

      &:last-child {
        border-radius: 0 4px 0 0;
        border-inline-end: 1px solid var(--color-border-primary);
      }
    }
  }

  &--invites tbody td {
    vertical-align: middle;
  }
}

.table-wrapper {
  overflow: auto;
  margin-bottom: 20px;
}

samp {
  font-family: var(--font-monospace);
}

button.table-action-link {
  background: transparent;
  border: 0;
  font: inherit;
}

button.table-action-link,
a.table-action-link {
  text-decoration: none;
  display: inline-block;
  margin-inline-end: 5px;
  padding: 0 10px;
  color: var(--color-text-secondary);
  font-weight: 500;
  white-space: nowrap;

  &:hover {
    color: var(--color-text-brand);
  }

  &:first-child {
    padding-inline-start: 0;
  }
}

.table-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  aspect-ratio: 1;

  &.table-icon-link--danger {
    border-radius: 8px;
    border: 1px solid var(--color-border-primary);
    color: var(--color-text-error);
  }
}

.batch-table {
  &--no-toolbar {
    .batch-table__toolbar {
      position: static;
      height: 4px;
      border-bottom: none;
    }
  }

  &__toolbar,
  &__row {
    display: flex;

    &__select {
      box-sizing: border-box;
      padding: 8px 16px;
      cursor: pointer;
      min-height: 100%;

      input {
        margin-top: 8px;
      }

      &--aligned {
        display: flex;
        align-items: center;

        input {
          margin-top: 0;
        }
      }
    }

    &__actions,
    &__content {
      padding: 8px 0;
      padding-inline-end: 16px;
      flex: 1 1 auto;
    }
  }

  &__toolbar {
    position: sticky;
    top: 0;
    z-index: 200;
    border: 1px solid var(--color-border-primary);
    background: var(--color-bg-primary);
    border-radius: 4px 4px 0 0;
    height: 47px;
    align-items: center;

    &__actions {
      text-align: end;
      padding-inline-end: 16px - 5px;

      .table-action-link {
        padding: 0;
      }
    }
  }

  &__select-all {
    background: var(--color-bg-primary);
    height: 47px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--color-border-primary);
    border-top: 0;
    color: var(--color-text-primary);
    display: none;

    &.active {
      display: flex;
    }

    .selected,
    .not-selected {
      display: none;

      &.active {
        display: block;
      }
    }

    strong {
      font-weight: 700;
    }

    span {
      padding: 8px;
      display: inline-block;
    }

    button {
      background: transparent;
      border: 0;
      font: inherit;
      color: var(--color-text-brand);
      border-radius: 4px;
      font-weight: 700;
      padding: 8px;

      &:hover,
      &:focus,
      &:active {
        background: var(--color-bg-secondary);
      }
    }
  }

  &__form {
    padding: 16px;
    border: 1px solid var(--color-border-primary);
    border-top: 0;
    background: var(--color-bg-primary);

    .fields-row {
      padding-top: 0;
      margin-bottom: 0;
    }
  }

  &__row {
    border: 1px solid var(--color-border-primary);
    border-top: 0;
    background: var(--color-bg-primary);

    @media screen and (max-width: $no-gap-breakpoint) {
      .optional &:first-child {
        border-top: 1px solid var(--color-border-primary);
      }
    }

    &:last-child {
      border-radius: 0 0 4px 4px;
    }

    &__content {
      padding-top: 12px;
      padding-bottom: 16px;
      overflow: hidden;

      &--unpadded {
        padding: 0;
      }

      &--padded {
        padding: 12px 16px 16px;
      }

      &--with-image {
        display: flex;
        align-items: center;
      }

      &__image {
        flex: 0 0 auto;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-inline-end: 10px;

        .emojione {
          width: 32px;
          height: 32px;
        }
      }

      &__text {
        flex: 1 1 auto;
      }

      &__quote {
        padding: 12px;
        padding-top: 0;
      }

      &__extra {
        flex: 0 0 auto;
        text-align: end;
        color: var(--color-text-secondary);
        font-weight: 500;
      }
    }

    .directory__tag {
      margin: 0;
      width: 100%;

      a {
        background: transparent;
        border-radius: 0;
      }
    }
  }

  &.optional .batch-table__toolbar,
  &.optional .batch-table__row__select {
    @media screen and (max-width: $no-gap-breakpoint) {
      display: none;
    }
  }

  // Reset the status card to not have borders, background or padding when
  // inline in the table of statuses
  .batch-table__row__content > .status__card {
    border: none;
    background: none;
    padding: 0;
  }

  @media screen and (width <= 870px) {
    .accounts-table tbody td.optional {
      display: none;
    }
  }
}

.one-liner {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
