/**
 * CSOT Chat Widget — Front-end Stylesheet
 *
 * Uses CSS custom properties injected inline by PHP for dynamic
 * theming: --csot-widget-primary, --csot-widget-secondary,
 * --csot-widget-text, --csot-widget-width.
 *
 * BEM naming: csot-widget (block), __ (element), -- (modifier).
 *
 * @package CompanySourceOfTruth
 * @since   1.11.0
 */

/* ---------------------------------------------------------------
 * 1. Variables / Reset
 * ------------------------------------------------------------- */

:root {
	--csot-widget-primary: #0073aa;
	--csot-widget-secondary: #f0f0f1;
	--csot-widget-text: #ffffff;
	--csot-widget-width: 380px;
	--csot-widget-radius: 12px;
	--csot-widget-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
	--csot-widget-font:
		-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
		Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* ---------------------------------------------------------------
 * 2. Floating Container
 * ------------------------------------------------------------- */

#csot-chat-widget {
	position: fixed;
	z-index: 999999;
	bottom: 24px;
	font-family: var(--csot-widget-font);
	font-size: 14px;
	line-height: 1.5;
}

#csot-chat-widget.csot-widget--right {
	right: 24px;
}

#csot-chat-widget.csot-widget--left {
	left: 24px;
}

/* ---------------------------------------------------------------
 * 3. Bubble Trigger
 * ------------------------------------------------------------- */

.csot-widget__bubble {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 12px 18px;
	background: var(--csot-widget-primary);
	color: var(--csot-widget-text);
	border: none;
	border-radius: 50px;
	cursor: pointer;
	box-shadow: var(--csot-widget-shadow);
	font-size: 14px;
	font-family: inherit;
	transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.csot-widget__bubble:hover {
	transform: scale(1.05);
	box-shadow: 0 6px 28px rgba(0, 0, 0, 0.2);
}

.csot-widget__bubble:focus-visible {
	outline: 2px solid var(--csot-widget-primary);
	outline-offset: 2px;
}

.csot-widget__bubble-icon {
	font-size: 22px !important;
	width: 22px !important;
	height: 22px !important;
	line-height: 1 !important;
}

.csot-widget__bubble-close {
	font-size: 22px !important;
	width: 22px !important;
	height: 22px !important;
	line-height: 1 !important;
}

.csot-widget__bubble-label {
	font-weight: 500;
	white-space: nowrap;
}

/* ---------------------------------------------------------------
 * 4. Chat Panel
 * ------------------------------------------------------------- */

.csot-widget__panel {
	position: absolute;
	bottom: 72px;
	width: var(--csot-widget-width);
	max-height: 520px;
	display: flex;
	flex-direction: column;
	background: #fff;
	border-radius: var(--csot-widget-radius);
	box-shadow: var(--csot-widget-shadow);
	overflow: hidden;
}

.csot-widget--right .csot-widget__panel {
	right: 0;
}

.csot-widget--left .csot-widget__panel {
	left: 0;
}

/* ---------------------------------------------------------------
 * 5. Header
 * ------------------------------------------------------------- */

.csot-widget__header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	background: var(--csot-widget-primary);
	color: var(--csot-widget-text);
	font-weight: 600;
	flex-shrink: 0;
}

.csot-widget__avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
}

.csot-widget__agent-name {
	flex: 1;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.csot-widget__close {
	display: flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	color: var(--csot-widget-text);
	cursor: pointer;
	opacity: 0.8;
	padding: 0;
	font-size: 20px;
}

.csot-widget__close:hover {
	opacity: 1;
}

.csot-widget__new-chat {
	display: flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	color: var(--csot-widget-text);
	cursor: pointer;
	opacity: 0.7;
	padding: 0;
	font-size: 16px;
	transition: opacity 0.15s ease;
}

.csot-widget__new-chat:hover {
	opacity: 1;
}

/* ---------------------------------------------------------------
 * 6. Messages Area
 * ------------------------------------------------------------- */

.csot-widget__messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	display: flex;
	flex-direction: column;
	gap: 10px;
	min-height: 200px;
	max-height: 340px;
}

/* ---- Message Row ---- */

.csot-widget__msg {
	display: flex;
	flex-direction: column;
	max-width: 85%;
	animation: csotFadeIn 0.2s ease;
}

.csot-widget__msg--user {
	align-self: flex-end;
}

.csot-widget__msg--assistant,
.csot-widget__msg--system {
	align-self: flex-start;
}

/* ---- Bubble ---- */

