#shopuni-chat-panel {
	position: fixed;
	bottom: 0;
	right: 20px;
	width: 320px;
	max-height: 480px;
	background: #fff;
	border: 1px solid #ddd;
	border-bottom: none;
	border-radius: 8px 8px 0 0;
	box-shadow: 0 4px 20px rgba(0,0,0,0.15);
	display: none;
	flex-direction: column;
	z-index: 9999;
}
#shopuni-chat-panel.is-open { display: flex; }

#shopuni-chat-messages {
	flex: 1;
	overflow-y: auto;
	padding: 12px;
	max-height: 320px;
}

/* =========================================================
   Message bubbles, avatars, header, read receipts, attachments
   — styled after the reference chat UI (rounded bubbles, avatar
   beside each message, timestamp + read receipt below "mine" bubbles).
   ========================================================= */

.shopuni-chat-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	border-bottom: 1px solid #eee;
	background: #fff;
}
.shopuni-chat-header-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
}
.shopuni-chat-header-name {
	font-weight: 600;
	font-size: 15px;
	color: #1a1a1a;
}

.shopuni-msg-row {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	margin-bottom: 16px;
}
.shopuni-msg-row.is-theirs { justify-content: flex-start; }
.shopuni-msg-row.is-mine { justify-content: flex-end; }

.shopuni-msg-avatar {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
}

.shopuni-msg-col {
	display: flex;
	flex-direction: column;
	max-width: 72%;
}
.shopuni-msg-row.is-mine .shopuni-msg-col { align-items: flex-end; }
.shopuni-msg-row.is-theirs .shopuni-msg-col { align-items: flex-start; }

.shopuni-chat-bubble {
	max-width: 100%;
	padding: 10px 14px;
	border-radius: 16px;
	font-size: 14px;
	line-height: 1.45;
	word-wrap: break-word;
	overflow-wrap: break-word;
	word-break: break-word;
}
.shopuni-msg-row.is-mine .shopuni-chat-bubble {
	background: #3294DF;
	color: #fff;
	border-bottom-right-radius: 4px;
}
.shopuni-msg-row.is-theirs .shopuni-chat-bubble {
	background: #f1f1f3;
	color: #222;
	border-bottom-left-radius: 4px;
}

.shopuni-msg-meta {
	display: flex;
	align-items: center;
	gap: 4px;
	font-size: 11px;
	color: #999;
	margin-top: 4px;
	padding: 0 4px;
}
.shopuni-read-receipt {
	display: inline-flex;
	color: #b0b0b0; /* sent, not yet read */
}
.shopuni-read-receipt.is-read {
	color: #34b7f1; /* read — matches the reference UI's blue double-check convention */
}

