/**
 * Stitch Payment Gateway - Modern Card UI
 *
 * @package Bricks_Child
 * @since 1.0.0
 */

/* CSS Variables for theming */
:root {
	--stitch-primary: #1a1a2e;
	--stitch-secondary: #16213e;
	--stitch-accent: #0f3460;
	--stitch-highlight: #e94560;
	--stitch-success: #10b981;
	--stitch-error: #ef4444;
	--stitch-text: #f1f1f1;
	--stitch-text-muted: #94a3b8;
	--stitch-border: rgba(255, 255, 255, 0.1);
	--stitch-card-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
	--stitch-input-bg: #ffffff;
	--stitch-input-border: #e2e8f0;
	--stitch-input-focus: #3b82f6;
	--stitch-label: #374151;
	--stitch-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
	--stitch-radius: 16px;
	--stitch-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Payment Form Container */
#wc-stitch-form {
	margin: 1.5em 0;
	padding: 0;
	border: none;
	background: transparent;
}

/* ========================================
   ACCESSIBILITY - Screen Reader Only Text
   ======================================== */
.screen-reader-text {
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	width: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute;
	word-wrap: normal !important;
}

/* ========================================
   STITCH LOGO & ACCEPTED CARDS HEADER
   ======================================== */

.stitch-payment-header {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 1rem;
	padding: 1.5rem;
	margin-bottom: 1.5rem;
	background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
	border-radius: var(--stitch-radius);
	border: 1px solid #e2e8f0;
}

.stitch-logo {
	display: flex;
	align-items: center;
	justify-content: center;
}

.stitch-logo svg,
.stitch-logo img {
	width: 120px;
	max-width: 100%;
	height: auto;
	color: #1a1a2e;
}

.stitch-accepted-cards {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.5rem;
}

.stitch-accepted-label {
	font-size: 0.75rem;
	font-weight: 500;
	color: #64748b;
	text-transform: uppercase;
	letter-spacing: 0.05em;
}

.stitch-card-icons-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.stitch-card-icon {
	display: flex;
	align-items: center;
	justify-content: center;
	transition: var(--stitch-transition);
}

.stitch-card-icon:hover {
	transform: translateY(-2px);
}

