/* =========================
   Checkout input UX
   - Floating label
   - Placeholder only on focus when empty
   - Crisp neutral focus (no ugly fat outline)
   - Green success state with checkmark
   ========================= */


/* IMPORTANT: kill theme/woo inset shadows so focus doesn't look chunky */
.checkout .form-row input,
.checkout .form-row input:focus {
  box-shadow: none !important;
}

/* Field wrapper gap */
.woocommerce-billing-fields__field-wrapper {
  gap: 7px !important;
}

/* Fix side-by-side fields on desktop to account for 7px gap */
@media (min-width: 576px) {
  #billing_first_name_field,
  #billing_last_name_field,
  #billing_postcode_field,
  #billing_city_field {
    width: calc(50% - 3.5px) !important;
    flex: none !important;
  }
}

/* Field wrappers */
#billing_email_field,
#billing_first_name_field,
#billing_last_name_field,
#billing_postcode_field,
#billing_city_field,
#billing_address_1_field,
#billing_address_2_field {
  position: relative;
}

/* Country/State dropdowns - reduced height */
#billing_country_field select,
#billing_state_field select {
  height: 40px;
}

/* Safari fix - force input wrapper to be positioning context with full width */
/* Without this, Safari renders error messages narrow instead of 100% width */
/* IMPORTANT: Generic selectors don't work in Safari - must target each field by ID */
/* When adding new validated fields, add their ID here too */
#billing_email_field .woocommerce-input-wrapper,
#billing_first_name_field .woocommerce-input-wrapper,
#billing_last_name_field .woocommerce-input-wrapper,
#billing_postcode_field .woocommerce-input-wrapper,
#billing_city_field .woocommerce-input-wrapper,
#billing_address_1_field .woocommerce-input-wrapper,
#billing_address_2_field .woocommerce-input-wrapper {
  position: relative;
  width: 100%;
  display: block;
}

/* Extra margin when error is shown (pushes next row down) */
#billing_email_field.has-error,
#billing_first_name_field.has-error,
#billing_last_name_field.has-error,
#billing_postcode_field.has-error,
#billing_city_field.has-error,
#billing_address_1_field.has-error,
#billing_address_2_field.has-error {
  margin-bottom: 32px; /* error height ~32px, gap adds 7px = 39px total, so 32px margin */
}

/* Prevent flex items from stretching to match heights (fixes checkmark alignment) */
.woocommerce-billing-fields__field-wrapper {
  align-items: flex-start;
}

/* Label (idle sits in middle, then floats) */
#billing_email_field > label,
#billing_first_name_field > label,
#billing_last_name_field > label,
#billing_postcode_field > label,
#billing_city_field > label,
#billing_address_1_field > label,
#billing_address_2_field > label {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 17px;
  font-weight: 400;
  color: #8a8a8a;
  pointer-events: none;
  z-index: 2;
  background: transparent;
  padding: 0 4px;
  transition:
    top 0.15s ease-out,
    font-size 0.15s ease-out,
    opacity 0.15s ease-out,
    color 0.15s ease-out,
    background-color 0.15s ease-out,
    transform 0.15s ease-out;
}

/* Input base */
#billing_email_field input,
#billing_first_name_field input,
#billing_last_name_field input,
#billing_postcode_field input,
#billing_city_field input,
#billing_address_1_field input,
#billing_address_2_field input {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 60px;
  padding: 12px;
  font-size: 18px;
  line-height: 1.2;
  color: #333333;
  border: 1px solid #bfbfbf;
  border-radius: 4px;
  background: #ffffff;
  transition: padding 0.15s ease-out, border-color 0.15s ease-out, background-color 0.15s ease-out;
}

/* Placeholder hidden by default (only appears on focus when empty) */
#billing_email_field input::placeholder,
#billing_first_name_field input::placeholder,
#billing_last_name_field input::placeholder,
#billing_postcode_field input::placeholder,
#billing_city_field input::placeholder,
#billing_address_1_field input::placeholder,
#billing_address_2_field input::placeholder {
  color: #b0b0b0;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

