/**
 * LFVC Local Events — front end.
 *
 * Designed to inherit the site's design rather than impose one.
 *
 * Three layers, in order of preference:
 *   1. WordPress global styles (theme.json) — --wp--preset--* variables, which
 *      block themes and Full Site Editing themes expose automatically.
 *   2. The surrounding page — font, text colour, and background are inherited,
 *      and greys are derived from the inherited text colour with color-mix()
 *      so the calendar adapts to a light or dark section without media queries.
 *   3. Plain fallback values, for classic themes that provide neither.
 *
 * To restyle, override the tokens on .lfvc-calendar. Nothing below hardcodes a
 * colour that a theme cannot displace.
 */

.lfvc-calendar {
	/* Typography comes from the page. */
	--lfvc-font: inherit;
	/* Twenty Twenty-Five publishes neither a "heading" nor a "body" slug, so
	   this must degrade to plain inheritance rather than assume one exists. */
	--lfvc-heading-font: var(--wp--preset--font-family--heading,
		var(--theme-font-family, var(--lfvc-font)));

	/* Divi sets heading colour globally; safe to adopt because Divi guarantees
	   it reads against the site background — that is what it is for. */
	--lfvc-heading-color: var(--gcid-heading-color, var(--lfvc-muted));

	/* Layout. */
	--lfvc-gap: 1.25rem;
	--lfvc-radius: 10px;

	/*
	 * Secondary text keeps the FULL inherited colour. Hierarchy comes from
	 * size and weight, not from lightening.
	 *
	 * Fading text toward the background is the usual trick, and it is unsafe
	 * on a theme whose body text already sits near the contrast floor. Divi's
	 * default body colour is #666 on white — 5.74:1, only just over AA.
	 * Fading that to 70% gives 3.04:1; even 85% only reaches 4.12:1. The
	 * lowest fade that stays compliant is 90%, which is not visibly muted at
	 * all. The technique buys nothing and costs legibility on exactly the
	 * themes that can least afford it.
	 *
	 * Soften it deliberately where the theme's body text has headroom:
	 *
	 *   .lfvc-calendar { --lfvc-muted: color-mix(in srgb, currentColor 70%, transparent); }
	 */
	--lfvc-muted: currentColor;

	/* Borders and tag fills are decorative surfaces rather than text, so
	   deriving them by transparency is safe. Plain values first, for browsers
	   without color-mix(). */
	--lfvc-border: #e2e5e9;
	--lfvc-tag-bg: #eef2f5;
	--lfvc-border: color-mix(in srgb, currentColor 16%, transparent);
	--lfvc-tag-bg: color-mix(in srgb, currentColor 7%, transparent);
	--lfvc-border: var(--theme-border-color, color-mix(in srgb, currentColor 16%, transparent));
	--lfvc-tag-bg: color-mix(in srgb, currentColor 7%, transparent);

	/*
	 * Accent — the date and time line.
	 *
	 * Defaults to currentColor, which is readable on any background by
	 * definition; the date is distinguished by weight rather than hue. Set
	 * this to your brand colour to add hue back:
	 *
	 *     .lfvc-calendar { --lfvc-accent: #1f5673; }
	 *
	 * Deliberately NOT taken from a block theme's "accent" preset. In the
	 * stock themes that slug is a decorative tint, not an action colour:
	 * Twenty Twenty-Four's is pale beige #cfcabe, and Twenty Twenty-Five has
	 * no "accent" slug at all (only accent-1..6: yellow, pink, purple).
	 * Pairing those with the theme's base colour measured 1.55:1.
	 */
	--lfvc-accent: currentColor;

	/*
	 * Divi is a classic theme: it publishes no --wp--preset--* variables at
	 * all, only its own global colours. Those are opt-in rather than
	 * automatic, because a brand colour is not guaranteed to meet contrast as
	 * small text — the site's own blue on downinthecounty.com measures 3.33:1.
	 * To adopt Divi's palette, uncomment in your child theme or Divi's custom
	 * CSS box, then check the result:
	 *
	 *     .lfvc-calendar { --lfvc-accent: var(--gcid-primary-color); }
	 *
	 * Divi's global colours are --gcid-primary-color, --gcid-secondary-color,
	 * --gcid-heading-color, and --gcid-body-color.
	 */

	/*
	 * The filter button is a ghost control by default: inherited text on the
	 * page background, which is the one colour pair every theme guarantees is
	 * readable, on light and dark alike.
	 *
	 * Both halves fall back TOGETHER. An earlier version took the background
	 * from one source and the text from another, so a theme publishing
	 * --wp--preset--color--base but not --contrast produced dark-on-dark at
	 * 2.26:1. Sourcing both from the same theme namespace makes the pair
	 * atomic: a theme that publishes one publishes the other.
	 */
	--lfvc-button-bg: var(--theme-button-background-initial-color, transparent);
	--lfvc-button-text: var(--theme-button-text-initial-color, inherit);

	/* Cards sit on the page background by default. */
	--lfvc-card-bg: transparent;

	font-family: var(--lfvc-font);
	color: inherit;
	container-type: inline-size;
}

