/*
 * 前台聊天气泡
 *
 * 注意：Storefront 主题里有些全局样式会串进来（.button / a 颜色 / box-sizing），
 * 这里一律用 .mmchw 前缀 + 显式属性，不依赖主题变量。
 */

.mmchw,
.mmchw * {
	box-sizing: border-box;
}

.mmchw {
	--mmchw-accent: #1a1a1a;
	--mmchw-ink: #14161a;
	--mmchw-muted: #6b7280;
	--mmchw-line: #e5e7eb;
	--mmchw-bg: #ffffff;
	--mmchw-in: #f3f4f6;

	position: fixed;
	bottom: 20px;
	z-index: 999998;
	font-size: 14px;
	line-height: 1.55;
	color: var(--mmchw-ink);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.mmchw[data-pos="right"] {
	right: 20px;
}

.mmchw[data-pos="left"] {
	left: 20px;
}

/* ---------------------------------------------------------------- 按钮 */

.mmchw-launcher {
	position: relative;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	border: 0;
	padding: 0;
	cursor: pointer;
	background: var(--mmchw-accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
	float: right;
}

.mmchw[data-pos="left"] .mmchw-launcher {
	float: left;
}

.mmchw-launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
}

.mmchw-launcher:focus-visible {
	outline: 3px solid rgba(0, 0, 0, 0.25);
	outline-offset: 2px;
}

.mmchw.is-open .mmchw-launcher {
	transform: scale(0.92);
}

.mmchw-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 10px;
	background: #dc2626;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	line-height: 20px;
	text-align: center;
	border: 2px solid #fff;
}

/* ---------------------------------------------------------------- 面板 */

.mmchw-panel {
	position: absolute;
	bottom: 72px;
	width: 360px;
	max-width: calc(100vw - 32px);
	height: 560px;
	max-height: calc(100vh - 120px);
	background: var(--mmchw-bg);
	border-radius: 14px;
	box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
	display: none;
	flex-direction: column;
	overflow: hidden;
	transform-origin: bottom right;
}

.mmchw[data-pos="right"] .mmchw-panel {
	right: 0;
}

.mmchw[data-pos="left"] .mmchw-panel {
	left: 0;
	transform-origin: bottom left;
}

.mmchw.is-open .mmchw-panel {
	display: flex;
	animation: mmchw-in 0.2s ease-out;
}

