/**
 * Niwa AI — Lead Form Generator Builder styles
 *
 * Scoped styles for the admin builder UI. Complements niwa-admin.css
 * (which provides .niwa-card / .niwa-field / .niwa-toggle / .niwa-tabs).
 */

/* ── Builder shell ───────────────────────────────────────────── */
#niwa-lf-builder {
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.niwa-lf-toolbar {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
}

.niwa-lf-empty {
	padding: 24px;
	text-align: center;
	color: #64748b;
	background: #f8fafc;
	border: 1px dashed #cbd5e1;
	border-radius: 8px;
}

.niwa-lf-steps {
	display: flex;
	flex-direction: column;
	gap: 10px;
}

/* ── Step card ───────────────────────────────────────────────── */
.niwa-lf-step {
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	background: #ffffff;
}

.niwa-lf-step__details > summary {
	list-style: none;
	cursor: pointer;
	padding: 10px 12px;
	display: flex;
	align-items: center;
	gap: 10px;
	user-select: none;
}

.niwa-lf-step__details > summary::-webkit-details-marker { display: none; }

.niwa-lf-step__title {
	font-weight: 600;
	flex: 1 1 auto;
	color: #0f172a;
}

.niwa-lf-step__meta {
	font-size: 12px;
	color: #64748b;
	background: #f1f5f9;
	padding: 2px 8px;
	border-radius: 999px;
}

.niwa-lf-step__body {
	padding: 12px;
	border-top: 1px solid #e2e8f0;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.niwa-lf-step__footer {
	display: flex;
	justify-content: flex-start;
}

