/*
 * ChatGR widget. WCAG 2.2 AA:
 * - Targets at least 44 by 44 px. The focus ring is two-tone (dark ring
 *   inside a white halo) so it shows on any page and any brand color.
 * - Panel text is #1F2937 on #FFFFFF (14.7:1), muted text #4B5563 (7.6:1).
 *   Brand pairs are checked at 4.5:1 before they can be saved.
 * - No fixed heights on text, so text spacing overrides never clip.
 * - Full width on small screens, no sideways scroll at 320 px.
 * - Reduced motion and forced colors (Windows High Contrast) are honored.
 */

#pgrc-root {
	--pgrc-brand: #1D4ED8;
	--pgrc-brand-text: #FFFFFF;
	--pgrc-ink: #1F2937;
	--pgrc-muted: #4B5563;
	--pgrc-line: #6B7280;
	--pgrc-soft: #F3F4F6;
	--pgrc-off: 20px;
	position: fixed;
	bottom: var(--pgrc-off);
	z-index: 2147482990;
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 12px;
	font: 400 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
	color: var(--pgrc-ink);
	text-align: left;
	letter-spacing: normal;
	word-spacing: normal;
	text-transform: none;
}
#pgrc-root.pgrc-side-right { right: var(--pgrc-off); }
#pgrc-root.pgrc-side-left { left: var(--pgrc-off); align-items: flex-start; }
#pgrc-root *, #pgrc-root *::before, #pgrc-root *::after { box-sizing: border-box; font-family: inherit; }
#pgrc-root [hidden] { display: none !important; }

#pgrc-root button:focus-visible,
#pgrc-root a:focus-visible,
#pgrc-root textarea:focus-visible,
#pgrc-root input:focus-visible,
#pgrc-root .pgrc-log:focus-visible {
	outline: 3px solid #111827;
	outline-offset: 2px;
	box-shadow: 0 0 0 5px #FFFFFF;
}

.pgrc-sr {
	position: absolute !important;
	width: 1px; height: 1px;
	margin: -1px; padding: 0;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
	border: 0;
}

/* Launcher */
#pgrc-root .pgrc-launch {
	width: 60px; height: 60px;
	min-width: 44px; min-height: 44px;
	display: inline-flex; align-items: center; justify-content: center;
	border: 2px solid var(--pgrc-brand-text);
	border-radius: 50%;
	background: var(--pgrc-brand);
	color: var(--pgrc-brand-text);
	box-shadow: 0 4px 14px rgba(17, 24, 39, .35);
	cursor: pointer;
	padding: 0;
}
#pgrc-root .pgrc-launch[aria-expanded="true"] { box-shadow: 0 2px 6px rgba(17, 24, 39, .35); }

/* Panel */
#pgrc-root .pgrc-panel {
	width: 380px;
	max-width: calc(100vw - 2 * var(--pgrc-off));
	max-height: calc(100vh - 120px);
	display: flex;
	flex-direction: column;
	background: #FFFFFF;
	color: var(--pgrc-ink);
	border: 1px solid var(--pgrc-line);
	border-radius: 14px;
	box-shadow: 0 12px 32px rgba(17, 24, 39, .3);
	overflow: hidden;
}
#pgrc-root .pgrc-head {
	display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
	padding: 12px 12px 12px 16px;
	background: var(--pgrc-brand);
	color: var(--pgrc-brand-text);
}
#pgrc-root .pgrc-titles { flex: 1 1 auto; min-width: 0; }
#pgrc-root .pgrc-avatar { flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #FFFFFF; }
#pgrc-root .pgrc-title { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 700; color: inherit; }
#pgrc-root .pgrc-sub { margin: 2px 0 0; font-size: 14px; color: inherit; }
#pgrc-root .pgrc-close {
	min-width: 44px; min-height: 44px;
	display: inline-flex; align-items: center; justify-content: center;
	background: transparent; color: inherit;
	border: 2px solid transparent; border-radius: 8px;
	cursor: pointer; padding: 0;
}
#pgrc-root .pgrc-close:hover { border-color: currentColor; }

