/**
 * DAISCH Live Chat —— 访客端样式。
 *
 * 前缀 daisch-lc，与主题的 daisch-*、MOCA 的 moca-* 都错开。
 * 配色优先吃主题令牌，取不到才用兜底值——这样两站各自的主题色能自动带过来。
 * z-index 用 998：低于移动菜单的 999，否则全屏导航会被气泡压住。
 */

.daisch-lc {
	--lc-accent: var(--daisch-accent, #e63946);
	--lc-accent-hover: var(--daisch-accent-hover, #cf2a35);
	--lc-radius-lg: var(--daisch-radius-lg, 12px);
	--lc-radius-md: var(--daisch-radius-md, 8px);
	--lc-radius-full: var(--daisch-radius-full, 9999px);
	--lc-shadow: var(--daisch-shadow-lg, 0 12px 32px rgba(15, 23, 42, 0.18));
	--lc-ease: var(--daisch-ease-out, cubic-bezier(0.16, 1, 0.3, 1));
	--lc-duration: var(--daisch-duration, 0.3s);
	--lc-gutter: var(--daisch-page-gutter, 24px);
	--lc-ink: #111827;
	--lc-muted: #6b7280;
	--lc-line: #e5e7eb;
	--lc-soft: #f3f4f6;
	--lc-surface: #fff;

	position: fixed;
	right: var(--lc-gutter);
	bottom: var(--lc-gutter);
	z-index: 998;
	/* 气泡与招呼卡右对齐：根盒子宽度取两者较宽的那个，靠 align-items 把窄的那个推到右边 */
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	font-family: var(--daisch-font-cn, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif);
	font-size: 15px;
	line-height: 1.6;
	color: var(--lc-ink);
	-webkit-text-size-adjust: 100%;
}

.daisch-lc *,
.daisch-lc *::before,
.daisch-lc *::after {
	box-sizing: border-box;
}

/* ── 气泡按钮 ─────────────────────────────────────── */

/* 桌面端是「图标 + 在线咨询」的胶囊：光一个气泡图标，头一次来的人不知道那是什么。
   移动端回到圆形（见文末断点），靠招呼卡把那层意思补上。 */
.daisch-lc__bubble {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	height: 52px;
	padding: 0 20px 0 17px;
	border: 0;
	border-radius: var(--lc-radius-full);
	background: var(--lc-accent);
	color: #fff;
	font-family: inherit;
	font-size: 15px;
	font-weight: 600;
	line-height: 1;
	cursor: pointer;
	box-shadow: var(--lc-shadow);
	transition: transform var(--lc-duration) var(--lc-ease), background var(--lc-duration) var(--lc-ease);
}

.daisch-lc__bubble-text {
	white-space: nowrap;
}

.daisch-lc__bubble:hover {
	background: var(--lc-accent-hover);
	transform: translateY(-2px);
}

.daisch-lc__bubble:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
	box-shadow: 0 0 0 4px var(--lc-accent);
}

.daisch-lc__icon-chat {
	width: 24px;
	height: 24px;
	fill: currentColor;
	flex: 0 0 auto;
}

/* ── 首次进站的招呼卡 ─────────────────────────────── */

.daisch-lc__teaser {
	position: relative;
	width: 250px;
	margin-bottom: 10px;
	border: 1px solid var(--lc-line);
	border-radius: var(--lc-radius-lg);
	background: var(--lc-surface);
	box-shadow: var(--lc-shadow);
	animation: daisch-lc-teaser-in var(--lc-duration) var(--lc-ease);
}

.daisch-lc__teaser[hidden] {
	display: none;
}

/* 面板打开后气泡让位，招呼卡也没必要留着 */
.daisch-lc[data-state="open"] .daisch-lc__teaser {
	display: none;
}

.daisch-lc__teaser-open {
	display: block;
	width: 100%;
	padding: 11px 34px 12px 14px;
	border: 0;
	border-radius: var(--lc-radius-lg);
	background: none;
	color: inherit;
	font-family: inherit;
	font-size: 15px;
	text-align: left;
	cursor: pointer;
}

.daisch-lc__teaser-title {
	display: block;
	font-size: 14px;
	font-weight: 600;
	color: var(--lc-accent);
}

.daisch-lc__teaser-text {
	display: block;
	margin-top: 2px;
	font-size: 13px;
	line-height: 1.5;
	color: var(--lc-muted);
}

.daisch-lc__teaser-x {
	position: absolute;
	top: 6px;
	right: 6px;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	padding: 0;
	border: 0;
	border-radius: var(--lc-radius-full);
	background: none;
	color: var(--lc-muted);
	cursor: pointer;
}

.daisch-lc__teaser-x:hover {
	background: var(--lc-soft);
	color: var(--lc-ink);
}

.daisch-lc__teaser-x svg {
	width: 12px;
	height: 12px;
}

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

.daisch-lc__badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: var(--lc-radius-full);
	background: #fff;
	color: var(--lc-accent);
	border: 2px solid var(--lc-accent);
	font-size: 11px;
	font-weight: 700;
	line-height: 16px;
	text-align: center;
}

