/*
 * Estilos: Página de categoría WooCommerce
 * Agregar en: tu-tema/assets/css/woo-category.css
 * O encolar desde functions.php con wp_enqueue_style()
 *
 * Basado en el diseño de referencia con sidebar de filtros
 * y grid de 5 columnas.
 */

/* ── Reset / Variables ────────────────────────────────────────────── */
:root {
    --woo-font:         'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --woo-color-bg:     #ffffff;
    --woo-color-surface:#f7f7f7;
    --woo-color-border: #e5e5e5;
    --woo-color-text:   #111111;
    --woo-color-muted:  #6b6b6b;
    --woo-color-badge-agotado-bg:  rgba(255,255,255,0.85);
    --woo-color-badge-agotado-text:#555555;
    --woo-color-badge-nuevo-bg:    #2563eb;
    --woo-color-badge-nuevo-text:  #ffffff;
    --woo-radius-sm:    4px;
    --woo-radius-md:    8px;
    --woo-radius-lg:    12px;
    --woo-sidebar-w:    220px;
    --woo-gap:          16px;
    --woo-transition:   0.2s ease;
}

/* ── Wrapper principal ───────────────────────────────────────────── */
.woo-cat-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px 48px;
    font-family: var(--woo-font);
    color: var(--woo-color-text);
}

/* ── Barra superior ──────────────────────────────────────────────── */
.woo-cat-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--woo-color-border);
    margin-bottom: 24px;
    gap: 12px;
    flex-wrap: wrap;
}

.woo-cat-topbar-left,
.woo-cat-topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Botón filtrar */
.btn-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border: 1px solid var(--woo-color-border);
    border-radius: var(--woo-radius-sm);
    background: var(--woo-color-bg);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--woo-transition), border-color var(--woo-transition);
    color: var(--woo-color-text);
}
.btn-filter:hover {
    background: var(--woo-color-surface);
    border-color: #aaa;
}

/* Contador de productos */
.product-count {
    font-size: 14px;
    color: var(--woo-color-muted);
}
.product-count strong {
    color: var(--woo-color-text);
    font-weight: 500;
}

/* Toggle comparar */
.compare-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
}
.toggle-track {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}
.toggle-input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.toggle-thumb {
    position: absolute;
    inset: 0;
    background: #ccc;
    border-radius: 999px;
    transition: background var(--woo-transition);
}
.toggle-thumb::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform var(--woo-transition);
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-input:checked + .toggle-thumb {
    background: #111;
}
.toggle-input:checked + .toggle-thumb::after {
    transform: translateX(18px);
}

/* Ordenar por */
.orderby-wrap {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}
.orderby-wrap::before {
    content: 'Ordenar por:';
    color: var(--woo-color-muted);
    white-space: nowrap;
}
.woo-cat-wrapper select.orderby {
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--woo-color-bg);
    border: 1px solid var(--woo-color-border);
    border-radius: var(--woo-radius-sm);
    padding: 6px 28px 6px 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--woo-color-text);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%23555' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color var(--woo-transition);
}
.woo-cat-wrapper select.orderby:hover,
.woo-cat-wrapper select.orderby:focus {
    border-color: #aaa;
    outline: none;
}

