/*
 * MTB Guides: frontend styles.
 *
 * Built to disappear into the theme:
 *  - fonts, text colour and sizes are inherited, never set;
 *  - the accent follows the theme's own palette (theme.json "primary") when it has one;
 *  - defaults sit in :where(), which has zero specificity, so any theme or Customizer rule wins;
 *  - the booking button carries WordPress's button classes, so the theme styles it itself.
 *
 * To restyle: override the custom properties below on .mtbg (or any wrapper), e.g.
 *   .mtbg { --mtbg-accent: #c2410c; --mtbg-radius: 0; }
 */

:where(.mtbg) {
	--mtbg-accent: var(--wp--preset--color--primary, currentColor);
	--mtbg-border: rgba(128, 128, 128, 0.3);
	--mtbg-muted: rgba(128, 128, 128, 0.95);
	--mtbg-surface: transparent;
	--mtbg-radius: 6px;
	--mtbg-gap: var(--wp--style--block-gap, 1.5rem);

	/* Trail difficulty: same scale and colours as the MTBMate app. Shape carries it too. */
	--mtbg-green: #6ca74a;
	--mtbg-blue: #4a8cb8;
	--mtbg-red: #b8472f;
	--mtbg-black: #1f1d1b;
	--mtbg-purple: #6f3a76;

	font: inherit;
	color: inherit;
	box-sizing: border-box;
}

:where(.mtbg) *,
:where(.mtbg) *::before,
:where(.mtbg) *::after {
	box-sizing: inherit;
}

@supports (color: color-mix(in srgb, red, blue)) {
	:where(.mtbg) {
		--mtbg-border: color-mix(in srgb, currentColor 20%, transparent);
		--mtbg-muted: color-mix(in srgb, currentColor 65%, transparent);
	}
}

/* ------------------------------------------------------------------ lists */

:where(.mtbg-list) {
	display: grid;
	gap: var(--mtbg-gap);
	margin: 0;
	padding: 0;
}

:where(.mtbg-list--grid) {
	grid-template-columns: repeat(var(--mtbg-columns, 3), minmax(0, 1fr));
}
:where(.mtbg-cols-1) { --mtbg-columns: 1; }
:where(.mtbg-cols-2) { --mtbg-columns: 2; }
:where(.mtbg-cols-3) { --mtbg-columns: 3; }
:where(.mtbg-cols-4) { --mtbg-columns: 4; }

@media (max-width: 960px) {
	:where(.mtbg-list--grid) { grid-template-columns: repeat(min(var(--mtbg-columns, 3), 2), minmax(0, 1fr)); }
}
@media (max-width: 600px) {
	:where(.mtbg-list--grid) { grid-template-columns: minmax(0, 1fr); }
}

:where(.mtbg-list--list) {
	grid-template-columns: minmax(0, 1fr);
}

/* ------------------------------------------------------------------ cards */

:where(.mtbg-card) {
	display: flex;
	flex-direction: column;
	gap: 0.6em;
	padding: 1.25em;
	background: var(--mtbg-surface);
	border: 1px solid var(--mtbg-border);
	border-radius: var(--mtbg-radius);
}

/* In a list the card reads as a row: details left, price and button right. */
@media (min-width: 700px) {
	:where(.mtbg-list--list .mtbg-card) {
		display: grid;
		grid-template-columns: minmax(0, 1fr) auto;
		column-gap: 1.5em;
		align-items: start;
	}
	:where(.mtbg-list--list .mtbg-card > :not(.mtbg-card__foot)) {
		grid-column: 1;
	}
	:where(.mtbg-list--list .mtbg-card > .mtbg-card__foot) {
		grid-column: 2;
		grid-row: 1 / span 6;
		flex-direction: column;
		align-items: flex-end;
		justify-content: center;
		margin: 0;
	}
}

:where(.mtbg-card__meta) {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.5em;
	font-size: 0.8em;
}

:where(.mtbg-card__title),
:where(.mtbg-single__title) {
	margin: 0;
	line-height: 1.25;
}

:where(.mtbg-card__when) {
	margin: 0;
	font-weight: 600;
}

:where(.mtbg-card__where),
:where(.mtbg-card__excerpt) {
	margin: 0;
}
:where(.mtbg-card__where) {
	color: var(--mtbg-muted);
}

:where(.mtbg-card__foot) {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 0.75em 1em;
	margin-top: auto;
	padding-top: 0.75em;
}

:where(.mtbg-price) {
	font-weight: 600;
}

/* ------------------------------------------------------------------ badges */

