/**
 * PC Onsite AI Chatbot — frontend styles.
 * Clean, professional, mobile-responsive. No external dependencies.
 */

.pcoai-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;
}

.pcoai-chatbot,
.pcoai-chatbot * {
	box-sizing: border-box;
}

.pcoai-chatbot {
	--pcoai-primary: #1565c0;
	--pcoai-primary-dark: #0d47a1;
	--pcoai-primary-contrast: #ffffff;
	--pcoai-surface: #ffffff;
	--pcoai-bg: #f6f8fb;
	--pcoai-text: #1f2937;
	--pcoai-text-muted: #5b6472;
	--pcoai-border: #e3e8f0;
	--pcoai-error-bg: #fdecea;
	--pcoai-error-text: #b3261e;
	--pcoai-radius: 16px;
	--pcoai-shadow: 0 12px 40px rgba(13, 71, 161, 0.22), 0 2px 8px rgba(15, 23, 42, 0.12);

	position: fixed;
	bottom: 24px;
	right: 24px;
	z-index: 9999;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	line-height: 1.45;
}

/* ---------------------------------------------------------------- Launcher */

.pcoai-chatbot__launcher {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 56px;
	height: 56px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--pcoai-primary-dark), var(--pcoai-primary));
	color: var(--pcoai-primary-contrast);
	cursor: pointer;
	box-shadow: 0 8px 24px rgba(13, 71, 161, 0.4);
	transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.pcoai-chatbot__launcher:hover {
	transform: translateY(-2px);
	box-shadow: 0 12px 28px rgba(13, 71, 161, 0.45);
}

.pcoai-chatbot__launcher:focus-visible {
	outline: 3px solid rgba(21, 101, 192, 0.5);
	outline-offset: 3px;
}

/* ------------------------------------------------------------------ Panel */

.pcoai-chatbot__panel {
	position: absolute;
	bottom: calc(100% + 14px);
	right: 0;
	display: flex;
	flex-direction: column;
	width: min(380px, calc(100vw - 48px));
	height: min(560px, calc(100vh - 140px));
	background: var(--pcoai-surface);
	border: 1px solid var(--pcoai-border);
	border-radius: var(--pcoai-radius);
	box-shadow: var(--pcoai-shadow);
	overflow: hidden;
	animation: pcoai-panel-in 0.22s ease-out;
}

.pcoai-chatbot__panel[hidden] {
	display: none;
}

@keyframes pcoai-panel-in {
	from {
		opacity: 0;
		transform: translateY(12px) scale(0.98);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* ----------------------------------------------------------------- Header */

.pcoai-chatbot__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 14px 16px;
	background: linear-gradient(135deg, var(--pcoai-primary-dark), var(--pcoai-primary));
	color: var(--pcoai-primary-contrast);
	flex: 0 0 auto;
}

.pcoai-chatbot__title {
	margin: 0;
	font-size: 16px;
	font-weight: 600;
}

.pcoai-chatbot__status {
	display: flex;
	align-items: center;
	gap: 6px;
	margin: 2px 0 0;
	font-size: 12px;
	opacity: 0.9;
}

.pcoai-chatbot__status-dot {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: #4caf50;
	display: inline-block;
	flex: 0 0 auto;
}

.pcoai-chatbot__header-actions {
	display: flex;
	align-items: center;
	gap: 4px;
	flex: 0 0 auto;
}

.pcoai-chatbot__clear,
.pcoai-chatbot__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: var(--pcoai-primary-contrast);
	cursor: pointer;
	transition: background 0.15s ease;
	flex: 0 0 auto;
}

.pcoai-chatbot__clear {
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	padding: 0;
	border: 0;
	border-radius: 9px;
	background: transparent;
	color: var(--pcoai-primary-contrast);
	cursor: pointer;
	transition: background 0.15s ease, opacity 0.15s ease;
}

.pcoai-chatbot__clear:hover {
	background: rgba(255, 255, 255, 0.18);
}

.pcoai-chatbot__clear:focus-visible {
	outline: 2px solid rgba(255, 255, 255, 0.8);
	outline-offset: 2px;
}

.pcoai-chatbot__clear:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

.pcoai-chatbot__close:hover {
	background: rgba(255, 255, 255, 0.18);
}

.pcoai-chatbot__close:focus-visible {
	outline: 2px solid rgba(255, 255, 255, 0.8);
	outline-offset: 2px;
}

/* --------------------------------------------------------------- Messages */

.pcoai-chatbot__messages {
	flex: 1 1 auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 16px;
	background: var(--pcoai-bg);
	overflow-y: auto;
	overscroll-behavior: contain;
	scroll-behavior: smooth;
	outline: none;
}