/* Most themes define .screen-reader-text, but not all do, and a visible
   "Search events" label above the input looks like a bug. Scope our own. */

.lfvc-calendar .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* Filters ---------------------------------------------------------------- */

.lfvc-filters {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;
	margin-bottom: var(--lfvc-gap);
}

.lfvc-filters .lfvc-field { flex: 0 1 auto; margin: 0; }
.lfvc-filters .lfvc-field--search { flex: 1 1 14rem; }

/* Inherit the theme's own form styling where it has any, and only fill in
   what is missing. Themes that style inputs will win on the visual details. */
.lfvc-filters input[type="search"],
.lfvc-filters select {
	width: 100%;
	padding: 0.5rem 0.65rem;
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	background-color: var(--lfvc-card-bg);
	color: inherit;
	font: inherit;
}

.lfvc-submit {
	padding: 0.5rem 1rem;
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	background-color: var(--lfvc-button-bg);
	color: var(--lfvc-button-text);
	font-weight: 600;
	font: inherit;
	line-height: 1.3;
	cursor: pointer;
}

.lfvc-clear {
	color: var(--lfvc-muted);
	font-size: 0.9em;
}

/* Layout ----------------------------------------------------------------- */

.lfvc-day-heading {
	margin: 1.5rem 0 0.5rem;
	padding-bottom: 0.35rem;
	border-bottom: 1px solid var(--lfvc-border);
	font-family: var(--lfvc-heading-font);
	font-size: 0.95em;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	color: var(--lfvc-heading-color);
}

.lfvc-day-heading:first-child { margin-top: 0; }

.lfvc-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
	gap: var(--lfvc-gap);
	/* Size each card to its own content. Stretching them to match the tallest
	   in the row leaves a large void under the ones without a photo, and
	   whether an event has a photo varies row by row. */
	align-items: start;
}

/* Day headings must span the full grid row. */
.lfvc-grid .lfvc-day-heading { grid-column: 1 / -1; }

.lfvc-list .lfvc-event + .lfvc-event { margin-top: 0.75rem; }

/* Card ------------------------------------------------------------------- */

.lfvc-event {
	display: flex;
	gap: 1rem;
	padding: 1rem;
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	background-color: var(--lfvc-card-bg);
}

.lfvc-grid .lfvc-event { flex-direction: column; gap: 0.75rem; }

/*
 * Images are shown whole, never cropped.
 *
 * Community event imagery is very often a flyer rather than a photograph, and
 * a flyer carries its information as text inside the image. Cropping one to a
 * uniform tile cuts off the date, the price, or the venue — exactly the parts
 * a reader needs. So the default is to letterbox rather than crop: rows are
 * slightly less uniform, and nothing is destroyed.
 *
 * To trade that back for uniform tiles, set the two tokens:
 *
 *     .lfvc-calendar { --lfvc-image-fit: cover; --lfvc-image-height: 10rem; }
 */

.lfvc-calendar {
	--lfvc-image-fit: contain;
	--lfvc-image-height: auto;
	--lfvc-image-max-height: 11rem;
}

.lfvc-event__media {
	flex: 0 0 7rem;
	display: block;
	overflow: hidden;
	border-radius: calc(var(--lfvc-radius) - 3px);
	align-self: flex-start;
}

.lfvc-grid .lfvc-event__media {
	flex: 0 0 auto;
	width: 100%;
}

.lfvc-event__media img {
	display: block;
	width: 100%;
	height: var(--lfvc-image-height);
	max-height: var(--lfvc-image-max-height);
	object-fit: var(--lfvc-image-fit);
}

.lfvc-event__body { flex: 1 1 auto; min-width: 0; }

