/* =========================
   Phone field validation styling (WIP)
   - Exact copy of email/other field styles
   - No prefix wrapper (disabled for debugging)
   ========================= */

/* Field wrapper */
#billing_phone_field {
    position: relative;
}

/* Safari fix */
#billing_phone_field .woocommerce-input-wrapper {
    position: relative;
    width: 100%;
    display: block;
}

/* Extra margin when error is shown */
#billing_phone_field.has-error {
    margin-bottom: 32px;
}

/* Label (idle sits in middle, then floats) */
#billing_phone_field > label {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 17px;
    font-weight: 400;
    color: #8a8a8a;
    pointer-events: none;
    z-index: 4; /* Higher than prefix (z-index: 3) */
    background: transparent;
    padding: 0 4px;
    transition:
        top 0.15s ease-out,
        left 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;
}

/* When prefix visible: shift idle label right */
#billing_phone_field.has-phone-prefix > label {
    left: 100px;
}

/* Input base */
#billing_phone_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;
}

/* When prefix visible: add left padding to input */
#billing_phone_field.has-phone-prefix input {
    padding-left: 100px;
}

/* Placeholder hidden by default */
#billing_phone_field input::placeholder {
    color: #b0b0b0;
    opacity: 0;
    transition: opacity 0.15s ease-out;
}

/* Focused + empty: hide label, show placeholder */
#billing_phone_field.is-focused:not(.has-value) > label {
    opacity: 0;
}
#billing_phone_field.is-focused:not(.has-value) input::placeholder {
    opacity: 1;
}

/* Has value: float label up + shift input text down */
#billing_phone_field.has-value > label {
    top: 8px;
    left: 12px; /* Normal position when floated */
    transform: translateY(0);
    font-size: 12px;
    font-weight: 400;
    opacity: 1;
    background: #ffffff;
}

/* When prefix visible: floated label stays right of prefix */
#billing_phone_field.has-phone-prefix.has-value > label {
    left: 100px;
}

#billing_phone_field.has-value input {
    padding: 28px 12px 8px 12px;
}

/* Override padding when prefix is visible */
#billing_phone_field.has-phone-prefix.has-value input {
    padding: 28px 12px 8px 100px;
}

/* Hide placeholder when has value */
#billing_phone_field.has-value input::placeholder {
    opacity: 0;
}

/* Crisp neutral focus */
#billing_phone_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_phone_field.has-value:not(.is-focused):not(.has-error) > label {
    color: #47b426;
    background: #fafff8;
}

#billing_phone_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 */
#billing_phone_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: 4; /* Higher than prefix */
    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
   ========================= */
#billing_phone_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_phone_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
   ========================= */
#billing_phone_field.has-error.has-value:not(.is-focused) > label {
    color: #CA232C;
    background: #ffffff;
}

#billing_phone_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_phone_field.has-error.has-value:not(.is-focused)::after {
    display: none;
}

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

#billing_phone_field.has-error:not(.has-value):not(.is-focused) > label {
    color: #CA232C;
}
