/**
 * AKS Autosuggest Styles
 * Beautiful styling for autocomplete dropdowns
 */

/* jQuery UI Autocomplete Override for AKS */
.ui-autocomplete {
    background: #ffffff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 9999 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    /* Fix width issues - should match input field width */
    max-width: 400px !important;
    min-width: 200px !important;
    width: auto !important;
    /* Force absolute positioning */
    position: absolute !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Ensure autocomplete doesn't overflow container */
.woocommerce .ui-autocomplete,
.woocommerce-page .ui-autocomplete {
    max-width: 100% !important;
    box-sizing: border-box;
}

/* Let jQuery UI handle positioning - don't override */
body .ui-autocomplete {
    /* Removed top and left overrides to let jQuery UI position correctly */
}

.ui-autocomplete .ui-menu-item {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ui-autocomplete .ui-menu-item-wrapper {
    display: block;
    padding: 10px 15px;
    border-bottom: 1px solid #f0f0f0;
    color: #333;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ui-autocomplete .ui-menu-item-wrapper:last-child {
    border-bottom: none;
}

.ui-autocomplete .ui-menu-item-wrapper:hover,
.ui-autocomplete .ui-menu-item-wrapper.ui-state-active {
    background: #f7f7f7;
    color: #0073aa;
    font-weight: 500;
}

.ui-autocomplete .ui-state-focus {
    background: #e8f4f8;
    color: #0073aa;
    border: none;
    margin: 0;
}

/* AKS Field Validation Styles */
input[data-aks-field] {
    position: relative;
}

input[data-aks-field].aks-valid {
    border-color: #46b450 !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2346b450'%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41L9 16.17z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: calc(100% - 10px) center;
    background-size: 20px;
    padding-right: 40px;
}

input[data-aks-field].aks-invalid {
    border-color: #dc3232 !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23dc3232'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: calc(100% - 10px) center;
    background-size: 20px;
    padding-right: 40px;
}

/* Loading indicator */
input[data-aks-field].ui-autocomplete-loading {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%230073aa'%3E%3Cstyle%3E@keyframes rotate %7B to %7B transform: rotate(360deg); %7D %7D%3C/style%3E%3Cg style='animation: rotate 1s linear infinite; transform-origin: center;'%3E%3Cpath d='M12 4V2A10 10 0 0 0 2 12h2a8 8 0 0 1 8-8z'/%3E%3C/g%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: calc(100% - 10px) center;
    background-size: 20px;
    padding-right: 40px;
}

/* Validation message styling */
.aks-validation-message {
    margin: 15px 0;
    animation: slideDown 0.3s ease;
}

.aks-validation-message .woocommerce-error {
    background: #fff;
    border-left: 4px solid #dc3232;
    padding: 15px;
    margin: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

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

/* Helper text for AKS fields */
.aks-field-helper {
    display: block;
    font-size: 12px;
    color: #666;
    margin-top: 5px;
    font-style: italic;
}

/* Highlight autocomplete match */
.ui-autocomplete .ui-menu-item-wrapper strong {
    color: #0073aa;
    font-weight: 600;
}

/* No results message */
.ui-autocomplete-no-results {
    padding: 10px 15px;
    color: #666;
    font-style: italic;
    text-align: center;
}

/* Mobile responsive */
@media (max-width: 768px) {
    .ui-autocomplete {
        max-width: 90vw;
        left: 5vw !important;
        right: 5vw !important;
    }
    
    .ui-autocomplete .ui-menu-item-wrapper {
        padding: 12px 15px;
        font-size: 16px;
    }
}

/* WooCommerce specific overrides */
.woocommerce-checkout .ui-autocomplete,
.woocommerce-account .ui-autocomplete,
.woocommerce form .ui-autocomplete {
    font-size: 14px;
    line-height: 1.5;
}

/* Fix z-index issues with WooCommerce modals */
.woocommerce .blockUI.blockOverlay ~ .ui-autocomplete {
    z-index: 10001;
}

/* Read-only state for validated fields */
input[data-aks-field][readonly] {
    background-color: #f8f8f8;
    cursor: not-allowed;
}

/* Error tooltip - will be positioned absolutely in body */
.aks-error-tooltip {
    position: absolute;
    background: #dc3232;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    margin-top: 5px;
    z-index: 10000;
    white-space: nowrap;
    animation: fadeIn 0.3s ease;
    pointer-events: none; /* Prevent interference with form inputs */
}

.aks-error-tooltip:before {
    content: '';
    position: absolute;
    top: -5px;
    left: 15px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #dc3232;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}