.daisch-lc__badge[hidden] {
	display: none;
}

/* 打开时气泡收起，让位给面板 */
.daisch-lc[data-state="open"] .daisch-lc__bubble {
	display: none;
}

/* ── 面板 ─────────────────────────────────────────── */

.daisch-lc__panel {
	position: absolute;
	right: 0;
	bottom: 0;
	display: flex;
	flex-direction: column;
	width: 360px;
	height: 520px;
	max-height: calc(100vh - var(--lc-gutter) * 2);
	background: var(--lc-surface);
	border-radius: var(--lc-radius-lg);
	box-shadow: var(--lc-shadow);
	overflow: hidden;
	opacity: 0;
	visibility: hidden;
	transform: translateY(12px) scale(0.98);
	transform-origin: bottom right;
	transition: opacity var(--lc-duration) var(--lc-ease),
		transform var(--lc-duration) var(--lc-ease),
		visibility 0s linear var(--lc-duration);
	outline: none;
}

.daisch-lc[data-state="open"] .daisch-lc__panel {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}

.daisch-lc__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	flex: 0 0 auto;
	padding: 12px 14px;
	border-bottom: 1px solid var(--lc-line);
	background: var(--lc-surface);
}

.daisch-lc__title {
	font-size: 15px;
	font-weight: 600;
}

.daisch-lc__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	padding: 0;
	border: 0;
	border-radius: var(--lc-radius-md);
	background: transparent;
	color: var(--lc-muted);
	cursor: pointer;
}

.daisch-lc__close:hover {
	background: var(--lc-soft);
	color: var(--lc-ink);
}

.daisch-lc__close svg {
	width: 16px;
	height: 16px;
}

.daisch-lc__body {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overscroll-behavior: contain;
	background: #fafafa;
}

.daisch-lc__log {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 14px;
}

/* ── 消息 ─────────────────────────────────────────── */

.daisch-lc__msg {
	display: flex;
	flex-direction: column;
	max-width: 82%;
	gap: 4px;
}

.daisch-lc__msg--visitor {
	align-self: flex-end;
	align-items: flex-end;
}

.daisch-lc__msg--admin,
.daisch-lc__msg--system {
	align-self: flex-start;
	align-items: flex-start;
}

.daisch-lc__text {
	padding: 9px 12px;
	border-radius: var(--lc-radius-lg);
	background: var(--lc-surface);
	color: var(--lc-ink);
	word-break: break-word;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
}

.daisch-lc__msg--visitor .daisch-lc__text {
	background: var(--lc-accent);
	color: #fff;
	border-bottom-right-radius: var(--lc-radius-md);
}

.daisch-lc__msg--admin .daisch-lc__text {
	border: 1px solid var(--lc-line);
	border-bottom-left-radius: var(--lc-radius-md);
}

/* 系统消息（欢迎语、离线提示）是整段话，不是短提示。
   居中排会让换行后的第二行左边缘参差，中文段落齐左更好读。 */
.daisch-lc__msg--system {
	align-self: stretch;
	max-width: 100%;
}