.csot-widget__msg-bubble {
	padding: 10px 14px;
	border-radius: 16px;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.csot-widget__msg--user .csot-widget__msg-bubble {
	background: var(--csot-widget-primary);
	color: var(--csot-widget-text);
	border-bottom-right-radius: 4px;
}

.csot-widget__msg--assistant .csot-widget__msg-bubble {
	background: var(--csot-widget-secondary);
	color: #1e1e1e;
	border-bottom-left-radius: 4px;
}

.csot-widget__msg--system .csot-widget__msg-bubble {
	background: #fff3cd;
	color: #856404;
	font-size: 13px;
	border-radius: 8px;
}

/* ---- Label ---- */

.csot-widget__msg-label {
	font-size: 11px;
	font-weight: 600;
	color: #666;
	margin-bottom: 2px;
	padding-left: 4px;
}

/* ---- Fade-in animation ---- */

@keyframes csotFadeIn {
	from {
		opacity: 0;
		transform: translateY(4px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ---------------------------------------------------------------
 * 7. Typing Indicator
 * ------------------------------------------------------------- */

.csot-widget__typing {
	display: flex;
	gap: 4px;
	align-items: center;
	padding: 10px 14px;
	background: var(--csot-widget-secondary);
	border-radius: 16px;
	border-bottom-left-radius: 4px;
	align-self: flex-start;
	max-width: 70px;
}

.csot-widget__typing span {
	display: block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: #999;
	animation: csotTypingDot 1.2s infinite ease-in-out;
}

.csot-widget__typing span:nth-child(2) {
	animation-delay: 0.15s;
}

.csot-widget__typing span:nth-child(3) {
	animation-delay: 0.3s;
}

@keyframes csotTypingDot {
	0%, 60%, 100% {
		opacity: 0.3;
		transform: scale(0.8);
	}
	30% {
		opacity: 1;
		transform: scale(1);
	}
}

/* ---------------------------------------------------------------
 * 8. Input Area
 * ------------------------------------------------------------- */

.csot-widget__input-area {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	padding: 10px 12px;
	border-top: 1px solid #e0e0e0;
	background: #fff;
	flex-shrink: 0;
}

.csot-widget__input {
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 8px;
	padding: 8px 12px;
	font-size: 14px;
	font-family: inherit;
	line-height: 1.4;
	resize: none;
	outline: none;
	max-height: calc(1.4em * 4 + 16px);
	overflow-y: auto;
}

.csot-widget__input:focus {
	border-color: var(--csot-widget-primary);
	box-shadow: 0 0 0 1px var(--csot-widget-primary);
}

.csot-widget__send {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	flex-shrink: 0;
	background: var(--csot-widget-primary);
	color: var(--csot-widget-text);
	border: none;
	border-radius: 50%;
	cursor: pointer;
	transition: opacity 0.15s;
}

.csot-widget__send:hover {
	opacity: 0.85;
}

.csot-widget__send .dashicons {
	font-size: 18px;
	width: 18px;
	height: 18px;
	line-height: 1;
}

/* ---------------------------------------------------------------
 * 9. Footer
 * ------------------------------------------------------------- */

.csot-widget__footer {
	text-align: center;
	padding: 6px 12px;
	font-size: 11px;
	color: #999;
	background: #fafafa;
	border-top: 1px solid #f0f0f0;
	flex-shrink: 0;
}

.csot-widget__footer strong {
	color: #666;
}

/* ---------------------------------------------------------------
 * 10. Embedded Mode
 * ------------------------------------------------------------- */

.csot-widget--embedded {
	position: relative;
	display: flex;
	flex-direction: column;
	width: 100%;
	border: 1px solid #ddd;
	border-radius: var(--csot-widget-radius);
	overflow: hidden;
	font-family: var(--csot-widget-font);
	font-size: 14px;
	line-height: 1.5;
	background: #fff;
}

.csot-widget--embedded .csot-widget__messages {
	max-height: none;
	flex: 1;
}

/* ---------------------------------------------------------------
 * 11. Responsive
 * ------------------------------------------------------------- */

@media screen and (max-width: 480px) {

	#csot-chat-widget {
		bottom: 12px;
		right: 12px !important;
		left: 12px !important;
	}

	.csot-widget__panel {
		width: calc(100vw - 24px) !important;
		max-height: 70vh;
		bottom: 64px;
		right: 0 !important;
		left: 0 !important;
	}

	.csot-widget__bubble-label {
		display: none;
	}
}

/* ---------------------------------------------------------------
 * 12. Front-end Dashicons
 *     Ensure dashicons font is available on the front end.
 * ------------------------------------------------------------- */

.csot-widget .dashicons,
.csot-widget .dashicons-before::before {
	font-family: dashicons;
	font-style: normal;
	font-weight: 400;
	line-height: 1;
}
