/*
 * Mim-Cafe — order receipt
 *
 * Adapted from the Uiverse printer component by dexter-st (MIT). Differences
 * from the original: no print button and no "click to print" label — it prints
 * itself when the order lands — the animation runs off an `.is-printing` class
 * instead of `:has(button:focus)`, the paper reads right-to-left, and the whole
 * thing is given room to breathe on a phone.
 */

/* The paper is absolutely positioned — it has to slide out from behind the
   printer — so it contributes nothing to the stage's height. The script
   measures the printed receipt and sets `min-height` here, which is why this
   only carries a floor for the printer itself. Clipping is deliberately *not*
   used: it would cut the paper off as it lifts. */
.mim-receipt-stage {
	position: relative;
	display: flex;
	justify-content: center;
	/* Stretch explicitly: a grid or flex parent that centres its items would
	   otherwise size this to its content, and everything inside is measured as a
	   percentage of it. */
	width: 100%;
	justify-self: stretch;
	align-self: stretch;
	min-height: 180px;
	padding: 24px 16px 32px;
	box-sizing: border-box;
}

.mim-printer {
	--printer-color: #E7E2D6;
	--printer-color-2: #C9C2B0;
	--receipt-color: #FBFAF7;

	/* Both are Elementor controls. The paper was previously sized as a fraction
	   of the machine, which made it a 10px receipt nobody could read. */
	--mim-receipt-width: 300px;
	--mim-receipt-size: 14px;
	--mim-receipt-offset: 44px;

	position: relative;
	/* Width comes from the container and is only *capped* by the control. The
	   other way round — width straight from the variable — meant the Elementor
	   control (higher specificity) beat every media query, so a 300px receipt
	   stayed 300px on a 320px phone and pushed the page sideways. */
	width: 100%;
	min-width: min(100%, 240px);
	max-width: calc(var(--mim-receipt-width) + var(--mim-receipt-offset, 44px) * 2);
	font-size: 14px;
	user-select: none;
}

/* ── The machine ────────────────────────────────────────── */

.mim-printer__body {
	position: relative;
	width: 100%;
	height: 80px;
	border-radius: 0 0 8px 8px;
	border: 2px solid var(--printer-color-2);
	background-color: var(--printer-color);
	box-shadow:
		0 16px 32px 0 rgba(0, 0, 0, .13),
		0 -30px 16px 0 rgba(0, 0, 0, .06);
}

.mim-printer__body::before {
	content: "";
	position: absolute;
	top: -30px;
	left: 0;
	width: 100%;
	height: 70px;
	box-sizing: border-box;
	border-radius: 12px 12px 0 0;
	border-bottom: 2px solid rgba(0, 0, 0, .2);
	background-color: inherit;
	filter: brightness(1.06);
	box-shadow:
		0 12px 16px -12px rgba(255, 255, 255, .33) inset,
		0 -6px 16px -6px rgba(0, 0, 0, .2) inset,
		0 6px 8px -6px rgba(0, 0, 0, .27);
	z-index: 2;
}

/* The slot the paper comes out of. */
.mim-printer__body::after {
	content: "";
	position: absolute;
	top: 20px;
	left: 30px;
	right: 30px;
	width: auto;
	height: 40px;
	border-radius: 0 0 4px 4px;
	border-bottom: 1px solid rgba(0, 0, 0, .2);
	background-image: linear-gradient(to top, var(--printer-color), 60%, var(--printer-color-2));
	box-shadow: 0 4px 4px -2px rgba(0, 0, 0, .27);
	z-index: 1;
}

.mim-printer__display {
	position: absolute;
	top: -10px;
	inset-inline-start: 30px;
	display: flex;
	align-items: center;
	width: 160px;
	height: 32px;
	padding: 6px 8px;
	box-sizing: border-box;
	border: 3px solid var(--printer-color-2);
	border-radius: 6px;
	background-color: #000;
	background-image: linear-gradient(transparent 0, rgba(255, 255, 255, .13) 90%, transparent 100%);
	background-size: 100% 8px;
	background-repeat: no-repeat;
	box-shadow:
		-1px -1px 2px 0 rgba(255, 255, 255, .6) inset,
		1px 1px 5px 1px #000 inset,
		0 0 1px 2px rgba(0, 0, 0, .13);
	color: #5aff5a;
	font-size: .8em;
	z-index: 2;
}

