/* TWEKO Messengers — front v1.1 */
.twm {
	--twm-accent: #1473e6;
	--twm-accent-dark: #0b4fb3;
	--twm-offset: 24px;
	--twm-offset-m: 84px;
	--twm-size: 60px;
	--twm-ink: #22354d;
	--twm-muted: #6b7a8f;
	--twm-line: #e5ebf2;
	--twm-hover: #f7f9fc;
	position: fixed;
	bottom: var(--twm-bottom, var(--twm-offset));
	z-index: 9990;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 14px;
	font-family: inherit;
	line-height: 1.35;
	-webkit-tap-highlight-color: transparent;
}
@supports (color: color-mix(in srgb, red, blue)) {
	.twm { --twm-accent-dark: color-mix(in srgb, var(--twm-accent) 72%, #001a4d); }
}
.twm--right { right: 24px; }
.twm--left { left: 24px; align-items: flex-start; }
.twm *, .twm *::before, .twm *::after { box-sizing: border-box; }
.twm [hidden] { display: none !important; }
.twm svg { display: block; width: 100%; height: 100%; }
.twm button { font: inherit; letter-spacing: normal; text-transform: none; }

/* ---------- Кнопка-launcher ---------- */
.twm-toggle {
	position: relative;
	flex: 0 0 auto;
	width: var(--twm-size);
	height: var(--twm-size);
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--twm-accent);
	background: linear-gradient(145deg, var(--twm-accent) 0%, var(--twm-accent-dark) 100%);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 10px 24px rgba(20, 115, 230, .32), 0 2px 6px rgba(22, 50, 83, .16);
	transition: transform .2s ease, box-shadow .2s ease;
}
.twm-toggle__open,
.twm-toggle__close {
	position: absolute;
	inset: 0;
	margin: auto;
	width: 26px;
	height: 26px;
	transition: opacity .2s ease, transform .25s ease;
}
.twm-toggle__close { opacity: 0; transform: rotate(-90deg) scale(.6); }
.twm.is-open .twm-toggle__open { opacity: 0; transform: rotate(90deg) scale(.6); }
.twm.is-open .twm-toggle__close { opacity: 1; transform: none; }

/* Червона точка — поки відвідувач не відкривав віджет */
.twm-toggle__dot {
	position: absolute;
	top: 3px;
	right: 3px;
	width: 13px;
	height: 13px;
	border-radius: 50%;
	background: #ff4b4b;
	border: 2px solid #fff;
	transition: transform .2s ease, opacity .2s ease;
}
.twm.is-seen .twm-toggle__dot,
.twm.is-open .twm-toggle__dot { opacity: 0; transform: scale(0); }

/* ---------- Анімація кнопки ----------
   Короткий рух раз на ~6 с, решту часу кнопка спокійна.
   rotate/scale — окремі властивості, тож не конфліктують з transform при hover. */
.twm--anim-wiggle:not(.is-open):not(.is-seen) .twm-toggle,
.twm--anim-wiggle.twm--anim-always:not(.is-open) .twm-toggle {
	animation: twm-wiggle 6s ease-in-out 2s infinite;
}
.twm--anim-pulse:not(.is-open):not(.is-seen) .twm-toggle,
.twm--anim-pulse.twm--anim-always:not(.is-open) .twm-toggle {
	animation: twm-pulse 6s ease-in-out 2s infinite;
}
.twm--anim-both:not(.is-open):not(.is-seen) .twm-toggle,
.twm--anim-both.twm--anim-always:not(.is-open) .twm-toggle {
	animation: twm-both 6s ease-in-out 2s infinite;
}
/* М'яке кільце-хвиля для пульсації */
.twm--anim-pulse:not(.is-open):not(.is-seen) .twm-toggle::before,
.twm--anim-pulse.twm--anim-always:not(.is-open) .twm-toggle::before,
.twm--anim-both:not(.is-open):not(.is-seen) .twm-toggle::before,
.twm--anim-both.twm--anim-always:not(.is-open) .twm-toggle::before {
	content: "";
	position: absolute;
	inset: 0;
	border-radius: 50%;
	background: var(--twm-accent);
	opacity: 0;
	z-index: -1;
	pointer-events: none;
	animation: twm-ring 6s ease-out 2s infinite;
}
/* Під курсором — пауза, щоб кнопка не «тікала» */
.twm-toggle:hover,
.twm-toggle:hover::before { animation-play-state: paused !important; }

@keyframes twm-wiggle {
	0%, 76%, 100% { rotate: 0deg; }
	80% { rotate: -12deg; }
	84% { rotate: 10deg; }
	88% { rotate: -7deg; }
	92% { rotate: 4deg; }
	96% { rotate: 0deg; }
}
@keyframes twm-pulse {
	0%, 70%, 100% { scale: 1; }
	76% { scale: 1.08; }
	82% { scale: .97; }
	88% { scale: 1.05; }
	94% { scale: 1; }
}
@keyframes twm-both {
	0%, 74%, 100% { rotate: 0deg; scale: 1; }
	78% { rotate: -10deg; scale: 1.07; }
	82% { rotate: 9deg; scale: 1.07; }
	86% { rotate: -6deg; scale: 1.04; }
	90% { rotate: 3deg; scale: 1.02; }
	94% { rotate: 0deg; scale: 1; }
}
@keyframes twm-ring {
	0%, 74% { opacity: 0; transform: scale(1); }
	76% { opacity: .35; transform: scale(1); }
	96%, 100% { opacity: 0; transform: scale(1.6); }
}

/* ---------- Вітання ---------- */
.twm-greet {
	position: relative;
	max-width: 290px;
	background: #fff;
	border: 1px solid var(--twm-line);
	border-radius: 14px;
	box-shadow: 0 12px 30px rgba(22, 50, 83, .14);
	animation: twm-in .28s ease both;
}
.twm-greet::after {
	content: "";
	position: absolute;
	bottom: -7px;
	right: 23px;
	width: 13px;
	height: 13px;
	background: #fff;
	border-right: 1px solid var(--twm-line);
	border-bottom: 1px solid var(--twm-line);
	transform: rotate(45deg);
}
.twm--left .twm-greet::after { right: auto; left: 23px; }
.twm-greet__body {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	margin: 0;
	padding: 13px 38px 13px 14px;
	border: 0;
	border-radius: 14px;
	background: transparent;
	color: var(--twm-ink);
	text-align: left;
	cursor: pointer;
}
.twm-greet__icon {
	flex: 0 0 36px;
	width: 36px;
	height: 36px;
	padding: 8px;
	border-radius: 10px;
	background: #eaf2fd;
	color: var(--twm-accent);
}
.twm-greet__copy { display: block; min-width: 0; }
.twm-greet__title { display: block; font-size: 14px; font-weight: 700; color: #16243a; margin-bottom: 2px; }
.twm-greet__text { display: block; font-size: 13px; color: #3b4c63; }
.twm-greet__close {
	position: absolute;
	top: 7px;
	right: 7px;
	width: 24px;
	height: 24px;
	padding: 5px;
	margin: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #8a95a5;
	cursor: pointer;
}

/* ---------- Вікно ---------- */
.twm-panel {
	display: flex;
	flex-direction: column;
	width: 320px;
	max-height: calc(100vh - var(--twm-bottom, var(--twm-offset)) - var(--twm-size) - 40px);
	background: #fff;
	border: 1px solid var(--twm-line);
	border-radius: 16px;
	box-shadow: 0 14px 36px rgba(22, 50, 83, .14);
	overflow: hidden;
	animation: twm-in .22s ease both;
}
.twm-panel__head {
	flex: 0 0 auto;
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 18px 16px 18px 20px;
	background: var(--twm-accent);
	background: linear-gradient(120deg, var(--twm-accent) 0%, var(--twm-accent-dark) 100%);
	color: #fff;
}
.twm-panel__logo {
	flex: 0 0 40px;
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
}
#twm .twm-panel__logo img {
	display: block;
	width: 40px;
	height: 40px;
	max-width: none;
	object-fit: contain;
	margin: 0;
	border: 0;
	box-shadow: none;
}
#twm .twm-panel__logo--white img { filter: brightness(0) invert(1); }
.twm-panel__head-text { flex: 1 1 auto; min-width: 0; }
.twm-panel__title { font-size: 18px; font-weight: 700; line-height: 1.25; }
.twm-panel__sub { margin-top: 3px; font-size: 13px; opacity: .88; }
.twm-panel__close {
	flex: 0 0 32px;
	width: 32px;
	height: 32px;
	align-self: flex-start;
	margin: -4px -4px 0 0;
	padding: 7px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: #fff;
	cursor: pointer;
	transition: background .15s ease;
}
.twm-panel__list {
	flex: 1 1 auto;
	list-style: none;
	margin: 0;
	padding: 8px;
	overflow-y: auto;
	overscroll-behavior: contain;
}
.twm-panel__list li { margin: 0; padding: 0; list-style: none; }
.twm-panel__list li::before { content: none; display: none; }
.twm-panel__list { display: flex; flex-direction: column; gap: 2px; }
/* #twm — вища специфічність, щоб стилі посилань теми (підкреслення, рамки) не перебивали віджет */
#twm .twm-item a,
#twm .twm-item a:hover,
#twm .twm-item a:focus,
#twm .twm-item a:active,
#twm .twm-item a:visited {
	text-decoration: none;
	border: 0;
	box-shadow: none;
	outline: none;
	color: var(--twm-ink);
}
#twm .twm-item a * { text-decoration: none; }
.twm-item a {
	display: flex;
	align-items: center;
	gap: 14px;
	width: 100%;
	min-height: 64px;
	padding: 10px 12px;
	border-radius: 12px;
	color: var(--twm-ink);
	text-decoration: none;
	transition: background .2s ease;
}
.twm-item__icon {
	flex: 0 0 44px;
	width: 44px;
	height: 44px;
	padding: 10px;
	border-radius: 50%;
	color: #fff;
	transition: transform .2s ease, box-shadow .2s ease;
}
.twm-item--wa .twm-item__icon { background: #25d366; }
.twm-item--viber .twm-item__icon { background: #7360f2; }
.twm-item--tg .twm-item__icon { background: #229ed9; padding: 10px 11px 10px 9px; }
.twm-item__copy { flex: 1 1 auto; min-width: 0; }
.twm-item__label { display: block; font-size: 15px; font-weight: 600; color: var(--twm-ink); transition: color .2s ease; }
.twm-item__sub { display: block; margin-top: 1px; font-size: 12.5px; color: var(--twm-muted); }
.twm-item__arrow {
	flex: 0 0 18px;
	width: 18px;
	height: 18px;
	color: var(--twm-accent);
	transition: transform .2s ease;
}

@keyframes twm-in {
	from { opacity: 0; transform: translateY(8px); }
	to { opacity: 1; transform: none; }
}

/* Hover лише для пристроїв з мишею */
@media (hover: hover) {
	.twm-toggle:hover { transform: translateY(-2px); box-shadow: 0 14px 30px rgba(20, 115, 230, .38), 0 2px 6px rgba(22, 50, 83, .16); }
	#twm .twm-item a:hover { background: #f2f6fc; }
	#twm .twm-item a:hover .twm-item__label { color: var(--twm-accent); }
	#twm .twm-item a:hover .twm-item__icon { transform: scale(1.06); box-shadow: 0 4px 12px rgba(22, 50, 83, .16); }
	#twm .twm-item a:hover .twm-item__arrow { transform: translateX(3px); }
	.twm-greet__close:hover { color: var(--twm-ink); background: var(--twm-hover); }
	.twm-panel__close:hover { background: rgba(255, 255, 255, .16); }
}
/* На сенсорних — лише короткий ефект натискання */
@media (hover: none) {
	#twm .twm-item a:active { background: #f2f6fc; }
	.twm-toggle:active { transform: scale(.95); }
}

/* ---------- Мобільний ---------- */
@media (max-width: 767px) {
	.twm { --twm-size: 56px; bottom: var(--twm-bottom, var(--twm-offset-m)); gap: 12px; }
	.twm--right { right: 16px; }
	.twm--left { left: 16px; }
	.twm-greet { max-width: calc(100vw - 32px); }
	.twm-panel {
		width: min(320px, calc(100vw - 32px));
		max-height: min(78vh, calc(100vh - var(--twm-bottom, var(--twm-offset-m)) - var(--twm-size) - 28px));
	}
	.twm-panel__head { padding: 16px 14px 16px 18px; }
	.twm-panel__title { font-size: 17px; }
	.twm-panel__logo, #twm .twm-panel__logo img { flex-basis: 36px; width: 36px; height: 36px; }
	.twm-item a { min-height: 60px; padding: 9px 10px; }
	.twm-item__icon { flex-basis: 40px; width: 40px; height: 40px; padding: 9px; }
}
/* Viber лише на мобільних (якщо вимкнено показ на ПК) */
@media (min-width: 768px) and (hover: hover) {
	.twm-item--mobile-only { display: none; }
}

@media (prefers-reduced-motion: reduce) {
	.twm *, .twm *::before, .twm *::after { animation: none !important; transition: none !important; }
}

/* Чужі рамки фокусу/посилань (тема, віджет доступності) всередині віджета вимикаємо.
   Для клавіатури лишаємо власне акуратне кільце через box-shadow. */
#twm,
#twm *,
#twm *:focus,
#twm *:active,
#twm *:hover {
	outline: none !important;
}
#twm .twm-toggle,
#twm .twm-toggle:focus,
#twm .twm-toggle:active,
#twm .twm-item a,
#twm .twm-item a:focus,
#twm .twm-item a:active {
	border: 0 !important;
}
#twm .twm-toggle:focus { box-shadow: 0 10px 24px rgba(20, 115, 230, .32), 0 2px 6px rgba(22, 50, 83, .16) !important; }
#twm .twm-toggle:focus-visible { box-shadow: 0 0 0 3px #fff, 0 0 0 6px rgba(20, 115, 230, .55) !important; }
#twm .twm-item a:focus-visible { box-shadow: inset 0 0 0 2px var(--twm-accent) !important; }
#twm .twm-panel__close:focus-visible,
#twm .twm-greet__close:focus-visible { box-shadow: 0 0 0 2px currentColor !important; }
