/* ============================================
   HIERARCHICAL ADDRESS SELECTOR STYLES
   ============================================ */

.hierarchical-address-selector {
    width: 100%;
    position: relative;
}

/* Chips + Search Wrapper */
.address-chips-wrapper {
    position: relative;
    width: 100%;
    min-height: 48px;
    padding: 0.5rem;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    background: #fff;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
    margin-bottom: 0;
}

.address-chips-wrapper:focus-within {
    border-color: #f4a261;
    box-shadow: 0 0 0 3px rgba(244, 162, 97, 0.1);
}

/* Address Selector Display (clickable div replaces input) */
.address-selector-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    outline: none;
}

.address-selector-display:hover {
    background: rgba(244, 162, 97, 0.05);
    border-radius: 8px;
}

.address-selector-display:focus {
    background: rgba(244, 162, 97, 0.08);
    border-radius: 8px;
}

.address-placeholder {
    color: #999;
    font-size: 0.9375rem;
    font-weight: 500;
}

.address-dropdown-arrow {
    width: 20px;
    height: 20px;
    color: #666;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.address-selector-display[aria-expanded="true"] .address-dropdown-arrow {
    transform: rotate(180deg);
    color: #f4a261;
}

/* Address Chips */
.address-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.address-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    background: linear-gradient(135deg, #f4a261, #e76f51);
    color: #fff;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(244, 162, 97, 0.2);
}

.address-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(244, 162, 97, 0.3);
}

.chip-text {
    white-space: nowrap;
}

.chip-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chip-remove:hover {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.chip-remove svg {
    width: 12px;
    height: 12px;
    color: #fff;
}

/* Search Input inside chips wrapper */
.address-search-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    min-width: 150px;
}

.address-chips-wrapper .address-search-input {
    flex: 1;
    min-width: 0;
    padding: 0.375rem 0.5rem;
    font-size: 0.9375rem;
    border: none;
    outline: none;
    background: transparent;
    font-family: 'Quicksand', sans-serif;
}

.address-chips-wrapper .address-search-input::placeholder {
    color: #999;
}

.address-search-enable-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: #f4a261;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.address-search-enable-btn:hover {
    background: #e76f51;
    transform: scale(1.1);
}

.address-search-enable-btn svg {
    width: 16px;
    height: 16px;
    color: #fff;
}

.address-search-enable-btn:active {
    transform: scale(0.95);
}

/* Dropdown - positioned relative to chips-wrapper */
.address-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    right: 0;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 400px;
    z-index: 10001; /* Higher than modal overlay (10000) */
    animation: dropdownSlideIn 0.2s ease;
    
    /* Copy from modal - exact same structure */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateZ(0);
    
    /* Prevent overscroll propagation */
    overscroll-behavior: contain;
}

/* Mobile: Taller dropdown for easier scrolling */
@media (max-width: 768px) {
    .address-dropdown {
        max-height: 60vh;
    }
}

/* Search input inside dropdown */
.address-dropdown-search {
    position: relative;
    padding: 0.75rem;
    border-bottom: 1px solid #f0f0f0;
    background: #fafafa;
    flex-shrink: 0;
}

.address-dropdown-search .search-icon-inside {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: #999;
    pointer-events: none;
    z-index: 1;
}

.address-dropdown-search .address-search-input {
    width: 100%;
    padding: 0.625rem 0.75rem 0.625rem 2.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
}

.address-dropdown-search .address-search-input:focus {
    border-color: #f4a261;
    box-shadow: 0 0 0 2px rgba(244, 162, 97, 0.1);
}

.address-dropdown-content {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem;
    
    /* Force browser to treat like native scrolling */
    -webkit-overflow-scrolling: touch;
    
    /* Prevent overscroll bounce at top/bottom */
    overscroll-behavior-y: contain;
}


.address-dropdown.hidden {
    display: none;
}

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

.address-dropdown-header {
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #666;
    border-bottom: 1px solid #f0f0f0;
    margin: -0.5rem -0.5rem 0.5rem -0.5rem;
    background: #fafafa;
    border-radius: 10px 10px 0 0;
}

.address-dropdown-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.address-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
    background: #fff;
}

.address-list-item:hover {
    background: #fff0f5;
}

/* Disable hover transform on mobile for better performance */
@media (hover: hover) {
    .address-list-item:hover {
        transform: translateX(4px);
    }
}

.address-list-item .item-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    color: #ff6b9d;
}

.address-list-item .item-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.address-list-item .item-text {
    flex: 1;
    font-size: 0.9375rem;
    color: #333;
}

