/**
 * EASPNET Live Chat Bridge
 *
 * Custom UI layered on top of the cami (11.cmsrv.cc) chat widget:
 *   1. A "聯絡我們" launcher button (replaces the default polar-bear icon).
 *   2. A "contact panel" popover with several contact options.
 *
 * The cami polar bear (#cami_patrol_tool) is hidden *visually* but kept in the
 * DOM and clickable, because we programmatically .click() it to open the chat.
 * See assets/js/live-chat-bridge.js.
 *
 * Every rule for our own UI is prefixed with the wrapper id (#easpnet-live-chat)
 * so an id-level specificity keeps the theme (hello-elementor) from overriding
 * our styles. The cami bear rule below is the only exception — that element is
 * outside our wrapper.
 */

/* ── Hide the cami polar-bear launcher ─────────────────────────────────
 * Must stay rendered & hittable (not display:none) so JS .click() works.
 * We pull it off-screen and make it non-interactive to the user.
 * (Not inside #easpnet-live-chat — it's the cami widget's own element.)
 */
#cami_patrol_tool.easpnet-cami-hidden {
	position: fixed !important;
	left: -10000px !important;
	top: -10000px !important;
	opacity: 0 !important;
	pointer-events: none !important;
}

/* ── Shared fixed-corner anchor ────────────────────────────────────── */
#easpnet-live-chat.easpnet-lc {
	--easpnet-lc-primary: #1a5fb4;
	--easpnet-lc-primary-dark: #16345c;
	--easpnet-lc-mobile-panel-height: 90vh;
	--easpnet-lc-mobile-panel-margin: 0px;
	--easpnet-lc-panel-body-padding: 8px 20px 20px;
	--easpnet-lc-panel-header-padding: 40px 20px 40px;
	--easpnet-lc-item-label-font-size: 20px;
	--easpnet-lc-item-desc-font-size: 16px;
	--easpnet-lc-text: #333;
	--easpnet-lc-muted: #666;
	position: fixed;
	right: 24px;
	bottom: 24px;
	z-index: 2147483000; /* above the cami widget */
	font-family: -apple-system, "PingFang TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
}

/* ── "聯絡我們" launcher button ────────────────────────────────────── */
#easpnet-live-chat .easpnet-lc-launcher {
	position: relative;
	z-index: 3;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	/* !important so a theme's generic button rules can't repaint it into a
	 * white/outlined button — primary must stay the *background*. */
	padding: 14px 22px !important;
	background: var(--easpnet-lc-primary) !important;
	color: #fff !important;
	border: none !important;
	border-radius: 10px;
	font-size: 16px;
	font-weight: 700;
	line-height: 1;
	cursor: pointer;
	box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
	transition: background-color 0.2s ease, transform 0.15s ease;
}

#easpnet-live-chat .easpnet-lc-launcher:hover,
#easpnet-live-chat .easpnet-lc-launcher:focus {
	background: var(--easpnet-lc-primary-dark) !important;
	color: #fff !important;
}

#easpnet-live-chat .easpnet-lc-launcher:active {
	transform: translateY(1px);
}

/* Icon: fixed box, vertically centred with the text (align-items on the flex
 * button handles vertical; the box keeps it from stretching). */
#easpnet-live-chat .easpnet-lc-launcher__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 22px;
	flex: 0 0 22px;
}

#easpnet-live-chat .easpnet-lc-launcher__icon svg,
#easpnet-live-chat .easpnet-lc-launcher__icon img {
	display: block;
	width: 22px;
	height: 22px;
	max-width: 22px;
	max-height: 22px;
	object-fit: contain;
	fill: currentColor;
}

/* Some themes/plugins ship a global `svg path { fill: none !important }` that
 * would blank out our icons. Force our own paths to inherit the icon colour. */
#easpnet-live-chat .easpnet-lc-launcher__icon svg,
#easpnet-live-chat .easpnet-lc-launcher__icon svg path {
	fill: currentColor !important;
}

