/* ==========================================================================
   Typesense Search — Estilos del buscador autocomplete
   FarmaciaSoler v3 — Layout full-width con 2 columnas
   ========================================================================== */

/* ==========================================================================
   1. WRAPPER del buscador (dentro de la cajota teal)
   ========================================================================== */

.ts-search-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    max-width: 500px;
}

.ts-search-wrapper .ts-search-form {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #ddd;
    border-radius: 25px;
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

/* Input */
.ts-search-form input[type="text"] {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 16px;
    font-size: 15px;
    color: #333;
    background: transparent;
    min-width: 0;
}

.ts-search-form input[type="text"]::placeholder {
    color: #999;
}

/* Boton buscar */
.ts-search-form .ts-search-btn {
    border: none;
    background: #18ba9b;
    color: #fff;
    padding: 10px 18px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    line-height: 1;
}

.ts-search-form .ts-search-btn:hover {
    background: #14a085;
}

/* ==========================================================================
   2. PANEL de resultados (full-width debajo de la barra teal)
   ========================================================================== */

.ts-dropdown {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    width: 100%;
    background: #fff;
    border-top: 1px solid #eee;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    z-index: 100001; /* Por encima del navbar sticky (9999) */
}

/* Panel con altura fija para evitar cambios de tamanio al filtrar */
.ts-dropdown > .container {
    position: relative;
}

.ts-dropdown--open {
    display: block;
}

/* El container dentro del dropdown usa Bootstrap grid */
.ts-dropdown > .container {
    padding-top: 16px;
    padding-bottom: 8px;
}

/* ---- Layout 2 columnas ---- */
.ts-results-row {
    display: flex;
    gap: 24px;
}

.ts-results-col-main {
    flex: 1;
    min-width: 0;
    min-height: 380px;
}

/* Header fijo de la columna de productos (no scrollea) */
.ts-products-header {
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
    margin-bottom: 0;
}

.ts-section-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 0;
}

.ts-section-header .ts-section-title {
    padding: 0;
}

.ts-section-header .ts-section-count {
    font-size: 13px;
    color: #18ba9b;
    font-weight: 600;
}

/* Contador "Mostrando X-Y de Z" */
.ts-products-showing {
    font-size: 11px;
    color: #999;
    margin-left: auto;
}

/* Lista scrollable de productos */
.ts-products-scroll {
    max-height: 380px;
    overflow-y: auto;
}

/* ---- Etiquetas de filtro ---- */
.ts-filter-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    padding: 0 10px;
}

.ts-filter-tag {
    display: inline-flex;
    align-items: center;
    background: #e8f5f2;
    color: #18ba9b;
    border-radius: 14px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
}

.ts-filter-tag-remove {
    cursor: pointer;
    margin-left: 6px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    opacity: 0.7;
}

.ts-filter-tag-remove:hover {
    opacity: 1;
}

/* ---- Boton cargar mas ---- */
.ts-load-more {
    text-align: center;
    padding: 12px 10px;
    cursor: pointer;
    border-top: 1px solid #f0f0f0;
    transition: background 0.15s;
}

.ts-load-more:hover {
    background: #f5faf9;
}

.ts-load-more-text {
    font-size: 13px;
    font-weight: 600;
    color: #18ba9b;
}

.ts-load-more-text .fa {
    margin-right: 4px;
}

.ts-results-col-side {
    width: 280px;
    flex-shrink: 0;
    border-left: 1px solid #f0f0f0;
    padding-left: 20px;
}

/* ---- Layout 3 columnas (populares) ---- */
.ts-popular-row {
    display: flex;
    gap: 20px;
}

.ts-popular-col {
    flex: 1;
    min-width: 0;
}

/* ==========================================================================
   3. SECCIONES y ITEMS
   ========================================================================== */

.ts-section {
    padding: 0;
    margin-bottom: 8px;
}

.ts-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: #999;
    padding: 4px 0 6px;
    letter-spacing: 0.5px;
}

/* ---- Items genericos ---- */
.ts-item {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    cursor: pointer;
    text-decoration: none;
    color: #333;
    transition: background 0.1s;
    border-radius: 6px;
}

.ts-item:hover,
.ts-item--active {
    background: #f5faf9;
    text-decoration: none;
    color: #333;
}

