/* =========================
   Bulgarian Address Fields
   Населено място, Улица, ул. № (required visual)
   Квартал, бл., вх., ет., ап. (optional - no error, green only)
   Same styling as standard billing fields
   ========================= */

/* Field wrappers */
#billing_bg_city_field,
#billing_bg_street_field,
#billing_bg_nr_field,
#billing_bg_kvartal_field,
#billing_bg_bl_field,
#billing_bg_vh_field,
#billing_bg_et_field,
#billing_bg_ap_field {
  position: relative;
}

/* Safari fix - force input wrapper to be positioning context with full width */
#billing_bg_city_field .woocommerce-input-wrapper,
#billing_bg_street_field .woocommerce-input-wrapper,
#billing_bg_nr_field .woocommerce-input-wrapper,
#billing_bg_kvartal_field .woocommerce-input-wrapper,
#billing_bg_bl_field .woocommerce-input-wrapper,
#billing_bg_vh_field .woocommerce-input-wrapper,
#billing_bg_et_field .woocommerce-input-wrapper,
#billing_bg_ap_field .woocommerce-input-wrapper {
  position: relative;
  width: 100%;
  display: block;
}

/* Extra margin when error is shown (pushes next row down) */
#billing_bg_city_field.has-error,
#billing_bg_street_field.has-error,
#billing_bg_nr_field.has-error {
  margin-bottom: 32px;
}

/* Label (idle sits in middle, then floats) */
#billing_bg_city_field > label,
#billing_bg_street_field > label,
#billing_bg_nr_field > label,
#billing_bg_kvartal_field > label,
#billing_bg_bl_field > label,
#billing_bg_vh_field > label,
#billing_bg_et_field > label,
#billing_bg_ap_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_bg_city_field input,
#billing_bg_street_field input,
#billing_bg_nr_field input,
#billing_bg_kvartal_field input,
#billing_bg_bl_field input,
#billing_bg_vh_field input,
#billing_bg_et_field input,
#billing_bg_ap_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_bg_city_field input::placeholder,
#billing_bg_street_field input::placeholder,
#billing_bg_nr_field input::placeholder,
#billing_bg_kvartal_field input::placeholder,
#billing_bg_bl_field input::placeholder,
#billing_bg_vh_field input::placeholder,
#billing_bg_et_field input::placeholder,
#billing_bg_ap_field input::placeholder {
  color: #b0b0b0;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

/* Focused + empty: hide label, show placeholder */
#billing_bg_city_field.is-focused:not(.has-value) > label,
#billing_bg_street_field.is-focused:not(.has-value) > label,
#billing_bg_nr_field.is-focused:not(.has-value) > label,
#billing_bg_kvartal_field.is-focused:not(.has-value) > label,
#billing_bg_bl_field.is-focused:not(.has-value) > label,
#billing_bg_vh_field.is-focused:not(.has-value) > label,
#billing_bg_et_field.is-focused:not(.has-value) > label,
#billing_bg_ap_field.is-focused:not(.has-value) > label {
  opacity: 0;
}

#billing_bg_city_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_street_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_nr_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_kvartal_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_bl_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_vh_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_et_field.is-focused:not(.has-value) input::placeholder,
#billing_bg_ap_field.is-focused:not(.has-value) input::placeholder {
  opacity: 1;
}

/* Has value: float label up + shift input text down */
#billing_bg_city_field.has-value > label,
#billing_bg_street_field.has-value > label,
#billing_bg_nr_field.has-value > label,
#billing_bg_kvartal_field.has-value > label,
#billing_bg_bl_field.has-value > label,
#billing_bg_vh_field.has-value > label,
#billing_bg_et_field.has-value > label,
#billing_bg_ap_field.has-value > label {
  top: 8px;
  transform: translateY(0);
  font-size: 12px;
  font-weight: 400;
  opacity: 1;
  background: #ffffff;
}

#billing_bg_city_field.has-value input,
#billing_bg_street_field.has-value input,
#billing_bg_nr_field.has-value input,
#billing_bg_kvartal_field.has-value input,
#billing_bg_bl_field.has-value input,
#billing_bg_vh_field.has-value input,
#billing_bg_et_field.has-value input,
#billing_bg_ap_field.has-value input {
  padding: 28px 12px 8px 12px;
}

