/*
 * Three Rivers Chatbot — front-end widget styles.
 * Colors and shapes are matched to the live Three Rivers Therapy site
 * (deep teal / sage / cream palette, Inter body copy, rounded soft shadows)
 * without touching or depending on the active theme's stylesheet.
 */

#trc-chatbot,
#trc-chatbot * {
	box-sizing: border-box;
}

#trc-chatbot {
	--trc-primary: #1d3c3a;
	--trc-primary-dark: #143852;
	--trc-accent: #6b9e8a;
	--trc-secondary: #4f7fa6;
	--trc-bg: #f5f3ee;
	--trc-white: #ffffff;
	--trc-text: #24322f;
	--trc-text-muted: #5c6b66;
	--trc-border: rgba(29, 60, 58, 0.12);
	--trc-shadow: 0 10px 32px rgba(29, 60, 58, 0.16), 0 2px 8px rgba(29, 60, 58, 0.08);
	--trc-radius-lg: 20px;
	--trc-radius-md: 14px;
	--trc-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

	position: fixed;
	z-index: 999999;
	font-family: var(--trc-font);
	line-height: 1.45;
	-webkit-font-smoothing: antialiased;
}

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

/*
 * Dock: fixed-position anchor shared by the launcher and its nudge, so the
 * nudge is always positioned relative to the launcher itself (flexbox)
 * rather than separate hardcoded coordinates that could drift apart.
 * DOM order is launcher-first (primary control, first in tab order), then
 * nudge; column-reverse visually stacks the nudge directly above the
 * launcher (12 o'clock) without changing that tab order. Deliberately
 * not placed to the launcher's side - on this site that space is shared
 * with the language switcher, and stacking above it clears that entirely
 * regardless of exactly where that switcher sits.
 */
#trc-chatbot .trc-dock {
	position: fixed;
	right: 20px;
	bottom: 20px;
	z-index: 2;
	display: flex;
	flex-direction: column-reverse;
	align-items: center;
	gap: 12px;
}

/*
 * Launcher button. Every property a global theme/plugin rule could
 * plausibly target on :hover/:focus/:focus-visible/:active is set
 * explicitly, with !important, so nothing outside this stylesheet can
 * ever repaint this element's fill, border, outline or shadow - this is
 * the one component on the page most likely to collide with a sitewide
 * button/link style, since it's a bare <button> with no other class.
 */
#trc-chatbot .trc-launcher {
	position: relative;
	flex: none;
	width: 58px;
	height: 58px;
	margin: 0;
	padding: 0;
	border-radius: 50% !important;
	border: none !important;
	outline: none !important;
	background-color: var(--trc-primary) !important;
	background-image: none !important;
	color: var(--trc-white) !important;
	box-shadow: var(--trc-shadow) !important;
	display: flex;
	align-items: center;
	justify-content: center;
	overflow: hidden;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: transform 0.18s ease, background-color 0.18s ease;
}

#trc-chatbot .trc-launcher:hover {
	background-color: var(--trc-primary-dark) !important;
	border: none !important;
	outline: none !important;
	box-shadow: var(--trc-shadow) !important;
	transform: translateY(-2px);
}

#trc-chatbot .trc-launcher:active {
	background-color: var(--trc-primary-dark) !important;
	border: none !important;
	outline: none !important;
	box-shadow: var(--trc-shadow) !important;
	transform: translateY(0);
}

#trc-chatbot .trc-launcher:focus,
#trc-chatbot .trc-launcher:focus-visible {
	border: none !important;
	box-shadow: var(--trc-shadow) !important;
	outline: 3px solid var(--trc-secondary) !important;
	outline-offset: 3px;
}

#trc-chatbot .trc-launcher-close-icon {
	display: none;
}

#trc-chatbot .trc-launcher-icon,
#trc-chatbot .trc-launcher-close-icon {
	align-items: center;
	justify-content: center;
	color: inherit;
}

#trc-chatbot .trc-launcher-icon img {
	display: block;
	width: 26px;
	height: 26px;
	object-fit: contain;
	border: none;
	outline: none;
	pointer-events: none;
	-webkit-user-drag: none;
	user-select: none;
	-webkit-user-select: none;
}

#trc-chatbot .trc-launcher.is-open .trc-launcher-icon {
	display: none;
}

#trc-chatbot .trc-launcher.is-open .trc-launcher-close-icon {
	display: flex;
}

/*
 * "Need help?" proactive nudge - a single card/button (not a compound
 * control), positioned as a flex sibling of the launcher inside .trc-dock
 * so it always tracks the launcher's position and size.
 */
#trc-chatbot .trc-nudge {
	position: relative;
	flex: none;
	max-width: min(220px, calc(100vw - 40px));
	animation: trc-nudge-in 0.25s ease;
}

#trc-chatbot .trc-nudge[hidden] {
	display: none;
}

