/*
 * Rankly Produktkategorier – clean category-page layout (child theme 1.0.29).
 *
 * Important ownership rule:
 * - This file owns the Productkategori pills and the selected Productkategori result.
 * - Rankly MVP owns the ordinary category carousels and their vertical spacing.
 * - No historical fallback/patch blocks are kept here. Each geometry rule exists once.
 */

/* --------------------------------------------------------------------------
 * Shared tokens / defaults. Admin settings override these inline.
 * -------------------------------------------------------------------------- */
.bbpp-rankly-product-pills,
.bbpp-rankly-product-results {
    --bbpp-rpc-pills-top: 10px;
    --bbpp-rpc-pills-top-mobile: 8px;
    --bbpp-rpc-results-top: 20px;
    --bbpp-rpc-results-bottom: 42px;
    --bbpp-rpc-results-top-mobile: 16px;
    --bbpp-rpc-results-bottom-mobile: 42px;
    --bbpp-rpc-heading-bottom: 18px;
    --bbpp-rpc-heading-bottom-mobile: 14px;
}

/* --------------------------------------------------------------------------
 * Productkategori pills.
 * The bottom margin is intentionally zero. On the ordinary category view,
 * Rankly MVP's "Till innehåll ovanför" controls the next gap. When a
 * Productkategori is selected, .bbpp-rankly-product-results padding-top owns it.
 * Padding is intentional: unlike vertical margin it cannot collapse into parent/sibling spacing.
 * -------------------------------------------------------------------------- */
.bbpp-rankly-product-pills {
    box-sizing: border-box;
    width: min(100%, 1500px);
    max-width: 1500px;
    margin: var(--bbpp-rpc-pills-top, 10px) auto 0;
    padding: 0;
}

.bbpp-rankly-product-pills__track {
    display: flex;
    align-items: center;
    gap: 8px;
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
}

.bbpp-rankly-product-pills__track::-webkit-scrollbar {
    display: none;
}