.pcoai-chatbot__messages:focus-visible {
	box-shadow: inset 0 0 0 2px rgba(21, 101, 192, 0.35);
}

.pcoai-chatbot__message {
	display: flex;
	width: 100%;
}

.pcoai-chatbot__message--assistant {
	justify-content: flex-start;
}

.pcoai-chatbot__message--user {
	justify-content: flex-end;
}

.pcoai-chatbot__bubble {
	max-width: 82%;
	padding: 10px 14px;
	border-radius: 14px;
	font-size: 14px;
	color: var(--pcoai-text);
	background: var(--pcoai-surface);
	border: 1px solid var(--pcoai-border);
	overflow-wrap: anywhere;
	word-break: break-word;
}

.pcoai-chatbot__message--assistant .pcoai-chatbot__bubble {
	border-bottom-left-radius: 4px;
}

.pcoai-chatbot__message--user .pcoai-chatbot__bubble {
	background: var(--pcoai-primary);
	border-color: var(--pcoai-primary);
	color: var(--pcoai-primary-contrast);
	border-bottom-right-radius: 4px;
}

.pcoai-chatbot__message-text {
	line-height: 1.5;
}

.pcoai-chatbot__message-text--plain {
	white-space: pre-wrap;
}

.pcoai-chatbot__message-text > :first-child {
	margin-top: 0;
}

.pcoai-chatbot__message-text > :last-child {
	margin-bottom: 0;
}

.pcoai-chatbot__message-text p {
	margin: 0 0 8px;
}

.pcoai-chatbot__message-text strong {
	font-weight: 600;
}

.pcoai-chatbot__message-text ul,
.pcoai-chatbot__message-text ol {
	margin: 0 0 8px;
	padding-left: 20px;
}

.pcoai-chatbot__message-text li {
	margin: 0 0 4px;
}

.pcoai-chatbot__message-text .pcoai-chatbot__md-heading {
	font-weight: 700;
	margin: 10px 0 6px;
}

.pcoai-chatbot__message-text .pcoai-chatbot__md-h1 {
	font-size: 16px;
}

.pcoai-chatbot__message-text .pcoai-chatbot__md-h2 {
	font-size: 15px;
}

.pcoai-chatbot__message-text .pcoai-chatbot__md-h3 {
	font-size: 14px;
}

.pcoai-chatbot__message-text hr {
	border: 0;
	border-top: 1px solid var(--pcoai-border);
	margin: 10px 0;
}

.pcoai-chatbot__message-text code {
	background: rgba(0, 0, 0, 0.06);
	border-radius: 4px;
	padding: 1px 4px;
	font-size: 13px;
}

.pcoai-chatbot__message-text a {
	color: var(--pcoai-primary);
	text-decoration: underline;
}

.pcoai-chatbot__table-wrap {
	overflow-x: auto;
	margin: 0 0 8px;
}

.pcoai-chatbot__message-text table {
	border-collapse: collapse;
	font-size: 12.5px;
	width: 100%;
}

.pcoai-chatbot__message-text th,
.pcoai-chatbot__message-text td {
	border: 1px solid var(--pcoai-border);
	padding: 4px 6px;
	text-align: left;
	vertical-align: top;
}

.pcoai-chatbot__message-text th {
	background: rgba(0, 0, 0, 0.04);
	font-weight: 700;
}

/* Typing / loading indicator */

.pcoai-chatbot__typing {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	min-width: 54px;
}

.pcoai-chatbot__dot {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--pcoai-text-muted);
	display: inline-block;
	animation: pcoai-bounce 1.2s infinite ease-in-out;
}

.pcoai-chatbot__dot:nth-child(2) {
	animation-delay: 0.15s;
}

.pcoai-chatbot__dot:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes pcoai-bounce {
	0%, 60%, 100% {
		transform: translateY(0);
		opacity: 0.5;
	}
	30% {
		transform: translateY(-4px);
		opacity: 1;
	}
}

/* ------------------------------------------------------------- Error state */

.pcoai-chatbot__error {
	padding: 9px 16px;
	background: var(--pcoai-error-bg);
	color: var(--pcoai-error-text);
	font-size: 13px;
	border-top: 1px solid #f5cdc9;
	flex: 0 0 auto;
}

.pcoai-chatbot__error[hidden] {
	display: none;
}

/* ---------------------------------------------------------------- Composer */

.pcoai-chatbot__composer {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 12px;
	background: var(--pcoai-surface);
	border-top: 1px solid var(--pcoai-border);
	flex: 0 0 auto;
}

