/**
 * Frontend CSS for Turkish Districts
 * Styles the existing "İlçe / Semt" field with Select2-style dropdown
 * 
 * ✅ WCTD Plugin CSS Loaded Successfully!
 */

/* District field styling - Select2 style */
input[name*="district"], 
select[name*="district"],
input[placeholder*="İlçe"], 
select[placeholder*="İlçe"],
input[placeholder*="Semt"], 
select[placeholder*="Semt"] {
    /* WCTD Plugin Active - This field is styled by Turkish Districts Plugin */
    border-left: 3px solid #0073aa !important;
    width: 100% !important;
    padding: 8px 12px !important;
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    color: #333 !important;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out !important;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.075) !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 8px center !important;
    background-size: 12px !important;
    padding-right: 30px !important;
    min-height: 34px !important;
    height: 34px !important;
}

/* Specific styling for converted district select fields */
select[placeholder*="İlçe"], 
select[placeholder*="Semt"] {
    /* Force Select2-like styling */
    border: 1px solid #ddd !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    font-size: 14px !important;
    padding: 8px 30px 8px 12px !important;
    height: 34px !important;
    line-height: 18px !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e") !important;
    background-repeat: no-repeat !important;
    background-position: right 8px center !important;
    background-size: 12px !important;
    cursor: pointer !important;
}

/* Hidden select element */
.wctd-district-select {
    display: none !important;
}

input[name*="district"]:focus, 
select[name*="district"]:focus,
input[placeholder*="İlçe"]:focus, 
select[placeholder*="İlçe"]:focus,
input[placeholder*="Semt"]:focus, 
select[placeholder*="Semt"]:focus {
    border-color: #0073aa;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.075), 0 0 0 2px rgba(0, 115, 170, 0.2);
}

/* Hover effect */
input[name*="district"]:hover, 
select[name*="district"]:hover,
input[placeholder*="İlçe"]:hover, 
select[placeholder*="İlçe"]:hover,
input[placeholder*="Semt"]:hover, 
select[placeholder*="Semt"]:hover {
    border-color: #0073aa;
}

/* Form row styling */
.form-row input[name*="district"],
.form-row select[name*="district"],
.form-row input[placeholder*="İlçe"],
.form-row select[placeholder*="İlçe"],
.form-row input[placeholder*="Semt"],
.form-row select[placeholder*="Semt"] {
    margin-bottom: 0;
}

/* Funnel Builder Pro compatibility */
.wfacp-form-control-wrapper input[name*="district"],
.wfacp-form-control-wrapper select[name*="district"],
.wfacp-form-control-wrapper input[placeholder*="İlçe"],
.wfacp-form-control-wrapper select[placeholder*="İlçe"],
.wfacp-form-control-wrapper input[placeholder*="Semt"],
.wfacp-form-control-wrapper select[placeholder*="Semt"] {
    margin-bottom: 0;
}

/* Loading state */
.form-row.loading input[name*="district"],
.form-row.loading select[name*="district"],
.wfacp-form-control-wrapper.loading input[name*="district"],
.wfacp-form-control-wrapper.loading select[name*="district"] {
    opacity: 0.6;
    pointer-events: none;
}

/* Error state */
.form-row.error input[name*="district"],
.form-row.error select[name*="district"],
.wfacp-form-control-wrapper.error input[name*="district"],
.wfacp-form-control-wrapper.error select[name*="district"] {
    border-color: #e74c3c;
    box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.1);
}

/* Success state */
.form-row.success input[name*="district"],
.form-row.success select[name*="district"],
.wfacp-form-control-wrapper.success input[name*="district"],
.wfacp-form-control-wrapper.success select[name*="district"] {
    border-color: #27ae60;
    box-shadow: 0 0 0 3px rgba(39, 174, 96, 0.1);
}

/* Responsive design */
@media (max-width: 768px) {
    input[name*="district"], 
    select[name*="district"],
    input[placeholder*="İlçe"], 
    select[placeholder*="İlçe"],
    input[placeholder*="Semt"], 
    select[placeholder*="Semt"] {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 14px 16px;
        padding-right: 40px;
    }
}

/* Checkout page specific styling */
.woocommerce-checkout .form-row input[name*="district"],
.woocommerce-checkout .form-row select[name*="district"] {
    clear: both;
}

/* Account page styling */
.woocommerce-account .form-row input[name*="district"],
.woocommerce-account .form-row select[name*="district"] {
    margin-bottom: 15px;
}

/* My Account address forms */
.woocommerce-address-fields .form-row input[name*="district"],
.woocommerce-address-fields .form-row select[name*="district"] {
    margin-bottom: 20px;
}

/* Hide district field by default */
.form-row:has(input[placeholder*="İlçe"]),
.form-row:has(select[placeholder*="İlçe"]),
.form-row:has(input[placeholder*="Semt"]),
.form-row:has(select[placeholder*="Semt"]),
.wfacp-form-control-wrapper:has(input[placeholder*="İlçe"]),
.wfacp-form-control-wrapper:has(select[placeholder*="İlçe"]),
.wfacp-form-control-wrapper:has(input[placeholder*="Semt"]),
.wfacp-form-control-wrapper:has(select[placeholder*="Semt"]) {
    display: none;
}

/* Show district field when Turkey is selected */
.form-row:has(input[placeholder*="İlçe"]).show,
.form-row:has(select[placeholder*="İlçe"]).show,
.form-row:has(input[placeholder*="Semt"]).show,
.form-row:has(select[placeholder*="Semt"]).show,
.wfacp-form-control-wrapper:has(input[placeholder*="İlçe"]).show,
.wfacp-form-control-wrapper:has(select[placeholder*="İlçe"]).show,
.wfacp-form-control-wrapper:has(input[placeholder*="Semt"]).show,
.wfacp-form-control-wrapper:has(select[placeholder*="Semt"]).show {
    display: block;
}

/* Custom dropdown arrow for better styling */
select[name*="district"],
select[placeholder*="İlçe"],
select[placeholder*="Semt"] {
    cursor: pointer;
}

/* Focus ring for accessibility */
input[name*="district"]:focus-visible, 
select[name*="district"]:focus-visible,
input[placeholder*="İlçe"]:focus-visible, 
select[placeholder*="İlçe"]:focus-visible,
input[placeholder*="Semt"]:focus-visible, 
select[placeholder*="Semt"]:focus-visible {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Animation for field conversion */
.wctd-converting {
    transition: all 0.3s ease;
    opacity: 0.7;
}

.wctd-converted {
    animation: wctd-fadeIn 0.3s ease-in-out;
}

@keyframes wctd-fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}