/* QCS Form — frontend styles.
 *
 * Design goals:
 *   1. Look polished out-of-the-box on any WordPress theme (light or dark).
 *   2. Stay self-scoped — every selector is prefixed with .qcs-form so we don't
 *      bleed into host-theme typography or accidentally inherit unwanted styles.
 *   3. Theme-able via CSS custom properties — site owners override --qcs-* vars
 *      from their child theme without forking this file.
 *
 * Override examples (drop into theme stylesheet):
 *   .qcs-form { --qcs-brand: #16a34a; --qcs-radius: 12px; }
 *   body.dark-theme .qcs-form { --qcs-bg-field: #1f2937; --qcs-text: #f9fafb; }
 */

.qcs-form {
	/* ------- Theme tokens ------- */
	--qcs-brand:        #4A76F1;
	--qcs-brand-hover:  #3d66d9;
	--qcs-brand-soft:   rgba(74, 118, 241, 0.12);
	--qcs-text:         #111827;
	--qcs-text-muted:   #6b7280;
	--qcs-text-label:   #374151;
	--qcs-border:       #d1d5db;
	--qcs-border-hover: #9ca3af;
	--qcs-border-focus: #4A76F1;
	--qcs-bg-field:     #ffffff;
	--qcs-bg-card:      #ffffff;
	--qcs-error:        #dc2626;
	--qcs-error-soft:   #fef2f2;
	--qcs-success:      #15803d;
	--qcs-success-soft: #f0fdf4;
	--qcs-radius:       10px;
	--qcs-radius-sm:    6px;
	--qcs-shadow:       0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
	--qcs-shadow-focus: 0 0 0 3px var(--qcs-brand-soft);
	--qcs-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	--qcs-gap:          18px;
	--qcs-pad-field:    11px 14px;
	--qcs-fs-base:      15px;
	--qcs-fs-label:     14px;
	--qcs-fs-help:      13px;

	/* ------- Layout ------- */
	display: flex;
	flex-direction: column;
	gap: var(--qcs-gap);
	max-width: 640px;
	width: 100%;
	margin: 0 auto;
	font-family: var(--qcs-font);
	font-size: var(--qcs-fs-base);
	line-height: 1.5;
	color: var(--qcs-text);
	box-sizing: border-box;
}
.qcs-form *,
.qcs-form *::before,
.qcs-form *::after {
	box-sizing: inherit;
}

/* Optional card wrapper — wrap the form in <div class="qcs-form-card"> ... </div>
 * for a contained look with shadow. Off by default. */
