/**
 * BytePress WooCommerce Blocks Styles
 */

/* ========================================
   Stripe Logo 固定定位 - Blocks 模式
   ======================================== */

/* 确保支付方式容器有 position: relative */
.wc-block-components-radio-control-accordion-option,
.wc-block-components-radio-control__option,
.wp-block-woocommerce-checkout-payment-block .wc-block-components-radio-control__option {
  position: relative !important;
}

/* Stripe logo 固定在右上角 */
.bytepress-stripe-logo {
  position: absolute !important;
  right: 10px !important;
  top: 10px !important;
  width: 50px !important;
  height: 20px !important;
  opacity: 0.6 !important;
  pointer-events: none !important;
  z-index: 100 !important;
}

/* RTL 布局支持 */
[dir="rtl"] .bytepress-stripe-logo,
html[dir="rtl"] .bytepress-stripe-logo,
body[dir="rtl"] .bytepress-stripe-logo,
.rtl .bytepress-stripe-logo {
  right: auto !important;
  left: 10px !important;
}

/* ========================================
   表单样式 - Blocks 模式统一布局
   ======================================== */

/* 移除 Blocks 容器的默认样式（保留主题的 border） */
.wc-block-components-radio-control__option-content,
.wc-block-components-radio-control-accordion-content,
.wp-block-woocommerce-checkout-payment-block .wc-block-components-radio-control__option-content {
  padding: 0 !important;
  margin: 0 !important;
  background: transparent !important;
  /* 不移除 border，保留主题的分隔线 */
}

/* 白色背景铺满 */
.bytepress-blocks-payment-form {
  background: #fff !important;
  padding: 12px 20px 14px 20px !important;
  border-radius: 0 !important;
  margin: 0 !important;
  box-shadow: none !important;
  border: none !important;
  width: 100% !important;
  box-sizing: border-box !important;
}

/* 手机端减少内边距 */
@media (max-width: 480px) {
  .bytepress-blocks-payment-form {
    padding: 10px 12px 12px 12px !important;
  }
}

/* Trust badge 样式 */
.bytepress-blocks-payment-form .bytepress-trust-badge,
.bytepress-trust-badge {
  text-align: center !important;
  margin-top: 4px !important;
  margin-bottom: 0 !important;
  padding: 0 !important;
  color: #6b7280 !important;
  opacity: 1 !important;
  font-size: 12px !important;
  line-height: 1.4 !important;
}

/* 表单网格布局 - 日期和CVV始终同行 */
.bytepress-blocks-form-grid {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 12px !important;
  width: 100% !important;
}

/* 卡号字段总是占满一行 */
.bytepress-blocks-field-full {
  grid-column: 1 / -1 !important;
}

/* 日期和CVV各占半行 */
.bytepress-blocks-field-half {
  grid-column: span 1 !important;
}

/* 字段样式 */
.bytepress-blocks-field {
  position: relative !important;
  margin-bottom: 12px !important;
  box-sizing: border-box !important;
  padding: 0 !important;
}

.bytepress-blocks-field:last-child {
  margin-bottom: 0 !important;
}

/* 标签样式 */
.bytepress-blocks-payment-form .bytepress-blocks-label {
  display: block !important;
  margin-bottom: 6px !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  color: #30313d !important;
  line-height: 1.4 !important;
}

.bytepress-blocks-label .required {
  color: #dc2727 !important;
  margin-left: 2px !important;
}

/* RTL 布局支持 - 必填星号间距 */
[dir="rtl"] .bytepress-blocks-label .required,
html[dir="rtl"] .bytepress-blocks-label .required,
body[dir="rtl"] .bytepress-blocks-label .required,
.rtl .bytepress-blocks-label .required {
  margin-left: 0 !important;
  margin-right: 2px !important;
}

/* 输入框包装器 */
.bytepress-blocks-input-wrapper {
  position: relative !important;
  display: flex !important;
  align-items: center !important;
  width: 100% !important;
}

/* 输入框样式 */
.bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input,
.bytepress-blocks-payment-form input.bytepress-blocks-input,
input#bytepress-blocks-card-number,
input#bytepress-blocks-expiry,
input#bytepress-blocks-cvc {
  width: 100% !important;
  height: 44px !important;
  padding: 10px 12px !important;
  font-size: 16px !important;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  color: #30313d !important;
  background: #fff !important;
  border: 1px solid #d9d9d9 !important;
  border-radius: 6px !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04) !important;
  transition: border-color 0.2s, box-shadow 0.2s !important;
  outline: none !important;
  -webkit-appearance: none !important;
  appearance: none !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  line-height: 1.4 !important;
}

