:root {
	--msg-bg:          #FFFFFF;
	--msg-bg-alt:      #EFEAD4;
	--msg-border:      #C9AD6A;
	--msg-text:        #444444;
	--msg-text-muted:  #6b5a48;
	--msg-accent:      #58180D;
	--msg-unread:      #F95954;
	--msg-danger:      #F95954;
	--msg-success:     #5a7a38;
	--msg-radius:      2px;
	--msg-gap:         0.75rem;
	/* bubble colours */
	--msg-own-bg:      #e8d2b8;
	--msg-own-border:  #d4ba9a;
	--msg-other-bg:    #f5f1e2;
	--msg-other-border:#e2dcc8;
	--msg-input-bg:    #faf8f2;
	--msg-chat-bg:     #e6dbc4;
}

/* ----------------------------------------
 * Buttons
 * ---------------------------------------- */
.msg-btn {
	display: inline-block;
	padding: 0.45em 1.2em;
	border: 1px solid var(--msg-border);
	text-decoration: none;
	cursor: pointer;
	font-family: var(--font-caps);
	font-size: 0.88rem;
	border-radius: var(--msg-radius);
	background: var(--msg-bg);
	color: var(--msg-text);
}
.msg-btn:link, .msg-btn:visited { color: var(--msg-text); text-decoration: none; }
.msg-btn:hover { background: var(--msg-bg-alt); text-decoration: none; }

.msg-btn-primary {
	background: var(--msg-accent);
	border-color: var(--msg-accent);
	color: #fff;
}
.msg-btn-primary:link, .msg-btn-primary:visited { color: #fff; text-decoration: none; }
.msg-btn-primary:hover { opacity: 0.88; background: var(--msg-accent); color: #fff; text-decoration: none; }

/* ----------------------------------------
 * Conversation list items
 * ---------------------------------------- */
.msg-conv-item {
	display: flex;
	align-items: center;
	gap: .75rem;
	padding: 0.75rem 1rem;
	text-decoration: none;
	color: var(--msg-text);
	transition: background 0.15s;
}
.msg-conv-item:link, .msg-conv-item:visited { color: var(--msg-text); text-decoration: none; }
.msg-conv-item:hover { background: var(--msg-bg-alt); text-decoration: none; }

.msg-conv-avatar {
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 50%;
	object-fit: cover;
	flex-shrink: 0;
	border: 1px solid var(--msg-border);
}
.msg-conv-avatar-placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--msg-bg-alt);
	color: var(--msg-accent);
	font-family: var(--font-heading);
	font-size: 1.1rem;
	font-weight: 800;
	border: 1px solid var(--msg-border);
}
.msg-conv-body { flex: 1; min-width: 0; }

.msg-conv-info {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	margin-bottom: 0.25rem;
}
.msg-conv-name {
	font-family: var(--font-heading);
	font-weight: 800;
	color: #58180D;
}
.msg-conv-date { font-size: 0.8rem; color: var(--msg-text-muted); }