#trc-chatbot .trc-nudge-btn {
	display: block;
	width: 100%;
	margin: 0;
	font-family: inherit;
	font-size: 13.5px;
	font-weight: 600;
	line-height: 1.35;
	text-align: left;
	color: var(--trc-primary) !important;
	background-color: var(--trc-white) !important;
	background-image: none !important;
	border: 1px solid var(--trc-border) !important;
	border-radius: var(--trc-radius-md) !important;
	outline: none !important;
	box-shadow: var(--trc-shadow) !important;
	padding: 10px 14px;
	cursor: pointer;
	white-space: normal;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.15s ease, transform 0.15s ease;
}

#trc-chatbot .trc-nudge-btn:hover {
	background-color: var(--trc-bg) !important;
	border-color: var(--trc-border) !important;
	outline: none !important;
	box-shadow: var(--trc-shadow) !important;
	transform: translateY(-1px);
}

#trc-chatbot .trc-nudge-btn:active {
	background-color: var(--trc-bg) !important;
	border-color: var(--trc-border) !important;
	outline: none !important;
	box-shadow: var(--trc-shadow) !important;
	transform: translateY(0);
}

#trc-chatbot .trc-nudge-btn:focus,
#trc-chatbot .trc-nudge-btn:focus-visible {
	border-color: var(--trc-secondary) !important;
	box-shadow: var(--trc-shadow) !important;
	outline: 2px solid var(--trc-secondary) !important;
	outline-offset: 2px;
}

/* Tail pointing down, from the bubble toward the launcher below it */
#trc-chatbot .trc-nudge::after {
	content: '';
	position: absolute;
	left: 50%;
	bottom: -6px;
	width: 12px;
	height: 12px;
	background: var(--trc-white);
	border-right: 1px solid var(--trc-border);
	border-bottom: 1px solid var(--trc-border);
	transform: translateX(-50%) rotate(45deg);
	pointer-events: none;
}

@keyframes trc-nudge-in {
	from {
		opacity: 0;
		transform: translateY(6px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* Panel */
.trc-panel {
	position: fixed;
	right: 20px;
	bottom: 92px;
	width: 380px;
	max-width: calc(100vw - 32px);
	height: min(600px, calc(100vh - 120px));
	background: var(--trc-white);
	border-radius: var(--trc-radius-lg);
	box-shadow: var(--trc-shadow);
	border: 1px solid var(--trc-border);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	opacity: 0;
	transform: translateY(12px) scale(0.98);
	transform-origin: bottom right;
	transition: opacity 0.18s ease, transform 0.18s ease;
	pointer-events: none;
}

.trc-open .trc-panel {
	opacity: 1;
	transform: translateY(0) scale(1);
	pointer-events: auto;
}

.trc-panel[hidden] {
	display: none;
}

/* Header */
.trc-header {
	background: var(--trc-primary);
	color: var(--trc-white);
	padding: 14px 12px 14px 16px;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	flex: none;
}

.trc-header-info {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
}

.trc-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: var(--trc-accent);
	color: var(--trc-primary-dark);
	display: flex;
	align-items: center;
	justify-content: center;
	font-weight: 700;
	flex: none;
}

.trc-title {
	margin: 0;
	font-size: 15px;
	font-weight: 600;
	color: var(--trc-white);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.trc-subtitle {
	margin: 1px 0 0;
	font-size: 12px;
	color: rgba(255, 255, 255, 0.75);
}

.trc-header-actions {
	display: flex;
	align-items: center;
	gap: 2px;
	flex: none;
}

/*
 * Reset + close icon buttons inside the panel header. Same defensive
 * treatment as the launcher: every color/border/outline/shadow property
 * pinned explicitly for every interactive state, since these sit on a
 * dark teal header where any stray red/system focus color would be very
 * visible.
 */
#trc-chatbot .trc-icon-btn {
	width: 34px;
	height: 34px;
	margin: 0;
	border-radius: 50% !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	background-color: rgba(255, 255, 255, 0.1) !important;
	background-image: none !important;
	color: rgba(255, 255, 255, 0.95) !important;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.15s ease;
}

#trc-chatbot .trc-icon-btn svg {
	width: 18px;
	height: 18px;
	stroke-width: 2.25;
	overflow: visible;
}

#trc-chatbot .trc-icon-btn:hover {
	background-color: rgba(255, 255, 255, 0.2) !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	color: var(--trc-white) !important;
}

#trc-chatbot .trc-icon-btn:active {
	background-color: rgba(255, 255, 255, 0.28) !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	color: var(--trc-white) !important;
}

#trc-chatbot .trc-icon-btn:focus,
#trc-chatbot .trc-icon-btn:focus-visible {
	border: none !important;
	box-shadow: none !important;
	outline: 2px solid var(--trc-white) !important;
	outline-offset: 1px;
}

/* Body / messages */
.trc-body {
	flex: 1 1 auto;
	overflow: hidden;
	background: var(--trc-bg);
	display: flex;
	min-height: 0;
}

.trc-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.trc-msg {
	display: flex;
	max-width: 88%;
}

.trc-msg-bot {
	align-self: flex-start;
}