/* Focused + empty: hide label, show placeholder */
#billing_email_field.is-focused:not(.has-value) > label,
#billing_first_name_field.is-focused:not(.has-value) > label,
#billing_last_name_field.is-focused:not(.has-value) > label,
#billing_postcode_field.is-focused:not(.has-value) > label,
#billing_city_field.is-focused:not(.has-value) > label,
#billing_address_1_field.is-focused:not(.has-value) > label,
#billing_address_2_field.is-focused:not(.has-value) > label {
  opacity: 0;
}
#billing_email_field.is-focused:not(.has-value) input::placeholder,
#billing_first_name_field.is-focused:not(.has-value) input::placeholder,
#billing_last_name_field.is-focused:not(.has-value) input::placeholder,
#billing_postcode_field.is-focused:not(.has-value) input::placeholder,
#billing_city_field.is-focused:not(.has-value) input::placeholder,
#billing_address_1_field.is-focused:not(.has-value) input::placeholder,
#billing_address_2_field.is-focused:not(.has-value) input::placeholder {
  opacity: 1;
}

/* Has value: float label up + shift input text down */
#billing_email_field.has-value > label,
#billing_first_name_field.has-value > label,
#billing_last_name_field.has-value > label,
#billing_postcode_field.has-value > label,
#billing_city_field.has-value > label,
#billing_address_1_field.has-value > label,
#billing_address_2_field.has-value > label {
  top: 8px;
  transform: translateY(0);
  font-size: 12px;
  font-weight: 400;
  opacity: 1;
  background: #ffffff;
}
#billing_email_field.has-value input,
#billing_first_name_field.has-value input,
#billing_last_name_field.has-value input,
#billing_postcode_field.has-value input,
#billing_city_field.has-value input,
#billing_address_1_field.has-value input,
#billing_address_2_field.has-value input {
  padding: 28px 12px 8px 12px;
}

/* Hide placeholder when has value */
#billing_email_field.has-value input::placeholder,
#billing_first_name_field.has-value input::placeholder,
#billing_last_name_field.has-value input::placeholder,
#billing_postcode_field.has-value input::placeholder,
#billing_city_field.has-value input::placeholder,
#billing_address_1_field.has-value input::placeholder,
#billing_address_2_field.has-value input::placeholder {
  opacity: 0;
}

/* Crisp neutral focus (no fat outline) */
#billing_email_field input:focus,
#billing_first_name_field input:focus,
#billing_last_name_field input:focus,
#billing_postcode_field input:focus,
#billing_city_field input:focus,
#billing_address_1_field input:focus,
#billing_address_2_field input:focus {
  outline: none;
  border-color: #6b7280;
  box-shadow: 0 0 0 1px rgba(107, 114, 128, 0.25) !important;
}

/* =========================
   Green success state with checkmark
   ========================= */
#billing_email_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_first_name_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_last_name_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_postcode_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_city_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_address_1_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_address_2_field.has-value:not(.is-focused):not(.has-error) > label {
  color: #47b426;
  background: #fafff8;
}

#billing_email_field.has-value:not(.is-focused):not(.has-error) input,
#billing_first_name_field.has-value:not(.is-focused):not(.has-error) input,
#billing_last_name_field.has-value:not(.is-focused):not(.has-error) input,
#billing_postcode_field.has-value:not(.is-focused):not(.has-error) input,
#billing_city_field.has-value:not(.is-focused):not(.has-error) input,
#billing_address_1_field.has-value:not(.is-focused):not(.has-error) input,
#billing_address_2_field.has-value:not(.is-focused):not(.has-error) input {
  border: 2px solid #47b426;
  outline: none;
  background-color: #fafff8;
  box-shadow: none !important;
  padding-right: 44px; /* make room for checkmark */
}

/* Checkmark icon (inline SVG) */
#billing_email_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_first_name_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_last_name_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_postcode_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_city_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_address_1_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_address_2_field.has-value:not(.is-focused):not(.has-error)::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  z-index: 2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2347b426' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'%3E%3C/polyline%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none;
  opacity: 0;
  animation: checkFadeIn 0.2s ease-out forwards;
}

@keyframes checkFadeIn {
  from {
    opacity: 0;
    transform: translateY(-50%) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(-50%) scale(1);
  }
}

