/**
 * Northbridge Chatbot — scoped to #nb-chatbot-root only
 *
 * Root is a zero-size fixed anchor (not display:contents — avoids WebKit/Safari layout bugs).
 */

#nb-chatbot-root {
	--nb-chatbot-accent: #b89d64;
	--nb-chatbot-bg: #0d1b2a;
	--nb-chatbot-surface: #ffffff;
	/* Single tone for message area + composer (no white band below the thread). */
	--nb-chatbot-chat-bg: #e7e9ee;
	--nb-chatbot-muted: rgba(255, 255, 255, 0.82);
	--nb-chatbot-radius: 14px;
	--nb-chatbot-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
	--nb-chatbot-launcher-shadow:
		inset 0 1px 0 rgba(255, 255, 255, 0.28),
		inset 0 -1px 0 rgba(13, 27, 42, 0.12),
		0 2px 4px rgba(13, 27, 42, 0.06),
		0 8px 22px rgba(13, 27, 42, 0.22),
		0 18px 40px rgba(13, 27, 42, 0.16);
	--nb-chatbot-launcher-shadow-hover:
		inset 0 1px 0 rgba(255, 255, 255, 0.32),
		inset 0 -1px 0 rgba(13, 27, 42, 0.1),
		0 4px 8px rgba(13, 27, 42, 0.08),
		0 12px 28px rgba(13, 27, 42, 0.26),
		0 22px 48px rgba(184, 157, 100, 0.18);
	position: fixed;
	left: 0;
	top: 0;
	width: 0;
	height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	overflow: visible;
	/* Host must receive hit-testing for ShadowRoot UI; none would pass clicks to elements below (e.g. theme toggle). */
	pointer-events: auto;
	/* Above .nb-header (10050) and .nb-theme-toggle--floating (10042) */
	z-index: 10070;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.45;
}

#nb-chatbot-root *,
#nb-chatbot-root *::before,
#nb-chatbot-root *::after {
	box-sizing: border-box;
}

/* Visually hidden labels inside Shadow DOM (theme .screen-reader-text does not apply). */
#nb-chatbot-root .nb-chatbot-sr-only {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	width: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	word-wrap: normal !important;
}

/* Launcher — pill with depth, soft gold glow, optional icon + label */
#nb-chatbot-root .nb-chatbot__launcher {
	position: fixed;
	bottom: max(1rem, env(safe-area-inset-bottom, 0px));
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 0.7rem 1.2rem 0.7rem 0.95rem;
	min-height: 50px;
	border: none;
	border-radius: 100px;
	color: #fff;
	font: inherit;
	font-weight: 600;
	font-size: 0.9375rem;
	letter-spacing: 0.04em;
	text-transform: none;
	cursor: pointer;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	background-color: var(--nb-chatbot-accent);
	background-image: linear-gradient(
		165deg,
		rgba(255, 255, 255, 0.22) 0%,
		rgba(255, 255, 255, 0) 42%,
		rgba(13, 27, 42, 0.14) 100%
	);
	box-shadow: var(--nb-chatbot-launcher-shadow);
	transition:
		transform 0.28s cubic-bezier(0.34, 1.2, 0.64, 1),
		box-shadow 0.28s ease,
		filter 0.22s ease;
	z-index: 10071;
	pointer-events: auto;
	touch-action: manipulation;
	-webkit-tap-highlight-color: transparent;
}

#nb-chatbot-root .nb-chatbot__launcher-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	line-height: 0;
	opacity: 0.98;
}

#nb-chatbot-root .nb-chatbot__launcher-icon-svg {
	display: block;
	filter: drop-shadow(0 1px 1px rgba(13, 27, 42, 0.15));
}

#nb-chatbot-root .nb-chatbot__launcher-text {
	white-space: nowrap;
}

#nb-chatbot-root.nb-chatbot--right .nb-chatbot__launcher {
	right: max(1rem, env(safe-area-inset-right, 0px));
	left: auto;
}

/*
 * Theme uses a fixed bottom-left control (~2.75rem + ~2.5rem from bottom). When chat is also left,
 * sit above it so the two controls do not overlap.
 */
#nb-chatbot-root.nb-chatbot--left .nb-chatbot__launcher {
	left: max(1rem, env(safe-area-inset-left, 0px));
	right: auto;
	bottom: max(6.25rem, calc(2.75rem + 2.5rem + 1rem + env(safe-area-inset-bottom, 0px)));
}

#nb-chatbot-root .nb-chatbot__launcher:hover {
	filter: brightness(1.04);
	transform: translateY(-2px) scale(1.02);
	box-shadow: var(--nb-chatbot-launcher-shadow-hover);
	outline: none;
}

#nb-chatbot-root .nb-chatbot__launcher:focus {
	outline: 0 !important;
}

#nb-chatbot-root .nb-chatbot__launcher:focus-visible {
	filter: brightness(1.05);
	transform: translateY(-1px);
	box-shadow:
		var(--nb-chatbot-launcher-shadow-hover),
		0 0 0 3px rgba(255, 255, 255, 0.35),
		0 0 0 5px rgba(184, 157, 100, 0.45);
	outline: none;
}

