// Chat Messages Container
.jbs-chat-list {
	display: flex;
	flex-direction: column;
	padding: 15px 25px;
	gap: 4px; 
	background-color: #ffffff;
	overflow-y: auto;
	height: 100%;
	@media (max-width: 480px) {
		padding: 0 4px 0 0;
	}
}

// Chat Message Row
.jbs-chat-message {
	display: flex;
	align-items: flex-end;
	width: 100%;
	margin-bottom: 2px;

	&.group-end {
		margin-bottom: 12px;
	}

	&.message-out {
		justify-content: flex-end;

		.jbs-chat-inner {
			align-items: flex-end;
		}
	}

	&.message-in {
		justify-content: flex-start;

		.jbs-chat-inner {
			align-items: flex-start;
		}
	}
}

// Date Divider
.jbs-chat-date-divider {
	display: flex;
	justify-content: center;
	margin: 16px 0;
	
	span {
		background: rgba(0, 0, 0, 0.05);
		color: #65676b;
		font-size: 11px;
		font-weight: 500;
		padding: 4px 12px;
		border-radius: 12px;
	}
}

// Message Wrap
.jbs-chat-inner {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	max-width: 70%;
	min-width: 0; 
}

.jbs-chat-bubble {
	position: relative;
	padding: 8px 12px;
	font-size: 14.5px;
	line-height: 1.4;
	word-wrap: break-word;
	word-break: break-word; 
	display: flex;
	flex-direction: column;
	min-width: 80px; 
	box-shadow: 0 1px 2px rgba(0,0,0,0.05);
	
	&.is-sender {
		background-color: var(--jbs-brand_color_1, #31795A);
		color: #ffffff;
		border-radius: 18px 18px 4px 18px;
		
		&.continues-prev {
			border-top-right-radius: 4px;
		}
		&.continues-next {
			border-bottom-right-radius: 4px;
		}
	}
	
	&.is-receiver {
		background-color: #f0f2f5;
		color: #1d1f23;
		border-radius: 18px 18px 18px 4px; 
		border: 1px solid rgba(0,0,0,0.03);
		
		&.continues-prev {
			border-top-left-radius: 4px;
		}
		&.continues-next {
			border-bottom-left-radius: 4px;
		}
	}
}

// Message Content Elements
.jbs-chat-text {
	display: block;
	color: inherit;
}

// Message Time
.jbs-chat-time {
	font-size: 10px;
	margin-top: 4px;
	align-self: flex-end;
	opacity: 0.8;
	line-height: 1;

	.is-sender & {
		color: rgba(255, 255, 255, 0.85);
	}

	.is-receiver & {
		color: #8c939d;
	}
}

// Avatar
.jbs-chat-avatar-wrap {
	width: 40px;
	height: 40px;
	margin-right: 12px;
	flex-shrink: 0;
	align-self: flex-end; 
}

.jbs-chat-avatar-img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	border-radius: 50%;
}

.jbs-chat-avatar-placeholder {
	width: 100%;
	height: 100%;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #fff;
	background-color: #cbd5e1; 
	font-size: 11px;
}

// Composer Area
.jbs-chat-footer {
	background: #ffffff;
	padding: 12px 20px;
	border-top: 1px solid #f1f2f4;
	flex-shrink: 0;

	.jbs-chat-form {
		width: 100%;
		margin: 0;
	}
	
	.jbs-chat-composer-wrap {
		width: 100%;
	}

	.jbs-chat-composer {
		display: flex;
		align-items: center;
		background-color: #f0f2f5; 
		border-radius: 20px;
		padding: 4px 6px 4px 16px;
		transition: background-color 0.2s;

		&:focus-within {
			background-color: #ffffff;
			box-shadow: 0 0 0 1px #d1d5db; // softer focus ring
		}
	}

	input[type="text"].jbs-chat-input {
		font-size: 14px;
		color: #1d1f23;
		border: none;
		outline: none;
		background: transparent;
		width: 100%;
		padding: 8px 0;
		margin: 0;
		height: 36px;
		
		&::placeholder {
			color: #8e959f;
		}
	}

	.jbs-chat-submit {
		width: 32px;
		height: 32px;
		margin-left: 8px;
		border: none;
		border-radius: 50%;
		background-color: var(--jbs-brand_color_1, #31795A);
		color: white;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-shrink: 0;
		transition: opacity 0.2s;
		
		&:hover {
			opacity: 0.9;
		}
		
		&:active {
			opacity: 0.8;
		}
		
		i {
			font-size: 13px;
			color: #ffffff;
			margin-left: -2px; // Optic bump for paper airplane to look centered
		}
	}
}

// Chat Component Structural Wrappers
.jbs-chat-history {
	display: flex;
	flex-direction: column;
	flex: 1;
	height: 100%;
	overflow: hidden;
}

.jbs-chat-header {
	display: flex;
	justify-content: space-between;
	padding: 12px 25px;
	border-bottom: 1px solid #f1f2f4;
	background: #ffffff;
	flex-shrink: 0;
}

.jbs-chat-sender-info {
	display: flex;
	align-items: center;
}

.jbs-chat-header-avatar {
	margin-right: 12px;
}

.jbs-chat-header-name {
	padding-left: 0;
}

.jbs-chat-info {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	justify-content: center;
}

.jbs-chat-read {
	margin-bottom: 4px;
	font-size: 12px;
}

.jbs-chat-actions {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	
	.reply-email {
		background: transparent;
		border: none;
		padding: 0;
		cursor: pointer;
		img {
			width: 24px;
			height: 24px;
		}
	}
}

.jbs-chat-body {
	flex: 1;
	display: flex;
	flex-direction: column;
	overflow-y: auto;
	background: #ffffff;
	max-height: 600px;
}

// Thread List Classes
.jbs-chat-thread-avatar {
	width: 45px;
	height: 45px;
	flex-shrink: 0;
	object-fit: cover;
}

.jbs-chat-thread-info {
	min-width: 0;
}

// Chat Component Initial States
.jobus-messaging__history {
	display: none;
}

.jbs-chat-empty-state {
	display: none;
	min-height: 400px;
	align-items: center;
	justify-content: center;
	
	// Map jQuery's block restoration dynamically back to flex 
	&[style*="display: block"] {
		display: flex !important;
	}
}

// Chat Header Overrides
.jbs-chat-header-avatar {
	width: 50px;
	height: 50px;
	flex-shrink: 0;
	
	img {
		width: 100%;
		height: 100%;
		display: none;
		object-fit: cover;
	}
}
