/*
 * «نوار پایین موبایل»: below 1024px only (where the header turns into the burger).
 *
 * --fbb-h is how much of the screen's foot the bar takes now (0 while it steps
 * aside); the product buy bar, the cart pay bar, the chat button and the
 * install message sit on it. --fbb-space is what the page keeps free under its
 * content, and does not change while scrolling (no jump).
 */

.fbb,
.fbb-sheet,
.fbb-scrim {
	display: none;
}

@media (max-width: 1023.98px) {
	body.has-fbb {
		--fbb-bar: 64px;
		--fbb-h: calc(var(--fbb-bar) + env(safe-area-inset-bottom));
		--fbb-space: var(--fbb-h);
		padding-block-end: var(--fbb-space);
	}

	body.has-fbb--float {
		--fbb-h: calc(var(--fbb-bar) + 12px + env(safe-area-inset-bottom));
	}

	/* With the product buy bar or the cart pay bar on top, the page's end stays clear of both. */
	body.has-fbb:has(.fp-mbar:not([hidden])) {
		--fbb-space: calc(var(--fbb-h) + var(--fp-mbar-h, 72px));
	}

	body.has-fbb:has(.fc-mbar) {
		--fbb-space: calc(var(--fbb-h) + 72px);
	}

	body.has-fbb.fbb-away {
		--fbb-h: env(safe-area-inset-bottom);
	}

	/* The phone bars of the product and cart pages stand on it. */
	body.has-fbb :is(.fp-mbar, .fc-mbar) {
		inset-block-end: calc(var(--fbb-h) - env(safe-area-inset-bottom) + var(--fp-mbar-gap, 0px));
		transition: inset-block-end 0.25s cubic-bezier(0.32, 0.72, 0, 1);
	}

	/* The bar already keeps the iPhone's home line free below them. */
	body.has-fbb:not(.fbb-away) .fc-mbar {
		padding-block-end: 10px;
	}

	.fbb {
		--fbb-ease: cubic-bezier(0.32, 0.72, 0, 1);
		position: fixed;
		inset-inline: 0;
		inset-block-end: 0;
		z-index: 860;
		display: block;
		padding-block-end: env(safe-area-inset-bottom);
		border-block-start: 1px solid rgb(20 16 40 / 0.08);
		background: var(--fbb-bg);
		box-shadow: 0 -6px 20px rgb(20 16 40 / 0.06);
		font-family: var(--farin-font, inherit);
		letter-spacing: 0;
		transition: transform 0.25s var(--fbb-ease);
	}

	.fbb-away .fbb {
		transform: translateY(110%);
	}

	.fbb__list {
		display: grid;
		grid-template-columns: repeat(var(--fbb-n), minmax(0, 1fr));
		block-size: var(--fbb-bar);
		margin: 0;
		padding: 0 4px;
		list-style: none;
	}

	.fbb__item {
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		gap: 2px;
		block-size: 100%;
		min-inline-size: 44px;
		color: var(--fbb-fg);
		font-size: 11px;
		font-weight: 600;
		line-height: 1.5;
		text-decoration: none;
		-webkit-tap-highlight-color: transparent;
	}

	.fbb__item.is-active {
		color: var(--fbb-accent);
	}

	.fbb__item.is-active .fbb__label {
		font-weight: 800;
	}

	.fbb__item:focus-visible {
		outline: 2px solid var(--fbb-accent);
		outline-offset: -4px;
		border-radius: 12px;
	}

	.fbb__icon {
		position: relative;
		display: grid;
		place-items: center;
		inline-size: 44px;
		block-size: 28px;
		border-radius: 999px;
		transition: background-color 0.2s var(--fbb-ease), transform 0.2s var(--fbb-ease);
	}

	.fbb__item:active .fbb__icon {
		transform: scale(0.92);
	}

	.fbb__item.is-active .fbb__icon {
		background: color-mix(in srgb, var(--fbb-accent) 12%, transparent);
	}

	.fbb__label {
		max-inline-size: 100%;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	/* Labels off: only the active place keeps its name. */
	.fbb--quiet .fbb__item:not(.is-active) .fbb__label {
		position: absolute;
		inline-size: 1px;
		block-size: 1px;
		overflow: hidden;
		clip-path: inset(50%);
	}

	/* On the cart's corner, not over its middle. */
	.fbb__badge {
		position: absolute;
		inset-block-start: -7px;
		inset-inline-end: -2px;
		display: grid;
		place-items: center;
		min-inline-size: 18px;
		block-size: 18px;
		padding: 0 4px;
		border: 2px solid var(--fbb-bg);
		border-radius: 999px;
		background: #e11d48;
		color: #fff;
		font-size: 10px;
		font-weight: 800;
		line-height: 1;
	}

	.fbb__badge[hidden] {
		display: none;
	}

	.fbb__badge.is-bump {
		animation: fbb-bump 0.4s var(--fbb-ease);
	}

	@keyframes fbb-bump {
		40% {
			transform: scale(1.3);
		}
	}

	/* ---------- Floating ---------- */

	.fbb--float {
		inset-inline: 12px;
		inset-block-end: calc(12px + env(safe-area-inset-bottom));
		padding-block-end: 0;
		border: 1px solid rgb(20 16 40 / 0.08);
		border-radius: 24px;
		box-shadow: 0 12px 32px rgb(20 16 40 / 0.16);
	}

	.fbb--float .fbb__item.is-active .fbb__icon {
		background: var(--fbb-accent);
		color: #fff;
		box-shadow: 0 6px 14px color-mix(in srgb, var(--fbb-accent) 40%, transparent);
	}

	.fbb-away .fbb--float {
		transform: translateY(calc(100% + 24px));
	}

	/* ---------- Glass (like the iPhone's tab bar) ---------- */

	.fbb__lens {
		display: none;
	}

	body.has-fbb--glass {
		--fbb-h: calc(var(--fbb-bar) + 12px + env(safe-area-inset-bottom));
	}

	.fbb--glass {
		inset-inline: 14px;
		inset-block-end: calc(12px + env(safe-area-inset-bottom));
		padding-block-end: 0;
		border: 1px solid rgb(255 255 255 / 0.55);
		border-radius: 999px;
		background: color-mix(in srgb, var(--fbb-bg) 58%, transparent);
		box-shadow:
			inset 0 1px 0 rgb(255 255 255 / 0.65),
			inset 0 -1px 0 rgb(0 0 0 / 0.04),
			0 12px 32px rgb(20 16 40 / 0.16),
			0 2px 6px rgb(20 16 40 / 0.06);
		-webkit-backdrop-filter: blur(24px) saturate(180%);
		backdrop-filter: blur(24px) saturate(180%);
	}

	.fbb--glass .fbb__list {
		position: relative;
		padding: 0 6px;
	}

	/* The lens: a brighter pane of glass under the current item. */
	.fbb--glass .fbb__lens {
		position: absolute;
		inset-block: 6px;
		inset-inline-start: 6px;
		display: block;
		box-sizing: border-box;
		/* Border inside the width: each step is exactly one place, so the last one stays in the bar. */
		inline-size: calc((100% - 12px) / var(--fbb-n));
		border: 1px solid rgb(255 255 255 / 0.7);
		border-radius: 999px;
		background: color-mix(in srgb, var(--fbb-accent) 13%, rgb(255 255 255 / 0.6));
		box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.9), 0 4px 12px rgb(20 16 40 / 0.1);
		transform: translateX(calc(var(--fbb-at, 0) * -100%));
		transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1);
		pointer-events: none;
	}

	[dir="ltr"] .fbb--glass .fbb__lens {
		transform: translateX(calc(var(--fbb-at, 0) * 100%));
	}

	.fbb--glass .fbb__lens[hidden] {
		display: none;
	}

	.fbb--glass .fbb__item {
		z-index: 1;
	}

	.fbb--glass .fbb__item.is-active .fbb__icon {
		background: transparent;
	}

	.fbb--glass .fbb__item:active .fbb__icon {
		transform: scale(0.88);
	}

	.fbb--glass .fbb__badge {
		border-color: transparent;
	}

	.fbb-away .fbb--glass {
		transform: translateY(calc(100% + 24px));
	}

	/* No blur in the browser: a solid bar, still readable. */
	@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
		.fbb--glass {
			background: var(--fbb-bg);
		}
	}

	@media (prefers-reduced-transparency: reduce) {
		.fbb--glass {
			background: var(--fbb-bg);
			-webkit-backdrop-filter: none;
			backdrop-filter: none;
		}
	}

	@media (prefers-reduced-motion: reduce) {
		.fbb--glass .fbb__lens {
			transition: none;
		}
	}

	/* ---------- Sheets: search and categories ---------- */

	/*
	 * They rise from behind the bar (the bar stays on top and in reach) and
	 * take about half the screen; the page behind dims. Not the burger's side
	 * drawer, so the two ways in look different.
	 */
	.fbb-scrim {
		position: fixed;
		inset: 0;
		z-index: 845;
		display: block;
		background: rgb(15 12 25 / 0.4);
		opacity: 0;
		transition: opacity 0.3s var(--fbb-ease, ease);
	}

	.fbb-scrim.is-on {
		opacity: 1;
	}

	.fbb-scrim[hidden],
	.fbb-sheet[hidden] {
		display: none;
	}

	.fbb-sheet {
		position: fixed;
		inset-inline: 0;
		inset-block-end: 0;
		z-index: 850;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
		inline-size: 100%;
		max-block-size: min(62dvh, 560px);
		padding: 8px 16px calc(var(--fbb-h, 64px) + 16px);
		border-start-start-radius: 24px;
		border-start-end-radius: 24px;
		background: #fff;
		color: #1d1730;
		box-shadow: 0 -12px 40px rgb(20 16 40 / 0.18);
		font-family: var(--farin-font, inherit);
		letter-spacing: 0;
		transform: translateY(100%);
		transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1), max-block-size 0.38s cubic-bezier(0.32, 0.72, 0, 1), block-size 0.38s cubic-bezier(0.32, 0.72, 0, 1);
		touch-action: pan-y;
	}

	.fbb-sheet.is-on {
		transform: none;
	}

	/* Following the finger: no easing in the way. */
	.fbb-sheet.is-dragging {
		transition: none;
	}

	/* Pulled up: nearly the whole screen. */
	.fbb-sheet.is-full {
		max-block-size: calc(100dvh - 24px);
	}

	/* The search sheet keeps its height, so suggestions under the field have room. */
	#fbb-search {
		block-size: min(62dvh, 560px);
	}

	#fbb-search.is-full {
		block-size: calc(100dvh - 24px);
	}

	.fbb-sheet:focus {
		outline: none;
	}

	/* A handle at the top, like a sheet on a phone. */
	.fbb-sheet::before {
		content: "";
		align-self: center;
		inline-size: 40px;
		block-size: 4px;
		margin-block-end: 8px;
		border-radius: 999px;
		background: rgb(29 23 48 / 0.15);
	}

	.fbb-sheet__head {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-block-end: 12px;
		font-size: 16px;
	}

	.fbb-sheet__close {
		display: grid;
		place-items: center;
		inline-size: 44px;
		block-size: 44px;
		padding: 0;
		border: 0;
		border-radius: 12px;
		background: rgb(31 41 51 / 0.06);
		color: inherit;
		cursor: pointer;
	}

	.fbb-sheet__body {
		flex: 1;
		min-block-size: 0;
		overflow-y: auto;
		overscroll-behavior: contain;
		scrollbar-width: none;
	}

	.fbb-sheet__body::-webkit-scrollbar {
		display: none;
	}

	/* The live search's results open inside the sheet, not as a floating panel. */
	#fbb-search .farin-search__panel {
		position: static;
		margin-block-start: 12px;
		max-block-size: none;
		padding: 0;
		border: 0;
		box-shadow: none;
	}

	/* Categories: tiles, three in a row. */
	.fbb-cats {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: 8px;
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.fbb-cat {
		display: flex;
		flex-direction: column;
		align-items: center;
		gap: 6px;
		box-sizing: border-box;
		block-size: 100%;
		padding: 10px 6px;
		border-radius: 16px;
		background: #f6f5f9;
		color: inherit;
		font-size: 12px;
		font-weight: 700;
		line-height: 1.6;
		text-align: center;
		text-decoration: none;
	}

	.fbb-cat:active {
		transform: scale(0.97);
	}

	.fbb-cat__img {
		display: grid;
		place-items: center;
		inline-size: 56px;
		block-size: 56px;
		color: var(--fbb-accent, #7b2cbf);
	}

	.fbb-cat__img img {
		inline-size: 100%;
		block-size: 100%;
		object-fit: contain;
	}

	.fbb-cats__all,
	.fbb-sub__list a {
		display: flex;
		align-items: center;
		justify-content: space-between;
		min-block-size: 48px;
		padding-inline: 12px;
		border-radius: 12px;
		color: inherit;
		text-decoration: none;
	}

	.fbb-cats__all {
		margin-block-start: 12px;
		background: color-mix(in srgb, var(--fbb-accent, #7b2cbf) 10%, transparent);
		color: var(--fbb-accent, #7b2cbf);
		font-weight: 800;
	}

	.fbb-cats__main[hidden],
	.fbb-sub[hidden] {
		display: none;
	}

	.fbb-sub {
		animation: fbb-in 0.25s var(--fbb-ease, ease);
	}

	@keyframes fbb-in {
		from {
			opacity: 0;
			transform: translateX(-12px);
		}
	}

	.fbb-sub__back {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		min-block-size: 44px;
		margin-block-end: 4px;
		padding: 0 8px;
		border: 0;
		border-radius: 12px;
		background: none;
		color: inherit;
		font: inherit;
		font-weight: 800;
		cursor: pointer;
	}

	.fbb-sub__list {
		margin: 0;
		padding: 0;
		list-style: none;
	}

	.fbb-sub__list li + li a {
		border-block-start: 1px solid #f0edf5;
		border-radius: 0;
	}

	.fbb-sub__list b {
		color: var(--fbb-accent, #7b2cbf);
	}
}

@media (prefers-reduced-motion: reduce) {
	.fbb,
	.fbb__icon,
	.fbb-sheet,
	.fbb-scrim,
	.fbb-sub,
	body.has-fbb :is(.fp-mbar, .fc-mbar) {
		animation: none;
		transition: none;
	}
}