/* Input wrapper needs position for absolute error */
#billing_email_field .woocommerce-input-wrapper,
#billing_first_name_field .woocommerce-input-wrapper,
#billing_last_name_field .woocommerce-input-wrapper,
#billing_postcode_field .woocommerce-input-wrapper,
#billing_city_field .woocommerce-input-wrapper,
#billing_address_1_field .woocommerce-input-wrapper,
#billing_address_2_field .woocommerce-input-wrapper {
  position: relative;
}

/* Error message (absolute positioned, margin on parent pushes content) */
#billing_email_field .field-error,
#billing_first_name_field .field-error,
#billing_last_name_field .field-error,
#billing_postcode_field .field-error,
#billing_city_field .field-error,
#billing_address_1_field .field-error,
#billing_address_2_field .field-error {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: -4px;
  padding: 12px 12px 8px 17px;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.2;
  color: #CA232C;
  background: #F9E7E8;
  border-radius: 0 0 4px 4px;
  box-sizing: border-box;
  z-index: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#billing_email_field .field-error::before,
#billing_first_name_field .field-error::before,
#billing_last_name_field .field-error::before,
#billing_postcode_field .field-error::before,
#billing_city_field .field-error::before,
#billing_address_1_field .field-error::before,
#billing_address_2_field .field-error::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  vertical-align: middle;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23CA232C' stroke-width='4' stroke-linecap='round'%3E%3Cpath d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* Error state: red border, red label, white label bg, no checkmark */
#billing_email_field.has-error.has-value:not(.is-focused) > label,
#billing_first_name_field.has-error.has-value:not(.is-focused) > label,
#billing_last_name_field.has-error.has-value:not(.is-focused) > label,
#billing_postcode_field.has-error.has-value:not(.is-focused) > label,
#billing_city_field.has-error.has-value:not(.is-focused) > label,
#billing_address_1_field.has-error.has-value:not(.is-focused) > label,
#billing_address_2_field.has-error.has-value:not(.is-focused) > label {
  color: #CA232C;
  background: #ffffff;
}

#billing_email_field.has-error.has-value:not(.is-focused) input,
#billing_first_name_field.has-error.has-value:not(.is-focused) input,
#billing_last_name_field.has-error.has-value:not(.is-focused) input,
#billing_postcode_field.has-error.has-value:not(.is-focused) input,
#billing_city_field.has-error.has-value:not(.is-focused) input,
#billing_address_1_field.has-error.has-value:not(.is-focused) input,
#billing_address_2_field.has-error.has-value:not(.is-focused) input {
  border: 2px solid #CA232C;
  outline: none;
  background-color: #ffffff;
  box-shadow: none !important;
  padding-right: 12px;
}

#billing_email_field.has-error.has-value:not(.is-focused)::after,
#billing_first_name_field.has-error.has-value:not(.is-focused)::after,
#billing_last_name_field.has-error.has-value:not(.is-focused)::after,
#billing_postcode_field.has-error.has-value:not(.is-focused)::after,
#billing_city_field.has-error.has-value:not(.is-focused)::after,
#billing_address_1_field.has-error.has-value:not(.is-focused)::after,
#billing_address_2_field.has-error.has-value:not(.is-focused)::after {
  display: none;
}

/* Error state when empty (no value) */
#billing_email_field.has-error:not(.has-value):not(.is-focused) input,
#billing_first_name_field.has-error:not(.has-value):not(.is-focused) input,
#billing_last_name_field.has-error:not(.has-value):not(.is-focused) input,
#billing_postcode_field.has-error:not(.has-value):not(.is-focused) input,
#billing_city_field.has-error:not(.has-value):not(.is-focused) input,
#billing_address_1_field.has-error:not(.has-value):not(.is-focused) input,
#billing_address_2_field.has-error:not(.has-value):not(.is-focused) input {
  border: 2px solid #CA232C;
  outline: none;
  background-color: #ffffff;
  box-shadow: none !important;
}

#billing_email_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_first_name_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_last_name_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_postcode_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_city_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_address_1_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_address_2_field.has-error:not(.has-value):not(.is-focused) > label {
  color: #CA232C;
}