#easpnet-live-chat .easpnet-lc-launcher__text {
	display: inline-block;
	line-height: 1;
}

/* ── Mobile backdrop overlay ───────────────────────────────────────── *
 * Only shown on mobile (see the media query below). Hidden on desktop. */
#easpnet-live-chat .easpnet-lc-overlay {
	display: none;
}

/* ── Contact panel (the "new contact window") ──────────────────────── */
#easpnet-live-chat .easpnet-lc-panel {
	position: relative;
	z-index: 2;
	width: 340px;
	max-width: calc(100vw - 32px);
	background: #fff;
	border-radius: 14px;
	overflow: hidden;
	box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);

	/* Genie-like open/close: the panel scales out of the launcher corner.
	 * Collapsed base state — small, squashed toward the bottom-right, faded. */
	transform-origin: bottom right;
	transform: scale(0.2, 0.05) translateY(24px);
	opacity: 0;
	transition:
		transform 0.32s cubic-bezier(0.22, 1, 0.36, 1),
		opacity 0.24s ease;
	will-change: transform, opacity;
}

/* Open state — full size, fully visible. */
#easpnet-live-chat .easpnet-lc-panel.easpnet-lc-panel--open {
	transform: scale(1, 1) translateY(0);
	opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
	#easpnet-live-chat .easpnet-lc-panel {
		transition: opacity 0.15s ease;
		transform: none;
	}
	#easpnet-live-chat .easpnet-lc-panel.easpnet-lc-panel--open {
		transform: none;
	}
}

#easpnet-live-chat .easpnet-lc-panel__header {
	background: var(--easpnet-lc-primary);
	color: #fff;
	padding: var(--easpnet-lc-panel-header-padding);
	position: relative;
}

#easpnet-live-chat .easpnet-lc-panel__title {
	margin: 0;
	font-size: 18px;
	font-weight: 700;
	line-height: 1.5;
}

#easpnet-live-chat .easpnet-lc-panel__close {
	position: absolute;
	top: 16px;
	right: 14px;
	width: 32px;
	height: 32px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: transparent;
	/* Force a white 1px box regardless of theme button styles, and neutralise
	 * any inherited outline/box-shadow that themes add to focused buttons. */
	border: 0 !important;
	outline: none;
	box-shadow: none;
	color: #fff !important;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	border-radius: 6px;
}

#easpnet-live-chat .easpnet-lc-panel__close:hover {
	background: rgba(255, 255, 255, 0.15);
	border-color: #fff !important;
}

#easpnet-live-chat .easpnet-lc-panel__close:focus,
#easpnet-live-chat .easpnet-lc-panel__close:focus-visible {
	outline: 2px solid rgba(255, 255, 255, 0.9);
	outline-offset: 1px;
	border-color: #fff !important;
}

#easpnet-live-chat .easpnet-lc-panel__body {
	padding: var(--easpnet-lc-panel-body-padding);
}

/* Each contact option row */
#easpnet-live-chat .easpnet-lc-item {
	display: flex;
	align-items: flex-start;
	gap: 14px;
	padding: 24px 0;
	text-decoration: none;
	color: inherit;
}

#easpnet-live-chat .easpnet-lc-item:last-child {
	border-bottom: none;
}

#easpnet-live-chat .easpnet-lc-item__icon {
	flex: 0 0 26px;
	width: 26px;
	height: 26px;
	margin-top: 2px;
	color: var(--easpnet-lc-primary);
}

#easpnet-live-chat .easpnet-lc-item__icon svg,
#easpnet-live-chat .easpnet-lc-item__icon img {
	display: block;
	width: 26px;
	height: 26px;
	max-width: 26px;
	max-height: 26px;
	object-fit: contain;
	fill: currentColor;
}

/* Override a global `svg path { fill: none !important }` from other plugins. */
#easpnet-live-chat .easpnet-lc-item__icon svg,
#easpnet-live-chat .easpnet-lc-item__icon svg path {
	fill: currentColor !important;
}

