/*
 * RecLite Headless — Communications
 *
 * Surfaces: header notification bell, account Inbox (notification center),
 * account Messages (history + detail/timeline), and the public unsubscribe
 * landing.
 *
 * Palette: theme accents only (--reclite-color-primary / -secondary) plus the
 * shared neutral tokens (--rl-border / --rl-muted / --rl-surface* / --rl-text)
 * with inline fallbacks, so the bundle renders standalone (the bell can appear
 * on pages where no other RecLite CSS loads). One danger tint is introduced
 * for bounced/failed delivery — always paired with a text label, so colour is
 * never the sole signal (WCAG 1.4.1). A forced-colors block closes the file.
 */

.rl-bell,
.rl-inbox,
.rl-msg,
.rl-unsub {
	--_p:  var(--reclite-color-primary, #1f6feb);
	--_s:  var(--reclite-color-secondary, #5b6472);
	--_d:  var(--rl-danger, #b3261e);
	--_p10: color-mix(in srgb, var(--_p) 10%, transparent);
	--_p18: color-mix(in srgb, var(--_p) 18%, transparent);
	--_d10: color-mix(in srgb, var(--_d) 12%, transparent);
	--_border:  var(--rl-border, #d8dde7);
	--_muted:   var(--rl-muted, #5b6472);
	--_surface: var(--rl-surface, #ffffff);
	--_alt:     var(--rl-surface-alt, #f7f8fb);
	--_text:    var(--rl-text, #1a1f29);
}

/* --------------------------------------------------------------
 * Small shared button modifiers (self-contained; additive)
 * -------------------------------------------------------------- */
.rl-btn-sm { padding: 4px 12px; font-size: 0.85rem; }
.rl-btn-link {
	background: none;
	border: none;
	color: var(--reclite-color-primary, #1f6feb);
	padding: 4px 6px;
	text-decoration: underline;
	cursor: pointer;
	font: inherit;
}
.rl-btn-link:hover,
.rl-btn-link:focus-visible { text-decoration: none; }

/* --------------------------------------------------------------
 * Badges (classification + delivery/read status)
 * -------------------------------------------------------------- */
.rl-bell .rl-badge,
.rl-inbox .rl-badge,
.rl-msg .rl-badge {
	display: inline-block;
	padding: 1px 9px;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 600;
	line-height: 1.5;
	text-transform: capitalize;
	white-space: nowrap;
	border: 1px solid transparent;
	vertical-align: middle;
}
.rl-badge-transactional { background: var(--_alt); color: var(--_muted); border-color: var(--_border); }
.rl-badge-marketing     { background: var(--_p10); color: var(--_p); border-color: var(--_p); }

.rl-badge-queued    { background: var(--_alt); color: var(--_muted); border-color: var(--_border); }
.rl-badge-sent      { background: var(--_p10); color: var(--_p); border-color: var(--_p); }
.rl-badge-delivered { background: var(--_p); color: #fff; border-color: var(--_p); }
.rl-badge-bounced   { background: var(--_d10); color: var(--_d); border-color: var(--_d); }
.rl-badge-failed    { background: var(--_d); color: #fff; border-color: var(--_d); }
.rl-badge-neutral   { background: var(--_alt); color: var(--_muted); border-color: var(--_border); }

/* ==============================================================
 * Header notification bell
 * ============================================================== */
.rl-bell { position: relative; display: inline-flex; }

.rl-bell-btn {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	padding: 0;
	border: 1px solid transparent;
	border-radius: 8px;
	background: transparent;
	color: currentColor;
	cursor: pointer;
	line-height: 0;
}
.rl-bell-btn:hover { background: color-mix(in srgb, currentColor 8%, transparent); }
.rl-bell-btn:focus-visible {
	outline: 2px solid var(--reclite-color-primary, #1f6feb);
	outline-offset: 2px;
}
.rl-bell-icon { display: block; }

.rl-bell-badge {
	position: absolute;
	top: 2px;
	right: 2px;
	min-width: 18px;
	height: 18px;
	padding: 0 4px;
	border-radius: 999px;
	background: var(--_d, #b3261e);
	color: #fff;
	font-size: 0.7rem;
	font-weight: 700;
	line-height: 18px;
	text-align: center;
	box-shadow: 0 0 0 2px var(--_surface, #fff);
}
.rl-bell-badge[hidden] { display: none; }

.rl-bell-panel {
	position: absolute;
	top: calc(100% + 8px);
	right: 0;
	z-index: 1000;
	width: 360px;
	max-width: calc(100vw - 24px);
	max-height: min(70vh, 560px);
	display: flex;
	flex-direction: column;
	background: var(--_surface);
	color: var(--_text);
	border: 1px solid var(--_border);
	border-radius: 12px;
	box-shadow: 0 12px 32px rgba(20, 25, 40, 0.18);
	overflow: hidden;
}
.rl-bell-panel[hidden] { display: none; }
.rl-bell-panel:focus-visible { outline: 2px solid var(--reclite-color-primary, #1f6feb); outline-offset: -2px; }

.rl-bell-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 12px 14px;
	border-bottom: 1px solid var(--_border);
}
.rl-bell-title { margin: 0; font-size: 1rem; }
.rl-bell-markall[hidden] { display: none; }

.rl-bell-list { overflow-y: auto; flex: 1 1 auto; }
.rl-bell-loading { padding: 20px 14px; }
.rl-bell-items { list-style: none; margin: 0; padding: 0; }

.rl-bell-item {
	display: flex;
	gap: 10px;
	width: 100%;
	text-align: left;
	padding: 12px 14px;
	background: transparent;
	border: none;
	border-bottom: 1px solid var(--_border);
	cursor: pointer;
	font: inherit;
	color: inherit;
}
.rl-bell-item:last-child { border-bottom: none; }
.rl-bell-item:hover { background: var(--_alt); }
.rl-bell-item:focus-visible { outline: 2px solid var(--reclite-color-primary, #1f6feb); outline-offset: -2px; }
.rl-bell-item-dot {
	flex: 0 0 auto;
	width: 8px;
	height: 8px;
	margin-top: 6px;
	border-radius: 50%;
	background: transparent;
}
.rl-bell-item.is-unread .rl-bell-item-dot { background: var(--color-tertiary, #1b6ca8); }
.rl-bell-item-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rl-bell-item-title { font-weight: 600; }
.rl-bell-item.is-unread .rl-bell-item-title { color: var(--_text); }
.rl-bell-item:not(.is-unread) .rl-bell-item-title { color: var(--_muted); font-weight: 500; }
.rl-bell-item-body {
	font-size: 0.85rem;
	color: var(--_muted);
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.rl-bell-item-meta { font-size: 0.75rem; color: var(--_muted); }
.rl-bell-item-unreadtag { color: var(--color-tertiary, #1b6ca8); font-weight: 600; }

.rl-bell-empty { padding: 28px 16px; text-align: center; }
.rl-bell-empty p { margin: 4px 0; }

.rl-bell-foot {
	padding: 10px 14px;
	border-top: 1px solid var(--_border);
	text-align: center;
}
.rl-bell-viewall { font-weight: 600; text-decoration: none; color: var(--reclite-color-primary, #1f6feb); }
.rl-bell-viewall:hover { text-decoration: underline; }
.rl-bell-error { margin: 10px 14px; }

/* Bell inside a nav menu item — strip list affordances the theme may add. */
.rl-bell-menu-item { list-style: none; display: flex; align-items: center; }
.rl-bell-menu-item::before,
.rl-bell-menu-item::marker { content: none; }

@media (max-width: 480px) {
	.rl-bell-panel {
		position: fixed;
		top: auto;
		bottom: 0;
		left: 0;
		right: 0;
		width: auto;
		max-width: none;
		max-height: 80vh;
		border-radius: 12px 12px 0 0;
	}
}

/* ==============================================================
 * Account "Inbox" tab — unread count badge overlaid on the icon
 * ============================================================== */
/* A relatively-positioned wrapper around the (dimmed) icon so the badge can
 * sit on the icon's corner at full opacity. Kept within the tab's top padding
 * so the tab strip's overflow-y:hidden never clips it. */
.rl-tab-iconwrap {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
}
.rl-tab-icon-badge {
	position: absolute;
	top: -7px;
	left: 100%;
	margin-left: -10px;
	min-width: 16px;
	height: 16px;
	padding: 0 4px;
	border-radius: 999px;
	background: var(--rl-danger, #b3261e);
	color: #fff;
	font-size: 0.62rem;
	font-weight: 700;
	line-height: 16px;
	text-align: center;
	box-shadow: 0 0 0 2px var(--rl-surface, #fff);
	pointer-events: none;
	z-index: 2;
}
.rl-tab-icon-badge[hidden] { display: none; }
/* The wrapper isn't the dimmed .rl-tab-icon, so lift the active/hover icon
 * emphasis onto it too for visual parity with the other tabs. */
.rl-tab:hover .rl-tab-iconwrap .rl-tab-icon,
.rl-tab.is-active .rl-tab-iconwrap .rl-tab-icon { opacity: 1; }

/* ==============================================================
 * Inbox (notification center) tab
 * ============================================================== */
.rl-inbox-card { padding: 0; overflow: hidden; }
.rl-inbox { display: block; }

/* Header ------------------------------------------------------- */
.rl-inbox-header {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
	flex-wrap: wrap;
	padding: 20px 22px;
	background: linear-gradient(180deg, var(--_p10), transparent);
	border-bottom: 1px solid var(--_border);
}
.rl-inbox-header-main { min-width: 0; }
.rl-inbox-heading {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 0;
	font-size: 1.2rem;
	line-height: 1.2;
}
.rl-inbox-heading-ico {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 9px;
	background: var(--_p);
	color: #fff;
	flex: 0 0 auto;
}
.rl-inbox-count-pill {
	display: inline-block;
	padding: 2px 10px;
	border-radius: 999px;
	font-size: 0.75rem;
	font-weight: 700;
	background: var(--color-tertiary, #1b6ca8);
	color: #fff;
	white-space: nowrap;
}
.rl-inbox-count-pill.is-zero {
	background: var(--_alt);
	color: var(--_muted);
	border: 1px solid var(--_border);
}
.rl-inbox-lede { margin: 6px 0 0; color: var(--_muted); font-size: 0.9rem; }

.rl-inbox-actions {
	display: flex;
	align-items: center;
	gap: 8px;
	flex: 0 0 auto;
	flex-wrap: wrap;
}
.rl-inbox-markall,
.rl-inbox-prefs-toggle {
	display: inline-flex;
	align-items: center;
	gap: 7px;
	flex: 0 0 auto;
	white-space: nowrap;
}
.rl-inbox-markall svg,
.rl-inbox-prefs-toggle svg { flex: 0 0 auto; }

/* Controls (segmented filter) --------------------------------- */
.rl-inbox-controls { padding: 16px 22px 4px; }
.rl-inbox-seg {
	display: inline-flex;
	padding: 3px;
	gap: 3px;
	background: var(--_alt);
	border: 1px solid var(--_border);
	border-radius: 999px;
}
.rl-inbox-seg-btn {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 16px;
	border-radius: 999px;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--_muted);
	cursor: pointer;
	transition: background .12s ease, color .12s ease;
}
.rl-inbox-seg-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.rl-inbox-seg-btn.is-active { background: var(--_surface); color: var(--_text); box-shadow: 0 1px 3px rgba(20,25,40,.12); }
.rl-inbox-seg-btn:hover:not(.is-active) { color: var(--_text); }
.rl-inbox-seg-btn input:focus-visible + span { outline: 2px solid var(--_p); outline-offset: 3px; border-radius: 4px; }
.rl-inbox-seg-count {
	min-width: 18px;
	padding: 0 5px;
	border-radius: 999px;
	background: var(--color-tertiary, #1b6ca8);
	color: #fff;
	font-size: 0.7rem;
	line-height: 18px;
	text-align: center;
}

/* List --------------------------------------------------------- */
.rl-inbox-list { list-style: none; margin: 0; padding: 8px 12px 16px; display: flex; flex-direction: column; gap: 6px; }

.rl-inbox-item {
	display: flex;
	gap: 12px;
	align-items: flex-start;
	padding: 14px 14px;
	background: var(--_surface);
	border: 1px solid transparent;
	border-radius: 10px;
	transition: background .12s ease, border-color .12s ease;
}
.rl-inbox-item:hover { background: var(--_alt); }
.rl-inbox-item.is-unread {
	background: var(--_p10);
	border-color: color-mix(in srgb, var(--_p) 28%, var(--_border));
}
.rl-inbox-item.is-unread:hover { background: color-mix(in srgb, var(--_p) 14%, var(--_surface)); }

.rl-inbox-avatar {
	flex: 0 0 auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 38px;
	height: 38px;
	border-radius: 50%;
	background: var(--_alt);
	color: var(--_muted);
	border: 1px solid var(--_border);
}
.rl-inbox-item.is-unread .rl-inbox-avatar { background: var(--_p); color: #fff; border-color: var(--_p); }
.rl-inbox-avatar.is-marketing { color: var(--_s); }

.rl-inbox-item-main { flex: 1 1 auto; min-width: 0; }
.rl-inbox-item-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rl-inbox-item-title { margin: 0; font-size: 1rem; font-weight: 600; }
.rl-inbox-item.is-unread .rl-inbox-item-title { font-weight: 700; }
.rl-inbox-new-tag {
	font-size: 0.68rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: .03em;
	padding: 1px 7px;
	border-radius: 999px;
	background: var(--_p);
	color: #fff;
}
.rl-inbox-item-body { margin: 4px 0 6px; color: var(--_text); font-size: 0.92rem; line-height: 1.45; overflow-wrap: anywhere; }
/* Formatting inside the sanitized notification body renders naturally. */
.rl-inbox-item-body > :first-child { margin-top: 0; }
.rl-inbox-item-body > :last-child { margin-bottom: 0; }
.rl-inbox-item-body p { margin: 0 0 8px; }
.rl-inbox-item-body a { color: var(--color-tertiary, #1b6ca8); text-decoration: underline; }
.rl-inbox-item-body a:hover { text-decoration: none; }
.rl-inbox-item-body strong, .rl-inbox-item-body b { font-weight: 700; }
.rl-inbox-item-body ul, .rl-inbox-item-body ol { margin: 6px 0; padding-left: 20px; }
.rl-inbox-item-body li { margin: 2px 0; }
.rl-inbox-item-body blockquote { margin: 6px 0; padding-left: 12px; border-left: 3px solid var(--_border); color: var(--_muted); }
.rl-inbox-item-body code { font-size: 0.85em; background: var(--_alt); padding: 1px 4px; border-radius: 4px; }
.rl-inbox-item-body hr { border: none; border-top: 1px solid var(--_border); margin: 8px 0; }
.rl-inbox-item-meta { font-size: 0.78rem; color: var(--_muted); }

.rl-inbox-item-actions { flex: 0 0 auto; display: flex; align-items: center; }
.rl-inbox-read-check {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	border-radius: 50%;
	color: var(--_p);
	background: var(--_p10);
}

/* Skeleton loading -------------------------------------------- */
.rl-inbox-skeleton {
	display: flex;
	gap: 12px;
	align-items: center;
	padding: 14px;
	border-radius: 10px;
	border: 1px solid var(--_border);
}
.rl-inbox-skeleton > span {
	display: block;
	height: 12px;
	border-radius: 6px;
	background: linear-gradient(90deg, var(--_alt) 25%, color-mix(in srgb, var(--_muted) 12%, var(--_alt)) 50%, var(--_alt) 75%);
	background-size: 200% 100%;
	animation: rl-inbox-shimmer 1.2s ease-in-out infinite;
}
.rl-inbox-skeleton > span:nth-child(1) { width: 38px; height: 38px; border-radius: 50%; flex: 0 0 auto; }
.rl-inbox-skeleton > span:nth-child(2) { flex: 1 1 auto; }
.rl-inbox-skeleton > span:nth-child(3) { width: 64px; flex: 0 0 auto; }
@keyframes rl-inbox-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.rl-inbox-pagination {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 14px;
	padding: 4px 22px 20px;
}
.rl-inbox-pagination[hidden] { display: none; }

.rl-inbox-empty { text-align: center; padding: 48px 16px; color: var(--_muted); }
.rl-inbox-empty svg { color: var(--_border); margin-bottom: 8px; }
.rl-inbox-empty p { margin: 4px 0; }
.rl-inbox [data-inbox-error] { margin: 0 22px 16px; }

@media (prefers-reduced-motion: reduce) {
	.rl-inbox-skeleton > span { animation: none; }
	.rl-inbox-item, .rl-inbox-seg-btn { transition: none; }
}

/* ==============================================================
 * Messages (history) tab
 * ============================================================== */
.rl-msg-filters {
	display: flex;
	gap: 12px;
	flex-wrap: wrap;
	align-items: flex-end;
	margin-bottom: 16px;
}
.rl-msg-filters .rl-field { display: flex; flex-direction: column; gap: 4px; }
.rl-msg-filters label { font-size: 0.8rem; font-weight: 600; color: var(--_muted); }

.rl-msg-list { display: flex; flex-direction: column; gap: 8px; }

.rl-msg-row {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	text-align: left;
	padding: 14px 16px;
	background: var(--_surface);
	border: 1px solid var(--_border);
	border-radius: 10px;
	cursor: pointer;
	font: inherit;
	color: inherit;
}
.rl-msg-row:hover { background: var(--_alt); }
.rl-msg-row:focus-visible { outline: 2px solid var(--reclite-color-primary, #1f6feb); outline-offset: 2px; }
.rl-msg-row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.rl-msg-row-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.rl-msg-row-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rl-msg-row-snippet {
	color: var(--_muted);
	font-size: 0.9rem;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	-webkit-box-orient: vertical;
	overflow: hidden;
}
.rl-msg-row-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 0.8rem; color: var(--_muted); }
.rl-msg-row-channel { font-weight: 600; }
.rl-msg-row-arrow { flex: 0 0 auto; color: var(--_muted); }

/* Detail modal */
.rl-msg-detail-modal { max-width: 720px; width: 100%; }
.rl-msg-detail-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}
.rl-msg-detail-meta {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	align-items: center;
	font-size: 0.85rem;
	color: var(--_muted);
	margin-bottom: 12px;
}
.rl-msg-detail-bodywrap {
	border: 1px solid var(--_border);
	border-radius: 8px;
	overflow: hidden;
	margin-bottom: 20px;
	background: var(--_surface);
}
.rl-msg-body-frame { display: block; width: 100%; height: 52vh; border: 0; background: #fff; }
.rl-msg-body-text { padding: 14px 16px; white-space: pre-wrap; word-break: break-word; }

.rl-msg-detail-tl-h { font-size: 1rem; margin: 0 0 10px; }
.rl-msg-timeline { list-style: none; margin: 0; padding: 0; }
.rl-msg-timeline-item { display: flex; gap: 12px; padding: 0 0 14px; position: relative; }
.rl-msg-timeline-item:not(:last-child)::before {
	content: "";
	position: absolute;
	left: 5px;
	top: 14px;
	bottom: 0;
	width: 2px;
	background: var(--_border);
}
.rl-msg-timeline-dot {
	flex: 0 0 auto;
	width: 12px;
	height: 12px;
	margin-top: 2px;
	border-radius: 50%;
	background: var(--_alt);
	border: 2px solid var(--_muted);
	z-index: 1;
}
.rl-msg-timeline-delivered,
.rl-msg-timeline-read { background: var(--_p); border-color: var(--_p); }
.rl-msg-timeline-sent { background: color-mix(in srgb, var(--_p) 40%, #fff); border-color: var(--_p); }
.rl-msg-timeline-queued { background: var(--_alt); border-color: var(--_muted); }
.rl-msg-timeline-bounced,
.rl-msg-timeline-failed { background: var(--_d); border-color: var(--_d); }
.rl-msg-timeline-main { display: flex; flex-direction: column; gap: 2px; }
.rl-msg-timeline-type { font-weight: 600; }
.rl-msg-timeline-detail { font-size: 0.85rem; color: var(--_muted); }
.rl-msg-timeline-time { font-size: 0.8rem; color: var(--_muted); }

/* ==============================================================
 * Public unsubscribe landing
 * ============================================================== */
.rl-unsub { max-width: 620px; margin: 0 auto; }
.rl-unsub-h1 { margin-bottom: 20px; }
.rl-unsub-state:focus-visible { outline: 2px solid var(--reclite-color-primary, #1f6feb); outline-offset: 4px; }
.rl-unsub-view, .rl-unsub-done, .rl-unsub-invalid { padding: 24px; }
.rl-unsub-view-h { margin-top: 0; }
.rl-unsub-contact { font-size: 1.05rem; }
.rl-unsub-transactional { color: var(--_muted); }
.rl-unsub-already { margin: 16px 0; }
.rl-unsub-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.rl-unsub-done { text-align: center; }
.rl-unsub-done-icon { color: var(--_p); display: flex; justify-content: center; margin-bottom: 8px; }
.rl-unsub-done h2 { margin-top: 0; }

/* ==============================================================
 * Reduced motion
 * ============================================================== */
@media (prefers-reduced-motion: reduce) {
	.rl-bell-btn, .rl-bell-item, .rl-msg-row { transition: none; }
}

/* ==============================================================
 * High-contrast / forced-colors fallback
 * ============================================================== */
@media (forced-colors: active) {
	.rl-bell .rl-badge,
	.rl-inbox .rl-badge,
	.rl-msg .rl-badge,
	.rl-tab-icon-badge,
	.rl-bell-badge { border: 1px solid CanvasText; }
	.rl-bell-panel,
	.rl-inbox-item,
	.rl-msg-row,
	.rl-msg-detail-bodywrap { border: 1px solid CanvasText; }
	.rl-bell-item.is-unread .rl-bell-item-dot,
	.rl-inbox-item.is-unread .rl-inbox-avatar,
	.rl-inbox-count-pill,
	.rl-inbox-new-tag,
	.rl-msg-timeline-dot { forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight; }
	.rl-bell-btn:focus-visible,
	.rl-msg-row:focus-visible,
	.rl-bell-item:focus-visible { outline: 2px solid Highlight; }
}
