/**
 * Search Autocomplete Styles
 * Mobile-first responsive design
 */

/* Wrapper */
.search-autocomplete-wrapper {
    position: relative;
    width: 100%;
}

/* Size variants */
.search-sm .form-control {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
}

.search-md .form-control {
    font-size: 1rem;
}

.search-lg .form-control {
    font-size: 1.125rem;
    padding: 0.75rem 1rem;
}

/* Input focus state */
.search-autocomplete-input:focus {
    border-color: #377dff;
    box-shadow: 0 0 0 0.2rem rgba(55, 125, 255, 0.25);
}

/* Results container */
.autocomplete-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1050;
    display: none;
    background: #fff;
    border: 1px solid #e7eaf3;
    border-top: none;
    border-radius: 0 0 0.3125rem 0.3125rem;
    box-shadow: 0 0.5rem 1rem rgba(140, 152, 164, 0.175);
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.autocomplete-results.show {
    display: block;
}

/* List */
.autocomplete-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* Item */
.autocomplete-item {
    border-bottom: 1px solid #f1f1f1;
    cursor: pointer;
}

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

.autocomplete-link {
    display: block;
    padding: 0.75rem 1rem;
    color: #1e2022;
    text-decoration: none;
    transition: background-color 0.15s ease-in-out;
}

.autocomplete-link:hover {
    text-decoration: none;
    color: #1e2022;
}

.autocomplete-item:hover .autocomplete-link,
.autocomplete-item.active .autocomplete-link {
    background-color: #f8f9fa;
    color: #377dff;
}

.autocomplete-item.active .autocomplete-link {
    background-color: #e7f1ff;
}

/* Label and meta */
.autocomplete-label {
    display: block;
    font-weight: 500;
    line-height: 1.4;
    word-break: break-word;
}

.autocomplete-label mark {
    background-color: #fff3cd;
    padding: 0;
    font-weight: 600;
    border-radius: 2px;
}

.autocomplete-meta {
    display: block;
    font-size: 0.75rem;
    margin-top: 0.25rem;
    color: #8c98a4;
}

/* Loading */
.autocomplete-loading {
    padding: 1rem;
    text-align: center;
    color: #8c98a4;
}

/* Empty state */
.autocomplete-empty {
    padding: 1rem;
    text-align: center;
    color: #8c98a4;
    font-size: 0.875rem;
}

.autocomplete-empty i {
    margin-right: 0.5rem;
}

/* View all results link */
.autocomplete-view-all {
    border-top: 1px solid #e7eaf3;
    background-color: #f8f9fa;
}

.autocomplete-view-all-link {
    display: block;
    padding: 0.75rem 1rem;
    text-align: center;
    color: #377dff;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s ease-in-out;
}

.autocomplete-view-all-link:hover {
    background-color: #e7f1ff;
    color: #2d6cd9;
    text-decoration: none;
}

.autocomplete-view-all-link i {
    margin-right: 0.5rem;
}

/* Badge styles (kept for potential other uses) */
.badge-soft-primary {
    background-color: rgba(55, 125, 255, 0.1);
    color: #377dff;
}

.badge-soft-secondary {
    background-color: rgba(113, 134, 157, 0.1);
    color: #555;
}

/* Sidebar list styles */
.sidebar-list .list-group-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.8rem;
    border: none;
    cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,0.05);
    color: #333;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.sidebar-list .list-group-item:hover {
    background-color: rgba(55, 125, 255, 0.05);
    color: #377dff;
}

.sidebar-list .list-group-item:last-child {
    border-bottom: none;
}

.sidebar-list .badge {
    font-size: 1rem;
    font-weight: 500;
    padding: 0.35em 0.65em;
    border-radius: 50rem;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

/* Screen reader only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Form styling */
.search-form .input-group {
    width: 100%;
}

.search-form .btn-primary {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Mobile optimizations */
@media (max-width: 767.98px) {
    .autocomplete-results {
        max-height: 50vh;
        border-radius: 0;
        position: fixed;
        left: 0;
        right: 0;
        top: auto;
        border-left: none;
        border-right: none;
    }

    .autocomplete-link {
        padding: 1rem;
    }

    .autocomplete-label {
        font-size: 1rem;
    }

    /* Larger touch targets */
    .search-autocomplete-input {
        font-size: 16px !important; /* Prevent iOS zoom */
        min-height: 44px;
    }

    .search-lg .search-autocomplete-input {
        min-height: 52px;
    }

    .search-form .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Filtri su mobile */
    .search-active-filters {
        padding: 0.5rem 0;
    }

    .search-active-filters .badge {
        display: inline-block;
        margin-top: 0.25rem;
    }
}

/* Tablet */
@media (min-width: 768px) and (max-width: 991.98px) {
    .autocomplete-results {
        max-height: 55vh;
    }
}

/* Desktop */
@media (min-width: 992px) {
    .autocomplete-results {
        max-height: 400px;
    }

    .search-lg .autocomplete-results {
        max-height: 450px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .autocomplete-item.active .autocomplete-link {
        outline: 2px solid currentColor;
        outline-offset: -2px;
    }

    .autocomplete-label mark {
        background-color: yellow;
        color: black;
    }

    .autocomplete-results {
        border-width: 2px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .autocomplete-link {
        transition: none;
    }
}

/* Dark mode support (se il sito lo supporta in futuro) */
@media (prefers-color-scheme: dark) {
    /* Placeholder per futura implementazione dark mode */
}

/* Header specific styling */
.navbar .search-autocomplete-wrapper {
    min-width: 200px;
}

@media (min-width: 992px) {
    .navbar .search-autocomplete-wrapper {
        min-width: 280px;
    }
}

/* Homepage hero search */
.search-lg.search-autocomplete-wrapper {
    max-width: 600px;
    margin: 0 auto;
}

@media (max-width: 767.98px) {
    .search-lg.search-autocomplete-wrapper {
        max-width: 100%;
    }
}
