/**
 * Fundraiser Grid — block styles.
 *
 * Shared between the editor and the frontend. Uses a CSS custom property
 * (--ambh-fg-columns) to drive the grid column count, which is set inline
 * by the PHP render callback based on the block attribute.
 *
 * @package AmbassadorHub\Fundraisers\Blocks\FundraiserGrid
 */

/* ── Editor canvas preview ─────────────────────────────────────────────── */

.ambh-fundraiser-grid.ambh-block-preview {
	padding: 2rem;
	background: #f0f0f1;
	border: 1px solid #ddd;
	border-radius: 4px;
	text-align: center;
}

.ambh-block-preview__label {
	margin: 0 0 0.375rem;
	font-weight: 600;
	font-size: var(--ambh-font-sm, 0.875rem);
}

.ambh-block-preview__meta {
	margin: 0.25rem 0 0;
	font-size: var(--ambh-font-xs, 0.75rem);
	color: var(--ambh-text-muted, #646970);
}

/* ── Grid layout ────────────────────────────────────────────────────────── */

.ambh-fundraiser-grid {
	display: grid;
	grid-template-columns: repeat( var( --ambh-fg-columns, 3 ), 1fr );
	gap: 1.5rem;
	list-style: none;
	margin: 1.5rem 0;
	padding: 0;
}

/* Tablet — cap at 2 columns when the configured count is higher. */
@media ( max-width: 768px ) {
	.ambh-fundraiser-grid {
		grid-template-columns: repeat( min( var( --ambh-fg-columns, 3 ), 2 ), 1fr );
	}
}

/* Mobile — always 1 column. */
@media ( max-width: 480px ) {
	.ambh-fundraiser-grid {
		grid-template-columns: 1fr;
	}
}

/* ── Card ───────────────────────────────────────────────────────────────── */

.ambh-fg-card {
	display: flex;
	flex-direction: column;
	border: 1px solid var(--ambh-border-color, #e0e0e0);
	border-radius: 6px;
	overflow: hidden;
	background: #fff;
	transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.ambh-fg-card:hover {
	box-shadow: 0 4px 16px rgba( 0, 0, 0, 0.1 );
	transform: translateY( -2px );
}

.ambh-fg-card__link {
	display: flex;
	flex-direction: column;
	flex: 1;
	text-decoration: none;
	color: inherit;
}

.ambh-fg-card__link:hover,
.ambh-fg-card__link:focus {
	text-decoration: none;
	color: inherit;
}

/* ── Card image ─────────────────────────────────────────────────────────── */

.ambh-fg-card__image img,
.ambh-fg-card__placeholder {
	display: block;
	width: 100%;
	aspect-ratio: 16 / 9;
	object-fit: cover;
}

/* Placeholder replaces the featured image when none is set. */
.ambh-fg-card__placeholder {
	display: flex;
	align-items: center;
	justify-content: center;
	background: var(--ambh-bg-subtle, #f6f7f7);
	color: var(--ambh-text-muted, #646970);
}

.ambh-fg-card__placeholder svg {
	width: 3rem;
	height: 3rem;
}

/* ── Card body ──────────────────────────────────────────────────────────── */

.ambh-fg-card__body {
	display: flex;
	flex-direction: column;
	flex: 1;
	padding: 1rem;
	gap: 0.5rem;
}

.ambh-fg-card__title {
	margin: 0;
	font-size: var(--ambh-font-base, 1rem);
	font-weight: 600;
	line-height: 1.4;
}

/* ── Stats row ──────────────────────────────────────────────────────────── */

.ambh-fg-card__stats {
	display: flex;
	flex-wrap: wrap;
	align-items: baseline;
	gap: 0.25rem 0.5rem;
	font-size: var(--ambh-font-sm, 0.875rem);
}

.ambh-fg-card__raised {
	font-weight: 600;
	color: var(--ambh-text-color, #1e1e1e);
}

.ambh-fg-card__target {
	color: var(--ambh-text-muted, #646970);
}

/* ── Progress bar ───────────────────────────────────────────────────────── */

.ambh-fg-card__progress {
	height: 6px;
	border-radius: 3px;
	background: var(--ambh-border-color, #e0e0e0);
	overflow: hidden;
	margin-top: auto;
}

.ambh-fg-card__progress-fill {
	height: 100%;
	border-radius: 3px;
	background: var(--ambh-color-progress, #00a32a);
	transition: width 0.3s ease;
	min-width: 2px; /* Always show a sliver so the bar is visible at 0. */
}

/* ── List view ──────────────────────────────────────────────────────────── */

.ambh-fundraiser-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
}

.ambh-fl-item {
	background: #fff;
	border: 1px solid var(--ambh-border-color, #e0e0e0);
	border-radius: 6px;
	overflow: hidden; /* Clips child corners and contains the progress bar flush. */
}

.ambh-fl-item__link {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 0.75rem 1rem;
	text-decoration: none;
	color: inherit;
}

.ambh-fl-item__link:hover,
.ambh-fl-item__link:focus {
	background: var(--ambh-bg-subtle, #f6f7f7);
	color: inherit;
	text-decoration: none;
}

/* ── Rank number ────────────────────────────────────────────────────────── */

.ambh-fl-item__rank {
	flex-shrink: 0;
	width: 1.75rem;
	text-align: center;
	font-weight: 700;
	font-size: var(--ambh-font-sm, 0.875rem);
	color: var(--ambh-text-muted, #646970);
}

/* Gold / silver / bronze treatment for the top 3 positions. */
.ambh-fundraiser-list > .ambh-fl-item:nth-child(1) .ambh-fl-item__rank { color: #c9a227; }
.ambh-fundraiser-list > .ambh-fl-item:nth-child(2) .ambh-fl-item__rank { color: #8e9ba6; }
.ambh-fundraiser-list > .ambh-fl-item:nth-child(3) .ambh-fl-item__rank { color: #b87043; }

/* ── Avatar ─────────────────────────────────────────────────────────────── */

.ambh-fl-item__avatar {
	flex-shrink: 0;
	width: 2.5rem;
	height: 2.5rem;
	border-radius: 50%;
	overflow: hidden;
	background: var(--ambh-border-color, #e0e0e0);
	display: flex;
	align-items: center;
	justify-content: center;
}

.ambh-fl-item__avatar img {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

.ambh-fl-item__initial {
	font-weight: 600;
	font-size: var(--ambh-font-base, 1rem);
	color: var(--ambh-text-muted, #646970);
	line-height: 1;
	text-transform: uppercase;
}

/* ── Name & amount ──────────────────────────────────────────────────────── */

.ambh-fl-item__name {
	flex: 1;
	font-weight: 500;
	font-size: var(--ambh-font-sm, 0.875rem);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.ambh-fl-item__raised {
	flex-shrink: 0;
	font-weight: 600;
	font-size: var(--ambh-font-sm, 0.875rem);
	color: var(--ambh-text-color, #1e1e1e);
}

/* ── Progress bar (sits below the link row, flush to the card bottom) ───── */

.ambh-fl-item__progress {
	height: 4px;
	background: var(--ambh-border-color, #e0e0e0);
	overflow: hidden;
}

.ambh-fl-item__progress-fill {
	height: 100%;
	background: var(--ambh-color-progress, #00a32a);
	min-width: 2px;
	transition: width 0.3s ease;
}