.stitch-card-icon svg {
	width: 42px;
	height: 28px;
	border-radius: 4px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Responsive adjustments */
@media (min-width: 480px) {
	.stitch-payment-header {
		flex-direction: row;
		justify-content: space-between;
		padding: 1rem 1.5rem;
	}
	
	.stitch-accepted-cards {
		flex-direction: row;
		gap: 0.75rem;
	}
	
	.stitch-accepted-label {
		font-size: 0.7rem;
	}
}

/* ========================================
   SAVED PAYMENT METHODS
   ======================================== */

.wc-stitch-saved-methods {
	margin-bottom: 2rem;
}

.wc-stitch-saved-methods h3 {
	margin-bottom: 1rem;
	font-size: 1rem;
	font-weight: 600;
	color: var(--stitch-label);
	display: flex;
	align-items: center;
	gap: 0.5rem;
}

.wc-stitch-saved-methods h3::before {
	content: '';
	width: 4px;
	height: 1em;
	background: var(--stitch-highlight);
	border-radius: 2px;
}

.wc-stitch-saved-method {
	display: flex;
	align-items: center;
	gap: 1rem;
	margin-bottom: 0.75rem;
	padding: 1rem 1.25rem;
	border: 2px solid var(--stitch-input-border);
	border-radius: 12px;
	cursor: pointer;
	transition: var(--stitch-transition);
	background: #fff;
}

.wc-stitch-saved-method:hover {
	border-color: var(--stitch-input-focus);
	background: #f8fafc;
}

.wc-stitch-saved-method input[type="radio"] {
	width: 20px;
	height: 20px;
	accent-color: var(--stitch-input-focus);
	cursor: pointer;
}

.wc-stitch-saved-method input[type="radio"]:checked ~ span {
	font-weight: 800;
	color: var(--stitch-input-focus);
}

.wc-stitch-saved-method:has(input:checked) {
	border-color: var(--stitch-input-focus);
	background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
}

/* Saved card icons use the same .stitch-card-icon class - no duplicate styles needed */

.stitch-saved-card-info {
	flex: 1;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.stitch-saved-card-number {
	font-size: 1.3rem;
	color: #1f2937;
}

.stitch-saved-card-expiry {
	font-size: 1rem;
	color: #6b7280;
}

/* ========================================
   FORM FIELDS - MODERN DESIGN
   ======================================== */

.wc-stitch-new-method {
	background: #fff;
	border-radius: var(--stitch-radius);
	padding: 1.5rem;
	border: 1px solid var(--stitch-input-border);
	box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.stitch-form-row {
	position: relative;
	margin-bottom: 1.5rem;
}

.stitch-form-row.half {
	display: inline-block;
	width: calc(50% - 0.5rem);
}

.stitch-form-row.half:first-of-type {
	margin-right: 1rem;
}

/* Floating labels */
.stitch-input-wrapper {
	position: relative;
}

.stitch-input-wrapper label {
	position: absolute;
	left: 1rem;
	top: 50%;
	transform: translateY(-50%);
	font-size: 0.95rem;
	color: #9ca3af;
	pointer-events: none;
	transition: var(--stitch-transition);
	background: #fff;
	padding: 0 0.25rem;
}

.stitch-input-wrapper label .required {
	color: var(--stitch-highlight);
	margin-left: 2px;
}

.stitch-input-wrapper input:focus ~ label,
.stitch-input-wrapper input:not(:placeholder-shown) ~ label,
.stitch-input-wrapper.has-value label {
	top: 0;
	font-size: 0.75rem;
	color: var(--stitch-input-focus);
	font-weight: 500;
}

.stitch-input-wrapper input {
	width: 100%;
	/* padding: 1rem; */
	border: 2px solid var(--stitch-input-border);
	border-radius: 10px;
	/* font-size: 1rem; */
	background: #fff;
	transition: var(--stitch-transition);
	outline: none;
}

.stitch-input-wrapper input::placeholder {
	color: transparent;
}

.stitch-input-wrapper input:focus {
	border-color: var(--stitch-input-focus);
	box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Input icons */
.stitch-input-icon {
	position: absolute;
	right: 1rem;
	top: 50%;
	transform: translateY(-50%);
	width: 24px;
	height: 24px;
	color: #9ca3af;
	transition: var(--stitch-transition);
}

.stitch-input-wrapper input:focus ~ .stitch-input-icon {
	color: var(--stitch-input-focus);
}

/* Validation states */
.stitch-input-wrapper.valid input {
	border-color: var(--stitch-success);
}

.stitch-input-wrapper.valid .stitch-input-icon {
	color: var(--stitch-success);
}

.stitch-input-wrapper.invalid input {
	border-color: var(--stitch-error);
}

.stitch-input-wrapper.invalid .stitch-input-icon {
	color: var(--stitch-error);
}

.stitch-input-wrapper.invalid input:focus {
	box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1);
}

/* Card number iframe container - borderless to avoid double borders */
#stitch-card-number-iframe {
	width: 100%;
	min-height: 52px;
	height: auto;
	border: none;
	border-radius: 0;
	overflow: visible;
	background: transparent;
}

#stitch-card-number-iframe:focus-within,
#stitch-card-number-iframe.focused {
	/* No extra styling - iframe handles its own focus */
}

/* The actual iframe element - let it control its own styling */
#stitch-card-number-iframe iframe,
#stitch-tokenizer-iframe {
	width: 100% !important;
	height: 52px !important;
	min-height: 52px !important;
	border: none !important;
	background: transparent !important;
	display: block;
}

