/**
 * Sacraw chat widget — self-contained styles.
 * Loaded only when SACRAW_CHAT_ENABLED.
 */

:root {
	--sacraw-chat-primary: #003399;
	--sacraw-chat-primary-dark: #00257a;
	--sacraw-chat-accent: #FF933B;
	--sacraw-chat-accent-dark: #E07E2B;
	--sacraw-chat-cream: #F7F5F1;
	--sacraw-chat-text: #1a1a1a;
	--sacraw-chat-muted: #6b7280;
	--sacraw-chat-border: #e5e7eb;
}

#sacraw-chat-root {
	position: fixed;
	bottom: 20px;
	right: 20px;
	z-index: 9998;
	font-family: 'Open Sans', system-ui, -apple-system, sans-serif;
}

#sacraw-chat-root[x-cloak] { display: none !important; }

/* ─── FAB ─── */
.sacraw-chat-fab {
	display: inline-flex;
	align-items: center;
	gap: 0.5rem;
	padding: 0.75rem 1.1rem 0.75rem 0.9rem;
	border-radius: 999px;
	background: var(--sacraw-chat-primary);
	color: #fff;
	border: none;
	box-shadow: 0 6px 22px rgba(0, 51, 153, 0.28);
	cursor: pointer;
	font-family: inherit;
	font-size: 0.95rem;
	font-weight: 600;
	transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.sacraw-chat-fab:hover {
	background: var(--sacraw-chat-primary-dark);
	transform: translateY(-1px);
	box-shadow: 0 10px 28px rgba(0, 51, 153, 0.38);
}
.sacraw-chat-fab:focus-visible {
	outline: 2px solid var(--sacraw-chat-accent);
	outline-offset: 2px;
}
.sacraw-chat-fab svg { flex-shrink: 0; }
.sacraw-chat-fab-label { white-space: nowrap; }

/* ─── Panel ─── */
.sacraw-chat-panel {
	position: absolute;
	bottom: 0;
	right: 0;
	width: 380px;
	max-width: calc(100vw - 20px);
	height: min(560px, calc(100vh - 40px));
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
	display: flex;
	flex-direction: column;
	overflow: hidden;
	border: 1px solid var(--sacraw-chat-border);
}

/* Entrance animation */
.sacraw-chat-enter            { transition: opacity 200ms ease, transform 200ms ease; }
.sacraw-chat-enter-start      { opacity: 0; transform: translateY(16px) scale(0.98); }
.sacraw-chat-enter-end        { opacity: 1; transform: translateY(0) scale(1); }

/* ─── Header ─── */
.sacraw-chat-header {
	background: var(--sacraw-chat-primary);
	color: #fff;
	padding: 0.85rem 1rem;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
}
.sacraw-chat-header-title {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	min-width: 0;
}
.sacraw-chat-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: #fff;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	overflow: hidden;
	padding: 4px;
}
.sacraw-chat-avatar img {
	width: 100%;
	height: 100%;
	object-fit: contain;
	display: block;
}
.sacraw-chat-brand {
	font-weight: 600;
	font-size: 0.95rem;
	line-height: 1.1;
}
.sacraw-chat-status {
	font-size: 0.72rem;
	opacity: 0.85;
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	margin-top: 0.1rem;
}
.sacraw-chat-dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #5fd68a;
	box-shadow: 0 0 0 0 rgba(95, 214, 138, 0.6);
	animation: sacraw-chat-pulse 2s ease-in-out infinite;
}
@keyframes sacraw-chat-pulse {
	0%, 100% { box-shadow: 0 0 0 0 rgba(95, 214, 138, 0.6); }
	50%      { box-shadow: 0 0 0 6px rgba(95, 214, 138, 0); }
}
.sacraw-chat-close {
	background: transparent;
	border: 0;
	color: inherit;
	padding: 6px;
	border-radius: 8px;
	cursor: pointer;
	opacity: 0.85;
	transition: opacity 0.15s, background 0.15s;
}
.sacraw-chat-close:hover { opacity: 1; background: rgba(255, 255, 255, 0.12); }
.sacraw-chat-close:focus-visible { outline: 2px solid var(--sacraw-chat-accent); outline-offset: 1px; }

/* ─── Info-only disclaimer band (§25 regulatory disclosure) ─── */
.sacraw-chat-disclaimer {
	padding: 0.75rem 1rem;
	font-size: 0.8125rem;
	line-height: 1.4;
	color: #7a5a00;
	background: #fff7e6;
	border-bottom: 1px solid #f2dfa8;
}
.sacraw-chat-disclaimer a {
	color: var(--sacraw-chat-primary);
	text-decoration: underline;
	font-weight: 600;
	white-space: nowrap;
}
.sacraw-chat-disclaimer a:hover { text-decoration-thickness: 2px; }

/* ─── Messages ─── */
.sacraw-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 1rem;
	background: var(--sacraw-chat-cream);
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}
.sacraw-chat-msg {
	display: flex;
	max-width: 85%;
}
.sacraw-chat-msg-bot { align-self: flex-start; }
.sacraw-chat-msg-user { align-self: flex-end; }