.daisch-lc__msg--system .daisch-lc__text {
	background: transparent;
	border: 0;
	padding: 0 2px;
	color: var(--lc-muted);
	font-size: 13px;
	line-height: 1.7;
	text-align: left;
	/*
	 * 欢迎语 28 个字，在 360px 面板里差一点放不下，硬换行会把「回复。」丢到第二行。
	 * balance 让两行均分。旧浏览器忽略这条，退回普通换行，只是难看一点。
	 */
	text-wrap: balance;
}

.daisch-lc__text a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.daisch-lc__img {
	display: block;
	max-width: 220px;
	max-height: 220px;
	border-radius: var(--lc-radius-md);
	cursor: zoom-in;
	background: var(--lc-soft);
}

.daisch-lc__msg--visitor .daisch-lc__img {
	border: 0;
}

.daisch-lc__meta {
	padding: 0 4px;
	font-size: 11px;
	color: var(--lc-muted);
}

/* 发送中 / 失败 */
.daisch-lc__msg[data-status="sending"] {
	opacity: 0.55;
}

.daisch-lc__msg[data-status="failed"] .daisch-lc__text,
.daisch-lc__msg[data-status="failed"] .daisch-lc__img {
	outline: 2px solid var(--lc-accent);
	outline-offset: -2px;
}

.daisch-lc__retry {
	align-self: inherit;
	padding: 0 4px;
	border: 0;
	background: none;
	color: var(--lc-accent);
	font-size: 12px;
	cursor: pointer;
	text-decoration: underline;
}

/* ── 留资提示 ─────────────────────────────────────── */

.daisch-lc__ask {
	flex: 0 0 auto;
	padding: 10px 14px;
	border-top: 1px solid var(--lc-line);
	background: #fffdf5;
}

.daisch-lc__ask[hidden] {
	display: none;
}

.daisch-lc__ask-text {
	margin-bottom: 8px;
	font-size: 13px;
	color: #92400e;
}

.daisch-lc__ask-row {
	display: flex;
	gap: 8px;
}

.daisch-lc__ask-row + .daisch-lc__ask-row {
	margin-top: 8px;
}

.daisch-lc__ask-row--btns {
	justify-content: flex-end;
	align-items: center;
}

.daisch-lc__ask input {
	flex: 1 1 0;
	min-width: 0;
	padding: 8px 10px;
	border: 1px solid var(--lc-line);
	border-radius: var(--lc-radius-md);
	font-size: 16px;
	font-family: inherit;
	color: var(--lc-ink);
	background: #fff;
}

.daisch-lc__ask input:focus {
	border-color: var(--lc-accent);
	outline: none;
}

.daisch-lc__ask-save,
.daisch-lc__ask-later {
	padding: 8px 16px;
	border-radius: var(--lc-radius-md);
	font-size: 13px;
	font-family: inherit;
	cursor: pointer;
}

.daisch-lc__ask-save {
	border: 0;
	background: var(--lc-accent);
	color: #fff;
}

.daisch-lc__ask-save:hover {
	background: var(--lc-accent-hover);
}

.daisch-lc__ask-later {
	border: 0;
	background: none;
	color: var(--lc-muted);
}

/* ── 输入区 ───────────────────────────────────────── */

.daisch-lc__form {
	display: flex;
	align-items: flex-end;
	/* 示例问题占满一行（flex-basis:100%），所以要允许换行 */
	flex-wrap: wrap;
	gap: 8px;
	flex: 0 0 auto;
	padding: 10px 12px;
	border-top: 1px solid var(--lc-line);
	background: var(--lc-surface);
}

