/**
 * Ubigeo Peru - Checkout Fields Styling (OPTIMIZED v2.0)
 * Clean, efficient CSS for consistent dropdown appearance across all ubigeo fields
 * Eliminates over-specification and reduces complexity
 */

/* UNIFIED UBIGEO FIELD STYLING - Covers all field variations efficiently */
select[name*="billing_state"],
select[name*="billing_city"],
select[name*="billing_district"],
select[name*="shipping_state"],
select[name*="shipping_city"],
select[name*="shipping_district"],
select[data-ubigeo],
#billing_state,
#billing_city,
#billing_district,
#shipping_state,
#shipping_city,
#shipping_district,
.ubigeo-field select,
.ubigeo-department select,
.ubigeo-province select,
.ubigeo-district select {
    /* Reset native select appearance for consistent styling */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    /* Consistent dropdown arrow for all ubigeo fields */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.75rem center;
    background-repeat: no-repeat;
    background-size: 1.25em 1.25em;

    /* Consistent padding to accommodate dropdown arrow */
    padding: 0.5rem 2.5rem 0.5rem 0.75rem;

    /* Consistent visual styling */
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: inherit;
    line-height: 1.5;
    color: #374151;
    background-color: #fff;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

/* Focus states for better accessibility */
select[name*="billing_state"]:focus,
select[name*="billing_city"]:focus,
select[name*="billing_district"]:focus,
select[name*="shipping_state"]:focus,
select[name*="shipping_city"]:focus,
select[name*="shipping_district"]:focus,
select[data-ubigeo]:focus,
#billing_state:focus,
#billing_city:focus,
#billing_district:focus,
#shipping_state:focus,
#shipping_city:focus,
#shipping_district:focus {
    border-color: #3b82f6;
    outline: 0;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Disabled/Loading states */
select[name*="billing_state"]:disabled,
select[name*="billing_city"]:disabled,
select[name*="billing_district"]:disabled,
select[name*="shipping_state"]:disabled,
select[name*="shipping_city"]:disabled,
select[name*="shipping_district"]:disabled,
select[data-ubigeo]:disabled {
    background-color: #f9fafb;
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
    background-image: none;
}

/* Option styling */
select[name*="billing_state"] option,
select[name*="billing_city"] option,
select[name*="billing_district"] option,
select[name*="shipping_state"] option,
select[name*="shipping_city"] option,
select[name*="shipping_district"] option,
select[data-ubigeo] option {
    padding: 0.375rem 0.5rem;
    background-color: #fff;
    color: #374151;
}

/* WooCommerce form compatibility */
.woocommerce form .form-row select[name*="billing_state"],
.woocommerce form .form-row select[name*="billing_city"],
.woocommerce form .form-row select[name*="billing_district"],
.woocommerce form .form-row select[name*="shipping_state"],
.woocommerce form .form-row select[name*="shipping_city"],
.woocommerce form .form-row select[name*="shipping_district"],
.woocommerce form .form-row select[data-ubigeo] {
    width: 100%;
    max-width: 100%;
}

/* Elementor compatibility - inherits from base styles */
.elementor-widget-woocommerce-checkout-page select[name*="billing_state"],
.elementor-widget-woocommerce-checkout-page select[name*="billing_city"],
.elementor-widget-woocommerce-checkout-page select[name*="billing_district"],
.elementor-widget-woocommerce-checkout-page select[name*="shipping_state"],
.elementor-widget-woocommerce-checkout-page select[name*="shipping_city"],
.elementor-widget-woocommerce-checkout-page select[name*="shipping_district"] {
    /* Inherits from base ubigeo field styles above */
}

/* Loading state with spinner animation */
.ubigeo-loading {
    position: relative;
    background-image: none !important;
}

.ubigeo-loading::after {
    content: "";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: ubigeo-spin 1s linear infinite;
}

@keyframes ubigeo-spin {
    0% { transform: translateY(-50%) rotate(0deg); }
    100% { transform: translateY(-50%) rotate(360deg); }
}

/* High specificity rules for theme compatibility - only when needed */
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="billing_state"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="billing_city"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="billing_district"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="shipping_state"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="shipping_city"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="shipping_district"] {
    /* Force consistent appearance when theme overrides exist */
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
    background-position: right 0.75rem center !important;
    background-repeat: no-repeat !important;
    background-size: 1.25em 1.25em !important;
    padding-right: 2.5rem !important;
}

/* Select2 compatibility */
.select2-container--default .select2-selection--single {
    background-image: none !important;
}

/* Responsive design for mobile devices */
@media (max-width: 768px) {
    select[name*="billing_state"],
    select[name*="billing_city"],
    select[name*="billing_district"],
    select[name*="shipping_state"],
    select[name*="shipping_city"],
    select[name*="shipping_district"] {
        font-size: 16px; /* Prevent zoom on iOS */
        background-size: 1.125em 1.125em;
        padding-right: 2.25rem;
        background-position: right 0.625rem center;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    select[name*="billing_state"],
    select[name*="billing_city"],
    select[name*="billing_district"],
    select[name*="shipping_state"],
    select[name*="shipping_city"],
    select[name*="shipping_district"] {
        border-width: 2px;
        border-color: #000;
    }
}

/* Checkout Field Editor Pro compatibility - ensure our styles apply */
.thwcfe-input-field select[name*="billing_state"],
.thwcfe-input-field select[name*="billing_city"],
.thwcfe-input-field select[name*="billing_district"],
.thwcfe-input-field select[name*="shipping_state"],
.thwcfe-input-field select[name*="shipping_city"],
.thwcfe-input-field select[name*="shipping_district"] {
    /* Inherit all styles from main ubigeo field rules */
}