.bbpp-rankly-product-pill {
    flex: 0 0 auto;
    scroll-snap-align: start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 14px;
    border-style: solid;
    border-width: var(--bbpp-rpc-pill-border-width, 1px);
    border-color: var(--bbpp-rpc-pill-border-color, #e2e8f0);
    border-radius: var(--bbpp-rpc-pill-radius, 999px);
    background: var(--bbpp-rpc-pill-item-bg, var(--bbpp-rpc-pill-bg, #fff));
    color: var(--bbpp-rpc-pill-item-text, var(--bbpp-rpc-pill-text, #111827)) !important;
    font-size: var(--bbpp-rpc-pill-font-size, 13px);
    font-weight: var(--bbpp-rpc-pill-font-weight, 650);
    line-height: 1.15;
    white-space: nowrap;
    text-decoration: none !important;
    box-shadow: none !important;
    transform: scale(1);
    transform-origin: center;
    transition: transform .18s ease, background-color .18s ease, color .18s ease, border-color .18s ease;
}

.bbpp-rankly-product-pill.is-active {
    background: var(--bbpp-rpc-pill-active-bg, #111827);
    color: var(--bbpp-rpc-pill-active-text, #fff) !important;
    border-color: var(--bbpp-rpc-pill-active-border, #111827);
    box-shadow: none !important;
}

.bbpp-rankly-product-pill:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
    box-shadow: none !important;
}

/* Desktop hover: reserve exactly the same amount we cancel with negative margin,
 * so hover room does not secretly add vertical height to the category page. */
@media (min-width: 783px) and (hover: hover) {
    .bbpp-rankly-product-pills {
        overflow: visible;
    }

    .bbpp-rankly-product-pills__track {
        width: calc(100% + 20px);
        margin: -10px;
        padding: 10px;
    }

    .bbpp-rankly-product-pill:hover {
        position: relative;
        z-index: 2;
        transform: scale(1.07);
        box-shadow: none !important;
        opacity: 1;
    }

    /* Mouse clicks should not leave the theme/browser dotted ring. */
    .bbpp-rankly-product-pill:focus {
        outline: none !important;
        box-shadow: none !important;
    }

    .bbpp-rankly-product-pill:focus-visible {
        outline: 2px solid currentColor !important;
        outline-offset: 3px;
    }
}

/* --------------------------------------------------------------------------
 * AJAX product area. Ordinary Rankly category carousels live inside this too,
 * so do not impose overflow/gutters on the parent.
 * -------------------------------------------------------------------------- */
.bbpp-rankly-product-area {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow: visible;
    transition: opacity .14s ease;
}

.bbpp-rankly-product-area.is-loading {
    opacity: .42;
}

.bbpp-rankly-product-pills.is-loading .bbpp-rankly-product-pill {
    pointer-events: none;
}

/* --------------------------------------------------------------------------
 * Selected Productkategori result – desktop/tablet.
 * -------------------------------------------------------------------------- */
.bbpp-rankly-product-results {
    clear: both;
    box-sizing: border-box;
    width: min(100%, 1500px);
    max-width: 1500px;
    min-width: 0;
    margin: 0 auto var(--bbpp-rpc-results-bottom, 42px);
    padding: var(--bbpp-rpc-results-top, 20px) 0 0;
}

.bbpp-rankly-product-results__title {
    display: block;
    box-sizing: border-box;
    width: 100%;
    margin: 0 0 var(--bbpp-rpc-heading-bottom, 18px) !important;
    padding: 0 !important;
    color: var(--bbpp-rpc-heading-color, #111827) !important;
    font-size: var(--bbpp-rpc-heading-size, 30px) !important;
    line-height: var(--bbpp-rpc-heading-line-height, 1.15) !important;
    font-weight: var(--bbpp-rpc-heading-weight, 800) !important;
    text-align: var(--bbpp-rpc-heading-align, left) !important;
}

.bbpp-rankly-product-results__products {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
}

/* Neutralise the generic Rankly archive container only inside the selected
 * Productkategori result. The card internals themselves remain Rankly-owned. */
.bbpp-rankly-product-results .rankly-product-group-results__archive,
.bbpp-rankly-product-results .rankly-archive,
.bbpp-rankly-product-results .rankly-archive.alignfull,
.bbpp-rankly-product-results .rankly-archive__inner,
.bbpp-rankly-product-results .rankly-archive__inner[style],
.bbpp-rankly-product-results .rankly-archive__results,
.bbpp-rankly-product-results .rankly-results,
.bbpp-rankly-product-results .rankly-table-wrap,
.bbpp-rankly-product-results .rankly-table-scroll,
.bbpp-rankly-product-results .rankly-table {
    box-sizing: border-box !important;
    max-width: 100% !important;
    min-width: 0 !important;
}

.bbpp-rankly-product-results .rankly-product-group-results__archive,
.bbpp-rankly-product-results .rankly-archive,
.bbpp-rankly-product-results .rankly-archive.alignfull,
.bbpp-rankly-product-results .rankly-archive__inner,
.bbpp-rankly-product-results .rankly-archive__inner[style] {
    position: static !important;
    left: auto !important;
    right: auto !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    transform: none !important;
}

.bbpp-rankly-product-results .rankly-archive.alignfull {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* One desktop card gap for ordinary category rows and selected results. */
@media (min-width: 783px) {
    body {
        --bbpp-rankly-category-card-gap-desktop: 14px;
    }

    html body .rankly-category-products__archive[data-rankly-category-archive="1"][data-rankly-view="cards"] .rankly-table tbody,
    html body .bbpp-rankly-product-results .rankly-archive[data-rankly-view="cards"] .rankly-table tbody {
        gap: var(--bbpp-rankly-category-card-gap-desktop, 14px) !important;
        column-gap: var(--bbpp-rankly-category-card-gap-desktop, 14px) !important;
        row-gap: var(--bbpp-rankly-category-card-gap-desktop, 14px) !important;
    }
}

/* --------------------------------------------------------------------------
 * Mobile.
 * - Pill scroller is full viewport width, first pill starts at 16px.
 * - Ordinary Rankly carousels are untouched.
 * - Selected Productkategori becomes a contained two-column grid.
 * -------------------------------------------------------------------------- */
@media (max-width: 782px) {
    .bbpp-rankly-product-pills {
        position: relative;
        left: 50%;
        width: 100vw;
        max-width: none;
        margin-top: var(--bbpp-rpc-pills-top-mobile, 8px);
        margin-right: -50vw;
        margin-bottom: 0;
        margin-left: -50vw;
        padding: 0;
    }

    .bbpp-rankly-product-pills__track {
        width: 100%;
        max-width: none;
        gap: 7px;
        margin: 0;
        padding: 0 16px;
        scroll-padding-left: 16px;
        overscroll-behavior-inline: contain;
    }

    .bbpp-rankly-product-pill {
        min-height: 32px;
        padding: 6px 12px;
        font-size: var(--bbpp-rpc-pill-font-size, 13px);
    }

    .bbpp-rankly-product-results {
        position: static !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 0 var(--bbpp-rpc-results-bottom-mobile, 42px) !important;
        padding: var(--bbpp-rpc-results-top-mobile, 16px) 0 0 !important;
        overflow: visible !important;
    }

    .bbpp-rankly-product-results__title {
        width: 100% !important;
        margin-bottom: var(--bbpp-rpc-heading-bottom-mobile, 14px) !important;
        font-size: var(--bbpp-rpc-heading-size-mobile, 24px) !important;
    }

    .bbpp-rankly-product-results__products {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    html body .bbpp-rankly-product-results .rankly-product-group-results__archive,
    html body .bbpp-rankly-product-results .rankly-archive,
    html body .bbpp-rankly-product-results .rankly-archive.alignfull,
    html body .bbpp-rankly-product-results .rankly-archive__inner,
    html body .bbpp-rankly-product-results .rankly-archive__inner[style],
    html body .bbpp-rankly-product-results .rankly-archive__results,
    html body .bbpp-rankly-product-results .rankly-results,
    html body .bbpp-rankly-product-results .rankly-table-wrap,
    html body .bbpp-rankly-product-results .rankly-table-scroll,
    html body .bbpp-rankly-product-results .rankly-table {
        position: static !important;
        left: auto !important;
        right: auto !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        transform: none !important;
    }

    html body .bbpp-rankly-product-results .rankly-table-scroll {
        overflow-x: visible !important;
        overflow-y: visible !important;
        -webkit-overflow-scrolling: auto !important;
        overscroll-behavior-x: auto !important;
    }

    html body .bbpp-rankly-product-results .rankly-archive[data-rankly-view="cards"] .rankly-table tbody {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        grid-auto-flow: row !important;
        gap: 12px !important;
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        justify-content: stretch !important;
        justify-items: stretch !important;
        align-items: stretch !important;
        overflow: visible !important;
    }

    html body .bbpp-rankly-product-results .rankly-archive[data-rankly-view="cards"] .rankly-table tbody > tr.rankly-row--product {
        box-sizing: border-box !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 0 !important;
        flex: none !important;
    }

    html body .bbpp-rankly-product-results .rankly-archive[data-rankly-view="cards"] .rankly-table tbody > tr.rankly-row--detail {
        grid-column: 1 / -1 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    html body .bbpp-rankly-product-results .rankly-productcell,
    html body .bbpp-rankly-product-results .rankly-productcell__text,
    html body .bbpp-rankly-product-results .rankly-table td,
    html body .bbpp-rankly-product-results .rankly-thumb,
    html body .bbpp-rankly-product-results .rankly-thumb.rankly-thumb--empty {
        max-width: 100% !important;
        min-width: 0 !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .bbpp-rankly-product-area,
    .bbpp-rankly-product-pill {
        transition: none;
    }
}
