/* ─── DM Inbox (/messages/) ───────────────────────────────────────────────── */
/* Instagram.com-inspired messaging UI — fully tokenised for light/dark mode  */

.igcr-messages-wrap {
	max-width: 935px;
	margin: 0 auto;
	padding: 24px 16px 60px;
	min-height: 60vh;
	position: relative;
}

/* ── Header ── */
.igcr-dm-header {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px 12px;
	margin-bottom: 16px;
}

.igcr-dm-title {
	font-size: 1.4em;
	font-weight: 700;
	margin: 0;
	color: var(--igcr-text);
}

.igcr-dm-header-actions {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-left: auto;
}

.igcr-dm-account-picker {
	font-size: 0.85em;
	padding: 6px 10px;
	border: 1px solid var(--igcr-border);
	border-radius: var(--igcr-radius-sm);
	background: var(--igcr-bg);
	color: var(--igcr-text);
}

.igcr-dm-sync-btn {
	display: inline-flex;
	align-items: center;
	gap: 5px;
	padding: 6px 12px;
	font-size: 0.8em;
	font-weight: 600;
	color: var(--igcr-text-secondary);
	background: var(--igcr-bg-subtle);
	border: 1px solid var(--igcr-border);
	border-radius: var(--igcr-radius-sm);
	cursor: pointer;
	transition: background 0.2s, color 0.2s;
}

.igcr-dm-sync-btn:hover {
	background: var(--igcr-bg-muted);
	color: var(--igcr-text);
}

.igcr-dm-sync-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.igcr-dm-sync-btn.is-syncing .igcr-icon {
	animation: igcr-spin 1s linear infinite;
}

@keyframes igcr-spin {
	from { transform: rotate(0deg); }
	to   { transform: rotate(360deg); }
}

/* ── Auth notice (non-admin) ── */
.igcr-dm-auth-notice {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 16px;
	padding: 48px 24px;
	text-align: center;
	color: var(--igcr-text-secondary);
	background: var(--igcr-bg-subtle);
	border: 1px solid var(--igcr-border-light);
	border-radius: var(--igcr-radius-lg);
	margin: 24px 0;
}

.igcr-dm-auth-notice svg {
	color: var(--igcr-text-muted);
}

.igcr-dm-auth-notice p {
	margin: 0;
	font-size: 1em;
	max-width: 320px;
}

/* ── Loading state ── */
.igcr-dm-loading {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 40px 20px;
	color: var(--igcr-text-muted);
	font-size: 0.9em;
}

/* ── Thread list ── */
.igcr-dm-threads-panel[hidden] {
	display: none;
}

.igcr-dm-threads {
	display: flex;
	flex-direction: column;
}

.igcr-dm-thread {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 14px 16px;
	border-bottom: 1px solid var(--igcr-border-light);
	border-left: 3px solid transparent;
	cursor: pointer;
	transition: background 0.12s, border-color 0.12s;
	text-decoration: none;
	color: inherit;
}

.igcr-dm-thread:hover {
	background: var(--igcr-bg-subtle);
}

.igcr-dm-thread--active {
	background: var(--igcr-accent-light);
	border-left-color: var(--igcr-accent);
}

.igcr-dm-thread-avatar {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	background: var(--igcr-bg-muted);
	color: var(--igcr-text-secondary);
	font-weight: 700;
	font-size: 16px;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	text-transform: uppercase;
}

.igcr-dm-thread-info {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 3px;
}

.igcr-dm-thread-name {
	font-weight: 600;
	font-size: 0.9em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	color: var(--igcr-text);
}

.igcr-dm-thread-preview {
	font-size: 0.82em;
	color: var(--igcr-text-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	margin: 0;
}

.igcr-dm-thread-preview--outbound::before {
	content: "You: ";
	color: var(--igcr-text-muted);
}

.igcr-dm-thread-meta {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 4px;
	flex-shrink: 0;
}

.igcr-dm-thread-time {
	font-size: 0.72em;
	color: var(--igcr-text-muted);
	white-space: nowrap;
}

.igcr-dm-thread-count {
	font-size: 0.7em;
	color: var(--igcr-text-muted);
	background: var(--igcr-bg-muted);
	padding: 1px 6px;
	border-radius: var(--igcr-radius-full);
}

.igcr-dm-empty {
	text-align: center;
	padding: 60px 20px;
	color: var(--igcr-text-muted);
	font-size: 0.9em;
}

/* ── Conversation panel ── */
.igcr-dm-conversation-panel {
	display: flex;
	flex-direction: column;
	height: 70vh;
	min-height: 400px;
	background: var(--igcr-bg);
}

.igcr-dm-conversation-panel[hidden] {
	display: none;
}

.igcr-dm-conv-header {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 12px 0;
	border-bottom: 1px solid var(--igcr-border);
	margin-bottom: 0;
}

.igcr-dm-back {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: none;
	border: none;
	cursor: pointer;
	color: var(--igcr-text-secondary);
	padding: 4px;
	border-radius: var(--igcr-radius-sm);
	transition: background 0.12s;
}

.igcr-dm-back:hover {
	background: var(--igcr-bg-muted);
	color: var(--igcr-text);
}

.igcr-dm-conv-identity {
	display: flex;
	align-items: center;
	gap: 8px;
}

.igcr-dm-conv-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	background: var(--igcr-bg-muted);
	color: var(--igcr-text-secondary);
	font-weight: 700;
	font-size: 13px;
	display: flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	text-transform: uppercase;
}

