/**
 * Floating widgets: scroll-to-top, contact buttons and the lucky wheel launcher.
 *
 * Hafez_Float_Position prints --hafez-float-x / -y (desktop) and, when a
 * mobile distance is set, --hafez-float-mx / -my. Bottom corners add
 * --hafez-float-lift and side corners --hafez-float-shift-r / -l, which the
 * account skin sets so the buttons stay clear of its bottom bar and of the
 * sidebar with the «خروج» button.
 */

.hafez-float {
	--hafez-float-ex: var(--hafez-float-x, 24px);
	--hafez-float-ey: var(--hafez-float-y, 24px);
	position: fixed;
	z-index: var(--hafez-float-z, 99990);
	inset: auto;
	margin: 0;
	padding: 0;
	line-height: 1;
	transition: bottom 0.25s ease, right 0.25s ease, left 0.25s ease;
}

@media (max-width: 781px) {
	.hafez-float {
		--hafez-float-ex: var(--hafez-float-mx, var(--hafez-float-x, 24px));
		--hafez-float-ey: var(--hafez-float-my, var(--hafez-float-y, 24px));
	}
}

.hafez-float--br {
	right: calc(var(--hafez-float-ex) + var(--hafez-float-shift-r, 0px));
	bottom: calc(var(--hafez-float-ey) + var(--hafez-float-lift, 0px));
}

.hafez-float--bl {
	left: calc(var(--hafez-float-ex) + var(--hafez-float-shift-l, 0px));
	bottom: calc(var(--hafez-float-ey) + var(--hafez-float-lift, 0px));
}

.hafez-float--bc {
	left: 50%;
	bottom: calc(var(--hafez-float-ey) + var(--hafez-float-lift, 0px));
	transform: translateX(-50%);
}

.hafez-float--tr {
	right: calc(var(--hafez-float-ex) + var(--hafez-float-shift-r, 0px));
	top: var(--hafez-float-ey);
}

.hafez-float--tl {
	left: calc(var(--hafez-float-ex) + var(--hafez-float-shift-l, 0px));
	top: var(--hafez-float-ey);
}

.hafez-float--tc {
	left: 50%;
	top: var(--hafez-float-ey);
	transform: translateX(-50%);
}

/*
 * Account skins (Hafez_Account_Skins, body.hafez-acc-skin): the RTL sidebar
 * (logout at its foot) sits on the right from 900px; below that a fixed
 * bottom bar (.acc-bn, ~66px + safe area) takes the bottom edge.
 */
@media (min-width: 900px) {
	body.hafez-acc-skin {
		--hafez-float-shift-r: 280px;
	}

	body.hafez-acc-skin:has(.hafez-acc.is-rail) {
		--hafez-float-shift-r: 72px;
	}
}

@media (max-width: 899px) {
	body.hafez-acc-skin {
		--hafez-float-lift: calc(70px + env(safe-area-inset-bottom, 0px));
	}
}

/* Open menus of the account (skin «بیشتر» drawer, classic side drawer) stay uncovered. */
body.hafez-account-nav-open .hafez-float {
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
}

/* Separate rule: a browser without :has() drops only this one. */
body:has(.hafez-acc.is-drawer) .hafez-float {
	visibility: hidden;
	opacity: 0;
	pointer-events: none;
}

/*
 * «رنگ‌بندی: از هویت بصری» (default). Hafez_Float_Position::enqueue_identity()
 * prints the --hafez-dp-* colours of the visual identity on .hafez-float-dp,
 * with the readable text colour of «تضمین خوانایی رنگ‌ها».
 */
