/**
 * BytePress WooCommerce Blocks Styles
 */

/* Blocks特定的样式 */
.bytepress-blocks-payment-form {
  background: var(--bytepress-background, #fff);
  padding: var(--bytepress-spacing-lg, 16px);
  border-radius: var(--bytepress-border-radius, 5px);
  margin: var(--bytepress-spacing, 12px) 0;
}

.bytepress-blocks-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--bytepress-spacing-lg, 16px);
}

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

/* 桌面端：日期和CVV等宽显示在同一行 */
@media (min-width: 768px) {
  .bytepress-blocks-form-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--bytepress-spacing-lg, 16px);
  }
  
  .bytepress-blocks-field-half {
    grid-column: span 1;
  }
}

/* 移动端：所有字段堆叠显示 */
@media (max-width: 767px) {
  .bytepress-blocks-form-grid {
    grid-template-columns: 1fr;
  }
  
  .bytepress-blocks-field-full,
  .bytepress-blocks-field-half {
    grid-column: 1 / -1;
  }
}

/* 字段样式 */
.bytepress-blocks-field {
  position: relative;
  margin-bottom: var(--bytepress-spacing, 12px);
  box-sizing: border-box;
}

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

/* 标签样式 */
.bytepress-blocks-label {
  display: block;
  margin-bottom: var(--bytepress-spacing-xs, 4px);
  font-size: var(--bytepress-font-size-sm, 14px);
  font-weight: 500;
  color: var(--bytepress-text-color, #30313d);
  line-height: 1.3;
}

.bytepress-blocks-label .required {
  color: var(--bytepress-error-color, #df1b41);
  margin-left: 2px;
}

/* 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;
  display: flex;
  align-items: center;
}

/* 输入框样式 - 高特异性防止主题覆盖 */
.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;
  padding: var(--bytepress-spacing, 12px) !important;
  font-size: var(--bytepress-font-size, 16px) !important;
  font-family: var(--bytepress-font-family, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif) !important;
  color: var(--bytepress-text-color, #30313d) !important;
  background: var(--bytepress-background, #fff) !important;
  border: 1px solid var(--bytepress-border-color, #e6e6e6) !important;
  border-radius: var(--bytepress-border-radius, 5px) !important;
  box-shadow: var(--bytepress-shadow, 0px 1px 1px rgba(0, 0, 0, 0.03), 0px 3px 6px rgba(0, 0, 0, 0.02)) !important;
  transition: border-color 0.15s ease, box-shadow 0.15s ease !important;
  outline: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  height: auto !important;
  line-height: normal !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: rgba(5, 115, 225, 0.5) !important;
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.03), 0px 3px 6px rgba(0, 0, 0, 0.02), 0 0 0 3px rgba(5, 115, 225, 0.25) !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 - only when not focused */
.bytepress-blocks-payment-form .bytepress-blocks-field .bytepress-blocks-input.error:not(:focus),
.bytepress-blocks-payment-form input.bytepress-blocks-input.error:not(:focus),
input#bytepress-block-card-number.error:not(:focus),
input#bytepress-block-card-expiry.error:not(:focus),
input#bytepress-block-card-cvc.error:not(:focus),
.bytepress-field-error .bytepress-blocks-input:not(:focus) {
  border-color: #dc2727 !important;
  box-shadow: 0 0 0 0.1px #dc2727 !important;
  color: #dc2727 !important;
}

/* Error message styles */
.bytepress-blocks-error-message {
  display: block;
  margin-top: 8px;
  font-size: var(--bytepress-font-size-sm, 14px);
  color: #dc2727;
  line-height: 1.4;
}

/* 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: var(--bytepress-spacing, 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;
  }
}


