/**
 * Ubigeo Peru - Definitive Visual Consistency CSS (v3.0)
 * 
 * This CSS file ensures ALL three ubigeo fields (Department, Province, District) 
 * have identical dropdown arrow styling across ALL possible scenarios:
 * - WooCommerce Blocks
 * - Classic WooCommerce checkout
 * - Checkout Field Editor Pro compatibility
 * - Various themes and plugins
 * - All browsers and devices
 * 
 * Last Updated: 2025-09-13
 */

/* ================================================================
   CORE UBIGEO FIELD SELECTORS - Maximum Coverage
   ================================================================ */

/* Primary selectors for all ubigeo fields */
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[name*="billing_provincia"],
select[name*="billing_distrito"],
select[name*="shipping_provincia"],
select[name*="shipping_distrito"],
select[data-ubigeo="department"],
select[data-ubigeo="province"],
select[data-ubigeo="district"],
#billing_state,
#billing_city,
#billing_district,
#billing_provincia,
#billing_distrito,
#shipping_state,
#shipping_city,
#shipping_district,
#shipping_provincia,
#shipping_distrito,
.ubigeo-field select,
.ubigeo-department select,
.ubigeo-province select,
.ubigeo-district select,
.ubigeo-provincia select,
.ubigeo-distrito select {
    /* Reset native appearance for consistent cross-browser styling */
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    appearance: none !important;
    
    /* Consistent dropdown arrow - SVG embedded for reliability */
    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;
    
    /* Consistent spacing to accommodate dropdown arrow */
    padding: 0.5rem 2.5rem 0.5rem 0.75rem !important;
    
    /* Visual styling consistency */
    border: 1px solid #d1d5db !important;
    border-radius: 4px !important;
    font-size: inherit !important;
    line-height: 1.5 !important;
    color: #374151 !important;
    background-color: #fff !important;
    cursor: pointer !important;
    width: 100% !important;
    box-sizing: border-box !important;
    
    /* Smooth transitions */
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
}

/* ================================================================
   WOOCOMMERCE BLOCKS SPECIFIC TARGETING
   ================================================================ */

/* WooCommerce Blocks - Field wrappers */
.wp-block-woocommerce-checkout-billing-address-block select[name*="billing_state"],
.wp-block-woocommerce-checkout-billing-address-block select[name*="billing_city"],
.wp-block-woocommerce-checkout-billing-address-block select[name*="billing_district"],
.wp-block-woocommerce-checkout-shipping-address-block select[name*="shipping_state"],
.wp-block-woocommerce-checkout-shipping-address-block select[name*="shipping_city"],
.wp-block-woocommerce-checkout-shipping-address-block select[name*="shipping_district"],
.wp-block-woocommerce-checkout .wc-block-components-address-form select[name*="state"],
.wp-block-woocommerce-checkout .wc-block-components-address-form select[name*="city"],
.wp-block-woocommerce-checkout .wc-block-components-address-form select[name*="district"] {
    /* Inherit all styles from main ubigeo field rules above */
}

/* ================================================================
   CHECKOUT FIELD EDITOR PRO COMPATIBILITY
   ================================================================ */

/* Checkout Field Editor Pro - Custom field wrappers */
.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"],
.thwcfe-input-field select[name*="billing_provincia"],
.thwcfe-input-field select[name*="billing_distrito"],
.thwcfe-input-field select[name*="shipping_provincia"],
.thwcfe-input-field select[name*="shipping_distrito"],
.checkout-field-editor .form-row select[name*="state"],
.checkout-field-editor .form-row select[name*="city"],
.checkout-field-editor .form-row select[name*="district"] {
    /* Inherit all styles from main ubigeo field rules above */
}

/* ================================================================
   WOOCOMMERCE FORM COMPATIBILITY
   ================================================================ */

/* Standard WooCommerce forms */
.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-checkout .form-row select[name*="state"],
.woocommerce-checkout .form-row select[name*="city"],
.woocommerce-checkout .form-row select[name*="district"] {
    /* Ensure 100% width and max-width for form compatibility */
    width: 100% !important;
    max-width: 100% !important;
}

/* ================================================================
   ELEMENTOR COMPATIBILITY
   ================================================================ */

/* Elementor Pro WooCommerce widgets */
.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"],
.elementor .woocommerce select[name*="state"],
.elementor .woocommerce select[name*="city"],
.elementor .woocommerce select[name*="district"] {
    /* Inherit from base ubigeo field styles above */
}

/* ================================================================
   INTERACTIVE STATES - Focus, Hover, Disabled
   ================================================================ */

/* Focus states for 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[name*="billing_provincia"]:focus,
select[name*="billing_distrito"]:focus,
select[name*="shipping_provincia"]:focus,
select[name*="shipping_distrito"]: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 !important;
    outline: 0 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

/* Hover states */
select[name*="billing_state"]:hover:not(:disabled),
select[name*="billing_city"]:hover:not(:disabled),
select[name*="billing_district"]:hover:not(:disabled),
select[name*="shipping_state"]:hover:not(:disabled),
select[name*="shipping_city"]:hover:not(:disabled),
select[name*="shipping_district"]:hover:not(:disabled),
select[name*="billing_provincia"]:hover:not(:disabled),
select[name*="billing_distrito"]:hover:not(:disabled),
select[name*="shipping_provincia"]:hover:not(:disabled),
select[name*="shipping_distrito"]:hover:not(:disabled) {
    border-color: #9ca3af !important;
}