/* Revealed by clipping a single text node. Animating per-letter spans was what
   broke the Persian: cursive joining and bidi ordering are properties of a
   whole run, so splitting the word reversed and disconnected it. */
.mim-printer__status {
	display: inline-block;
	white-space: nowrap;
	clip-path: inset(0 0 0 100%);
}

/* ── The paper ──────────────────────────────────────────── */

.mim-receipt-wrapper {
	/* Centred by auto margins between left:0 and right:0, which leaves
	   `transform` free for the print animation. Offsetting from one edge put the
	   paper off-centre the moment the machine was narrower than its natural
	   width. */
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	/* Inset from the machine by the offset on each side, whatever the machine's
	   width turns out to be. Capping the paper at 100% instead let it grow until
	   the machine was a sliver peeking out behind it. */
	width: calc(100% - var(--mim-receipt-offset, 44px) * 2);
	max-width: var(--mim-receipt-width);
	margin-inline: auto;
	transform: translateY(-100%);
	clip-path: inset(100% -100px -100px -100px);
	transition: clip-path .5s;
	filter: drop-shadow(0 0 12px rgba(0, 0, 0, .07));
}

.mim-receipt {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 1em;
	width: 100%;
	min-height: 160px;
	padding: 18px 16px;
	box-sizing: border-box;
	background-color: var(--receipt-color);
	color: #3d3d3d;
	font-family: var(--mim-receipt-font, var(--mim-font, system-ui, sans-serif));
	font-size: var(--mim-receipt-size);
	line-height: 1.85;
	text-align: start;
	box-shadow:
		0 12px 12px 0 rgba(0, 0, 0, .07),
		0 24px 24px 0 rgba(0, 0, 0, .07),
		0 36px 36px 0 rgba(0, 0, 0, .07);
	z-index: 2;
}

/* The torn edges, top and bottom. */
.mim-receipt::before,
.mim-receipt::after {
	--angle: 45deg;

	content: "";
	display: block;
	position: absolute;
	left: 0;
	width: 100%;
	height: 8px;
	background:
		linear-gradient(calc(var(--angle) * -1), var(--receipt-color) 4px, transparent 0),
		linear-gradient(var(--angle), var(--receipt-color) 4px, transparent 0);
	background-position: 4px 0;
	background-repeat: repeat-x;
	background-size: 8px 8px;
}

.mim-receipt::before { top: -8px; }

.mim-receipt::after {
	--angle: 225deg;
	bottom: -8px;
	background-position: 0 100%;
}

.mim-receipt__head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 8px;
	font-size: 1.05em;
}

.mim-receipt__shop {
	display: grid;
	gap: 2px;
	min-width: 0;
}

.mim-receipt__address {
	font-size: .85em;
	font-weight: 400;
	opacity: .7;
}

.mim-receipt__logo-img {
	display: block;
	width: 42px;
	max-width: 42px;
	height: auto;
	object-fit: contain;
}

.mim-receipt__logo-icon {
	width: 34px;
	height: 34px;
	color: #3d3d3d;
	fill: currentColor;
	opacity: .55;
	transform: rotate(8deg);
}

.mim-receipt__meta {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	padding-bottom: .4em;
	border-bottom: 1px dashed #cfcfcf;
	font-size: .95em;
	opacity: .85;
}

.mim-receipt__ltr {
	direction: ltr;
	font-variant-numeric: tabular-nums;
}

.mim-receipt__note-row {
	display: grid;
	gap: 2px;
	padding-bottom: .5em;
	border-bottom: 1px dashed #cfcfcf;
	font-size: .95em;
}

.mim-receipt__note-label {
	font-weight: 700;
	opacity: .75;
}

.mim-receipt__note-text {
	overflow-wrap: anywhere;
	white-space: pre-line;
}

.mim-receipt__table {
	width: 100%;
	border-collapse: collapse;
	font: inherit;
	color: inherit;
	line-height: 1.9;
	text-align: start;
}

.mim-receipt__table th,
.mim-receipt__table td {
	padding: 0;
	vertical-align: top;
}

.mim-receipt__table th { font-weight: 600; }