/* ── Body: sidebar + main ────────────────────────────────────────── */
.woo-cat-body {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.woo-cat-sidebar {
    flex: 0 0 var(--woo-sidebar-w);
    width: var(--woo-sidebar-w);
    position: sticky;
    top: 24px;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #ddd transparent;
    transition: width var(--woo-transition), opacity var(--woo-transition);
}
.woo-cat-sidebar.is-hidden {
    width: 0;
    opacity: 0;
    overflow: hidden;
    margin: 0;
    flex: 0 0 0;
}

/* Grupos de filtro */
.filter-group {
    border-bottom: 1px solid var(--woo-color-border);
}
.filter-group:first-child {
    border-top: 1px solid var(--woo-color-border);
}
.filter-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 13px 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--woo-color-text);
    text-align: left;
    gap: 8px;
}
.filter-group-header:hover {
    color: #000;
}
.filter-group-header .chevron {
    flex-shrink: 0;
    transition: transform var(--woo-transition);
}
.filter-group-header[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.filter-group-body {
    padding-bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.filter-group-body[hidden] {
    display: none;
}

.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    color: var(--woo-color-text);
    padding: 2px 0;
}
.filter-option:hover {
    color: #000;
}
.filter-option input[type="checkbox"] {
    width: 15px;
    height: 15px;
    border: 1.5px solid #bbb;
    border-radius: 3px;
    accent-color: #111;
    cursor: pointer;
    flex-shrink: 0;
}
.filter-count {
    color: var(--woo-color-muted);
    font-size: 12px;
    margin-left: auto;
}

/* ── Main / Grid ─────────────────────────────────────────────────── */
.woo-cat-main {
    flex: 1;
    min-width: 0;
}

/* Reset del ul de WooCommerce */
.woo-cat-main ul.products {
    display: grid !important;
    grid-template-columns: repeat(5, 1fr) !important;
    gap: var(--woo-gap) !important;
    margin: 0 !important;
    padding: 0 !important;
    list-style: none !important;
}

/* ── Tarjeta de producto ─────────────────────────────────────────── */
.product-card,
.woo-cat-main ul.products li.product {
    list-style: none;
    background: var(--woo-color-bg);
    border-radius: var(--woo-radius-md);
    overflow: hidden;
    transition: transform var(--woo-transition), box-shadow var(--woo-transition);
}
.product-card:hover,
.woo-cat-main ul.products li.product:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(0,0,0,.07);
}

/* Imagen */
.product-card-img-wrap,
.woo-cat-main ul.products li.product a.woocommerce-loop-product__link {
    display: block;
    position: relative;
    overflow: hidden;
    border-radius: var(--woo-radius-md) var(--woo-radius-md) 0 0;
    background: var(--woo-color-surface);
    aspect-ratio: 1 / 1;
}
.product-img,
.woo-cat-main ul.products li.product img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
    display: block;
    transition: transform 0.35s ease;
}
.product-card:hover .product-img,
.woo-cat-main ul.products li.product:hover img {
    transform: scale(1.04);
}

/* Badges */
.product-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 2;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.4;
}
.badge-agotado {
    background: var(--woo-color-badge-agotado-bg);
    color: var(--woo-color-badge-agotado-text);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0,0,0,.08);
}
.badge-nuevo {
    background: var(--woo-color-badge-nuevo-bg);
    color: var(--woo-color-badge-nuevo-text);
}

/* WooCommerce: onsale badge nativo → sobrescribir con nuestro estilo */
.woo-cat-main ul.products li.product .onsale {
    background: var(--woo-color-badge-nuevo-bg) !important;
    color: #fff !important;
    border-radius: 999px !important;
    font-size: 11px !important;
    font-weight: 600 !important;
    min-width: unset !important;
    min-height: unset !important;
    line-height: 1.4 !important;
    padding: 3px 10px !important;
    top: 10px !important;
    left: 10px !important;
    right: auto !important;
}

/* Info de la tarjeta */
.product-card-info {
    padding: 10px 12px 12px;
}
.woo-cat-main ul.products li.product .woocommerce-loop-product__title,
.product-name {
    font-size: 13px !important;
    font-weight: 500 !important;
    line-height: 1.35 !important;
    color: var(--woo-color-text) !important;
    margin: 0 0 6px !important;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.product-name a,
.woo-cat-main ul.products li.product .woocommerce-loop-product__title a {
    color: inherit;
    text-decoration: none;
}
.product-name a:hover {
    text-decoration: underline;
}

/* Categoría */
.product-cat {
    display: block;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--woo-color-muted);
    margin-bottom: 4px;
}
.product-cat a {
    color: inherit;
    text-decoration: none;
}

/* Precio */
.product-price,
.woo-cat-main ul.products li.product .price {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: var(--woo-color-text) !important;
    margin: 0 !important;
}
.woo-cat-main ul.products li.product .price del {
    color: var(--woo-color-muted) !important;
    font-weight: 400 !important;
    font-size: 12px !important;
    margin-right: 4px;
}

