/**
 * 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;
	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: flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: var(--lc-radius-full);
	background: var(--lc-accent);
	color: #fff;
	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: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: 26px;
	height: 26px;
	fill: currentColor;
}

.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 .daisch-lc__text {
	background: transparent;
	border: 0;
	padding: 0 4px;
	color: var(--lc-muted);
	font-size: 13px;
	text-align: center;
	align-self: center;
}

.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;
	gap: 8px;
	flex: 0 0 auto;
	padding: 10px 12px;
	border-top: 1px solid var(--lc-line);
	background: var(--lc-surface);
}

.daisch-lc__input {
	flex: 1 1 auto;
	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;
	}

	.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;
	}
}