@keyframes mmchw-in {
	from {
		opacity: 0;
		transform: translateY(10px) scale(0.98);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* ---------------------------------------------------------------- 头部 */

/*
 * 头部 = 2 行 Grid：
 *
 *   ┌──────────────────────────┬──────────────┐
 *   │ 标题（Chat with us）      │ 🌐 Deutsch ✕ │  ← 语言切换和标题同一行
 *   ├──────────────────────────┴──────────────┤
 *   │ ● 副标题（占满整宽，不再被右侧按钮挤）    │
 *   └─────────────────────────────────────────┘
 *
 * 为什么用 grid 而不是 flex：原来标题+副标题包在 .mmchw-head-txt 里，
 * 右侧 .mmchw-head-tools 是兄弟，于是副标题的可用宽度 = 面板宽 − padding − tools 宽，
 * 只剩 209px（v1.1.7 之前更惨，因为 head-txt 默认 flex:0 1 auto 被压到标题宽度，只剩 143px）。
 * 用 grid 把「工具按钮」钉在第一行右上角，副标题单独跨第二行 → 可用宽度直接吃满 328px。
 */
.mmchw-head {
	display: grid;
	grid-template-columns: minmax(0, 1fr) auto;
	grid-template-areas:
		"title  tools"
		"status status";
	align-items: center;
	column-gap: 8px;
	row-gap: 1px;
	padding: 12px 16px;
	background: var(--mmchw-accent);
	color: #fff;
	flex: 0 0 auto;
}

.mmchw-head-title {
	grid-area: title;
	min-width: 0;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.3;
	/* 标题是主信息，真放不下时宁可省略，也不要把它挤成两行撑高头部 */
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.mmchw-status {
	grid-area: status;
	min-width: 0;
	font-size: 12px;
	line-height: 1.5;
	opacity: 0.78;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.mmchw-status.is-online::before {
	content: "";
	display: inline-block;
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: #4ade80;
	margin-right: 5px;
	vertical-align: middle;
}

.mmchw-close {
	background: transparent;
	border: 0;
	color: inherit;
	padding: 4px;
	cursor: pointer;
	opacity: 0.8;
	line-height: 0;
	border-radius: 6px;
}

.mmchw-close:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.14);
}

/* 语言切换：头部右侧一个地球小按钮 + 下拉 */

.mmchw-head-tools {
	grid-area: tools;
	display: flex;
	align-items: center;
	gap: 4px;
	flex: 0 0 auto;
}

.mmchw-lang {
	position: relative;
}

.mmchw-lang-btn {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	max-width: 118px;
	padding: 4px 7px;
	border: 0;
	border-radius: 6px;
	background: rgba(255, 255, 255, 0.12);
	color: inherit;
	font: inherit;
	font-size: 11.5px;
	line-height: 1.2;
	cursor: pointer;
	opacity: 0.92;
}

.mmchw-lang-btn:hover {
	opacity: 1;
	background: rgba(255, 255, 255, 0.2);
}

.mmchw-lang-btn span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* 下拉箭头：让「这是个可以点开的切换器」一眼看出来，而不是像一行普通文字 */
.mmchw-lang-caret {
	flex: 0 0 auto;
	margin-left: 1px;
	opacity: 0.75;
	transition: transform 0.16s ease;
}

/*
 * 老大 2026-11-02 定：语言名在左、地球在右。
 * 按钮本身是 inline-flex，用 order 重排即可，不用改 HTML。
 */
#mmchw-lang-label {
	order: 1;
}

.mmchw-lang-btn > svg:not(.mmchw-lang-caret) {
	order: 2;
}

.mmchw-lang-caret {
	order: 3;
}

.mmchw-lang-btn[aria-expanded="true"] .mmchw-lang-caret {
	transform: rotate(180deg);
	opacity: 1;
}

.mmchw-lang-menu {
	position: absolute;
	top: calc(100% + 6px);
	right: 0;
	z-index: 10;
	margin: 0;
	padding: 4px;
	list-style: none;
	min-width: 132px;
	background: #fff;
	color: var(--mmchw-ink);
	border-radius: 10px;
	box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}

.mmchw-lang-menu li {
	padding: 7px 10px;
	border-radius: 7px;
	font-size: 13px;
	line-height: 1.3;
	cursor: pointer;
	white-space: nowrap;
}

.mmchw-lang-menu li:hover {
	background: var(--mmchw-in);
}

.mmchw-lang-menu li[aria-selected="true"] {
	font-weight: 600;
}

.mmchw-lang-menu li[aria-selected="true"]::after {
	content: "✓";
	float: right;
	margin-left: 10px;
	opacity: 0.55;
}

/* ---------------------------------------------------------------- 消息区 */

.mmchw-body {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px 14px 8px;
	display: flex;
	flex-direction: column;
	gap: 9px;
	background: #fafafa;
	-webkit-overflow-scrolling: touch;
}

.mmchw-msg {
	display: flex;
	flex-direction: column;
	max-width: 84%;
}

.mmchw-msg.is-in {
	align-self: flex-start;
}

.mmchw-msg.is-out {
	align-self: flex-end;
	align-items: flex-end;
}

.mmchw-bubble {
	padding: 9px 13px;
	border-radius: 14px;
	white-space: pre-wrap;
	word-break: break-word;
	font-size: 14px;
}

.mmchw-msg.is-in .mmchw-bubble {
	background: #fff;
	border: 1px solid var(--mmchw-line);
	border-bottom-left-radius: 4px;
}

.mmchw-msg.is-out .mmchw-bubble {
	background: var(--mmchw-accent);
	color: #fff;
	border-bottom-right-radius: 4px;
}

.mmchw-meta {
	margin-top: 3px;
	font-size: 11px;
	color: var(--mmchw-muted);
}

/* -------------------------------------------------------------------------
 *  对话自动翻译：原文折叠 + 翻译中提示
 *
 *  原则：客户默认只看译文，原文收起来（12px、灰色、贴着气泡下沿），
 *  不喧宾夺主，也不占掉聊天窗口本来就不多的竖向空间。
 * ---------------------------------------------------------------------- */

.mmchw-tr-tools {
	display: flex;
	margin-top: 3px;
}

.mmchw-msg.is-out .mmchw-tr-tools {
	justify-content: flex-end;
}

/*
 * ⚠️ 这三条必须带 #mm-chat-widget 前缀（特异性抬到 1,x,x），不能用裸 class。
 *
 * 实测踩过两次，两次原因不同，都已用 CDP CSS.getMatchedStylesForNode 确认：
 *
 *   ① 主题 inline <style> 里给全站按钮写了
 *        button, input[type="submit"], … { font-family: var(--mm-font-head);
 *          background: var(--mm-coral); padding: 14px 30px;
 *          box-shadow: 0 8px 20px rgba(255,107,91,.32); }
 *      → 「原文」按钮被撑成大按钮、带珊瑚色投影。靠 ID 前缀已压住。
 *
 *   ② **同一条规则里还有 color: #fff !important** —— 这个谁也压不住，
 *      只能同样上 !important，再靠 (1,1,0) > (0,0,1) 的特异性取胜。
 *      所以下面 color / hover color 两处是**唯一必须**的 !important，
 *      别顺手删，删了按钮立刻变回白字隐形。
 */
#mm-chat-widget .mmchw-src-btn {
	appearance: none;
	-webkit-appearance: none;
	display: inline-block;
	border: 0;
	background: none;
	box-shadow: none;
	padding: 0;
	margin: 0;
	min-width: 0;
	width: auto;
	height: auto;
	cursor: pointer;
	font-family: inherit;
	font-size: 11px;
	font-weight: 400;
	line-height: 1.6;
	letter-spacing: normal;
	text-transform: none;
	color: var(--mmchw-muted) !important;
	text-decoration: underline;
	text-underline-offset: 2px;
	text-decoration-color: rgba(0, 0, 0, 0.18);
}

