/* css-dish-card.css — styles that only matter when one of these sections is on the page:
 * main-brand, main-category, main-collection, main-menu, main-search, main-shop.
 * Linked from each of them (see the first line of the section file); theme.css
 * holds the common styles. */

/* Every card's picture is the same size, and nothing inside it gets a vote.
 *
 * `aspect-ratio` alone did not hold. This is a flex item, and a flex item's
 * automatic minimum size is its content's — so a portrait photo pushed the
 * box past the ratio and a broken image collapsed it below, which is exactly
 * the row of mismatched pictures this replaces. `min-height: 0` gives up that
 * automatic minimum and `flex: none` stops the box being stretched or
 * squeezed by its siblings.
 *
 * The image is then taken out of flow entirely: absolutely positioned to fill
 * the box, it cannot contribute any size at all. A broken one shows its alt
 * text inside the frame instead of resizing it, and `overflow: hidden` keeps
 * that text in the frame. */
.dish__media {
  position: relative;
  display: block;
  flex: none;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(160deg, var(--surface-3), var(--line-2));
  margin-bottom: 0.75rem;
}

/* Sized by its content, never cropped — currency codes and three-decimal
   minor units (BHD, KWD, OMR) make this string much wider than a "$14". It
   sits inside the image's corner: on a square edge there is nothing to hang
   off, and a token half outside the card would be clipped by it. */
.dish__badge {
  position: absolute;
  inset-inline-end: 0.5rem;
  bottom: 0.5rem;
  max-width: calc(100% - 1rem);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-pill);
  background: var(--dark);
  color: var(--on-dark);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

/* Catalogue names nobody chose the length of: let them wrap anywhere rather
 * than push the card wider than its column. */
.dish__title,
.dish__desc {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* The text block. Carries the inset for both children, so the two of them
 * stay one thing to place. */
.dish__text { padding-inline: var(--dish-pad); }

.dish__title {
  font-size: 1.02rem;
  margin: 0 0 0.35rem;
}

.dish__desc {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 0.6rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* `margin-top: auto` pins the action to the bottom, so cards in a row line
 * their buttons up however tall the names above them run. The padding is the
 * floor for a card that is the tallest in its row, where `auto` resolves to
 * nothing and the button would otherwise sit against the name. */
.dish__actions { margin-top: auto; padding-top: 0.45rem; padding-inline: var(--dish-pad); }

/* Sold out as a badge — a state of the dish, not a line of copy. Sized to its
 * words and pinned to the card's foot where the add button would be. */
.dish__sold {
  align-self: flex-start;
  width: fit-content;
  /* Its cell (.dish__actions) already insets it by --dish-pad; a margin on
   * top of that set it twice as far in as the title. */
  margin: 0;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--danger) 12%, var(--surface));
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
}

.dish__actions .btn { width: 100%; }

/* The offer ribbon, across the corner of the picture — PLUS marks a
 * discounted card this way, and a corner is the one part of a photograph that
 * is never the subject. Rotated through the media's own clipped box, so the
 * ends disappear off the card rather than needing to be mitred.
 *
 * Not a link and not a button: the whole card already goes to the product. */
.dish__ribbon {
  position: absolute;
  z-index: 1;
  top: 0.85rem;
  inset-inline-start: -2.2rem;
  width: 9rem;
  padding: 0.22rem 0;
  transform: rotate(-45deg);
  background: var(--danger);
  color: #fff;
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  pointer-events: none;
}

/* The ribbon is drawn in the start corner, so in RTL it leans the other way
 * or it would read as a fold on the wrong edge. */
[dir="rtl"] .dish__ribbon { transform: rotate(45deg); }

/* Was-price: quieter than the price it precedes, and never the thing read
 * first — the token's job is still to say what this costs now. */
.dish__was {
  opacity: 0.7;
  font-weight: 500;
  margin-inline-end: 0.15rem;
}

/* In the list view the picture is a thumbnail, and a ribbon across it would
 * cover most of the food. A tag on the row instead. */
[data-view="list"] .dish__ribbon {
  top: 0.3rem;
  inset-inline-start: 0.3rem;
  width: auto;
  padding: 0.12rem 0.4rem;
  border-radius: var(--radius-sm);
  transform: none;
  font-size: 0.6rem;
}

[dir="rtl"] [data-view="list"] .dish__ribbon { transform: none; }

@media (max-width: 48rem) {
  .dish__media { margin-bottom: 0.6rem; }
  .dish__badge {
      inset-inline-end: 0.4rem;
      bottom: 0.4rem;
      max-width: calc(100% - 0.8rem);
      font-size: 0.78rem;
    }
  .dish__title {
      font-size: 0.9rem;
      /* Two lines, then ellipsis: uneven card heights are worse than a
       * truncated name, and the full name is on the product page. */
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      line-clamp: 2;
      overflow: hidden;
    }
  .dish__desc { display: none; }
}
/* List: the same card turned on its side. The picture becomes a square rail
 * down the start edge spanning every row of the card, so the text column is
 * whatever is left — no second set of card styles, just a different flow. */
[data-view="list"] .dish-grid {
  grid-template-columns: 1fr;
  gap: 0.6rem;
}

[data-view="list"] .dish__media {
  grid-column: 1;
  grid-row: 1;
  aspect-ratio: 1;
  margin-bottom: 0;
}

/* Explicit placement, because the description is optional: without it the
 * rows would shuffle up and the name would sit where the description was. */
[data-view="list"] .dish__text { grid-column: 2; padding-inline: 0; }

[data-view="list"] .dish__actions,
[data-view="list"] .dish__sold {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  margin: 0;
  padding: 0;
}

[data-view="list"] .dish__title { margin: 0; }

/* Room to read, and the reason someone picked this view — so it comes back on
 * a phone, where the grid card hides it. */
[data-view="list"] .dish__desc {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  margin: 0.2rem 0 0;
}

/* The picture is a third of its grid size here, so the token has to come
 * down with it — at the grid's size it covered most of an 88px thumbnail. */
[data-view="list"] .dish__badge {
  inset-inline-end: 0.3rem;
  bottom: 0.3rem;
  padding: 0.22rem 0.45rem;
  font-size: 0.72rem;
  border-radius: 0.5rem;
}

/* A button as wide as a laptop row is a target nobody needs. */
[data-view="list"] .dish__actions .btn { width: auto; min-width: 8rem; }

@media (max-width: 48rem) {
  [data-view="list"] .dish__media { grid-row: 1 / -1; align-self: start; }
  [data-view="list"] .dish__text { grid-row: 1; }
  [data-view="list"] .dish__title {
      /* The grid card clamps hard because two sit side by side; a full-width
       * row has space for the whole name. */
      display: block;
      font-size: 0.92rem;
    }
  [data-view="list"] .dish__actions,
    [data-view="list"] .dish__sold {
      grid-column: 2;
      grid-row: 2;
      justify-self: stretch;
      margin-top: 0.5rem;
    }
  [data-view="list"] .dish__actions .btn { min-width: 0; width: 100%; }
}
/* The list view zeroes its cell's padding and stretches it; the badge keeps
 * its own padding and stays the size of its words. */
[data-view="list"] .dish__sold { padding: 0.25rem 0.65rem; width: fit-content; }

.dish__badge-from { font-weight: 500; opacity: 0.72; font-size: 0.72em; }

