/**
 * Concorbit Social Feed - Frontend Stylesheet
 *
 * Theme-neutral by design: no hardcoded fonts, no colour overrides on text.
 * Inherits typography from the host theme so the feed slots into the
 * surrounding page styling without looking like a bolted-on widget.
 *
 * Only structural CSS (layout, spacing, borders) plus a small set of CSS
 * variables that consumers can override via their theme stylesheet:
 *
 *   --concorbit-sf-accent       Link/hover colour. Default: inherits.
 *   --concorbit-sf-border       Card divider colour. Default: rgba(0,0,0,0.12).
 *   --concorbit-sf-muted        Time / secondary text. Default: rgba(0,0,0,0.55).
 *   --concorbit-sf-radius       Card corner radius. Default: 8px.
 *   --concorbit-sf-avatar-bg    Facebook avatar circle background. Default: #1877f2.
 *
 * All selectors are scoped under .concorbit-sf.
 */

.concorbit-sf {
	--concorbit-sf-accent: inherit;
	--concorbit-sf-border: rgba(0, 0, 0, 0.12);
	--concorbit-sf-muted: rgba(0, 0, 0, 0.55);
	--concorbit-sf-radius: 8px;
	--concorbit-sf-avatar-bg: #1877f2;

	/* Density tokens - overridden per density modifier below */
	--concorbit-sf-card-gap-y:  28px;
	--concorbit-sf-card-gap-x:  40px;
	--concorbit-sf-card-pad:    24px;
	--concorbit-sf-card-stack:  14px;
	--concorbit-sf-photo-h:     480px;
	--concorbit-sf-avatar-size: 40px;
	--concorbit-sf-title-mb:    32px;
	--concorbit-sf-section-py:  32px;

	max-width: 100%;
	margin: 0 auto;
	padding: var(--concorbit-sf-section-py) 0;
	box-sizing: border-box;
}

/* Density presets ------------------------------------------------------- */

.concorbit-sf-density-compact {
	--concorbit-sf-card-gap-y:  18px;
	--concorbit-sf-card-gap-x:  24px;
	--concorbit-sf-card-pad:    16px;
	--concorbit-sf-card-stack:  10px;
	--concorbit-sf-photo-h:     220px;
	--concorbit-sf-avatar-size: 32px;
	--concorbit-sf-title-mb:    20px;
	--concorbit-sf-section-py:  20px;
}

.concorbit-sf-density-spacious {
	--concorbit-sf-card-gap-y:  44px;
	--concorbit-sf-card-gap-x:  56px;
	--concorbit-sf-card-pad:    32px;
	--concorbit-sf-card-stack:  20px;
	--concorbit-sf-photo-h:     560px;
	--concorbit-sf-avatar-size: 44px;
	--concorbit-sf-title-mb:    40px;
	--concorbit-sf-section-py:  48px;
}

.concorbit-sf *,
.concorbit-sf *::before,
.concorbit-sf *::after {
	box-sizing: border-box;
}

/* Title ----------------------------------------------------------------- */

.concorbit-sf-title {
	text-align: center;
	margin: 0 0 var(--concorbit-sf-title-mb);
}

/* Grid layout ----------------------------------------------------------- */

.concorbit-sf-grid {
	display: grid;
	gap: var(--concorbit-sf-card-gap-y) var(--concorbit-sf-card-gap-x);
}

.concorbit-sf-cols-1 .concorbit-sf-grid {
	grid-template-columns: 1fr;
	max-width: 720px;
	margin: 0 auto;
}