#nb-chatbot-root .nb-chatbot__launcher:active {
	transform: translateY(0) scale(0.99);
	filter: brightness(0.97);
	box-shadow:
		inset 0 2px 4px rgba(13, 27, 42, 0.15),
		0 4px 12px rgba(13, 27, 42, 0.18);
	transition-duration: 0.08s;
}

/* Panel */
#nb-chatbot-root .nb-chatbot__panel {
	position: fixed;
	bottom: max(4.75rem, calc(env(safe-area-inset-bottom, 0px) + 3.5rem));
	width: min(100% - 1.5rem, 400px);
	max-height: min(78vh, 560px);
	display: flex;
	flex-direction: column;
	/* Same as message area: avoids harsh white vertical “rails” beside the dark header (panel≠header seam). */
	background: var(--nb-chatbot-chat-bg);
	color: #0d1b2a;
	border-radius: var(--nb-chatbot-radius);
	box-shadow: var(--nb-chatbot-shadow);
	overflow: hidden;
	z-index: 10072;
	opacity: 0;
	visibility: hidden;
	transform: translateY(0.5rem) scale(0.98);
	transition: opacity 0.18s ease, visibility 0.18s ease, transform 0.18s ease;
	pointer-events: auto;
}

#nb-chatbot-root.nb-chatbot--right .nb-chatbot__panel {
	right: max(0.75rem, env(safe-area-inset-right, 0px));
	left: auto;
}

#nb-chatbot-root.nb-chatbot--left .nb-chatbot__panel {
	left: max(0.75rem, env(safe-area-inset-left, 0px));
	right: auto;
	/* Launcher is shifted up for the theme toggle; keep panel above it */
	bottom: max(10.5rem, calc(6.25rem + 3.5rem + env(safe-area-inset-bottom, 0px)));
}

#nb-chatbot-root.is-open .nb-chatbot__panel {
	opacity: 1;
	visibility: visible;
	transform: translateY(0) scale(1);
}

#nb-chatbot-root .nb-chatbot__panel[hidden] {
	display: none !important;
}

#nb-chatbot-root.is-open .nb-chatbot__panel {
	display: flex !important;
}

#nb-chatbot-root .nb-chatbot__head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.5rem 1rem 0.5rem;
	background: var(--nb-chatbot-bg);
	color: #fff;
	/* Match panel top radius so the dark header fills the curve (avoids white panel bg peeking). */
	border-top-left-radius: var(--nb-chatbot-radius);
	border-top-right-radius: var(--nb-chatbot-radius);
	position: relative;
	z-index: 1;
	align-self: stretch;
	width: 100%;
	max-width: 100%;
	margin: 0;
	flex-shrink: 0;
	box-sizing: border-box;
}

#nb-chatbot-root .nb-chatbot__title {
	margin: 0;
	font-size: 1.05rem;
	font-weight: 700;
	line-height: 1.25;
}

#nb-chatbot-root .nb-chatbot__close {
	background: transparent;
	border: none;
	color: #fff;
	font-size: 1.5rem;
	line-height: 1;
	cursor: pointer;
	padding: 0.15rem 0.35rem;
	border-radius: 6px;
}

#nb-chatbot-root .nb-chatbot__close:hover,
#nb-chatbot-root .nb-chatbot__close:focus-visible {
	background: rgba(255, 255, 255, 0.12);
	outline: none;
}

#nb-chatbot-root .nb-chatbot__body {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	background: var(--nb-chatbot-chat-bg);
	border-radius: 0 0 var(--nb-chatbot-radius) var(--nb-chatbot-radius);
}

#nb-chatbot-root .nb-chatbot__first-visit[hidden],
#nb-chatbot-root .nb-chatbot__thread-view[hidden] {
	display: none !important;
}

#nb-chatbot-root .nb-chatbot__first-visit,
#nb-chatbot-root .nb-chatbot__thread-view {
	flex: 1;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

#nb-chatbot-root .nb-chatbot__welcome {
	margin: 0;
	padding: 0.85rem 1rem;
	font-size: 0.9rem;
	color: rgba(13, 27, 42, 0.78);
	max-height: 6.5em;
	overflow: auto;
	flex-shrink: 0;
	background: transparent;
}

#nb-chatbot-root .nb-chatbot__form {
	padding: 0 1rem 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
	flex: 1;
	min-height: 0;
	overflow: auto;
}

#nb-chatbot-root .nb-chatbot__thread {
	flex: 1;
	min-height: 120px;
	overflow: auto;
	padding: 0.65rem 1rem 0.75rem;
	display: flex;
	flex-direction: column;
	gap: 0.625rem;
	background: transparent;
}

/*
 * Bubble shape (reference layout — colors unchanged):
 * Visitor = right, “tail” at top-right (sharp corner).
 * Staff = left, “tail” at top-left (sharp corner).
 */
#nb-chatbot-root .nb-chatbot__bubble {
	max-width: min(78%, 20.5rem);
	min-width: 0;
	padding: 0.75rem 0.95rem;
	font-size: 0.9375rem;
	line-height: 1.5;
	font-weight: 500;
	letter-spacing: 0.01em;
}

