/* =====================================================================
   RM Forms — Repeatable Field Groups.

   One stylesheet for the live form. Everything is namespaced under
   .rm-rep-* and driven by custom properties, so a form's theme colour can
   flow in from the form renderer without this file knowing anything about
   a particular form.

   Touch targets are 44px minimum, focus is always visible, and the layout
   collapses to a single column below 640px — a conference attendee adding
   their fourth co-author on a phone is the primary case, not the edge one.
===================================================================== */

.rm-rep {
	--rm-rep-accent: #6366f1;
	--rm-rep-border: #e2e8f0;
	--rm-rep-bg: #f8fafc;
	--rm-rep-text: #1e293b;
	--rm-rep-muted: #64748b;
	--rm-rep-danger: #dc2626;
	--rm-rep-radius: 12px;

	display: block;
}

/* ---------- Group header ---------- */

.rm-rep-group-title {
	display: block;
	font-weight: 600;
	font-size: 14px;
	margin-bottom: 6px;
	color: #334155;
}

.rm-rep-group-help {
	margin: 0 0 10px;
	font-size: 12px;
	color: var(--rm-rep-muted);
	line-height: 1.5;
}

/* ---------- Entry list ---------- */

.rm-rep-list {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.rm-rep-entry {
	border: 1px solid var(--rm-rep-border);
	border-radius: var(--rm-rep-radius);
	background: var(--rm-rep-bg);
	overflow: hidden;
	/* Only the properties that actually change are transitioned — animating
	   `all` here would also animate the child inputs' focus rings. */
	transition: opacity .16s ease, transform .16s ease, box-shadow .16s ease;
}

.rm-rep-entry:focus-within {
	border-color: var(--rm-rep-accent);
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--rm-rep-accent) 14%, transparent);
}

/* Entering / leaving. Both are opt-in classes rather than CSS animations on
   the element itself, so a row that is simply re-rendered doesn't flicker. */
@keyframes rm-rep-in {
	from { opacity: 0; transform: translateY(-6px); }
	to   { opacity: 1; transform: none; }
}

.rm-rep-entry {
	animation: rm-rep-in .18s ease both;
}

.rm-rep-entry.rm-rep-leaving {
	opacity: 0;
	transform: translateY(-6px);
	pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
	.rm-rep-entry,
	.rm-rep-entry.rm-rep-leaving {
		animation: none;
		transition: none;
		transform: none;
	}
}

/* ---------- Entry header ---------- */

.rm-rep-entry-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 10px 14px;
	background: #fff;
	border-bottom: 1px solid var(--rm-rep-border);
}

.rm-rep-entry-title {
	font-size: 13px;
	font-weight: 700;
	color: var(--rm-rep-text);
	letter-spacing: .01em;
}

