/**
 * BoldForm Pro — Advanced Fields CSS
 *
 * Styles for: password_field, rich_text, date_range, nps, matrix, lookup, geolocation
 * Covers both frontend form rendering and builder canvas previews.
 */

/* =============================================================================
   1. Password Field
   ============================================================================= */

.bf-password-wrap {
	display: flex;
	flex-direction: column;
	gap: 0;
}

.bf-password-field {
	position: relative;
}

.bf-password-field .boldform-lite-form__input {
	padding-right: 44px;
}

.bf-password-toggle {
	position: absolute;
	right: 10px;
	top: 50%;
	transform: translateY(-50%);
	background: none;
	border: none;
	padding: 4px;
	cursor: pointer;
	color: #9ca3af;
	line-height: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: color 0.15s;
}

.bf-password-toggle:hover {
	color: #374151;
}

.bf-password-toggle.is-visible {
	color: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
}

.bf-password-match-msg {
	margin: 4px 0 0;
	font-size: 12px;
	font-weight: 500;
}

.bf-password-match-msg.is-match {
	color: #16a34a;
}

.bf-password-match-msg.is-mismatch {
	color: var(--bf-error-color, #dc2626);
}

/* =============================================================================
   2. Rich Text Editor
   ============================================================================= */

.bf-rte-wrap {
	/* Plain container — TinyMCE (wp.editor) renders its own chrome. Before it loads,
	   or if the editor API is unavailable, the fallback <textarea> shows as-is. */
	width: 100%;
}

/* Fallback / pre-init textarea (graceful degradation when TinyMCE isn't available). */
.bf-rte-textarea {
	width: 100%;
	box-sizing: border-box;
	padding: 10px 12px;
	font-size: 14px;
	line-height: 1.6;
	color: var(--bf-field-text, #111827);
	background: var(--bf-field-bg, #fff);
	border: 1px solid var(--bf-field-border, #d1d5db);
	border-radius: var(--bf-field-radius, 6px);
	resize: vertical;
}

/* Strip the default WP editor margin so it lines up with other form fields. */
.bf-rte-wrap .wp-editor-wrap {
	margin: 0;
}

/* Required-but-empty error state — outline whichever element is showing. */
.bf-rte-wrap.bf-rte-error .bf-rte-textarea,
.bf-rte-wrap.bf-rte-error .wp-editor-wrap,
.bf-rte-wrap.bf-rte-error .mce-tinymce {
	outline: 2px solid var(--bf-error-color, #ef4444);
	outline-offset: 1px;
	border-radius: 4px;
}

/* Theme the WordPress TinyMCE chrome so the live editor matches the other themed
   fields instead of showing TinyMCE's default grey skin. Scoped to .bf-rte-wrap so
   wp-admin editors are never affected. !important is required — the TinyMCE
   "lightgray" skin sets these via high-specificity skin rules. The editing surface
   itself is a separate iframe document (its white body is standard + readable, so
   it's left as-is). */
.bf-rte-wrap .mce-tinymce.mce-container.mce-panel {
	border: 1px solid var(--bf-field-border, #d1d5db) !important;
	border-radius: var(--bf-field-radius, 6px) !important;
	overflow: hidden !important;
	box-shadow: none !important;
}

.bf-rte-wrap .mce-toolbar-grp {
	background: color-mix( in srgb, var(--bf-button-bg, var(--bf-focus-color, #64748b)) 6%, #ffffff ) !important;
	border-bottom: 1px solid var(--bf-field-border, #e5e7eb) !important;
}

/* Active (toggled) toolbar button picks up the theme accent for clear feedback. */
.bf-rte-wrap .mce-btn.mce-active button,
.bf-rte-wrap .mce-btn.mce-active i {
	color: var(--bf-button-bg, var(--bf-focus-color, #1e293b)) !important;
}

/* =============================================================================
   3. Date Range Picker
   ============================================================================= */

.bf-daterange-wrap {
	position: relative;
	display: inline-block;
	width: 100%;
}

.bf-daterange-icon {
	position: absolute;
	right: 10px;
	top: 50%;
	transform: translateY(-50%);
	color: #9ca3af;
	pointer-events: none;
	line-height: 1;
	display: flex;
	align-items: center;
}

.bf-daterange-input {
	padding-right: 36px;
	cursor: pointer;
}

.bf-daterange-picker {
	position: absolute;
	z-index: 999;
	top: calc(100% + 4px);
	left: 0;
	background: var(--bf-field-bg, #fff);
	border: 1px solid var(--bf-field-border, #e5e7eb);
	border-radius: 8px;
	box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
	padding: 16px;
	min-width: 560px;
}

.bf-daterange-months {
	display: flex;
	gap: 24px;
}

.bf-drp-month {
	flex: 1;
	min-width: 0;
}

.bf-drp-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 8px;
}

.bf-drp-month-label {
	font-size: 13px;
	font-weight: 600;
	color: #111827;
}

.bf-drp-nav {
	background: none;
	border: 1px solid #e5e7eb;
	border-radius: 4px;
	width: 28px;
	height: 28px;
	cursor: pointer;
	font-size: 18px;
	line-height: 1;
	color: #6b7280;
	display: flex;
	align-items: center;
	justify-content: center;
	transition: background 0.1s, color 0.1s;
}

.bf-drp-nav:hover {
	background: #f3f4f6;
	color: #111827;
}

.bf-drp-grid {
	display: grid;
	grid-template-columns: repeat(7, 1fr);
	gap: 2px;
}

.bf-drp-dow {
	text-align: center;
	font-size: 11px;
	font-weight: 600;
	color: #9ca3af;
	padding: 4px 0;
	text-transform: uppercase;
}

.bf-drp-day {
	text-align: center;
	padding: 6px 4px;
	font-size: 13px;
	color: var(--bf-field-text, #374151);
	cursor: pointer;
	border-radius: 4px;
	transition: background 0.1s, color 0.1s;
	user-select: none;
}

.bf-drp-day:hover {
	background: #eff6ff;
	color: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
}

.bf-drp-day.is-start,
.bf-drp-day.is-end {
	background: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	color: #fff;
	border-radius: 4px;
}

.bf-drp-day.is-in-range {
	background: #dbeafe;
	color: #1e40af;
	border-radius: 0;
}

.bf-drp-day.is-start {
	border-radius: 4px 0 0 4px;
}

.bf-drp-day.is-end {
	border-radius: 0 4px 4px 0;
}

.bf-drp-day.is-start.is-end {
	border-radius: 4px;
}

/* Hover preview of the tentative range (after the start is picked). */
.bf-drp-day.is-preview {
	background: #eff6ff;
	color: #1e40af;
	border-radius: 0;
}

.bf-drp-day.is-preview-end {
	background: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	color: #fff;
	border-radius: 0 4px 4px 0;
	opacity: 0.65;
}

.bf-daterange-footer {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	margin-top: 12px;
	padding-top: 12px;
	border-top: 1px solid #f3f4f6;
}

.bf-drp-clear {
	background: none;
	border: 1px solid #e5e7eb;
	border-radius: 5px;
	padding: 6px 14px;
	font-size: 13px;
	color: #6b7280;
	cursor: pointer;
	transition: background 0.1s;
}

.bf-drp-clear:hover {
	background: #f3f4f6;
}

.bf-drp-apply {
	background: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	border: 1px solid var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	border-radius: 5px;
	padding: 6px 14px;
	font-size: 13px;
	color: var(--bf-button-text, #fff);
	cursor: pointer;
	transition: background 0.1s;
}

.bf-drp-apply:hover {
	background: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	border-color: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
}

/* =============================================================================
   4. NPS Rating
   ============================================================================= */

.bf-nps-wrap {
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.bf-nps-scale {
	display: flex;
	gap: 4px;
	flex-wrap: wrap;
}

.bf-nps-item {
	flex: 1;
	min-width: 0;
	cursor: pointer;
}

.bf-nps-item input[type="radio"] {
	position: absolute;
	opacity: 0;
	width: 0;
	height: 0;
}

.bf-nps-btn {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-width: 32px;
	height: 40px;
	border: 1px solid var(--bf-field-border, #e5e7eb);
	border-radius: 5px;
	font-size: 13px;
	font-weight: 500;
	color: var(--bf-field-text, #374151);
	background: #f9fafb;
	cursor: pointer;
	transition: background 0.15s, border-color 0.15s, color 0.15s;
	user-select: none;
}

/* Rest-state zone colours — each segment shows its own light tint so the three
   parts (detractors / passives / promoters) read at a glance. The base colours
   come from the per-field --bf-nps-* vars (customisable in the builder), falling
   back to the semantic red / amber / green. Rest = 14% tint bg + 40% tint border. */
.bf-nps-btn--detractor {
	background: color-mix( in srgb, var( --bf-nps-d, #ef4444 ) 14%, #fff );
	border-color: color-mix( in srgb, var( --bf-nps-d, #ef4444 ) 40%, #fff );
}

.bf-nps-btn--passive {
	background: color-mix( in srgb, var( --bf-nps-p, #f59e0b ) 14%, #fff );
	border-color: color-mix( in srgb, var( --bf-nps-p, #f59e0b ) 40%, #fff );
}

.bf-nps-btn--promoter {
	background: color-mix( in srgb, var( --bf-nps-pr, #22c55e ) 14%, #fff );
	border-color: color-mix( in srgb, var( --bf-nps-pr, #22c55e ) 40%, #fff );
}

/* Selected (filled) state — deeper 30% tint + full-saturation border + dark zone
   text, derived from the same vars so it works for any custom colour (readable on
   all hues, unlike a white-on-fill that breaks for yellow). Beats the rest rules
   via the extra is-selected specificity. HOVER previews this exact same active
   style for the hovered button's own zone (so hovering tells the user what picking
   that score will look like) instead of a generic blue. */
.bf-nps-btn.is-selected.is-detractor,
.bf-nps-item:hover .bf-nps-btn--detractor {
	background: color-mix( in srgb, var( --bf-nps-d, #ef4444 ) 30%, #fff );
	border-color: var( --bf-nps-d, #ef4444 );
	color: color-mix( in srgb, var( --bf-nps-d, #ef4444 ) 65%, #111 );
	font-weight: 700;
}

.bf-nps-btn.is-selected.is-passive,
.bf-nps-item:hover .bf-nps-btn--passive {
	background: color-mix( in srgb, var( --bf-nps-p, #f59e0b ) 30%, #fff );
	border-color: var( --bf-nps-p, #f59e0b );
	color: color-mix( in srgb, var( --bf-nps-p, #f59e0b ) 65%, #111 );
	font-weight: 700;
}

.bf-nps-btn.is-selected.is-promoter,
.bf-nps-item:hover .bf-nps-btn--promoter {
	background: color-mix( in srgb, var( --bf-nps-pr, #22c55e ) 30%, #fff );
	border-color: var( --bf-nps-pr, #22c55e );
	color: color-mix( in srgb, var( --bf-nps-pr, #22c55e ) 65%, #111 );
	font-weight: 700;
}

.bf-nps-labels {
	display: flex;
	justify-content: space-between;
	font-size: 11px;
	color: #9ca3af;
}

/* =============================================================================
   5. Matrix / Grid
   ============================================================================= */

.bf-matrix-wrap {
	overflow-x: auto;
}

.bf-matrix-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 14px;
}

.bf-matrix-table thead th {
	padding: 8px 12px;
	text-align: center;
	font-weight: 600;
	color: var(--bf-label-color, #374151);
	background: var(--bf-field-bg, #f9fafb);
	border: 1px solid var(--bf-field-border, #e5e7eb);
	white-space: nowrap;
}

.bf-matrix-table thead th:first-child {
	text-align: left;
}

.bf-matrix-row-label {
	padding: 8px 12px;
	font-weight: 500;
	color: var(--bf-label-color, #374151);
	border: 1px solid var(--bf-field-border, #e5e7eb);
	background: var(--bf-field-bg, #f9fafb);
	white-space: nowrap;
}

.bf-matrix-cell {
	padding: 8px;
	text-align: center;
	border: 1px solid var(--bf-field-border, #e5e7eb);
}

.bf-matrix-cell input[type="radio"],
.bf-matrix-cell input[type="checkbox"] {
	width: 16px;
	height: 16px;
	cursor: pointer;
	accent-color: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
}

.bf-matrix-table tbody tr:hover td {
	background: #f9fafb;
}

.bf-matrix-empty {
	color: #9ca3af;
	font-style: italic;
	font-size: 13px;
}

/* =============================================================================
   6. Lookup / Autocomplete
   ============================================================================= */

.bf-lookup-wrap {
	position: relative;
}

.bf-lookup-list {
	position: absolute;
	z-index: 999;
	top: calc(100% + 2px);
	left: 0;
	right: 0;
	background: var(--bf-field-bg, #fff);
	border: 1px solid var(--bf-field-border, #e5e7eb);
	border-radius: var(--bf-field-radius, 6px);
	box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
	list-style: none;
	margin: 0;
	padding: 4px 0;
	max-height: 240px;
	overflow-y: auto;
}

.bf-lookup-item {
	padding: 8px 12px;
	font-size: 14px;
	color: var(--bf-field-text, #374151);
	cursor: pointer;
	transition: background 0.1s;
	outline: none;
}

.bf-lookup-item:hover,
.bf-lookup-item:focus {
	background: #eff6ff;
	color: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
}

.bf-lookup-item mark {
	background: #fde68a;
	color: inherit;
	font-weight: 600;
	border-radius: 2px;
	padding: 0 1px;
}

/* =============================================================================
   7. Geolocation
   ============================================================================= */

.bf-geo-wrap {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.bf-geo-controls {
	display: flex;
	gap: 8px;
	align-items: center;
}

.bf-geo-controls .bf-geo-address {
	flex: 1;
	min-width: 0;
}

.bf-geo-detect-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 0 14px;
	height: 40px;
	background: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	border: 1px solid var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	border-radius: var(--bf-button-radius, 6px);
	color: var(--bf-button-text, #fff);
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	white-space: nowrap;
	transition: background 0.15s, border-color 0.15s;
}

.bf-geo-detect-btn:hover {
	background: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
	border-color: var(--bf-button-bg, var(--bf-focus-color, #2f80ed));
}

.bf-geo-detect-btn:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.bf-geo-map {
	display: none;
	border-radius: 6px;
	overflow: hidden;
	border: 1px solid #e5e7eb;
	background: #f3f4f6;
}

.bf-geo-status {
	font-size: 12px;
	color: #6b7280;
	margin: 0;
}

.bf-geo-status.is-error {
	color: var(--bf-error-color, #dc2626);
}

/* =============================================================================
   8. Builder canvas preview variants
   ============================================================================= */

/* Generic advanced field preview wrapper */
.bf-adv-preview {
	padding: 8px 0;
}

/* Password preview */
.bf-adv-preview .bf-password-wrap {
	pointer-events: none;
}

/* Rich text preview */
.bf-rte-preview {
	pointer-events: none;
}

.bf-rte-preview .bf-rte-toolbar {
	background: #f9fafb;
}

.bf-rte-preview .bf-rte-editor {
	color: #9ca3af;
	font-style: italic;
}

/* NPS preview */
.bf-nps-preview {
	pointer-events: none;
}

/* Matrix preview */
.bf-matrix-preview {
	pointer-events: none;
}

.bf-matrix-preview .bf-matrix-table {
	font-size: 12px;
}

/* Geolocation preview */
.bf-geo-preview {
	pointer-events: none;
}

.bf-geo-preview .bf-geo-detect-btn {
	opacity: 0.7;
}

/* Lookup preview */
.bf-lookup-preview {
	pointer-events: none;
}

/* Date range preview */
.bf-daterange-preview {
	pointer-events: none;
}