.lfvc-event__when {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
	font-size: 0.85em;
	font-weight: 600;
	color: var(--lfvc-accent);
}

/* Grouped lists hide the per-card date; don't leave its gap behind. */
.lfvc-event__when time:empty { display: none; }

.lfvc-event__time { color: var(--lfvc-muted); font-weight: 400; }

.lfvc-event__title {
	margin: 0.2rem 0 0.35rem;
	font-family: var(--lfvc-heading-font);
	font-size: 1.1em;
	line-height: 1.3;
}

.lfvc-event__title a { color: inherit; text-decoration: none; }
.lfvc-event__title a:hover,
.lfvc-event__title a:focus-visible { text-decoration: underline; }

.lfvc-event__where,
.lfvc-event__excerpt {
	margin: 0 0 0.4rem;
	font-size: 0.9em;
	color: var(--lfvc-muted);
}

.lfvc-event__where { font-weight: 500; }

.lfvc-event__meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.35rem;
	align-items: center;
}

.lfvc-tag,
.lfvc-price {
	padding: 0.15rem 0.5rem;
	border-radius: 999px;
	background-color: var(--lfvc-tag-bg);
	font-size: 0.78em;
	color: var(--lfvc-muted);
}

.lfvc-price { font-weight: 600; color: inherit; }

/* Only ever seen by logged-in editors trying the calendar out. Deliberately
   loud: it must be impossible to mistake a sample for a real event. */
.lfvc-tag--sample {
	background-color: #fff4d6;
	color: #6b4d00;
	font-weight: 700;
	letter-spacing: 0.02em;
	text-transform: uppercase;
}

/* Pagination and empty state --------------------------------------------- */

.lfvc-pagination {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 1rem;
	margin-top: var(--lfvc-gap);
	padding-top: 0.75rem;
	border-top: 1px solid var(--lfvc-border);
	font-size: 0.92em;
}

.lfvc-page-count { color: var(--lfvc-muted); }

.lfvc-empty {
	padding: 2rem 1rem;
	border: 1px dashed var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	text-align: center;
	color: var(--lfvc-muted);
}

/* Cards reflow on the width of their own column, not the viewport, so the
   calendar behaves correctly inside a narrow sidebar or a wide full-width
   block alike. */
@container (max-width: 30rem) {
	.lfvc-event { flex-direction: column; }
	.lfvc-event__media { flex: 0 0 auto; }
	.lfvc-pagination { flex-direction: column; }
}

/* Respect a reader's motion preference for any theme-added transitions. */
@media (prefers-reduced-motion: reduce) {
	.lfvc-calendar * { transition: none !important; animation: none !important; }
}

/* ---------------------------------------------------------------------------
   Reader submission form
   ---------------------------------------------------------------------------
   Same tokens as the calendar, so it inherits the site design too. Built for
   a phone first: one column, 16px inputs (anything smaller makes iOS zoom on
   focus), and touch targets around 44px.
*/

.lfvc-submit-form {
	--lfvc-field-gap: 1rem;
	max-width: 40rem;
	display: flex;
	flex-direction: column;
	gap: var(--lfvc-field-gap);
	font-family: var(--lfvc-font);
	container-type: inline-size;
}

.lfvc-submit-form__intro { margin: 0; font-size: 0.95em; }

.lfvc-submit-form__error {
	margin: 0;
	padding: 0.75rem 1rem;
	border: 1px solid currentColor;
	border-left-width: 4px;
	border-radius: var(--lfvc-radius);
	color: #b4451f;
	font-weight: 600;
}

.lfvc-field { display: flex; flex-direction: column; gap: 0.3rem; }

.lfvc-field label { font-weight: 600; font-size: 0.95em; }