#mm-chat-widget .mmchw-src-btn:hover {
	color: var(--mmchw-accent) !important;
	text-decoration-color: currentColor;
}

#mm-chat-widget .mmchw-src {
	margin-top: 4px;
	padding: 7px 10px;
	border-left: 2px solid rgba(0, 0, 0, 0.12);
	background: rgba(0, 0, 0, 0.03);
	border-radius: 0 8px 8px 0;
	font-size: 12px;
	line-height: 1.55;
	color: #5a5d66;
	white-space: pre-wrap;
	word-break: break-word;
	max-width: 100%;
}

#mm-chat-widget .mmchw-msg.is-out .mmchw-src {
	border-left: 0;
	border-right: 2px solid rgba(0, 0, 0, 0.12);
	border-radius: 8px 0 0 8px;
	text-align: left;
}

#mm-chat-widget .mmchw-tr-note {
	margin-top: 3px;
	font-size: 11px;
	line-height: 1.6;
	color: var(--mmchw-muted);
	font-style: italic;
}

.mmchw-thumbs {
	display: flex;
	gap: 6px;
	flex-wrap: wrap;
	margin-top: 6px;
}

.mmchw-thumbs.is-alone {
	margin-top: 0;
}

.mmchw-thumbs img {
	width: 96px;
	height: 96px;
	object-fit: cover;
	border-radius: 8px;
	border: 1px solid var(--mmchw-line);
	cursor: zoom-in;
	background: #fff;
}

.mmchw-note {
	align-self: center;
	font-size: 12px;
	color: var(--mmchw-muted);
	background: #eef0f2;
	border-radius: 10px;
	padding: 4px 12px;
	text-align: center;
	max-width: 90%;
}

.mmchw-typing {
	align-self: flex-start;
	color: var(--mmchw-muted);
	font-size: 12px;
}

