/*
 * WhatsApp Badge by MA - Frontend badge styles.
 * All colors and sizing are driven by CSS custom properties
 * injected inline by WBMA_Frontend::render_badge().
 */

.wbma-badge {
	position: fixed !important;
	right: 0;
	transform: translateY(-50%);
	z-index: var(--wbma-z, 9999);

	display: inline-flex !important;
	flex-direction: row;
	direction: ltr;
	align-items: center;
	justify-content: center;
	gap: calc(10px * var(--wbma-scale, 1));

	background-color: var(--wbma-bg, #25D366);
	color: var(--wbma-color, #ffffff);
	text-decoration: none !important;
	opacity: 1 !important;
	visibility: visible !important;

	box-sizing: border-box;
	width: max-content;
	min-width: min(var(--wbma-width, 42px), 100vw);
	max-width: 100vw;
	min-height: calc(42px * var(--wbma-scale, 1));
	padding: calc(10px * var(--wbma-scale, 1)) calc(14px * var(--wbma-scale, 1)) calc(10px * var(--wbma-scale, 1)) calc(18px * var(--wbma-scale, 1));
	border-radius: var(--wbma-radius, 22px) 0 0 var(--wbma-radius, 22px);

	transition: right 0.2s ease, left 0.2s ease, top 0.2s ease, transform 0.2s ease, box-shadow 0.15s ease;

	user-select: none;
	-webkit-user-select: none;
	touch-action: none;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
	cursor: pointer;

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: calc(14px * var(--wbma-scale, 1));
	font-weight: 600;
	line-height: 1;
}

/* Size presets (Settings > WhatsApp Button > Edge badge > Size). M is the original look. */
.wbma-badge--size-xs { --wbma-scale: 0.75; }
.wbma-badge--size-s  { --wbma-scale: 0.875; }
.wbma-badge--size-m  { --wbma-scale: 1; }
.wbma-badge--size-l  { --wbma-scale: 1.15; }
.wbma-badge--size-xl { --wbma-scale: 1.3; }

.wbma-badge:focus-visible {
	outline: 2px solid currentColor;
	outline-offset: 3px;
}

.wbma-badge--left {
	right: auto;
	left: 0;
	border-radius: 0 var(--wbma-radius, 22px) var(--wbma-radius, 22px) 0;
	box-shadow: 2px 2px 8px rgba(0, 0, 0, 0.18);
}

.wbma-badge--free {
	border-radius: var(--wbma-radius, 22px);
	box-shadow: 0 3px 14px rgba(0, 0, 0, 0.22);
}

.wbma-badge--dragging {
	transform: none;
	transition: box-shadow 0.15s ease;
	box-shadow: -4px 4px 16px rgba(0, 0, 0, 0.28);
	will-change: transform, top, right, left;
	cursor: grabbing;
}

/* Lift the dragged badge over the drop zone and any fixed bottom bar. */
#wbma-badge.wbma-badge--dragging {
	z-index: 2147483647;
}

/* Dropped on the "hide" zone: fade out, then the script sets display:none. */
#wbma-badge.wbma-badge--dismissed {
	opacity: 0 !important;
	pointer-events: none !important;
	transform: translateY(24px) scale(0.6) !important;
	transition: opacity 0.22s ease, transform 0.22s ease !important;
}

/* Drop target shown at the bottom of the screen while the badge is dragged. */
.wbma-dropzone {
	position: fixed;
	left: 50%;
	bottom: calc(18px + env(safe-area-inset-bottom, 0px));
	z-index: 2147483646;

	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 6px;

	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translate(-50%, 16px);
	transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;

	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 12px;
	font-weight: 600;
	line-height: 1;
	color: #ffffff;
}

.wbma-dropzone--visible {
	opacity: 1;
	visibility: visible;
	transform: translate(-50%, 0);
	transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s;
}

.wbma-dropzone__icon {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 52px;
	height: 52px;
	border-radius: 50%;
	background: rgba(20, 20, 20, 0.72);
	border: 2px solid rgba(255, 255, 255, 0.85);
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
	/* --wbma-dz-p (0..1) = how close the finger is; set on every pointer move. */
	transform: scale(calc(1 + 0.32 * var(--wbma-dz-p, 0)));
	transition: transform 0.12s ease-out, background-color 0.18s ease, box-shadow 0.18s ease;
	will-change: transform;
}

.wbma-dropzone__icon svg {
	display: block;
	width: 22px;
	height: 22px;
	color: #ffffff;
}

.wbma-dropzone__label {
	padding: 4px 9px;
	border-radius: 999px;
	background: rgba(20, 20, 20, 0.72);
}

/* Grabbed: springy pop past full size, red, with a soft glow ring. */
.wbma-dropzone--active .wbma-dropzone__icon {
	transform: scale(1.55);
	background: #d93025;
	box-shadow: 0 0 0 6px rgba(217, 48, 37, 0.22), 0 6px 18px rgba(0, 0, 0, 0.3);
	transition: transform 0.32s cubic-bezier(0.34, 1.7, 0.5, 1), background-color 0.18s ease, box-shadow 0.18s ease;
}