/* Ocultar el botón "Añadir al carrito" del loop (opcional) */
/* Descomenta si prefieres mostrarlo:
.woo-cat-main ul.products li.product .button { display: block; }
*/
.woo-cat-main ul.products li.product .button {
    display: none;
}

/* Tarjetas agotadas: imagen desaturada */
.product-card.is-outofstock .product-img {
    filter: grayscale(35%);
    opacity: 0.85;
}

/* ── Paginación ──────────────────────────────────────────────────── */
.woo-cat-main .woocommerce-pagination,
.woo-cat-main nav.woocommerce-pagination {
    margin-top: 32px;
    display: flex;
    justify-content: center;
}
.woo-cat-main .woocommerce-pagination ul {
    display: flex;
    align-items: center;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
}
.woo-cat-main .woocommerce-pagination ul li span,
.woo-cat-main .woocommerce-pagination ul li a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    border-radius: var(--woo-radius-sm);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--woo-color-text);
    border: 1px solid transparent;
    transition: background var(--woo-transition), border-color var(--woo-transition);
}
.woo-cat-main .woocommerce-pagination ul li a:hover {
    background: var(--woo-color-surface);
    border-color: var(--woo-color-border);
}
.woo-cat-main .woocommerce-pagination ul li span.current {
    background: var(--woo-color-text);
    color: #fff;
    border-color: var(--woo-color-text);
}
.woo-cat-main .woocommerce-pagination ul li .page-numbers.dots {
    border: none;
    background: none;
    color: var(--woo-color-muted);
    pointer-events: none;
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 1280px) {
    .woo-cat-main ul.products {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}
@media (max-width: 1024px) {
    .woo-cat-main ul.products {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .woo-cat-sidebar {
        --woo-sidebar-w: 190px;
    }
}
@media (max-width: 768px) {
    .woo-cat-body {
        flex-direction: column;
    }
    .woo-cat-sidebar {
        position: static;
        width: 100% !important;
        max-height: none;
        border-bottom: 1px solid var(--woo-color-border);
        padding-bottom: 12px;
        margin-bottom: 16px;
    }
    .woo-cat-sidebar.is-hidden {
        width: 0 !important;
        padding: 0;
        border: none;
        margin: 0;
        height: 0;
    }
    .woo-cat-main ul.products {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .orderby-wrap::before {
        display: none;
    }
}
@media (max-width: 480px) {
    .woo-cat-wrapper {
        padding: 0 16px 32px;
    }
    .woo-cat-main ul.products {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }
}

/* ── Nuevos estilos: filtros como links ─────────────────── */

/* Los filtros ahora son <a> no <label> */
.filter-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    cursor: pointer;
    color: var(--woo-color-text);
    padding: 3px 0;
    text-decoration: none;
    transition: color var(--woo-transition);
}
.filter-option:hover {
    color: #000;
}
.filter-option.is-active {
    font-weight: 500;
}

/* Checkbox visual (span en lugar de input) */
.filter-checkbox {
    width: 15px;
    height: 15px;
    border: 1.5px solid #bbb;
    border-radius: 3px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background var(--woo-transition), border-color var(--woo-transition);
    background: #fff;
}
.filter-option.is-active .filter-checkbox {
    background: #111;
    border-color: #111;
}
.filter-option.is-active .filter-checkbox::after {
    content: '';
    width: 8px;
    height: 5px;
    border-left: 1.5px solid #fff;
    border-bottom: 1.5px solid #fff;
    transform: rotate(-45deg) translateY(-1px);
    display: block;
}

/* Contador de activos en el header del grupo */
.filter-group-count {
    background: #111;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 999px;
    padding: 1px 6px;
    margin-left: auto;
    margin-right: 4px;
}

/* Punto indicador de filtros activos en botón Filtrar */
.filter-active-dot {
    width: 6px;
    height: 6px;
    background: #2563eb;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* Botón limpiar filtros */
.btn-clear-filters {
    font-size: 13px;
    color: var(--woo-color-muted);
    text-decoration: none;
    border: 1px solid var(--woo-color-border);
    border-radius: var(--woo-radius-sm);
    padding: 4px 10px;
    transition: color var(--woo-transition), border-color var(--woo-transition);
    white-space: nowrap;
}
.btn-clear-filters:hover {
    color: #c00;
    border-color: #c00;
}

/* Sin productos */
.woo-no-products {
    padding: 40px 0;
    text-align: center;
    color: var(--woo-color-muted);
}
.woo-no-products p {
    margin-bottom: 16px;
    font-size: 15px;
}


/* ══════════════════════════════════════════════════════════
   FIX: Alta especificidad para contrarrestar temas con Tailwind
══════════════════════════════════════════════════════════ */

/* Grid — forzar con wrapper + clase */
.woo-cat-wrapper .woo-cat-main ul.products,
.woo-cat-wrapper .woo-cat-main .products {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 16px !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
}

/* Cards — resetear lo que Tailwind pueda estar pisando */
.woo-cat-wrapper .woo-cat-main ul.products li.product,
.woo-cat-wrapper .woo-cat-main ul.products li.product-card {
    width: 100% !important;
    float: none !important;
    clear: none !important;
    margin: 0 !important;
    padding: 0 !important;
    background: var(--woo-color-bg) !important;
    border-radius: var(--woo-radius-md) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Imagen */
.woo-cat-wrapper .woo-cat-main ul.products li.product a.product-card-img-wrap,
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-card-img-wrap {
    display: block !important;
    position: relative !important;
    overflow: hidden !important;
    aspect-ratio: 1 / 1 !important;
    background: var(--woo-color-surface) !important;
    border-radius: 0 !important;
    flex-shrink: 0 !important;
}

.woo-cat-wrapper .woo-cat-main ul.products li.product .product-card-img-wrap img,
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

/* Info de la card */
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-card-info {
    padding: 10px 12px 12px !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 3px !important;
}

/* Categoría */
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-cat,
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-cat a {
    font-size: 10px !important;
    font-weight: 600 !important;
    letter-spacing: 0.06em !important;
    text-transform: uppercase !important;
    color: var(--woo-color-muted) !important;
    text-decoration: none !important;
    display: block !important;
    margin: 0 !important;
}

/* Nombre */
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-name,
.woo-cat-wrapper .woo-cat-main ul.products li.product .woocommerce-loop-product__title {
    font-size: 13px !important;
    font-weight: 500 !important;
    line-height: 1.35 !important;
    color: var(--woo-color-text) !important;
    margin: 0 0 4px !important;
    padding: 0 !important;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important;
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
}
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-name a {
    color: inherit !important;
    text-decoration: none !important;
    font-size: inherit !important;
}

/* Precio */
.woo-cat-wrapper .woo-cat-main ul.products li.product .product-price,
.woo-cat-wrapper .woo-cat-main ul.products li.product .price {
    font-size: 14px !important;
    font-weight: 600 !important;
    color: var(--woo-color-text) !important;
    margin: 0 !important;
    padding: 0 !important;
    display: block !important;
}
.woo-cat-wrapper .woo-cat-main ul.products li.product .price del {
    color: var(--woo-color-muted) !important;
    font-weight: 400 !important;
    font-size: 11px !important;
    margin-right: 4px !important;
    text-decoration: line-through !important;
}
.woo-cat-wrapper .woo-cat-main ul.products li.product .price ins {
    text-decoration: none !important;
    font-weight: 600 !important;
}

/* Ocultar botón añadir al carrito del loop */
.woo-cat-wrapper .woo-cat-main ul.products li.product .button,
.woo-cat-wrapper .woo-cat-main ul.products li.product .add_to_cart_button {
    display: none !important;
}

/* Responsive con alta especificidad */
@media (max-width: 1280px) {
    .woo-cat-wrapper .woo-cat-main ul.products,
    .woo-cat-wrapper .woo-cat-main .products {
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }
}
@media (max-width: 1024px) {
    .woo-cat-wrapper .woo-cat-main ul.products,
    .woo-cat-wrapper .woo-cat-main .products {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}
@media (max-width: 768px) {
    .woo-cat-wrapper .woo-cat-main ul.products,
    .woo-cat-wrapper .woo-cat-main .products {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}