.lfvc-req { color: #b4451f; }

.lfvc-submit-form input[type="text"],
.lfvc-submit-form input[type="url"],
.lfvc-submit-form input[type="email"],
.lfvc-submit-form input[type="date"],
.lfvc-submit-form input[type="time"],
.lfvc-submit-form input[type="file"],
.lfvc-submit-form select,
.lfvc-submit-form textarea {
	width: 100%;
	/* 16px exactly: iOS Safari zooms the page on focus below this. */
	font-size: 16px;
	font-family: inherit;
	line-height: 1.4;
	padding: 0.65rem 0.7rem;
	min-height: 44px;
	color: inherit;
	background-color: var(--lfvc-card-bg);
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
}

.lfvc-submit-form textarea { min-height: 6rem; resize: vertical; }

.lfvc-submit-form :is(input, select, textarea):focus-visible {
	outline: 2px solid var(--lfvc-accent);
	outline-offset: 1px;
}

.lfvc-hint { font-size: 0.85em; opacity: 0.75; }
.lfvc-hint--block { margin: 0; }

.lfvc-row {
	display: grid;
	gap: var(--lfvc-field-gap);
	grid-template-columns: 1fr;
}

/* Side by side only when the column is genuinely wide enough. */
@container (min-width: 30rem) {
	.lfvc-row { grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
}

.lfvc-more {
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	padding: 0.75rem 1rem;
}

.lfvc-more summary {
	cursor: pointer;
	font-weight: 600;
	font-size: 0.95em;
	min-height: 44px;
	display: flex;
	align-items: center;
}

.lfvc-more[open] summary { margin-bottom: var(--lfvc-field-gap); }

.lfvc-more > *:not(summary) { margin-bottom: var(--lfvc-field-gap); }
.lfvc-more > *:last-child { margin-bottom: 0; }

.lfvc-you {
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	padding: 0.75rem 1rem 1rem;
	margin: 0;
	display: flex;
	flex-direction: column;
	gap: var(--lfvc-field-gap);
}

.lfvc-you legend { font-weight: 600; font-size: 0.95em; padding: 0 0.35rem; }

.lfvc-submit-form__button {
	align-self: start;
	min-height: 48px;
	padding: 0.7rem 1.5rem;
	font: inherit;
	font-weight: 700;
	font-size: 1.02em;
	color: var(--lfvc-button-text);
	background-color: var(--lfvc-button-bg);
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	cursor: pointer;
}

/* The honeypot. Off-screen rather than display:none, which some bots detect
   and skip; aria-hidden on the wrapper keeps it from screen readers. */
.lfvc-hp {
	position: absolute !important;
	left: -9999px !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
}

.lfvc-submit-form--done {
	padding: 1.25rem 1.5rem;
	border: 1px solid var(--lfvc-border);
	border-left: 4px solid var(--lfvc-accent);
	border-radius: var(--lfvc-radius);
}

.lfvc-submit-form--done h3 { margin: 0 0 0.4rem; font-family: var(--lfvc-heading-font); }
.lfvc-submit-form--done p { margin: 0 0 0.5rem; }
.lfvc-submit-form--done p:last-child { margin-bottom: 0; }

/* Paste-the-details box.
   Delivered hidden and revealed by submit.js, so it never appears without
   the script that makes it work. */

.lfvc-paste {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	padding: 1rem;
	border: 1px dashed var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	background-color: var(--lfvc-tag-bg);
}

.lfvc-paste__label { font-weight: 600; font-size: 0.95em; }

.lfvc-paste__text {
	width: 100%;
	min-height: 5.5rem;
	font-size: 16px;
	font-family: inherit;
	line-height: 1.4;
	padding: 0.65rem 0.7rem;
	color: inherit;
	background-color: var(--lfvc-card-bg);
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	resize: vertical;
}

.lfvc-paste__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.6rem;
}

.lfvc-paste__go {
	min-height: 44px;
	padding: 0.6rem 1.1rem;
	font: inherit;
	font-weight: 600;
	color: var(--lfvc-button-text);
	background-color: var(--lfvc-button-bg);
	border: 1px solid var(--lfvc-border);
	border-radius: var(--lfvc-radius);
	cursor: pointer;
}

.lfvc-paste__go[disabled] { opacity: 0.6; cursor: progress; }

.lfvc-paste__status { font-size: 0.9em; }
.lfvc-paste__status.is-error { color: #b4451f; font-weight: 600; }
.lfvc-paste__status.is-ok { font-weight: 600; }

.lfvc-paste__or {
	margin: 0;
	text-align: center;
	font-size: 0.9em;
	opacity: 0.7;
}

/* A field the paste filled in, so it is obvious what to check. Fades out,
   because after a few seconds it has done its job. */
.lfvc-filled {
	animation: lfvc-filled-fade 6s ease-out forwards;
}

@keyframes lfvc-filled-fade {
	0%, 40% { background-color: color-mix( in srgb, var(--lfvc-accent) 14%, transparent ); }
	100%    { background-color: var(--lfvc-card-bg); }
}

@media (prefers-reduced-motion: reduce) {
	.lfvc-filled { animation: none; }
}