.qcs-form-card {
	padding: clamp(20px, 4vw, 36px);
	background: var(--qcs-bg-card, #fff);
	border: 1px solid var(--qcs-border, #e5e7eb);
	border-radius: calc(var(--qcs-radius) + 4px);
	box-shadow: var(--qcs-shadow);
}

/* ------------------------------------------------------------------ */
/* Fields                                                             */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.qcs-form .qcs-field label {
	font-weight: 600;
	font-size: var(--qcs-fs-label);
	color: var(--qcs-text-label);
	letter-spacing: -0.005em;
}

.qcs-form .qcs-required {
	color: var(--qcs-error);
	margin-left: 3px;
	font-weight: 600;
}

/* All inputs share the same look. */
.qcs-form input[type="text"],
.qcs-form input[type="email"],
.qcs-form input[type="tel"],
.qcs-form input[type="number"],
.qcs-form input[type="url"],
.qcs-form input[type="date"],
.qcs-form input[type="time"],
.qcs-form select,
.qcs-form textarea {
	appearance: none;
	-webkit-appearance: none;
	width: 100%;
	padding: var(--qcs-pad-field);
	border: 1px solid var(--qcs-border);
	border-radius: var(--qcs-radius);
	background: var(--qcs-bg-field);
	color: var(--qcs-text);
	font-family: inherit;
	font-size: var(--qcs-fs-base);
	line-height: 1.4;
	transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.qcs-form input::placeholder,
.qcs-form textarea::placeholder {
	color: var(--qcs-text-muted);
	opacity: 1;
}

.qcs-form input:hover:not(:focus):not(:disabled),
.qcs-form select:hover:not(:focus):not(:disabled),
.qcs-form textarea:hover:not(:focus):not(:disabled) {
	border-color: var(--qcs-border-hover);
}

.qcs-form input:focus,
.qcs-form select:focus,
.qcs-form textarea:focus {
	outline: none;
	border-color: var(--qcs-border-focus);
	box-shadow: var(--qcs-shadow-focus);
}

.qcs-form textarea {
	min-height: 140px;
	resize: vertical;
}

/* Native <select> looks awful by default — give it a custom caret. */
.qcs-form select {
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1.5L6 6.5L11 1.5' stroke='%236b7280' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
	background-repeat: no-repeat;
	background-position: right 14px center;
	background-size: 12px 8px;
	padding-right: 38px;
}

/* Checkbox: align nicely with label text. */
.qcs-form .qcs-field-checkbox {
	flex-direction: row;
	align-items: flex-start;
	gap: 10px;
}
.qcs-form .qcs-field-checkbox label {
	order: 2;
	font-weight: 500;
	color: var(--qcs-text);
	cursor: pointer;
	line-height: 1.4;
}
.qcs-form .qcs-field-checkbox input[type="checkbox"] {
	order: 1;
	width: 18px;
	height: 18px;
	margin-top: 2px;
	accent-color: var(--qcs-brand);
	flex-shrink: 0;
}

/* Multi-column rows: adjacent .qcs-field elements wrapped in .qcs-row sit
 * side-by-side. v1.16.0 introduces explicit per-field width (data-width=half|third).
 *
 * - .qcs-row-half  → up to 2 children in a row
 * - .qcs-row-third → up to 3 children in a row
 *
 * Older auto-pair rows (no -half/-third modifier) keep the legacy 1fr 1fr grid
 * so any 1.15.x-era data still renders the same on this template.
 */
.qcs-form .qcs-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 14px;
}
.qcs-form .qcs-row-half  { grid-template-columns: 1fr 1fr; }
.qcs-form .qcs-row-third { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 520px) {
	.qcs-form .qcs-row,
	.qcs-form .qcs-row-half,
	.qcs-form .qcs-row-third { grid-template-columns: 1fr; }
}

/* Per-field width modifiers. Applied to the field wrapper itself so an
 * isolated half/third field (not inside a row) still occupies the right
 * fraction of the form. */
.qcs-form > .qcs-field.qcs-w-half  { max-width: calc(50% - 0.5rem); }
.qcs-form > .qcs-field.qcs-w-third { max-width: calc(33.333% - 0.5rem); }
@media (max-width: 520px) {
	.qcs-form > .qcs-field.qcs-w-half,
	.qcs-form > .qcs-field.qcs-w-third { max-width: 100%; }
}

/* When a field's data-qcs-cond hides it via [hidden], collapse it out of layout. */
.qcs-form .qcs-field[hidden] { display: none !important; }

/* ------------------------------------------------------------------ */
/* Inline field errors                                                */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-field-error {
	display: none;
	font-size: var(--qcs-fs-help);
	color: var(--qcs-error);
	margin-top: 2px;
}
.qcs-form .qcs-field.qcs-invalid .qcs-field-error {
	display: block;
}
.qcs-form .qcs-field.qcs-invalid input,
.qcs-form .qcs-field.qcs-invalid select,
.qcs-form .qcs-field.qcs-invalid textarea {
	border-color: var(--qcs-error);
	background: var(--qcs-error-soft);
}
.qcs-form .qcs-field.qcs-invalid input:focus,
.qcs-form .qcs-field.qcs-invalid select:focus,
.qcs-form .qcs-field.qcs-invalid textarea:focus {
	box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14);
}

/* ------------------------------------------------------------------ */
/* Submit                                                             */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-submit-row {
	display: flex;
	align-items: center;
	gap: 14px;
	margin-top: 4px;
}

/* Per-form Submit alignment classes (set from the Design meta box). */
.qcs-form .qcs-submit-row.qcs-align-center { justify-content: center; }
.qcs-form .qcs-submit-row.qcs-align-right  { justify-content: flex-end; }
.qcs-form .qcs-submit-row.qcs-align-block .qcs-submit { flex: 1 1 100%; }

.qcs-form .qcs-submit {
	position: relative;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	padding: 12px 24px;
	border: 0;
	border-radius: var(--qcs-radius);
	background: var(--qcs-brand);
	color: #fff;
	font-family: inherit;
	font-size: var(--qcs-fs-base);
	font-weight: 600;
	letter-spacing: 0.005em;
	cursor: pointer;
	transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
	min-width: 140px;
}
.qcs-form .qcs-submit:hover:not(:disabled) {
	background: var(--qcs-brand-hover);
}
.qcs-form .qcs-submit:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px var(--qcs-brand-soft);
}
.qcs-form .qcs-submit:active:not(:disabled) {
	transform: translateY(1px);
}
.qcs-form .qcs-submit:disabled {
	opacity: 0.65;
	cursor: not-allowed;
}

