/**
 * CSS DEL BUSCADOR AVANZADO
 * Sistema de búsqueda inteligente con autocompletado, voz y resultados
 * Fecha: 2025-10-15
 */

/* ============================================
   MODAL DEL BUSCADOR
   ============================================ */
#modal-buscador {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

#modal-buscador.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-buscador-content {
    background: white;
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 700px;
    min-height: 500px;
    max-height: 90vh;
    overflow: visible;
    position: relative;
    animation: slideDown 0.3s ease;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

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

.modal-buscador-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    transition: color 0.2s ease;
    z-index: 10;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
}

.modal-buscador-close:hover {
    color: #333;
}

/* ============================================
   CONTENEDOR PRINCIPAL DEL BUSCADOR
   ============================================ */
.buscador-avanzado-container {
    position: relative;
    z-index: 1000;
    width: 100%;
    max-width: 650px;
    margin: 0px auto;
    margin-top: -150px;
}

/* Cuando está dentro del modal */
#modal-buscador .buscador-avanzado-container {
    margin-top: 0;
    max-width: 100%;
}

/* Estilos para el formulario del modal - idénticos al normal */
#searchFormModal {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border-radius: 50px;
    padding: 8px 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease;
}

#searchFormModal:focus-within {
    box-shadow: 0 6px 30px rgba(100, 115, 207, 0.25);
}

#searchInputModal {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    padding: 12px 10px;
    background: transparent;
    color: #333;
}

#searchInputModal::placeholder {
    color: #999;
}

#voiceSearchBtnModal {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    font-size: 22px;
    color: #6473cf;
    transition: transform 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

#voiceSearchBtnModal:hover {
    transform: scale(1.1);
    color: #5462b5;
}

#voiceSearchBtnModal.listening {
    color: #ff4444;
    animation: pulse 1s infinite;
}

#searchSubmitBtnModal {
    background: linear-gradient(135deg, #6473cf 0%, #5462b5 100%);
    color: #fff;
    border: none;
    padding: 12px 28px;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(100, 115, 207, 0.3);
}

#searchSubmitBtnModal:hover {
    background: linear-gradient(135deg, #5462b5 0%, #4351a3 100%);
    box-shadow: 0 5px 15px rgba(100, 115, 207, 0.4);
    transform: translateY(-1px);
}

#searchSubmitBtnModal:active {
    transform: translateY(0);
}

/* Sugerencias del modal - posición relativa dentro del modal */
#suggestionsListModal {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 100%;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    list-style: none;
    margin: 0;
    padding: 8px 0;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 10;
    display: none;
}

#suggestionsListModal.active {
    display: block;
}

#suggestionsListModal li {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #f0f0f0;
}

#suggestionsListModal li:last-child {
    border-bottom: none;
}

#suggestionsListModal li:hover {
    background: #f8f9ff;
}

#suggestionsListModal li .sugerencia-icono {
    font-size: 20px;
    flex-shrink: 0;
}

#suggestionsListModal li .sugerencia-texto {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#suggestionsListModal li .sugerencia-titulo {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#suggestionsListModal li .sugerencia-subtitulo {
    font-size: 13px;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#suggestionsListModal li.loading {
    justify-content: center;
    color: #999;
    font-size: 14px;
}

/* ============================================
   FORMULARIO DE BÚSQUEDA
   ============================================ */
#searchForm {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    border-radius: 50px;
    padding: 8px 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease;
}

#searchForm:focus-within {
    box-shadow: 0 6px 30px rgba(100, 115, 207, 0.25);
}

/* Icono de lupa */
.search-icon {
    font-size: 20px;
    color: #6473cf;
    flex-shrink: 0;
}

/* Input de búsqueda */
#searchInput {
    flex: 1;
    border: none;
    outline: none;
    font-size: 16px;
    padding: 12px 10px;
    background: transparent;
    color: #333;
}

#searchInput::placeholder {
    color: #999;
}

/* Botón de voz */
#voiceSearchBtn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    font-size: 22px;
    color: #6473cf;
    transition: transform 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

#voiceSearchBtn:hover {
    transform: scale(1.1);
    color: #5462b5;
}

#voiceSearchBtn.listening {
    color: #ff4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.15); }
}

/* Botón de búsqueda */
#searchSubmitBtn {
    background: linear-gradient(135deg, #6473cf 0%, #5462b5 100%);
    color: #fff;
    border: none;
    padding: 12px 28px;
    border-radius: 50px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 3px 10px rgba(100, 115, 207, 0.3);
}

