/* Private message chatbox widget */
.pm-chatbox {
	--pm-bg: #1a1a1a;
	--pm-header-bg: #e8e8e8;
	--pm-header-fg: #1a1a1a;
	--pm-header-muted: rgba(26, 26, 26, 0.65);
	--pm-border: rgba(255, 255, 255, 0.1);
	--pm-them-bubble: #2a2a2a;
	--pm-them-fg: #f5f5f5;
	--pm-me-bubble: #e8e8e8;
	--pm-me-fg: #1a1a1a;
	--pm-input-bg: #121212;
	--pm-muted: rgba(255, 255, 255, 0.45);
	--pm-online: #34d399;

	position: fixed;
	bottom: 1.25rem;
	right: 1.25rem;
	z-index: 999;
	display: flex;
	flex-direction: column;
	width: min(22rem, calc(100vw - 2.5rem));
	max-height: min(32rem, calc(100vh - 2.5rem));
	overflow: hidden;
	border: 1px solid var(--pm-border);
	border-radius: 1rem;
	background: var(--pm-bg);
	box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 0.875rem;
}

.pm-chatbox .msg_header,
.pm-chatbox .pm-chatbox-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	background: var(--pm-header-bg);
	color: var(--pm-header-fg);
	border: none;
	cursor: default;
	flex-shrink: 0;
}

.pm-chatbox-peer {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	min-width: 0;
	flex: 1;
}

.pm-chatbox-avatar-wrap {
	position: relative;
	flex-shrink: 0;
}

.pm-chatbox-avatar {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 2.25rem;
	height: 2.25rem;
	border-radius: 50%;
	background: rgba(26, 26, 26, 0.12);
	font-size: 0.8125rem;
	font-weight: 600;
	overflow: hidden;
}

.pm-chatbox-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.pm-chatbox-online-dot {
	position: absolute;
	right: -1px;
	bottom: -1px;
	width: 0.75rem;
	height: 0.75rem;
	border-radius: 50%;
	background: var(--pm-online);
	border: 2px solid var(--pm-header-bg);
}

.pm-chatbox-peer-info {
	min-width: 0;
	line-height: 1.25;
}

#msg_box_title,
.pm-chatbox-peer-info #msg_box_title {
	display: block;
	font-size: 0.875rem;
	font-weight: 600;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

#msg_box_title a,
.pm-chatbox-peer-info a {
	color: inherit;
	text-decoration: none;
}

.pm-chatbox-status {
	display: block;
	font-size: 0.75rem;
	color: var(--pm-header-muted);
}

.pm-chatbox-controls {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	flex-shrink: 0;
}