.igcr-dm-conv-name {
	font-size: 0.95em;
	font-weight: 600;
	color: var(--igcr-text);
}

/* ── Messages area ── */
.igcr-dm-messages {
	flex: 1;
	overflow-y: auto;
	padding: 16px 0;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.igcr-dm-msg {
	display: flex;
	flex-direction: column;
	align-items: flex-start;
	max-width: 75%;
}

.igcr-dm-msg--outbound {
	align-self: flex-end;
	align-items: flex-end;
}

.igcr-dm-msg-bubble {
	padding: 8px 14px;
	border-radius: 18px 18px 18px 4px;
	background: var(--igcr-bg-muted);
	color: var(--igcr-text);
	font-size: 0.9em;
	line-height: 1.45;
	word-break: break-word;
}

.igcr-dm-msg--outbound .igcr-dm-msg-bubble {
	background: var(--igcr-accent);
	color: #fff;
	border-radius: 18px 18px 4px 18px;
}

/* Failed message — red-tinted bubble + error notice */
.igcr-dm-msg--failed .igcr-dm-msg-bubble {
	background: var(--igcr-danger, #ef4444);
	opacity: 0.7;
}

.igcr-dm-msg-error {
	display: block;
	font-size: 0.72em;
	color: var(--igcr-danger, #ef4444);
	margin-top: 4px;
	padding: 0 4px;
	max-width: 260px;
	line-height: 1.4;
}

.igcr-dm-msg-time {
	font-size: 0.68em;
	color: var(--igcr-text-muted);
	margin-top: 2px;
	padding: 0 4px;
}

.igcr-dm-msg-date-sep {
	text-align: center;
	font-size: 0.75em;
	color: var(--igcr-text-muted);
	padding: 12px 0 6px;
	font-weight: 600;
}

/* ── Automation source badge ── */
.igcr-dm-msg-source {
	display: inline-flex;
	align-items: center;
	gap: 3px;
	font-size: 0.65em;
	color: var(--igcr-text-muted);
	margin-top: 2px;
	padding: 0 4px;
}

.igcr-dm-msg-source .igcr-icon {
	color: var(--igcr-accent);
}

/* ── Reply form ── */
.igcr-dm-reply-form {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px 0 0;
	border-top: 1px solid var(--igcr-border-light);
}

.igcr-dm-reply-input {
	flex: 1;
	padding: 10px 14px;
	border: 1px solid var(--igcr-border);
	border-radius: 24px;
	font-size: 0.9em;
	font-family: inherit;
	background: var(--igcr-bg-subtle);
	color: var(--igcr-text);
	outline: none;
	transition: border-color 0.15s;
}

.igcr-dm-reply-input::placeholder {
	color: var(--igcr-text-muted);
}

.igcr-dm-reply-input:focus {
	border-color: var(--igcr-accent);
}

.igcr-dm-reply-send {
	width: 40px;
	height: 40px;
	border-radius: 50%;
	border: none;
	background: var(--igcr-accent);
	color: #fff;
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.15s;
	flex-shrink: 0;
	padding: 0;
}

.igcr-dm-reply-send:hover:not(:disabled) {
	background: var(--igcr-accent-hover);
}

.igcr-dm-reply-send:disabled {
	opacity: 0.4;
	cursor: default;
}

/* ── SSE new message indicator ── */
.igcr-sse-dot {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: var(--igcr-accent);
	margin-left: 6px;
	vertical-align: middle;
	animation: igcr-pulse 1s ease-in-out infinite;
}

@keyframes igcr-pulse {
	0%, 100% { opacity: 1; }
	50%      { opacity: 0.4; }
}

/* ── Responsive: side-by-side on wide screens ── */
@media ( min-width: 876px ) {
	.igcr-messages-wrap {
		display: grid;
		grid-template-columns: 320px 1fr;
		gap: 0;
		max-width: 935px;
		border: 1px solid var(--igcr-border);
		border-radius: var(--igcr-radius-lg);
		overflow: hidden;
		padding: 0;
		margin-top: 32px;
		margin-bottom: 60px;
		height: calc(100vh - 120px);
		min-height: 400px;
		max-height: 800px;
		background: var(--igcr-bg);
	}

	.igcr-dm-header {
		padding: 16px;
		border-bottom: 1px solid var(--igcr-border-light);
		margin-bottom: 0;
	}

	.igcr-dm-threads-panel {
		border-right: 1px solid var(--igcr-border);
		display: flex;
		flex-direction: column;
		background: var(--igcr-bg);
		min-height: 0;
		overflow: hidden;
	}

	/* Always show threads panel on desktop */
	.igcr-dm-threads-panel[hidden] {
		display: flex;
	}

	.igcr-dm-threads {
		flex: 1;
		overflow-y: auto;
	}

	.igcr-dm-conversation-panel {
		height: auto;
		min-height: 0;
		overflow: hidden;
	}

	/* Show conversation panel as empty state when hidden on desktop */
	.igcr-dm-conversation-panel[hidden] {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.igcr-dm-conversation-panel[hidden]::after {
		content: "Select a conversation";
		color: var(--igcr-text-muted);
		font-size: 0.95em;
	}

	.igcr-dm-conversation-panel[hidden] > * {
		display: none;
	}

	.igcr-dm-conv-header {
		padding: 12px 16px;
		margin: 0;
	}

	.igcr-dm-back {
		display: none;
	}

	.igcr-dm-messages {
		padding: 16px;
	}

	.igcr-dm-reply-form {
		padding: 12px 16px;
		border-top: 1px solid var(--igcr-border-light);
	}
}
