/* advanced-search.css - Advanced Search Bar - Versão otimizada v4.0
   CONSOLIDAÇÃO:
   - Barra de pesquisa unificada
   - Autocomplete dropdown otimizado
   - Resultados grid responsivo
   - Cores padronizadas com variáveis CSS
   - Modal flutuante consolidado
   - CORREÇÃO: Suporte para tela 360px
*/

/* ============================================ */
/* MAIN CONTAINER
/* ============================================ */
.advanced-search-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.search-wrapper {
    position: relative;
    width: 100%;
}

/* ============================================ */
/* SEARCH INPUT
/* ============================================ */
.advanced-search-input {
    width: 100%;
    padding: 5px 48px 5px 20px;
    font-size: 14px;
    border: 2px solid #ffffff;
    background: white;
    transition: all 0.3s ease;
    outline: none;
    font-family: inherit;
    border-radius:20px;
}

.advanced-search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(145, 0, 133, 0.1);
}

/* Mobile */
@media (max-width: 768px) {
    .advanced-search-input {
        padding: 6px 48px 6px 44px !important;
        font-size: 14px !important;
    }
}

@media (max-width: 360px) {
    .advanced-search-input {
        padding: 4px 36px 4px 32px !important;
        font-size: 11px !important;
    }
}

/* ============================================ */
/* CLEAR SEARCH BUTTON
/* ============================================ */
.clear-search-btn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 2;
}

.clear-search-btn:hover {
    color: var(--danger);
}

.clear-search-btn.hidden {
    display: none;
}

@media (max-width: 768px) {
    .clear-search-btn {
        right: 12px;
        width: 32px;
        height: 32px;
    }
}

@media (max-width: 360px) {
    .clear-search-btn {
        right: 8px;
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
}

/* ============================================ */
/* SEARCH ICON (Inline)
/* ============================================ */
.search-icon-inline {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-light);
    font-size: 16px;
    pointer-events: none;
    z-index: 2;
}

@media (max-width: 768px) {
    .search-icon-inline {
        left: 14px !important;
        font-size: 16px !important;
    }
}

@media (max-width: 360px) {
    .search-icon-inline {
        left: 8px !important;
        font-size: 11px !important;
    }
}

/* Icon button (alternative) */
.search-icon-btn {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 18px;
    padding: 4px;
}

/* ============================================ */
/* AUTOCOMPLETE DROPDOWN
/* ============================================ */
.autocomplete-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-height: 350px;
    overflow-y: auto;
    display: none;
    border: 1px solid #f0f0f0;
}

.autocomplete-dropdown.show {
    display: block;
    animation: dropdownFadeIn 0.2s ease;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile */
@media (max-width: 768px) {
    .autocomplete-dropdown {
        max-height: 60vh;
        width: 100%;
        left: 0;
        right: 0;
    }
}

@media (max-width: 360px) {
    .autocomplete-dropdown {
        max-height: 50vh;
    }
}

/* Dropdown Sections */
.dropdown-section {
    padding: 12px 0;
    border-bottom: 1px solid #f5f5f5;
}

.dropdown-section:last-child {
    border-bottom: none;
}

.dropdown-section-title {
    padding: 0 16px 8px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #999;
    letter-spacing: 0.5px;
}

@media (max-width: 768px) {
    .dropdown-section-title {
        font-size: 10px;
    }
}

@media (max-width: 360px) {
    .dropdown-section-title {
        font-size: 9px;
        padding: 0 12px 6px;
    }
}

/* Autocomplete Items */
.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.autocomplete-item:hover {
    background: #f8f9fa;
}

.autocomplete-item.active {
    background: #f0f2f5;
}

.autocomplete-icon {
    width: 32px;
    height: 32px;
    background: #f5f5f5;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    flex-shrink: 0;
}

.autocomplete-icon i {
    font-size: 16px;
}

.autocomplete-content {
    flex: 1;
    min-width: 0;
}

.autocomplete-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.autocomplete-subtitle {
    font-size: 11px;
    color: #999;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.autocomplete-price {
    font-size: 13px;
    font-weight: 600;
    color: var(--success);
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .autocomplete-item {
        padding: 10px 12px;
    }
    
    .autocomplete-title {
        font-size: 13px;
    }
}

@media (max-width: 360px) {
    .autocomplete-item {
        padding: 8px 10px;
    }
    
    .autocomplete-title {
        font-size: 11px;
    }
}

/* Popular Terms */
.popular-term {
    background: #f5f5f5;
    border-radius: 20px;
    padding: 8px 16px;
    margin: 0 8px 8px 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}

.popular-term:hover {
    background: var(--primary);
    color: white;
}

.popular-term i {
    font-size: 12px;
}

@media (max-width: 768px) {
    .popular-term {
        padding: 6px 12px;
        font-size: 12px;
    }
}

@media (max-width: 360px) {
    .popular-term {
        padding: 4px 10px;
        font-size: 10px;
    }
}

/* Search History */
.search-history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-history-item:hover {
    background: #f8f9fa;
}

.search-history-item .term {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.search-history-item .delete-history {
    opacity: 0;
    background: none;
    border: none;
    color: #999;
    cursor: pointer;
    padding: 4px 8px;
    transition: opacity 0.2s;
}

.search-history-item:hover .delete-history {
    opacity: 1;
}

.delete-history:hover {
    color: var(--danger);
}

/* ============================================ */
/* SEARCH RESULTS HEADER
/* ============================================ */
.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.results-count {
    font-size: 14px;
    color: var(--gray);
}

.results-count strong {
    color: var(--dark);
    font-weight: 600;
}

/* ============================================ */
/* SEARCH RESULTS GRID
/* ============================================ */
.search-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}

@media (max-width: 768px) {
    .search-results-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .search-results-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* ============================================ */
/* SEARCH RESULT CARD
/* ============================================ */
.search-result-card {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: 1px solid #f0f0f0;
}

.search-result-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.1);
}