/* ---- Attachments (images + PDF/file bubbles) ---- */
.shopuni-chat-bubble.has-attachment {
	padding: 6px;
	background: transparent !important;
}
.shopuni-attachment-image {
	max-width: 220px;
	max-height: 220px;
	border-radius: 12px;
	display: block;
	object-fit: cover;
}
.shopuni-attachment-file {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 14px;
	border-radius: 12px;
	background: #fff;
	border: 1px solid #e2e2e2;
	color: #222;
	text-decoration: none;
	max-width: 220px;
}
.shopuni-msg-row.is-mine .shopuni-attachment-file {
	background: #e8f3fd;
	border-color: #bfe0f9;
}
.shopuni-attachment-file span {
	font-size: 13px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.shopuni-attachment-caption {
	margin-top: 6px;
	padding: 8px 12px;
	border-radius: 12px;
	background: #3294DF;
	color: #fff;
	font-size: 14px;
}
.shopuni-msg-row.is-theirs .shopuni-attachment-caption {
	background: #f1f1f3;
	color: #222;
}

/* ---- Input row: attach icon, text field, circular send button ---- */
#shopuni-chat-input-row,
#shopuni-chat-modal-input-row {
	display: flex;
	align-items: center;
	gap: 8px;
	border-top: 1px solid #eee;
	padding: 10px 12px;
	background: #fff;
}
.shopuni-attach-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border: none;
	background: transparent !important;
	color: #888 !important;
	cursor: pointer;
	border-radius: 50%;
	flex-shrink: 0;
}
.shopuni-attach-btn:hover { background: #f1f1f3; color: #3294DF; }
.shopuni-attach-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Text-character icons (📎 and ➤) instead of inline SVG — after repeated
   fights with theme CSS silently hiding/overriding SVG fill and visibility
   on some pages, plain styled text is far harder to accidentally hide:
   there's no fill/stroke/viewBox for anything else to override, just a
   font-size and a color. */
.shopuni-icon-text {
	display: inline-block !important;
	font-size: 17px !important;
	line-height: 1 !important;
	font-style: normal !important;
}
.shopuni-attach-btn .shopuni-icon-text { color: #888 !important; }
.shopuni-send-btn .shopuni-icon-text { color: #fff !important; font-size: 15px !important; }

#shopuni-chat-input,
#shopuni-chat-modal-input {
	flex: 1;
	min-width: 0;
	border: 1px solid #e2e2e2;
	border-radius: 20px;
	padding: 9px 16px;
	font-size: 14px;
}
#shopuni-chat-input:focus,
#shopuni-chat-modal-input:focus {
	outline: none;
	border-color: #3294DF;
}

.shopuni-send-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	border: none;
	background: #3294DF !important;
	color: #fff !important;
	cursor: pointer;
	flex-shrink: 0;
	transition: background 0.15s ease;
}
.shopuni-send-btn:hover { background: #217bc4; }

.shopuni-attach-error {
	display: none;
	color: #d9534f;
	font-size: 12px;
	padding: 0 16px 8px;
}
.shopuni-attach-error:not(:empty) { display: block; }

#shopuni-chat-messages,
#shopuni-chat-modal-messages {
	background: #fafafa;
}

.shopuni-chat-unread-badge {
	display: none;
	background: #e74c3c;
	color: #fff;
	border-radius: 50%;
	font-size: 11px;
	padding: 1px 6px;
	margin-left: 6px;
}

.shopuni-chat-inbox {
	display: flex;
	gap: 20px;
	max-width: 100%;
	box-sizing: border-box;
}
.shopuni-chat-window,
.shopuni-thread-list {
	min-width: 0; /* critical: allows flex children to shrink instead of forcing page-wide overflow */
	box-sizing: border-box;
}
.dokan-dashboard-content.shopuni-chat-dashboard,
.shopuni-chat-myaccount {
	max-width: 900px;
	margin-left: auto;
	margin-right: auto;
	overflow-x: hidden;
	box-sizing: border-box;
}
#shopuni-chat-messages {
	min-width: 0;
	box-sizing: border-box;
}

.shopuni-thread-list-item {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	border-bottom: 1px solid #eee;
	cursor: pointer;
}
.shopuni-thread-avatar {
	width: 40px;
	height: 40px;
	min-width: 40px;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
	background: #eee; /* visible placeholder color while the image loads */
}
.shopuni-thread-name {
	font-weight: 500;
	color: #222;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.shopuni-thread-list-item:hover { background: #f7f7f7; }
.shopuni-thread-list-item.is-active { background: #eaf4fd; border-left: 3px solid #3294DF; }

/* ---- Modal (triggered by any "Message Vendor" button) ---- */
#shopuni-chat-modal-overlay {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,0.5);
	z-index: 100000;
	align-items: center;
	justify-content: center;
}
#shopuni-chat-modal-overlay.is-open { display: flex; }

#shopuni-chat-modal {
	background: #fff;
	width: 100%;
	max-width: 420px;
	height: 70vh;
	max-height: 560px;
	border-radius: 10px;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}

