/**
 * Joingram front-end styles.
 */
.joingram {
	--jg-bg: #229ED9;
	--jg-fg: #ffffff;
	--jg-box-bg: #ffffff;
	--jg-box-fg: #111b21;
	--jg-bubble-bg: #f0f2f5;
	--jg-bubble-fg: #111b21;
	--jg-shadow: 0 6px 24px rgba(0, 0, 0, .22);
	--jg-size: 60px;
	--jg-offset: 24px;

	position: fixed;
	bottom: var(--jg-offset);
	z-index: 9000;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
}

.joingram[hidden] { display: block !important; }

/* CSS-driven reveal: works even if JS is delayed (e.g. WP Rocket "Delay JS") */
.joingram--delay .joingram__button {
	animation: jg-show .45s cubic-bezier(.18, .89, .32, 1.28) var(--jg-delay, 0s) both;
}
@keyframes jg-show {
	from { transform: scale(0); opacity: 0; }
	to   { transform: scale(1); opacity: 1; }
}

.joingram--right { right: var(--jg-offset); }
.joingram--left  { left: var(--jg-offset); }

/* ---------- Button ---------- */
.joingram__button {
	position: relative;
	width: var(--jg-size);
	height: var(--jg-size);
	border-radius: 50%;
	background: var(--jg-bg);
	color: var(--jg-fg);
	box-shadow: var(--jg-shadow);
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: transform .3s cubic-bezier(.18, .89, .32, 1.28), box-shadow .2s;
	outline: none;
}
.joingram__button:hover,
.joingram__button:focus-visible { box-shadow: 0 8px 28px rgba(0, 0, 0, .3); }
.joingram__button:active { transform: scale(.92); }

.joingram__button__ico {
	position: absolute;
	inset: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	overflow: hidden;
	transition: opacity .3s;
}
.joingram__button__ico svg { display: block; }

/* custom image / gif / video overlay */
.joingram__button__image {
	position: absolute;
	inset: 2px;
	border-radius: 50%;
	overflow: hidden;
	opacity: 0;
	/* alternate mode: fade in/out over the icon every cycle */
	animation: jg-image-loop 20s linear 5s infinite both;
}
.joingram__button__image img,
.joingram__button__image video {
	display: block;
	width: 100%; height: 100%;
	object-fit: cover;
	object-position: center;
}

/* fixed mode: image always visible, icon hidden, no animation */
.joingram--img .joingram__button__image { opacity: 1; animation: none; }
.joingram--img .joingram__button__ico { opacity: 0; }

@keyframes jg-image-loop {
	0%        { opacity: 0; }
	3%, 20%   { opacity: 1; }
	25%, 100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
	.joingram__button__image { animation: none; }
}

/* gentle pulse to draw attention */
.joingram__button::before {
	content: "";
	position: absolute; inset: 0;
	border-radius: 50%;
	box-shadow: 0 0 0 0 var(--jg-bg);
	opacity: .55;
	animation: jg-pulse 2.4s infinite;
}
@keyframes jg-pulse {
	0%   { box-shadow: 0 0 0 0 var(--jg-bg); opacity: .5; }
	70%  { box-shadow: 0 0 0 16px var(--jg-bg); opacity: 0; }
	100% { box-shadow: 0 0 0 0 var(--jg-bg); opacity: 0; }
}
.joingram--box-open .joingram__button::before { animation: none; }

/* ---------- Tooltip ---------- */
.joingram__tooltip {
	position: absolute;
	bottom: 50%;
	transform: translateY(50%);
	white-space: nowrap;
	pointer-events: none;
	opacity: 0;
	transition: opacity .2s;
}
.joingram--right .joingram__tooltip { right: calc(var(--jg-size) + 12px); }
.joingram--left  .joingram__tooltip { left:  calc(var(--jg-size) + 12px); }
.joingram__tooltip > div {
	background: #111b21; color: #fff;
	font-size: 14px; line-height: 1.3;
	padding: 8px 12px; border-radius: 8px;
	box-shadow: var(--jg-shadow);
}
.joingram__button:hover .joingram__tooltip { opacity: 1; }
.joingram--box-open .joingram__tooltip { display: none; }

/* ---------- Badge ---------- */
.joingram__badge {
	position: absolute;
	top: -4px;
	width: 22px; height: 22px;
	border-radius: 50%;
	background: #ff3b30; color: #fff;
	font-size: 13px; font-weight: 700;
	display: flex; align-items: center; justify-content: center;
	box-shadow: 0 2px 6px rgba(0, 0, 0, .25);
	transform: scale(0);
	transition: transform .3s cubic-bezier(.18, .89, .32, 1.28);
}
.joingram--right .joingram__badge { right: -4px; }
.joingram--left  .joingram__badge { left: -4px; }
.joingram--show-badge .joingram__badge { transform: scale(1); }
.joingram--box-open .joingram__badge { transform: scale(0); }