.trc-msg-user {
	align-self: flex-end;
}

.trc-bubble {
	padding: 10px 13px;
	border-radius: var(--trc-radius-md);
	font-size: 14px;
	word-wrap: break-word;
	white-space: normal;
}

.trc-msg-bot .trc-bubble {
	background: var(--trc-white);
	color: var(--trc-text);
	border: 1px solid var(--trc-border);
	border-bottom-left-radius: 4px;
}

.trc-msg-user .trc-bubble {
	background: var(--trc-primary);
	color: var(--trc-white);
	border-bottom-right-radius: 4px;
}

.trc-msg-notice .trc-bubble {
	background: var(--trc-bg);
	border: 1px solid var(--trc-border);
	border-left: 3px solid var(--trc-accent);
	color: var(--trc-text-muted);
}

.trc-contact-link {
	color: var(--trc-secondary);
	font-weight: 600;
	text-decoration: underline;
}

.trc-bubble a {
	color: var(--trc-secondary);
	text-decoration: underline;
	word-break: break-word;
}

.trc-bubble a:hover,
.trc-bubble a:focus {
	text-decoration: none;
}

/* Typing indicator */
.trc-typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 13px 14px;
}

.trc-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--trc-text-muted);
	opacity: 0.5;
	animation: trc-blink 1.2s infinite ease-in-out;
}

.trc-typing span:nth-child(2) {
	animation-delay: 0.2s;
}

.trc-typing span:nth-child(3) {
	animation-delay: 0.4s;
}

@keyframes trc-blink {
	0%, 80%, 100% {
		opacity: 0.3;
		transform: translateY(0);
	}
	40% {
		opacity: 1;
		transform: translateY(-2px);
	}
}

/* Privacy notice */
.trc-privacy {
	flex: none;
	display: flex;
	gap: 7px;
	align-items: flex-start;
	padding: 9px 16px;
	background: var(--trc-white);
	border-top: 1px solid var(--trc-border);
	font-size: 11.5px;
	line-height: 1.4;
	color: var(--trc-text-muted);
}

.trc-privacy-icon {
	flex: none;
	margin-top: 1px;
	color: var(--trc-secondary);
}

/* Input row */
.trc-input-row {
	flex: none;
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	background: var(--trc-white);
	border-top: 1px solid var(--trc-border);
}

.trc-input-row textarea {
	flex: 1;
	resize: none;
	max-height: 120px;
	min-height: 38px;
	padding: 9px 12px;
	border: 1px solid var(--trc-border);
	border-radius: 999px;
	font-family: inherit;
	font-size: 14px;
	color: var(--trc-text);
	background: var(--trc-bg);
	transition: border-color 0.15s ease;
}

.trc-input-row textarea:focus {
	outline: none;
	border-color: var(--trc-secondary);
	background: var(--trc-white);
}

.trc-input-row textarea:disabled {
	opacity: 0.6;
}

#trc-chatbot .trc-send-btn {
	flex: none;
	width: 38px;
	height: 38px;
	margin: 0;
	border-radius: 50% !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
	background-color: var(--trc-primary) !important;
	background-image: none !important;
	color: var(--trc-white) !important;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	-webkit-tap-highlight-color: transparent;
	transition: background-color 0.15s ease, opacity 0.15s ease;
}

#trc-chatbot .trc-send-btn:hover:not(:disabled) {
	background-color: var(--trc-primary-dark) !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
}

#trc-chatbot .trc-send-btn:active:not(:disabled) {
	background-color: var(--trc-primary-dark) !important;
	border: none !important;
	outline: none !important;
	box-shadow: none !important;
}

#trc-chatbot .trc-send-btn:disabled {
	opacity: 0.5;
	cursor: default;
}

#trc-chatbot .trc-send-btn:focus,
#trc-chatbot .trc-send-btn:focus-visible {
	border: none !important;
	box-shadow: none !important;
	outline: 2px solid var(--trc-secondary) !important;
	outline-offset: 2px;
}

/* Mobile: full-screen panel */
@media (max-width: 560px) {
	.trc-panel {
		right: 0;
		bottom: 0;
		left: 0;
		top: 0;
		width: 100%;
		height: 100%;
		max-width: 100%;
		border-radius: 0;
	}

	#trc-chatbot .trc-dock {
		right: 16px;
		bottom: 16px;
		gap: 10px;
	}

	#trc-chatbot .trc-launcher {
		width: 52px;
		height: 52px;
	}

	#trc-chatbot .trc-launcher-icon img {
		width: 24px;
		height: 24px;
	}

	#trc-chatbot .trc-nudge {
		max-width: min(190px, calc(100vw - 32px));
	}

	#trc-chatbot .trc-nudge-btn {
		font-size: 12.5px;
		padding: 8px 12px;
	}
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
	.trc-panel,
	.trc-launcher,
	.trc-nudge,
	.trc-nudge-btn {
		transition: none;
		animation: none;
	}

	.trc-typing span {
		animation: none;
		opacity: 0.8;
	}
}
