/*!
 * ==========================================================
 * BA.UI Framework
 * BAAutocomplete Styles
 * Version : 1.0.0
 * ==========================================================
 */

/* Use the same CSS variables as ba-search-panel.css */

/* Container */
.ba-autocomplete {
    position: relative;
    width: 100%;
    font-family: var(--ba-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
}

/* Dropdown */
.ba-autocomplete__dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: auto;
    width: 210%;
    max-width: 500px;
    max-height: 320px;
    background: #ffffff !important;
    border: 1px solid #E5E7EB !important;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    display: none;
    animation: ba-autocomplete-slide-down 0.15s ease;
}

.ba-autocomplete__dropdown.is-open {
    display: block !important;
}

/* Mobile dropdown must always be visible when open */
.ba-autocomplete__dropdown.is-mobile.is-open {
    display: block !important;
}

@keyframes ba-autocomplete-slide-down {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* List */
.ba-autocomplete__list {
    list-style: none;
    margin: 0;
    padding: 4px;
}

/* List Item */
.ba-autocomplete__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background-color 0.15s ease;
    color: #374151 !important;
    background: transparent;
}

.ba-autocomplete__item:hover,
.ba-autocomplete__item.is-highlighted {
    background: #F3F4F6 !important;
}

.ba-autocomplete__item:active {
    background: #E5E7EB !important;
}

/* Item Icon */
.ba-autocomplete__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: #6B7280;
}

.ba-autocomplete__icon .ba-icon {
    width: 20px;
    height: 20px;
    color: inherit;
}