/* ---------------------------------------------------------------- 附件 / 邮箱 */

.mmchw-preview {
	display: flex;
	gap: 6px;
	padding: 8px 14px 0;
	flex-wrap: wrap;
	background: #fff;
	border-top: 1px solid var(--mmchw-line);
}

.mmchw-preview .chip {
	position: relative;
}

.mmchw-preview img {
	width: 46px;
	height: 46px;
	object-fit: cover;
	border-radius: 6px;
	border: 1px solid var(--mmchw-line);
}

.mmchw-preview .x {
	position: absolute;
	top: -6px;
	right: -6px;
	width: 16px;
	height: 16px;
	border-radius: 50%;
	background: #dc2626;
	color: #fff;
	font-size: 11px;
	line-height: 16px;
	text-align: center;
	cursor: pointer;
	border: 1px solid #fff;
}

.mmchw-email {
	padding: 8px 14px 0;
	background: #fff;
}

.mmchw-email input {
	width: 100%;
	height: 34px;
	border: 1px solid var(--mmchw-line);
	border-radius: 8px;
	padding: 0 10px;
	font-size: 13px;
	background: #fff;
	color: var(--mmchw-ink);
}

.mmchw-email input:focus {
	outline: none;
	border-color: var(--mmchw-accent);
}

/* ---------------------------------------------------------------- 输入区 */

.mmchw-compose {
	display: flex;
	align-items: flex-end;
	gap: 6px;
	padding: 10px 12px;
	background: #fff;
	border-top: 1px solid var(--mmchw-line);
	flex: 0 0 auto;
}

.mmchw-attach {
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	border-radius: 8px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: var(--mmchw-muted);
	cursor: pointer;
}

.mmchw-attach:hover {
	background: var(--mmchw-in);
	color: var(--mmchw-ink);
}

.mmchw-compose textarea {
	flex: 1 1 auto;
	min-height: 34px;
	max-height: 110px;
	resize: none;
	border: 1px solid var(--mmchw-line);
	border-radius: 17px;
	padding: 7px 12px;
	font-size: 14px;
	line-height: 1.4;
	font-family: inherit;
	background: #fff;
	color: var(--mmchw-ink);
	outline: none;
}

.mmchw-compose textarea:focus {
	border-color: var(--mmchw-accent);
}

.mmchw-send {
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	border: 0;
	background: var(--mmchw-accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	padding: 0;
	transition: opacity 0.15s;
}

.mmchw-send:disabled {
	opacity: 0.4;
	cursor: default;
}

.mmchw-foot {
	flex: 0 0 auto;
	padding: 6px 14px 10px;
	font-size: 11px;
	color: var(--mmchw-muted);
	text-align: center;
	background: #fff;
}

/* ---------------------------------------------------------------- 手机 */

/*
 * v1.3.4（老大 2026-11-02）：Storefront 在 ≤768px 有一条固定底部栏
 * （我的账户 / 搜索 / 购物车，实测高 69px）。气泡原来 bottom:14 正好压在购物车图标上，
 * 这里整体抬到底部栏之上：69 + 16 = 85px。
 */
@media (max-width: 768px) {
	.mmchw {
		bottom: 85px;
	}
}

@media (max-width: 480px) {
	.mmchw[data-pos="right"] {
		right: 14px;
	}

	.mmchw[data-pos="left"] {
		left: 14px;
	}

	.mmchw-launcher {
		width: 52px;
		height: 52px;
	}

	.mmchw.is-open .mmchw-launcher {
		display: none;
	}

	.mmchw-panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		max-height: none;
		max-width: none;
		border-radius: 0;
		z-index: 999999;
	}

	.mmchw-body {
		padding-bottom: 12px;
	}

	/*
	 * v1.3.3（2026-11-02 老大要求）：手机端改回和 PC 一样的「🌐 语言名 ⌄」。
	 * 之前为了省头部宽度把文字砍成只剩地球图标，结果认不出当前是哪种语言 —— 省下的 60px 不值。
	 * 现在靠小字号 + 4px gap 控宽度，整个按钮 ~104px 封顶。
	 */
	#mmchw-lang-label {
		display: inline-block;
	}

	/* 文字回来了，箭头也要回来，否则「能点开」的暗示就没了 */
	.mmchw-lang-caret {
		display: block;
	}

	.mmchw-lang-btn {
		padding: 5px 7px;
		gap: 4px;
		max-width: 132px;
		border-radius: 999px;
	}

	.mmchw-lang-btn svg {
		width: 15px;
		height: 15px;
	}

	.mmchw-head {
		padding: 11px 14px;
	}

	.mmchw-head-title {
		font-size: 16px;
	}
}