.sacraw-chat-bubble {
	padding: 0.6rem 0.85rem;
	border-radius: 14px;
	font-size: 0.9rem;
	line-height: 1.45;
	word-wrap: break-word;
	overflow-wrap: anywhere;
}
.sacraw-chat-msg-bot .sacraw-chat-bubble {
	background: #fff;
	color: var(--sacraw-chat-text);
	border: 1px solid var(--sacraw-chat-border);
	border-bottom-left-radius: 4px;
}
.sacraw-chat-msg-user .sacraw-chat-bubble {
	background: var(--sacraw-chat-primary);
	color: #fff;
	border-bottom-right-radius: 4px;
}
.sacraw-chat-bubble a {
	color: inherit;
	text-decoration: underline;
	text-underline-offset: 2px;
}

/* ─── Suggested chips ─── */
.sacraw-chat-suggested {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	margin-top: 0.35rem;
	padding-right: 1rem;
}
.sacraw-chat-chip {
	padding: 0.4rem 0.7rem;
	border-radius: 999px;
	background: #fff;
	border: 1px solid var(--sacraw-chat-border);
	font-size: 0.8rem;
	color: var(--sacraw-chat-primary);
	cursor: pointer;
	font-family: inherit;
	transition: background 0.15s, border-color 0.15s;
}
.sacraw-chat-chip:hover {
	background: var(--sacraw-chat-primary);
	color: #fff;
	border-color: var(--sacraw-chat-primary);
}

/* ─── Typing indicator ─── */
.sacraw-chat-typing {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	min-width: 44px;
	min-height: 20px;
}
.sacraw-chat-typing span {
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--sacraw-chat-muted);
	animation: sacraw-chat-bounce 1.4s infinite ease-in-out;
}
.sacraw-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.sacraw-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes sacraw-chat-bounce {
	0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
	40%           { transform: scale(1);   opacity: 1; }
}

.sacraw-chat-error {
	background: #fef2f2;
	color: #991b1b;
	font-size: 0.8rem;
	padding: 0.5rem 0.7rem;
	border-radius: 10px;
	border: 1px solid #fecaca;
	margin-top: 0.25rem;
}

/* ─── Composer ─── */
.sacraw-chat-composer {
	display: flex;
	align-items: flex-end;
	gap: 0.5rem;
	padding: 0.6rem;
	border-top: 1px solid var(--sacraw-chat-border);
	background: #fff;
}
.sacraw-chat-composer textarea {
	flex: 1;
	border: 1px solid var(--sacraw-chat-border);
	border-radius: 12px;
	padding: 0.55rem 0.7rem;
	font-family: inherit;
	font-size: 0.9rem;
	line-height: 1.4;
	resize: none;
	max-height: 120px;
	background: var(--sacraw-chat-cream);
	color: var(--sacraw-chat-text);
	transition: border-color 0.15s;
}
.sacraw-chat-composer textarea:focus {
	outline: none;
	border-color: var(--sacraw-chat-primary);
	background: #fff;
}
.sacraw-chat-composer textarea:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.sacraw-chat-send {
	background: var(--sacraw-chat-accent);
	color: var(--sacraw-chat-text);
	border: none;
	border-radius: 12px;
	width: 42px;
	height: 42px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background 0.15s, transform 0.15s;
	flex-shrink: 0;
}
.sacraw-chat-send:hover:not(:disabled) {
	background: var(--sacraw-chat-accent-dark);
	color: #fff;
}
.sacraw-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.sacraw-chat-send:focus-visible { outline: 2px solid var(--sacraw-chat-primary); outline-offset: 2px; }

/* ─── Footer ─── */
.sacraw-chat-foot {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.5rem;
	padding: 0.45rem 0.8rem;
	font-size: 0.7rem;
	color: var(--sacraw-chat-muted);
	background: #fafafa;
	border-top: 1px solid var(--sacraw-chat-border);
}
.sacraw-chat-reset {
	background: transparent;
	border: 0;
	color: var(--sacraw-chat-primary);
	cursor: pointer;
	font-size: 0.7rem;
	font-family: inherit;
	text-decoration: underline;
	padding: 0;
}
.sacraw-chat-reset:hover { color: var(--sacraw-chat-primary-dark); }

/* ─── Mobile: fullscreen takeover ─── */
@media (max-width: 639px) {
	#sacraw-chat-root {
		bottom: 14px;
		right: 14px;
	}
	.sacraw-chat-panel {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100dvh;
		max-width: 100%;
		border-radius: 0;
		border: 0;
	}
	.sacraw-chat-fab-label { display: none; }
	.sacraw-chat-fab { padding: 0.85rem; }
}

/* ─── Keep clear of the mobile sticky CTA when both are on screen ─── */
@media (max-width: 767px) {
	body:has(#mobile-sticky-cta:not(.translate-y-full)) #sacraw-chat-root {
		bottom: 110px;
	}
}

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

/* ─── Lead capture (V1.2) ─── */