.msg-conv-preview {
	display: flex;
	justify-content: space-between;
	align-items: center;
}
.msg-conv-preview-text {
	font-size: 0.85rem;
	color: var(--msg-text-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	flex: 1;
	margin-right: 0.5rem;
}
.msg-conv-unread {
	display: inline-block;
	background: var(--msg-unread);
	color: #fff;
	font-size: 0.72rem;
	font-weight: bold;
	padding: 0.15em 0.5em;
	border-radius: 10px;
	min-width: 1.2em;
	text-align: center;
}

.msg-empty {
	text-align: center;
	color: var(--msg-text-muted);
	padding: 2rem 0;
}

/* ----------------------------------------
 * Conversation View — wrapper
 * ---------------------------------------- */
.msg-conversation {
	display: flex;
	flex-direction: column;
	background: var(--surface);
	border-radius: var(--radius-lg);
	overflow: hidden;
	box-shadow: 0 2px 12px rgba(0,0,0,.08);
}

/* ── header bar ── */
.msg-conv-header {
	display: flex;
	align-items: center;
	gap: .75rem;
	padding: .85rem 1.25rem;
	background: var(--surface-light);
	border-bottom: 1px solid var(--border-light);
}

.msg-back {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 32px;
	height: 32px;
	border-radius: 50%;
	color: var(--text-muted);
	text-decoration: none;
	transition: background .15s;
	flex-shrink: 0;
}
.msg-back:hover { background: rgba(0,0,0,.05); color: var(--text-muted); text-decoration: none; }
.msg-back svg { width: 18px; height: 18px; }

.msg-header-user {
	display: flex;
	align-items: center;
	gap: .6rem;
	flex: 1;
	min-width: 0;
	text-decoration: none;
}
.msg-header-user:link, .msg-header-user:visited { text-decoration: none; }
.msg-header-user:hover { text-decoration: none; }

.msg-header-avatar {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: linear-gradient(135deg, var(--gold), var(--gold-dark));
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: var(--font-heading);
	font-size: .95rem;
	font-weight: 700;
	color: var(--surface-light);
	flex-shrink: 0;
}
.msg-header-avatar-img {
	width: 36px;
	height: 36px;
	border-radius: 50%;
	object-fit: cover;
	display: block;
}

.msg-header-name {
	font-family: var(--font-heading);
	font-size: 1.1rem;
	color: var(--text-heading);
	line-height: 1.2;
}

/* ── message list ── */
.msg-message-list {
	flex: 1;
	overflow-y: auto;
	padding: 1rem 1.25rem;
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-height: 280px;
	max-height: 55vh;
	background: var(--msg-chat-bg);
	background-image:
		radial-gradient(ellipse at 30% 20%, rgba(201,168,76,.06) 0%, transparent 50%),
		radial-gradient(ellipse at 70% 80%, rgba(201,168,76,.04) 0%, transparent 50%);

	/* scrollbar */
	scrollbar-width: thin;
	scrollbar-color: var(--border) transparent;
}
.msg-message-list::-webkit-scrollbar { width: 6px; }
.msg-message-list::-webkit-scrollbar-track { background: transparent; }
.msg-message-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.msg-message-list::-webkit-scrollbar-thumb:hover { background: var(--gold); }

/* ── date separator ── */
.msg-date-sep {
	display: flex;
	align-items: center;
	justify-content: center;
	margin: .75rem 0;
}
.msg-date-sep span {
	font-family: var(--font-caps);
	font-size: .7rem;
	letter-spacing: .06em;
	color: var(--text-faint);
	background: rgba(211,187,149,.7);
	padding: .2rem .75rem;
	border-radius: 10px;
}

/* ── message bubbles ── */
.msg-message {
	max-width: 72%;
	padding: .5rem .8rem .35rem;
	border-radius: 12px;
	word-wrap: break-word;
	position: relative;
	animation: msgAppear .2s ease;
}
@keyframes msgAppear {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: translateY(0); }
}

.msg-own {
	align-self: flex-end;
	background: var(--msg-own-bg);
	border: 1px solid var(--msg-own-border);
	border-bottom-right-radius: 4px;
}
.msg-other {
	align-self: flex-start;
	background: var(--msg-other-bg);
	border: 1px solid var(--msg-other-border);
	border-bottom-left-radius: 4px;
}

.msg-own + .msg-own,
.msg-other + .msg-other { margin-top: 0; }
.msg-own + .msg-other,
.msg-other + .msg-own,
.msg-date-sep + .msg-own,
.msg-date-sep + .msg-other { margin-top: .5rem; }

.msg-message-body {
	font-size: .92rem;
	line-height: 1.55;
	color: var(--text);
}
.msg-message-body p { margin: 0; }
.msg-message-body p + p { margin-top: .3em; }