/* Hide placeholder when has value */
#billing_bg_city_field.has-value input::placeholder,
#billing_bg_street_field.has-value input::placeholder,
#billing_bg_nr_field.has-value input::placeholder,
#billing_bg_kvartal_field.has-value input::placeholder,
#billing_bg_bl_field.has-value input::placeholder,
#billing_bg_vh_field.has-value input::placeholder,
#billing_bg_et_field.has-value input::placeholder,
#billing_bg_ap_field.has-value input::placeholder {
  opacity: 0;
}

/* Crisp neutral focus (no fat outline) */
#billing_bg_city_field input:focus,
#billing_bg_street_field input:focus,
#billing_bg_nr_field input:focus,
#billing_bg_kvartal_field input:focus,
#billing_bg_bl_field input:focus,
#billing_bg_vh_field input:focus,
#billing_bg_et_field input:focus,
#billing_bg_ap_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
   ========================= */

/* Required fields: green only when has value, not focused, no error */
#billing_bg_city_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_bg_street_field.has-value:not(.is-focused):not(.has-error) > label,
#billing_bg_nr_field.has-value:not(.is-focused):not(.has-error) > label,
/* Optional fields: green when has value, not focused (no error check needed) */
#billing_bg_kvartal_field.has-value:not(.is-focused) > label,
#billing_bg_bl_field.has-value:not(.is-focused) > label,
#billing_bg_vh_field.has-value:not(.is-focused) > label,
#billing_bg_et_field.has-value:not(.is-focused) > label,
#billing_bg_ap_field.has-value:not(.is-focused) > label {
  color: #47b426;
  background: #fafff8;
}

#billing_bg_city_field.has-value:not(.is-focused):not(.has-error) input,
#billing_bg_street_field.has-value:not(.is-focused):not(.has-error) input,
#billing_bg_nr_field.has-value:not(.is-focused):not(.has-error) input,
#billing_bg_kvartal_field.has-value:not(.is-focused) input,
#billing_bg_bl_field.has-value:not(.is-focused) input,
#billing_bg_vh_field.has-value:not(.is-focused) input,
#billing_bg_et_field.has-value:not(.is-focused) input,
#billing_bg_ap_field.has-value:not(.is-focused) input {
  border: 2px solid #47b426;
  outline: none;
  background-color: #fafff8;
  box-shadow: none !important;
  padding-right: 44px;
}

/* Checkmark icon (inline SVG) */
#billing_bg_city_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_bg_street_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_bg_nr_field.has-value:not(.is-focused):not(.has-error)::after,
#billing_bg_kvartal_field.has-value:not(.is-focused)::after,
#billing_bg_bl_field.has-value:not(.is-focused)::after,
#billing_bg_vh_field.has-value:not(.is-focused)::after,
#billing_bg_et_field.has-value:not(.is-focused)::after,
#billing_bg_ap_field.has-value:not(.is-focused)::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;
}

/* Error message (absolute positioned, margin on parent pushes content) */
#billing_bg_city_field .field-error,
#billing_bg_street_field .field-error,
#billing_bg_nr_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_bg_city_field .field-error::before,
#billing_bg_street_field .field-error::before,
#billing_bg_nr_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_bg_city_field.has-error.has-value:not(.is-focused) > label,
#billing_bg_street_field.has-error.has-value:not(.is-focused) > label,
#billing_bg_nr_field.has-error.has-value:not(.is-focused) > label {
  color: #CA232C;
  background: #ffffff;
}

#billing_bg_city_field.has-error.has-value:not(.is-focused) input,
#billing_bg_street_field.has-error.has-value:not(.is-focused) input,
#billing_bg_nr_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_bg_city_field.has-error.has-value:not(.is-focused)::after,
#billing_bg_street_field.has-error.has-value:not(.is-focused)::after,
#billing_bg_nr_field.has-error.has-value:not(.is-focused)::after {
  display: none;
}

/* Error state when empty (no value) */
#billing_bg_city_field.has-error:not(.has-value):not(.is-focused) input,
#billing_bg_street_field.has-error:not(.has-value):not(.is-focused) input,
#billing_bg_nr_field.has-error:not(.has-value):not(.is-focused) input {
  border: 2px solid #CA232C;
  outline: none;
  background-color: #ffffff;
  box-shadow: none !important;
}

#billing_bg_city_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_bg_street_field.has-error:not(.has-value):not(.is-focused) > label,
#billing_bg_nr_field.has-error:not(.has-value):not(.is-focused) > label {
  color: #CA232C;
}