/* ── Questions ───────────────────────────────────────────────── */
.niwa-lf-questions {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.niwa-lf-question {
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	background: #f8fafc;
}

.niwa-lf-question__details > summary {
	list-style: none;
	cursor: pointer;
	padding: 8px 10px;
	display: flex;
	align-items: center;
	gap: 8px;
	user-select: none;
}

.niwa-lf-question__details > summary::-webkit-details-marker { display: none; }

.niwa-lf-question__title {
	font-weight: 600;
	flex: 1 1 auto;
	color: #0f172a;
}

.niwa-lf-question__id {
	font-size: 11px;
	color: #64748b;
	background: #e2e8f0;
	padding: 1px 6px;
	border-radius: 4px;
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.niwa-lf-question__body {
	padding: 10px 12px;
	border-top: 1px solid #e2e8f0;
	background: #ffffff;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

/* ── Grids ───────────────────────────────────────────────────── */
.niwa-lf-grid-2 {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 10px;
}

.niwa-lf-grid-3 {
	display: grid;
	grid-template-columns: repeat(3, minmax(0, 1fr));
	gap: 10px;
}

@media (max-width: 768px) {
	.niwa-lf-grid-2,
	.niwa-lf-grid-3 { grid-template-columns: 1fr; }
}

/* ── Drag handles / delete buttons ───────────────────────────── */
.niwa-lf-drag {
	cursor: grab;
	color: #94a3b8;
	font-size: 14px;
	line-height: 1;
	padding: 0 4px;
	user-select: none;
}

.niwa-lf-drag:active { cursor: grabbing; }

.niwa-lf-delete {
	color: #64748b !important;
	text-decoration: none !important;
	padding: 2px 6px;
	border-radius: 4px;
	font-size: 14px;
	line-height: 1;
	background: transparent;
	border: none;
	cursor: pointer;
}

.niwa-lf-delete:hover {
	color: #ffffff !important;
	background: #dc2626;
}

.niwa-lf-sort-placeholder {
	background: #e0f2fe;
	border: 1px dashed #38bdf8;
	border-radius: 8px;
	min-height: 48px;
	margin: 4px 0;
}

/* ── Radios ──────────────────────────────────────────────────── */
.niwa-lf-radios {
	display: flex;
	gap: 16px;
	flex-wrap: wrap;
}

.niwa-lf-radios label {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	cursor: pointer;
}

/* ── Sublabels ───────────────────────────────────────────────── */
.niwa-field__sublabel {
	display: block;
	font-size: 12px;
	font-weight: 600;
	color: #475569;
	margin-bottom: 4px;
}

/* ── Options editor ──────────────────────────────────────────── */
.niwa-lf-options-wrap {
	background: #fefce8;
	border: 1px solid #fde68a;
	border-radius: 8px;
	padding: 10px 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.niwa-lf-options {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.niwa-lf-option-row {
	display: grid;
	grid-template-columns: 1fr 1fr auto;
	gap: 8px;
	align-items: center;
}

/* ── Validation block ────────────────────────────────────────── */
.niwa-lf-validation {
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	padding: 10px 12px;
}

/* ── Branching (unified conditional + AI) ────────────────────── */
.niwa-lf-branch {
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 10px;
	padding: 14px;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.niwa-lf-branch__header {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.niwa-lf-branch__title {
	font-size: 14px;
	font-weight: 600;
	color: #0f172a;
}

.niwa-lf-branch__subtitle {
	font-size: 12px;
	color: #64748b;
}

.niwa-lf-branch__modes {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 8px;
}

@media (max-width: 900px) {
	.niwa-lf-branch__modes { grid-template-columns: 1fr; }
}

.niwa-lf-branch-card {
	display: flex;
	gap: 10px;
	align-items: flex-start;
	padding: 10px 12px;
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	cursor: pointer;
	transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.niwa-lf-branch-card:hover {
	border-color: #cbd5e1;
	background: #f8fafc;
}

.niwa-lf-branch-card.is-active {
	border-color: #2563eb;
	background: #eff6ff;
	box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.niwa-lf-branch-card input[type="radio"] {
	margin-top: 3px;
	flex-shrink: 0;
}

.niwa-lf-branch-card__body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	flex: 1 1 auto;
	min-width: 0;
}

.niwa-lf-branch-card__title {
	font-size: 13px;
	font-weight: 600;
	color: #0f172a;
	line-height: 1.3;
}

.niwa-lf-branch-card__desc {
	font-size: 12px;
	color: #64748b;
	line-height: 1.45;
}

.niwa-lf-branch__section {
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 12px;
}

.niwa-lf-branch__section[hidden] { display: none; }

.niwa-lf-branch__section-head {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.niwa-lf-branch__section-title {
	margin: 0;
	font-size: 13px;
	font-weight: 600;
	color: #0f172a;
}

.niwa-lf-branch__section-desc {
	font-size: 12px;
	color: #64748b;
	line-height: 1.45;
}

/* Field wrapper used inside branching section */
.niwa-lf-field {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.niwa-lf-field__label {
	font-size: 13px;
	font-weight: 600;
	color: #0f172a;
}

.niwa-lf-field__hint {
	font-size: 12px;
	color: #64748b;
	line-height: 1.45;
}

/* Rules */
.niwa-lf-rules {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.niwa-lf-rule {
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	padding: 10px 12px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.niwa-lf-rule__row {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
}

.niwa-lf-rule__lead {
	font-size: 12px;
	font-weight: 600;
	color: #475569;
	text-transform: uppercase;
	letter-spacing: 0.04em;
}

.niwa-lf-rule__lead--arrow {
	color: #2563eb;
}

.niwa-lf-rule__arrow {
	font-size: 16px;
	color: #2563eb;
	font-weight: 700;
}

.niwa-lf-rule__op {
	min-width: 180px;
}

.niwa-lf-rule__value {
	flex: 1 1 180px;
	min-width: 160px;
}

.niwa-lf-rule__next {
	flex: 1 1 220px;
	min-width: 180px;
}

.niwa-lf-rule__hint {
	font-size: 12px;
	color: #64748b;
	line-height: 1.45;
}

/* AI candidates — checkbox list */
.niwa-lf-candidates__head {
	display: flex;
	justify-content: space-between;
	align-items: baseline;
	gap: 10px;
	flex-wrap: wrap;
}

.niwa-lf-candidates__actions {
	display: flex;
	gap: 6px;
	align-items: center;
	font-size: 12px;
	color: #64748b;
}

.niwa-lf-linkbtn {
	background: none;
	border: none;
	color: #2563eb !important;
	font-size: 12px;
	font-weight: 600;
	padding: 0;
	cursor: pointer;
	text-decoration: none;
}

.niwa-lf-linkbtn:hover {
	text-decoration: underline;
}

.niwa-lf-candidates {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 6px;
	padding: 8px;
	background: #f8fafc;
	border: 1px solid #e2e8f0;
	border-radius: 8px;
	max-height: 260px;
	overflow-y: auto;
}

.niwa-lf-candidate {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	background: #ffffff;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
	cursor: pointer;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.niwa-lf-candidate:hover {
	border-color: #cbd5e1;
	background: #f8fafc;
}

.niwa-lf-candidate input[type="checkbox"] {
	flex-shrink: 0;
	margin: 0;
}

.niwa-lf-candidate:has(input[type="checkbox"]:checked) {
	border-color: #2563eb;
	background: #eff6ff;
}

.niwa-lf-candidate__body {
	display: flex;
	flex-direction: column;
	gap: 2px;
	min-width: 0;
	flex: 1 1 auto;
}

.niwa-lf-candidate__label {
	font-size: 13px;
	color: #0f172a;
	line-height: 1.3;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.niwa-lf-candidate__id {
	font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
	font-size: 11px;
	color: #64748b;
	background: transparent;
	padding: 0;
}

.niwa-lf-candidates__empty {
	padding: 12px;
	text-align: center;
	font-size: 12px;
	color: #64748b;
	background: #f8fafc;
	border: 1px dashed #cbd5e1;
	border-radius: 8px;
}

/* ── Inputs inside builder (consistent width) ────────────────── */
.niwa-lf-step__body input[type="text"],
.niwa-lf-step__body input[type="number"],
.niwa-lf-step__body textarea,
.niwa-lf-step__body select {
	max-width: 100%;
}

/* Appointment question ------------------------------------------------- */
.niwa-lf-appointment-wrap {
	margin: 16px 0;
	padding: 16px;
	border: 1px solid #cbd5e1;
	border-radius: 10px;
	background: #f8fafc;
}

.niwa-lf-appointment-wrap__header {
	display: flex;
	flex-direction: column;
	gap: 3px;
	margin-bottom: 12px;
}

.niwa-lf-appointment-wrap__header strong {
	font-size: 14px;
	color: #0f172a;
}

.niwa-lf-appointment-wrap__header span,
.niwa-lf-appointment-empty {
	font-size: 12px;
	color: #64748b;
}

.niwa-lf-appointment-options {
	display: grid;
	gap: 6px;
	margin-top: 8px;
	max-height: 220px;
	overflow: auto;
}

.niwa-lf-appointment-option {
	display: grid;
	grid-template-columns: 18px minmax(0, 1fr);
	gap: 2px 8px;
	align-items: center;
	padding: 9px 10px;
	border: 1px solid #e2e8f0;
	border-radius: 7px;
	background: #fff;
	cursor: pointer;
}

.niwa-lf-appointment-option:has(input:checked) {
	border-color: #2563eb;
	background: #eff6ff;
}

.niwa-lf-appointment-option input {
	grid-row: 1 / span 2;
	margin: 0;
}

.niwa-lf-appointment-option span {
	font-weight: 600;
	color: #0f172a;
}

.niwa-lf-appointment-option small {
	grid-column: 2;
	color: #64748b;
}
