/**
 * Right-rail live chat window (opened from the floating enquiry icon).
 * Every message that contains an email / WhatsApp number is stored in the
 * `tux_inquiry` custom post type through admin-ajax.php.
 */

/* 聊天窗打开时只隐藏主触发按钮（避免与面板重叠），回到顶部按钮保持可见可用。 */
.tux-floating-widgets.is-chat-open .tux-float-btn--trigger {
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: scale(0.85);
}
.tux-floating-widgets.is-chat-open .tux-float-btn--top {
	opacity: 1 !important;
	visibility: visible !important;
	pointer-events: auto !important;
	transform: none !important;
}

.tux-live-chat [hidden] {
	display: none !important;
}

.tux-live-chat {
	position: fixed;
	right: 10px;
	bottom: 96px;
	z-index: 99997;
	display: flex;
	flex-direction: column;
	width: 376px;
	max-width: calc(100vw - 24px);
	height: min(600px, calc(100vh - 170px));
	background: #ffffff;
	border-radius: 20px;
	box-shadow: 0 26px 64px rgba(103, 55, 78, 0.28);
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateY(16px) scale(0.98);
	transition: opacity 0.24s ease, transform 0.24s ease, visibility 0.24s;
}

.tux-live-chat.is-open {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: none;
}

/* ---------- Header ---------- */
.tux-live-chat__header {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--accent, #ae3f72) 0%, #831843 100%);
	color: #ffffff;
}

.tux-live-chat__avatar {
	position: relative;
	flex-shrink: 0;
}

.tux-live-chat__avatar img {
	display: block;
	width: 42px;
	height: 42px;
	border-radius: 50%;
	object-fit: cover;
	box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

.tux-live-chat__dot {
	position: absolute;
	right: 1px;
	bottom: 1px;
	width: 11px;
	height: 11px;
	border-radius: 50%;
	background: #22c55e;
	border: 2px solid #ffffff;
}

.tux-live-chat__meta {
	flex: 1;
	min-width: 0;
}

.tux-live-chat__name {
	margin: 0;
	font-size: 0.98rem;
	font-weight: 850;
	line-height: 1.25;
	color: #ffffff;
}

.tux-live-chat__status {
	display: block;
	font-size: 0.74rem;
	font-weight: 700;
	color: #dcfce7;
	line-height: 1.3;
	margin-top: 2px;
}

.tux-live-chat__close {
	flex-shrink: 0;
	width: 30px;
	height: 30px;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.16);
	border: 0;
	border-radius: 50%;
	color: #ffffff;
	font-size: 20px;
	line-height: 1;
	cursor: pointer;
	transition: background 0.2s ease;
}

.tux-live-chat__close:hover {
	background: rgba(255, 255, 255, 0.3);
}

/* ---------- Conversation ---------- */
.tux-live-chat__thread {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 16px 14px 8px;
	background: linear-gradient(180deg, #fff8fb 0%, #fdf6f9 100%);
	scrollbar-width: thin;
}

.tux-live-chat__thread::-webkit-scrollbar {
	width: 6px;
}

.tux-live-chat__thread::-webkit-scrollbar-thumb {
	background: #e6d3dc;
	border-radius: 999px;
}

.tux-chat-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin-bottom: 12px;
}

.tux-chat-row--me {
	justify-content: flex-end;
}

.tux-chat-row__avatar {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
	box-shadow: 0 2px 8px rgba(103, 55, 78, 0.14);
}

.tux-chat-row__body {
	max-width: 82%;
}

