/* Scroll container for a table. It draws the rounded, bordered card the table sits inside,
   because a collapsed-border table cannot clip its own corners. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  background-color: var(--color-bg-primary);
  border: 1px solid var(--color-border-secondary);
  border-radius: var(--border-radius-md);

  /* Stops clipping once the table fits, so a popover opened from a cell (e.g. a row action
     menu) can escape the container. Below the breakpoint the table still scrolls. */
  &.allow-overflow {
    @media (min-width: 1100px) {
      overflow: visible;
    }
  }
}

.table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--color-bg-primary);

  th, td {
    border: none;
    border-bottom: 1px solid var(--color-border-secondary);
    padding: 16px 8px;
    text-align: left;
    vertical-align: middle;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-text-sm);
    color: var(--color-text-secondary);

    &.center {
      text-align: center;
    }
  }

  th {
    height: 40px;
    padding: 8px;
    background-color: var(--color-bg-secondary);
    font-size: var(--font-size-xs);
    line-height: var(--line-height-text-xs);
    font-weight: var(--weight-semi-bold);
    white-space: nowrap;

    .sort-heading {
      display: flex;
      align-items: center;
      gap: var(--spacing-xs);
    }
  }

  td {
    height: 64px;
  }

  tbody tr:last-child td {
    border-bottom: none;
  }

  tbody tr:hover {
    background-color: var(--color-bg-secondary);
  }

  /* Two-line cell content: an identifying line above a quieter supporting line. */
  .cell-stack {
    display: flex;
    flex-direction: column;
  }

  .cell-title {
    font-weight: var(--weight-medium);
    color: var(--color-text-primary);
  }

  .cell-support {
    font-size: var(--font-size-xs);
    line-height: var(--line-height-text-xs);
    color: var(--color-text-secondary);
  }

  /* Links */

  /* Header links (e.g. sort controls) carry the header's own styling. */
  th a {
    color: inherit;
    text-decoration: none;
  }

  /* Body links inherit the cell colour and are marked by an underline. */
  td a {
    color: inherit;
    text-decoration: underline;

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

  /* A link wrapping its own composite content (avatar plus label) needs no underline. */
  a.cell-plain {
    text-decoration: none;
  }

  /* Inline brand action inside a cell, e.g. "Assign". */
  a.cell-action {
    color: var(--color-text-brand-secondary);
    font-weight: var(--weight-semi-bold);
    text-decoration: none;

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

  /* Trailing column holding row actions, separated by a rule as in the design. */
  th.actions, td.actions {
    border-left: 1px solid var(--color-border-secondary);
    white-space: nowrap;
  }

  /* Size */

  &.sm {
    th {
      height: 36px;
    }

    td {
      height: 48px;
      padding: 10px 8px;
    }
  }

  /* Tables with a second, expandable row of detail beneath each primary row. */
  &.with-expandable-rows {
    min-width: 1180px;

    .detail-expander-heading, .detail-expander {
      width: 40px;
    }

    .detail-expander {
      padding-right: 0;

      i {
        font-size: var(--font-size-icon-sm);
      }
    }

    .detail-row td {
      height: auto;
      padding: var(--spacing-xl) var(--spacing-xl) var(--spacing-xl) var(--spacing-6xl);
      white-space: normal;
    }

    .detail-row:hover {
      background-color: var(--color-bg-primary);
    }
  }

  /* Row state */

  tr.success {
    background-color: var(--color-bg-success-primary);

    &:hover {
      background-color: var(--color-bg-success-secondary);
    }
  }

  tr.warning {
    background-color: var(--color-bg-warning-primary);

    &:hover {
      background-color: var(--color-bg-warning-secondary);
    }
  }

  tr.error {
    background-color: var(--color-bg-error-primary);

    &:hover {
      background-color: var(--color-bg-error-secondary);
    }
  }

  tr.disabled td {
    color: var(--color-text-disabled);
  }
}
