/**
 * Restaurant Proximity Picker — card grid for the locations checkbox field.
 *
 * Add the CSS class `rpp-grid` to the Checkboxes field under
 * Appearance > Custom CSS Class in the Gravity Forms field editor.
 * Nothing here applies until you do, so this file is safe to load globally.
 *
 * Written against Gravity Forms 2.5+ markup (div.gchoice) with a fallback for
 * the older li.gchoice markup.
 */

.rpp-grid .gfield_checkbox {
	display: grid;
	grid-template-columns: repeat( auto-fill, minmax( 240px, 1fr ) );
	gap: 12px;
	margin: 0;
	padding: 0;
	list-style: none;
}

.rpp-grid .gfield_checkbox .gchoice {
	margin: 0;
	padding: 0;
	list-style: none;
	position: relative;
}

/* Keep the real checkbox reachable by keyboard and screen readers, but out of
   sight — the card is the visible control. Never display:none this. */
.rpp-grid .gfield_checkbox .gchoice input[type="checkbox"] {
	position: absolute;
	width: 1px;
	height: 1px;
	margin: 0;
	padding: 0;
	overflow: hidden;
	clip: rect( 0 0 0 0 );
	clip-path: inset( 50% );
	white-space: nowrap;
	border: 0;
}

.rpp-grid .gfield_checkbox .gchoice label {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	min-height: 100%;
	box-sizing: border-box;
	margin: 0;
	padding: 16px 16px 16px 44px;
	position: relative;

	border: 1px solid #d8d8d8;
	border-radius: 8px;
	background: #fff;

	font-weight: 500;
	line-height: 1.4;
	cursor: pointer;

	transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

/* The tick box we draw ourselves. */
.rpp-grid .gfield_checkbox .gchoice label::before {
	content: "";
	position: absolute;
	left: 14px;
	top: 16px;
	width: 18px;
	height: 18px;
	border: 2px solid #c4c4c4;
	border-radius: 4px;
	background: #fff;
	transition: border-color 0.15s ease, background-color 0.15s ease;
}

/* The checkmark, hidden until selected. */
.rpp-grid .gfield_checkbox .gchoice label::after {
	content: "";
	position: absolute;
	left: 19px;
	top: 20px;
	width: 7px;
	height: 12px;
	border: solid #fff;
	border-width: 0 2px 2px 0;
	transform: rotate( 45deg ) scale( 0.6 );
	opacity: 0;
	transition: opacity 0.12s ease, transform 0.12s ease;
}

.rpp-grid .gfield_checkbox .gchoice label:hover {
	border-color: #9a9a9a;
}

.rpp-grid .gfield_checkbox .gchoice input[type="checkbox"]:focus-visible + label {
	outline: 2px solid #1d68d6;
	outline-offset: 2px;
}

/* Older browsers without :focus-visible support. */
.rpp-grid .gfield_checkbox .gchoice input[type="checkbox"]:focus + label {
	box-shadow: 0 0 0 3px rgba( 29, 104, 214, 0.25 );
}

.rpp-grid .gfield_checkbox .gchoice input[type="checkbox"]:checked + label {
	border-color: #1d68d6;
	background: #f2f7ff;
	box-shadow: 0 0 0 1px #1d68d6;
}

.rpp-grid .gfield_checkbox .gchoice input[type="checkbox"]:checked + label::before {
	border-color: #1d68d6;
	background: #1d68d6;
}

.rpp-grid .gfield_checkbox .gchoice input[type="checkbox"]:checked + label::after {
	opacity: 1;
	transform: rotate( 45deg ) scale( 1 );
}

/* Long restaurant names and addresses wrap rather than overflow the card. */
.rpp-grid .gfield_checkbox .gchoice label,
.rpp-grid .gfield_checkbox .gchoice label * {
	overflow-wrap: anywhere;
}

/* -------------------------------------------------------------------------
   Card contents: brand, location name, address, distance.

   Everything below sits inside the <label>, built by rpp_choice_inner_html().
   Spans are used rather than divs (block elements inside a label are asking
   for trouble), so each one needs display:block here.
   ------------------------------------------------------------------------- */

.rpp-grid .rpp-card {
	display: block;
	width: 100%;
}

.rpp-grid .rpp-brand {
	display: block;
	font-weight: 700;
	font-size: 1em;
	line-height: 1.25;
	letter-spacing: 0.01em;
	color: inherit;
}

.rpp-grid .rpp-name {
	display: block;
	margin-top: 2px;
	font-weight: 500;
	font-size: 0.95em;
	line-height: 1.3;
	color: inherit;
}

.rpp-grid .rpp-address {
	display: block;
	margin-top: 6px;
	font-weight: 400;
	font-size: 0.875em;
	line-height: 1.4;
	color: #5c5c5c;
}

.rpp-grid .rpp-distance {
	display: block;
	margin-top: 8px;
	font-weight: 600;
	font-size: 0.8125em;
	line-height: 1;
	color: #6b6b6b;
	font-variant-numeric: tabular-nums;
}

.rpp-grid .gchoice input[type="checkbox"]:checked + label .rpp-address,
.rpp-grid .gchoice input[type="checkbox"]:checked + label .rpp-distance {
	color: #3a5f93;
}

/* -------------------------------------------------------------------------
   Per-brand styling.

   Each card and each choice wrapper carries the brand's term slug as a class,
   plus an rpp-brand-- prefixed twin. So for a brand named "Red Robin":

       .rpp-grid .red-robin { ... }
       .rpp-grid .rpp-brand--red-robin { ... }

   Use the prefixed version if a bare slug collides with something in your
   theme. Both are always present.

   Examples — uncomment and edit, or put your own in the theme stylesheet:

   .rpp-grid .gchoice.red-robin label { border-left: 4px solid #c8102e; }
   .rpp-grid .red-robin .rpp-brand    { color: #c8102e; }

   .rpp-grid .gchoice.taco-cabana label { border-left: 4px solid #e4002b; }
   .rpp-grid .taco-cabana .rpp-brand    { color: #e4002b; }

   A selected card keeps the shared blue treatment unless you override it:

   .rpp-grid .gchoice.red-robin input:checked + label {
       border-color: #c8102e;
       background: #fdf3f4;
       box-shadow: 0 0 0 1px #c8102e;
   }
   ------------------------------------------------------------------------- */

/* Single column on narrow screens — a two-up grid of address cards on a phone
   is unreadable. */
@media ( max-width: 480px ) {
	.rpp-grid .gfield_checkbox {
		grid-template-columns: 1fr;
	}
}

/* -------------------------------------------------------------------------
   Empty state.

   Gravity Forms renders one blank checkbox when a Checkboxes field has no
   choices. Before a ZIP is entered that reads as a stray option, so the whole
   list is hidden and only the description message shows.
   ------------------------------------------------------------------------- */

.rpp-grid.rpp-no-results .gfield_checkbox {
	display: none;
}

.rpp-grid .gchoice.rpp-blank-choice {
	display: none;
}

.rpp-grid.rpp-no-results .gfield_description,
.rpp-grid .rpp-description {
	margin-top: 4px;
}

/* -------------------------------------------------------------------------
   Search icon / spinner in the ZIP field.
   ------------------------------------------------------------------------- */

.rpp-zip-container {
	position: relative;
	display: block;
}

.rpp-zip-container input[type="text"],
.rpp-zip-container input[type="number"],
.rpp-zip-container input[type="search"] {
	/* Room for the icon. Gravity Forms inputs are full width already. */
	padding-right: 40px !important;
}

.rpp-search-state {
	position: absolute;
	top: 50%;
	right: 12px;
	transform: translateY( -50% );
	width: 20px;
	height: 20px;
	display: flex;
	align-items: center;
	justify-content: center;
	color: #8a8a8a;
	pointer-events: none;
	transition: color 0.15s ease;
}

.rpp-search-state svg {
	width: 20px;
	height: 20px;
	display: block;
}

.rpp-search-state.is-loading {
	color: #1d68d6;
}

.rpp-search-state .rpp-spin {
	animation: rpp-spin 0.7s linear infinite;
	transform-origin: 50% 50%;
}

@keyframes rpp-spin {
	to {
		transform: rotate( 360deg );
	}
}

@media ( prefers-reduced-motion: reduce ) {
	.rpp-search-state .rpp-spin {
		animation-duration: 2s;
	}
}

/* While GPPA is fetching new choices it adds this class; fade rather than
   flicker so the grid doesn't jump as the applicant types. */
.rpp-grid.gppa-loading .gfield_checkbox,
.rpp-grid .gfield_checkbox.gppa-loading {
	opacity: 0.5;
	transition: opacity 0.15s ease;
	pointer-events: none;
}

@media ( prefers-reduced-motion: reduce ) {
	.rpp-grid .gfield_checkbox .gchoice label,
	.rpp-grid .gfield_checkbox .gchoice label::before,
	.rpp-grid .gfield_checkbox .gchoice label::after {
		transition: none;
	}
}