#nb-chatbot-root .nb-chatbot__bubble--visitor {
	align-self: flex-end;
	/* top-left, top-right, bottom-right, bottom-left — sharp top-right */
	border-radius: 1.125rem 0 1.125rem 1.125rem;
	background: var(--nb-chatbot-bg);
	color: #fff;
}

#nb-chatbot-root .nb-chatbot__bubble--visitor .nb-chatbot__bubble-who {
	color: rgba(255, 255, 255, 0.82);
	font-size: 0.72rem;
	display: block;
	margin-bottom: 0.2rem;
	font-weight: 600;
}

#nb-chatbot-root .nb-chatbot__bubble--admin {
	align-self: flex-start;
	/* Sharp top-left */
	border-radius: 0 1.125rem 1.125rem 1.125rem;
	background: #ffffff;
	color: #0d1b2a;
	border: 1px solid rgba(13, 27, 42, 0.1);
	box-shadow: 0 1px 2px rgba(13, 27, 42, 0.06);
}

#nb-chatbot-root .nb-chatbot__bubble--admin .nb-chatbot__bubble-who {
	color: rgba(13, 27, 42, 0.55);
	font-size: 0.72rem;
	display: block;
	margin-bottom: 0.2rem;
	font-weight: 600;
}

#nb-chatbot-root .nb-chatbot__bubble-body {
	word-break: break-word;
}

#nb-chatbot-root .nb-chatbot__followup {
	padding: 0 1rem 1rem;
	display: flex;
	flex-direction: column;
	gap: 0.55rem;
	flex-shrink: 0;
	background: transparent;
}

#nb-chatbot-root .nb-chatbot__textarea--followup {
	min-height: 72px;
}

#nb-chatbot-root .nb-chatbot__input,
#nb-chatbot-root .nb-chatbot__textarea {
	width: 100%;
	padding: 0.55rem 0.85rem;
	border: 1px solid rgba(13, 27, 42, 0.16);
	border-radius: 10px;
	font: inherit;
	font-size: 0.95rem;
	background: #fff;
}

#nb-chatbot-root .nb-chatbot__textarea {
	resize: vertical;
	min-height: 96px;
}

#nb-chatbot-root .nb-chatbot__input:focus,
#nb-chatbot-root .nb-chatbot__textarea:focus {
	outline: none;
	border-color: var(--nb-chatbot-accent);
	box-shadow: 0 0 0 3px rgba(184, 157, 100, 0.25);
}

#nb-chatbot-root .nb-chatbot__consent {
	display: flex;
	align-items: flex-start;
	gap: 0.5rem;
	font-size: 0.8rem;
	color: rgba(13, 27, 42, 0.72);
	cursor: pointer;
}

#nb-chatbot-root .nb-chatbot__consent input {
	margin-top: 0.2rem;
	flex-shrink: 0;
}

#nb-chatbot-root .nb-chatbot__status {
	min-height: 1.25em;
	margin: 0;
	font-size: 0.85rem;
	color: rgba(13, 27, 42, 0.72);
}

#nb-chatbot-root .nb-chatbot__status.is-error {
	color: #b42318;
}

#nb-chatbot-root .nb-chatbot__status.is-success {
	color: #0d1b2a;
}

#nb-chatbot-root .nb-chatbot__submit {
	width: 100%;
	padding: 0.65rem 1rem;
	border: none;
	border-radius: 999px;
	background: var(--nb-chatbot-accent);
	color: #fff;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	transition: filter 0.15s ease;
}

#nb-chatbot-root .nb-chatbot__submit:hover:not(:disabled),
#nb-chatbot-root .nb-chatbot__submit:focus-visible:not(:disabled) {
	filter: brightness(1.06);
	outline: none;
}

#nb-chatbot-root .nb-chatbot__submit:disabled {
	opacity: 0.65;
	cursor: not-allowed;
}

@media screen and (max-width: 380px) {
	#nb-chatbot-root .nb-chatbot__launcher-text {
		display: none;
	}

	#nb-chatbot-root .nb-chatbot__launcher {
		width: 3.35rem;
		height: 3.35rem;
		min-height: 3.35rem;
		padding: 0;
		border-radius: 50%;
	}

	#nb-chatbot-root .nb-chatbot__launcher-icon-svg {
		width: 22px;
		height: 22px;
	}

	#nb-chatbot-root .nb-chatbot__panel {
		width: 100%;
		left: 0 !important;
		right: 0 !important;
		bottom: max(4.25rem, env(safe-area-inset-bottom, 0px));
		max-height: 85vh;
		border-radius: var(--nb-chatbot-radius) var(--nb-chatbot-radius) 0 0;
	}

	#nb-chatbot-root.nb-chatbot--left .nb-chatbot__panel {
		bottom: max(10.5rem, calc(6.25rem + 3.5rem + env(safe-area-inset-bottom, 0px)));
	}
}

@media (prefers-reduced-motion: reduce) {
	#nb-chatbot-root .nb-chatbot__launcher,
	#nb-chatbot-root .nb-chatbot__panel,
	#nb-chatbot-root .nb-chatbot__submit {
		transition: none;
	}
}