/* ---- Producto ---- */
.ts-item--product {
    gap: 12px;
    padding: 10px;
}

.ts-product-img {
    flex-shrink: 0;
    width: 60px;
    height: 60px;
    border-radius: 6px;
    overflow: hidden;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ts-product-img img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.ts-product-img-placeholder {
    color: #ccc;
    font-size: 20px;
}

.ts-product-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.ts-product-title {
    font-size: 14px;
    font-weight: 500;
    color: #333;
    line-height: 1.3;
    /* Allow 2 lines max */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ts-product-title mark {
    background: rgba(24, 186, 155, 0.2);
    color: inherit;
    padding: 0 1px;
    border-radius: 2px;
}

.ts-product-brand {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}

/* ---- Precios ---- */
.ts-product-price {
    flex-shrink: 0;
    text-align: right;
    margin-left: 12px;
}

.ts-price-current {
    font-size: 16px;
    font-weight: 700;
    color: #333;
    display: block;
}

.ts-price-offer {
    color: #e74c3c;
}

.ts-price-old {
    font-size: 12px;
    color: #bbb;
    text-decoration: line-through;
    display: block;
}

/* ---- Badge de oferta ---- */
.ts-badge-offer {
    font-size: 10px;
    color: #fff;
    background: rgba(247, 96, 146, 0.85);
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
    margin-top: 3px;
    font-weight: 600;
    text-transform: uppercase;
}

.ts-badge-soldout {
    font-size: 10px;
    color: #fff;
    background: #e74c3c;
    padding: 2px 6px;
    border-radius: 3px;
    display: inline-block;
    margin-top: 2px;
}

/* ---- Marca (sidebar con logo) ---- */
.ts-item--brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
}

.ts-brand-logo {
    width: 50px;
    height: 16px;
    object-fit: contain;
    flex-shrink: 0;
}

.ts-brand-name {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
}

.ts-brand-count {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Marca/categoria activa (filtro aplicado) */
.ts-item--filter-active {
    background: #e8f5f2;
    font-weight: 600;
}

/* ---- Categoria (sidebar con breadcrumb) ---- */
.ts-item--category {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
}

.ts-cat-info {
    flex: 1;
    min-width: 0;
}

.ts-cat-breadcrumb {
    font-size: 10px;
    color: #bbb;
    line-height: 1.2;
    margin-bottom: 1px;
}

.ts-cat-name {
    font-size: 13px;
    font-weight: 500;
    display: block;
}

.ts-cat-count {
    font-size: 12px;
    color: #999;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 8px;
}

/* ---- Recientes ---- */
.ts-item--recent {
    font-size: 14px;
    color: #666;
    padding: 6px 10px;
}

.ts-item--recent .fa {
    margin-right: 8px;
    color: #bbb;
}

/* ---- Populares ---- */
.ts-item--popular {
    font-size: 14px;
    color: #555;
    padding: 6px 10px;
}

.ts-item--popular .fa {
    margin-right: 8px;
    color: #e67e22;
}

/* ---- Footer: Ver todos ---- */
.ts-footer {
    border-top: 1px solid #f0f0f0;
    margin-top: 8px;
    padding: 0;
}

.ts-view-all {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    font-size: 14px;
    font-weight: 600;
    color: #18ba9b;
    text-align: center;
    border-radius: 0;
}

.ts-view-all:hover {
    background: #f5faf9;
    color: #14a085;
    text-decoration: none;
}

/* ---- No results ---- */
.ts-no-results {
    padding: 24px 16px;
    text-align: center;
}

.ts-no-results-text {
    font-size: 15px;
    color: #666;
    margin-bottom: 6px;
}

.ts-no-results-text .fa {
    color: #ccc;
    margin-right: 6px;
}

.ts-no-results-tips {
    font-size: 13px;
    color: #999;
}

/* ---- Loading ---- */
.ts-loading {
    padding: 24px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

.ts-loading .fa-spinner {
    margin-right: 6px;
}

/* ==========================================================================
   4. MOBILE: Overlay fullscreen
   ========================================================================== */

.ts-mobile-search-btn {
    display: none;
    cursor: pointer;
    font-size: 20px;
    color: #fff;
    padding: 8px;
}

.ts-search-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    z-index: 99999;
    flex-direction: column;
}

.ts-overlay--open {
    display: flex;
}

.ts-overlay-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    background: #18ba9b;
    gap: 8px;
}

.ts-overlay-header .ts-search-close {
    border: none;
    background: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.ts-overlay-header input[type="text"] {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px 14px;
    font-size: 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
}

.ts-overlay-header input[type="text"]::placeholder {
    color: #999;
}

/* Body del overlay: zona scrollable de resultados */
.ts-overlay-body {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    padding: 12px 16px;
    -webkit-overflow-scrolling: touch; /* scroll fluido en iOS */
}

/* Items mas grandes en mobile (touch-friendly) */
.ts-overlay-body .ts-item {
    padding: 10px 12px;
}

.ts-overlay-body .ts-item--product {
    padding: 12px 10px;
}

.ts-overlay-body .ts-product-img {
    width: 55px;
    height: 55px;
}

.ts-overlay-body .ts-product-title {
    font-size: 13px;
}

.ts-overlay-body .ts-price-current {
    font-size: 15px;
}

.ts-overlay-body .ts-badge-offer {
    font-size: 9px;
}

.ts-body-noscroll {
    overflow: hidden !important;
}

/* ==========================================================================
   5. RESPONSIVE
   ========================================================================== */

@media (max-width: 991px) {
    .ts-search-wrapper {
        max-width: 100%;
    }

    .ts-results-col-side {
        width: 220px;
    }
}

@media (max-width: 767px) {
    /* En mobile, el dropdown desktop no se usa (se usa el overlay) */
    .ts-dropdown {
        display: none !important;
    }

    /* Layout columnar pasa a stack */
    .ts-results-row {
        flex-direction: column;
    }

    .ts-results-col-side {
        width: 100%;
        border-left: none;
        border-top: 1px solid #f0f0f0;
        padding-left: 0;
        padding-top: 12px;
    }

    .ts-popular-row {
        flex-direction: column;
    }

    /* Header de productos mas compacto */
    .ts-products-header {
        padding-bottom: 6px;
    }

    .ts-section-header {
        flex-wrap: wrap;
    }

    .ts-products-showing {
        width: 100%;
        margin-left: 0;
    }
}

@media (min-width: 768px) {
    /* En desktop, el overlay no se usa */
    .ts-search-overlay {
        display: none !important;
    }
}

/* ==========================================================================
   6. Integracion cajota teal (.product-seach)
   ========================================================================== */

/* El search-box necesita position:relative para que el dropdown se posicione */
.product-seach {
    position: relative;
}

.product-seach .ts-search-wrapper {
    max-width: 100%;
}

.product-seach .ts-search-form--searchbox {
    background: rgba(255, 255, 255, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.8);
}

.product-seach .ts-search-form--searchbox input[type="text"] {
    font-size: 16px;
    color: #333;
}

.product-seach .ts-search-form--searchbox input[type="text"]::placeholder {
    color: #888;
}

.product-seach #kwords_info {
    margin-top: 8px;
}

/* ==========================================================================
   7. Boton "Cerrar buscador" (abajo-derecha del footer)
   ========================================================================== */

.ts-close-panel-bottom {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 13px;
    color: #999;
    text-decoration: none;
    float: right;
    transition: color 0.15s;
}

.ts-close-panel-bottom:hover {
    color: #666;
    text-decoration: none;
}

.ts-close-panel-bottom .fa {
    font-size: 12px;
}

/* ==========================================================================
   8. Buscador activo: navbar forzado + cajota fixed + overlay
   ========================================================================== */

/* Bloquear scroll */
.ts-search-active {
    overflow: hidden !important;
}

/* Forzar navbar a fixed con !important (handleHeader no puede interferir) */
.ts-search-active .header-v5.header-static {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    z-index: 9999 !important;
    background: rgba(255, 255, 255, 0.98) !important;
    box-shadow: 0 0 3px #bbb !important;
}

/* Ocultar topbar cuando el buscador esta activo */
.ts-search-active .header-v5.header-static .topbar-v3 {
    display: none !important;
}

/* Overlay oscuro */
.ts-search-active::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 9997;
    pointer-events: auto;
}

/* Altura fija de la columna de productos — evita cambios al filtrar */
.ts-results-col-main {
    min-height: 380px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.7);
}