.concorbit-sf-cols-2 .concorbit-sf-grid {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.concorbit-sf-cols-3 .concorbit-sf-grid {
	grid-template-columns: repeat(3, minmax(0, 1fr));
}

.concorbit-sf-cols-4 .concorbit-sf-grid {
	grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* Tablet (<=1024px): 4-col collapses to 2-col, 3-col stays */
@media (max-width: 1024px) {
	.concorbit-sf-cols-4 .concorbit-sf-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

/* Small tablet (<=860px): 3-col collapses to 2-col */
@media (max-width: 860px) {
	.concorbit-sf-cols-3 .concorbit-sf-grid {
		grid-template-columns: repeat(2, minmax(0, 1fr));
	}
}

/* Mobile (<=600px): everything collapses to 1-col */
@media (max-width: 600px) {
	.concorbit-sf-cols-2 .concorbit-sf-grid,
	.concorbit-sf-cols-3 .concorbit-sf-grid,
	.concorbit-sf-cols-4 .concorbit-sf-grid {
		grid-template-columns: 1fr;
		gap: 24px;
	}
	.concorbit-sf { padding: 24px 0; }
}

/* Post card ------------------------------------------------------------- */

.concorbit-sf-post {
	padding: 0 0 var(--concorbit-sf-card-pad);
	border-bottom: 1px solid var(--concorbit-sf-border);
	display: flex;
	flex-direction: column;
	gap: var(--concorbit-sf-card-stack);
	min-width: 0;
}

/* Drop the bottom rule on the last row of cards in each column count */
.concorbit-sf-cols-2 .concorbit-sf-post:nth-last-child(-n+2),
.concorbit-sf-cols-3 .concorbit-sf-post:nth-last-child(-n+3),
.concorbit-sf-cols-4 .concorbit-sf-post:nth-last-child(-n+4),
.concorbit-sf-cols-1 .concorbit-sf-post:last-child {
	border-bottom: 0;
	padding-bottom: 0;
}

/* Header (avatar + meta) ------------------------------------------------- */

.concorbit-sf-post-header {
	display: flex;
	align-items: center;
	gap: 12px;
}

.concorbit-sf-avatar {
	flex-shrink: 0;
	width: var(--concorbit-sf-avatar-size);
	height: var(--concorbit-sf-avatar-size);
	border-radius: 50%;
	background: var(--concorbit-sf-avatar-bg);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
}

.concorbit-sf-avatar svg {
	width: 70%;
	height: 70%;
	display: block;
}

.concorbit-sf-post-meta {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
}

.concorbit-sf-post-name {
	font-weight: 700;
	text-decoration: underline;
	text-underline-offset: 2px;
}

.concorbit-sf-post-time {
	font-size: 0.875em;
	color: var(--concorbit-sf-muted);
}

/* Body ------------------------------------------------------------------ */

.concorbit-sf-post-body {
	line-height: 1.55;
	word-wrap: break-word;
	overflow-wrap: break-word;
}

.concorbit-sf-post-ellipsis { color: var(--concorbit-sf-muted); }

.concorbit-sf-post-more {
	text-decoration: underline;
	font-weight: 600;
	margin-left: 2px;
}

/* Photo block ----------------------------------------------------------- */

.concorbit-sf-post-photo {
	position: relative;
	margin: 4px 0;
	border-radius: var(--concorbit-sf-radius);
	overflow: hidden;
	background: rgba(0, 0, 0, 0.04);
	display: flex;
}

/* Default (ratio=natural): height capped by density preset, content cropped if taller */
.concorbit-sf-post-photo a,
.concorbit-sf-post-photo img,
.concorbit-sf-post-photo .concorbit-sf-photo-trigger {
	display: block;
	width: 100%;
	height: auto;
	max-height: var(--concorbit-sf-photo-h);
	object-fit: cover;
}

.concorbit-sf-post-photo a { line-height: 0; }

/* Fixed aspect ratios - the wrapper enforces, the image fills via object-fit */
.concorbit-sf-ratio-landscape .concorbit-sf-post-photo {
	aspect-ratio: 16 / 9;
}
.concorbit-sf-ratio-square .concorbit-sf-post-photo {
	aspect-ratio: 1 / 1;
}
.concorbit-sf-ratio-portrait .concorbit-sf-post-photo {
	aspect-ratio: 4 / 5;
}

/* When a fixed aspect-ratio is set, the children must fill the wrapper exactly,
   not respect max-height (which would defeat the ratio). */
.concorbit-sf-ratio-landscape .concorbit-sf-post-photo a,
.concorbit-sf-ratio-landscape .concorbit-sf-post-photo img,
.concorbit-sf-ratio-landscape .concorbit-sf-post-photo .concorbit-sf-photo-trigger,
.concorbit-sf-ratio-landscape .concorbit-sf-post-photo .concorbit-sf-photo-trigger img,
.concorbit-sf-ratio-square .concorbit-sf-post-photo a,
.concorbit-sf-ratio-square .concorbit-sf-post-photo img,
.concorbit-sf-ratio-square .concorbit-sf-post-photo .concorbit-sf-photo-trigger,
.concorbit-sf-ratio-square .concorbit-sf-post-photo .concorbit-sf-photo-trigger img,
.concorbit-sf-ratio-portrait .concorbit-sf-post-photo a,
.concorbit-sf-ratio-portrait .concorbit-sf-post-photo img,
.concorbit-sf-ratio-portrait .concorbit-sf-post-photo .concorbit-sf-photo-trigger,
.concorbit-sf-ratio-portrait .concorbit-sf-post-photo .concorbit-sf-photo-trigger img {
	width: 100%;
	height: 100%;
	max-height: none;
	object-fit: cover;
}

.concorbit-sf-photo-badge {
	position: absolute;
	top: 12px;
	right: 12px;
	background: rgba(0, 0, 0, 0.65);
	color: #fff;
	font-size: 0.8125em;
	font-weight: 700;
	padding: 4px 10px;
	border-radius: 999px;
	pointer-events: none;
}

/* Footer (action links) ------------------------------------------------- */

.concorbit-sf-post-footer {
	display: flex;
	align-items: center;
	gap: 8px;
	flex-wrap: wrap;
	font-size: 0.875em;
}

.concorbit-sf-post-action {
	text-decoration: underline;
	text-underline-offset: 2px;
}

.concorbit-sf-sep {
	color: var(--concorbit-sf-muted);
}

/* Page card (optional footer) ------------------------------------------ */

.concorbit-sf-page-card {
	grid-column: 1 / -1;
	margin-top: 12px;
	border: 1px solid var(--concorbit-sf-border);
	border-radius: var(--concorbit-sf-radius);
	overflow: hidden;
	background: rgba(0, 0, 0, 0.02);
}

.concorbit-sf-page-card-cover {
	width: 100%;
	height: 160px;
	overflow: hidden;
	background: rgba(0, 0, 0, 0.05);
}

.concorbit-sf-page-card-cover img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.concorbit-sf-page-card-body {
	padding: 16px 20px;
	display: flex;
	align-items: center;
	gap: 16px;
}

.concorbit-sf-page-card-avatar {
	flex-shrink: 0;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	overflow: hidden;
	border: 3px solid #fff;
	margin-top: -40px;
	background: #fff;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.concorbit-sf-page-card-avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.concorbit-sf-page-card-meta {
	display: flex;
	flex-direction: column;
	gap: 4px;
	min-width: 0;
}

.concorbit-sf-page-card-name {
	font-weight: 700;
	font-size: 1.1em;
}

.concorbit-sf-page-card-link {
	font-size: 0.875em;
	color: var(--concorbit-sf-muted);
	text-decoration: underline;
	text-underline-offset: 2px;
}

/* States ---------------------------------------------------------------- */

.concorbit-sf-empty {
	text-align: center;
	padding: 48px 24px;
	color: var(--concorbit-sf-muted);
}

.concorbit-sf-error {
	padding: 16px 20px;
	background: #fef2f2;
	border: 1px solid #fecaca;
	border-radius: var(--concorbit-sf-radius);
	color: #991b1b;
	line-height: 1.5;
}
.concorbit-sf-error em {
	color: #b45568;
	font-style: italic;
	font-size: 0.8125em;
}

/* ══════════════════════════════════════════════════════════════════════
 * ALIGNED MODE - uniform card heights for clean grid layouts
 *
 * When .concorbit-sf-aligned is on the wrapper, every card has the same internal
 * structure heights: header is naturally fixed, body is clamped to N lines
 * (--concorbit-sf-msg-lines, set inline), and photo uses a fixed aspect ratio.
 * Result: photos and footers line up exactly across the row.
 * ══════════════════════════════════════════════════════════════════════ */

.concorbit-sf-aligned {
	--concorbit-sf-msg-lines: 3; /* default if not overridden via inline style */
}

/* Force a fixed photo ratio when aligned (CSS layer in case ratio class
   wasn't applied for any reason - e.g. user passed photo_ratio="natural"). */
.concorbit-sf-aligned.concorbit-sf-ratio-natural .concorbit-sf-post-photo {
	aspect-ratio: 16 / 9;
}
.concorbit-sf-aligned.concorbit-sf-ratio-natural .concorbit-sf-post-photo a,
.concorbit-sf-aligned.concorbit-sf-ratio-natural .concorbit-sf-post-photo img,
.concorbit-sf-aligned.concorbit-sf-ratio-natural .concorbit-sf-post-photo .concorbit-sf-photo-trigger,
.concorbit-sf-aligned.concorbit-sf-ratio-natural .concorbit-sf-post-photo .concorbit-sf-photo-trigger img {
	width: 100%;
	height: 100%;
	max-height: none;
	object-fit: cover;
}

/* Card becomes a flex column where the body grows to fill - but we don't
   want the body to actually grow visually, just reserve consistent space.
   The line-clamp on the body handles that. */
.concorbit-sf-aligned .concorbit-sf-post {
	height: 100%;
}

/* Clamp the message to a fixed number of lines and reserve that space even
   when the message is shorter. Webkit line-clamp is well supported (Safari,
   Chrome, Firefox 68+, Edge). */
.concorbit-sf-aligned .concorbit-sf-post-body {
	display: -webkit-box;
	-webkit-line-clamp: var(--concorbit-sf-msg-lines, 3);
	-webkit-box-orient: vertical;
	overflow: hidden;
	/* Reserve min-height so short messages don't shrink the card. 1.55 matches
	   the line-height set on .concorbit-sf-post-body above. */
	min-height: calc(1.55em * var(--concorbit-sf-msg-lines, 3));
}

/* "See More" link is meaningless when the body is clamped - we don't know
   where to clip to since it's CSS-only. Hide it in aligned mode. The user
   can still click "View on Facebook" in the footer for the full post. */
.concorbit-sf-aligned .concorbit-sf-post-more,
.concorbit-sf-aligned .concorbit-sf-post-ellipsis {
	display: none;
}

/* Push the photo + footer to the bottom of the card so even short messages
   still produce a card with a footer at the bottom edge. */
.concorbit-sf-aligned .concorbit-sf-post-photo {
	margin-top: auto;
}

/* Mobile: when columns collapse to 1, the alignment isn't needed (each
   card stacks vertically anyway) so relax the constraints for readability. */
@media (max-width: 600px) {
	.concorbit-sf-aligned .concorbit-sf-post-body {
		-webkit-line-clamp: unset;
		min-height: 0;
	}
	.concorbit-sf-aligned .concorbit-sf-post-more,
	.concorbit-sf-aligned .concorbit-sf-post-ellipsis {
		display: inline;
	}
}

/* ══════════════════════════════════════════════════════════════════════
 * LIGHTBOX
 * ══════════════════════════════════════════════════════════════════════ */

/* The photo trigger button - resets default button styling and keeps the
   image as the visible surface. */
.concorbit-sf-photo-trigger {
	display: block;
	width: 100%;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: zoom-in;
	line-height: 0;
}
.concorbit-sf-photo-trigger:focus-visible {
	outline: 2px solid var(--concorbit-sf-accent, currentColor);
	outline-offset: 2px;
}
.concorbit-sf-photo-trigger img {
	display: block;
	width: 100%;
	height: auto;
	max-height: var(--concorbit-sf-photo-h);
	object-fit: cover;
}

/* When the lightbox is open, lock background scroll. */
html.concorbit-sf-lb-locked,
html.concorbit-sf-lb-locked body {
	overflow: hidden;
}

/* Overlay. Fixed positioning + high z-index. Scoped to .concorbit-sf-lb so the
   host theme can't bleed into it. */
.concorbit-sf-lb {
	position: fixed;
	inset: 0;
	z-index: 99999;
	display: flex;
	align-items: center;
	justify-content: center;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
.concorbit-sf-lb[hidden] { display: none; }

.concorbit-sf-lb-backdrop {
	position: absolute;
	inset: 0;
	background: rgba(0, 0, 0, 0.92);
	cursor: zoom-out;
}

.concorbit-sf-lb-frame {
	position: relative;
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 16px 56px;
	box-sizing: border-box;
}

.concorbit-sf-lb-figure {
	position: relative;
	max-width: 100%;
	max-height: calc( 100vh - 160px );
	margin: 0;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 12px;
}

.concorbit-sf-lb-img {
	display: block;
	max-width: 100%;
	max-height: calc( 100vh - 200px );
	object-fit: contain;
	border-radius: 4px;
	background: rgba(255, 255, 255, 0.04);
}

.concorbit-sf-lb-caption {
	display: flex;
	align-items: center;
	gap: 16px;
	color: rgba(255, 255, 255, 0.85);
	font-size: 13px;
	flex-wrap: wrap;
	justify-content: center;
	text-align: center;
}
.concorbit-sf-lb-counter { font-weight: 600; }
.concorbit-sf-lb-label   { opacity: 0.75; }
.concorbit-sf-lb-perma {
	color: #fff;
	text-decoration: underline;
	text-underline-offset: 3px;
}
.concorbit-sf-lb-perma[hidden] { display: none; }

/* Buttons */
.concorbit-sf-lb-close,
.concorbit-sf-lb-prev,
.concorbit-sf-lb-next {
	position: absolute;
	background: rgba(255, 255, 255, 0.08);
	border: 0;
	color: #fff;
	width: 44px;
	height: 44px;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	cursor: pointer;
	transition: background 0.15s;
}
.concorbit-sf-lb-close:hover,
.concorbit-sf-lb-prev:hover,
.concorbit-sf-lb-next:hover {
	background: rgba(255, 255, 255, 0.18);
}
.concorbit-sf-lb-close:focus-visible,
.concorbit-sf-lb-prev:focus-visible,
.concorbit-sf-lb-next:focus-visible {
	outline: 2px solid #fff;
	outline-offset: 2px;
}
.concorbit-sf-lb-close {
	top: 16px;
	right: 16px;
}
.concorbit-sf-lb-prev { left: 8px;  top: 50%; transform: translateY(-50%); }
.concorbit-sf-lb-next { right: 8px; top: 50%; transform: translateY(-50%); }
.concorbit-sf-lb-prev[hidden],
.concorbit-sf-lb-next[hidden] { display: none; }

/* Thumbnail strip */
.concorbit-sf-lb-thumbs {
	position: absolute;
	bottom: 16px;
	left: 50%;
	transform: translateX(-50%);
	display: flex;
	gap: 6px;
	max-width: calc(100% - 32px);
	overflow-x: auto;
	padding: 6px;
	background: rgba(255, 255, 255, 0.06);
	border-radius: 8px;
	scrollbar-width: thin;
}
.concorbit-sf-lb-thumbs[hidden] { display: none; }
.concorbit-sf-lb-thumbs button {
	border: 2px solid transparent;
	padding: 0;
	background: transparent;
	border-radius: 4px;
	cursor: pointer;
	flex-shrink: 0;
	line-height: 0;
	transition: border-color 0.15s, opacity 0.15s;
	opacity: 0.6;
}
.concorbit-sf-lb-thumbs button:hover    { opacity: 0.95; }
.concorbit-sf-lb-thumbs button.is-active {
	border-color: #fff;
	opacity: 1;
}
.concorbit-sf-lb-thumbs img {
	display: block;
	width: 60px;
	height: 60px;
	object-fit: cover;
	border-radius: 2px;
}

/* Mobile */
@media (max-width: 600px) {
	.concorbit-sf-lb-frame { padding: 8px 8px 88px; }
	.concorbit-sf-lb-prev  { left: 4px;  width: 36px; height: 36px; }
	.concorbit-sf-lb-next  { right: 4px; width: 36px; height: 36px; }
	.concorbit-sf-lb-thumbs img { width: 44px; height: 44px; }
}

/* Respect reduced motion. */
@media (prefers-reduced-motion: reduce) {
	.concorbit-sf-lb-close,
	.concorbit-sf-lb-prev,
	.concorbit-sf-lb-next,
	.concorbit-sf-lb-thumbs button {
		transition: none;
	}
}
