/* ==========================================================================
   YC Chatbot – Frontend Widget Styles
   ========================================================================== */

/* --- Variables (--yc-primary is set inline by PHP) --- */
.yc-chatbot {
	--yc-primary-hover: color-mix(in srgb, var(--yc-primary) 82%, black);
	--yc-primary-light: color-mix(in srgb, var(--yc-primary) 15%, white);
	--yc-bg: #ffffff;
	--yc-bg-secondary: #f3f4f6;
	--yc-text: #1f2937;
	--yc-text-light: #6b7280;
	--yc-border: #e5e7eb;
	--yc-radius: 16px;
	--yc-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
	--yc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;

	font-family: var(--yc-font);
	font-size: 14px;
	line-height: 1.5;
	box-sizing: border-box;
}

.yc-chatbot *,
.yc-chatbot *::before,
.yc-chatbot *::after {
	box-sizing: border-box;
	margin: 0;
	padding: 0;
}

/* --- Dark mode --- */
@media (prefers-color-scheme: dark) {
	.yc-chatbot {
		--yc-bg: #1e1e2e;
		--yc-bg-secondary: #2a2a3c;
		--yc-text: #e4e4e7;
		--yc-text-light: #a1a1aa;
		--yc-border: #3f3f50;
		--yc-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
	}
}

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
	.yc-chatbot *,
	.yc-chatbot *::before,
	.yc-chatbot *::after {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}
}

/* --- Launcher Button --- */
.yc-chatbot__launcher {
	position: fixed;
	bottom: 24px;
	z-index: 99998;
	display: flex;
	align-items: center;
	justify-content: center;
	width: 60px;
	height: 60px;
	border: none;
	border-radius: 50%;
	background: var(--yc-primary);
	color: #fff;
	cursor: pointer;
	box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
	transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.2s ease, box-shadow 0.2s ease;
}

.yc-chatbot[data-position="right"] .yc-chatbot__launcher {
	right: 24px;
}

.yc-chatbot[data-position="left"] .yc-chatbot__launcher {
	left: 24px;
}

.yc-chatbot__launcher:hover {
	transform: scale(1.08);
	background: var(--yc-primary-hover);
	box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

.yc-chatbot__launcher:focus-visible {
	outline: 3px solid #000;
	outline-offset: 3px;
}

@media (prefers-color-scheme: dark) {
	.yc-chatbot__launcher:focus-visible {
		outline-color: #fff;
	}
}

/* Unread badge */
.yc-chatbot__badge {
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 20px;
	height: 20px;
	border-radius: 10px;
	background: #ef4444;
	color: #fff;
	font-size: 11px;
	font-weight: 700;
	line-height: 20px;
	text-align: center;
	padding: 0 5px;
	display: none;
	animation: yc-pop-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.yc-chatbot__badge--visible {
	display: block;
}

@keyframes yc-pop-in {
	from { transform: scale(0); }
	to { transform: scale(1); }
}

/* Icon swap */
.yc-chatbot__launcher-icon--close {
	display: none;
}

.yc-chatbot--open .yc-chatbot__launcher-icon--chat {
	display: none;
}

.yc-chatbot--open .yc-chatbot__launcher-icon--close {
	display: block;
}

/* --- Chat Window --- */
.yc-chatbot__window {
	position: fixed;
	bottom: 100px;
	z-index: 99999;
	display: flex;
	flex-direction: column;
	width: 380px;
	height: 520px;
	max-height: 70vh;
	background: var(--yc-bg);
	border-radius: var(--yc-radius);
	box-shadow: var(--yc-shadow);
	overflow: hidden;
	animation: yc-slide-up 0.3s ease-out both;
}

.yc-chatbot[data-position="right"] .yc-chatbot__window {
	right: 24px;
}

.yc-chatbot[data-position="left"] .yc-chatbot__window {
	left: 24px;
}

.yc-chatbot__window[hidden] {
	display: none;
}

@keyframes yc-slide-up {
	from {
		opacity: 0;
		transform: translateY(20px) scale(0.95);
	}
	to {
		opacity: 1;
		transform: translateY(0) scale(1);
	}
}

/* --- Header --- */
.yc-chatbot__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	background: linear-gradient(135deg, var(--yc-primary), var(--yc-primary-hover));
	color: #fff;
	flex-shrink: 0;
}

.yc-chatbot__title {
	font-size: 16px;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.yc-chatbot__header-actions {
	display: flex;
	align-items: center;
	gap: 6px;
}

.yc-chatbot__header-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 28px;
	height: 28px;
	border: none;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.2);
	color: #fff;
	font-size: 16px;
	line-height: 1;
	cursor: pointer;
	transition: background 0.2s ease;
}