/* Spinner — pure CSS, no extra HTTP requests. Shown while .is-loading. */
.qcs-form .qcs-submit .qcs-spinner {
	display: none;
	width: 16px;
	height: 16px;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-top-color: #fff;
	border-radius: 50%;
	animation: qcs-spin 0.6s linear infinite;
}
.qcs-form .qcs-submit.is-loading .qcs-spinner {
	display: inline-block;
}
.qcs-form .qcs-submit.is-loading .qcs-submit-label {
	opacity: 0.85;
}
@keyframes qcs-spin {
	to { transform: rotate(360deg); }
}

/* ------------------------------------------------------------------ */
/* Status / Success                                                   */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-status {
	min-height: 1.2em;
	font-size: var(--qcs-fs-help);
	margin: 0;
}
.qcs-form .qcs-status.qcs-ok  { color: var(--qcs-success); }
.qcs-form .qcs-status.qcs-err { color: var(--qcs-error); }

/* Success message that replaces the form after submit. */
.qcs-success {
	max-width: 640px;
	width: 100%;
	margin: 0 auto;
	padding: 20px 22px;
	background: var(--qcs-success-soft, #f0fdf4);
	border: 1px solid #bbf7d0;
	border-radius: 12px;
	color: #14532d;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	display: flex;
	align-items: flex-start;
	gap: 12px;
	box-sizing: border-box;
	animation: qcs-fade-in 0.25s ease-out;
}
.qcs-success::before {
	content: "";
	flex-shrink: 0;
	width: 22px;
	height: 22px;
	border-radius: 50%;
	background-color: #16a34a;
	background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 14px 14px;
}
@keyframes qcs-fade-in {
	from { opacity: 0; transform: translateY(4px); }
	to   { opacity: 1; transform: translateY(0); }
}

/* ------------------------------------------------------------------ */
/* Honeypot — visually hidden, but reachable by bots                  */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-hp {
	position: absolute !important;
	left: -9999px !important;
	top: -9999px !important;
	height: 0 !important;
	width: 0 !important;
	overflow: hidden !important;
}

/* ------------------------------------------------------------------ */
/* Footer mark (subtle attribution; can be hidden by setting display:none) */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-foot {
	font-size: 11px;
	color: var(--qcs-text-muted);
	margin-top: -4px;
	letter-spacing: 0.02em;
}
.qcs-form .qcs-foot a {
	color: inherit;
	text-decoration: none;
	border-bottom: 1px dotted currentColor;
}

/* ------------------------------------------------------------------ */
/* Dark-mode-friendly defaults                                         */
/* Only kicks in if the host theme uses prefers-color-scheme.          */
/* Sites with custom themes can override via the CSS vars above.       */
/* ------------------------------------------------------------------ */

@media (prefers-color-scheme: dark) {
	.qcs-form {
		--qcs-text:         #f3f4f6;
		--qcs-text-muted:   #9ca3af;
		--qcs-text-label:   #e5e7eb;
		--qcs-border:       #374151;
		--qcs-border-hover: #4b5563;
		--qcs-bg-field:     #1f2937;
		--qcs-bg-card:      #111827;
		--qcs-error-soft:   #2a1414;
		--qcs-success-soft: #052e1a;
	}
	.qcs-success {
		background: #052e1a;
		border-color: #166534;
		color: #bbf7d0;
	}
}

/* ------------------------------------------------------------------ */
/* v1.16.0 — Per-field style overrides + new field types              */
/* ------------------------------------------------------------------ */

/* Each .qcs-field can override the global theme via local CSS variables
 * supplied inline (style="--qcs-f-label-color:...; --qcs-f-bg:...;").
 * Empty/missing → inherits the form-wide value. */
.qcs-form .qcs-field label,
.qcs-form .qcs-field legend {
	color: var(--qcs-f-label-color, var(--qcs-text-label));
}
.qcs-form .qcs-field input[type="text"],
.qcs-form .qcs-field input[type="email"],
.qcs-form .qcs-field input[type="tel"],
.qcs-form .qcs-field input[type="number"],
.qcs-form .qcs-field input[type="url"],
.qcs-form .qcs-field input[type="date"],
.qcs-form .qcs-field input[type="time"],
.qcs-form .qcs-field select,
.qcs-form .qcs-field textarea {
	background: var(--qcs-f-bg, var(--qcs-bg-field));
	border-color: var(--qcs-f-border, var(--qcs-border));
	color: var(--qcs-f-color, var(--qcs-text));
}

/* Label size + weight modifiers. */
.qcs-form .qcs-ls-s { font-size: calc(var(--qcs-fs-label) - 2px); }
.qcs-form .qcs-ls-m { font-size: var(--qcs-fs-label); }
.qcs-form .qcs-ls-l { font-size: calc(var(--qcs-fs-label) + 3px); }
.qcs-form .qcs-lw-normal { font-weight: 500; }
.qcs-form .qcs-lw-bold   { font-weight: 700; }

/* Radio + checkbox group (fieldset/legend wrapper). */
.qcs-form .qcs-fieldset {
	border: 0;
	padding: 0;
	margin: 0;
	min-width: 0;
}
.qcs-form .qcs-fieldset legend {
	font-weight: 600;
	font-size: var(--qcs-fs-label);
	padding: 0;
	margin-bottom: 6px;
}
.qcs-form .qcs-opts {
	display: flex;
	flex-direction: column;
	gap: 6px;
}
.qcs-form .qcs-opts-inline {
	flex-direction: row;
	flex-wrap: wrap;
	gap: 14px;
}
.qcs-form .qcs-opt {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	font-weight: 500;
	color: var(--qcs-text);
	cursor: pointer;
	line-height: 1.4;
}
.qcs-form .qcs-opt input[type="radio"],
.qcs-form .qcs-opt input[type="checkbox"] {
	width: 18px;
	height: 18px;
	accent-color: var(--qcs-brand);
	flex-shrink: 0;
	margin: 0;
}

/* Heading field — section divider. */
.qcs-form .qcs-section-heading {
	margin: 8px 0 4px;
	color: var(--qcs-f-label-color, var(--qcs-text-label));
	padding-bottom: 8px;
	border-bottom: 1px solid var(--qcs-border);
}

/* HTML block — owner-trusted free-form content. */
.qcs-form .qcs-html-block {
	color: var(--qcs-f-color, var(--qcs-text));
	font-size: var(--qcs-fs-base);
	line-height: 1.5;
}
.qcs-form .qcs-html-block a {
	color: var(--qcs-brand);
}
.qcs-form .qcs-html-block p:first-child { margin-top: 0; }
.qcs-form .qcs-html-block p:last-child  { margin-bottom: 0; }

/* ------------------------------------------------------------------ */
/* v1.17.0 — File upload field                                         */
/* ------------------------------------------------------------------ */

.qcs-form .qcs-field-file .qcs-file-drop {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 14px 16px;
	border: 1.5px dashed var(--qcs-f-border, var(--qcs-border));
	border-radius: var(--qcs-radius);
	background: var(--qcs-f-bg, var(--qcs-bg-field));
	color: var(--qcs-f-color, var(--qcs-text-muted));
	cursor: pointer;
	transition: border-color .15s ease, background .15s ease, color .15s ease;
	font-size: var(--qcs-fs-help);
	font-weight: 500;
}
.qcs-form .qcs-field-file .qcs-file-drop:hover {
	border-color: var(--qcs-brand);
	background: var(--qcs-brand-soft);
	color: var(--qcs-text);
}
.qcs-form .qcs-field-file .qcs-file-drop-icon {
	display: inline-grid;
	place-items: center;
	width: 28px;
	height: 28px;
	border-radius: 999px;
	background: var(--qcs-brand-soft);
	color: var(--qcs-brand);
	flex-shrink: 0;
}
.qcs-form .qcs-field-file input[type="file"] {
	/* Visually hidden but keyboard-focusable. The wrapping label is the
	 * visible click target; clicking it opens the file picker via for=. */
	clip: rect(0 0 0 0);
	clip-path: inset(50%);
	height: 1px;
	overflow: hidden;
	position: absolute;
	white-space: nowrap;
	width: 1px;
}
.qcs-form .qcs-field-file .qcs-file-summary {
	display: block;
	margin-top: 6px;
	font-size: var(--qcs-fs-help);
	color: var(--qcs-text-muted);
}
.qcs-form .qcs-field-file.qcs-invalid .qcs-file-drop {
	border-color: var(--qcs-error);
	background: var(--qcs-error-soft);
}
