/**
 * SureDonation Form Editor Styles
 *
 * Styles for the block editor when editing donation forms.
 * Matches SureForms editor styling patterns.
 *
 * @package SureDonation
 * @since 0.0.1
 */

/* ==========================================================================
   CSS Variables (Editor) - Matches SureForms
   ========================================================================== */

:root {
	/* Base */
	--sd-font-size: 16px;

	/* Colors - Primary */
	--sd-color-scheme-primary: #10b981;
	--sd-color-scheme-primary-hover: #059669;

	/* Colors - Input */
	--sd-color-input-text: #1f2937;
	--sd-color-input-label: #1f2937;
	--sd-color-input-description: #6b7280;
	--sd-color-input-placeholder: #9ca3af;
	--sd-color-input-background: #ffffff;
	--sd-color-input-background-hover: #f9fafb;
	--sd-color-input-border: #d1d5db;
	--sd-color-input-border-hover: #9ca3af;
	--sd-color-input-border-focus-glow: rgba(16, 185, 129, 0.15);
	--sd-color-input-selected: rgba(16, 185, 129, 0.05);
	--sd-color-multi-choice-svg: #9ca3af;
	--sd-color-input-prefix: #6b7280;

	/* Colors - Error */
	--sd-error-color: #dc2626;
	--sd-error-color-border: rgba(220, 38, 38, 0.65);
	--sd-error-color-border-glow: rgba(220, 38, 38, 0.15);

	/* Layout - Gaps */
	--sd-column-gap-between-blocks: 16px;
	--sd-col-gap-between-fields: 16px;
	--sd-row-gap-between-blocks: 18px;

	/* Input Field */
	--sd-input-height: 40px;
	--sd-input-field-font-size: 16px;
	--sd-input-field-font-weight: 400;
	--sd-input-field-line-height: 1.5;
	--sd-input-field-padding: 10px 14px;
	--sd-input-field-border-radius: 6px;
	--sd-input-label-gap: 6px;

	/* Label */
	--sd-label-font-size: 14px;
	--sd-label-font-weight: 500;
	--sd-label-line-height: 20px;

	/* Description */
	--sd-description-font-size: 13px;
	--sd-description-font-weight: 400;
	--sd-description-line-height: 18px;
	--sd-description-margin-top: 2px;

	/* Error */
	--sd-error-font-size: 12px;
	--sd-error-font-weight: 500;
	--sd-error-line-height: 16px;

	/* Checkbox */
	--sd-checkbox-size: 18px;
	--sd-checkbox-input-border-radius: 4px;
	--sd-check-svg-top: 2px;
	--sd-check-svg-left: 2px;

	/* Multi-Choice */
	--sd-gap-between-icon-text: 8px;
	--sd-multi-choice-horizontal-svg-size: 16px;

	/* Button */
	--sd-btn-padding: 12px 24px;
	--sd-btn-font-size: 16px;
	--sd-btn-font-weight: 500;
	--sd-btn-line-height: 1.5;
	--sd-btn-border-radius: 6px;
}

/* ==========================================================================
   Editor Block Wrapper - Root Container Flex Layout
   ========================================================================== */

/* Make the root container a flex container for block width support */
/* Target any editor containing SD blocks */
.is-root-container.block-editor-block-list__layout:has([data-type^="sd/"]),
.block-editor-inner-blocks .block-editor-block-list__layout:has([data-type^="sd/"]) {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sd-row-gap-between-blocks, 18px) var(--sd-col-gap-between-fields, 16px);
	padding: 0;
	max-width: 620px;
	margin: 0 auto;
}

/* Override padding from built editor.css that causes width calculation issues */
body.post-type-suredonation_form div.is-root-container.block-editor-block-list__layout .block-editor-block-list__block,
body.post-type-suredonation_form div.is-root-container.block-editor-block-list__layout .block-list-appender {
	padding: 0 !important;
}

/* Ensure box-sizing for all SD blocks - critical for height calculations */
.is-root-container [data-type^="sd/"] *,
.editor-styles-wrapper [data-type^="sd/"] * {
	box-sizing: border-box;
}

