/* Rows and tables: white fills separated by space, never by lines. */
@layer components {
  .rows { display: grid; gap: var(--space-2); }

  .row {
    --fill: var(--color-ink-8);

    display: flex;
    gap: var(--space-4);
    align-items: center;
    min-height: 4rem;
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: inherit;
    text-decoration: none;
  }

  /* A row that posts, such as one opening Stripe's billing portal, looks like one that links. */
  button.row { width: 100%; border: 0; font: inherit; text-align: start; cursor: pointer; }
  a.row, button.row { transition: background var(--duration-fast) var(--ease); }
  a.row:hover, button.row:hover { background: var(--color-surface-hover); }

  .row__main { display: grid; flex: 1; min-width: 0; }
  /* A row whose main part opens the record while its trail holds a button of its own. */
  a.row__main { color: inherit; text-decoration: none; }
  .row__title { font-size: var(--text-lg); font-weight: var(--weight-bold); letter-spacing: var(--tracking-snug); }
  .row__meta { font-size: var(--text-sm); }
  .row__trail { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: center; justify-content: end; }

  .table-scroll { position: relative; overflow-x: auto; margin-inline: calc(-1 * var(--space-1)); padding-inline: var(--space-1); }

  .table {
    --fill: var(--color-ink-8);

    width: 100%;
    border-collapse: separate;
    border-spacing: 0 var(--space-2);

    th {
      padding: 0 var(--space-5) var(--space-1);
      font-size: var(--text-sm);
      font-weight: var(--weight-bold);
      text-align: left;
      white-space: nowrap;
    }

    td {
      padding: var(--space-3) var(--space-5);
      background: var(--color-surface);
      vertical-align: middle;
    }

    td:first-child { border-start-start-radius: var(--radius-md); border-end-start-radius: var(--radius-md); }
    td:last-child { border-start-end-radius: var(--radius-md); border-end-end-radius: var(--radius-md); }
  }

  /* Fixed columns keep a tag or a name in the same place on every page and filter, whatever the rows hold. */
  .table--fixed { table-layout: fixed; }
  .table__col--tag { width: 11rem; }
  .table__col--person { width: 14rem; }
  .table__col--action { width: 9rem; }
  .table__col--check { width: 3rem; }
  /* A row's checkbox sits above the link that opens the row. */
  .table__check { position: relative; z-index: 1; }

  .table__primary { font-weight: var(--weight-bold); }

  /* A row with one link opens from anywhere on it. */
  .table--links tr { position: relative; }
  .table--links tr:hover td { background: var(--color-surface-hover); }
  .table__link::after { content: ""; position: absolute; inset: 0; }
  .table .table__number { text-align: right; font-variant-numeric: tabular-nums; }
  .table .table__actions { text-align: right; white-space: nowrap; }

  /* On phones each row is a card: the primary cell across the top, the rest wrapping under it, actions last. */
  @media (max-width: 767px) {
    .table, .table tbody { display: block; }

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

    .table tr {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-2) var(--space-3);
      align-items: center;
      margin-bottom: var(--space-2);
      padding: var(--space-4);
      border-radius: var(--radius-md);
      background: var(--color-surface);
    }

    .table td,
    .table td:first-child,
    .table td:last-child {
      display: flex;
      flex-wrap: wrap;
      gap: var(--space-2);
      align-items: center;
      min-width: 0;
      padding: 0;
      border-radius: 0;
      background: none;
      overflow-wrap: anywhere;
    }

    .table .table__primary { flex-basis: 100%; }
    .table--links .table__primary { flex: 1 1 10rem; }
    .table--links tr:hover { background: var(--color-surface-hover); }
    .table td.table__wide { display: none; }
    .table .table__actions { margin-left: auto; }
  }

  /* A date as a small block at the start of a row: JAN over 13 */
  .date-block {
    display: grid;
    flex: none;
    place-content: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: var(--radius-md);
    background: var(--fill);
    font-weight: var(--weight-bold);
    line-height: 1.1;
    text-align: center;
  }

  .date-block__month { font-size: var(--text-xs); text-transform: uppercase; }
  .date-block__day { font-size: var(--text-xl); }
}

/* A record's facts: label beside value, stacked on phones. */
@layer components {
  .facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-3) var(--space-8);
    align-items: baseline;

    dt { font-weight: var(--weight-bold); }
    dd { white-space: pre-line; overflow-wrap: anywhere; }
  }

  @media (max-width: 767px) {
    .facts { grid-template-columns: 1fr; gap: var(--space-1); }
    .facts dd + dt { margin-top: var(--space-3); }
  }
}

/* What happened, in order: a dot per entry on a dotted line, what on the left and when on the right. */
@layer components {
  .timeline { display: grid; gap: var(--space-4); }

  .timeline__item {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-4);
    align-items: baseline;
    padding-left: var(--space-6);

    &::before {
      content: "";
      position: absolute;
      top: 0.45em;
      left: 0;
      width: 0.6rem;
      height: 0.6rem;
      border-radius: var(--radius-sm);
      background: var(--color-ink);
    }

    &:not(:last-child)::after {
      content: "";
      position: absolute;
      top: calc(0.45em + 0.6rem + 3px);
      bottom: calc(-1 * var(--space-4) + 3px);
      left: calc(0.3rem - 1px);
      border-left: 2px dotted var(--color-ink);
    }
  }

  .timeline__what { font-weight: var(--weight-bold); }
  .timeline__when { font-size: var(--text-sm); white-space: nowrap; }
}

