/*
 * Ez2 AIRAG LINE —— 前台懸浮對話視窗
 *
 * ═══════════════════════════════════════════════════════════
 * ★ 這一支與後台完全分開,不共用 token
 * ═══════════════════════════════════════════════════════════
 *
 * `admin-chat.css` 的 token 是照 WordPress 後台調的(它要跟 wp-admin
 * 融在一起)。前台是**訪客眼中的這個品牌**,套後台的 token 會讓這個視窗
 * 看起來像一塊 wp-admin 掉在別人的網站上。
 *
 * 所以:不 import、不共用變數、不共用 class 前綴(這裡是 `ez2airag-w`,
 * 後台是 `ez2airag-`)。前綴不同也讓「哪一支在管這個元素」一眼看得出來。
 *
 * ═══════════════════════════════════════════════════════════
 * ★ 佈景主題會侵入,所以每一個屬性都要寫出來
 * ═══════════════════════════════════════════════════════════
 *
 * 這支 CSS 跑在別人的佈景裡(本站是 Blocksy),而佈景會對 button / input /
 * p / h2 下全域樣式。**沒有明寫的屬性就是佈景說了算**,而佈景改版時我們
 * 這裡會無聲地變形。
 *
 * 所以底下的元件把 font / line-height / margin / padding / border /
 * background / color 全部寫死,不依賴任何繼承來的預設值。
 * 這不是囉嗦,是這支檔唯一的防線。
 *
 * ═══════════════════════════════════════════════════════════
 * ★ 三個由後端決定、前端不可以放寬的東西
 * ═══════════════════════════════════════════════════════════
 *
 * 1. `--w-op`(透明度)後端已夾在 0.60–1.00。**前端不再乘、不再調低。**
 *    低於 0.6 文字會讀不清,而那不是風格是壞掉。
 * 2. `--w-fg`(前景色)是 View 用 WCAG 相對亮度算出來的,不是寫死的白。
 *    使用者可以選淺色底,但不可以選到讀不出字。
 * 3. 透明度只作用在**啟動鈕**,不作用在展開後的面板 —— 面板裡是要讀的
 *    內容,半透明的內文疊在別人的網頁上必然難讀。
 */

.ez2airag-w {
	position: fixed;
	bottom: 20px;
	z-index: 99990; /* 高於一般佈景元素,低於 WP 管理列的 99999 */
	display: flex;
	flex-direction: column-reverse; /* 啟動鈕在 DOM 最前(Tab 先到),視覺在最下 */
	align-items: flex-end;
	gap: 12px;
	font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Segoe UI", sans-serif;
	font-size: 15px;
	line-height: 1.6;
	color: #1a1d21;
}

.ez2airag-w--right { right: 20px; }
.ez2airag-w--left  { left: 20px; align-items: flex-start; }

.ez2airag-w *,
.ez2airag-w *::before,
.ez2airag-w *::after {
	box-sizing: border-box;
}

/* 螢幕閱讀器專用 —— 不用佈景的 .screen-reader-text,那支不一定存在 */
.ez2airag-w__sr {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: -1px;
	padding: 0;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	white-space: nowrap;
	border: 0;
}

/* ── 啟動鈕 ── */

