/* Mobile-Specific Autocomplete Optimizations */

/* Google Places Autocomplete Container Styling */
.pac-container {
    background-color: #fff;
    border-radius: 0 0 18px 18px;
    box-shadow: 0 18px 42px rgba(15, 28, 42, 0.14);
    border: none;
    margin-top: 6px;
    z-index: 9999 !important;
    font-family: 'Manrope', sans-serif;
    transition: box-shadow 0.25s ease;
    position: absolute !important;
    overflow: hidden;
}

.pac-container:hover {
    box-shadow: 0 20px 46px rgba(15, 28, 42, 0.16);
}

/* Mobile-specific autocomplete dropdown styling */
@media (max-width: 768px) {
    .pac-container {
        border-radius: 0 0 18px 18px;
        box-shadow: 0 18px 38px rgba(15, 28, 42, 0.16);
        margin-top: 4px;
        max-height: 50vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .pac-item {
        padding: 12px 18px !important;
        min-height: 42px !important;
        border-bottom: none !important;
        cursor: pointer;
        display: flex;
        align-items: center;
        line-height: 1.25;
        font-size: 14px !important;
        transition: background-color 0.2s ease;
        position: relative;
    }
    
    .pac-item:last-child {
        border-bottom: none !important;
    }
    
    .pac-item:hover,
    .pac-item.pac-item-selected {
        background-color: #f7f9fb !important;
        border-left: none !important;
        transform: none;
        box-shadow: none;
    }
    
    .pac-icon {
        display: none !important;
    }
    
    .pac-item-query {
        font-weight: 400 !important;
        color: #161c22 !important;
        font-size: 14px !important;
    }
    
    .pac-matched {
        font-weight: 500 !important;
        color: #161c22 !important;
    }
    
    .pac-item .pac-item-query .pac-matched + span {
        color: #5f6b76 !important;
        font-weight: 400 !important;
        font-size: 13px !important;
        display: block;
        margin-top: 1px;
    }
}

/* Desktop-specific styling to match form design */
@media (min-width: 769px) {
    .pac-container {
        border-radius: 0 0 18px 18px;
        box-shadow: 0 18px 36px rgba(15, 28, 42, 0.12);
        border: none;
        font-family: 'Manrope', sans-serif;
    }
    
    .pac-item {
        padding: 10px 16px !important;
        min-height: 38px !important;
        font-size: 14px !important;
        border-bottom: none !important;
        transition: background-color 0.2s ease;
        line-height: 1.2;
    }
    
    .pac-item:hover,
    .pac-item.pac-item-selected {
        background-color: #f7f9fb !important;
        border-left: none !important;
        transform: none;
    }

    .pac-icon {
        display: none !important;
    }

    .pac-item-query {
        font-weight: 400 !important;
        color: #161c22 !important;
        font-size: 14px !important;
    }

    .pac-matched {
        font-weight: 500 !important;
        color: #161c22 !important;
    }
}

/* Tablet-specific adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
    .pac-container {
        border-radius: 0 0 18px 18px;
        box-shadow: 0 18px 36px rgba(15, 28, 42, 0.14);
    }
    
    .pac-item {
        padding: 11px 16px !important;
        min-height: 40px !important;
        font-size: 14px !important;
    }
}

/* Input field enhancements for mobile */
@media (max-width: 768px) {
    /* Prevent zoom on iOS when focusing input fields */
    #pickupAddress,
    #deliveryAddress {
        font-size: 16px !important;
        -webkit-appearance: none;
        border-radius: 12px;
        padding: 14px 16px;
        border: 1px solid rgba(129, 149, 166, 0.24);
        transition: border-color 0.3s ease, box-shadow 0.3s ease;
    }
    
    /* Focus states for better mobile UX */
    #pickupAddress:focus,
    #deliveryAddress:focus {
        border-color: #007bff !important;
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1) !important;
        outline: none !important;
    }
    
    /* Loading state indicator */
    .autocomplete-loading {
        background-image: url('data:image/svg+xml;charset=utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><circle cx="10" cy="10" r="8" fill="none" stroke="%23007bff" stroke-width="2" stroke-dasharray="12.57 12.57" stroke-dashoffset="0"><animateTransform attributeName="transform" type="rotate" values="0 10 10;360 10 10" dur="1s" repeatCount="indefinite"/></circle></svg>') !important;
        background-repeat: no-repeat !important;
        background-position: right 16px center !important;
        background-size: 20px 20px !important;
        padding-right: 50px !important;
    }
}

