/* ═══════════════════════════════════════════════════════════════
   KAR DISTRIBUIDORA — Catálogo CSS
   Rediseño UX/UI profesional
═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f4f6f9;
    color: #1a1a2e;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ─── HEADER ──────────────────────────────────────────────────── */
.cat-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,.10);
}

.cat-header-top {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid #f0f0f0;
}

/* Logo */
.cat-logo-link { flex-shrink: 0; }
.cat-logo {
    height: 56px;
    width: auto;
    object-fit: contain;
    display: block;
}

/* ─── BUSCADOR ────────────────────────────────────────────────── */
.cat-search-box {
    display: flex;
    align-items: center;
    background: #f5f6fa;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 0 14px;
    gap: 10px;
    transition: border-color .2s, box-shadow .2s;
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
}
.cat-search-box:focus-within {
    border-color: #dc2626;
    box-shadow: 0 0 0 3px rgba(220,38,38,.10);
    background: #fff;
}
.cat-search-icon { color: #9ca3af; font-size: 15px; flex-shrink: 0; }
.cat-search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    color: #1a1a2e;
    padding: 11px 0;
    outline: none;
    min-width: 0;
}
.cat-search-input::placeholder { color: #9ca3af; }
.cat-search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 14px;
    padding: 4px;
    border-radius: 50%;
    transition: color .2s, background .2s;
    display: flex;
    align-items: center;
}
.cat-search-clear:hover { color: #dc2626; background: #fee2e2; }

/* ─── ACCIONES HEADER ─────────────────────────────────────────── */
.cat-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* Toggle precio */
.cat-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.cat-toggle input { display: none; }
.cat-toggle-track {
    width: 40px;
    height: 22px;
    background: #d1d5db;
    border-radius: 11px;
    position: relative;
    transition: background .25s;
    flex-shrink: 0;
}
.cat-toggle input:checked ~ .cat-toggle-track { background: #dc2626; }
.cat-toggle-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform .25s;
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.cat-toggle input:checked ~ .cat-toggle-track .cat-toggle-thumb { transform: translateX(18px); }
.cat-toggle-label { font-size: 13px; font-weight: 500; color: #6b7280; white-space: nowrap; }

/* Botón ofertas */
.cat-btn-ofertas {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    color: #374151;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .2s, color .2s, background .2s;
    white-space: nowrap;
}
.cat-btn-ofertas:hover { border-color: #dc2626; color: #dc2626; background: #fff5f5; }
.cat-btn-ofertas.activo { background: #dc2626; color: #fff; border-color: #dc2626; }
.cat-btn-ofertas.activo:hover { background: #b91c1c; }

/* Botón carrito */
.cat-btn-carrito {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #fff;
    border: 2px solid #e5e7eb;
    color: #374151;
    font-size: 16px;
    text-decoration: none;
    transition: border-color .2s, color .2s, background .2s;
}
.cat-btn-carrito:hover { border-color: #dc2626; color: #dc2626; background: #fff5f5; }
.cat-cart-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #dc2626;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
}

/* Usuario */
.cat-usuario {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    background: #fff5f5;
    border: 2px solid #fecaca;
    border-radius: 10px;
    text-decoration: none;
    color: #dc2626;
    font-size: 13px;
    font-weight: 600;
    transition: background .2s, border-color .2s;
    white-space: nowrap;
    max-width: 240px;
    overflow: hidden;
}
.cat-usuario:hover { background: #fee2e2; border-color: #dc2626; }
.cat-usuario-icon { font-size: 16px; flex-shrink: 0; }
.cat-usuario-nombre {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ─── BOTÓN FILTROS ───────────────────────────────────────────── */
.cat-btn-filtros {
    position: relative;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    background: #fff;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    color: #374151;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .2s, color .2s, background .2s;
    white-space: nowrap;
    font-family: inherit;
}
.cat-btn-filtros:hover { border-color: #dc2626; color: #dc2626; background: #fff5f5; }
.cat-btn-filtros.activo { border-color: #dc2626; color: #dc2626; background: #fff5f5; }

.cat-btn-filtros-label { font-size: 13px; }

.filtro-activo-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 10px;
    height: 10px;
    background: #dc2626;
    border-radius: 50%;
    border: 2px solid #fff;
}

/* ─── BARRA DE FILTROS ────────────────────────────────────────── */
.cat-filtros-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 0 24px;
    background: #fafafa;
    border-top: 1px solid transparent;
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease, padding .3s ease, border-color .3s ease;
}
.cat-filtros-bar.abierto {
    max-height: 400px;
    padding: 12px 24px;
    border-top-color: #f0f0f0;
}

.cat-filtro-grupo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.cat-filtro-sep { display: none; }
.cat-filtro-label {
    font-size: 12px;
    font-weight: 600;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: .5px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Chips de filtro */
.filtro-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* Subrubro: scroll cuando hay muchos chips */
#filtrosSubRubro {
    max-height: 90px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #374151 #e5e7eb;
}
#filtrosSubRubro::-webkit-scrollbar { width: 5px; }
#filtrosSubRubro::-webkit-scrollbar-track { background: #e5e7eb; border-radius: 3px; }
#filtrosSubRubro::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }

/* Nombre producto como link */
.card-nombre-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

/* Buscador dentro de cada grupo de filtros */
.filtro-busqueda {
    width: 100%;
    padding: 5px 10px;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: 12px;
    outline: none;
    background: #f9fafb;
    color: #374151;
    margin-bottom: 6px;
    transition: border-color .2s;
}
.filtro-busqueda:focus { border-color: #dc2626; background: #fff; }

.filtro-chip {
    padding: 5px 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    background: #fff;
    cursor: pointer;
    white-space: nowrap;
    transition: all .18s;
    flex-shrink: 0;
}
.filtro-chip:hover { border-color: #dc2626; color: #dc2626; background: #fff5f5; }
.filtro-chip.activo {
    background: #dc2626;
    border-color: #dc2626;
    color: #fff;
    font-weight: 600;
}

/* ─── LAYOUT CON SIDEBAR ──────────────────────────────────────── */
.cat-layout {
    display: flex;
    align-items: flex-start;
    min-height: calc(100vh - 73px);
}

/* ─── SIDEBAR ─────────────────────────────────────────────────── */
.cat-sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #fff;
    border-right: 1.5px solid #f0f0f0;
    position: sticky;
    top: 73px;
    height: calc(100vh - 73px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #374151 #e5e7eb;
}
.cat-sidebar::-webkit-scrollbar { width: 4px; }
.cat-sidebar::-webkit-scrollbar-track { background: #e5e7eb; }
.cat-sidebar::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }

.cat-sidebar-titulo {
    padding: 16px 16px 10px;
    font-size: 13px;
    font-weight: 700;
    color: #374151;
    letter-spacing: .3px;
    border-bottom: 1.5px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.cat-sidebar-titulo i { color: #dc2626; }

.cat-sidebar-seccion {
    padding: 14px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Chips en sidebar: columna, 6 visibles + scroll para el resto */
.filtro-chips-sidebar {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 4px;
    max-height: 212px; /* ~6 chips */
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #374151 #e5e7eb;
}
.filtro-chips-sidebar::-webkit-scrollbar { width: 5px; }
.filtro-chips-sidebar::-webkit-scrollbar-track { background: #e5e7eb; border-radius: 3px; }
.filtro-chips-sidebar::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }

/* En sidebar los chips se estiran al ancho */
.filtro-chips-sidebar .filtro-chip {
    width: 100%;
    text-align: left;
    border-radius: 8px;
    white-space: normal;
    word-break: break-word;
    flex-shrink: 0;
}

/* Subrubro: mismo comportamiento, sin override de altura */
#filtrosSubRubro {
    max-height: 212px;
    overflow-y: auto;
}

/* ─── MAIN ────────────────────────────────────────────────────── */
.cat-main {
    flex: 1;
    padding: 20px;
    min-width: 0;
}

/* ─── GRILLA DE PRODUCTOS ─────────────────────────────────────── */
.grilla-productos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 18px;
}

.cargando {
    grid-column: 1 / -1;
    text-align: center;
    color: #9ca3af;
    padding: 48px;
    font-size: 15px;
}

/* ─── TARJETA PRODUCTO ────────────────────────────────────────── */
.tarjeta-producto {
    background: #fff;
    border-radius: 14px;
    border: 1.5px solid #f0f0f0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform .2s, box-shadow .2s, border-color .2s;
}
.tarjeta-producto:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0,0,0,.10);
    border-color: #fecaca;
}

/* Imagen */
.card-imagen {
    background: #f9fafb;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 170px;
    overflow: hidden;
}
.card-imagen img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 12px;
    transition: transform .3s;
}
.tarjeta-producto:hover .card-imagen img { transform: scale(1.04); }

/* Info */
.tarjeta-producto > .card-codigo {
    font-size: 11px;
    font-weight: 600;
    color: #9ca3af;
    letter-spacing: .5px;
    text-transform: uppercase;
    padding: 10px 14px 0;
}
.tarjeta-producto h3 {
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
    line-height: 1.4;
    padding: 4px 14px 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.card-subtitulo {
    font-size: 11px;
    color: #b0b7c3;
    padding: 2px 14px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card-multiplo {
    display: inline-block;
    margin: 6px 14px 0;
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
}

/* Precios */
.card-precios {
    padding: 8px 14px 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: auto;
}
.precio-sin-iva {
    font-size: 11px;
    color: #b0b7c3;
    display: flex;
    align-items: center;
    gap: 4px;
}
.precio-sin-iva strong { color: #9ca3af; font-weight: 500; }
/* Ícono de oferta — estrella con % sobre la imagen */
.badge-oferta-icono {
    position: absolute;
    top: 6px;
    left: 6px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    cursor: default;
    pointer-events: none;
}
.badge-oferta-icono .fa-certificate {
    font-size: 38px;
    color: #dc2626;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,.25));
}
.badge-oferta-icono span {
    position: absolute;
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: -.5px;
    pointer-events: none;
}

/* Precios en cards de oferta — inmunes al toggle de precio venta */
.oferta-precio-siniva {
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}
.oferta-precio-siniva strong { font-weight: 600; }

.oferta-precio-coniva {
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}
.oferta-precio-coniva strong {
    color: #1a1a2e;
    font-weight: 700;
    font-size: 17px;
}
.precio-mayorista {
    font-size: 13px;
    font-weight: 500;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}
.precio-mayorista strong {
    color: #1a1a2e;
    font-weight: 700;
    font-size: 17px;
}
.precio-sugerido {
    font-size: 13px;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 4px;
}
.precio-sugerido strong { color: #059669; font-weight: 700; font-size: 16px; }
.oculto { display: none !important; }

/* Badge compatible */
.badge-compatible {
    display: inline-block;
    margin: 6px 14px 0;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
}

/* Badge stock */
.badge-stock {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 14px;
}
.badge-stock span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}
.en-stock   { color: #059669; }
.en-stock span   { background: #10b981; }
.poco-stock { color: #d97706; }
.poco-stock span { background: #f59e0b; }
.sin-stock  { color: #dc2626; }
.sin-stock span  { background: #ef4444; }

/* Selector cantidad */
.selector-cantidad {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px 0;
}
.selector-cantidad button {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1.5px solid #e5e7eb;
    background: #f9fafb;
    color: #374151;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    transition: all .15s;
}
.selector-cantidad button:hover { border-color: #dc2626; color: #dc2626; background: #fff5f5; }
.cant-input {
    font-size: 15px;
    font-weight: 700;
    width: 52px;
    text-align: center;
    color: #1a1a2e;
    border: 1.5px solid #e5e7eb;
    border-radius: 6px;
    padding: 3px 4px;
    background: #f9fafb;
    outline: none;
    -moz-appearance: textfield;
}
.cant-input::-webkit-inner-spin-button,
.cant-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.cant-input:focus { border-color: #dc2626; background: #fff; }

/* Botón agregar */
.btn-agregar {
    margin: 8px 14px 14px;
    padding: 10px;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: background .2s, transform .15s;
    width: calc(100% - 28px);
}
.btn-agregar:hover { background: #b91c1c; transform: translateY(-1px); }
.btn-agregar:active { transform: translateY(0); }
.btn-agregar.deshabilitado,
.btn-agregar:disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

/* ─── MENSAJE SIN RESULTADOS ──────────────────────────────────── */
.cat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 24px;
    text-align: center;
    color: #9ca3af;
}
.cat-empty i { font-size: 56px; margin-bottom: 16px; color: #d1d5db; }
.cat-empty p { font-size: 18px; font-weight: 600; color: #6b7280; margin-bottom: 8px; }
.cat-empty span { font-size: 14px; }

/* ─── MENSAJE FLOTANTE ────────────────────────────────────────── */
.mensaje-flotante {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1a1a2e;
    color: #fff;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s, transform .3s;
    z-index: 999;
    box-shadow: 0 4px 20px rgba(0,0,0,.25);
    white-space: nowrap;
}
.mensaje-flotante.mostrar {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .cat-header-top { padding: 10px 16px; gap: 10px; }
    .cat-logo { height: 44px; }
    .cat-toggle-label,
    .cat-usuario-nombre { display: none; }
    .cat-usuario { padding: 7px 10px; }
    .cat-filtros-bar { padding: 8px 16px; }
    .cat-main { padding: 16px; }
    .grilla-productos { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
    .card-imagen { height: 130px; }
}

@media (max-width: 480px) {
    .grilla-productos { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .cat-search-box { max-width: none; }
}

/* ─── PAGINACIÓN NUMERADA ─────────────────────────────────────── */
.paginacion {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 32px 16px 16px;
    flex-wrap: wrap;
}

.pag-btn {
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .2s, color .2s;
    line-height: 1;
}

/* Flechas ← → */
.pag-flecha {
    background: #f3f4f6;
    color: #374151;
    padding: 10px 16px;
    font-size: 16px;
    border-radius: 8px;
}
.pag-flecha:hover:not(:disabled) { background: #e5e7eb; }
.pag-flecha:disabled { opacity: .35; cursor: not-allowed; }

/* Números */
.pag-num {
    background: #f3f4f6;
    color: #374151;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.pag-num:hover:not(:disabled):not(.activo) { background: #e5e7eb; }
.pag-num.activo {
    background: #1a1a2e;
    color: #fff;
    cursor: default;
}
.pag-num:disabled.activo { opacity: 1; }

/* Puntos suspensivos */
.pag-dots {
    color: #9ca3af;
    font-size: 14px;
    padding: 0 4px;
    line-height: 38px;
}