/* 卡号输入框右侧预留图标空间 */
input#bytepress-blocks-card-number,
.bytepress-blocks-field-full .bytepress-blocks-input {
  padding-right: 110px !important;
}

/* Placeholder 样式 - 防止主题覆盖 */
.bytepress-blocks-payment-form input.bytepress-blocks-input::placeholder,
input#bytepress-blocks-card-number::placeholder,
input#bytepress-blocks-expiry::placeholder,
input#bytepress-blocks-cvc::placeholder {
  color: var(--bytepress-text-placeholder, #757680) !important;
  opacity: 1 !important;
}

/* RTL 布局支持 - 输入框文本对齐方向（数字字段保持 LTR 方向但右对齐） */
[dir="rtl"] .bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input,
[dir="rtl"] .bytepress-blocks-payment-form input.bytepress-blocks-input,
[dir="rtl"] input#bytepress-blocks-card-number,
[dir="rtl"] input#bytepress-blocks-expiry,
[dir="rtl"] input#bytepress-blocks-cvc,
html[dir="rtl"] .bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input,
html[dir="rtl"] .bytepress-blocks-payment-form input.bytepress-blocks-input,
html[dir="rtl"] input#bytepress-blocks-card-number,
html[dir="rtl"] input#bytepress-blocks-expiry,
html[dir="rtl"] input#bytepress-blocks-cvc,
body[dir="rtl"] .bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input,
body[dir="rtl"] .bytepress-blocks-payment-form input.bytepress-blocks-input,
body[dir="rtl"] input#bytepress-blocks-card-number,
body[dir="rtl"] input#bytepress-blocks-expiry,
body[dir="rtl"] input#bytepress-blocks-cvc,
.rtl input#bytepress-blocks-card-number,
.rtl input#bytepress-blocks-expiry,
.rtl input#bytepress-blocks-cvc {
  text-align: right !important;
  direction: ltr !important;
}

/* Focus状态样式 */
.bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input:focus,
.bytepress-blocks-payment-form input.bytepress-blocks-input:focus,
input#bytepress-blocks-card-number:focus,
input#bytepress-blocks-expiry:focus,
input#bytepress-blocks-cvc:focus {
  border-color: #0570de !important;
  box-shadow: 0 0 0 3px rgba(5, 112, 222, 0.15) !important;
  outline: none !important;
}