/* Loading state */
#stitch-card-number-iframe .stitch-iframe-loading {
	padding: 14px 16px;
	color: #9ca3af;
	font-size: 0.95rem;
	border: 2px solid var(--stitch-input-border);
	border-radius: 10px;
	background: #fff;
}

/* Card number container label - floating style */
#stitch-card-number-container {
	position: relative;
}

#stitch-card-number-container > label {
	position: absolute;
	left: 0.75rem;
	top: -2px;
	transform: translateY(-50%);
	font-size: 0.75rem;
	color: var(--stitch-label);
	font-weight: 500;
	pointer-events: none;
	background: #fff;
	padding: 0 0.25rem;
	z-index: 1;
}

#stitch-card-number-container > label .required {
	color: var(--stitch-highlight);
	margin-left: 2px;
}

/* ========================================
   CHECKBOX - SAVE PAYMENT METHOD
   ======================================== */

.stitch-checkbox-wrapper {
	display: flex;
	align-items: center;
	gap: 0.75rem;
	padding: 1rem;
	background: #f8fafc;
	border-radius: 10px;
	cursor: pointer;
	transition: var(--stitch-transition);
}

.stitch-checkbox-wrapper:hover {
	background: #f1f5f9;
}

.stitch-checkbox-wrapper input[type="checkbox"] {
	width: 20px;
	height: 20px;
	accent-color: var(--stitch-input-focus);
	cursor: pointer;
}

.stitch-checkbox-wrapper span {
	font-size: 0.9rem;
	color: #4b5563;
}

.stitch-checkbox-wrapper .stitch-checkbox-hint {
	display: block;
	font-size: 0.75rem;
	color: #9ca3af;
	margin-top: 2px;
}

/* ========================================
   SURCHARGE NOTICE
   ======================================== */

#stitch-surcharge-notice {
	margin-top: 1.5rem;
	padding: 1rem 1.25rem;
	background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
	border: 1px solid #f59e0b;
	border-radius: 10px;
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

#stitch-surcharge-notice::before {
	content: '⚠️';
	font-size: 1.25rem;
}

#stitch-surcharge-notice p {
	margin: 0;
	font-size: 0.9rem;
	color: #92400e;
}

/* ========================================
   SECURE BADGE
   ======================================== */

.stitch-secure-badge {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.5rem;
	padding: 0.75rem;
	margin-top: 1.5rem;
	background: #f0fdf4;
	border-radius: 8px;
	font-size: 0.8rem;
	color: #166534;
}

.stitch-secure-badge svg {
	width: 16px;
	height: 16px;
}

/* ========================================
   LOADING STATE
   ======================================== */

.stitch-loading {
	position: relative;
	pointer-events: none;
	opacity: 0.7;
}

.stitch-loading::after {
	content: '';
	position: absolute;
	top: 50%;
	left: 50%;
	width: 24px;
	height: 24px;
	margin: -12px 0 0 -12px;
	border: 3px solid var(--stitch-input-border);
	border-top-color: var(--stitch-input-focus);
	border-radius: 50%;
	animation: stitch-spin 0.8s linear infinite;
}

@keyframes stitch-spin {
	to { transform: rotate(360deg); }
}

/* ========================================
   ANIMATIONS
   ======================================== */

