/**
 * Google Places API Integration - Checkout Styles
 * 
 * Provides styling for address autocomplete functionality
 * 
 * @since 1.0.0
 */


/* ==========================================================================
   Google Places Input Field
   ========================================================================== */

.aihr-google-places-input {
    position: relative;
    background-color: #fff;
    transition: all 0.3s ease;
}

.aihr-google-places-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.2);
}

.aihr-google-places-input.aihr-loading {
    background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M8 12l2 2 4-4"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px 20px;
    padding-right: 40px;
}


/* ==========================================================================
   Loading Indicator
   ========================================================================== */

.aihr-places-loading {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 999;
    pointer-events: none;
}

.aihr-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0073aa;
    border-radius: 50%;
    animation: aihr-spin 1s linear infinite;
}

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


/* ==========================================================================
   Custom Places Suggestions Dropdown (New API)
   ========================================================================== */


/* Custom suggestions container */

.aihr-places-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-family: inherit;
    z-index: 9999 !important;
    margin-top: 2px;
    max-height: 300px;
    overflow-y: auto;
}

.aihr-places-suggestions.aihr-suggestions-visible {
    display: block !important;
}


/* Individual suggestion items */

.aihr-suggestion-item {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
}

.aihr-suggestion-item:last-child {
    border-bottom: none;
}

.aihr-suggestion-item:hover,
.aihr-suggestion-item.aihr-suggestion-highlighted {
    background-color: #f8f9fa;
}

.aihr-suggestion-item .suggestion-text {
    flex: 1;
    color: #333;
    font-weight: 500;
}


/* Add location icon to suggestions */

.aihr-suggestion-item::before {
    content: "📍";
    margin-right: 8px;
    font-size: 12px;
    opacity: 0.7;
}


/* Legacy support for old Google dropdown (if any remain) */

.pac-container {
    border-radius: 4px;
    border: 1px solid #ddd;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    font-family: inherit;
    z-index: 9999 !important;
    margin-top: 2px;
}

.pac-container[style*="display: none"] {
    display: none !important;
}

.pac-container:after {
    display: none;
}

.pac-item {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.pac-item:last-child {
    border-bottom: none;
}

.pac-item:hover,
.pac-item.pac-item-selected {
    background-color: #f8f9fa;
}

.pac-item-query {
    font-weight: 600;
    color: #333;
}

.pac-matched {
    font-weight: 700;
    color: #0073aa;
}

.pac-item-query .pac-matched {
    color: #0073aa;
}

.pac-secondary-text {
    color: #666;
    font-size: 12px;
    margin-top: 2px;
}

.pac-icon {
    width: 16px;
    height: 16px;
    margin-right: 8px;
    background-size: contain;
}


/* ==========================================================================
   Error Messages
   ========================================================================== */

.aihr-places-error {
    background-color: #fff2f2;
    border: 1px solid #ffb3b3;
    border-radius: 4px;
    padding: 12px 16px;
    color: #d63638;
    font-size: 14px;
    margin: 8px 0;
    display: flex;
    align-items: center;
}

.aihr-places-error::before {
    content: "⚠️";
    margin-right: 8px;
    font-size: 16px;
}


/* ==========================================================================
   Mobile Responsiveness
   ========================================================================== */

@media (max-width: 768px) {
    .aihr-places-suggestions {
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0;
        border-radius: 0;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        max-height: 250px;
    }
    .aihr-suggestion-item {
        padding: 16px;
        font-size: 16px;
        /* Prevent zoom on iOS */
    }
    /* Legacy mobile support */
    .pac-container {
        width: 100% !important;
        left: 0 !important;
        right: 0 !important;
        margin: 0;
        border-radius: 0;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    .pac-item {
        padding: 16px;
        font-size: 16px;
        /* Prevent zoom on iOS */
    }
    .aihr-places-loading {
        right: 8px;
    }
    .aihr-spinner {
        width: 14px;
        height: 14px;
    }
    .aihr-places-error {
        font-size: 14px;
        padding: 12px;
        margin: 8px 0;
    }
}

@media (max-width: 480px) {
    .aihr-suggestion-item {
        padding: 14px 12px;
    }
    .aihr-suggestion-item::before {
        font-size: 10px;
    }
    /* Legacy support */
    .pac-item {
        padding: 14px 12px;
    }
    .pac-secondary-text {
        font-size: 11px;
    }
}


/* ==========================================================================
   WooCommerce Integration
   ========================================================================== */


/* Ensure proper spacing in WooCommerce forms */

.woocommerce-checkout .aihr-google-places-input {
    width: 100%;
    max-width: none;
}

.woocommerce-checkout .aihr-places-loading {
    position: absolute;
    right: 12px;
}


/* Style integration with WooCommerce field containers */

.woocommerce-billing-fields .form-row {
    position: relative;
}

.woocommerce-billing-fields .form-row .aihr-places-loading {
    top: 35px;
    /* Adjust based on label height */
}


/* Custom suggestions positioning for WooCommerce */

.woocommerce-checkout .aihr-places-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 99999;
}


/* Ensure proper stacking in WooCommerce checkout */

.woocommerce-billing-fields .form-row .aihr-places-suggestions {
    position: absolute;
    width: 100%;
    top: 100%;
    left: 0;
    z-index: 99999;
}


/* ==========================================================================
   Accessibility
   ========================================================================== */

.aihr-google-places-input:focus {
    border-color: #005177;
    box-shadow: 0 0 0 2px rgba(0, 81, 119, 0.2);
}

.pac-item:focus,
.pac-item:focus-visible {
    outline: 2px solid #005177;
    outline-offset: -2px;
}


/* High contrast mode support */

@media (prefers-contrast: high) {
    .aihr-places-suggestions {
        border: 2px solid #000;
        background: #fff;
    }
    .aihr-suggestion-item:hover,
    .aihr-suggestion-item.aihr-suggestion-highlighted {
        background-color: #000;
        color: #fff;
    }
    /* Legacy support */
    .pac-container {
        border: 2px solid #000;
        background: #fff;
    }
    .pac-item:hover,
    .pac-item.pac-item-selected {
        background-color: #000;
        color: #fff;
    }
    .aihr-places-error {
        border: 2px solid #d63638;
        background-color: #fff;
    }
}


/* Reduced motion support */

@media (prefers-reduced-motion: reduce) {
    .aihr-google-places-input,
    .aihr-suggestion-item,
    .pac-item,
    .aihr-spinner {
        transition: none;
        animation: none;
    }
}


/* ==========================================================================
   Theme Integration
   ========================================================================== */


/* Inherit theme font family */

.pac-container,
.pac-item,
.aihr-places-error {
    font-family: inherit;
}


/* Match theme button styles for consistency */

.aihr-google-places-input {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}


/* Ensure proper z-index stacking */

.pac-container {
    z-index: 999999 !important;
}


/* ==========================================================================
   Loading States
   ========================================================================== */

.disable_auto_address .aihr-google-places-input.aihr-loading {
    background-image: none!important;
}

.aihr-google-places-input.aihr-loading {
    opacity: 0.8;
    cursor: wait;
}

.aihr-places-loading {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.aihr-places-loading[style*="block"] {
    opacity: 1;
}


/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .aihr-places-suggestions,
    .pac-container,
    .aihr-places-loading,
    .aihr-places-error {
        display: none !important;
    }
}