/*
 * TKT-014: cụm nút nổi các kênh liên hệ.
 *
 * Chuyển từ `nd/floating-button` của nd-core (cùng cách làm: nút tròn chỉ có
 * icon, nhãn nở ra khi rê chuột; nút lên đầu trang có ngưỡng riêng và vòng tiến
 * độ). Màu: nút ở mọi trạng thái (nghỉ, hover, focus) dùng một màu primary
 * #A61B16, theo yêu cầu TKT-009 feedback #2.
 */

.px-floating {
	--px-floating-gap: 1.25rem;
	--px-floating-step: 0.5rem;
	--px-floating-color: var( --wp--preset--color--brand, #a61b16 );

	position: fixed;
	inset-block-end: calc( var( --px-floating-gap ) + var( --px-floating-lift, 0px ) );
	z-index: 60;
	display: flex;
	flex-direction: column;
}

.px-floating--right {
	inset-inline-end: var( --px-floating-gap );
	align-items: flex-end;
}

.px-floating--left {
	inset-inline-start: var( --px-floating-gap );
	align-items: flex-start;
}

/* Khoảng cách là margin, không phải gap, để nút lên đầu co về 0 mà không để lỗ. */
.px-floating > * + * {
	margin-block-start: var( --px-floating-step );
}

.px-floating__button {
	box-sizing: border-box;
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	column-gap: 0;
	min-inline-size: 2.75rem;
	block-size: 2.75rem;
	margin-block-end: 0;
	padding: 0 0.6rem;
	border: 0;
	border-radius: 62.4375rem;
	background: var( --px-floating-color );
	color: #fff;
	box-shadow: 0 2px 8px rgb( 0 0 0 / 0.22 );
	font: inherit;
	font-size: 0.875rem;
	font-weight: 600;
	line-height: 1;
	text-decoration: none;
	cursor: pointer;
	overflow: hidden;
	transition: column-gap 0.2s ease, box-shadow 0.2s ease;
}

/* Hover/focus giữ nguyên màu primary; theme tô màu liên kết khi rê chuột nên phải khai lại. */
.px-floating__button.px-floating__button:hover,
.px-floating__button.px-floating__button:focus-visible,
.px-floating__button.px-floating__button:active {
	background: var( --px-floating-color );
	color: #fff;
	text-decoration: none;
	column-gap: 0.5rem;
	box-shadow: 0 4px 12px rgb( 0 0 0 / 0.3 );
}

.px-floating__button:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 4px rgb( 0 0 0 / 0.45 );
}

.px-floating__icon {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: center;
	inline-size: 1.35rem;
	block-size: 1.35rem;
}

.px-floating__icon svg,
.px-floating__icon img {
	display: block;
	inline-size: 100%;
	block-size: 100%;
	object-fit: contain;
}

/* Chưa có logo Zalo thì nút chữ "Zalo" dùng màu primary như các nút khác; thu padding để vẫn tròn 44px. */
.px-floating__button--zalo:not( :has( img ) ) {
	padding-inline: 0.3rem;
}

/* Có logo Zalo (đĩa tròn đủ màu) thì để nó LÀ cái nút, không đặt vào đĩa đỏ. */
.px-floating__button--zalo:has( img ) {
	padding-inline: 0;
	background: transparent;
}

.px-floating__button.px-floating__button--zalo:has( img ):hover,
.px-floating__button.px-floating__button--zalo:has( img ):focus-visible {
	padding-inline-end: 0.6rem;
	background: var( --px-floating-color );
}

.px-floating__button--zalo:has( img ) .px-floating__icon {
	inline-size: 2.75rem;
	block-size: 2.75rem;
	border-radius: 50%;
	overflow: hidden;
}

.px-floating__button--zalo:has( img ) .px-floating__icon img {
	object-fit: cover;
}

.px-floating__zalo {
	font-size: 0.8125rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}

.px-floating__button--zalo .px-floating__icon:has( .px-floating__zalo ) {
	inline-size: auto;
}

.px-floating__text {
	max-inline-size: 0;
	overflow: hidden;
	white-space: nowrap;
	opacity: 0;
	transition: max-inline-size 0.2s ease, opacity 0.2s ease;
}

.px-floating__button:hover .px-floating__text,
.px-floating__button:focus-visible .px-floating__text {
	max-inline-size: 13rem;
	opacity: 1;
}

/* Nút lên đầu: ngưỡng cuộn riêng, thu về 0 khi chưa cần để hotline không lơ lửng cao. */
.px-floating__button--top.px-floating__button--top {
	block-size: 0;
	min-block-size: 0;
	margin-block-start: 0;
	padding-block: 0;
	opacity: 0;
	visibility: hidden;
	transform: translateY( 1.25rem );
	transition: block-size 0.32s ease-out, margin-block-start 0.32s ease-out, opacity 0.32s ease-out,
		transform 0.32s ease-out, visibility 0.32s, column-gap 0.2s ease;
}

.px-floating__button--top.px-floating__button--top.is-top-visible {
	block-size: 2.75rem;
	opacity: 1;
	visibility: visible;
	transform: translateY( 0 );
}

.px-floating > * + .px-floating__button--top.is-top-visible {
	margin-block-start: var( --px-floating-step );
}

/* Icon mũi tên trái của bộ icon Figma, xoay thành mũi tên lên. */
.px-floating__button--top .px-floating__icon {
	transform: rotate( 90deg );
}

/* Vòng tiến độ đọc, vẽ bên trong nút; neo vào mép trước để không méo khi nút nở. */
.px-floating__ring {
	position: absolute;
	inset-block-start: 0.2rem;
	inset-inline-start: 0.2rem;
	inline-size: 2.35rem;
	block-size: 2.35rem;
	border-radius: 50%;
	pointer-events: none;
	background: conic-gradient( currentColor var( --px-floating-progress, 0% ), rgb( 255 255 255 / 0.28 ) 0 );
	-webkit-mask: radial-gradient( farthest-side, transparent calc( 100% - 0.14rem ), #000 calc( 100% - 0.14rem ) );
	mask: radial-gradient( farthest-side, transparent calc( 100% - 0.14rem ), #000 calc( 100% - 0.14rem ) );
}

/* Màn hẹp: bám sát mép, không nở chữ (cảm ứng không có hover, chữ nở chỉ che nội dung). */
@media ( max-width: 480px ) {

	.px-floating {
		--px-floating-gap: 0.875rem;
	}

	.px-floating__button.px-floating__button:hover,
	.px-floating__button.px-floating__button:focus-visible {
		column-gap: 0;
	}

	.px-floating__button:hover .px-floating__text,
	.px-floating__button:focus-visible .px-floating__text {
		max-inline-size: 0;
		opacity: 0;
	}

	.px-floating__button--zalo:has( img ):hover,
	.px-floating__button--zalo:has( img ):focus-visible {
		padding-inline-end: 0;
	}
}

@media ( prefers-reduced-motion: reduce ) {

	.px-floating__button,
	.px-floating__text {
		transition: none;
	}
}
