/* ---------- Pienso: the town hall's food stock (food_stock/index, pickup_points/show) ---------- */

/* The whole town hall's stock, one figure per line (kg of dry food, cans of each size) */
.food-totals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-6);
  padding: var(--space-4) var(--space-5);
}

.food-totals__item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.food-totals__value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

/* A point's stock table scrolls sideways on a phone instead of spilling out of its card */
.food-lines {
  overflow-x: auto;
}

@media (max-width: 40rem) {
  .food-lines__detail {
    display: none;
  }
}

/* Food to collect (Mi pienso), side by side on wide screens */
.food-points {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr));
  gap: var(--space-4);
  align-items: start;
}

/* A punto de recogida on its own page's map: a teal square */
.map-marker.map-marker--pickup {
  background: var(--category-teal);
  border-radius: 4px;
}

/* Give / collect / cancel at the end of a row, kept on one line */
.food-actions {
  text-align: right;
  white-space: nowrap;

  .row {
    justify-content: flex-end;
  }
}

/* An entrada's lines in the list, one under the other */
.food-receipt-lines {
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-1);
  font-size: var(--text-sm);
}

/* An entrada's food in its form: each kind of food in a box of its own, with its button to take it out */
.food-receipt-line {
  display: grid;
  /* minmax(0, …): a plain column can't be narrower than its fields, which then stuck out of the box on phones */
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.food-receipt-line__remove {
  justify-self: end;
}

/* On a computer a row reads across, in one line when it fits: the kind, the amount, brand, product, the bag's photo
   and the button to take it out (also an entrega's rows: which food and how much). The fields' own grids step aside
   (display: contents) so every field is one item of the row */
@media (min-width: 64rem) {
  .food-receipt-line {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    column-gap: var(--space-4);

    > .form {
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      align-items: flex-end;
      gap: var(--space-3) var(--space-4);

      > .form-grid {
        display: contents;
      }

      .form-field {
        flex: 1 1 7rem;
        min-width: 0;
      }

      > fieldset.form-field {
        flex: none;
      }

      /* Which line of stock, in an entrega: the longest label */
      .form-field:has(select) {
        flex: 3 1 16rem;
      }
    }
  }

  .food-receipt-line > .photo-tile {
    align-self: center;
  }

  /* An entrega's row has no photo: its fields take the first column */
  .food-receipt-line:not(:has(> .photo-tile)) {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .food-receipt-line__remove {
    align-self: end;
  }
}

/* A bag's photo (FoodHelper#food_photo): a small square opening the large one, beside its food */
.food-photo {
  display: block;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);

  img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }
}

.food-photo--sm {
  width: 2.5rem;
  height: 2.5rem;
}

.food-photo--md {
  width: 4rem;
  height: 4rem;
}

.food-with-photo {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--space-3);
}

/* In the totals, the photo at the top beside the amount, and those without one level with it */
.food-totals__item.food-with-photo {
  align-items: flex-start;
}

.food-totals__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.food-receipt-lines__line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---------- Balance: given vs used, per person (food_balances/show) ---------- */

.food-balance__hint {
  max-width: 60rem;
  margin-bottom: var(--space-4);
}

/* "Pienso seco" over its three columns, and a line between the two kinds of food */
.food-balance__group {
  text-align: center;
  border-left: 1px solid var(--color-border);
}

.food-balance tbody td:nth-child(2),
.food-balance tbody td:nth-child(5),
.food-balance thead tr:last-child th:nth-child(1),
.food-balance thead tr:last-child th:nth-child(4) {
  border-left: 1px solid var(--color-border);
}

.food-balance .badge {
  white-space: nowrap;
}

/* Five tabs don't fit a phone: they scroll sideways, each on one line */
.food-tabs {
  max-width: 100%;
  overflow-x: auto;

  .segmented__item {
    flex-shrink: 0;
    white-space: nowrap;
  }
}