#easpnet-live-chat .easpnet-lc-item__body {
	flex: 1 1 auto;
	min-width: 0;
	/* Column so the (inline) label sits on its own line above the desc, and
	 * align-items:flex-start keeps the label from stretching full width. */
	display: flex;
	flex-direction: column;
	align-items: flex-start;
}

/* Only the label is interactive. Keep it inline so just the text is a hit
 * target (not the whole row), and reset native <button> chrome so the
 * start-chat label looks identical to the <a> labels. */
#easpnet-live-chat .easpnet-lc-item__label {
	display: inline;
	align-self: flex-start;
	margin: 0 0 4px;
	padding: 0;
	background: none;
	border: none;
	font-family: inherit;
	font-size: var(--easpnet-lc-item-label-font-size);
	font-weight: 700;
	line-height: 1.4;
	color: var(--easpnet-lc-primary);
	text-decoration: underline;
	text-align: left;
	cursor: pointer;
}

/* Enabled-but-no-destination label: plain text, not a link. */
#easpnet-live-chat .easpnet-lc-item__label--static {
	cursor: default;
}

#easpnet-live-chat .easpnet-lc-item__desc {
	display: block;
	color: var(--easpnet-lc-muted);
	font-size: var(--easpnet-lc-item-desc-font-size);
	line-height: 1.5;
	word-break: break-word;
}

/* ── Visibility helpers ────────────────────────────────────────────── */
#easpnet-live-chat[hidden],
#easpnet-live-chat [hidden] {
	display: none !important;
}

/* ── Mobile ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
	#easpnet-live-chat.easpnet-lc {
		right: 16px;
		bottom: 16px;
	}

	/* Backdrop behind the panel. Fixed to the full viewport, fades in/out with
	 * the panel. Sits behind the panel (earlier DOM sibling, same stacking
	 * context) but above the page. */
	#easpnet-live-chat .easpnet-lc-overlay {
		display: block;
		position: fixed;
		z-index: 1;
		inset: 0;
		background: #374151;
		opacity: 0;
		transition: opacity 0.28s ease;
		pointer-events: none;
	}

	#easpnet-live-chat .easpnet-lc-overlay.easpnet-lc-overlay--open {
		opacity: 0.85;
		pointer-events: auto;
	}

	/* Launcher collapses to a circular icon-only button (hide the text). */
	#easpnet-live-chat .easpnet-lc-launcher {
		gap: 0;
		width: 56px;
		height: 56px;
		padding: 0 !important;
		border-radius: 50%;
	}

	#easpnet-live-chat .easpnet-lc-launcher__text {
		display: none;
	}

	#easpnet-live-chat .easpnet-lc-launcher__icon {
		width: 26px;
		height: 26px;
		flex: 0 0 26px;
	}

	#easpnet-live-chat .easpnet-lc-launcher__icon svg,
	#easpnet-live-chat .easpnet-lc-launcher__icon img {
		width: 26px;
		height: 26px;
		max-width: 26px;
		max-height: 26px;
	}

	/* Contact panel goes full-width, flush to the bottom of the screen with
	 * no bottom corners rounded. Pinned to the viewport (not the corner
	 * anchor) so it spans edge-to-edge. */
	#easpnet-live-chat .easpnet-lc-panel {
		position: fixed;
		z-index: 2;
		left: var(--easpnet-lc-mobile-panel-margin);
		right: var(--easpnet-lc-mobile-panel-margin);
		bottom: 0;
		width: auto;
		max-width: 100%;
		border-radius: 14px 14px 0 0;
		height: var(--easpnet-lc-mobile-panel-height);
		overflow-y: auto;          /* 內容超過就可捲動 */

		/* On mobile the panel is a full-width bottom sheet, so the genie rises
		 * from the bottom centre instead of the corner. */
		transform-origin: bottom center;
		transform: scale(0.85, 0.02) translateY(40px);
	}

	#easpnet-live-chat .easpnet-lc-panel.easpnet-lc-panel--open {
		transform: scale(1, 1) translateY(0);
	}
}
