/* 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);
  scrollbar-color: var(--color-border-primary) transparent;
  scrollbar-width: thin;

  /* 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;
  }

  .checkbox-cell {
    width: 44px;
    min-width: 44px;
    max-width: 44px;
  }

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

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

  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". */
  .cell-action {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--color-text-brand-secondary);
    font-weight: var(--weight-semi-bold);
    text-decoration: none;

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

  button.cell-action {
    padding: 0;
    background: none;
    border: 0;
    font: inherit;
    font-weight: var(--weight-semi-bold);
    cursor: pointer;
  }

  /* 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;

    &.compact {
      width: 1%;
    }
  }

  /* Size */

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

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

  /* Keeps a many-column table at its natural content width instead of squeezing its cells. */
  &.nowrap {
    width: max-content;
    min-width: 100%;
    white-space: nowrap;
  }

  /* Pins explicitly marked edge columns while the columns between them scroll horizontally. */
  &.with-sticky-columns {
    border-collapse: separate;
    border-spacing: 0;

    .sticky-left,
    .sticky-right {
      position: sticky;
      z-index: 3;
      background: inherit;
    }

    .sticky-left {
      left: 0;
      box-shadow: 1px 0 0 var(--color-border-secondary);
    }

    .sticky-right {
      right: 0;
      box-shadow: -1px 0 0 var(--color-border-secondary);
    }

    thead .sticky-left,
    thead .sticky-right {
      z-index: 5;
      background-color: var(--color-bg-secondary);
    }
  }

  /* 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);
  }
}