/* Handoff pill — appears below a bot reply that routed to a Sacraw human */
.sacraw-chat-handoff-pill {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0.35rem 0 0.6rem 0;
	padding: 0.45rem 0.85rem;
	background: var(--sacraw-chat-accent);
	color: #1a1a1a;
	border: 1px solid var(--sacraw-chat-accent-dark);
	border-radius: 999px;
	font-size: 0.85rem;
	font-weight: 600;
	font-family: inherit;
	cursor: pointer;
	box-shadow: 0 2px 8px rgba(255, 147, 59, 0.25);
	transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.sacraw-chat-handoff-pill:hover {
	background: var(--sacraw-chat-accent-dark);
	color: #fff;
	transform: translateY(-1px);
	box-shadow: 0 4px 12px rgba(255, 147, 59, 0.35);
}
.sacraw-chat-handoff-pill:focus-visible {
	outline: 2px solid var(--sacraw-chat-primary);
	outline-offset: 2px;
}
.sacraw-chat-handoff-pill svg { flex-shrink: 0; }

/* System-note bubble — used for the post-submit thank-you message */
.sacraw-chat-msg-system .sacraw-chat-bubble {
	background: #ecfdf5;
	color: #064e3b;
	border: 1px solid #6ee7b7;
}

/* Lead form */
.sacraw-chat-leadform {
	margin: 0.5rem 0 1rem;
	background: var(--sacraw-chat-cream);
	border: 1px solid var(--sacraw-chat-border);
	border-radius: 12px;
	padding: 1rem;
}
.sacraw-chat-leadform[x-cloak] { display: none !important; }

.sacraw-chat-leadform-head h4 {
	font-family: 'DM Serif Display', Georgia, serif;
	font-size: 1.1rem;
	margin: 0 0 0.25rem;
	color: var(--sacraw-chat-primary);
}
.sacraw-chat-leadform-head p {
	margin: 0 0 0.85rem;
	font-size: 0.85rem;
	color: var(--sacraw-chat-muted);
	line-height: 1.4;
}

.sacraw-chat-leadform-fields {
	display: flex;
	flex-direction: column;
	gap: 0.65rem;
}
.sacraw-chat-leadform-fields label {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	font-size: 0.85rem;
	color: var(--sacraw-chat-text);
}
.sacraw-chat-leadform-fields label > span {
	font-weight: 600;
}
.sacraw-chat-leadform-fields input[type="text"],
.sacraw-chat-leadform-fields input[type="email"],
.sacraw-chat-leadform-fields input[type="tel"],
.sacraw-chat-leadform-fields textarea {
	font: inherit;
	padding: 0.55rem 0.65rem;
	border: 1px solid var(--sacraw-chat-border);
	border-radius: 8px;
	background: #fff;
	color: var(--sacraw-chat-text);
	font-size: 0.9rem;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.sacraw-chat-leadform-fields input:focus,
.sacraw-chat-leadform-fields textarea:focus {
	outline: none;
	border-color: var(--sacraw-chat-primary);
	box-shadow: 0 0 0 3px rgba(0, 51, 153, 0.15);
}
.sacraw-chat-leadform-fields textarea {
	resize: vertical;
	min-height: 60px;
}

.sacraw-chat-leadform-consent {
	flex-direction: row !important;
	align-items: flex-start;
	gap: 0.55rem !important;
	font-size: 0.8rem !important;
	color: var(--sacraw-chat-muted) !important;
	line-height: 1.4;
}
.sacraw-chat-leadform-consent input[type="checkbox"] {
	margin-top: 2px;
	flex-shrink: 0;
	width: 16px;
	height: 16px;
	accent-color: var(--sacraw-chat-primary);
	cursor: pointer;
}
.sacraw-chat-leadform-consent span { font-weight: 400 !important; }

.sacraw-chat-leadform-error {
	margin: 0;
	padding: 0.5rem 0.65rem;
	background: #fef2f2;
	border: 1px solid #fecaca;
	border-radius: 6px;
	color: #991b1b;
	font-size: 0.82rem;
}

.sacraw-chat-leadform-actions {
	display: flex;
	gap: 0.5rem;
	justify-content: flex-end;
	margin-top: 0.25rem;
}
.sacraw-chat-leadform-cancel,
.sacraw-chat-leadform-submit {
	font: inherit;
	font-size: 0.88rem;
	font-weight: 600;
	padding: 0.55rem 1rem;
	border-radius: 8px;
	border: 1px solid transparent;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.sacraw-chat-leadform-cancel {
	background: transparent;
	border-color: var(--sacraw-chat-border);
	color: var(--sacraw-chat-muted);
}
.sacraw-chat-leadform-cancel:hover {
	background: #fff;
	color: var(--sacraw-chat-text);
}
.sacraw-chat-leadform-submit {
	background: var(--sacraw-chat-primary);
	color: #fff;
}
.sacraw-chat-leadform-submit:hover { background: var(--sacraw-chat-primary-dark); }
.sacraw-chat-leadform-submit:disabled,
.sacraw-chat-leadform-cancel:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}