.rm-rep-entry-num {
	display: inline-block;
	min-width: 20px;
	padding: 1px 7px;
	margin-left: 2px;
	border-radius: 999px;
	background: color-mix(in srgb, var(--rm-rep-accent) 12%, #fff);
	color: var(--rm-rep-accent);
	font-size: 12px;
	font-weight: 700;
	text-align: center;
}

.rm-rep-remove {
	appearance: none;
	border: 1px solid #fecaca;
	background: #fff;
	color: var(--rm-rep-danger);
	font-size: 13px;
	font-weight: 600;
	padding: 8px 12px;
	min-height: 36px;
	border-radius: 8px;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}

.rm-rep-remove:hover:not(:disabled) {
	background: #fef2f2;
	border-color: #fca5a5;
}

.rm-rep-remove:disabled {
	opacity: .4;
	cursor: not-allowed;
}

/* ---------- Entry body ---------- */

.rm-rep-entry-body {
	display: grid;
	grid-template-columns: repeat(6, 1fr);
	gap: 14px;
	padding: 16px 14px;
}

.rm-rep-cell        { grid-column: span 6; min-width: 0; }
.rm-rep-w-full      { grid-column: span 6; }
.rm-rep-w-half      { grid-column: span 3; }
.rm-rep-w-third     { grid-column: span 2; }

.rm-rep-label {
	display: block;
	font-weight: 600;
	font-size: 13px;
	margin-bottom: 6px;
	color: #334155;
}

.rm-rep-req { color: #ef4444; }

.rm-rep-help {
	margin: 4px 0 0;
	font-size: 12px;
	color: var(--rm-rep-muted);
	line-height: 1.45;
}

/* Every control inside a row gets a comfortable touch target and a focus
   ring that does not depend on the theme's own input styling being present. */
.rm-rep-cell input[type="text"],
.rm-rep-cell input[type="email"],
.rm-rep-cell input[type="tel"],
.rm-rep-cell input[type="number"],
.rm-rep-cell input[type="date"],
.rm-rep-cell select,
.rm-rep-cell textarea {
	min-height: 44px;
	font-family: inherit;
	max-width: 100%;
}

.rm-rep-cell input:focus,
.rm-rep-cell select:focus,
.rm-rep-cell textarea:focus {
	outline: none;
	border-color: var(--rm-rep-accent) !important;
	box-shadow: 0 0 0 3px color-mix(in srgb, var(--rm-rep-accent) 18%, transparent);
}

/* ---------- Choice groups ---------- */

.rm-rep-choices {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.rm-rep-choice {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 9px 12px;
	min-height: 44px;
	background: #fff;
	border: 1px solid #cbd5e1;
	border-radius: 8px;
	font-size: 14px;
	color: var(--rm-rep-text);
	cursor: pointer;
	transition: border-color .15s ease, background .15s ease;
}

.rm-rep-choice:hover { border-color: var(--rm-rep-accent); }

.rm-rep-choice input {
	width: 17px;
	height: 17px;
	margin: 0;
	accent-color: var(--rm-rep-accent);
	flex: none;
}

.rm-rep-choice:has(input:checked) {
	border-color: var(--rm-rep-accent);
	background: color-mix(in srgb, var(--rm-rep-accent) 8%, #fff);
}

/* ---------- Validation ---------- */

.rm-rep-error {
	margin: 5px 0 0;
	font-size: 12px;
	font-weight: 600;
	color: var(--rm-rep-danger);
	line-height: 1.4;
}

.rm-rep-invalid input,
.rm-rep-invalid select,
.rm-rep-invalid textarea {
	border-color: var(--rm-rep-danger) !important;
	background: #fff5f5;
}

.rm-rep-invalid .rm-rep-choices {
	padding: 6px;
	border: 1px dashed var(--rm-rep-danger);
	border-radius: 8px;
}

.rm-rep-notice {
	margin: 10px 0 0;
	padding: 9px 12px;
	border-radius: 8px;
	background: #fffbeb;
	border: 1px solid #fde68a;
	color: #92400e;
	font-size: 13px;
	font-weight: 600;
}

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

.rm-rep-add {
	appearance: none;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	margin-top: 12px;
	padding: 11px 18px;
	min-height: 44px;
	width: 100%;
	border: 1px dashed var(--rm-rep-accent);
	border-radius: 10px;
	background: color-mix(in srgb, var(--rm-rep-accent) 6%, #fff);
	color: var(--rm-rep-accent);
	font-size: 14px;
	font-weight: 700;
	font-family: inherit;
	cursor: pointer;
	transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}

.rm-rep-add:hover:not(:disabled) {
	background: color-mix(in srgb, var(--rm-rep-accent) 12%, #fff);
	border-style: solid;
}

.rm-rep-add:focus-visible {
	outline: 3px solid color-mix(in srgb, var(--rm-rep-accent) 40%, transparent);
	outline-offset: 2px;
}

.rm-rep-add:disabled {
	opacity: .45;
	cursor: not-allowed;
	border-style: dotted;
}

@media (min-width: 641px) {
	.rm-rep-add { width: auto; }
}

/* ---------- Mobile ---------- */

@media (max-width: 640px) {
	.rm-rep-entry-body {
		grid-template-columns: 1fr;
		padding: 14px 12px;
		gap: 12px;
	}

	.rm-rep-cell,
	.rm-rep-w-full,
	.rm-rep-w-half,
	.rm-rep-w-third {
		grid-column: 1 / -1;
	}

	.rm-rep-entry-head {
		padding: 10px 12px;
	}

	.rm-rep-choice {
		width: 100%;
	}
}

/* ---------- Fallback for browsers without color-mix() ----------
   Safari < 16.2 and older Chromium simply drop the declarations above that
   use color-mix(); these plain values keep the component legible there
   instead of leaving it transparent. Declared AFTER so modern browsers
   that DO support color-mix() have already applied the tinted versions —
   @supports not is what prevents this block from overriding them. */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
	.rm-rep-entry-num { background: #eef2ff; }
	.rm-rep-add       { background: #f5f6ff; }
	.rm-rep-add:hover:not(:disabled) { background: #eef0ff; }
	.rm-rep-choice:has(input:checked) { background: #f5f6ff; }
	.rm-rep-entry:focus-within { box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
	.rm-rep-cell input:focus,
	.rm-rep-cell select:focus,
	.rm-rep-cell textarea:focus { box-shadow: 0 0 0 3px rgba(99, 102, 241, .18); }
}
