/* Viva bulk order table (product page).
 *
 * Priority: the order-quantity box must always be fully visible. The size /
 * colour name is the column that gives way (it wraps); numbers never wrap.
 * The layout follows the width of the box the table sits in (a container
 * query), not the screen: on desktop the table lives in the narrow right-hand
 * product column, so its width has little to do with the viewport.
 *
 *   wide    Size | SKU | Price | Order qty | Total
 *   medium  Size | SKU | Price | Order qty         (line total dropped; the
 *                                                  footer total still adds up)
 *   narrow  one card per size: name, SKU and price on the left, qty box on
 *           the right
 */
.viva-bulk-order {
  container-type: inline-size;
  container-name: viva-bulk;
  margin: 1rem 0;
}

.viva-bulk-order__scroll {
  border: 1px solid var(--bs-border-color, #dee2e6);
  border-radius: 0.375rem;
}

.viva-bulk-order__table {
  width: 100%;
  margin-bottom: 0;
  font-size: 0.9rem;
}

.viva-bulk-order__table thead th {
  vertical-align: bottom;
  background: var(--bs-light, #f8f9fa);
}

.viva-bulk-order__table td,
.viva-bulk-order__table th {
  vertical-align: middle;
}

/* Long colour names wrap instead of pushing the qty box out of view. */
.viva-bulk-order__size {
  min-width: 6rem;
  white-space: normal;
  overflow-wrap: anywhere;
}

.viva-bulk-order__sku,
.viva-bulk-order__price,
.viva-bulk-order__line-total,
.viva-bulk-order__table thead th:not(.viva-bulk-order__size) {
  white-space: nowrap;
}

.viva-bulk-order__qty,
.viva-bulk-order__qty-head {
  width: 1%;
  white-space: nowrap;
}

.viva-bulk-order__qty input {
  width: 5.5rem;
}

.viva-bulk-order__tax {
  font-weight: normal;
  color: var(--bs-secondary-color, #6c757d);
}

.viva-bulk-order__in-cart,
.viva-bulk-order__unavailable,
.viva-bulk-order__message {
  display: block;
  font-size: 0.75rem;
  white-space: normal;
}

.viva-bulk-order__in-cart {
  color: var(--bs-secondary-color, #6c757d);
}

.viva-bulk-order__row--unavailable {
  color: var(--bs-secondary-color, #6c757d);
}

.viva-bulk-order__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.viva-bulk-order.is-loading .viva-bulk-order__add {
  opacity: 0.6;
  pointer-events: none;
}

.viva-bulk-order__feedback {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

/* Medium: drop the per-line total, tighten cells. */
@container viva-bulk (max-width: 560px) {
  .viva-bulk-order__total-col {
    display: none;
  }

  .viva-bulk-order__table {
    font-size: 0.85rem;
  }

  .viva-bulk-order__table > :not(caption) > * > * {
    padding: 0.45rem 0.4rem;
  }

  .viva-bulk-order__qty input {
    width: 4.75rem;
  }
}

/* Narrow (phones, and very narrow product columns): one card per size. */
@container viva-bulk (max-width: 420px) {
  .viva-bulk-order__table thead {
    display: none;
  }

  .viva-bulk-order__table,
  .viva-bulk-order__table tbody {
    display: block;
  }

  .viva-bulk-order__table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "size qty"
      "meta qty";
    column-gap: 0.75rem;
    align-items: center;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
  }

  .viva-bulk-order__table tbody tr:last-child {
    border-bottom: 0;
  }

  .viva-bulk-order__table tbody > tr > * {
    padding: 0;
    border: 0;
    background: transparent;
  }

  .viva-bulk-order__table tbody .viva-bulk-order__size {
    grid-area: size;
    min-width: 0;
  }

  /* SKU and price share the second line under the name. */
  .viva-bulk-order__table tbody .viva-bulk-order__sku,
  .viva-bulk-order__table tbody .viva-bulk-order__price {
    grid-area: meta;
    font-size: 0.8rem;
    color: var(--bs-secondary-color, #6c757d);
    text-align: left !important;
  }

  .viva-bulk-order__table tbody .viva-bulk-order__sku::before {
    content: "SKU ";
  }

  .viva-bulk-order__table tbody .viva-bulk-order__price {
    justify-self: end;
    font-weight: 600;
    color: inherit;
  }

  .viva-bulk-order__table tbody .viva-bulk-order__qty {
    grid-area: qty;
    width: auto;
  }

  .viva-bulk-order__qty input {
    width: 5rem;
  }

  .viva-bulk-order__add {
    width: 100%;
  }
}
