/*
 * Shared — product card and the grid it sits in.
 *
 * Declarations copied from the prototype, later overrides folded in (it defines
 * .pc twice; the second block wins on padding, radius and the image plinth).
 * Selector map: .pc → .mgk-pc, .pc-img → .mgk-pc__img, .pz → .mgk-pz,
 * .add → .mgk-pc__add, .wish → .mgk-pc__wish, .grid → .mgk-grid.
 */

/* A minimum card width, not a column count — the prototype's flat
   repeat(5,1fr) cannot hold this card.
   The foot has to carry the price lockup and the CTA side by side, and
   "Choose options" is 138px of it: with the 8px gap and 103px for
   "S$61.23 S$85.03" the foot needs 249px, so the card needs 275px once its
   26px of padding is counted. (The prototype got away with five columns
   because it kept the struck price on its OWN line, leaving a ~60px price
   block. One-line pricing costs that width back.)
   A fixed count cannot deliver 275px everywhere, because the grids are not the
   same width: 1265px on the homepage but 973px on the catalogue, which carries
   a 210px filter rail. Five columns gave 231px cards on both; four gave 298px
   on the homepage and still 231px on the catalogue. auto-fill + minmax states
   the real constraint once and lets each grid pick its own count — four across
   the homepage, three beside the filter rail — with no per-page override and
   nothing for a new screen to remember.
   --4 is kept as a selector because templates still carry it (deals.php, the
   homepage deal band), but it no longer pins a count. */