:where(.mtbg-badge) {
	padding: 0.15em 0.6em;
	border: 1px solid var(--mtbg-border);
	border-radius: 2px;
	font-size: 0.9em;
	line-height: 1.5;
	white-space: nowrap;
}
:where(.mtbg-badge--course),
:where(.mtbg-badge--guided),
:where(.mtbg-badge--offer) {
	border-color: var(--mtbg-accent);
	color: var(--mtbg-accent);
}

:where(.mtbg-level) {
	display: inline-flex;
	align-items: center;
	gap: 0.4em;
	white-space: nowrap;
}

:where(.mtbg-shape) {
	display: inline-block;
	width: 0.85em;
	height: 0.85em;
	background: currentColor;
	flex: none;
}
:where(.mtbg-shape--circle)   { border-radius: 50%; }
:where(.mtbg-shape--square)   { border-radius: 1px; }
:where(.mtbg-shape--triangle) { clip-path: polygon(50% 5%, 100% 95%, 0 95%); }
:where(.mtbg-shape--diamond)  { clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
:where(.mtbg-shape--hexagon)  { clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%); }

:where(.mtbg-level--green)  .mtbg-shape { color: var(--mtbg-green); }
:where(.mtbg-level--blue)   .mtbg-shape { color: var(--mtbg-blue); }
:where(.mtbg-level--red)    .mtbg-shape { color: var(--mtbg-red); }
:where(.mtbg-level--black)  .mtbg-shape { color: var(--mtbg-black); }
:where(.mtbg-level--purple) .mtbg-shape { color: var(--mtbg-purple); }

/* ------------------------------------------------------------------- facts */

:where(.mtbg-facts) {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(9em, 1fr));
	gap: 0.5em 1em;
	margin: 0;
	font-size: 0.9em;
}
:where(.mtbg-facts--compact) {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}
:where(.mtbg-facts) dt {
	color: var(--mtbg-muted);
	font-size: 0.85em;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}
:where(.mtbg-facts) dd {
	margin: 0;
}

/* ------------------------------------------------------------ single view */

:where(.mtbg-single) {
	display: flex;
	flex-direction: column;
	gap: 1.25em;
}
:where(.mtbg-single__head) {
	display: flex;
	flex-direction: column;
	gap: 0.5em;
}
:where(.mtbg-section h3) {
	margin: 0 0 0.4em;
}
:where(.mtbg-richtext > :first-child) { margin-top: 0; }
:where(.mtbg-richtext > :last-child)  { margin-bottom: 0; }

/* ------------------------------------------------------------------ button */

/* Only a fallback: themes that style .wp-element-button / .button win automatically. */
:where(.mtbg-button) {
	display: inline-block;
	padding: 0.6em 1.2em;
	border: 1px solid var(--mtbg-accent);
	border-radius: var(--mtbg-radius);
	background: var(--mtbg-accent);
	color: var(--wp--preset--color--base, #fff);
	font: inherit;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	text-decoration: none;
	cursor: pointer;
}
:where(.mtbg-button):hover,
:where(.mtbg-button):focus-visible {
	opacity: 0.88;
}

/* -------------------------------------------------- theme-proofing (structure)
 * Layout integrity, not looks: these use normal specificity on purpose so a theme's generic
 * rules (link underlines, default <dd> indent, flex quirks) can't break the cards.
 */

/* Cards keep their natural height; the footer never gets squashed by the column layout. */
.mtbg-card > * {
	flex-shrink: 0;
}
.mtbg-card__foot {
	align-content: flex-start;
}
/*
 * Some themes (and the block library) stretch .wp-block-button__link to a fixed height or to
 * 100%, which makes the button taller than its card when the price and button wrap. Others
 * underline every link inside content areas. A button is neither: keep its natural height and
 * no underline. The selector is deliberately specific enough to beat typical theme rules.
 */
.mtbg .mtbg-card__foot a.mtbg-button,
.mtbg .mtbg-card__foot a.mtbg-button:hover,
.mtbg .mtbg-card__foot a.mtbg-button:focus {
	height: auto;
	min-height: 0;
	text-decoration: none;
}
/* Themes give <dd> a left indent. */
.mtbg .mtbg-facts dd {
	margin: 0;
	overflow-wrap: anywhere;
}
.mtbg .mtbg-facts > div {
	min-width: 0;
}

/* ----------------------------------------------------------- empty / notice */

:where(.mtbg-empty) {
	padding: 1.5em;
	border: 1px dashed var(--mtbg-border);
	border-radius: var(--mtbg-radius);
	color: var(--mtbg-muted);
}
:where(.mtbg-empty) p {
	margin: 0;
}
:where(.mtbg-notice) {
	padding: 0.75em 1em;
	border-left: 4px solid #dba617;
	background: rgba(219, 166, 23, 0.12);
	font-size: 0.9em;
}