.editor-styles-wrapper .sd-block-single {
	display: flex;
	flex-direction: column;
	width: 100%;
	margin-bottom: 0;
}

/* Block placeholder styles - remove margin since gap handles it */
.editor-styles-wrapper [data-type^="sd/"] {
	margin: 0;
}

/* Reset margin for last child compatibility */
.editor-styles-wrapper [data-type^="sd/"]:last-child {
	margin-bottom: 0;
}

/* ==========================================================================
   Label & Description (Editor)
   ========================================================================== */

.editor-styles-wrapper .sd-label {
	display: flex;
	align-items: center;
	gap: 4px;
	font-size: var(--sd-label-font-size, 14px);
	font-weight: var(--sd-label-font-weight);
	line-height: var(--sd-label-line-height, 20px);
	color: var(--sd-color-input-label, #1f2937);
	margin-bottom: var(--sd-input-label-gap, 6px);
}

.editor-styles-wrapper .sd-required {
	color: var(--sd-error-color);
}

.editor-styles-wrapper .sd-help {
	font-size: var(--sd-description-font-size, 13px);
	font-weight: var(--sd-description-font-weight);
	line-height: var(--sd-description-line-height, 18px);
	color: var(--sd-color-input-description, #6b7280);
	margin-top: var(--sd-description-margin-top);
	margin-bottom: var(--sd-input-label-gap, 6px);
}

/* ==========================================================================
   Input Fields (Editor) - Matches SureForms editor input styles
   ========================================================================== */

.editor-styles-wrapper .sd-block-wrap {
	position: relative;
	width: 100%;
}

.editor-styles-wrapper .sd-input-common {
	display: block;
	width: 100%;
	height: var(--sd-input-height, 44px);
	/* padding: var(--sd-input-field-padding, 10px 14px); */
	font-family: inherit;
	font-size: var(--sd-input-field-font-size, 16px);
	font-weight: var(--sd-input-field-font-weight);
	line-height: var(--sd-input-field-line-height, 1.5);
	color: var(--sd-color-input-text, #1f2937);
	background-color: var(--sd-color-input-background, #ffffff);
	border: 1px solid var(--sd-color-input-border, #d1d5db);
	border-radius: var(--sd-input-field-border-radius);
	outline: none;
	pointer-events: none;
}

.editor-styles-wrapper .sd-input-common::placeholder {
	color: var(--sd-color-input-placeholder, #9ca3af);
}

/* ==========================================================================
   Number Block (Editor)
   ========================================================================== */

.editor-styles-wrapper .sd-number-block .sd-number-wrap {
	display: flex;
	width: 100%;
	align-items: center;
	font-family: inherit;
	font-size: var(--sd-input-field-font-size, 16px);
	font-weight: var(--sd-input-field-font-weight);
	line-height: var(--sd-input-field-line-height, 1.5);
	color: var(--sd-color-input-text, #1f2937);
	border: 1px solid var(--sd-color-input-border, #d1d5db);
	border-radius: var(--sd-input-field-border-radius);
	background-color: var(--sd-color-input-background, #ffffff);
	height: var(--sd-input-height, 44px);
	overflow: hidden;
}

.editor-styles-wrapper .sd-number-block .sd-input-number {
	border: none;
	border-radius: 0;
	padding: var(--sd-input-field-padding, 10px 14px);
	height: 100%;
	flex: 1;
	pointer-events: none;
}

.editor-styles-wrapper .sd-currency-symbol {
	display: flex;
	align-items: center;
	height: 100%;
	padding: 0 12px;
	white-space: nowrap;
	color: var(--sd-color-input-prefix, #6b7280);
	border-right: 1px solid var(--sd-color-input-border, #d1d5db);
}

/* ==========================================================================
   Error Message (Editor)
   ========================================================================== */

.editor-styles-wrapper .suredonation-error {
	display: none;
	font-size: var(--sd-error-font-size);
	font-weight: var(--sd-error-font-weight);
	line-height: var(--sd-error-line-height);
	color: var(--sd-error-color);
	margin-top: 6px;
}

/* ==========================================================================
   Checkbox Block (Editor) - Matches SureForms checkbox editor styles
   ========================================================================== */

.editor-styles-wrapper .sd-checkbox-block .sd-checkbox-wrap {
	display: flex;
	align-items: flex-start;
}

.editor-styles-wrapper .sd-checkbox-block .sd-checkbox-label {
	position: relative;
	display: flex;
	align-items: flex-start;
	gap: 10px;
	cursor: default;
}

.editor-styles-wrapper .sd-checkbox-block .sd-input-checkbox {
	position: relative;
	flex-shrink: 0;
	width: var(--sd-checkbox-size, 18px);
	height: var(--sd-checkbox-size, 18px);
	border: 1px solid var(--sd-color-input-border, #d1d5db);
	border-radius: var(--sd-checkbox-input-border-radius);
	background-color: var(--sd-color-input-background, #ffffff);
	-webkit-appearance: none;
	-moz-appearance: none;
	appearance: none;
	margin: 0;
	pointer-events: none;
}

.editor-styles-wrapper .sd-checkbox-block .sd-checkbox-text {
	font-size: var(--sd-input-field-font-size, 16px);
	line-height: var(--sd-input-field-line-height, 1.5);
	color: var(--sd-color-input-text, #1f2937);
}

.editor-styles-wrapper .sd-checkbox-block .sd-checkbox-text .sd-required {
	color: var(--sd-error-color);
}

/* ==========================================================================
   Multi-Choice Block (Editor) - Matches SureForms multi-choice editor styles
   ========================================================================== */

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap {
	display: flex;
	flex-wrap: wrap;
	margin: 0 -4px;
	padding: var(--sd-multi-choice-outer-padding, 0) 0;
}

/* Layout variations - class on wrap div (matching SureForms pattern) */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap {
	flex-direction: row;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-vertical-layout {
	flex-direction: column;
}

/* Single choice item - matches SureForms srfm-multi-choice-single */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-single {
	padding: 4px;
	cursor: pointer;
	margin: 0;
}

/* Choice width variations - controls option width in horizontal layout */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-choice-width-100 .sd-multi-choice-single {
	width: 100%;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-choice-width-75 .sd-multi-choice-single {
	width: 75%;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-choice-width-66-66 .sd-multi-choice-single {
	width: 66.66%;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-choice-width-50 .sd-multi-choice-single {
	width: 50%;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-choice-width-33-33 .sd-multi-choice-single {
	width: 33.33%;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-choice-width-25 .sd-multi-choice-single {
	width: 25%;
}

/* Block content wrap - matches SureForms srfm-block-content-wrap */
.editor-styles-wrapper .sd-multi-choice-block .sd-block-content-wrap {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: var(--sd-multi-choice-internal-option-gap, 10px);
	padding: var(--sd-input-field-padding, 10px 14px);
	font-size: var(--sd-input-field-font-size, 16px);
	font-weight: var(--sd-input-field-font-weight);
	line-height: var(--sd-input-field-line-height, 1.5);
	color: var(--sd-color-input-text, #1f2937);
	border: 1px solid var(--sd-color-input-border, #d1d5db);
	border-radius: var(--sd-input-field-border-radius, 6px);
	background-color: var(--sd-color-input-background, #ffffff);
	min-height: var(--sd-input-height, 44px);
	height: auto;
	margin: 0;
	transition: 0.2s ease-out;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-block-content-wrap:hover {
	border-color: var(--sd-color-input-border-hover, #9ca3af);
	background-color: var(--sd-color-input-background-hover, #f9fafb);
}

/* Selected state */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-single.sd-selected .sd-block-content-wrap {
	border-color: var(--sd-color-input-border-hover, #9ca3af);
	background-color: var(--sd-color-input-selected, #f0fdf4);
}

/* Option container */
.editor-styles-wrapper .sd-multi-choice-block .sd-option-container {
	display: flex;
	flex: 1;
	gap: var(--sd-multi-choice-internal-option-gap, 10px);
	align-items: center;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-option-container p {
	font-size: 1em;
	line-height: var(--sd-input-field-line-height, 1.5);
	margin: 0;
	word-break: break-word;
	flex: 1;
}

/* Icon container */
.editor-styles-wrapper .sd-multi-choice-block .sd-icon-container {
	display: flex;
	align-items: center;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-icon,
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-icon-unchecked {
	display: flex;
	align-items: center;
	color: var(--sd-color-input-border, #d1d5db);
	transition: opacity 0.2s ease-out;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-icon svg,
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-icon-unchecked svg {
	width: 20px;
	height: 20px;
}

/* Unchecked state - show unchecked icon, hide checked icon */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-icon {
	opacity: 0;
	width: 0;
	overflow: hidden;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-icon-unchecked {
	opacity: 1;
}

/* Selected state - show checked icon, hide unchecked icon */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-single.sd-selected .sd-multi-choice-icon {
	opacity: 1;
	width: auto;
	color: var(--sd-color-scheme-primary, #10b981);
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-single.sd-selected .sd-multi-choice-icon-unchecked {
	opacity: 0;
	width: 0;
	overflow: hidden;
}

/* Vertical layout specific styles - class on wrap div */
.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-vertical-layout .sd-block-content-wrap {
	position: relative;
	padding: var(--sd-multi-choice-vertical-padding, 16px);
	min-height: 80px;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-vertical-layout .sd-option-container {
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
}

.editor-styles-wrapper .sd-multi-choice-block .sd-multi-choice-wrap.sd-vertical-layout .sd-icon-container {
	position: absolute;
	top: 8px;
	right: 8px;
}

/* ==========================================================================
   Payment Block (Editor) - Matches SureForms payment editor styles
   ========================================================================== */

.editor-styles-wrapper .sd-payment-block {
	width: 100%;
}

.editor-styles-wrapper .sd-payment-wrap {
	margin-bottom: 16px;
}

.editor-styles-wrapper .sd-payment-element {
	padding: 16px;
	border: 1px dashed var(--sd-color-input-border, #d1d5db);
	border-radius: var(--sd-input-field-border-radius);
	background-color: #f9fafb;
	min-height: 80px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.editor-styles-wrapper .sd-payment-placeholder {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	color: var(--sd-color-input-description, #6b7280);
	font-size: var(--sd-description-font-size, 13px);
}

.editor-styles-wrapper .sd-payment-placeholder svg {
	width: 32px;
	height: 32px;
	opacity: 0.5;
}

.editor-styles-wrapper .sd-payment-not-configured {
	padding: 16px;
	background-color: #fffbeb;
	border: 1px solid #fbbf24;
	border-radius: var(--sd-input-field-border-radius);
	color: #92400e;
	font-size: var(--sd-description-font-size, 13px);
}

/* Submit Button Preview */
.editor-styles-wrapper .sd-payment-submit {
	margin-top: 8px;
}

.editor-styles-wrapper .sd-submit-button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	padding: var(--sd-btn-padding, 12px 24px);
	font-family: inherit;
	font-size: var(--sd-btn-font-size, 16px);
	font-weight: var(--sd-btn-font-weight);
	line-height: var(--sd-btn-line-height, 1.5);
	color: #ffffff;
	background-color: var(--sd-color-scheme-primary, #10b981);
	border: none;
	border-radius: var(--sd-btn-border-radius);
	cursor: default;
	pointer-events: none;
}

/* ==========================================================================
   Block Selection States
   ========================================================================== */

.editor-styles-wrapper [data-type^="sd/"].is-selected .sd-block-single,
.editor-styles-wrapper [data-type^="sd/"].has-child-selected .sd-block-single {
	position: relative;
}

/* Subtle highlight on selection */
.editor-styles-wrapper [data-type^="sd/"].is-selected::after {
	content: '';
	position: absolute;
	top: -4px;
	left: -4px;
	right: -4px;
	bottom: -4px;
	border: 2px solid var(--sd-color-scheme-primary, #10b981);
	border-radius: 4px;
	pointer-events: none;
	opacity: 0.5;
}

/* ==========================================================================
   Block Inserter Panel
   ========================================================================== */

/* Style for SD blocks in the inserter */
.block-editor-block-types-list__list-item[class*="sd-"] .block-editor-block-types-list__item-icon {
	color: var(--sd-color-scheme-primary, #10b981);
}

/* ==========================================================================
   Responsive Preview
   ========================================================================== */

/* Mobile view preview */
.editor-styles-wrapper .is-mobile-preview .sd-block-single {
	flex: 0 1 100% !important;
}

/* ==========================================================================
   Field Width Previews
   ========================================================================== */

/* Block width classes - applied to block wrapper via blockProps className */
.is-root-container .sd-block-width-100,
.block-editor-block-list__layout .sd-block-width-100 {
	flex: 0 1 100%;
}

.is-root-container .sd-block-width-75,
.block-editor-block-list__layout .sd-block-width-75 {
	flex: 0 1 calc(75% - 0.25 * var(--sd-col-gap-between-fields, 16px));
}

.is-root-container .sd-block-width-66-66,
.block-editor-block-list__layout .sd-block-width-66-66 {
	flex: 0 1 calc(66.66% - 0.3333 * var(--sd-col-gap-between-fields, 16px));
}

.is-root-container .sd-block-width-50,
.block-editor-block-list__layout .sd-block-width-50 {
	flex: 0 1 calc(50% - 0.5 * var(--sd-col-gap-between-fields, 16px));
}

.is-root-container .sd-block-width-33-33,
.block-editor-block-list__layout .sd-block-width-33-33 {
	flex: 0 1 calc(33.33% - 0.6666 * var(--sd-col-gap-between-fields, 16px));
}

.is-root-container .sd-block-width-25,
.block-editor-block-list__layout .sd-block-width-25 {
	flex: 0 1 calc(25% - 0.75 * var(--sd-col-gap-between-fields, 16px));
}

/* Mobile responsive - all blocks full width */
@media (max-width: 576px) {
	.is-root-container .sd-block-width-25,
	.is-root-container .sd-block-width-33-33,
	.is-root-container .sd-block-width-50,
	.is-root-container .sd-block-width-66-66,
	.is-root-container .sd-block-width-75,
	.block-editor-block-list__layout .sd-block-width-25,
	.block-editor-block-list__layout .sd-block-width-33-33,
	.block-editor-block-list__layout .sd-block-width-50,
	.block-editor-block-list__layout .sd-block-width-66-66,
	.block-editor-block-list__layout .sd-block-width-75 {
		flex: 0 1 100%;
		min-width: 100%;
	}
}

/* ==========================================================================
   Inspector Controls Enhancements
   ========================================================================== */

/* Gateway selection in inspector */
.sd-gateway-selector {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.sd-gateway-option {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 12px;
	border: 1px solid #e5e7eb;
	border-radius: 6px;
	cursor: pointer;
	transition: border-color 0.2s;
}

.sd-gateway-option:hover {
	border-color: var(--sd-color-scheme-primary, #10b981);
}

.sd-gateway-option.is-selected {
	border-color: var(--sd-color-scheme-primary, #10b981);
	background-color: rgba(16, 185, 129, 0.05);
}

.sd-gateway-option svg {
	width: 24px;
	height: 24px;
}

.sd-gateway-option-label {
	font-weight: 500;
}

.sd-gateway-option-status {
	margin-left: auto;
	font-size: 12px;
	color: var(--sd-color-input-description, #6b7280);
}

.sd-gateway-option-status.is-configured {
	color: var(--sd-color-scheme-primary, #10b981);
}

/* ==========================================================================
   Test Mode Banner
   ========================================================================== */

.sd-test-mode-banner {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 12px;
	background-color: #fffbeb;
	border: 1px solid #fbbf24;
	border-radius: 4px;
	font-size: 13px;
	color: #92400e;
	margin-bottom: 12px;
}

.sd-test-mode-banner svg {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
}