.yc-chatbot__header-btn:hover {
	background: rgba(255, 255, 255, 0.35);
}

.yc-chatbot__header-btn:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}

.yc-chatbot__close {
	font-size: 20px;
}

/* --- Messages --- */
.yc-chatbot__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 8px;
	scroll-behavior: smooth;
	scrollbar-width: thin;
	scrollbar-color: var(--yc-border) transparent;
}

.yc-chatbot__messages::-webkit-scrollbar {
	width: 5px;
}

.yc-chatbot__messages::-webkit-scrollbar-track {
	background: transparent;
}

.yc-chatbot__messages::-webkit-scrollbar-thumb {
	background: var(--yc-border);
	border-radius: 10px;
}

/* --- Scroll-to-bottom button --- */
.yc-chatbot__scroll-btn {
	position: absolute;
	bottom: 72px;
	left: 50%;
	transform: translateX(-50%) translateY(10px);
	opacity: 0;
	pointer-events: none;
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 6px 14px;
	border: none;
	border-radius: 20px;
	background: var(--yc-bg);
	color: var(--yc-text);
	font-size: 12px;
	font-weight: 500;
	box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
	cursor: pointer;
	transition: opacity 0.2s ease, transform 0.2s ease;
	z-index: 2;
}

.yc-chatbot__scroll-btn--visible {
	opacity: 1;
	pointer-events: auto;
	transform: translateX(-50%) translateY(0);
}

.yc-chatbot__scroll-btn svg {
	width: 14px;
	height: 14px;
}

/* --- Message Bubbles --- */
.yc-chatbot__message {
	max-width: 80%;
	padding: 10px 16px;
	overflow-wrap: break-word;
	word-break: break-word;
	animation: yc-fade-in 0.25s ease;
	white-space: pre-wrap;
}

.yc-chatbot__message--user {
	align-self: flex-end;
	background: var(--yc-primary);
	color: #fff;
	border-radius: 16px 16px 4px 16px;
	margin-left: 40px;
}

.yc-chatbot__message--assistant {
	align-self: flex-start;
	background: var(--yc-bg-secondary);
	color: var(--yc-text);
	border-radius: 16px 16px 16px 4px;
	margin-right: 40px;
}

/* Timestamp */
.yc-chatbot__time {
	display: block;
	font-size: 10px;
	opacity: 0.6;
	margin-top: 4px;
}

.yc-chatbot__message--user .yc-chatbot__time {
	text-align: right;
}