.pcoai-chatbot__input {
	flex: 1 1 auto;
	min-height: 42px;
	max-height: 120px;
	padding: 10px 14px;
	border: 1px solid #cdd6e2;
	border-radius: 21px;
	background: var(--pcoai-surface);
	color: var(--pcoai-text);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	resize: none;
	overflow-y: auto;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pcoai-chatbot__input::placeholder {
	color: #8b95a5;
}

.pcoai-chatbot__input:focus {
	outline: none;
	border-color: var(--pcoai-primary);
	box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.18);
}

.pcoai-chatbot__send {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 42px;
	height: 42px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: var(--pcoai-primary);
	color: var(--pcoai-primary-contrast);
	cursor: pointer;
	transition: background 0.15s ease, opacity 0.15s ease;
	flex: 0 0 auto;
}

.pcoai-chatbot__send:hover:not(:disabled) {
	background: var(--pcoai-primary-dark);
}

.pcoai-chatbot__send:disabled {
	opacity: 0.45;
	cursor: default;
}

.pcoai-chatbot__send:focus-visible {
	outline: 3px solid rgba(21, 101, 192, 0.5);
	outline-offset: 2px;
}

/* ------------------------------------------------------------ Lead form */

.pcoai-chatbot__composer[hidden],
.pcoai-chatbot__lead[hidden] {
	display: none;
}

.pcoai-chatbot__lead {
	display: flex;
	flex-direction: column;
	gap: 10px;
	padding: 14px;
	background: var(--pcoai-surface);
	border-top: 1px solid var(--pcoai-border);
	flex: 0 0 auto;
}

.pcoai-chatbot__lead-intro {
	margin: 0;
	font-size: 13px;
	line-height: 1.5;
	color: var(--pcoai-text-muted);
}

.pcoai-chatbot__lead-fields {
	display: flex;
	flex-direction: column;
}

.pcoai-chatbot__lead-fields label {
	font-size: 12px;
	font-weight: 600;
	color: var(--pcoai-text);
	margin-bottom: 4px;
}

.pcoai-chatbot__lead-fields input {
	margin-bottom: 8px;
	padding: 9px 12px;
	border: 1px solid #cdd6e2;
	border-radius: 8px;
	background: var(--pcoai-surface);
	color: var(--pcoai-text);
	font-family: inherit;
	font-size: 14px;
	line-height: 1.4;
	transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pcoai-chatbot__lead-fields input::placeholder {
	color: #8b95a5;
}

.pcoai-chatbot__lead-fields input:focus {
	outline: none;
	border-color: var(--pcoai-primary);
	box-shadow: 0 0 0 3px rgba(21, 101, 192, 0.18);
}

.pcoai-chatbot__lead-fields input[aria-invalid='true'] {
	border-color: var(--pcoai-error-text);
}

.pcoai-chatbot__lead-submit {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	align-self: flex-start;
	padding: 10px 18px;
	border: 0;
	border-radius: 8px;
	background: var(--pcoai-primary);
	color: var(--pcoai-primary-contrast);
	font-family: inherit;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease, opacity 0.15s ease;
}

.pcoai-chatbot__lead-submit:hover:not(:disabled) {
	background: var(--pcoai-primary-dark);
}

.pcoai-chatbot__lead-submit:disabled {
	opacity: 0.6;
	cursor: default;
}

.pcoai-chatbot__lead-submit:focus-visible {
	outline: 3px solid rgba(21, 101, 192, 0.5);
	outline-offset: 2px;
}

/* --------------------------------------------------------- Mobile layout */

@media (max-width: 480px) {
	.pcoai-chatbot {
		bottom: 16px;
		right: 16px;
	}

	.pcoai-chatbot__panel {
		position: fixed;
		inset: 0;
		width: 100%;
		height: 100%;
		max-width: none;
		border-radius: 0;
		border: 0;
		animation: none;
	}

	.pcoai-chatbot__header {
		border-radius: 0;
		padding-top: max(14px, env(safe-area-inset-top));
	}

	.pcoai-chatbot__composer {
		padding-bottom: max(12px, env(safe-area-inset-bottom));
	}

	.pcoai-chatbot__lead {
		padding-bottom: max(14px, env(safe-area-inset-bottom));
	}
}

@media (max-width: 480px) and (display-mode: browser) {
	/* Reserve comfortable spacing when the virtual keyboard opens. */
	.pcoai-chatbot__panel {
		height: 100%;
	}
}

/* --------------------------------------------------------- Reduced motion */

@media (prefers-reduced-motion: reduce) {
	.pcoai-chatbot__panel,
	.pcoai-chatbot__launcher,
	.pcoai-chatbot__dot {
		animation: none;
		transition: none;
	}

	.pcoai-chatbot__messages {
		scroll-behavior: auto;
	}
}