#shopuni-chat-modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 14px 16px;
	border-bottom: 1px solid #eee;
	font-weight: 600;
}
#shopuni-chat-modal-close {
	background: none;
	border: none;
	font-size: 22px;
	line-height: 1;
	cursor: pointer;
	color: #888;
}
#shopuni-chat-modal #shopuni-chat-modal-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
	max-height: none;
}
#shopuni-chat-modal-input-row {
	display: flex;
	border-top: 1px solid #eee;
	padding: 8px;
}
#shopuni-chat-modal-input {
	flex: 1;
	border: 1px solid #ddd;
	border-radius: 16px;
	padding: 6px 12px;
	font-size: 14px;
}
#shopuni-chat-modal-send {
	margin-left: 8px;
}

/* ---- Full "browse vendors + messages" page ([shopuni_messages_page]) ---- */
.shopuni-messages-page {
	display: flex;
	gap: 20px;
	min-height: 500px;
}
.shopuni-messages-page__sidebar {
	width: 300px;
	border: 1px solid #eee;
	border-radius: 8px;
	display: flex;
	flex-direction: column;
}
.shopuni-messages-page__chat {
	flex: 1;
	display: flex;
	flex-direction: column;
	border: 1px solid #eee;
	border-radius: 8px;
	overflow: hidden;
}
.shopuni-chat-messages--fullpage {
	flex: 1;
	overflow-y: auto;
	padding: 16px;
}

.shopuni-tabs {
	display: flex;
	border-bottom: 1px solid #eee;
}
.shopuni-tab {
	flex: 1;
	padding: 12px;
	background: none;
	border: none;
	cursor: pointer;
	font-weight: 600;
	color: #888;
}
.shopuni-tab.is-active {
	color: #3294DF;
	border-bottom: 2px solid #3294DF;
}

.shopuni-tab-panel { display: none; padding: 10px; overflow-y: auto; }
.shopuni-tab-panel.is-active { display: block; }

#shopuni-vendor-search {
	width: 100%;
	padding: 8px 10px;
	border: 1px solid #ddd;
	border-radius: 6px;
	margin-bottom: 10px;
}

.shopuni-vendor-card {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 6px;
	border-bottom: 1px solid #f2f2f2;
}
.shopuni-vendor-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
}
.shopuni-vendor-card span {
	flex: 1;
	font-weight: 500;
}

/* ---- Admin bar unread badge ---- */
#wpadminbar .shopuni-chat-admin-bar-badge {
	background: #e74c3c;
	color: #fff;
	border-radius: 10px;
	font-size: 11px;
	padding: 1px 6px;
	margin-left: 6px;
}

/* =========================================================
   RESPONSIVE BEHAVIOR
   Desktop (default, above): fixed 70px left margin + 70% max-width,
   side-by-side thread list + chat window, as requested.
   Below, we progressively relax both as screen space shrinks, so the
   layout never gets pushed off-screen or squeezed unreadable.
   ========================================================= */

/* ---- Tablet (~1024px and below): margin shrinks, width grows,
   columns stay side-by-side but narrower ---- */
@media (max-width: 1024px) {
	.dokan-dashboard-content.shopuni-chat-dashboard,
	.shopuni-chat-myaccount {
		max-width: 100%;
	}
	.shopuni-thread-list {
		width: 200px; /* narrower sidebar list, still visible alongside chat */
	}
}

/* ---- Small tablet / large phone (~768px and below): drop the fixed
   margin entirely, let content use full available width, still
   side-by-side if there's room ---- */
@media (max-width: 768px) {
	.dokan-dashboard-content.shopuni-chat-dashboard,
	.shopuni-chat-myaccount {
		max-width: 100%;
		padding-left: 12px;
		padding-right: 12px;
	}
	.shopuni-thread-list {
		width: 160px;
	}
	.shopuni-chat-inbox {
		gap: 12px;
	}
}

