/*
 * Backoffice data table. On phones each row becomes a small card and every cell shows its
 * column name from data-label; from 40rem it is a regular table.
 */
@layer components {
  [data-theme] {
    .table {
      display: block;
      width: 100%;
      border-collapse: collapse;
      font-variant-numeric: tabular-nums;

      :where(tbody) {
        display: block;
      }

      :where(thead) {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip-path: inset(50%);
      }

      :where(tbody tr) {
        display: block;
        margin-bottom: var(--space-3);
        padding: var(--space-2) var(--space-4);
        border: var(--border-width) solid var(--color-border);
        border-radius: var(--radius-card);
        background: var(--color-surface);
      }

      :where(td) {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        justify-content: space-between;
        gap: var(--space-2) var(--space-4);
        padding-block: var(--space-2);
        text-align: end;

        &::before {
          content: attr(data-label);
          flex: 0 1 auto;
          max-width: 50%;
          color: var(--color-text-muted);
          font-size: var(--text-sm);
          font-weight: var(--weight-strong);
          text-align: start;
        }

        & + td {
          border-top: 1px solid var(--color-border);
        }
      }

      @media (min-width: 40rem) {
        display: table;
        border: var(--border-width) solid var(--color-border);
        border-radius: var(--radius-card);
        background: var(--color-surface);
        border-collapse: separate;
        border-spacing: 0;
        overflow: hidden;

        :where(tbody) {
          display: table-row-group;
        }

        :where(thead) {
          position: static;
          width: auto;
          height: auto;
          clip-path: none;
        }

        :where(th) {
          padding: var(--space-3) var(--space-4);
          border-bottom: var(--border-width) solid var(--color-border);
          background: var(--color-surface-sunken);
          color: var(--color-text-muted);
          font-size: var(--text-sm);
          font-weight: var(--weight-strong);
          text-align: start;
          white-space: nowrap;
        }

        :where(tbody tr) {
          display: table-row;
          margin: 0;
          padding: 0;
          border: 0;
          border-radius: 0;

          &:hover {
            background: var(--color-surface-sunken);
          }
        }

        :where(td) {
          display: table-cell;
          padding: var(--space-3) var(--space-4);
          text-align: start;
          vertical-align: middle;

          &::before {
            content: none;
          }

          & + td {
            border-top: 0;
          }
        }

        :where(tbody tr:not(:last-child) td) {
          border-bottom: 1px solid var(--color-border);
        }
      }
    }

    .table__actions > * {
      margin-block: var(--space-1);
    }

    /* Wide tables scroll sideways inside this wrapper instead of stretching the page. */
    .table-scroll {
      @media (min-width: 40rem) {
        overflow-x: auto;
      }
    }

    .page-header {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: space-between;
      gap: var(--space-3);
    }
  }
}