/* 空状态示例问题。放在表单里面，省得在灰底和输入区之间多出一条分隔线 */
.daisch-lc__hints {
	flex: 0 0 100%;
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.daisch-lc__hints[hidden] {
	display: none;
}

.daisch-lc__hint {
	padding: 6px 12px;
	border: 1px solid var(--lc-line);
	border-radius: var(--lc-radius-full);
	background: var(--lc-soft);
	color: var(--lc-ink);
	font-family: inherit;
	font-size: 13px;
	line-height: 1.4;
	cursor: pointer;
}

.daisch-lc__hint:hover {
	border-color: var(--lc-accent);
	background: var(--lc-surface);
	color: var(--lc-accent);
}

.daisch-lc__input {
	/*
	 * flex-basis 必须是 0，不能是 auto。GeneratePress 的 main.min.css 里有一条
	 * 光秃秃的 `textarea { width: 100% }`，我们没声明 width，于是它就生效，
	 * 交集尺寸变成整个输入区宽度 → 回形针、输入框、发送键各占一行。
	 * basis 取 0 + min-width: 0 之后，输入框不再贡献固有宽度，主题那两条都无从发力。
	 * 同理 width: auto 把主题的 100% 明确压掉，别删。
	 */
	flex: 1 1 0;
	width: auto;
	min-width: 0;
	min-height: 38px;
	max-height: 120px;
	padding: 8px 10px;
	border: 1px solid var(--lc-line);
	border-radius: var(--lc-radius-md);
	/* 16px：低于此值 iOS 聚焦时会自动放大页面 */
	font-size: 16px;
	font-family: inherit;
	line-height: 1.5;
	color: var(--lc-ink);
	resize: none;
	overflow-y: auto;
}

.daisch-lc__input:focus {
	border-color: var(--lc-accent);
	outline: none;
}

.daisch-lc__attach,
.daisch-lc__send {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: 0 0 auto;
	width: 38px;
	height: 38px;
	padding: 0;
	border: 0;
	border-radius: var(--lc-radius-full);
	cursor: pointer;
}

.daisch-lc__attach {
	background: transparent;
	color: var(--lc-muted);
}

.daisch-lc__attach:hover {
	background: var(--lc-soft);
	color: var(--lc-ink);
}

.daisch-lc__attach svg {
	width: 20px;
	height: 20px;
}

.daisch-lc__send {
	background: var(--lc-accent);
	color: #fff;
}

.daisch-lc__send:hover {
	background: var(--lc-accent-hover);
}

.daisch-lc__send:disabled,
.daisch-lc__attach:disabled {
	opacity: 0.45;
	cursor: not-allowed;
}

.daisch-lc__send svg {
	width: 18px;
	height: 18px;
	fill: currentColor;
}

.daisch-lc__status {
	flex: 0 0 auto;
	max-height: 0;
	overflow: hidden;
	padding: 0 14px;
	background: var(--lc-surface);
	color: var(--lc-muted);
	font-size: 12px;
	transition: max-height var(--lc-duration) var(--lc-ease), padding var(--lc-duration) var(--lc-ease);
}

.daisch-lc__status[data-show="1"] {
	max-height: 60px;
	padding: 6px 14px 10px;
}

.daisch-lc__status[data-kind="error"] {
	color: var(--lc-accent);
}

/* ── 大图查看 ─────────────────────────────────────── */

.daisch-lc__viewer {
	position: fixed;
	inset: 0;
	z-index: 9999;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 24px;
	background: rgba(15, 23, 42, 0.86);
	cursor: zoom-out;
}

.daisch-lc__viewer img {
	max-width: 100%;
	max-height: 100%;
	border-radius: var(--lc-radius-md);
}

/* ── 移动端全屏 ───────────────────────────────────── */

@media (max-width: 768px) {
	.daisch-lc {
		--lc-gutter: var(--daisch-page-gutter, 16px);
	}

	.daisch-lc[data-state="open"] {
		inset: 0;
		right: 0;
		bottom: 0;
	}

	/* 移动端回到 56px 正圆：360px 宽的屏上胶囊会盖住更多内容，圆形认知度也够 */
	.daisch-lc__bubble {
		width: 56px;
		height: 56px;
		gap: 0;
		padding: 0;
	}

	.daisch-lc__bubble-text {
		display: none;
	}

	.daisch-lc__icon-chat {
		width: 26px;
		height: 26px;
	}

	.daisch-lc__panel {
		position: fixed;
		inset: 0;
		width: auto;
		height: 100%;
		height: 100dvh;
		max-height: none;
		border-radius: 0;
		transform-origin: center;
	}

	.daisch-lc__form {
		padding-bottom: max(10px, env(safe-area-inset-bottom));
	}

	.daisch-lc__msg {
		max-width: 88%;
	}
}

@media (prefers-reduced-motion: reduce) {
	.daisch-lc *,
	.daisch-lc *::before,
	.daisch-lc *::after {
		transition-duration: 0.01ms !important;
	}
}