.pm-chatbox-btn {
	display: grid;
	place-items: center;
	width: 1.75rem;
	height: 1.75rem;
	padding: 0;
	border: none;
	border-radius: 0.375rem;
	background: transparent;
	color: rgba(26, 26, 26, 0.75);
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.pm-chatbox-btn:hover {
	background: rgba(26, 26, 26, 0.08);
	color: var(--pm-header-fg);
}

.pm-chatbox-btn svg {
	width: 1rem;
	height: 1rem;
}

.pm-chatbox .toggle_chat,
.pm-chatbox .pm-chatbox-body {
	display: flex;
	flex-direction: column;
	height: min(calc(32rem - 3.5rem), calc(100vh - 6rem));
	max-height: min(calc(32rem - 3.5rem), calc(100vh - 6rem));
	min-height: 0;
	overflow: hidden;
}

.pm-chatbox .message_box,
.pm-chatbox .pm-chatbox-messages {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	overflow-x: hidden;
	padding: 1rem;
	background: var(--pm-bg);
	border: none;
}

.pm-chatbox .user_info,
.pm-chatbox .pm-chatbox-compose {
	display: flex;
	align-items: flex-end;
	gap: 0.5rem;
	flex-shrink: 0;
	padding: 0.75rem;
	border-top: 1px solid var(--pm-border);
	background: #222;
	position: relative;
	z-index: 1;
}

.pm-chatbox[style*="display: block"],
.pm-chatbox[style*="display:block"] {
	display: flex !important;
	flex-direction: column;
}

.pm-chatbox .toggle_chat[style*="display: block"],
.pm-chatbox .toggle_chat[style*="display:block"],
.pm-chatbox .pm-chatbox-body[style*="display: block"],
.pm-chatbox .pm-chatbox-body[style*="display:block"] {
	display: flex !important;
	flex-direction: column;
}

.pm-chatbox .pm-chatbox-input,
.pm-chatbox .user_info textarea.chat-compose-input {
	flex: 1;
	min-width: 0;
	width: 100%;
	/* 3 lines of text + vertical padding */
	min-height: calc(3 * 1.4em + 1rem);
	max-height: 8rem;
	padding: 0.5rem 0.875rem;
	border: 1px solid var(--pm-border);
	border-radius: 1rem;
	background: var(--pm-input-bg);
	color: #f5f5f5;
	font: inherit;
	font-size: 0.875rem;
	line-height: 1.4;
	outline: none;
	resize: none;
	overflow-y: auto;
	overflow-x: hidden;
	white-space: pre-wrap;
	overflow-wrap: anywhere;
	word-break: break-word;
	box-sizing: border-box;
}

.pm-chatbox .pm-chatbox-input:focus,
.pm-chatbox .pm-chatbox-input.is-expanded,
.pm-chatbox .user_info textarea.chat-compose-input:focus,
.pm-chatbox .user_info textarea.chat-compose-input.is-expanded {
	border-color: rgba(255, 255, 255, 0.2);
	box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.pm-chatbox .pm-chatbox-input::placeholder,
.pm-chatbox .user_info textarea::placeholder {
	color: var(--pm-muted);
}

.pm-chatbox-send {
	display: grid;
	place-items: center;
	width: 2.25rem;
	height: 2.25rem;
	padding: 0;
	border: none;
	border-radius: 50%;
	background: var(--pm-header-bg);
	color: var(--pm-header-fg);
	cursor: pointer;
	flex-shrink: 0;
	align-self: flex-end;
	transition: opacity 0.15s ease;
}

.pm-chatbox-send:hover {
	opacity: 0.9;
}

.pm-chatbox-send svg {
	width: 1rem;
	height: 1rem;
}

/* Message bubbles (widget + inline thread) */
.pm-chatbox .message_box,
.pm-thread .message_box {
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.pm-chatbox .msg_item,
.pm-thread .msg_item {
	display: flex;
	align-items: flex-end;
	gap: 0.5rem;
	margin: 0;
	padding: 0;
	border: none;
	min-height: 0;
	overflow: visible;
	font-size: 0.875rem;
}

.pm-chatbox .msg_item--me,
.pm-thread .msg_item--me {
	flex-direction: row-reverse;
}

.pm-chatbox .msg_avatar,
.pm-thread .msg_avatar {
	flex-shrink: 0;
}

.pm-chatbox .msg_avatar img,
.pm-thread .msg_avatar img,
.pm-chatbox .chat_icon,
.pm-thread .chat_icon {
	width: 1.75rem;
	height: 1.75rem;
	border-radius: 50%;
	object-fit: cover;
}

.pm-chatbox .msg_bubble-wrap,
.pm-thread .msg_bubble-wrap {
	display: flex;
	flex-direction: column;
	gap: 0.25rem;
	max-width: 78%;
	min-width: 0;
}

.pm-chatbox .msg_item--me .msg_bubble-wrap,
.pm-thread .msg_item--me .msg_bubble-wrap {
	align-items: flex-end;
}

.pm-chatbox .msg_item--them .msg_bubble-wrap,
.pm-thread .msg_item--them .msg_bubble-wrap {
	align-items: flex-start;
}

.pm-chatbox .msg_bubble,
.pm-thread .msg_bubble {
	padding: 0.625rem 0.875rem;
	border-radius: 1rem;
	line-height: 1.5;
	max-width: 100%;
	overflow-x: hidden;
	overflow-wrap: anywhere;
	word-break: break-word;
	white-space: pre-wrap;
}

.pm-chatbox .msg_item--them .msg_bubble,
.pm-thread .msg_item--them .msg_bubble {
	border-bottom-left-radius: 0.25rem;
	background: var(--pm-them-bubble, #2a2a2a);
	color: var(--pm-them-fg, #f5f5f5);
	box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.pm-chatbox .msg_item--me .msg_bubble,
.pm-thread .msg_item--me .msg_bubble {
	border-bottom-right-radius: 0.25rem;
	background: var(--pm-me-bubble, #e8e8e8);
	color: var(--pm-me-fg, #1a1a1a);
}

.pm-chatbox .msg_bubble .message,
.pm-thread .msg_bubble .message {
	color: inherit !important;
	overflow-wrap: anywhere;
	word-break: break-word;
	word-wrap: break-word;
	white-space: pre-wrap;
}

.pm-chatbox .msg_time,
.pm-thread .msg_time {
	font-size: 0.6875rem;
	color: var(--pm-muted, rgba(255, 255, 255, 0.45));
	padding: 0 0.25rem;
}

.pm-chatbox .msg_date_divider,
.pm-thread .msg_date_divider {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	width: 100%;
	padding: 0.25rem 0;
}

.pm-chatbox .msg_date_divider::before,
.pm-chatbox .msg_date_divider::after,
.pm-thread .msg_date_divider::before,
.pm-thread .msg_date_divider::after {
	content: "";
	flex: 1;
	height: 1px;
	background: rgba(255, 255, 255, 0.12);
}

.pm-chatbox .msg_date_label,
.pm-thread .msg_date_label {
	padding: 0.125rem 0.625rem;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.08);
	font-size: 0.6875rem;
	font-weight: 500;
	color: var(--pm-muted, rgba(255, 255, 255, 0.45));
	white-space: nowrap;
}

.pm-chatbox .msg_left,
.pm-chatbox .msg_clear,
.pm-thread .msg_left,
.pm-thread .msg_clear {
	display: none;
}

/* Legacy shout_box without pm-chatbox (fallback) */
.shout_box:not(.pm-chatbox) {
	background: #627BAE;
	width: 260px;
	overflow: hidden;
	position: fixed;
	bottom: 0;
	right: 0;
	z-index: 9;
}

.list_item_sel:hover {
	background-color: #EAEDF3;
	color: #BABA21;
}