.result-card-image {
    position: relative;
    height: 180px;
    overflow: hidden;
    background: #f5f7fa;
}

.result-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.search-result-card:hover .result-card-image img {
    transform: scale(1.05);
}

.result-card-info {
    padding: 14px;
}

.result-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 6px;
    line-height: 1.4;
}

.result-card-title mark {
    background: #fff3cd;
    color: #856404;
    padding: 0 2px;
    border-radius: 3px;
    font-weight: 600;
}

.result-card-price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--success);
    margin-bottom: 6px;
}

.result-card-price::before {
    content: "R$ ";
    font-size: 0.7rem;
    font-weight: normal;
}

.result-card-location {
    font-size: 0.7rem;
    color: #999;
    display: flex;
    align-items: center;
    gap: 4px;
}

.result-card-location i {
    font-size: 10px;
}

.result-card-desc {
    font-size: 0.7rem;
    color: #666;
    margin-top: 8px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.result-card-desc mark {
    background: #fff3cd;
    color: #856404;
    padding: 0 2px;
    border-radius: 3px;
}

.result-card-date {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    color: white;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 20px;
}

@media (max-width: 768px) {
    .result-card-image {
        height: 140px;
    }
    
    .result-card-info {
        padding: 10px;
    }
    
    .result-card-title {
        font-size: 0.85rem;
    }
    
    .result-card-price {
        font-size: 0.95rem;
    }
}

@media (max-width: 360px) {
    .result-card-image {
        height: 120px;
    }
    
    .result-card-info {
        padding: 8px;
    }
    
    .result-card-title {
        font-size: 0.75rem;
    }
    
    .result-card-price {
        font-size: 0.85rem;
    }
}

/* ============================================ */
/* EMPTY & LOADING STATES
/* ============================================ */
.search-empty {
    text-align: center;
    padding: 60px 20px;
    background: white;
    border-radius: 20px;
    grid-column: 1 / -1;
}

.search-empty i {
    font-size: 48px;
    color: #ccc;
    margin-bottom: 16px;
}

.search-empty p {
    font-size: 1rem;
    color: #666;
    margin-bottom: 8px;
}

.search-empty span {
    font-size: 0.8rem;
    color: #999;
}

.search-loading {
    text-align: center;
    padding: 60px 20px;
    grid-column: 1 / -1;
}

.search-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f0f0f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================ */
/* FLOATING RESULTS MODAL
/* ============================================ */
.search-results-floating {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 1200px;
    max-height: 80vh;
    background: white;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    z-index: 2000;
    overflow-y: auto;
    padding: 24px;
}

.search-results-floating .search-results-header {
    position: sticky;
    top: 0;
    background: white;
    padding-bottom: 16px;
    border-bottom: 1px solid #f0f0f0;
    margin-bottom: 20px;
    z-index: 10;
}

.search-results-floating .search-results-header h3 {
    font-size: 1.2rem;
    margin: 0;
}

.search-results-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1999;
}

.close-results-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: #f5f5f5;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-results-btn:hover {
    background: #e0e0e0;
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .search-results-floating {
        width: 95%;
        padding: 16px;
        max-height: 85vh;
    }
    
    .search-results-floating .search-results-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 360px) {
    .search-results-floating {
        width: 98%;
        padding: 12px;
    }
}

/* ============================================ */
/* TOOLS WRAPPER INTEGRATION
/* ============================================ */
.tools-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
}

.tools-wrapper .advanced-search-container {
    flex: 2;
    min-width: 250px;
    margin: 0 !important;
}

@media (max-width: 768px) {
    .tools-wrapper .advanced-search-container {
        width: 100%;
        min-width: auto;
    }
}

/* ============================================ */
/* GLOBAL VISIBILITY
/* ============================================ */
.advanced-search-container {
    display: block !important;
}

/* Hide old search bars */
.header-search,
.categoria-search-bar:not(.advanced-search-container .categoria-search-bar),
.search-mini:not(.loja-nav .search-mini),
input[type="search"]:not(.advanced-search-input) {
    /* Commented out to avoid breaking existing layouts */
    /* display: none !important; */
}

/* ============================================ */
/* SEARCH HISTORY MODAL
/* ============================================ */
.search-history-modal .modal-content {
    max-width: 400px;
}

.history-list {
    max-height: 400px;
    overflow-y: auto;
}

.empty-history {
    text-align: center;
    padding: 40px;
    color: #999;
}