.mgk-grid,
.mgk-grid--4 { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.mgk-grid > * { min-width: 0; }

/* Two card sizes, by SECTION — not by card.
   --4 is the showcase grid: the Fresh Deals band and the deals page. It keeps
   the tight 16px gutter, so its tracks stretch to the full width available and
   its cards stay the biggest on the page. That size difference is the point:
   it is what makes the band read as the headline.
   Everywhere else — Popular this week, the catalogue, the PDP strip — the
   cards come down a notch, and EVERY card in the grid comes down together so a
   section reads as one set.
   The reduction is spent on the column gutter rather than on an extra column,
   because a card cannot go below 269px without breaking its own layout:
   "S$61.23" 51 + 5 + "S$85.03" 41 + 8 + 138 for the button is 243px of foot,
   plus 26px of padding. An extra column would give 231px on the catalogue and
   240px on the homepage, and every discounted card in them would drop its
   button onto a second row. A 48px gutter instead gives 292px on the catalogue
   and 280px on the homepage — both under the band's 290/304, both clear of the
   269px floor, both edges of the row still flush with the section heading.
   Row gap stays 16px: the vertical rhythm was never the problem, and 48px
   between forty rows of catalogue would be a lot of nothing. */
/* Keyed on the SECTION, not on --4: that modifier is on the catalogue grid too
   (catalog.php), so it does not identify the showcase. The two grids that stay
   big are the ones inside the homepage deal band and the deals page — both
   two-class selectors, so they win on specificity wherever they sit in the file.
   The 230px floor everywhere else is what the shorter "Options" label buys:
   97px of price pair + 8 + 90px of button is 195px of foot, so a 230px card
   clears it. That puts five cards across the homepage (240px each) and four
   beside the catalogue's filter rail (231px), at the design's own 16px gutter
   rather than the wide one this used to need. */
.mgk-home__deals .mgk-grid,
.mgk-deals .mgk-grid { grid-template-columns: repeat(auto-fill, minmax(275px, 1fr)); }

.mgk-pc {
	position: relative;
	border: 1px solid var(--mgk-line);
	border-color: var(--mgk-line) var(--mgk-line) var(--mgk-line-d);
	border-radius: var(--mgk-radius);
	/* 13px is the prototype's own card padding; the card also carries two more
	   body rows than the first cut did (pack size/shop, and the tag chips), so
	   the vertical rhythm below is deliberately looser than it was. */
	padding: 13px;
	background: var(--mgk-paper);
	box-shadow: var(--mgk-highlight);
	display: flex;
	flex-direction: column;
	/* The foot stacks on the card's own width, not the viewport's: the same card
	   is 205px of content at five columns and 269px at four (Fresh Deals), and
	   only the narrow one has to stack. */
	container-type: inline-size;
	transition: border-color var(--mgk-t1), transform var(--mgk-t2) var(--mgk-ease), box-shadow var(--mgk-t2);
}

.mgk-pc:hover {
	transform: translateY(-3px);
	border-color: var(--mgk-line-d);
	box-shadow: var(--mgk-highlight), 0 10px 24px -14px rgba(33, 31, 26, .30);
}

/* One shared plinth rather than a per-card tint, so a grid of photos reads as
   one shot set and the colour comes from the produce. */
.mgk-pc__img {
	position: relative;
	height: 154px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: var(--mgk-radius-b);
	overflow: hidden;
	margin-bottom: 12px;
	background: linear-gradient(180deg, #FFFEFC 0%, #FEFCF8 55%, #F8F3E9 100%);
}

.mgk-pc__img img {
	max-width: 82%;
	max-height: 100%;
	width: auto;
	object-fit: contain;
	transition: transform var(--mgk-t2) var(--mgk-ease);
}

.mgk-pc:hover .mgk-pc__img img { transform: scale(1.05); }

/* Corner badges — the prototype's .bgs/.bg: a column stack in the top-left,
   800 weight, white on a solid fill, in its colour assignments (.bg-s red for
   the discount, .bg-b amber for best seller, .bg-n green for new).
   Inset INTO the photo rather than pinned to the card's own corner: 13px clears
   the card's padding, +8px lands the stack inside the image plinth, which is
   what makes it read as floating over the photograph instead of sitting on the
   card. (The wishlist control opposite is still on the card corner — it was not
   part of this change.)
   A notch smaller than the prototype's 21px/11px, per the same review that
   moved it.
   Upper-cased here rather than in PHP so the merchant's own wording is what
   gets stored and translated — "Best Seller" reads as BEST SELLER without
   anything rewriting it. */
.mgk-pc__badges {
	position: absolute;
	top: 21px;
	left: 21px;
	max-width: calc(100% - 63px);
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	gap: 4px;
	z-index: 2;
}

.mgk-pc__badge {
	max-width: 100%;
	height: 19px;
	padding: 0 6px;
	border-radius: var(--mgk-radius-s);
	font-family: var(--mgk-font);
	font-size: 10px;
	font-weight: 800;
	letter-spacing: .02em;
	text-transform: uppercase;
	display: inline-flex;
	align-items: center;
	color: #fff;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.mgk-pc__badge--sale { background: var(--mgk-red); }
.mgk-pc__badge--best { background: var(--mgk-amber); }
.mgk-pc__badge--new  { background: var(--mgk-green); }
.mgk-pc--oos .mgk-pc__img img { filter: grayscale(1); opacity: .5; }

.mgk-pc__wish {
	position: absolute;
	top: 0; right: 0;
	width: 29px; height: 29px;
	border-radius: var(--mgk-radius-s);
	background: #fff;
	border: 1px solid var(--mgk-line);
	color: var(--mgk-ink-3);
	display: grid;
	place-items: center;
	z-index: 2;
}

.mgk-pc__wish:hover { border-color: var(--mgk-red); color: var(--mgk-red); }
.mgk-pc__wish--on { background: var(--mgk-red); border-color: var(--mgk-red); color: #fff; }
.mgk-pc__wish--on svg { fill: currentColor; }

.mgk-pc__cat {
	font-size: 10.5px;
	font-weight: 700;
	letter-spacing: .05em;
	text-transform: uppercase;
	color: var(--mgk-ink-3);
}

/* Clamped to two lines with a reserved min-height, so a one-line title and a
   two-line title still leave their price rows aligned across the row. */
.mgk-pc__title {
	font-family: var(--mgk-font);
	font-size: 13.5px;
	font-weight: 700;
	line-height: 1.32;
	margin: 5px 0 6px;
	letter-spacing: -.015em;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
	min-height: 2.64em;
}

.mgk-pc__rating { display: flex; align-items: center; gap: 5px; font-size: 11.5px; }

/* One glyph run, clipped by a gradient — no half-star images to ship. */
.mgk-pc__stars {
	background: linear-gradient(90deg, var(--mgk-amber) var(--mgk-stars, 0%), var(--mgk-line-d) var(--mgk-stars, 0%));
	-webkit-background-clip: text;
	background-clip: text;
	color: transparent;
	letter-spacing: .5px;
}

/* "400 g · By FreshMart" — the shop name green, per the prototype's
   `.pc-by b{color:var(--g);font-weight:600}`. */
.mgk-pc__by { font-size: 11.5px; color: var(--mgk-ink-3); margin: 5px 0 8px; }
.mgk-pc__by b { color: var(--mgk-green); font-weight: 600; }

/* Product tags. Wraps rather than truncating, and sits between the by-line and
   the price foot — the one body row the prototype keeps for per-product
   merchandising. Colours follow v1's cert chips: the three recognised kinds
   take the store's themed tints, everything else stays neutral. */
.mgk-pc__tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 9px; }

.mgk-pc__chip {
	display: inline-flex;
	align-items: center;
	height: 20px;
	max-width: 100%;
	padding: 0 7px;
	border-radius: var(--mgk-radius-s);
	font-family: var(--mgk-font);
	font-size: 10.5px;
	font-weight: 700;
	line-height: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	background: var(--mgk-wash);
	color: var(--mgk-ink-3);
}

.mgk-pc__chip--halal   { background: var(--mgk-green-tint);   color: var(--mgk-green); }
.mgk-pc__chip--organic { background: var(--mgk-green-tint-2); color: var(--mgk-green-deep); }
.mgk-pc__chip--sfa     { background: var(--mgk-blue-tint);    color: var(--mgk-blue); }

/* The foot is allowed to wrap. At five columns a card is ~233px wide, and
   "Choose options" alone is 138px of that — side by side, the price block got
   squeezed to 59px and its struck price dropped to a second line, which is the
   exact thing the one-line price rule is there to prevent. So the price keeps
   its intrinsic width and the button drops to its own row when both no longer
   fit, right-aligned by the auto margin. Same stacked shape the prototype
   switches to at narrow viewports (.pc-ft{flex-direction:column}). */
.mgk-pc__ft {
	margin-top: auto;
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 8px;
	row-gap: 9px;
}

/* nowrap holds the live price and the struck one on one line; the tax note is
   display:block, so it still takes the line below on its own. */
.mgk-pc__price { flex: 1 1 auto; min-width: 0; white-space: nowrap; }
.mgk-pc__add { flex: 0 0 auto; margin-left: auto; }

/* The prototype's stacked foot, lifted from its 2-column breakpoint where the
   comment reads: "two cards per row leaves no room for price and a wide CTA
   side by side, so the footer stacks and the button takes the full card
   width".
   The --stack class marks the cards whose CTA is the wide "Choose options"
   one; this query decides whether that CTA actually has room. Every desktop
   and tablet grid above now leaves it 264px or more, so it never fires there
   and the foot stays two columns — price plus tax note on the left, button on
   the right. It survives only as the phone fallback: at two columns on a
   375px screen the foot is 133px, where no amount of shrinking would fit a
   138px button beside a price. */
/* 195px, not 240: with the "Options" label the foot needs 97 (price pair) + 8 +
   90 (button) = 195px, and a 240px card gives 214px of content. The stack is
   now only what it was meant to be — the phone fallback, where two columns on a
   375px screen leave 133px and nothing would fit beside anything. */
@container (max-width: 195px) {
	.mgk-pc__ft--stack { flex-direction: column; align-items: stretch; gap: 9px; }
	.mgk-pc__ft--stack .mgk-pc__add { justify-content: center; width: 100%; margin-left: 0; }
}

/* Sale-batch urgency rail — the prototype's .burn/.burn-r/.burn-t, declarations
   copied rather than approximated. Green while the batch is young, amber past
   half, red (and pulsing) past 80% — the prototype's note: "the last stretch
   pulses — only in the >=80% state, so it stays meaningful". */
.mgk-pc__burn { margin: 2px 0 10px; }

.mgk-pc__burn-rail {
	height: 5px;
	border-radius: 999px;
	background: rgba(33, 31, 26, .09);
	overflow: hidden;
}

.mgk-pc__burn-rail i {
	display: block;
	height: 100%;
	border-radius: 999px;
	background: var(--mgk-green);
	transition: width 600ms var(--mgk-ease);
}

.mgk-pc__burn-text {
	display: flex;
	justify-content: space-between;
	gap: 8px;
	margin-top: 5px;
	font-size: 10.5px;
	color: var(--mgk-ink-3);
	letter-spacing: .01em;
}

.mgk-pc__burn-text b { font-weight: 700; color: var(--mgk-ink-2); }

.mgk-pc__burn--warm .mgk-pc__burn-rail i { background: var(--mgk-amber); }
.mgk-pc__burn--warm .mgk-pc__burn-text b { color: var(--mgk-amber); }
.mgk-pc__burn--hot .mgk-pc__burn-rail i { background: var(--mgk-red); animation: mgk-pc-burn 1.9s var(--mgk-ease) infinite; }
.mgk-pc__burn--hot .mgk-pc__burn-text b { color: var(--mgk-red); }

@keyframes mgk-pc-burn { 0%, 100% { opacity: 1; } 50% { opacity: .62; } }
@media (prefers-reduced-motion: reduce) { .mgk-pc__burn--hot .mgk-pc__burn-rail i { animation: none; } }

.mgk-pz {
	display: inline-flex;
	align-items: baseline;
	font-family: var(--mgk-font);
	font-size: 13.5px;
	font-weight: 750;
	letter-spacing: -.03em;
	color: var(--mgk-ink);
	font-variant-numeric: tabular-nums;
	font-feature-settings: 'tnum' 1;
}

.mgk-pz--sale { color: var(--mgk-red); }

/* Sale and pre-sale price share ONE line: the struck price sits beside the
   live one, not under it, and the price itself is a notch smaller so the pair
   fits the narrowest card in the grid without wrapping. Only the tax note
   below breaks to its own line. */
.mgk-pc__price s { font-size: 10.5px; color: var(--mgk-ink-3); margin-left: 5px; }
.mgk-pc__tax { display: block; font-size: 10.5px; color: var(--mgk-ink-3); font-weight: 500; margin-top: 1px; }

.mgk-pc__add {
	height: 33px;
	padding: 0 12px;
	border-radius: var(--mgk-radius-b);
	border: 1.5px solid var(--mgk-green);
	color: var(--mgk-green);
	font-family: var(--mgk-font);
	font-weight: 700;
	font-size: 12.5px;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	white-space: nowrap;
	transition: background var(--mgk-t1), color var(--mgk-t1);
}

.mgk-pc__add:hover { background: var(--mgk-green); color: #fff; }
.mgk-pc__add--dis { border-color: var(--mgk-line-d); color: var(--mgk-ink-3); pointer-events: none; }

/* auto-fill covers every width down to here on its own. Below this a phone is
   narrow enough that one card per row would be the honest answer, but the
   catalogue has always shown two, so two it stays — and the card's own
   container query hands the CTA its own row, the only place that still
   happens. */
/* The showcase override above is a two-class selector, and a media query adds
   no specificity — so the phone rule has to match it selector for selector or
   the deals page keeps its 275px floor and drops to one card per row. */
@media (max-width: 640px) {
	.mgk-grid,
	.mgk-grid--4,
	.mgk-home__deals .mgk-grid,
	.mgk-deals .mgk-grid { grid-template-columns: repeat(2, 1fr); column-gap: 16px; }
}