/* 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[name*="billing_provincia"]:disabled,
select[name*="billing_distrito"]:disabled,
select[name*="shipping_provincia"]:disabled,
select[name*="shipping_distrito"]:disabled,
select[data-ubigeo]:disabled {
    background-color: #f9fafb !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
    opacity: 0.6 !important;
    /* Remove dropdown arrow when disabled */
    background-image: none !important;
}

/* ================================================================
   LOADING STATES WITH SPINNER ANIMATION
   ================================================================ */

.ubigeo-loading {
    position: relative !important;
    background-image: none !important;
}

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

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

/* ================================================================
   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[name*="billing_provincia"] option,
select[name*="billing_distrito"] option,
select[name*="shipping_provincia"] option,
select[name*="shipping_distrito"] option,
select[data-ubigeo] option {
    padding: 0.375rem 0.5rem !important;
    background-color: #fff !important;
    color: #374151 !important;
}

/* ================================================================
   THEME OVERRIDE PROTECTION (HIGH SPECIFICITY)
   ================================================================ */

/* Force consistent appearance when themes override exist */
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"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="billing_provincia"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="billing_distrito"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="shipping_provincia"],
body.woocommerce-checkout .woocommerce-checkout-fields select[name*="shipping_distrito"] {
    /* 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 (Prevent conflicts)
   ================================================================ */

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

.select2-container .select2-selection--single .select2-selection__arrow {
    /* Let Select2 handle its own arrows */
}

/* ================================================================
   RESPONSIVE DESIGN
   ================================================================ */

@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"],
    select[name*="billing_provincia"],
    select[name*="billing_distrito"],
    select[name*="shipping_provincia"],
    select[name*="shipping_distrito"] {
        font-size: 16px !important; /* Prevent zoom on iOS */
        background-size: 1.125em 1.125em !important;
        padding-right: 2.25rem !important;
        background-position: right 0.625rem center !important;
    }
}

/* ================================================================
   ACCESSIBILITY & HIGH CONTRAST
   ================================================================ */

@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"],
    select[name*="billing_provincia"],
    select[name*="billing_distrito"],
    select[name*="shipping_provincia"],
    select[name*="shipping_distrito"] {
        border-width: 2px !important;
        border-color: #000 !important;
    }
}

/* ================================================================
   DARK MODE SUPPORT
   ================================================================ */

@media (prefers-color-scheme: dark) {
    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[name*="billing_provincia"],
    select[name*="billing_distrito"],
    select[name*="shipping_provincia"],
    select[name*="shipping_distrito"] {
        background-color: #2a2a2a !important;
        color: #fff !important;
        border-color: #444 !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='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
    }
    
    select[name*="billing_state"]:hover:not(:disabled),
    select[name*="billing_city"]:hover:not(:disabled),
    select[name*="billing_district"]:hover:not(:disabled),
    select[name*="shipping_state"]:hover:not(:disabled),
    select[name*="shipping_city"]:hover:not(:disabled),
    select[name*="shipping_district"]:hover:not(:disabled) {
        border-color: #666 !important;
    }
}

/* ================================================================
   ERROR/VALIDATION STATES
   ================================================================ */

.woocommerce-checkout .form-row.woocommerce-invalid select[name*="billing_state"],
.woocommerce-checkout .form-row.woocommerce-invalid select[name*="billing_city"],
.woocommerce-checkout .form-row.woocommerce-invalid select[name*="billing_district"],
.woocommerce-checkout .form-row.woocommerce-invalid select[name*="shipping_state"],
.woocommerce-checkout .form-row.woocommerce-invalid select[name*="shipping_city"],
.woocommerce-checkout .form-row.woocommerce-invalid select[name*="shipping_district"] {
    border-color: #e2401c !important;
}

/* ================================================================
   DEBUG & TROUBLESHOOTING
   ================================================================ */

/* Uncomment the following rule for troubleshooting field detection */
/*
select[name*="billing_state"],
select[name*="billing_city"],
select[name*="billing_district"],
select[name*="shipping_state"],
select[name*="shipping_city"],
select[name*="shipping_district"] {
    outline: 2px solid red !important;
    outline-offset: 2px !important;
}
*/

/* ================================================================
   BROWSER-SPECIFIC FIXES
   ================================================================ */

/* Firefox specific fixes */
@-moz-document url-prefix() {
    select[name*="billing_state"],
    select[name*="billing_city"],
    select[name*="billing_district"],
    select[name*="shipping_state"],
    select[name*="shipping_city"],
    select[name*="shipping_district"] {
        background-position: calc(100% - 0.75rem) center !important;
    }
}

/* Safari specific fixes */
@supports (-webkit-appearance: none) and (not (-moz-appearance: none)) {
    select[name*="billing_state"],
    select[name*="billing_city"],
    select[name*="billing_district"],
    select[name*="shipping_state"],
    select[name*="shipping_city"],
    select[name*="shipping_district"] {
        background-attachment: scroll !important;
    }
}

/* ================================================================
   END OF UBIGEO PERU VISUAL CONSISTENCY CSS v3.0
   ================================================================ */