#pgrc-root .pgrc-log {
	flex: 1 1 auto;
	min-height: 96px;
	overflow-y: auto;
	padding: 16px;
	display: flex; flex-direction: column; gap: 10px;
}
#pgrc-root .pgrc-msg { max-width: 88%; padding: 10px 12px; border-radius: 12px; overflow-wrap: anywhere; }
#pgrc-root .pgrc-msg p { margin: 0; white-space: pre-wrap; }
#pgrc-root .pgrc-msg-bot { align-self: flex-start; background: var(--pgrc-soft); color: var(--pgrc-ink); border: 1px solid #E5E7EB; }
#pgrc-root .pgrc-msg-you { align-self: flex-end; background: var(--pgrc-brand); color: var(--pgrc-brand-text); }
#pgrc-root .pgrc-sources { margin-top: 8px; font-size: 14px; }
#pgrc-root .pgrc-sources-title { margin: 0 0 4px; color: var(--pgrc-muted); font-weight: 600; }
#pgrc-root .pgrc-sources ul { margin: 0; padding-left: 18px; }
#pgrc-root .pgrc-sources a { color: #1E40AF; text-decoration: underline; }

#pgrc-root .pgrc-status { padding: 0 16px; min-height: 0; font-size: 14px; color: var(--pgrc-muted); }
#pgrc-root .pgrc-status:not(:empty) { padding-bottom: 6px; }
#pgrc-root .pgrc-alert:not(:empty) {
	margin: 0 16px 8px; padding: 8px 10px;
	border: 2px solid #B91C1C; border-radius: 8px;
	background: #FEF2F2; color: #7F1D1D; font-size: 14px;
}
#pgrc-root .pgrc-notice,
#pgrc-root .pgrc-idle {
	margin: 0 16px 8px; padding: 10px 12px;
	border: 1px solid var(--pgrc-line); border-radius: 8px;
	background: #FFFBEB; color: #78350F; font-size: 14px;
}
#pgrc-root .pgrc-notice p,
#pgrc-root .pgrc-idle p { margin: 0 0 8px; }

/* Live: the waiting line and messages from a person */
#pgrc-root .pgrc-live { margin: 0; padding: 0; }
#pgrc-root .pgrc-live-on {
	display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
	margin: 0 16px 8px; padding: 10px 12px;
	border: 2px solid var(--pgrc-line); border-radius: 8px;
	background: #F0F9FF; color: var(--pgrc-ink); font-size: 15px;
}
#pgrc-root .pgrc-live p { margin: 0; flex: 1 1 160px; font-weight: 600; }
#pgrc-root .pgrc-msg-person { border: 2px solid var(--pgrc-line); background: #FFFFFF; }
#pgrc-root .pgrc-event {
	margin: 4px 0 12px; padding: 8px 12px;
	border: 1px solid var(--pgrc-line); border-radius: 8px;
	background: #F0F9FF; color: var(--pgrc-ink); font-size: 14px; font-weight: 600; text-align: center;
}
#pgrc-root .pgrc-msg .pgrc-who { margin: 0 0 2px; font-size: 14px; font-weight: 700; color: var(--pgrc-muted); }

#pgrc-root .pgrc-msg-actions,
#pgrc-root .pgrc-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
#pgrc-root .pgrc-msg-actions .pgrc-action { background: #FFFFFF; }
#pgrc-root .pgrc-chip {
	min-height: 44px;
	padding: 8px 14px;
	border-radius: 22px;
	border: 2px solid var(--pgrc-brand);
	background: #FFFFFF;
	color: var(--pgrc-ink);
	font-size: 15px; font-weight: 600; line-height: 1.3;
	cursor: pointer;
}
#pgrc-root .pgrc-chip:hover { background: var(--pgrc-soft); }
#pgrc-root .pgrc-action,
#pgrc-root .pgrc-send {
	min-height: 44px;
	padding: 8px 14px;
	border-radius: 8px;
	font-size: 15px; font-weight: 600; line-height: 1.3;
	cursor: pointer;
}
#pgrc-root .pgrc-action { background: #FFFFFF; color: var(--pgrc-ink); border: 2px solid var(--pgrc-line); }
#pgrc-root .pgrc-action:hover { background: var(--pgrc-soft); }
#pgrc-root .pgrc-send { background: var(--pgrc-brand); color: var(--pgrc-brand-text); border: 2px solid var(--pgrc-brand); }
#pgrc-root .pgrc-send[aria-disabled="true"] { opacity: .7; cursor: progress; }

