/**
 * Mapbox Address Autocomplete Styles
 * Simplified for single-page Shopify-style checkout
 */

/* Results container - Fixed positioning for proper z-index layering */
.mapbox-results {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    animation: slideDown 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999999 !important;
    position: fixed !important;
    margin-top: 0.25rem;
    border-radius: 0.75rem;
    background-color: white;
    border: 1px solid #e5e7eb;
    max-height: 20rem;
    overflow-y: auto;
}

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

/* Address summary box */
#billing_address_summary,
#shipping_address_summary {
    animation: slideDown 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    z-index: 1;
}

/* Result items with modern hover and focus states */
.mapbox-result-item {
    transition: all 0.15s ease;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
}

.mapbox-result-item::before {
    content: '';
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    margin-top: 0.125rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z'/%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M15 11a3 3 0 11-6 0 3 3 0 016 0z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
}

.mapbox-result-item:hover {
    background-color: #f3f4f6;
}

.mapbox-result-item:active {
    background-color: #e5e7eb;
}

.mapbox-result-item .mapbox-address-main {
    font-weight: 600;
    color: #111827;
    font-size: 0.9375rem;
    line-height: 1.4;
}

.mapbox-result-item .mapbox-address-secondary {
    color: #6b7280;
    font-size: 0.8125rem;
    margin-top: 0.125rem;
}

/* First and last item rounded corners */
.mapbox-results .mapbox-result-item:first-child {
    border-top-left-radius: 0.75rem;
    border-top-right-radius: 0.75rem;
}

.mapbox-results .mapbox-result-item:last-child {
    border-bottom-left-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
}

/* Divider between items */
.mapbox-result-item:not(:last-child) {
    border-bottom: 1px solid #f3f4f6;
}

/* Mobile-specific input styling to prevent zoom and improve usability */
.mapbox-mobile-input {
    font-size: 16px !important; /* Prevents iOS zoom */
    -webkit-appearance: none;
    appearance: none;
}

/* Touch-friendly manual toggle button */
.touch-target-button {
    display: inline-block;
    padding: 0.5rem 0.75rem;
    margin: -0.5rem -0.75rem;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

/* Mobile optimizations */
@media (max-width: 640px) {
    .mapbox-results {
        max-height: 50vh; /* Use viewport height for better mobile experience */
        font-size: 0.9375rem; /* Slightly larger for mobile readability */
    }
    
    .mapbox-result-item {
        padding: 1rem;
        min-height: 56px; /* Larger touch target */
    }
    
    .mapbox-result-item::before {
        width: 1.25rem;
        height: 1.25rem;
    }
    
    #billing_address_summary,
    #shipping_address_summary {
        padding: 1rem;
    }
    
    /* Larger input field on mobile */
    .mapbox-mobile-input {
        min-height: 48px !important;
        padding-top: 0.875rem !important;
        padding-bottom: 0.875rem !important;
    }
}

/* Loading state indicator */
.mapbox-loading {
    position: relative;
}

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

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

/* Focus styles for accessibility */
.mapbox-result-item:focus-visible {
    outline: 2px solid #10b981;
    outline-offset: -2px;
    background-color: #ecfdf5;
}

.mapbox-result-item:focus {
    outline: 2px solid #10b981;
    outline-offset: -2px;
    background-color: #ecfdf5;
}

/* Input focus state */
.mapbox-mobile-input:focus {
    outline: none;
    border-color: #10b981;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

/* Touch-friendly tap targets on mobile */
@media (hover: none) and (pointer: coarse) {
    .mapbox-result-item {
        min-height: 56px; /* 56px = 14 * 4px, good for touch */
        -webkit-tap-highlight-color: rgba(16, 185, 129, 0.1);
        tap-highlight-color: rgba(16, 185, 129, 0.1);
    }
    
    .mapbox-result-item:active {
        background-color: #d1fae5;
        transform: scale(0.98);
        transition: transform 0.1s ease, background-color 0.1s ease;
    }
    
    /* Improve text selection prevention on mobile */
    .mapbox-result-item {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
}

/* Smooth scrolling in results */
.mapbox-results {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #d1d5db #f9fafb;
}

.mapbox-results::-webkit-scrollbar {
    width: 0.5rem;
}

.mapbox-results::-webkit-scrollbar-track {
    background: #f9fafb;
    border-radius: 0.75rem;
}

.mapbox-results::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 0.75rem;
}

.mapbox-results::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Empty state */
.mapbox-no-results {
    padding: 2rem 1rem;
    text-align: center;
    color: #6b7280;
    font-size: 0.875rem;
}

/* Highlight matching text */
.mapbox-results mark {
    background-color: #fef3c7;
    color: inherit;
    font-weight: 600;
    padding: 0 0.125rem;
    border-radius: 0.125rem;
}

/* Prevent layout shift on mobile when keyboard appears */
@media (max-width: 768px) {
    .mapbox-search-container {
        position: relative;
        z-index: 1;
    }
    
    /* Ensure results don't cause horizontal scroll */
    .mapbox-results {
        max-height: 50vh;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
    }
    
    /* Better spacing on mobile */
    .mapbox-search-row label {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari */
    .mapbox-mobile-input {
        font-size: 16px !important;
        transform: translateZ(0); /* Force hardware acceleration */
    }
    
    .mapbox-results {
        -webkit-overflow-scrolling: touch;
        transform: translateZ(0);
    }
}

/* Search input enhancements */
.mapbox-search-container input[type="text"] {
    padding-right: 2.5rem;
}

.mapbox-search-container {
    position: relative;
}

/* Ensure parent container allows overflow */
.woocommerce-input-wrapper {
    position: relative;
    z-index: 1;
}

/* Manual toggle button styling */
.mapbox-manual-toggle {
    transition: all 0.15s ease;
}

.mapbox-manual-toggle:hover {
    text-decoration: underline;
}

.mapbox-manual-toggle:focus-visible {
    outline-offset: 2px;
    border-radius: 0.25rem;
}