.tux-chat-bubble {
	padding: 11px 15px;
	border-radius: 16px 16px 16px 4px;
	background: #ffffff;
	border: 1px solid #f0dfe7;
	color: #3f2a36;
	font-size: 0.9rem;
	line-height: 1.55;
	box-shadow: 0 4px 14px rgba(103, 55, 78, 0.07);
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.tux-chat-bubble strong {
	color: var(--accent, #ae3f72);
	font-weight: 850;
}

.tux-chat-row--me .tux-chat-bubble {
	border: 0;
	border-radius: 16px 16px 4px 16px;
	background: var(--accent, #ae3f72);
	color: #ffffff;
	box-shadow: 0 6px 16px rgba(174, 63, 114, 0.22);
}

.tux-chat-bubble--error {
	background: #fef2f2;
	border-color: #fecaca;
	color: #b91c1c;
}

.tux-chat-row__time {
	display: block;
	margin-top: 4px;
	font-size: 0.68rem;
	color: #9a8a92;
	letter-spacing: 0.01em;
}

.tux-chat-row--me .tux-chat-row__time {
	text-align: right;
}

/* Typing indicator */
.tux-chat-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 12px 16px;
}

.tux-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #d1b4c2;
	animation: tux-chat-bounce 1.1s infinite ease-in-out;
}

.tux-chat-typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.tux-chat-typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes tux-chat-bounce {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.55;
	}
	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* ---------- Quick chips ---------- */
.tux-live-chat__chips {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.tux-chat-chip {
	padding: 7px 12px;
	border: 1px solid #ecd6e0;
	border-radius: 999px;
	background: #ffffff;
	color: #8b3d61;
	font-size: 0.76rem;
	font-weight: 750;
	line-height: 1.2;
	cursor: pointer;
	transition: all 0.18s ease;
}

.tux-chat-chip:hover {
	background: var(--accent, #ae3f72);
	border-color: var(--accent, #ae3f72);
	color: #ffffff;
}

/* ---------- Step 1: intro + form ---------- */
.tux-chat-step--form {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 12px 14px 14px;
	background: linear-gradient(180deg, #fff8fb 0%, #fdf6f9 100%);
}

.tux-chat-intro {
	display: flex;
	align-items: flex-start;
	gap: 10px;
}

.tux-chat-intro__avatar {
	flex-shrink: 0;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	object-fit: cover;
	box-shadow: 0 4px 12px rgba(103, 55, 78, 0.16);
}

.tux-chat-intro__body {
	flex: 1;
	min-width: 0;
	padding: 10px 13px;
	background: #ffffff;
	border: 1px solid #f0dfe7;
	border-radius: 4px 14px 14px 14px;
	box-shadow: 0 4px 14px rgba(103, 55, 78, 0.06);
}

.tux-chat-intro__title {
	margin: 0 0 3px;
	font-size: 0.86rem;
	font-weight: 850;
	line-height: 1.3;
	color: #3f2a36;
}

.tux-chat-intro__text {
	margin: 0;
	font-size: 0.78rem;
	line-height: 1.5;
	color: #6b5561;
}

/* ---------- Enquiry form ---------- */
.tux-chat-form {
	display: flex;
	flex-direction: column;
	gap: 7px;
	padding: 12px;
	background: #ffffff;
	border: 1px solid #f1e3ea;
	border-radius: 14px;
	box-shadow: 0 6px 18px rgba(103, 55, 78, 0.05);
}

.tux-chat-form__error {
	padding: 8px 10px;
	border: 1px solid #fecaca;
	border-radius: 10px;
	background: #fef2f2;
	color: #b91c1c;
	font-size: 0.76rem;
	line-height: 1.45;
}

.tux-chat-form__row {
	display: flex;
	gap: 8px;
}

.tux-chat-form__field {
	flex: 1 1 0;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.tux-chat-form__field > span {
	font-size: 0.64rem;
	font-weight: 800;
	letter-spacing: 0.03em;
	text-transform: uppercase;
	color: #8b6b78;
	line-height: 1.2;
}

.tux-chat-form__field input,
.tux-chat-form__field textarea {
	width: 100%;
	box-sizing: border-box;
	padding: 8px 11px;
	border: 1px solid #e7d7df;
	border-radius: 10px;
	background: #fdf8fa;
	color: #33212b;
	font-family: inherit;
	font-size: 0.82rem;
	line-height: 1.35;
	outline: none;
	transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.tux-chat-form__field textarea {
	min-height: 46px;
	resize: none;
}

.tux-chat-form__field input:focus,
.tux-chat-form__field textarea:focus {
	border-color: var(--accent, #ae3f72);
	background: #ffffff;
	box-shadow: 0 0 0 3px rgba(174, 63, 114, 0.1);
}

.tux-chat-form__field input::placeholder,
.tux-chat-form__field textarea::placeholder {
	color: #b6a1ab;
}

.tux-chat-form__submit {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
	padding: 10px 14px;
	border: 0;
	border-radius: 999px;
	background: var(--accent, #ae3f72);
	color: #ffffff;
	font-family: inherit;
	font-size: 0.86rem;
	font-weight: 800;
	line-height: 1.2;
	cursor: pointer;
	box-shadow: 0 6px 18px rgba(174, 63, 114, 0.24);
	transition: background 0.2s ease, transform 0.2s ease;
}

.tux-chat-form__submit:hover {
	background: #8f2f5c;
	transform: translateY(-1px);
}

.tux-chat-form__submit:disabled {
	opacity: 0.65;
	cursor: default;
	transform: none;
}

/* ---------- Step 2: composer ---------- */
.tux-live-chat__composer {
	flex-shrink: 0;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	background: #ffffff;
	border-top: 1px solid #f1e3ea;
}

.tux-live-chat__input {
	flex: 1;
	min-height: 40px;
	max-height: 88px;
	padding: 10px 14px;
	border: 1px solid #e7d7df;
	border-radius: 20px;
	background: #fdf8fa;
	color: #33212b;
	font-family: inherit;
	font-size: 0.86rem;
	line-height: 1.4;
	resize: none;
	outline: none;
	box-sizing: border-box;
	transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.tux-live-chat__input:focus {
	border-color: var(--accent, #ae3f72);
	background: #ffffff;
	box-shadow: 0 0 0 3px rgba(174, 63, 114, 0.1);
}

.tux-live-chat__input::placeholder {
	color: #b6a1ab;
}

.tux-live-chat__send {
	flex-shrink: 0;
	width: 40px;
	height: 40px;
	display: flex;
	align-items: center;
	justify-content: center;
	border: 0;
	border-radius: 50%;
	background: var(--accent, #ae3f72);
	color: #ffffff;
	cursor: pointer;
	transition: transform 0.18s ease, background 0.18s ease;
}

.tux-live-chat__send:hover {
	background: #8f2f5c;
	transform: scale(1.05);
}

.tux-live-chat__send svg {
	display: block;
}

/* ---------- Other contact channels ---------- */
.tux-live-chat__channels {
	flex-shrink: 0;
	display: flex;
	align-items: center;
	gap: 6px;
	padding: 8px 12px 10px;
	background: #ffffff;
	border-top: 1px solid #f1e3ea;
}

.tux-live-chat__channel {
	flex: 1 1 0;
	min-width: 0;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 5px;
	padding: 7px 6px;
	border: 1px solid #eedee5;
	border-radius: 999px;
	background: #fdf8fa;
	color: #8b3d61;
	font-family: inherit;
	font-size: 0.7rem;
	font-weight: 750;
	line-height: 1.1;
	text-decoration: none;
	white-space: nowrap;
	cursor: pointer;
	transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.tux-live-chat__channel:hover {
	background: var(--accent, #ae3f72);
	border-color: var(--accent, #ae3f72);
	color: #ffffff;
}

.tux-live-chat__channel svg {
	flex-shrink: 0;
}

/* ---------- WeChat QR card ---------- */
.tux-live-chat__qr {
	position: absolute;
	left: 14px;
	right: 14px;
	bottom: 104px;
	z-index: 6;
	display: none;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	padding: 14px 16px 16px;
	background: #ffffff;
	border: 1px solid #f0dfe7;
	border-radius: 16px;
	box-shadow: 0 16px 40px rgba(103, 55, 78, 0.22);
}

.tux-live-chat__qr.is-visible {
	display: flex;
}

.tux-live-chat__qr-head {
	width: 100%;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	font-size: 0.86rem;
	color: #3f2a36;
}

.tux-live-chat__qr-head button {
	background: none;
	border: 0;
	padding: 0 4px;
	font-size: 20px;
	line-height: 1;
	color: #8b3d61;
	cursor: pointer;
}

.tux-live-chat__qr img {
	width: 150px;
	height: 150px;
	object-fit: contain;
	border-radius: 10px;
	background: #f8eef3;
}

.tux-live-chat__qr p {
	margin: 0;
	font-size: 0.76rem;
	line-height: 1.4;
	color: #6b5561;
	text-align: center;
}

/* ---------- Mobile: bottom sheet ---------- */
@media (max-width: 768px) {
	.tux-live-chat {
		right: 12px;
		left: 12px;
		bottom: calc(74px + env(safe-area-inset-bottom, 0px));
		width: auto;
		max-width: none;
		height: min(82vh, 620px);
		border-radius: 18px;
	}

	/* 手机端聊天是近乎全屏的底部弹层，回顶按钮会压在聊天输入栏上；
	   此处仍按原行为隐藏，桌面端（>768）保持可见 */
	.tux-floating-widgets.is-chat-open .tux-float-btn--top {
		opacity: 0 !important;
		visibility: hidden !important;
		pointer-events: none !important;
	}

	.tux-chat-form {
		gap: 6px;
		padding: 8px 10px 10px;
	}

	.tux-live-chat__thread {
		padding: 14px 12px 6px;
	}

	.tux-live-chat__chips {
		padding: 0 12px 8px;
	}

	.tux-chat-row__body {
		max-width: 86%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.tux-live-chat,
	.tux-chat-bubble,
	.tux-chat-form__submit {
		transition: none;
	}

	.tux-chat-typing span {
		animation: none;
	}
}