/* ---------- Chat box ---------- */
.joingram__box {
	position: absolute;
	bottom: calc(var(--jg-size) + 16px);
	width: 320px;
	max-width: calc(100vw - 2 * var(--jg-offset));
	background: var(--jg-box-bg);
	color: var(--jg-box-fg);
	border-radius: 18px;
	box-shadow: var(--jg-shadow);
	overflow: hidden;
	transform: translateY(12px) scale(.96);
	transform-origin: bottom right;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity .25s, transform .25s, visibility .25s;
}
.joingram--right .joingram__box { right: 0; }
.joingram--left  .joingram__box { left: 0; transform-origin: bottom left; }
.joingram--box-open .joingram__box {
	opacity: 1; visibility: visible; pointer-events: auto;
	transform: translateY(0) scale(1);
}

.joingram__header {
	display: flex; align-items: center; justify-content: space-between;
	gap: 8px;
	padding: 14px 16px;
	background: var(--jg-bg); color: var(--jg-fg);
}
.joingram__title { font-weight: 600; font-size: 15px; }
.joingram__brand { display: inline-flex; align-items: center; gap: 6px; }
.joingram__brand svg { width: 22px; height: 22px; }
.joingram__close {
	width: 26px; height: 26px; border-radius: 50%;
	cursor: pointer; position: relative; flex: 0 0 auto;
	opacity: .85; transition: opacity .2s, background .2s;
}
.joingram__close:hover { opacity: 1; background: rgba(255, 255, 255, .15); }
.joingram__close::before,
.joingram__close::after {
	content: ""; position: absolute; top: 50%; left: 50%;
	width: 14px; height: 2px; background: currentColor; border-radius: 2px;
}
.joingram__close::before { transform: translate(-50%, -50%) rotate(45deg); }
.joingram__close::after  { transform: translate(-50%, -50%) rotate(-45deg); }

.joingram__scroll { max-height: min(60vh, 420px); overflow-y: auto; }
.joingram__content { padding: 18px 16px 16px; }

/* message bubbles */
.joingram__bubble {
	position: relative;
	background: var(--jg-bubble-bg);
	color: var(--jg-bubble-fg);
	padding: 10px 14px;
	border-radius: 14px;
	border-top-left-radius: 4px;
	font-size: 14.5px; line-height: 1.45;
	margin-bottom: 10px;
	max-width: 90%;
	box-shadow: 0 1px 1px rgba(0, 0, 0, .06);
	animation: jg-bubble-in .35s both;
	word-wrap: break-word;
}
.joingram__bubble:nth-child(2) { animation-delay: .1s; }
.joingram__bubble:nth-child(3) { animation-delay: .2s; }
@keyframes jg-bubble-in {
	from { opacity: 0; transform: translateY(8px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* CTA */
.joingram__open {
	display: flex; align-items: center; justify-content: center; gap: 8px;
	margin-top: 6px;
	padding: 12px 16px;
	background: var(--jg-bg); color: var(--jg-fg);
	border-radius: 12px;
	font-size: 15px; font-weight: 600;
	cursor: pointer;
	transition: filter .2s, transform .1s;
}
.joingram__open:hover { filter: brightness(1.06); }
.joingram__open:active { transform: scale(.98); }
.joingram__open svg { width: 22px; height: 22px; }

/* ---------- Dark mode ---------- */
.joingram--dark,
.joingram--dark-auto {
	--jg-box-bg: #1f2c34;
	--jg-box-fg: #e9edef;
	--jg-bubble-bg: #2a3942;
	--jg-bubble-fg: #e9edef;
}
@media (prefers-color-scheme: light) {
	.joingram--dark-auto {
		--jg-box-bg: #ffffff;
		--jg-box-fg: #111b21;
		--jg-bubble-bg: #f0f2f5;
		--jg-bubble-fg: #111b21;
	}
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
	.joingram { --jg-size: 54px; --jg-offset: 16px; }
	.joingram__box { width: calc(100vw - 32px); }
}

/* ---------- Powered by ---------- */
.joingram__powered {
	display: block;
	text-align: center;
	padding: 8px;
	font-size: 11px;
	text-decoration: none;
	color: #8696a0;
	background: var(--jg-box-bg);
}
.joingram__powered span { color: var(--jg-bg); font-weight: 600; }