.wbma-dropzone--active .wbma-dropzone__label {
	background: #d93025;
}

/* Dropped: quick gulp (squeeze, then bounce) before the zone fades out. */
.wbma-dropzone--swallow .wbma-dropzone__icon {
	animation: wbma-dz-gulp 0.26s ease-out;
}

@keyframes wbma-dz-gulp {
	0% { transform: scale(1.55); }
	40% { transform: scale(1.25); }
	100% { transform: scale(1.7); }
}

/* While grabbed, the badge glides onto the X (and back off) instead of jumping. */
#wbma-badge.wbma-badge--magnet {
	transition: left 0.18s cubic-bezier(0.25, 1, 0.5, 1), top 0.18s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.15s ease;
}

#wbma-badge.wbma-badge--magnet-on {
	box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

/* Dropped on the X: shrink into it. */
#wbma-badge.wbma-badge--dismissed {
	transform: scale(0.3) !important;
}

@media (prefers-reduced-motion: reduce) {
	.wbma-dropzone,
	.wbma-dropzone__icon,
	.wbma-dropzone--active .wbma-dropzone__icon,
	#wbma-badge.wbma-badge--magnet {
		transition: none;
	}

	.wbma-dropzone--swallow .wbma-dropzone__icon {
		animation: none;
	}
}

.wbma-badge__icon {
	width: calc(22px * var(--wbma-scale, 1));
	height: calc(22px * var(--wbma-scale, 1));
	flex-shrink: 0;
	display: block;
}

.wbma-badge__label {
	display: inline-block;
	white-space: nowrap;
	color: var(--wbma-color, #ffffff);
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	line-height: 1.2;
	letter-spacing: 0;
}

.wbma-badge__grip {
	width: calc(12px * var(--wbma-scale, 1));
	height: calc(20px * var(--wbma-scale, 1));
	flex-shrink: 0;
	display: block;
	margin-left: 2px;
	opacity: 0.75;
	cursor: grab;
}

/* Keep the dots white even when the theme changes link/SVG hover colors. */
#wbma-badge .wbma-badge__grip circle {
	fill: #ffffff !important;
}

.wbma-badge--dragging .wbma-badge__grip {
	cursor: grabbing;
}

.wbma-badge--no-label .wbma-badge__label {
	display: none;
}

/*
 * Classic circle mode. --wbma-avoid is set by the script to the height of
 * whichever fixed bottom bar (mobile nav, sticky CTA) is currently visible.
 */
#wbma-badge.wbma-circle {
	position: fixed !important;
	/* A visible bar's height already includes the safe area, so take the larger of the two. */
	bottom: max(
		calc(var(--wbma-avoid, 0px) + var(--wbma-margin, 16px)),
		calc(var(--wbma-margin, 16px) + env(safe-area-inset-bottom, 0px))
	);
	right: calc(var(--wbma-margin, 16px) + env(safe-area-inset-right, 0px));
	left: auto;
	top: auto;
	z-index: var(--wbma-z, 9999);

	display: flex !important;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
	width: var(--wbma-size, 56px);
	height: var(--wbma-size, 56px);
	margin: 0;
	padding: 0;
	border-radius: 50%;
	background-color: #25D366 !important;
	color: #FFFFFF;
	text-decoration: none !important;
	opacity: 1 !important;
	visibility: visible !important;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: bottom 0.25s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

#wbma-badge.wbma-circle--left {
	right: auto;
	left: calc(var(--wbma-margin, 16px) + env(safe-area-inset-left, 0px));
}

#wbma-badge.wbma-circle:hover {
	transform: scale(1.06);
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

#wbma-badge.wbma-circle:active {
	transform: scale(0.96);
}

#wbma-badge.wbma-circle:focus-visible {
	outline: 3px solid #128C7E;
	outline-offset: 3px;
}

.wbma-circle__logo {
	display: block;
	width: 56%;
	height: 56%;
	flex-shrink: 0;
}

#wbma-badge .wbma-circle__logo path {
	fill: #FFFFFF !important;
}

@media (prefers-reduced-motion: reduce) {
	#wbma-badge.wbma-circle {
		transition: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.wbma-badge,
	.wbma-badge--dragging {
		transition: none;
	}
}

/*
 * The instant-checkout plugin hides #wbma-badge while its order form is on
 * screen (html.ma-ipc-form-in-view). This more specific rule wins when the
 * "Hide while the order form is on screen" setting is turned off.
 */
html.ma-ipc-form-in-view #wbma-badge.wbma-keep-visible {
	opacity: 1 !important;
	visibility: visible !important;
	pointer-events: auto !important;
}

@media (forced-colors: active) {
	.wbma-badge {
		border: 2px solid ButtonText;
		forced-color-adjust: none;
	}
}
