/* ---------------------------------------------------------------- icons -- */

.repo-icon {
  display: inline-block;
  text-align: center;
  object-fit: contain;
}

.repo-icon-lg {
  width: 5rem;
  height: 5rem;
  font-size: 4rem;
  line-height: 5rem;
}

.repo-icon-sm {
  width: 3.5rem;
  height: 3.5rem;
  font-size: 2.8rem;
  line-height: 3.5rem;
}

/* Padding lives here rather than in a Bootstrap utility class, so that the
   table view can tighten it: utilities are !important and cannot be overridden. */
.repo-icon-link {
  padding: 1rem;
}

/* --------------------------------------------------------- commit cards -- */

/* Commit messages keep their line breaks, but a single 80 line merge message
   must not stretch every card of its row. */
.commit-message {
  display: -webkit-box;
  -webkit-line-clamp: 8;
  line-clamp: 8;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
  margin-bottom: 0;
}

/* The drop shadow lives here rather than in Bootstrap's .shadow-sm utility:
   utilities are !important, so it would win over both the hover ring below and
   the underline of the table view. */
.repo-card,
.custom-repo-card {
  box-shadow: var(--bs-box-shadow-sm);
}

/* Cards highlight themselves when pointed at or keyboard focused. */
.commit-card,
.repo-card,
.section-card {
  transition:
    background-color 0.15s ease-in-out,
    border-color 0.15s ease-in-out,
    box-shadow 0.15s ease-in-out;
}

.commit-card:hover,
.commit-card:focus-within,
.repo-card:hover,
.repo-card:focus-within {
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

@media (prefers-reduced-motion: reduce) {
  .commit-card,
  .repo-card,
  .section-card {
    transition: none;
  }
}

/* ------------------------------------------------------- table view -- */

/* One item per row, whatever the viewport. */
[data-view="list"] .view-collection > * {
  flex: 0 0 100%;
  width: 100%;
}

/* Laying the card sections out side by side only makes sense once there is
   enough width for them; below that the regular stacked card is kept. */
@media (min-width: 768px) {
  /* The collection becomes the table frame, the cards become its rows. */
  [data-view="list"] .view-collection {
    --bs-gutter-x: 0;
    --bs-gutter-y: 0;
    border: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    overflow: hidden;
  }

  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card) {
    flex-direction: row;
    align-items: stretch;
    border: 0;
    border-bottom: var(--bs-border-width) solid var(--bs-border-color);
    border-radius: 0;
    box-shadow: none;
  }

  /* The last row has no divider, but it keeps a transparent one so that its
     hover underline lines up with the other rows instead of shifting them. */
  [data-view="list"] .view-collection > *:last-child :is(.repo-card, .commit-card, .section-card) {
    border-bottom-color: transparent;
  }

  /* The custom repository card is not a row: keep it flat inside the frame. */
  [data-view="list"] .view-collection .custom-repo-card {
    box-shadow: none;
    border-radius: 0;
    border-width: 0;
    border-top: var(--bs-border-width) solid var(--bs-border-color);
  }

  /* A row highlight reads better than a floating ring in a table. The
     underline reuses the halo recipe of the grid cards: the accent colour on
     the edge itself, topped by a 0.2rem translucent band of the same colour. */
  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card):hover,
  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card):focus-within {
    background-color: var(--bs-tertiary-bg);
    border-bottom-color: var(--bs-primary);
    box-shadow: inset 0 -0.2rem 0 rgba(var(--bs-primary-rgb), 0.25);
  }

  /* Cells: no cap background, tight padding, one continuous surface. */
  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card) > * {
    background-color: transparent;
    border: 0;
    padding: 0.35rem 0.75rem;
  }

  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card) > .card-header {
    display: flex;
    flex: 0 0 16.5rem;
    gap: 0.75rem;
    justify-content: flex-start;
    align-items: center;
    /* Keeping the sha and the date on a single line halves the row height. */
    white-space: nowrap;
  }

  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card) > .card-body {
    display: flex;
    flex: 1 1 auto;
    gap: 0.75rem;
    align-items: center;
    min-width: 0;
  }

  [data-view="list"] .view-collection :is(.repo-card, .commit-card, .section-card) > .card-footer {
    display: flex;
    flex: 0 0 auto;
    gap: 0.75rem;
    align-items: center;
    justify-content: flex-end;
  }

  /* A single line per row keeps the table scannable. */
  [data-view="list"] .commit-message {
    -webkit-line-clamp: 1;
    line-clamp: 1;
    white-space: normal;
  }

  [data-view="list"] .repo-card > .repo-icon-link {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    padding: 0.35rem 0.75rem;
  }

  [data-view="list"] .repo-icon-lg {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 1.25rem;
    line-height: 1.5rem;
  }

  [data-view="list"] .repo-card .card-title {
    margin-bottom: 0;
    font-size: 1rem;
  }

  [data-view="list"] .repo-card .card-text {
    margin-bottom: 0;
  }

  /* Compact controls so the rows stay dense. */
  [data-view="list"] .view-collection .btn {
    --bs-btn-padding-y: 0.15rem;
    --bs-btn-padding-x: 0.5rem;
    --bs-btn-font-size: 0.8125rem;
  }
}