/* meta line: delete + time */
.msg-message-meta {
	display: flex;
	align-items: center;
	justify-content: flex-end;
	gap: .5rem;
	margin-top: .2rem;
}
.msg-time {
	font-size: .68rem;
	color: var(--text-faint);
	white-space: nowrap;
}
.msg-delete-link {
	font-size: .8rem;
	color: var(--text-faint);
	text-decoration: none;
	opacity: 0;
	transition: opacity .15s, color .15s;
	padding: 0 2px;
}
.msg-delete-link:link, .msg-delete-link:visited { text-decoration: none; }
.msg-message:hover .msg-delete-link { opacity: 1; }
.msg-delete-link:hover { color: #c62828; text-decoration: none; }

/* ── status bar ── */
.msg-status {
	display: none;
	padding: .4rem .8rem;
	font-size: .78rem;
	text-align: center;
	margin: 0;
}
.msg-status-error { background: #fde8e8; color: var(--msg-danger); }
.msg-status-info  { background: #E0E5C1; color: var(--msg-accent); }

/* ── input area ── */
.msg-send-form {
	display: flex;
	align-items: flex-start;
	gap: .6rem;
	padding: .75rem 1rem;
	background: var(--surface-light);
	border-top: 1px solid var(--border-light);
}

.msg-input-wrap { flex: 1; position: relative; }

.msg-send-form textarea {
	width: 100%;
	resize: none;
	overflow-y: hidden;
	min-height: 42px;
	max-height: calc(1.45 * .92rem * 5 + 1.2rem + 2px);
	padding: .6rem .9rem;
	border: 1px solid var(--border-light);
	border-radius: 20px;
	font-family: var(--font-body);
	font-size: .92rem;
	line-height: 1.45;
	color: var(--text);
	background: var(--msg-input-bg);
	outline: none;
	transition: border-color .15s, box-shadow .15s;
	scrollbar-width: thin;
	scrollbar-color: var(--border) transparent;
}
.msg-send-form textarea.has-scroll { overflow-y: auto; }
.msg-send-form textarea::-webkit-scrollbar { width: 5px; }
.msg-send-form textarea::-webkit-scrollbar-track { background: transparent; margin: 10px 0; }
.msg-send-form textarea::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
.msg-send-form textarea::-webkit-scrollbar-thumb:hover { background: var(--gold); }
.msg-send-form textarea::placeholder { color: var(--text-faint); font-style: italic; }
.msg-send-form textarea:focus {
	border-color: var(--gold);
	box-shadow: 0 0 0 3px rgba(201,168,76,.15);
}
.msg-send-form textarea:disabled { opacity: .5; cursor: not-allowed; }

.msg-send-btn {
	width: 40px;
	height: 40px;
	margin-top: 1px;
	border-radius: 50%;
	border: none;
	background: var(--accent);
	color: var(--surface-light);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	transition: background .15s, transform .1s;
	box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.msg-send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.msg-send-btn:active { transform: scale(.95); }
.msg-send-btn svg { width: 18px; height: 18px; }
.msg-send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

/* ----------------------------------------
 * New Message Form
 * ---------------------------------------- */
.msg-form { max-width: 600px; }
.msg-form-actions {
	margin-top: 1rem;
	display: flex;
	gap: 1rem;
	align-items: center;
}
.msg-form-actions a { color: var(--msg-text-muted); text-decoration: none; font-size: 0.9rem; }
.msg-form-actions a:link, .msg-form-actions a:visited { color: var(--msg-text-muted); text-decoration: none; }
.msg-form-actions a:hover { color: var(--msg-accent); text-decoration: none; }

.msg-recipient-display {
	padding: 0.5rem;
	background: var(--msg-bg-alt);
	border: 1px solid var(--msg-border);
	border-radius: var(--msg-radius);
	margin-bottom: 0.5rem;
}

/* ----------------------------------------
 * Unread Badge (site template nav)
 * ---------------------------------------- */
.msg-unread-badge {
	display: inline-block;
	background: var(--msg-unread);
	color: #fff;
	font-size: 0.68rem;
	font-weight: bold;
	padding: 0.1em 0.45em;
	border-radius: 8px;
	min-width: 1em;
	text-align: center;
	vertical-align: super;
	margin-left: 0.2em;
}

/* ----------------------------------------
 * Responsive
 * ---------------------------------------- */
@media (max-width: 600px) {
	.msg-message { max-width: 88%; }
	.msg-send-form { padding: .6rem .75rem; }
	.msg-message-list { padding: .75rem; }
	.msg-conv-header { padding: .65rem .85rem; }
}
