
.bk-chat {
	--bk-chat-main: #4a6cf7;
	--bk-chat-main-dark: #3b57d6;
	--bk-chat-ink: #1f2430;
	--bk-chat-sub: #6b7280;
	--bk-chat-line: #e8eaf0;
	--bk-chat-bg: #f5f7ff;
	position: fixed;
	right: 22px;
	bottom: 22px;
	z-index: 9600;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
		"Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

/* ---------------------------------------------------------------- 角色形象
   右下角不再是圆形气泡按钮，而是一个站着的角色：默认待机，鼠标移上去（或
   有未读消息时）挥手，面板打开后整个退场（收起走面板右上角的「—」）。

   🔴 宽高必须严格等于立绘比例 450 : 775（导出图 116×200）。逐帧条是按同一
   尺寸切帧的，盒子比例一旦偏一点，每帧就会被拉伸，动作看起来会「跳」。 */
.bk-chat-fab {
	position: relative;
	display: block;
	width: 58px;
	height: 100px;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: transparent;
	color: var(--bk-chat-main);
	cursor: pointer;
	transition: opacity 0.16s ease, visibility 0.16s, transform 0.18s;
	-webkit-tap-highlight-color: transparent;
}

.bk-chat-fab:hover {
	transform: translateY(-2px);
}

.bk-chat-fab:focus-visible {
	outline: 2px solid var(--bk-chat-main-dark);
	outline-offset: 4px;
	border-radius: 14px;
}

/* 角色两层叠放，交叉淡入。图 URL 由 PHP 带 ?ver= 写进 --bk-pet-* 变量，
   否则 Cloudflare 会把旧图缓存 12 小时，改完素材线上看不见变化。 */
.bk-chat-pet {
	position: absolute;
	inset: 0;
	pointer-events: none;
}

.bk-chat-pet-l {
	position: absolute;
	inset: 0;
	background-repeat: no-repeat;
	background-position: 0 0;
	background-size: 100% 100%;
	transition: opacity 0.12s linear;
}

/* 挥手是 4 帧横排：background-size 拉到 400% 宽，用 background-position
   按 i/(n-1) 步进切帧，steps(1,end) 让每帧硬切不插值。 */
.bk-chat-pet-idle {
	background-image: var(--bk-pet-idle);
	opacity: 1;
}

.bk-chat-pet-wave {
	background-image: var(--bk-pet-wave);
	background-size: 400% 100%;
	opacity: 0;
}

/* 跺脚等待同样是逐帧条，6 帧横排 ⇒ 600% 宽，步进 20%。 */
.bk-chat-pet-wait {
	background-image: var(--bk-pet-wait);
	background-size: 600% 100%;
	opacity: 0;
}

.bk-chat-fab:hover .bk-chat-pet-idle,
.bk-chat.has-unread .bk-chat-pet-idle {
	opacity: 0;
}

.bk-chat-fab:hover .bk-chat-pet-wave,
.bk-chat.has-unread .bk-chat-pet-wave {
	opacity: 1;
	animation: bk-pet-wave 0.8s steps(1, end) infinite;
}

@keyframes bk-pet-wave {
	0% { background-position: 0% 0; }
	25% { background-position: 33.3334% 0; }
	50% { background-position: 66.6667% 0; }
	75%,
	100% { background-position: 100% 0; }
}

/* ------------------------------------------------------- 等其他状态
   三种状态，优先级：挥手（未读 / 悬停）> 跺脚（已发消息、等回复）> 待机。

   跺脚只在「自己说了话、客服还没回」时播——此时面板往往已经收起，
   右下角那个小人在原地跺脚，等于一个「我在等」的活体提示。 */
.bk-chat.is-waiting .bk-chat-pet-idle {
	opacity: 0;
}

.bk-chat.is-waiting .bk-chat-pet-wait {
	opacity: 1;
	animation: bk-pet-wait 1.15s steps(1, end) infinite;
}

@keyframes bk-pet-wait {
	0% { background-position: 0% 0; }
	20% { background-position: 20% 0; }
	40% { background-position: 40% 0; }
	60% { background-position: 60% 0; }
	80% { background-position: 80% 0; }
	100% { background-position: 100% 0; }
}

/* 挥手压过跺脚：有未读（客服回了）或鼠标悬停时，先挥手 */
.bk-chat.has-unread .bk-chat-pet-wait,
.bk-chat-fab:hover .bk-chat-pet-wait {
	opacity: 0;
	animation: none;
}

@media (prefers-reduced-motion: reduce) {

	.bk-chat.is-waiting .bk-chat-pet-wait {
		animation: none;
	}
}

@media (prefers-reduced-motion: reduce) {

	.bk-chat-fab:hover .bk-chat-pet-wave,
	.bk-chat.has-unread .bk-chat-pet-wave {
		animation: none;
	}
}

/* 面板打开后角色退场，右下角留空 —— 收起靠面板右上角那颗「—」。
   容器同时置 pointer-events:none：角色只是不可见，盒子还在原位，
   不这么做右下角会留一块 58×100 的隐形热区，挡住下面内容的点击。
   面板自己要把 auto 恢复回来，否则整个面板点不动。 */
.bk-chat.is-open {
	pointer-events: none;
}

.bk-chat.is-open .bk-chat-panel {
	pointer-events: auto;
}

.bk-chat.is-open .bk-chat-fab {
	opacity: 0;
	visibility: hidden;
	transform: translateY(8px) scale(0.92);
}

.bk-chat-dot {
	position: absolute;
	top: -3px;
	right: -3px;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 9px;
	background: #ff4d4f;
	color: #fff;
	font-size: 11px;
	font-weight: 500;
	line-height: 18px;
	text-align: center;
	box-shadow: 0 0 0 2px #fff;
}

.bk-chat-panel {
	position: absolute;
	right: 0;
	bottom: 68px;
	display: flex;
	flex-direction: column;
	width: 358px;
	height: 500px;
	max-height: calc(100vh - 110px);
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 18px 50px rgba(23, 26, 43, 0.18), 0 2px 6px rgba(23, 26, 43, 0.06);
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(10px) scale(0.98);
	transform-origin: right bottom;
	transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.bk-chat.is-open .bk-chat-panel {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

.bk-chat-head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: linear-gradient(135deg, #4a6cf7 0%, #6366f1 100%);
	color: #fff;
}

.bk-chat-head-main {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.bk-chat-head strong {
	font-size: 15px;
	font-weight: 500;
	line-height: 1.3;
}

.bk-chat-state {
	font-size: 12px;
	color: rgba(255, 255, 255, 0.82);
}

.bk-chat-end {
	display: flex;
	align-items: center;
	height: 28px;
	padding: 0 10px;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.16);
	color: #fff;
	font-size: 12px;
	line-height: 1;
	cursor: pointer;
	transition: background 0.15s;
}

.bk-chat-end:hover {
	background: rgba(255, 255, 255, 0.28);
}

.bk-chat-end:disabled {
	opacity: 0.6;
	cursor: default;
}

.bk-chat-end[hidden] {
	display: none;
}

.bk-chat-min {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	padding: 0;
	border: 0;
	border-radius: 8px;
	background: rgba(255, 255, 255, 0.16);
	color: #fff;
	cursor: pointer;
	transition: background 0.15s;
}

.bk-chat-min:hover {
	background: rgba(255, 255, 255, 0.28);
}

.bk-chat-log {
	flex: 1;
	min-height: 0;
	overflow-y: auto;
	padding: 14px 14px 6px;
	background: var(--bk-chat-bg);
	overscroll-behavior: contain;
}

.bk-chat-item {
	display: flex;
	margin-bottom: 10px;
}

.bk-chat-item.is-me {
	justify-content: flex-end;
}

.bk-chat-bubble {
	max-width: 78%;
	padding: 9px 13px;
	border-radius: 14px;
	font-size: 13.5px;
	line-height: 1.6;
	word-break: break-word;
	white-space: pre-wrap;
}

.bk-chat-item.is-them .bk-chat-bubble {
	background: #fff;
	color: var(--bk-chat-ink);
	border-bottom-left-radius: 5px;
	box-shadow: 0 1px 2px rgba(23, 26, 43, 0.06);
}

.bk-chat-item.is-me .bk-chat-bubble {
	background: var(--bk-chat-main);
	color: #fff;
	border-bottom-right-radius: 5px;
}

.bk-chat-item.is-sending .bk-chat-bubble {
	opacity: 0.62;
}

.bk-chat-item .bk-chat-bubble.is-img {
	max-width: 82%;
	padding: 0;
	background: transparent;
	color: var(--bk-chat-ink);
	box-shadow: none;
	white-space: normal;
}

.bk-chat-img-link {
	display: block;
	line-height: 0;
}

.bk-chat-img-cap {
	display: block;
	margin-top: 6px;
	padding: 7px 11px;
	border-radius: 12px;
	background: #fff;
	box-shadow: 0 1px 2px rgba(23, 26, 43, 0.06);
	font-size: 13px;
	line-height: 1.55;
	white-space: pre-wrap;
	word-break: break-word;
}

.bk-chat-item.is-me .bk-chat-img-cap {
	background: var(--bk-chat-main);
	color: #fff;
	box-shadow: none;
}

.bk-chat-img {
	display: block;
	max-width: 100%;
	max-height: 240px;
	width: auto;
	height: auto;
	border-radius: 12px;
	background: #eef0f6;
}

.bk-chat-time {
	align-self: flex-end;
	margin: 0 6px;
	font-size: 11px;
	color: #a3a8b8;
	white-space: nowrap;
}

.bk-chat-form {
	padding: 10px 12px 12px;
	background: #fff;
	border-top: 1px solid var(--bk-chat-line);
}

.bk-chat-gate {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 9px;
	padding: 30px 28px 34px;
	background: var(--bk-chat-bg);
	text-align: center;
}

.bk-chat-gate-ico {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 46px;
	height: 46px;
	margin-bottom: 2px;
	border-radius: 50%;
	background: #fff;
	color: var(--bk-chat-main);
	box-shadow: 0 2px 8px rgba(23, 26, 43, 0.08);
}

.bk-chat-gate h3 {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.4;
	color: var(--bk-chat-ink);
}

.bk-chat-gate p {
	margin: 0;
	max-width: 240px;
	font-size: 12.5px;
	line-height: 1.75;
	color: var(--bk-chat-sub);
}

.bk-chat-gate-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	margin-top: 10px;
	padding: 9px 26px;
	border-radius: 10px;
	background: var(--bk-chat-main);
	color: #fff;
	font-size: 13.5px;
	line-height: 1.4;
	text-decoration: none;
	transition: background 0.15s;
}

.bk-chat-gate-btn:hover,
.bk-chat-gate-btn:focus {
	background: var(--bk-chat-main-dark);
	color: #fff;
	text-decoration: none;
}

.bk-chat-gate-link {
	font-size: 12px;
	color: var(--bk-chat-sub);
	text-decoration: none;
}

.bk-chat-gate-link:hover {
	color: var(--bk-chat-main);
}

.bk-chat-inputrow {
	display: flex;
	align-items: flex-end;
	gap: 8px;
}

.bk-chat-inputrow textarea {
	flex: 1;
	min-height: 40px;
	max-height: 108px;
	padding: 10px 12px;
	border: 1px solid var(--bk-chat-line);
	border-radius: 12px;
	background: #fafbff;
	font-family: inherit;
	font-size: 13.5px;
	line-height: 1.5;
	color: var(--bk-chat-ink);
	resize: none;
	outline: none;
	transition: border-color 0.15s, background 0.15s;
}

.bk-chat-inputrow textarea:focus {
	border-color: var(--bk-chat-main);
	background: #fff;
}

.bk-chat-send {
	flex: none;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 0;
	border-radius: 12px;
	background: var(--bk-chat-main);
	color: #fff;
	cursor: pointer;
	transition: background 0.15s, opacity 0.15s;
}

.bk-chat-send:hover {
	background: var(--bk-chat-main-dark);
}

.bk-chat-send:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.bk-chat-tip {
	min-height: 15px;
	margin: 6px 2px 0;
	font-size: 11.5px;
	line-height: 1.4;
	color: #d4380d;
}

@media (max-width: 560px) {
	.bk-chat {
		right: 14px;
		bottom: 14px;
	}

	.bk-chat-panel {
		position: fixed;
		right: 0;
		left: 0;
		bottom: 0;
		width: 100%;
		height: 82vh;
		max-height: none;
		border-radius: 18px 18px 0 0;
		transform: translateY(16px);
	}

	.bk-chat.is-open .bk-chat-panel {
		transform: translateY(0);
	}

	.bk-chat-fab {
		width: 50px;
		height: 86px;
	}

	.bk-chat-form {
		padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
	}
}


/* 欢迎浮层要让开角色（角色高 100，比原来的 54 圆形高得多） */
body.bk-has-chat #bk-wn:not(.is-bl) {
	bottom: calc(22px + 100px + 14px);
}

body.bk-chat-open #bk-wn {
	display: none !important;
}

@media (max-width: 560px) {

	body.bk-has-chat #bk-wn:not(.is-bl) {
		bottom: calc(14px + 86px + 12px);
	}
}