#pgrc-root .pgrc-form,
#pgrc-root .pgrc-sheet {
	border-top: 1px solid #E5E7EB;
	padding: 12px 16px 14px;
}
#pgrc-root .pgrc-form { display: block; }
#pgrc-root .pgrc-compose { display: flex; align-items: flex-end; gap: 8px; }
#pgrc-root .pgrc-compose textarea { flex: 1 1 auto; min-width: 0; max-height: 140px; resize: none; }
#pgrc-root .pgrc-hint { margin: 6px 0 0; font-size: 13px; color: var(--pgrc-muted); }
#pgrc-root .pgrc-send-icon {
	flex: 0 0 auto;
	width: 48px; height: 48px; min-height: 48px;
	padding: 0;
	display: inline-flex; align-items: center; justify-content: center;
	border-radius: 50%;
}
#pgrc-root textarea,
#pgrc-root input[type="text"],
#pgrc-root input[type="email"],
#pgrc-root input[type="tel"] {
	width: 100%;
	min-height: 44px;
	padding: 10px 12px;
	font-size: 16px; line-height: 1.4;
	color: var(--pgrc-ink);
	background: #FFFFFF;
	border: 2px solid var(--pgrc-line);
	border-radius: 8px;
	resize: vertical;
}
#pgrc-root textarea:focus,
#pgrc-root input[type="text"]:focus,
#pgrc-root input[type="email"]:focus,
#pgrc-root input[type="tel"]:focus { border-color: var(--pgrc-brand) !important; box-shadow: none; }
#pgrc-root textarea::placeholder { color: #6B7280; opacity: 1; }
#pgrc-root [aria-invalid="true"] { border-color: #B91C1C !important; }
#pgrc-root .pgrc-hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; opacity: 0; }

#pgrc-root .pgrc-sheet { max-height: 60vh; overflow-y: auto; }
#pgrc-root fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
#pgrc-root legend { padding: 0; margin-bottom: 8px; font-weight: 700; font-size: 16px; }
#pgrc-root .pgrc-field { margin-bottom: 10px; }
#pgrc-root .pgrc-field label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 15px; }
#pgrc-root .pgrc-check { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0 12px; }
#pgrc-root .pgrc-check input { width: 24px; height: 24px; margin: 2px 0 0; flex: 0 0 auto; }
#pgrc-root .pgrc-row { display: flex; flex-wrap: wrap; gap: 8px; }

/* Proactive note beside the launcher */
#pgrc-root .pgrc-bubble {
	display: flex; align-items: flex-start; gap: 4px;
	max-width: min(300px, calc(100vw - 2 * var(--pgrc-off)));
	background: #FFFFFF; color: var(--pgrc-ink);
	border: 1px solid var(--pgrc-line); border-radius: 12px;
	box-shadow: 0 6px 18px rgba(17, 24, 39, .25);
	padding: 4px;
}
#pgrc-root .pgrc-bubble-text {
	flex: 1 1 auto; min-height: 44px;
	padding: 8px 10px; text-align: left;
	background: transparent; color: inherit; border: 0; border-radius: 8px;
	font-size: 15px; line-height: 1.4; cursor: pointer;
}
#pgrc-root .pgrc-bubble-x {
	min-width: 44px; min-height: 44px;
	display: inline-flex; align-items: center; justify-content: center;
	background: transparent; color: var(--pgrc-muted); border: 0; border-radius: 8px; cursor: pointer;
}

/* Small screens: full width, no sideways scroll at 320 px. */
@media (max-width: 480px) {
	#pgrc-root { --pgrc-off: 12px; }
	#pgrc-root .pgrc-panel {
		position: fixed;
		left: 0; right: 0; bottom: 0; top: 0;
		width: 100%; max-width: 100%;
		max-height: none; height: 100%;
		border-radius: 0; border: 0;
	}
	#pgrc-root .pgrc-msg { max-width: 92%; }
}

/* Very short viewports and 400 percent zoom. */
@media (max-height: 420px) {
	#pgrc-root .pgrc-panel { max-height: calc(100vh - 80px); }
	#pgrc-root .pgrc-log { min-height: 80px; }
}

@media (prefers-reduced-motion: no-preference) {
	#pgrc-root .pgrc-panel { animation: pgrc-in .16s ease-out; }
	@keyframes pgrc-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
}

@media (forced-colors: active) {
	#pgrc-root .pgrc-launch,
	#pgrc-root .pgrc-send,
	#pgrc-root .pgrc-action,
	#pgrc-root .pgrc-close,
	#pgrc-root .pgrc-bubble-text,
	#pgrc-root .pgrc-bubble-x { border: 2px solid ButtonText; forced-color-adjust: auto; }
	#pgrc-root .pgrc-panel,
	#pgrc-root .pgrc-msg,
	#pgrc-root .pgrc-live-on,
	#pgrc-root .pgrc-bubble { border: 1px solid CanvasText; }
	#pgrc-root .pgrc-msg-person { border-width: 2px; }
	#pgrc-root button:focus-visible,
	#pgrc-root a:focus-visible,
	#pgrc-root textarea:focus-visible,
	#pgrc-root input:focus-visible { outline: 3px solid Highlight; box-shadow: none; }
}

@media print {
	#pgrc-root { display: none !important; }
}