/* Virtual keyboard handling */
@media (max-width: 768px) {
    /* Reset any positioning overrides and use default Google positioning */
    .pac-container {
        position: absolute !important;
        max-height: 40vh !important;
        overflow-y: auto !important;
        z-index: 9999 !important;
        /* Remove width and positioning overrides to let Google handle it */
    }
}

/* Orientation change handling */
@media (max-width: 768px) and (orientation: landscape) {
    .pac-container {
        max-height: 25vh !important; /* Even smaller in landscape mode */
    }
    
    .pac-item {
        padding: 10px 14px !important;
        min-height: 38px !important;
        font-size: 14px !important;
    }
}

/* High DPI displays (Retina) */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .pac-icon {
        background-size: contain !important;
    }
}

/* Dark mode support (if needed) */
@media (prefers-color-scheme: dark) {
    .pac-container {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .pac-item {
        border-bottom-color: #4a5568 !important;
        color: #e2e8f0 !important;
    }
    
    .pac-item:hover,
    .pac-item.pac-item-selected {
        background-color: #4a5568 !important;
        border-left-color: #63b3ed !important;
    }
    
    .pac-item-query {
        color: #e2e8f0 !important;
    }
    
    .pac-matched {
        color: #63b3ed !important;
    }
}

/* Accessibility improvements */
.pac-container {
    /* Ensure proper focus management */
    outline: none;
}

.pac-item {
    /* Improve accessibility for screen readers */
    role: option;
    aria-selected: false;
}

.pac-item.pac-item-selected {
    aria-selected: true;
}

/* Error state styling for mobile */
@media (max-width: 768px) {
    .autocomplete-error {
        margin: 12px 0;
        padding: 16px 20px;
        border-radius: 12px;
        font-size: 15px;
        line-height: 1.5;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    }
    
    .manual-entry-mode {
        border-left-width: 4px !important;
        padding-left: 20px !important;
    }
}

/* Animation for smooth transitions */
.pac-container {
    animation: fadeInDown 0.2s ease-out;
}

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

/* Enhanced visual feedback for dropdown items */
.pac-item {
    position: relative;
}

.pac-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 0;
    background-color: #007bff;
    transition: width 0.2s ease;
}

.pac-item:hover::before,
.pac-item.pac-item-selected::before {
    width: 3px;
}

/* Loading state for dropdown */
.pac-container.loading {
    opacity: 0.7;
}

.pac-container.loading::after {
    content: 'Loading suggestions...';
    display: block;
    padding: 12px 16px;
    text-align: center;
    color: #666;
    font-style: italic;
    font-size: 14px;
}

/* Empty state for dropdown */
.pac-container.empty::after {
    content: 'No addresses found. Try a different search.';
    display: block;
    padding: 12px 16px;
    text-align: center;
    color: #856404;
    font-style: italic;
    font-size: 14px;
    background-color: #fff3cd;
    border-radius: 4px;
    margin: 8px;
}

/* Touch feedback for better mobile interaction */
@media (max-width: 768px) {
    .pac-item {
        transition: background-color 0.15s ease, border-left 0.15s ease;
        -webkit-tap-highlight-color: rgba(0, 123, 255, 0.1);
    }
    
    .pac-item:active {
        background-color: #e3f2fd !important;
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
}
