/**
 * SCF Repeater for Elementor — Card Grid blocks.
 *
 * Every visual property is a custom property set on the grid, so the cards
 * inside inherit one shared design and restyling the grid restyles them all.
 * A card can set the same properties on itself to override them for that card
 * alone. Each fallback below equals the old fixed value, so a card that sets
 * nothing renders exactly as before.
 * Loaded in both the editor and the front end.
 */

.scfre-card-grid {
	display: grid;
	grid-template-columns: repeat(var(--scfre-cols, 3), minmax(0, 1fr));
	gap: var(--scfre-gap, 16px);

	/*
	 * Stated explicitly rather than left to inherit: some themes put a border on
	 * block wrappers, and the grid should have none unless it is asked for.
	 */
	border: var(--scfre-grid-border-width, 0) solid var(--scfre-grid-border-color, transparent);
	border-radius: var(--scfre-grid-radius, 0);
	padding: var(--scfre-grid-padding, 0);
	background-color: var(--scfre-grid-bg, transparent);
}

.scfre-card {
	display: flex;
	flex-direction: column;
	justify-content: var(--scfre-card-justify, flex-start);
	gap: var(--scfre-card-inner-gap, 12px);
	min-width: 0;
	min-height: var(--scfre-card-min-height, auto);
	padding: var(--scfre-card-padding, 20px);
	border: var(--scfre-card-border-width, 1px) var(--scfre-card-border-style, solid) var(--scfre-card-border-color, #e3e6ef);
	border-radius: var(--scfre-card-radius, 8px);
	background-color: var(--scfre-card-bg, #fff);
	background-image: var(--scfre-card-bg-image, none);
	background-position: center;
	background-size: cover;
	background-repeat: no-repeat;
	box-shadow: var(--scfre-card-shadow, none);
}

/* Alignment */
.scfre-card-grid--align-left .scfre-card {
	align-items: flex-start;
	text-align: left;
}

.scfre-card-grid--align-center .scfre-card {
	align-items: center;
	text-align: center;
}

.scfre-card-grid--align-right .scfre-card {
	align-items: flex-end;
	text-align: right;
}

/*
 * Per-card alignment. One class more specific than the grid's rules above, so
 * a card that picks its own alignment wins over the grid's.
 */
.scfre-card-grid .scfre-card.scfre-card--align-left {
	align-items: flex-start;
	text-align: left;
}

.scfre-card-grid .scfre-card.scfre-card--align-center {
	align-items: center;
	text-align: center;
}

.scfre-card-grid .scfre-card.scfre-card--align-right {
	align-items: flex-end;
	text-align: right;
}

/*
 * Keeps buttons on a shared baseline when titles wrap differently. The second
 * rule covers cards saved before buttons gained a wrapper: their markup stays
 * as it was stored until the card is edited and re-saved.
 */
.scfre-card-grid--pin .scfre-card__buttons,
.scfre-card-grid--pin .scfre-card > .scfre-card__button {
	margin-top: auto;
}

/* Buttons */
.scfre-card__buttons {
	display: flex;
	flex-wrap: wrap;
	flex-direction: var(--scfre-btn-direction, row);
	align-items: var(--scfre-btn-align, center);
	gap: var(--scfre-btn-gap, 10px);
	width: 100%;
}

.scfre-card-grid--align-left .scfre-card__buttons {
	justify-content: flex-start;
}

.scfre-card-grid--align-center .scfre-card__buttons {
	justify-content: center;
}

.scfre-card-grid--align-right .scfre-card__buttons {
	justify-content: flex-end;
}

.scfre-card-grid .scfre-card--align-left .scfre-card__buttons {
	justify-content: flex-start;
}

.scfre-card-grid .scfre-card--align-center .scfre-card__buttons {
	justify-content: center;
}

.scfre-card-grid .scfre-card--align-right .scfre-card__buttons {
	justify-content: flex-end;
}

/* Icon */
.scfre-card__icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: var(--scfre-icon-padding, 0);
	border-radius: var(--scfre-icon-radius, 0);
	background-color: var(--scfre-icon-bg, transparent);
	font-size: var(--scfre-icon-size, 40px);
	line-height: 1;
	color: var(--scfre-icon-color, #1e2a4a);
}

.scfre-card__icon .dashicons {
	width: 1em;
	height: 1em;
	font-size: 1em;
	line-height: 1;
}

/* Inline SVG icons follow the icon size, and the icon colour through currentColor. */
.scfre-card__svg {
	display: inline-flex;
	width: 1em;
	height: 1em;
	line-height: 0;
}

.scfre-card__svg svg {
	display: block;
	width: 100%;
	height: 100%;
	overflow: visible;
}

.scfre-control-error {
	margin-top: -8px;
	color: #cc1818;
	font-size: 12px;
}

.scfre-card__icon-img {
	width: 1em;
	height: 1em;
	object-fit: contain;
}

/* Title */
.scfre-card__title {
	margin: 0;
	font-size: var(--scfre-title-size, 16px);
	line-height: var(--scfre-title-line-height, 1.4);
	color: var(--scfre-title-color, #1e2a4a);
	overflow-wrap: break-word;
}

/* Button */
.scfre-card__button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: var(--scfre-btn-py, 10px) var(--scfre-btn-px, 18px);
	border-radius: var(--scfre-btn-radius, 4px);
	background-color: var(--scfre-btn-bg, #2f5fe0);
	color: var(--scfre-btn-color, #fff);
	line-height: 1.3;
	text-decoration: none;
	transition: background-color 0.2s ease, color 0.2s ease;
}

a.scfre-card__button:hover,
a.scfre-card__button:focus {
	background-color: var(--scfre-btn-bg-hover, #1e46b8);
	color: var(--scfre-btn-color-hover, var(--scfre-btn-color, #fff));
	text-decoration: none;
}

/*
 * Settings with no harmless default. They apply only when a card switches
 * them on, so every other card keeps the theme's font weight and size.
 */
.scfre-card--title-weight .scfre-card__title {
	font-weight: var(--scfre-title-weight);
}

.scfre-card--btn-size .scfre-card__button {
	font-size: var(--scfre-btn-size);
}

.scfre-card--btn-weight .scfre-card__button {
	font-weight: var(--scfre-btn-weight);
}

.scfre-card--btn-border .scfre-card__button {
	border: var(--scfre-btn-border-width, 1px) solid var(--scfre-btn-border-color, currentColor);
}

/* Per-card hover effect */
.scfre-card--hover {
	transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}

.scfre-card--hover:hover {
	transform: translateY(calc(var(--scfre-card-lift, 0px) * -1));
	border-color: var(--scfre-card-border-color-hover, var(--scfre-card-border-color, #e3e6ef));
	background-color: var(--scfre-card-bg-hover, var(--scfre-card-bg, #fff));
	box-shadow: var(--scfre-card-shadow-hover, var(--scfre-card-shadow, none));
}

@media (prefers-reduced-motion: reduce) {
	.scfre-card--hover,
	.scfre-card--hover:hover {
		transition: none;
		transform: none;
	}
}

/* Responsive columns */
@media (max-width: 1024px) {
	.scfre-card-grid {
		grid-template-columns: repeat(var(--scfre-cols-tablet, 2), minmax(0, 1fr));
	}
}

@media (max-width: 767px) {
	.scfre-card-grid {
		grid-template-columns: repeat(var(--scfre-cols-mobile, 1), minmax(0, 1fr));
	}
}

/* Per-card visibility, using the same breakpoints as the columns. */
@media (min-width: 1025px) {
	.scfre-card-grid .scfre-card--hide-desktop {
		display: none;
	}
}

@media (min-width: 768px) and (max-width: 1024px) {
	.scfre-card-grid .scfre-card--hide-tablet {
		display: none;
	}
}

@media (max-width: 767px) {
	.scfre-card-grid .scfre-card--hide-mobile {
		display: none;
	}
}

/* In the editor a hidden card stays on screen, faded, so it can still be edited. */
.editor-styles-wrapper .scfre-card-grid .scfre-card.scfre-card--hide-desktop,
.editor-styles-wrapper .scfre-card-grid .scfre-card.scfre-card--hide-tablet,
.editor-styles-wrapper .scfre-card-grid .scfre-card.scfre-card--hide-mobile {
	display: flex;
	opacity: 0.5;
	outline: 1px dashed #949494;
}

/* Editor niceties */
.scfre-card-style-tools {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	margin-bottom: 16px;
}

.scfre-button-group,
.scfre-color-row {
	margin-bottom: 16px;
}

.scfre-control-label {
	margin-bottom: 8px;
	font-size: 11px;
	font-weight: 500;
	text-transform: uppercase;
}

.scfre-control-help {
	margin-top: 0;
	color: #757575;
	font-size: 12px;
	font-style: normal;
}

/* One button's settings in the inspector, boxed so the list stays readable. */
.scfre-button-row {
	margin-bottom: 16px;
	padding: 12px;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
}

.scfre-button-row__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 8px;
}

.scfre-button-row__title {
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
}

.scfre-button-row .components-base-control:last-of-type {
	margin-bottom: 0;
}

/*
 * In the editor the cards sit inside one or two InnerBlocks wrapper divs. Left
 * alone, those wrappers become the grid items — a single item in column one —
 * and the cards get squeezed into a fraction of the width. `display: contents`
 * removes the wrappers from layout so the cards become direct grid items and
 * the editor matches the front end, including the responsive rules above.
 */
.editor-styles-wrapper .scfre-card-grid > .block-editor-inner-blocks,
.editor-styles-wrapper .scfre-card-grid .block-editor-block-list__layout {
	display: contents;
}

/* Themes commonly constrain .wp-block, which would narrow the cards again. */
.editor-styles-wrapper .scfre-card-grid .scfre-card {
	max-width: none;
	margin-left: 0;
	margin-right: 0;
}

.editor-styles-wrapper .scfre-card__title {
	margin: 0;
}

.editor-styles-wrapper .scfre-card .block-editor-rich-text__editable:focus {
	outline: 1px solid rgba(47, 95, 224, 0.4);
}