@keyframes stitch-fade-in {
	from {
		opacity: 0;
		transform: translateY(10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

.stitch-animate-in {
	animation: stitch-fade-in 0.4s ease-out forwards;
}

/* Card flip animation for future use */
@keyframes stitch-card-flip {
	0% { transform: rotateY(0deg); }
	100% { transform: rotateY(180deg); }
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

@media (max-width: 768px) {
	.stitch-form-row.half {
		display: block;
		width: 100%;
		margin-right: 0;
	}

	.wc-stitch-new-method {
		padding: 1rem;
	}
}

/* ========================================
   ERROR MESSAGES
   ======================================== */

/* Contain errors within payment form */
#wc-stitch-form .woocommerce-error,
#wc-stitch-form .woocommerce-message,
#wc-stitch-form .woocommerce-info,
.wc-stitch-new-method .woocommerce-error,
.payment_method_stitch .woocommerce-error {
	margin: 0 0 1rem 0 !important;
	padding: 0.75rem 1rem !important;
	font-size: 0.875rem !important;
	border-radius: 8px !important;
	width: 100% !important;
	max-width: 100% !important;
	box-sizing: border-box !important;
	float: none !important;
	clear: both !important;
}

/* Field-level errors */
.stitch-field-error,
.stitch-input-wrapper .woocommerce-error {
	display: block;
	color: var(--stitch-error);
	font-size: 0.75rem;
	margin-top: 0.5rem;
	padding: 0;
	background: transparent;
	border: none;
}

/* Error state for inputs */
.stitch-input-wrapper.invalid input,
#stitch-card-number-iframe.invalid {
	border-color: var(--stitch-error) !important;
}

/* Checkout page error containment */
.woocommerce-checkout .payment_method_stitch .woocommerce-error {
	position: relative !important;
	width: 100% !important;
	left: auto !important;
	right: auto !important;
}

/* ========================================
   WOOCOMMERCE BLOCKS COMPATIBILITY
   ======================================== */

.wc-block-checkout__payment-method .wc-stitch-form,
.wc-block-components-payment-method-label {
	width: 100%;
}

/* Hide default WC styles that conflict */
#wc-stitch-form .form-row {
	padding: 0;
	margin: 0;
}

#wc-stitch-form .form-row-first,
#wc-stitch-form .form-row-last {
	width: auto;
	float: none;
}

/* Fix WooCommerce default error positioning */
.woocommerce-NoticeGroup-checkout,
.woocommerce-error {
	clear: both;
}

/* ========================================
   SURCHARGE NOTICE STYLES
   ======================================== */

.stitch-surcharge-notice {
	display: none;
	margin: 1rem 0;
	padding: 1rem;
	border-radius: 10px;
	font-size: 0.9rem;
	line-height: 1.5;
}

.stitch-surcharge-notice.calculating {
	background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
	border: 1px solid #bae6fd;
	color: #0369a1;
}

.stitch-surcharge-notice.has-fee {
	background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
	border: 1px solid #fcd34d;
	color: #92400e;
}

.stitch-surcharge-notice.no-fee {
	background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
	border: 1px solid #86efac;
	color: #166534;
}

.stitch-surcharge-calculating,
.stitch-surcharge-fee,
.stitch-surcharge-none {
	display: flex;
	align-items: center;
	gap: 0.75rem;
}

.stitch-surcharge-icon {
	width: 20px;
	height: 20px;
	flex-shrink: 0;
}

.stitch-surcharge-notice.has-fee .stitch-surcharge-icon {
	color: #d97706;
}

.stitch-surcharge-notice.no-fee .stitch-surcharge-icon {
	color: #16a34a;
}

.stitch-surcharge-text {
	flex: 1;
}

/* Spinner animation */
.stitch-spinner {
	display: inline-block;
	width: 16px;
	height: 16px;
	border: 2px solid #bae6fd;
	border-top-color: #0369a1;
	border-radius: 50%;
	animation: stitch-spin 0.8s linear infinite;
}

@keyframes stitch-spin {
	to {
		transform: rotate(360deg);
	}
}

/* Surcharge fee in order review */
.woocommerce-checkout-review-order-table .fee {
	color: #92400e;
}

.woocommerce-checkout-review-order-table .fee th {
	font-weight: 500;
}

/* Mobile responsive */
@media (max-width: 480px) {
	.stitch-surcharge-notice {
		padding: 0.75rem;
		font-size: 0.85rem;
	}
	
	.stitch-surcharge-icon {
		width: 18px;
		height: 18px;
	}
}
