/**
 * Buscador Koslan 2.0 - Drawer lateral
 * Diseño: Ernesto | Integración Meilisearch (endpoint /koslan/v1/search)
 * Todas las clases van prefijadas con `ksd-` para no colisionar con el tema.
 */

.ksd-root {
    --ksd-brand-blue: #3562a6;
    --ksd-brand-blue-hover: #294d85;
    --ksd-text-dark: #1e1e1e;
    --ksd-text-muted: #666666;
    --ksd-border-color: #e2e8f0;
    --ksd-card-radius: 14px;
    --ksd-drawer-width: 780px;
}

/* --- OVERLAY / BACKDROP --- */
.ksd-backdrop {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.4);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    z-index: 1050;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.ksd-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
}

/* --- DRAWER LATERAL (ABRE DESDE LA DERECHA) --- */
.ksd-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--ksd-drawer-width);
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    background-color: #ffffff;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    padding: 30px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1051;
    font-family: "Montserrat", sans-serif;
    color: var(--ksd-text-dark);
}

.ksd-backdrop.is-open .ksd-drawer {
    transform: translateX(0);
}

.ksd-drawer * {
    box-sizing: border-box;
}

/* --- HEADER BÚSQUEDA --- */
.ksd-header {
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid var(--ksd-border-color);
    padding-bottom: 14px;
}

.ksd-icon-search {
    width: 24px;
    height: 24px;
    stroke: #94a3b8;
    flex-shrink: 0;
}

.ksd-input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 20px;
    color: var(--ksd-text-dark);
    background: transparent;
    font-family: inherit;
}

/* Botón Limpiar */
.ksd-clear {
    background: none;
    border: none;
    color: var(--ksd-brand-blue);
    font-size: 16px;
    font-weight: 500;
    text-decoration: underline;
    cursor: pointer;
    display: none;
    white-space: nowrap;
    margin-right: 10px;
    font-family: inherit;
}

.ksd-clear.is-visible {
    display: block;
}

/* Botón Cerrar X */
.ksd-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}

.ksd-close svg {
    width: 26px;
    height: 26px;
    stroke: var(--ksd-brand-blue);
    stroke-width: 2.5;
}

/* --- VISTA INICIAL (CATEGORÍAS) --- */
.ksd-default-view {
    padding: 25px 0 10px;
}

.ksd-hint {
    font-size: 14px;
    color: var(--ksd-text-muted);
    margin-bottom: 20px;
}

.ksd-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.ksd-chip {
    background-color: #f1f5f9;
    color: var(--ksd-text-dark);
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.ksd-chip:hover {
    background-color: var(--ksd-brand-blue);
    color: #ffffff;
}

/* --- CONTENEDOR RESULTADOS --- */
.ksd-results {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    overflow: hidden;
    margin-top: 20px;
}

.ksd-results.is-active {
    display: flex;
}

/* GRID DE 2 COLUMNAS */
.ksd-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    overflow-y: auto;
    padding-right: 6px;
    flex-grow: 1;
    align-content: start;
}

.ksd-grid::-webkit-scrollbar {
    width: 6px;
}

.ksd-grid::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

/* --- TARJETA DE PRODUCTO (HOVER AZUL) --- */
.ksd-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    border-radius: var(--ksd-card-radius);
    text-decoration: none;
    color: var(--ksd-text-dark);
    background-color: #ffffff;
    border: 1px solid var(--ksd-border-color);
    transition: all 0.2s ease;
}

.ksd-card:hover {
    background-color: var(--ksd-brand-blue);
    color: #ffffff !important;
    border-color: var(--ksd-brand-blue);
}

.ksd-card-img {
    width: 68px;
    height: 68px;
    border-radius: 12px;
    border: 1px solid var(--ksd-border-color);
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 4px;
}

.ksd-card-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.ksd-card-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.ksd-card-title {
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ksd-card-price {
    font-size: 15px;
    font-weight: 700;
}

.ksd-card:hover .ksd-card-title,
.ksd-card:hover .ksd-card-price {
    color: #ffffff;
}

/* --- ESTADOS (loading / vacío / error) --- */
.ksd-state {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--ksd-text-muted);
    padding: 40px 20px;
    font-size: 15px;
}

.ksd-spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto 14px;
    border: 3px solid var(--ksd-border-color);
    border-top-color: var(--ksd-brand-blue);
    border-radius: 50%;
    animation: ksd-spin 0.8s linear infinite;
}

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

/* --- FOOTER DE RESULTADOS --- */
.ksd-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--ksd-border-color);
    gap: 20px;
    flex-shrink: 0;
}

.ksd-see-all {
    background-color: var(--ksd-brand-blue);
    color: #ffffff;
    border: none;
    padding: 14px 28px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 30px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease;
    text-decoration: none;
    display: inline-block;
    font-family: inherit;
}

.ksd-see-all:hover {
    background-color: var(--ksd-brand-blue-hover);
    color: #ffffff;
}

.ksd-count {
    font-size: 15px;
    color: var(--ksd-text-dark);
    line-height: 1.4;
    text-align: right;
}

/* Responsive Móvil */
@media (max-width: 640px) {
    .ksd-drawer {
        padding: 20px;
    }
    .ksd-grid {
        grid-template-columns: 1fr;
    }
    .ksd-footer {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    .ksd-see-all {
        text-align: center;
    }
    .ksd-count {
        text-align: center;
    }
}