.hafez-scroll-top.hafez-float-dp {
	--hafez-scroll-bg: var(--hafez-dp-primary-bg, #111827);
	--hafez-scroll-bg-hover: var(--hafez-dp-primary-hover-bg, var(--hafez-scroll-bg));
	--hafez-scroll-icon: var(--hafez-dp-primary-text, #fff);
}

.hafez-scroll-top.hafez-float-dp:hover,
.hafez-scroll-top.hafez-float-dp:focus-visible {
	color: var(--hafez-dp-primary-hover-text, var(--hafez-scroll-icon));
}

.hafez-contact.hafez-float-dp {
	--hafez-contact-bg: var(--hafez-dp-primary-bg, #111827);
	--hafez-contact-bg-hover: var(--hafez-dp-primary-hover-bg, var(--hafez-contact-bg));
	--hafez-contact-icon: var(--hafez-dp-primary-text, #fff);
	--hafez-contact-bubble-bg: var(--hafez-dp-primary-bg, #111827);
	--hafez-contact-bubble-ink: var(--hafez-dp-primary-text, #fff);
	--hafez-contact-title-bg: var(--hafez-dp-box-bg, #fff);
	--hafez-contact-title-ink: var(--hafez-dp-label, #111827);
}

.hafez-contact.hafez-float-dp .hafez-contact__launcher:hover,
.hafez-contact.hafez-float-dp .hafez-contact__launcher:focus-visible {
	color: var(--hafez-dp-primary-hover-text, var(--hafez-contact-icon));
}

@media (max-width: 781px) {
	.hafez-float--desktop {
		display: none !important;
	}
}

@media (min-width: 782px) {
	.hafez-float--mobile {
		display: none !important;
	}
}

.hafez-scroll-top {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: var(--hafez-scroll-size, 44px);
	min-height: var(--hafez-scroll-size, 44px);
	padding: 0;
	border: 0;
	border-radius: 999px;
	background: var(--hafez-scroll-bg, #111827);
	color: var(--hafez-scroll-icon, #fff);
	font: inherit;
	font-size: 13px;
	cursor: pointer;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition:
		opacity 0.4s cubic-bezier(0.22, 1, 0.36, 1),
		transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
		visibility 0s linear 0.4s,
		background-color 0.2s ease;
}

.hafez-scroll-top--rounded {
	border-radius: 14px;
}

.hafez-scroll-top--square {
	border-radius: 4px;
}

.hafez-scroll-top--shadow {
	box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
}

.hafez-scroll-top--slide:not(.is-visible) {
	transform: translateY(12px);
}

.hafez-float--bc.hafez-scroll-top--slide:not(.is-visible),
.hafez-float--tc.hafez-scroll-top--slide:not(.is-visible) {
	transform: translateX(-50%) translateY(12px);
}

.hafez-scroll-top--none {
	transition: none;
}

.hafez-scroll-top.is-visible {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition-delay: 0s;
}

.hafez-float--bc.hafez-scroll-top.is-visible,
.hafez-float--tc.hafez-scroll-top.is-visible {
	transform: translateX(-50%);
}

.hafez-scroll-top:hover,
.hafez-scroll-top:focus-visible {
	background: var(--hafez-scroll-bg-hover, #1f2937);
}

.hafez-scroll-top:focus-visible {
	outline: 2px solid var(--hafez-scroll-icon, #fff);
	outline-offset: 3px;
}

.hafez-scroll-top__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 18px;
	height: 18px;
}

.hafez-scroll-top__icon svg,
.hafez-scroll-top__img {
	width: 18px;
	height: 18px;
	object-fit: contain;
}

.hafez-scroll-top__label {
	white-space: nowrap;
}

.hafez-scroll-top:has(.hafez-scroll-top__label) {
	width: auto;
	padding: 0 14px;
}

.hafez-contact {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
}

.hafez-contact__panel {
	position: absolute;
	display: flex;
	align-items: stretch;
	width: max-content;
	min-width: var(--hafez-contact-size, 44px);
	gap: 10px;
	visibility: hidden;
	pointer-events: none;
	transition: visibility 0s linear 0.55s;
}

.hafez-contact--up .hafez-contact__panel {
	bottom: calc(100% + 12px);
	flex-direction: column-reverse;
}

.hafez-contact--down .hafez-contact__panel {
	top: calc(100% + 12px);
	flex-direction: column;
}

.hafez-float--br .hafez-contact__panel,
.hafez-float--tr .hafez-contact__panel,
.hafez-contact--from-right .hafez-contact__panel {
	right: 0;
	left: auto;
}

.hafez-float--bl .hafez-contact__panel,
.hafez-float--tl .hafez-contact__panel,
.hafez-contact--from-left .hafez-contact__panel {
	left: 0;
	right: auto;
}

.hafez-float--bc .hafez-contact__panel,
.hafez-float--tc .hafez-contact__panel {
	left: 50%;
	right: auto;
	transform: translateX(-50%);
}

.hafez-contact.is-open .hafez-contact__panel {
	visibility: visible;
	pointer-events: auto;
	transition-delay: 0s;
}

.hafez-contact__item {
	display: flex;
	align-items: center;
	gap: 8px;
	width: 100%;
	box-sizing: border-box;
	color: inherit;
	text-decoration: none;
	opacity: 0;
	transform: translateY(16px) scale(0.86);
	transition:
		opacity 0.42s cubic-bezier(0.22, 1, 0.36, 1),
		transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
	transition-delay: calc((var(--n, 1) - var(--i, 0)) * 32ms);
}

.hafez-contact__item.is-preview {
	cursor: default;
}

/* Pin bubbles to the launcher edge so titles of different lengths stay aligned. */
.hafez-float--br .hafez-contact__item,
.hafez-float--tr .hafez-contact__item,
.hafez-contact--from-right .hafez-contact__item {
	flex-direction: row;
	justify-content: flex-end;
}

.hafez-float--bl .hafez-contact__item,
.hafez-float--tl .hafez-contact__item,
.hafez-contact--from-left .hafez-contact__item {
	flex-direction: row-reverse;
	justify-content: flex-end;
}

.hafez-float--bc .hafez-contact__item,
.hafez-float--tc .hafez-contact__item {
	display: grid;
	grid-template-columns: minmax(0, 1fr) var(--hafez-contact-size, 44px) minmax(0, 1fr);
	justify-content: initial;
	gap: 8px;
}

.hafez-float--bc .hafez-contact__title,
.hafez-float--tc .hafez-contact__title {
	grid-column: 1;
	justify-self: end;
}

.hafez-float--bc .hafez-contact__bubble,
.hafez-float--tc .hafez-contact__bubble {
	grid-column: 2;
}

.hafez-contact.is-open .hafez-contact__item {
	opacity: 1;
	transform: none;
	transition-delay: calc(var(--i, 0) * 55ms);
}

.hafez-contact__title {
	padding: 7px 12px;
	border-radius: 999px;
	background: var(--hafez-contact-title-bg, #fff);
	color: var(--hafez-contact-title-ink, #111827);
	font-size: 13px;
	line-height: 1.3;
	white-space: nowrap;
	box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
}

.hafez-contact--labels-hover .hafez-contact__title {
	opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
	.hafez-contact--labels-hover .hafez-contact__title {
		opacity: 0;
		transform: translateX(8px);
		transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
	}

	.hafez-float--bl.hafez-contact--labels-hover .hafez-contact__title,
	.hafez-float--tl.hafez-contact--labels-hover .hafez-contact__title {
		transform: translateX(-8px);
	}

	.hafez-contact--labels-hover .hafez-contact__item:hover .hafez-contact__title,
	.hafez-contact--labels-hover .hafez-contact__item:focus-visible .hafez-contact__title {
		opacity: 1;
		transform: none;
	}
}

.hafez-contact__bubble,
.hafez-contact__launcher {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: var(--hafez-contact-size, 44px);
	height: var(--hafez-contact-size, 44px);
	border: 0;
	border-radius: 999px;
	box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
}

.hafez-contact__bubble {
	flex: 0 0 var(--hafez-contact-size, 44px);
	background: var(--hafez-contact-bubble-bg, #111827);
	color: var(--hafez-contact-bubble-ink, #fff);
}

.hafez-contact__launcher {
	position: relative;
	background: var(--hafez-contact-bg, #111827);
	color: var(--hafez-contact-icon, #fff);
	cursor: pointer;
	transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.2s ease;
}

.hafez-contact__launcher:hover,
.hafez-contact__launcher:focus-visible {
	background: var(--hafez-contact-bg-hover, #1f2937);
	transform: translateY(-2px);
}

.hafez-contact__item:hover .hafez-contact__bubble,
.hafez-contact__item:focus-visible .hafez-contact__bubble {
	transform: translateY(-2px);
}

.hafez-contact__launcher:focus-visible,
.hafez-contact__item:focus-visible .hafez-contact__bubble {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

.hafez-contact__glyph {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: opacity 0.35s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.hafez-contact__glyph--close {
	opacity: 0;
	transform: rotate(-80deg) scale(0.55);
}

.hafez-contact.is-open .hafez-contact__glyph--open {
	opacity: 0;
	transform: rotate(80deg) scale(0.55);
}

.hafez-contact.is-open .hafez-contact__glyph--close {
	opacity: 1;
	transform: none;
}

.hafez-contact__img,
.hafez-contact__glyph svg {
	width: 20px;
	height: 20px;
	object-fit: contain;
}

.hafez-contact__letter {
	font-size: 14px;
	font-weight: 700;
	line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
	.hafez-scroll-top,
	.hafez-contact__item,
	.hafez-contact__glyph,
	.hafez-contact__title,
	.hafez-contact__launcher,
	.hafez-contact__panel {
		transition: none !important;
	}
}