@keyframes yc-fade-in {
	from {
		opacity: 0;
		transform: translateY(8px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* --- Typing Indicator --- */
.yc-chatbot__typing {
	display: flex;
	align-items: center;
	gap: 4px;
	padding: 14px 16px;
}

.yc-chatbot__typing span {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--yc-text-light);
	animation: yc-bounce 1.4s infinite ease-in-out both;
}

.yc-chatbot__typing span:nth-child(1) {
	animation-delay: -0.32s;
}

.yc-chatbot__typing span:nth-child(2) {
	animation-delay: -0.16s;
}

.yc-chatbot__typing span:nth-child(3) {
	animation-delay: 0s;
}

@keyframes yc-bounce {
	0%, 80%, 100% {
		transform: scale(0);
		opacity: 0.4;
	}
	40% {
		transform: scale(1);
		opacity: 1;
	}
}

/* --- Error --- */
.yc-chatbot__error {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin: 0 16px 8px;
	padding: 10px 14px;
	background: #fef2f2;
	border-left: 3px solid #ef4444;
	border-radius: 6px;
	color: #991b1b;
	font-size: 13px;
	animation: yc-fade-in 0.2s ease;
}

@media (prefers-color-scheme: dark) {
	.yc-chatbot__error {
		background: #3b1c1c;
		color: #fca5a5;
	}
}

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

.yc-chatbot__error-icon {
	flex-shrink: 0;
	font-size: 16px;
}

.yc-chatbot__retry {
	flex-shrink: 0;
	border: none;
	background: none;
	color: #dc2626;
	font-weight: 600;
	font-size: 13px;
	cursor: pointer;
	text-decoration: underline;
	white-space: nowrap;
}

.yc-chatbot__retry:hover {
	color: #991b1b;
}

.yc-chatbot__retry:focus-visible {
	outline: 2px solid #dc2626;
	outline-offset: 2px;
}

/* --- Input Form --- */
.yc-chatbot__form {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 16px;
	border-top: 1px solid var(--yc-border);
	background: var(--yc-bg);
	flex-shrink: 0;
}

.yc-chatbot__input {
	flex: 1;
	min-width: 0;
	border: 1px solid var(--yc-border);
	border-radius: 24px;
	padding: 10px 16px;
	font-size: 14px;
	font-family: var(--yc-font);
	color: var(--yc-text);
	background: var(--yc-bg);
	outline: none;
	transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.yc-chatbot__input:focus {
	border-color: var(--yc-primary);
	box-shadow: 0 0 0 3px var(--yc-primary-light);
}

.yc-chatbot__input::placeholder {
	color: var(--yc-text-light);
	opacity: 1;
}

.yc-chatbot__input:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

/* Visually hidden label */
.yc-chatbot__sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

.yc-chatbot__send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	flex-shrink: 0;
	border: none;
	border-radius: 50%;
	background: var(--yc-primary);
	color: #fff;
	cursor: pointer;
	transition: background-color 0.2s ease, transform 0.15s ease;
	position: relative;
}

.yc-chatbot__send:hover {
	background: var(--yc-primary-hover);
}

.yc-chatbot__send:active {
	transform: scale(0.93);
}

.yc-chatbot__send:focus-visible {
	outline: 3px solid #000;
	outline-offset: 3px;
}

@media (prefers-color-scheme: dark) {
	.yc-chatbot__send:focus-visible {
		outline-color: #fff;
	}
}

.yc-chatbot__send:disabled {
	opacity: 0.5;
	cursor: not-allowed;
}

/* Send button spinner */
.yc-chatbot__send-icon {
	transition: opacity 0.15s ease;
}

.yc-chatbot__send--loading .yc-chatbot__send-icon {
	opacity: 0;
}

.yc-chatbot__send-spinner {
	position: absolute;
	width: 18px;
	height: 18px;
	border: 2px solid rgba(255, 255, 255, 0.3);
	border-top-color: #fff;
	border-radius: 50%;
	animation: yc-spin 0.6s linear infinite;
	display: none;
}

.yc-chatbot__send--loading .yc-chatbot__send-spinner {
	display: block;
}

@keyframes yc-spin {
	to { transform: rotate(360deg); }
}

/* --- Powered by --- */
.yc-chatbot__powered {
	text-align: center;
	padding: 6px;
	font-size: 10px;
	color: var(--yc-text-light);
	opacity: 0.6;
	border-top: 1px solid var(--yc-border);
}

/* --- Responsive --- */
@media (max-width: 480px) {
	.yc-chatbot__window {
		width: calc(100vw - 16px);
		height: calc(100dvh - 100px);
		max-height: none;
		bottom: 80px;
		right: 8px !important;
		left: 8px !important;
		border-radius: 12px;
	}

	.yc-chatbot__launcher {
		width: 52px;
		height: 52px;
		bottom: 16px;
	}

	.yc-chatbot[data-position="right"] .yc-chatbot__launcher {
		right: 16px;
	}

	.yc-chatbot[data-position="left"] .yc-chatbot__launcher {
		left: 16px;
	}

	.yc-chatbot__message {
		max-width: 90%;
	}

	.yc-chatbot__message--user {
		margin-left: 16px;
	}

	.yc-chatbot__message--assistant {
		margin-right: 16px;
	}

	.yc-chatbot__send {
		width: 44px;
		height: 44px;
	}
}

/* Safe area insets for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
	.yc-chatbot__launcher {
		bottom: calc(24px + env(safe-area-inset-bottom));
	}

	@media (max-width: 480px) {
		.yc-chatbot__launcher {
			bottom: calc(16px + env(safe-area-inset-bottom));
		}
	}
}