/* ---- Mobile (~600px and below): stack thread list ABOVE the chat
   window instead of side-by-side — a fixed-width sidebar next to a
   chat pane simply doesn't fit a phone screen readably ---- */
@media (max-width: 600px) {
	.shopuni-chat-inbox {
		flex-direction: column;
	}
	.shopuni-thread-list {
		width: 100%;
		max-height: 160px; /* scrollable strip of conversations instead of eating the whole screen */
		overflow-y: auto;
	}
	.shopuni-chat-window {
		width: 100%;
	}
	#shopuni-chat-messages {
		height: 300px; /* shorter on small screens so the input row stays reachable without excess scrolling */
	}
	.shopuni-chat-bubble {
		max-width: 85%; /* a bit wider than desktop's 75% since phone screens are already narrow */
	}
}

/* ---- Modal responsiveness: full-width sheet on phones instead of a
   fixed 420px box that would overflow a small viewport ---- */
@media (max-width: 480px) {
	#shopuni-chat-modal {
		max-width: 100%;
		width: 100%;
		height: 100%;
		max-height: 100%;
		border-radius: 0;
	}
	#shopuni-chat-modal-overlay {
		padding: 0;
	}
}

/* ---- Messages page ([shopuni_messages_page]) on mobile: same
   stacking logic as the dashboard, sidebar tabs above the chat ---- */
@media (max-width: 768px) {
	.shopuni-messages-page {
		flex-direction: column;
		min-height: 0;
	}
	.shopuni-messages-page__sidebar {
		width: 100%;
	}
	.shopuni-messages-page__chat {
		min-height: 400px;
	}
}

/* Vendor dashboard sidebar "Messages" icon — inline SVG (not an icon-font
   class) so it renders correctly regardless of whether Font Awesome or
   similar is loaded on the front end. */
.dokan-dashboard-nav .shopuni-chat-nav-icon,
[href*="dashboard/messages"] svg {
	vertical-align: middle;
	margin-right: 4px;
}

/* ---- Vendor dashboard "Messages" nav icon override ----
   Newer Dokan versions assign sidebar icons via an internal lookup keyed
   to recognized menu slugs, not the raw 'icon' HTML passed through the
   dokan_get_dashboard_nav filter — so a custom slug like ours silently
   falls back to Dokan's Settings (gear) icon regardless of what we send.
   There's no supported hook to register a new icon on this version, so
   this hides that mismatched icon specifically on our nav link and draws
   a chat-bubble icon in its place with CSS alone. */
a[href*="/dashboard/messages"] svg {
	display: none !important;
}
a[href*="/dashboard/messages"]::before {
	content: "";
	display: inline-block;
	width: 20px;
	height: 20px;
	min-width: 20px;
	margin-right: 8px;
	vertical-align: middle;
	background-repeat: no-repeat;
	background-position: center;
	background-size: contain;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z'/%3E%3C/svg%3E");
}

/* ---- WoodMart mobile footer nav "Messages" icon — unread badge ----
   WoodMart's custom-icon toolbar items don't offer a way to assign a
   custom CSS class in the theme UI, so this targets the link by its
   unique href instead (set once, via wc_get_account_endpoint_url() /
   the actual Messages page — see the JS for how the class is toggled). */
a[href="https://shopuni.ng/messages/"] .wd-toolbar-icon {
	position: relative;
	display: inline-block;
}
a[href="https://shopuni.ng/messages/"] .wd-toolbar-icon::after {
	content: attr(data-shopuni-unread);
	position: absolute;
	top: -4px;
	right: -4px;
	min-width: 16px;
	height: 16px;
	padding: 0 4px;
	background: #e74c3c;
	color: #fff;
	font-size: 10px;
	font-weight: 700;
	line-height: 16px;
	text-align: center;
	border-radius: 999px;
	display: none;
	z-index: 1;
}
a[href="https://shopuni.ng/messages/"] .wd-toolbar-icon.shopuni-has-unread::after {
	display: block;
}