.ez2airag-w__launch {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 58px;
	height: 58px;
	margin: 0;
	padding: 0;
	background: var( --w-bg, #1d2327 );
	color: var( --w-fg, #fff );
	opacity: var( --w-op, 1 );
	border: 0;
	border-radius: 50%;
	box-shadow: 0 6px 22px rgba( 12, 18, 28, .26 );
	cursor: pointer;
	transition: transform .18s ease, box-shadow .18s ease;
	-webkit-appearance: none;
	appearance: none;
}

.ez2airag-w__launch:hover {
	transform: translateY( -2px );
	box-shadow: 0 12px 30px rgba( 12, 18, 28, .32 );
}

.ez2airag-w__launch:focus-visible {
	outline: 3px solid var( --w-bg, #1d2327 );
	outline-offset: 3px;
}

.ez2airag-w__icon {
	font-size: 26px;
	line-height: 1;
}

/* ── 面板 ── */

/*
 * 面板刻意**不套 --w-op**:展開之後裡面是要讀的內容,
 * 半透明的內文疊在別人的網頁上必然難讀。透明度只給啟動鈕。
 */
.ez2airag-w__panel {
	width: min( 372px, calc( 100vw - 40px ) );
	max-height: min( 560px, calc( 100vh - 140px ) );
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: #fff;
	border: 1px solid rgba( 18, 24, 32, .1 );
	border-radius: 18px;
	box-shadow: 0 20px 56px rgba( 12, 18, 28, .24 );
}

.ez2airag-w__panel[hidden] { display: none; }

.ez2airag-w__head {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0;
	padding: 14px 16px;
	background: var( --w-bg, #1d2327 );
	color: var( --w-fg, #fff );
}

.ez2airag-w__head-icon { font-size: 18px; line-height: 1; }

.ez2airag-w__title {
	flex: 1 1 auto;
	margin: 0;
	padding: 0;
	font-size: 15px;
	font-weight: 600;
	line-height: 1.4;
	color: inherit;
	letter-spacing: 0;
	text-transform: none;
}

.ez2airag-w__close {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	margin: 0;
	padding: 0;
	background: transparent;
	color: inherit;
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	opacity: .85;
	-webkit-appearance: none;
	appearance: none;
}

.ez2airag-w__close:hover { opacity: 1; background: rgba( 255, 255, 255, .16 ); }
.ez2airag-w__close:focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }

/* ── 訊息 ── */

.ez2airag-w__log {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 16px;
	background: #f6f7f9;
	display: flex;
	flex-direction: column;
	gap: 12px;
	-webkit-overflow-scrolling: touch;
}

.ez2airag-w__msg {
	max-width: 86%;
	margin: 0;
	padding: 10px 13px;
	border-radius: 14px;
	font-size: 14.5px;
	line-height: 1.7;
	overflow-wrap: anywhere;
	white-space: pre-wrap;
}

.ez2airag-w__msg--them {
	align-self: flex-start;
	background: #fff;
	color: #1a1d21;
	border: 1px solid rgba( 18, 24, 32, .09 );
	border-bottom-left-radius: 5px;
}

.ez2airag-w__msg--me {
	align-self: flex-end;
	background: var( --w-bg, #1d2327 );
	color: var( --w-fg, #fff );
	border-bottom-right-radius: 5px;
}

/*
 * 「正在查…」的呼吸。只在等待時出現,而且不攜帶任何資訊 ——
 * 關掉動態效果的人看到的是同一句文字。
 */
.ez2airag-w__msg--wait { color: #5c6570; font-style: normal; }
.ez2airag-w__msg--wait::after {
	content: "";
	display: inline-block;
	width: 6px;
	height: 6px;
	margin-left: 6px;
	border-radius: 50%;
	background: currentColor;
	animation: ez2wPulse 1.1s ease-in-out infinite;
	vertical-align: middle;
}

@keyframes ez2wPulse {
	0%, 100% { opacity: .3; }
	50%      { opacity: 1; }
}

/* ── 出處 ── */

/*
 * ★ 措辭是「參考」不是「根據」。
 *
 * 我們附的是**觀測到檢索命中了這幾份文件**,不是「模型確實用了它們」——
 * 沒有 index→生成 的驗證管道,那是觀測值不是證明。
 * 「根據〈X〉,答案是…」是在宣稱因果,而我們沒有那個證據。
 */
.ez2airag-w__srcs {
	align-self: flex-start;
	max-width: 86%;
	margin: -4px 0 0;
	padding: 0;
	list-style: none;
	display: flex;
	flex-direction: column;
	gap: 3px;
	font-size: 12.5px;
	line-height: 1.6;
}

.ez2airag-w__srcs-label {
	margin: 0;
	padding: 0;
	color: #5c6570;
	font-size: 12px;
}

.ez2airag-w__srcs a {
	color: #1a4fd0;
	text-decoration: underline;
	overflow-wrap: anywhere;
}

.ez2airag-w__srcs a:hover { text-decoration: none; }

/* ── 輸入 ── */

.ez2airag-w__form {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 0;
	padding: 12px;
	background: #fff;
	border-top: 1px solid rgba( 18, 24, 32, .09 );
}

.ez2airag-w__form input[type="text"] {
	flex: 1 1 auto;
	width: 100%;
	min-height: 44px;
	margin: 0;
	padding: 10px 14px;
	background: #f6f7f9;
	color: #1a1d21;
	border: 1px solid rgba( 18, 24, 32, .12 );
	border-radius: 999px;
	font-family: inherit;
	font-size: 16px; /* iOS Safari 低於 16px 會在聚焦時放大整頁 */
	line-height: 1.5;
	-webkit-appearance: none;
	appearance: none;
}

.ez2airag-w__form input[type="text"]:focus {
	border-color: var( --w-bg, #1d2327 );
	box-shadow: 0 0 0 3px rgba( 18, 24, 32, .1 );
	outline: none;
}

.ez2airag-w__send {
	display: flex;
	align-items: center;
	justify-content: center;
	flex: none;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	background: var( --w-bg, #1d2327 );
	color: var( --w-fg, #fff );
	border: 0;
	border-radius: 50%;
	cursor: pointer;
	-webkit-appearance: none;
	appearance: none;
}

.ez2airag-w__send:disabled { opacity: .5; cursor: not-allowed; }
.ez2airag-w__send:focus-visible { outline: 3px solid var( --w-bg, #1d2327 ); outline-offset: 2px; }

/* ── 小螢幕 ── */

@media screen and ( max-width: 600px ) {
	.ez2airag-w { right: 14px; left: 14px; bottom: 14px; align-items: flex-end; }
	.ez2airag-w--left { align-items: flex-start; }

	.ez2airag-w__panel {
		width: 100%;
		max-height: calc( 100vh - 120px );
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.ez2airag-w__launch { transition: none; }
	.ez2airag-w__launch:hover { transform: none; }
	.ez2airag-w__msg--wait::after { animation: none; opacity: .7; }
}

/* ═══════════════════════════════════════════════════════════
 * 防護層 —— 對抗佈景主題的按鈕/輸入框樣式
 * ═══════════════════════════════════════════════════════════
 *
 * ★ 這是這支檔唯一使用 !important 的地方,而它是有理由的。
 *
 * 生產站實測(ez2.help,Blocksy):送出鈕被佈景畫成
 *
 *     background: rgb(181,93,56)   ← 佈景的磚紅色,不是設定的主色
 *     border-radius: 10px          ← 我寫的是 50%
 *     實際尺寸 64×60               ← 我寫的是 44×44 圓形
 *
 * 而且**查不出是哪一條規則贏的** —— 佈景的樣式表是跨網域載入的
 * (經 FlyingPress 處理),`sheet.cssRules` 會丟例外,列舉不到。
 *
 * 一般情況下 !important 是壞味道,但這裡的處境不同:
 * **這是一個要嵌進「未知的別人網站」的元件。**我們永遠不會知道客戶用
 * 哪個佈景、那個佈景對 button 下了什麼。同樣的理由讓廣告阻擋器、
 * cookie 橫幅、客服掛件全部都這樣做。
 *
 * 範圍刻意限制在**互動控制項的幾何與外觀**,不是全部屬性 ——
 * 只鎖「壞掉 vs 沒壞掉」的那幾個,其餘照常可被覆寫。
 */

.ez2airag-w :is( button, input ) {
	font-family: inherit !important;
	letter-spacing: normal !important;
	text-transform: none !important;
	box-shadow: none !important;
	min-width: 0 !important;
	max-width: none !important;
}

.ez2airag-w .ez2airag-w__launch {
	width: 58px !important;
	height: 58px !important;
	min-height: 58px !important;
	padding: 0 !important;
	background-color: var( --w-bg, #1d2327 ) !important;
	background-image: none !important;
	color: var( --w-fg, #fff ) !important;
	border: 0 !important;
	border-radius: 50% !important;
	box-shadow: 0 6px 22px rgba( 12, 18, 28, .26 ) !important;
}

.ez2airag-w .ez2airag-w__send {
	flex: none !important;
	width: 44px !important;
	height: 44px !important;
	min-height: 44px !important;
	padding: 0 !important;
	background-color: var( --w-bg, #1d2327 ) !important;
	background-image: none !important;
	color: var( --w-fg, #fff ) !important;
	border: 0 !important;
	border-radius: 50% !important;
}

.ez2airag-w .ez2airag-w__close {
	width: 32px !important;
	height: 32px !important;
	min-height: 32px !important;
	padding: 0 !important;
	background-color: transparent !important;
	background-image: none !important;
	color: inherit !important;
	border: 0 !important;
	border-radius: 50% !important;
}

.ez2airag-w .ez2airag-w__form input[type="text"] {
	flex: 1 1 auto !important;
	width: 100% !important;
	min-height: 44px !important;
	height: auto !important;
	padding: 10px 14px !important;
	background-color: #f6f7f9 !important;
	background-image: none !important;
	color: #1a1d21 !important;
	border: 1px solid rgba( 18, 24, 32, .12 ) !important;
	border-radius: 999px !important;
	font-size: 16px !important;
	line-height: 1.5 !important;
}

/* 訊息泡泡也會被佈景的 p 樣式打到(margin / font-size / line-height) */
.ez2airag-w .ez2airag-w__msg {
	margin: 0 !important;
	font-size: 14.5px !important;
	line-height: 1.7 !important;
}

.ez2airag-w .ez2airag-w__title {
	margin: 0 !important;
	padding: 0 !important;
	font-size: 15px !important;
	line-height: 1.4 !important;
	color: inherit !important;
	text-transform: none !important;
	letter-spacing: normal !important;
}