#searchSubmitBtn:hover {
    background: linear-gradient(135deg, #5462b5 0%, #4351a3 100%);
    box-shadow: 0 5px 15px rgba(100, 115, 207, 0.4);
    transform: translateY(-1px);
}

#searchSubmitBtn:active {
    transform: translateY(0);
}

/* ============================================
   LISTA DE SUGERENCIAS (AUTOCOMPLETADO)
   ============================================ */
#suggestionsList {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    max-width: 650px;
    background: #fff;
    border-radius: 15px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    list-style: none;
    margin: 0;
    padding: 8px 0;
    max-height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 120050 !important;
    display: none;
    pointer-events: none;
}

#suggestionsList.active {
    display: block;
    pointer-events: auto;
}

/* Overlay blanco para el modal de sugerencias */
#suggestionsList::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #fff;
    z-index: -1;
    opacity: 0;
    transition: opacity 0.2s ease;
}

#suggestionsList.active::before {
    opacity: 1;
}

#suggestionsList li {
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid #f0f0f0;
}

#suggestionsList li:last-child {
    border-bottom: none;
}

#suggestionsList li:hover {
    background: #f8f9ff;
}

#suggestionsList li .sugerencia-icono {
    font-size: 20px;
    flex-shrink: 0;
}

#suggestionsList li .sugerencia-texto {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

#suggestionsList li .sugerencia-titulo {
    font-size: 15px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#suggestionsList li .sugerencia-subtitulo {
    font-size: 13px;
    color: #777;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Loading en sugerencias */
#suggestionsList li.loading {
    justify-content: center;
    color: #999;
    font-size: 14px;
}

/* ============================================
   MODAL DE SELECCIÓN DE BARRIOS
   ============================================ */
#modalBarrios {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 120000 !important;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

#modalBarrios.active {
    display: flex;
}

.modal-barrios-content {
    background: #fff;
    border-radius: 20px;
    padding: 30px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    animation: modalSlideIn 0.3s ease;
    position: relative;
    z-index: 120010;
}

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

.modal-barrios-header {
    text-align: center;
    margin-bottom: 25px;
}

.modal-barrios-header h3 {
    font-size: 24px;
    color: #333;
    margin-bottom: 8px;
}

.modal-barrios-header p {
    font-size: 14px;
    color: #777;
}

#listaBarrios {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.barrio-item {
    background: #f8f9ff;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 15px 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.barrio-item:hover {
    background: #eef0ff;
    border-color: #6473cf;
    transform: translateX(5px);
}

.barrio-item.toda-ciudad {
    background: linear-gradient(135deg, #6473cf 0%, #5462b5 100%);
    color: #fff;
    border-color: #6473cf;
    font-weight: 600;
}

.barrio-item.toda-ciudad:hover {
    background: linear-gradient(135deg, #5462b5 0%, #4351a3 100%);
    transform: scale(1.02);
}

.barrio-item .barrio-icono {
    font-size: 22px;
}

.barrio-item .barrio-info {
    flex: 1;
}

.barrio-item .barrio-nombre {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 3px;
}

.barrio-item .barrio-contador {
    font-size: 13px;
    opacity: 0.8;
}

.barrio-item.toda-ciudad .barrio-contador {
    color: #fff;
}

/* Botón cerrar modal */
.modal-barrios-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #999;
    transition: color 0.2s ease;
}

.modal-barrios-close:hover {
    color: #333;
}

/* ============================================
   MODAL DE RESULTADOS
   ============================================ */
#modalResultados {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999999 !important;
    backdrop-filter: blur(3px);
    overflow-y: auto;
    overflow-x: hidden;
    pointer-events: auto;
    padding: 0;
}

#modalResultados.active {
    display: flex;
    align-items: flex-start;
    justify-content: center;
}