/* Item Text */
.ba-autocomplete__text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ba-autocomplete__primary {
    font-size: var(--ba-font-size-md, 14px);
    font-weight: var(--ba-font-weight-medium, 500);
    color: var(--ba-text-primary, #1F2937) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ba-autocomplete__secondary {
    font-size: var(--ba-font-size-sm, 12px);
    color: var(--ba-text-secondary, #6B7280) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Message States (Loading, No Results) */
.ba-autocomplete__message {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--ba-text-secondary, #6B7280);
    font-size: var(--ba-font-size-md, 14px);
    text-align: center;
}

.ba-autocomplete__loading {
    animation: ba-autocomplete-pulse 1.5s ease-in-out infinite;
}

@keyframes ba-autocomplete-pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.ba-autocomplete__no-results {
    color: #9CA3AF;
}

/* Input States */
.ba-autocomplete input {
    width: 100%;
}

.ba-autocomplete input:focus {
    outline: none;
}

/* Scrollbar Styling */
.ba-autocomplete__dropdown::-webkit-scrollbar {
    width: 6px;
}

.ba-autocomplete__dropdown::-webkit-scrollbar-track {
    background: #F9FAFB;
    border-radius: 3px;
}

.ba-autocomplete__dropdown::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

.ba-autocomplete__dropdown::-webkit-scrollbar-thumb:hover {
    background: #9CA3AF;
}

/* Item with Badge */
.ba-autocomplete__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    background: #EEF2FF;
    color: #3B82F6;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-left: auto;
    flex-shrink: 0;
}

/* Item with Label */
.ba-autocomplete__label {
    display: inline-flex;
    align-items: center;
    padding: 2px 6px;
    background: #F3F4F6;
    color: #6B7280;
    border-radius: 3px;
    font-size: 11px;
    margin-left: 4px;
}

/* Group Headers */
.ba-autocomplete__group {
    padding: 8px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Divider */
.ba-autocomplete__divider {
    height: 1px;
    background: #E5E7EB;
    margin: 4px 8px;
}

/* Disabled Item */
.ba-autocomplete__item.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Loading Spinner (optional) */
.ba-autocomplete__spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #E5E7EB;
    border-top-color: #3B82F6;
    border-radius: 50%;
    animation: ba-autocomplete-spin 0.6s linear infinite;
    margin-right: 8px;
}

@keyframes ba-autocomplete-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Compact Variant */
.ba-autocomplete--compact .ba-autocomplete__item {
    padding: 8px 12px;
    gap: 8px;
}

.ba-autocomplete--compact .ba-autocomplete__icon {
    font-size: 16px;
    width: 24px;
    height: 24px;
}

.ba-autocomplete--compact .ba-autocomplete__primary {
    font-size: 13px;
}

.ba-autocomplete--compact .ba-autocomplete__secondary {
    font-size: 11px;
}

/* Large Variant */
.ba-autocomplete--large .ba-autocomplete__item {
    padding: 14px 16px;
    gap: 14px;
}

.ba-autocomplete--large .ba-autocomplete__icon {
    font-size: 24px;
    width: 40px;
    height: 40px;
}

.ba-autocomplete--large .ba-autocomplete__primary {
    font-size: 16px;
}

.ba-autocomplete--large .ba-autocomplete__secondary {
    font-size: 13px;
}

/* Highlight Matching Text */
.ba-autocomplete__match {
    font-weight: 600;
    color: #3B82F6;
}

/* Error State */
.ba-autocomplete.is-error .ba-autocomplete__dropdown {
    border-color: #EF4444;
}

/* Success State */
.ba-autocomplete.is-success .ba-autocomplete__dropdown {
    border-color: #10B981;
}

/* Responsive - Mobile Bottom Sheet */
@media (max-width: 768px) {
    /* Mobile bottom sheet for autocomplete - hidden by default */
    .ba-autocomplete__dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 9999;
        border-radius: 20px 20px 0 0;
        max-height: 70vh;
        border: none;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        padding: 0;
        /* Keep hidden by default */
        display: none;
    }

    /* Only show when open - use flex for layout */
    .ba-autocomplete__dropdown.is-open {
        display: flex;
        flex-direction: column;
        animation: ba-autocomplete-slide-up 0.25s ease-out;
    }

    @keyframes ba-autocomplete-slide-up {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    /* Backdrop overlay */
    .ba-autocomplete.is-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 9998;
        animation: ba-fade-in 0.2s ease;
    }

    @keyframes ba-fade-in {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    /* Handle bar at top */
    .ba-autocomplete__dropdown::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #D1D5DB;
        border-radius: 2px;
        margin: 12px auto;
        flex-shrink: 0;
    }

    /* Search header in bottom sheet */
    .ba-autocomplete__header {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 0 16px 16px;
        border-bottom: 1px solid #E5E7EB;
        flex-shrink: 0;
    }

    .ba-autocomplete__header-input {
        flex: 1;
        height: 44px;
        padding: 0 16px;
        border: 1px solid #E5E7EB;
        border-radius: 12px;
        font-size: 16px;
        background: #F9FAFB;
    }

    .ba-autocomplete__header-input:focus {
        outline: none;
        border-color: #3B82F6;
        background: #ffffff;
    }

    .ba-autocomplete__header-close {
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: none;
        background: #F3F4F6;
        border-radius: 50%;
        cursor: pointer;
        color: #6B7280;
        flex-shrink: 0;
    }

    /* Results list */
    .ba-autocomplete__list {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .ba-autocomplete__item {
        padding: 14px 20px;
        gap: 14px;
        border-bottom: 1px solid #F3F4F6;
    }

    .ba-autocomplete__item:last-child {
        border-bottom: none;
    }

    .ba-autocomplete__icon {
        font-size: 20px;
        width: 32px;
        height: 32px;
    }

    .ba-autocomplete__primary {
        font-size: 15px;
    }

    .ba-autocomplete__secondary {
        font-size: 12px;
    }

    /* Loading and empty states */
    .ba-autocomplete__message {
        padding: 40px 20px;
        text-align: center;
    }

    /* Group headers */
    .ba-autocomplete__group-header {
        padding: 12px 20px 8px;
        font-size: 12px;
        font-weight: 600;
        color: #6B7280;
        background: #F9FAFB;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        position: sticky;
        top: 0;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .ba-autocomplete__dropdown {
        background: #1F2937;
        border-color: #374151;
    }

    .ba-autocomplete__item {
        color: #E5E7EB;
    }

    .ba-autocomplete__item:hover,
    .ba-autocomplete__item.is-highlighted {
        background: #374151;
    }

    .ba-autocomplete__primary {
        color: #F9FAFB;
    }

    .ba-autocomplete__secondary {
        color: #9CA3AF;
    }

    .ba-autocomplete__message {
        color: #9CA3AF;
    }

    .ba-autocomplete__dropdown::-webkit-scrollbar-track {
        background: #111827;
    }

    .ba-autocomplete__dropdown::-webkit-scrollbar-thumb {
        background: #4B5563;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .ba-autocomplete__dropdown {
        border: 2px solid currentColor;
    }

    .ba-autocomplete__item.is-highlighted {
        outline: 2px solid currentColor;
        outline-offset: -2px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .ba-autocomplete__dropdown {
        animation: none;
    }

    .ba-autocomplete__loading {
        animation: none;
    }
}

/* ==========================================================
 * MOBILE FULL-SCREEN MODAL STYLES
 * ========================================================== */

/* Modal Overlay */
.ba-autocomplete-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ba-autocomplete-overlay.is-visible {
    opacity: 1;
    visibility: visible;
}

/* Mobile Container - Full Screen */
.ba-autocomplete__mobile-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: #ffffff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(100%);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.ba-autocomplete__mobile-container.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Mobile Header */
.ba-autocomplete__mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #ffffff;
    border-bottom: 1px solid #E5E7EB;
    flex-shrink: 0;
}

.ba-autocomplete__mobile-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #374151;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease;
}

.ba-autocomplete__mobile-back:hover {
    background: #F3F4F6;
}

.ba-autocomplete__mobile-back:active {
    background: #E5E7EB;
}

/* Mobile Input Wrapper */
.ba-autocomplete__mobile-input-wrapper {
    flex: 1;
    min-width: 0;
}

.ba-autocomplete__mobile-input {
    width: 100%;
    height: 44px;
    padding: 0 16px;
    font-size: 16px;
    font-family: var(--ba-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif);
    color: #1F2937;
    background: #F9FAFB;
    border: 1px solid #E5E7EB;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ba-autocomplete__mobile-input:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.ba-autocomplete__mobile-input::placeholder {
    color: #9CA3AF;
}

/* Mobile Dropdown Adjustments */
.ba-autocomplete__mobile-container .ba-autocomplete__dropdown {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-width: none;
    max-height: none;
    flex: 1;
    border: none;
    border-radius: 0;
    box-shadow: none;
    display: block !important;
    overflow-y: auto;
}

.ba-autocomplete__mobile-container .ba-autocomplete__dropdown.is-open {
    display: block !important;
}

/* Mobile List Items */
.ba-autocomplete__mobile-container .ba-autocomplete__list {
    padding: 8px 0;
}

.ba-autocomplete__mobile-container .ba-autocomplete__item {
    padding: 14px 20px;
    min-height: 56px;
}

.ba-autocomplete__mobile-container .ba-autocomplete__primary {
    font-size: 15px;
}

.ba-autocomplete__mobile-container .ba-autocomplete__secondary {
    font-size: 13px;
}

.ba-autocomplete__mobile-container .ba-autocomplete__icon {
    width: 20px;
    height: 20px;
}

/* Mobile Loading/Message States */
.ba-autocomplete__mobile-container .ba-autocomplete__message {
    padding: 20px;
    text-align: center;
    font-size: 15px;
}

/* Hide mobile container elements on desktop (they are managed via JS) */
.ba-autocomplete__mobile-container {
    /* The container is added to body and managed by JS visibility */
}