.bytepress-blocks-input:disabled {
  background: #f2f2f2;
  color: var(--bytepress-text-placeholder, #757680);
  cursor: not-allowed;
}

/* 卡号字段特殊样式 */
.bytepress-blocks-field-full .bytepress-blocks-input {
  padding-right: 120px; /* 为卡片图标预留空间 */
}

/* RTL 布局支持 - 卡号字段左侧预留图标空间 */
[dir="rtl"] .bytepress-blocks-field-full .bytepress-blocks-input,
html[dir="rtl"] .bytepress-blocks-field-full .bytepress-blocks-input,
body[dir="rtl"] .bytepress-blocks-field-full .bytepress-blocks-input,
.rtl .bytepress-blocks-field-full .bytepress-blocks-input {
  padding-right: var(--bytepress-spacing, 12px) !important;
  padding-left: 120px !important;
}

/* Stripe风格卡片图标容器 */
.FormFieldInput-Icons {
  position: absolute;
  right: var(--bytepress-spacing, 12px);
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  height: 16px;
}

/* RTL 布局支持 - 卡片图标显示在左边 */
[dir="rtl"] .FormFieldInput-Icons,
html[dir="rtl"] .FormFieldInput-Icons,
body[dir="rtl"] .FormFieldInput-Icons,
.rtl .FormFieldInput-Icons {
  right: auto !important;
  left: var(--bytepress-spacing, 12px) !important;
}

/* Stripe风格图标样式 */
.FormFieldInput-IconsIcon {
  display: flex;
  align-items: center;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.FormFieldInput-IconsIcon.is-visible {
  opacity: 1;
}

.BrandIcon {
  height: 20px;
  width: auto;
  max-width: 32px;
}

/* 轮换图标容器 */
.CardFormFieldGroupIconOverflow {
  position: relative;
  display: flex;
  align-items: center;
  width: 28px;
  height: 16px;
  flex-shrink: 0;
}

.CardFormFieldGroupIconOverflow-Item {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.CardFormFieldGroupIconOverflow-Item--invisible {
  opacity: 0;
  transform: translateY(2px);
  z-index: 0;
}

.CardFormFieldGroupIconOverflow-Item--visible {
  opacity: 1;
  transform: translateY(0);
  z-index: 1;
}

/* 确保轮换图标内的元素样式一致 */
.CardFormFieldGroupIconOverflow .FormFieldInput-IconsIcon {
  opacity: 1;
}

.CardFormFieldGroupIconOverflow .BrandIcon {
  height: 20 px;
  width: auto;
  max-width: 32px;
}

/* Error icon in card icons area */
.FormFieldInput-ErrorIcon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 16px;
}

.FormFieldInput-ErrorIcon svg {
  width: 12px;
  height: 12px;
}

/* Error state for inputs */
.bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input.error,
.bytepress-blocks-payment-form input.bytepress-blocks-input.error,
input#bytepress-blocks-card-number.error,
input#bytepress-blocks-expiry.error,
input#bytepress-blocks-cvc.error,
.bytepress-field-error .bytepress-blocks-input {
  border-color: #dc2727 !important;
  box-shadow: 0 0 0 3px rgba(220, 39, 39, 0.1) !important;
}

/* Error message styles - 超高特异性防止被 FunnelKit 等插件覆盖 */
.bytepress-blocks-error-message,
body .bytepress-blocks-error-message,
.bytepress-blocks-payment-form .bytepress-blocks-error-message,
.wfacp_main_form .bytepress-blocks-error-message,
.wfacp-form .bytepress-blocks-error-message,
body .wfacp_main_form .bytepress-blocks-error-message,
body .wfacp-form .bytepress-blocks-error-message,
html body .wfacp_main_form .bytepress-blocks-error-message,
html body .wfacp-form .bytepress-blocks-error-message {
  display: block !important;
  margin-top: 8px !important;
  font-size: 12px !important;
  color: #dc2727 !important;
  line-height: 1.4 !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}

/* CVC icon - 与经典模式保持一致 */
.bytepress-blocks-cvc-icon {
  position: absolute !important;
  right: var(--bytepress-spacing, 12px) !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  width: 30px !important;
  height: 20px !important;
  opacity: 0.6 !important;
  pointer-events: none !important;
  --colorIconCardCvc: #6c7581;
}

.bytepress-blocks-cvc-icon .p-CardCvcIcons-svg {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  vertical-align: middle !important;
}

/* RTL 布局支持 - CVC 图标显示在左边 */
[dir="rtl"] .bytepress-blocks-cvc-icon,
html[dir="rtl"] .bytepress-blocks-cvc-icon,
body[dir="rtl"] .bytepress-blocks-cvc-icon,
.rtl .bytepress-blocks-cvc-icon {
  right: auto !important;
  left: var(--bytepress-spacing, 12px) !important;
}

/* Both input fields should have identical styling - no extra padding */



/* Blocks特定的网格修复 */
.wc-block-components-checkout-step__content .bytepress-blocks-payment-form {
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .bytepress-blocks-payment-form {
    padding: 12px;
  }
  
  .bytepress-blocks-form-grid {
    gap: var(--bytepress-spacing, 12px);
  }
  
  .bytepress-blocks-input {
    font-size: 16px; /* 防止iOS缩放 */
  }
}

/* Description styles */
.bytepress-blocks-description {
  margin: 0 0 20px 0;
  padding: 0;
  font-size: 14px;
  color: #666666;
  line-height: 1.5;
}

/* 深色模式支持 - 强制保持白色背景 */
@media (prefers-color-scheme: dark) {
  /* 强制blocks信用卡表单保持白色背景 */
  .bytepress-blocks-payment-form {
    background: #fff !important;
    color: #30313d !important;
  }
  
  /* 强制blocks输入框保持白色背景 */
  .bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input,
  .bytepress-blocks-payment-form input.bytepress-blocks-input,
  input#bytepress-blocks-card-number,
  input#bytepress-blocks-expiry,
  input#bytepress-blocks-cvc {
    background: #fff !important;
    color: #30313d !important;
    border-color: #e6e6e6 !important;
  }
  
  /* 强制blocks标签保持深色文字 */
  .bytepress-blocks-label {
    color: #30313d !important;
  }
  
  /* 强制blocks描述保持深灰色文字 */
  .bytepress-blocks-description {
    color: #6d6e78 !important;
  }
  
  /* 强制blocks placeholder保持原色 */
  .bytepress-blocks-payment-form input.bytepress-blocks-input::placeholder,
  input#bytepress-blocks-card-number::placeholder,
  input#bytepress-blocks-expiry::placeholder,
  input#bytepress-blocks-cvc::placeholder {
    color: #757680 !important;
  }
}


