/* ==========================================================================
   ChatCom – Frontend styles
   ========================================================================== */

/* Entrance animation for the trigger button */
@keyframes chatcom-pop-in {
	0%   { opacity: 0; transform: scale(0.5); }
	70%  { transform: scale(1.08); }
	100% { opacity: 1; transform: scale(1); }
}

/* Widget container (fixed to viewport) */
.chatcom-widget {
	position: fixed;
	bottom: 24px;
	z-index: 99999;
}

.chatcom-pos-left   { left: 24px; }
.chatcom-pos-center { left: 50%; transform: translateX(-50%); }
.chatcom-pos-right  { right: 24px; }

/* --------------------------------------------------------------------------
   Trigger button
   -------------------------------------------------------------------------- */

.chatcom-trigger {
	display: flex;
	align-items: center;
	justify-content: center;
	width:  var(--chatcom-size, 60px);
	height: var(--chatcom-size, 60px);
	border-radius: 50%;
	background-color: var(--chatcom-color, #0073aa);
	border: none;
	cursor: pointer;
	padding: 0;
	overflow: hidden;
	box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
	transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
	color: var(--chatcom-icon-color, #ffffff);
	/* Hidden until JS triggers the entrance */
	opacity: 0;
	pointer-events: none;
}

.chatcom-trigger.is-visible {
	animation: chatcom-pop-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
	pointer-events: auto;
}

.chatcom-trigger:hover {
	transform: scale(1.12) translateY(-2px);
	box-shadow: 0 8px 26px rgba(0, 0, 0, 0.34);
}

.chatcom-trigger:focus-visible {
	outline: 3px solid #fff;
	outline-offset: 2px;
}

/* The center-positioned widget has transform on the container; override the
   trigger hover so it scales within that context. */
.chatcom-pos-center .chatcom-trigger:hover {
	transform: scale(1.09);
}

.chatcom-svg-icon {
	width: 52%;
	height: 52%;
	fill: currentColor;
	pointer-events: none;
}

.chatcom-custom-img {
	max-width: 100%;
	max-height: 100%;
	width: auto;
	height: auto;
	object-fit: contain;
	display: block;
}

/* When a custom image is used, remove the circle shape and clipping */
.chatcom-trigger:has(.chatcom-custom-img) {
	border-radius: 0;
	background-color: transparent;
	overflow: visible;
	box-shadow: none;
	padding: 0;
}

/* --------------------------------------------------------------------------
   Popup panel
   -------------------------------------------------------------------------- */

.chatcom-popup {
	position: absolute;
	bottom: calc(var(--chatcom-size, 60px) + 14px);
	width: var(--chatcom-popup-w, 400px);
	max-width: calc(100vw - 48px);
	background: #fff;
	border-radius: 12px;
	box-shadow: 0 8px 40px rgba(0, 0, 0, 0.22);
	overflow: hidden;

	/* Hidden / closed state */
	opacity: 0;
	visibility: hidden;
	transform: translateY(10px);
	transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}

/* Anchor left/right positions to the matching edge */
.chatcom-pos-left  .chatcom-popup { left: 0; }
.chatcom-pos-right .chatcom-popup { right: 0; }

/* Centre: keep translateX(-50%) at all times so the animation Y-offset
   stacks correctly without overriding the horizontal centring. */
.chatcom-pos-center .chatcom-popup {
	left: 50%;
	transform: translateX(-50%) translateY(10px);
}

/* Open states */
.chatcom-widget.is-open .chatcom-popup {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
	transition: opacity 0.22s ease, transform 0.22s ease;
}

.chatcom-pos-center.is-open .chatcom-popup {
	transform: translateX(-50%) translateY(0);
}

/* --------------------------------------------------------------------------
   Popup header
   -------------------------------------------------------------------------- */

.chatcom-popup-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 12px 14px;
	background-color: var(--chatcom-header-bg, #0073aa);
	color: var(--chatcom-header-text, #ffffff);
	min-height: 50px;
}

.chatcom-header-img {
	display: block;
	height: 28px;
	width: auto;
	max-width: 80px;
	object-fit: contain;
	flex-shrink: 0;
}

.chatcom-popup-title {
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
	flex: 1;
}

/* Close button */
.chatcom-close-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	width: 28px;
	height: 28px;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	border: none;
	cursor: pointer;
	padding: 0;
	margin-left: auto;
	color: var(--chatcom-header-text, #ffffff);
	transition: background 0.15s ease;
}

.chatcom-close-btn:hover  { background: rgba(255, 255, 255, 0.38); }
.chatcom-close-btn:focus-visible {
	outline: 2px solid var(--chatcom-header-text, #ffffff);
	outline-offset: 2px;
}

.chatcom-close-btn svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
	pointer-events: none;
}

/* --------------------------------------------------------------------------
   Popup body (embed area)
   -------------------------------------------------------------------------- */

.chatcom-popup-body {
	overflow-y: auto;
	max-height: 70vh;
	line-height: 0; /* collapse whitespace around block-level embeds */
}

.chatcom-popup-body iframe {
	display: block;
	width: 100%;
	border: none;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {
	.chatcom-trigger {
		width:  calc(var(--chatcom-size, 60px) * 0.75);
		height: calc(var(--chatcom-size, 60px) * 0.75);
	}
}

@media (max-width: 480px) {
	.chatcom-widget {
		bottom: 16px;
	}
	.chatcom-pos-left   { left: 16px; }
	.chatcom-pos-right  { right: 16px; }

	.chatcom-popup {
		max-width: calc(100vw - 32px);
	}

	/* On mobile, left/right anchored popups should not overflow the
	   opposite edge – shift toward screen centre if needed. */
	.chatcom-pos-left  .chatcom-popup { left: 0; right: auto; }
	.chatcom-pos-right .chatcom-popup { right: 0; left: auto; }
}