.mim-receipt__qty {
	direction: ltr;
	text-align: center;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

.mim-receipt__num {
	text-align: end;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

.mim-receipt__count td,
.mim-receipt__total td {
	padding-top: .4em;
	border-top: 1px dashed #cfcfcf;
}

.mim-receipt__total td { font-weight: 700; }

.mim-receipt__status {
	padding: 6px 0;
	border-radius: 6px;
	text-align: center;
	font-weight: 700;
	letter-spacing: .02em;
}

.mim-receipt__status--ok {
	background: rgba(46, 138, 87, .12);
	color: #24734a;
}

.mim-receipt__status--fail {
	background: rgba(192, 57, 43, .12);
	color: #a5342a;
}

.mim-receipt__note {
	text-align: center;
	opacity: .8;
}

/* A free line reads as a word, not a number, so it gets the emphasis a price
   would have had. */
.mim-receipt__gift {
	font-weight: 700;
	color: #24734a;
}

.mim-receipt__cta {
	display: inline-block;
	align-self: center;
	max-width: 100%;
	padding: 9px 18px;
	border: 1px solid rgba(0, 0, 0, .12);
	border-radius: 8px;
	background: #fff;
	color: #3d3d3d;
	font-weight: 700;
	text-align: center;
	text-decoration: none;
	box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

.mim-receipt__cta:hover,
.mim-receipt__cta:focus {
	background: #fff;
	color: #000;
	text-decoration: none;
	border-color: rgba(0, 0, 0, .3);
}

/* ── Printing ───────────────────────────────────────────── */

.mim-printer.is-printing .mim-receipt-wrapper {
	animation:
		mim-print 1.2s 1 forwards ease-in,
		mim-print-show .4s 1 forwards cubic-bezier(0, .63, .96, 1.1);
	animation-delay: 0s, 1.35s;
}

.mim-printer.is-printing .mim-printer__status {
	animation: mim-print-type 1s steps(14, end) forwards;
}

@keyframes mim-print {
	100% {
		transform: translateY(10%);
		clip-path: inset(-20% -100px -100px -100px);
	}
}

/* The original lifts the paper up over the printer to present it. Here it
   settles just below the slot instead: lifting it would put the top of a long
   Persian receipt above the widget entirely. */
@keyframes mim-print-show {
	30%  { transform: translateY(14%) rotate3d(1, 0, 1, -4deg); }
	70%  { z-index: 5; }
	100% { z-index: 5; transform: translateY(8%) scale(1.03); }
}

/* Left inset, so in a right-to-left line the text appears right to left —
   the direction it is actually written in. */
@keyframes mim-print-type {
	from { clip-path: inset(0 0 0 100%); }
	to   { clip-path: inset(0 0 0 0); }
}

/* Printer switched off: the paper is just a card, sitting in the flow. */
.mim-checkout--no-printer .mim-printer__body,
.mim-checkout--no-printer .mim-printer__display { display: none; }

.mim-checkout--no-printer .mim-receipt-wrapper {
	position: static;
	transform: none;
	clip-path: none;
	animation: none !important;
}

.mim-checkout--no-printer .mim-receipt-stage { min-height: 0; }

.mim-checkout--no-printer .mim-printer {
	width: 100%;
	max-width: var(--mim-receipt-width);
}

/* ── Small screens ──────────────────────────────────────── */

@media (max-width: 480px) {
	.mim-receipt-stage {
		min-height: 470px;
		padding: 32px 10px 20px;
	}

	/* A smaller frame, but still a frame. Dropping it much below this made the
	   machine a sliver behind the paper rather than something the paper comes
	   out of. */
	.mim-printer { --mim-receipt-offset: 30px; }
}

/* ── Reduced motion ─────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
	.mim-printer.is-printing .mim-receipt-wrapper {
		animation: none;
		transform: translateY(8%);
		clip-path: none;
	}

	.mim-printer.is-printing .mim-printer__status {
		animation: none;
		clip-path: none;
	}
}

/* ── Print stylesheet: paper only ───────────────────────── */

@media print {
	body * { visibility: hidden; }

	.mim-receipt-stage,
	.mim-receipt-stage * { visibility: visible; }

	.mim-receipt-stage {
		position: absolute;
		inset: 0;
		min-height: 0;
		padding: 0;
	}

	.mim-printer__body,
	.mim-printer__display { display: none; }

	.mim-receipt-wrapper {
		position: static;
		transform: none;
		clip-path: none;
		animation: none !important;
		filter: none;
	}

	.mim-receipt { box-shadow: none; }

	.mim-receipt__cta { display: none; }
}