body.modal-buscador-activo,
body:has(#modalResultados.active),
body:has(#modalBarrios.active),
body:has(#modal-buscador.active) {
    overflow: hidden;
    touch-action: none;
}

body:has(#modalResultados.active),
body:has(#modalBarrios.active),
body:has(#modal-buscador.active) {
    overflow: hidden;
    touch-action: none;
}

.modal-resultados-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    padding: 40px 20px;
}

.modal-resultados-content {
    background: #fff;
    border-radius: 20px;
    padding: 30px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
    animation: modalFadeIn 0.3s ease;
    position: relative;
    z-index: 120010;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-resultados-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.modal-resultados-titulo h3 {
    font-size: 24px;
    color: #333;
    margin-bottom: 5px;
}

.modal-resultados-subtitulo {
    font-size: 14px;
    color: #777;
}

.modal-resultados-close {
    background: #f0f0f0;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.modal-resultados-close:hover {
    background: #e0e0e0;
    color: #333;
    transform: rotate(90deg);
}

/* Contenedor de fichas en resultados */
#contenedorResultados {
    margin-bottom: 30px;
}

#contenedorResultados.loading {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

#contenedorResultados .spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f0f0f0;
    border-top-color: #6473cf;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Mensaje sin resultados */
.sin-resultados {
    text-align: center;
    padding: 60px 20px;
}

.sin-resultados .icono {
    font-size: 60px;
    margin-bottom: 15px;
}

.sin-resultados h4 {
    font-size: 20px;
    color: #333;
    margin-bottom: 10px;
}

.sin-resultados p {
    font-size: 15px;
    color: #777;
}

/* ============================================
   PAGINACIÓN ESTILO GOOGLE
   ============================================ */
.paginacion-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 20px 0;
}

.paginacion-btn {
    background: #fff;
    border: 1px solid #ddd;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: #333;
    transition: all 0.2s ease;
    min-width: 38px;
    text-align: center;
}

.paginacion-btn:hover:not(.disabled):not(.active) {
    background: #f8f9ff;
    border-color: #6473cf;
    color: #6473cf;
}

.paginacion-btn.active {
    background: #6473cf;
    color: #fff;
    border-color: #6473cf;
    font-weight: 600;
}

.paginacion-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.paginacion-btn.prev,
.paginacion-btn.next {
    font-weight: 600;
}

/* ============================================
   SECCIÓN DE OFERTAS EN RESULTADOS
   ============================================ */
.ofertas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.oferta-card {
    background: #fff;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.oferta-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.oferta-card img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.oferta-card-content {
    padding: 15px;
}

.oferta-card-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
}

.oferta-card-descripcion {
    font-size: 14px;
    color: #666;
    margin-bottom: 10px;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.oferta-card-empresa {
    font-size: 13px;
    color: #6473cf;
    font-weight: 500;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .buscador-avanzado-container {
        max-width: 100%;
        width: 100%;
        padding: 0;
        margin: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 2147483647 !important;
        background: #fff;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        transition: opacity 0.3s ease;
        pointer-events: auto;
    }
    
    /* Ocultar buscador cuando modales están activos */
    body.modal-buscador-activo .buscador-avanzado-container {
        opacity: 0;
        pointer-events: none;
    }
    
    #searchForm {
        padding: 2px 6px;
        border-radius: 0px;
        width: 100%;
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        gap: 8px;
    }
    
    /* Ocultar iconos en vista móvil */
    .search-icon {
        display: none;
    }
    
    #voiceSearchBtn {
        display: none;
    }
    
    #searchInput {
        font-size: 14px;
        padding: 10px 8px;
        flex: 1;
    }
    
    #searchSubmitBtn {
        width: 35px;
        height: 35px;
        min-width: 35px;
        padding: 0;
        font-size: 0;
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    
    /* Añadir icono de búsqueda al botón */
    #searchSubmitBtn::before {
        content: '🔍';
        font-size: 18px;
    }
    
    /* Ajustar sugerencias en móvil - centradas en viewport */
    #suggestionsList {
        max-width: calc(100vw - 30px);
        width: calc(100vw - 30px);
        top: 40vh;
        left: 50%;
        transform: translate(-50%, -50%);
        position: fixed;
        max-height: 70vh;
        transition: top 0.2s ease;
    }

    /* Modal de resultados en móvil - centrado en viewport */
    #modalResultados {
        padding-top: 0;
    }
    
    .modal-resultados-wrapper {
        padding: 20px 10px;
        min-height: 100vh;
    }
    
    .modal-resultados-content {
        padding: 20px 15px;
    }
    
    .modal-resultados-header h3 {
        font-size: 20px;
    }
    
    /* Modal de barrios en móvil - centrado en viewport */
    .modal-barrios-content {
        padding: 20px;
        max-height: 85vh;
        overflow-y: auto;
    }
    
    .ofertas-grid {
        grid-template-columns: 1fr;
    }
    
    /* Agregar espacio superior al contenido para que no quede detrás del buscador fijo */
    #div-2 .content {
        padding-top: 55px;
    }
    
    /* Eliminar el espacio extra que había antes */
    #div-2 .content > div[style*="height: 35px"] {
        display: none;
    }
}

@media (max-width: 480px) {
    #searchForm {
        flex-wrap: nowrap;
    }
    
    #searchInput {
        flex: 1;
    }
    
    #searchSubmitBtn {
        width: 35px;
        height: 35px;
        min-width: 35px;
    }
}

