/**
 * Province-City Fields Styles
 */

/* Province field styles */
.jet-engine-province-field,
.jet-engine-city-field {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: #fff;
    font-size: 14px;
    line-height: 1.4;
    color: #333;
    direction: rtl;
    text-align: right;
}

.jet-engine-province-field:focus,
.jet-engine-city-field:focus {
    border-color: #4285f4;
    outline: none;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

.jet-engine-province-field:disabled,
.jet-engine-city-field:disabled {
    background-color: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

/* Search functionality styles */
.province-search-container,
.city-search-container {
    position: relative;
    margin-top: 5px;
}

.province-search-input,
.city-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    direction: rtl;
    text-align: right;
    background-color: #fff;
}

.province-search-input:focus,
.city-search-input:focus {
    border-color: #4285f4;
    outline: none;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

.province-search-results,
.city-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    direction: rtl;
    text-align: right;
    transition: background-color 0.2s ease;
}

.search-result-item:hover {
    background-color: #f0f8ff;
    color: #4285f4;
}

.search-result-item:last-child {
    border-bottom: none;
}

/* Toggle buttons */
.province-search-toggle,
.city-search-toggle {
    margin-top: 5px;
    padding: 6px 12px;
    background: #f8f9fa;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    transition: all 0.2s ease;
    direction: rtl;
}

.province-search-toggle:hover,
.city-search-toggle:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    color: #333;
}

.province-search-toggle:active,
.city-search-toggle:active {
    background: #dee2e6;
    transform: translateY(1px);
}

/* Form integration styles */
.jet-form-builder__field-wrap .jet-engine-province-field,
.jet-form-builder__field-wrap .jet-engine-city-field {
    margin-bottom: 0;
}

.jet-form__field.jet-engine-province-field,
.jet-form__field.jet-engine-city-field {
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px 12px;
    font-size: 14px;
    direction: rtl;
    text-align: right;
}

.jet-form__field.jet-engine-province-field:focus,
.jet-form__field.jet-engine-city-field:focus {
    border-color: #4285f4;
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.2);
}

/* Loading state */
.jet-engine-city-field.loading {
    background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjAiIGhlaWdodD0iMjAiIHZpZXdCb3g9IjAgMCAyMCAyMCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHBhdGggZD0iTTEwIDNWN00xNyAxMEgxM005IDE3VjEzTTMgMTBIN00xNS4zNjQgMTUuMzY0TDEyLjEyMSAxMi4xMjFNNC42MzYgNC42MzZMNy44NzkgNy44NzlNMTUuMzY0IDQuNjM2TDEyLjEyMSA3Ljg3OU00LjYzNiAxNS4zNjRMNy44NzkgMTIuMTIxIiBzdHJva2U9IiM0Mjg1ZjQiIHN0cm9rZS13aWR0aD0iMiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIi8+Cjwvc3ZnPgo=');
    background-repeat: no-repeat;
    background-position: left 10px center;
    background-size: 16px 16px;
    padding-left: 35px;
    opacity: 0.7;
    cursor: wait;
}

[dir="rtl"] .jet-engine-city-field.loading {
    background-position: right 10px center;
    padding-right: 35px;
    padding-left: 12px;
}

/* Loading spinner */
.city-loading-spinner {
    position: absolute;
    top: 50%;
    left: 10px;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    font-size: 12px;
    color: #4285f4;
    z-index: 10;
}

[dir="rtl"] .city-loading-spinner {
    left: auto;
    right: 10px;
}

.city-loading-spinner::before {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid #e3f2fd;
    border-top: 2px solid #4285f4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-left: 5px;
}

[dir="rtl"] .city-loading-spinner::before {
    margin-left: 0;
    margin-right: 5px;
}

.city-loading-spinner span {
    font-weight: 500;
    white-space: nowrap;
}

/* Container positioning for spinner */
.cx-control__content,
.jet-form-builder__field-wrap {
    position: relative;
}

/* Error states */
.jet-engine-province-field.error,
.jet-engine-city-field.error {
    border-color: #dc3545;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2);
}

/* Success states */
.jet-engine-province-field.success,
.jet-engine-city-field.success {
    border-color: #28a745;
    box-shadow: 0 0 0 2px rgba(40, 167, 69, 0.2);
}

/* Responsive design */
@media (max-width: 768px) {
    .province-search-results,
    .city-search-results {
        max-height: 150px;
    }
    
    .search-result-item {
        padding: 8px 10px;
        font-size: 13px;
    }
    
    .province-search-toggle,
    .city-search-toggle {
        padding: 5px 10px;
        font-size: 11px;
    }
}

/* RTL improvements */
[dir="rtl"] .jet-engine-province-field,
[dir="rtl"] .jet-engine-city-field {
    text-align: right;
}

[dir="rtl"] .province-search-input,
[dir="rtl"] .city-search-input {
    text-align: right;
}

[dir="rtl"] .search-result-item {
    text-align: right;
}

/* Admin interface specific styles */
.cx-control-province .cx-control__content,
.cx-control-city .cx-control__content {
    position: relative;
}

.cx-control-province .jet-engine-province-field,
.cx-control-city .jet-engine-city-field {
    width: 100%;
    max-width: none;
}

/* Vue component styles for admin */
.jet-engine-meta-wrap .jet-engine-province-field,
.jet-engine-meta-wrap .jet-engine-city-field {
    width: 100%;
    margin-bottom: 0;
}

/* Accessibility improvements */
.jet-engine-province-field:focus,
.jet-engine-city-field:focus {
    outline: 2px solid #4285f4;
    outline-offset: 2px;
}

.search-result-item:focus {
    background-color: #4285f4;
    color: white;
    outline: none;
}

/* Animation for smooth transitions */
.province-search-results,
.city-search-results {
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.2s ease;
}

.province-search-results.show,
.city-search-results.show {
    opacity: 1;
    transform: translateY(0);
}

/* Loading spinner animation */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.jet-engine-city-field.loading::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top: 2px solid #4285f4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