.address-list-item .item-arrow {
    font-size: 1.25rem;
    color: #ff6b9d;
    flex-shrink: 0;
}

/* Search Results */
.address-dropdown-results {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.address-result-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
    background: #fff;
}

.address-result-item:hover {
    background: #fff0f5;
}

/* Disable hover transform on mobile for better performance */
@media (hover: hover) {
    .address-result-item:hover {
        transform: translateX(4px);
    }
}

.address-result-item .result-icon {
    width: 1.25rem;
    height: 1.25rem;
    flex-shrink: 0;
    color: #ff6b9d;
}

.address-result-item .result-icon svg {
    width: 100%;
    height: 100%;
    display: block;
}

.address-result-item .result-content {
    flex: 1;
    min-width: 0;
}

.address-result-item .result-main {
    font-size: 0.9375rem;
    color: #333;
    font-weight: 500;
    margin-bottom: 0.125rem;
}

.address-result-item .result-main mark {
    background: #fff3cd;
    color: #856404;
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
    font-weight: 600;
}

.address-result-item .result-sub {
    font-size: 0.8125rem;
    color: #999;
}

.address-result-item .result-arrow {
    font-size: 1.25rem;
    color: #ff6b9d;
    flex-shrink: 0;
}

.address-dropdown-empty {
    padding: 2rem 1rem;
    text-align: center;
    color: #999;
    font-size: 0.9375rem;
}

/* Breadcrumb - Hidden, using input display instead */
.address-breadcrumb {
    display: none !important;
}

/* Street Input */
.address-street-wrapper {
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.address-street-wrapper.hidden {
    display: none;
}

/* Address Display */
.address-display {
    margin-top: 0.75rem;
    padding: 1rem;
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-radius: 10px;
    border: 1px solid #bae6fd;
}

.address-display.hidden {
    display: none;
}

.address-display-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #0369a1;
    margin-bottom: 0.5rem;
}

.address-display-text {
    font-size: 0.9375rem;
    color: #333;
    line-height: 1.5;
}

/* Scrollbar Styling */
.address-dropdown::-webkit-scrollbar {
    width: 8px;
}

.address-dropdown::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 10px;
}

.address-dropdown::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 10px;
}

.address-dropdown::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .address-search-input {
        font-size: 1rem;
        padding: 0.875rem 2.5rem 0.875rem 0.875rem;
    }
    
    /* Remove duplicate dropdown styles - moved above */
    
    .address-list-item,
    .address-result-item {
        padding: 1rem; /* Larger touch targets */
        min-height: 48px; /* Minimum touch target size */
    }
    
    .address-list-item .item-text,
    .address-result-item .result-main {
        font-size: 0.9375rem;
    }
    
    .address-result-item .result-sub {
        font-size: 0.8125rem;
    }
    
    .breadcrumb-items {
        font-size: 0.8125rem;
    }
}

/* Loading State */
.address-dropdown-loading {
    padding: 2rem 1rem;
    text-align: center;
    color: #999;
    font-size: 0.9375rem;
}

/* Keyboard Navigation Focus */
.address-list-item.keyboard-focused,
.address-result-item.keyboard-focused {
    background: #fff0f5;
    outline: 2px solid #ff6b9d;
    outline-offset: -2px;
    transform: translateX(4px);
}

/* Accessibility */
.address-list-item:focus,
.address-result-item:focus,
.breadcrumb-item:focus {
    outline: 2px solid #ff6b9d;
    outline-offset: 2px;
}

/* Remove unused animation classes */

/* Body scroll lock when address dropdown is open (cart page only, NOT in modal) */
body.address-dropdown-open:not(.modal-open) {
    /* DON'T use overflow: hidden - it prevents dropdown from scrolling! */
    /* Use position: fixed instead to lock scroll but allow child elements to scroll */
    position: fixed;
    width: 100%;
    overflow-y: scroll; /* Keep scrollbar space */
}

html.address-dropdown-open:not(.modal-open) {
    /* Prevent iOS Safari bounce */
    overflow: hidden;
}

/* When dropdown is inside modal, keep it simple with absolute positioning */
.address-modal .address-dropdown {
    /* Increase max-height to show more items */
    max-height: 350px;
}

/* Mobile: Make dropdown taller in modal - calculate based on available space */
@media (max-width: 768px) {
    .address-modal .address-dropdown {
        /* Calculate: 100dvh - header - footer - padding - search input - extra spacing */
        max-height: calc(100dvh - 60px - 70px - 60px - 60px);
        /* Fallback for older browsers */
        max-height: calc(100vh - 60px - 70px - 60px - 60px);
        /* Add margin bottom for spacing */
        margin-bottom: 1rem;
    }
}