/* 打开时锁住页面滚动（手机上很关键，不然背景会跟着滚） */
body.mmchw-lock {
	overflow: hidden;
}

/* ------------------------------------------------------------ 主题样式隔离
 *
 * Storefront 对全站表单控件写了这三条，会漏进气泡里：
 *   a:focus, input:focus, textarea:focus, button:focus { outline: 2px solid #7f54b3 }
 *   input[type="…"]:focus, textarea:focus { background-color: #ededed }
 *   input[type="…"], textarea { box-shadow: inset 0 1px 1px rgba(0,0,0,.125) }
 *
 * 麻烦在于它们和我们的规则**特异性相同**（0,1,1），但主题样式排在后面，
 * 于是聚焦输入框的瞬间会：底色变灰 #ededed、四周冒出 WooCommerce 紫环 #7f54b3。
 * 用 #mm-chat-widget 前缀把特异性抬到 (1,1,1) 压过去，不用 !important。
 */
#mm-chat-widget .mmchw-compose textarea,
#mm-chat-widget .mmchw-email input {
	background: #fff;
	box-shadow: none;
	-webkit-appearance: none;
	appearance: none;
}

#mm-chat-widget .mmchw-compose textarea:focus,
#mm-chat-widget .mmchw-email input:focus {
	outline: none;
	background: #fff;
	border-color: var(--mmchw-accent);
	box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.08);
}

/* 按钮也别留紫环，换成和主色一致的柔光 */
#mm-chat-widget .mmchw-send:focus,
#mm-chat-widget .mmchw-close:focus {
	outline: none;
	box-shadow: 0 0 0 3px rgba(26, 26, 26, 0.15);
}

/* 长文本继续长高到 110px 封顶后必然要滚动，把原生滚动条换成细的（Windows 上原生那条带上下箭头） */
#mm-chat-widget .mmchw-compose textarea::-webkit-scrollbar {
	width: 6px;
}

#mm-chat-widget .mmchw-compose textarea::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.18);
	border-radius: 3px;
}

#mm-chat-widget .mmchw-compose textarea::-webkit-scrollbar-track {
	background: transparent;
}

/* ------------------------------------------------- 主题按钮残留：珊瑚色光晕
 *
 * 主题（Kidora 版式）在同一条 inline 规则里还写了
 *   box-shadow: 0 8px 20px rgba(255, 107, 91, .32)
 * 和 font-family: var(--mm-font-head)（Nunito）/ font-weight: 600。
 * 实测漏到了「发送」「关闭」「语言切换」三个小按钮上 —— 深色圆按钮四周
 * 顶着一圈珊瑚色光，在白色气泡里非常扎眼。截图取证明：
 *   mmchw-send     => shadow=rgba(255,107,91,0.32) 0px 8px 20px
 *   mmchw-close    => shadow=rgba(255,107,91,0.32) 0px 8px 20px
 *   mmchw-lang-btn => shadow=rgba(255,107,91,0.32) 0px 8px 20px
 *
 * launcher（右下角浮球）**不在此列**：它自己有 0 6px 20px rgba(0,0,0,.22)，
 * 是设计要的悬浮感，别一起干掉。
 * 放在 focus 规则之后也没问题：`:focus` 那份特异性更高，焦点环照样生效。
 */
#mm-chat-widget .mmchw-send,
#mm-chat-widget .mmchw-close,
#mm-chat-widget .mmchw-lang-btn {
	box-shadow: none;
	font-family: inherit;
	font-weight: 400;
}
