/**
 * Buscador Koslan 3.0 - Search bar persistente (estilo MercadoLibre)
 * Reemplaza al drawer lateral: el input vive siempre en el header y los
 * resultados se muestran en un panel flotante de máximo 6 productos.
 * Clases prefijadas con `ksb-` para no colisionar con el tema.
 */

.ksb {
    --ksb-blue: #465fa7;
    --ksb-blue-hover: #35497f;
    --ksb-text: #1e1e1e;
    --ksb-muted: #707070;
    --ksb-border: #dddddd;
    position: relative;
    font-family: "Montserrat", sans-serif;
    box-sizing: border-box;
}

.ksb *,
.ksb *::before,
.ksb *::after {
    box-sizing: border-box;
}

/* --- INPUT PILL --- */

.ksb-form {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    height: 40px;
    padding: 0 6px 0 16px;
    background: #fff;
    border: 1px solid var(--ksb-border);
    border-radius: 40px;
    margin: 0;
}

.ksb-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    color: var(--ksb-text);
}

.ksb-input::placeholder {
    color: var(--ksb-muted);
    opacity: 1;
}

/* Oculta la X nativa de <input type="search"> para usar la propia */
.ksb-input::-webkit-search-decoration,
.ksb-input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.ksb-clear,
.ksb-submit {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: none;
    color: var(--ksb-muted);
    cursor: pointer;
    border-radius: 50%;
    transition: color .2s ease, background .2s ease;
}

.ksb-clear svg,
.ksb-submit svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
}

.ksb-submit svg {
    width: 17px;
    height: 17px;
}

.ksb-clear:hover,
.ksb-submit:hover {
    color: var(--ksb-blue);
    background: rgba(70, 95, 167, .08);
}

.ksb-clear[hidden] {
    display: none;
}

/* --- PANEL DE RESULTADOS --- */

.ksb-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 100%;
    min-width: 330px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--ksb-border);
    border-radius: 10px;
    box-shadow: 0 18px 50px rgba(7, 33, 132, .18);
    padding: 14px;
    z-index: 1200;
}

.ksb-panel[hidden] {
    display: none;
}

.ksb-count {
    font-size: 12px;
    line-height: 1.4;
    color: var(--ksb-text);
    margin-bottom: 10px;
}

.ksb-count strong {
    font-weight: 700;
}

.ksb-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: min(52vh, 380px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.ksb-item + .ksb-item {
    border-top: 1px solid #f0f0f0;
}

.ksb-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 10px;
    text-decoration: none;
    color: var(--ksb-text);
    border-radius: 8px;
    transition: background .18s ease;
}

.ksb-link:hover,
.ksb-link:focus,
.ksb-item.is-active .ksb-link {
    background: #f4f6fb;
    color: var(--ksb-text);
    text-decoration: none;
}

.ksb-thumb {
    flex: 0 0 auto;
    width: 46px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-radius: 6px;
    overflow: hidden;
}

.ksb-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.ksb-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12px;
    line-height: 1.35;
    font-weight: 400;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ksb-arrow {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    stroke: var(--ksb-blue);
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- FOOTER / CTA --- */

.ksb-footer {
    flex: 0 0 auto;
    margin-top: 12px;
}

.ksb-see-all {
    display: inline-block;
    padding: 9px 18px;
    background: var(--ksb-blue);
    color: #fff;
    font-size: 12px;
    font-weight: 400;
    text-decoration: none;
    border-radius: 10px;
    transition: background .2s ease;
}

.ksb-see-all:hover,
.ksb-see-all:focus {
    background: var(--ksb-blue-hover);
    color: #fff;
    text-decoration: none;
}

/* --- ESTADOS (cargando / vacío / error) --- */

.ksb-state {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 10px;
    font-size: 12px;
    color: var(--ksb-muted);
}

.ksb-spinner {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    border: 2px solid var(--ksb-border);
    border-top-color: var(--ksb-blue);
    border-radius: 50%;
    animation: ksb-spin .7s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
    .ksb-spinner { animation-duration: 2s; }
}

/* ===========================================================
   INSTANCIA DESKTOP (dentro del header azul, ≥1200px)
   =========================================================== */

.ksb--desktop {
    display: none;
    flex: 1 1 auto;
    min-width: 180px;
    max-width: 300px;
    margin-right: 12px;
}

@media (min-width: 1200px) {
    .ksb--desktop {
        display: block;
    }
}

.ksb--desktop .ksb-form {
    border-color: transparent;
}

/* El header usa columnas Bootstrap 2/6/4 de ancho fijo. Al meter el buscador en
   la botonera, el nav (min-width:700px) se desbordaba sobre el input bajo los
   ~1400px y los íconos se salían del pill. En desktop la fila pasa a anchos
   naturales: logo y menú ocupan lo que necesitan y la botonera toma el resto,
   con el input absorbiendo el espacio sobrante. Así el padding de 10px del menú
   se respeta tal cual en todo el rango. */
@media (min-width: 1200px) {
    .contenedor-header .row {
        flex-wrap: nowrap;
    }

    .contenedor-header .row > .col-md-2,
    .contenedor-header .menu-desktop-koslan-custom,
    .contenedor-header .menu-desktop-koslan-custom .menu-desktop {
        flex: 0 0 auto;
        width: auto;
        max-width: none;
    }

    .contenedor-header #menu-mobil {
        flex: 1 1 auto;
        width: auto;
        /* min-width:auto (el default en flex) impedía que la botonera cediera
           ancho y empujaba los íconos fuera del pill bajo ~1440px. */
        min-width: 0;
        max-width: none;
        justify-content: flex-end;
        gap: 10px;
    }

    /* Especificidad extra: el <style> inline de header.php declara
       .koslan-menu-wrap{min-width:700px} y va después en el documento. */
    .contenedor-header .koslan-menu-wrap {
        width: auto;
        min-width: 0;
    }

    /* La botonera ya separa con gap; el margen suelto del contacto sobra. */
    .contenedor-header #menu-mobil a.btn-contacto,
    .contenedor-header #menu-mobil .btn-menu {
        margin-right: 0;
        margin-left: 0;
    }

    .ksb--desktop {
        margin-right: 0;
    }
}

/* Desktop angosto (1200-1440px): logo 224px + nav 616px + íconos no dejan ancho
   útil para el input. Se achica el logo y se permite un input más angosto. */
@media (min-width: 1200px) and (max-width: 1439.98px) {
    .ksb--desktop {
        min-width: 140px;
    }

    .contenedor-header img.img-fluid.img-logo {
        width: 165px;
        padding: 8px 12px;
    }
}

/* ===========================================================
   INSTANCIA MOBILE (barra fija arriba, <1200px)
   El header azul flotante queda debajo, como siempre.
   =========================================================== */

.ksb--mobile {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    padding: 10px 14px;
    background: rgba(0, 94, 184, 0.8);
    box-shadow: 0 2px 10px rgba(7, 33, 132, .10);
}

.ksb--mobile .ksb-panel {
    min-width: 0;
}

@media (min-width: 1200px) {
    .ksb--mobile {
        display: none;
    }
}

/* Deja aire arriba para la barra fija y baja el header flotante. */
@media (max-width: 1199.98px) {
    body.ksb-has-mobile-bar {
        padding-top: 60px;
    }

    body.ksb-has-mobile-bar .header {
        top: 70px;
    }
}

@media (max-width: 600px) {
    body.ksb-has-mobile-bar .header {
        top: 68px;
    }
}
