/* ==========================================================================
   MG Commerce — sidebar category list (v1.7.2)
   Styles the native WooCommerce Product Categories block in widget areas.
   The .mg-cat-* classes are added by category-sidebar.js (progressive
   enhancement) — without JS the full list stays visible and styled.
   ========================================================================== */

.widget .wc-block-product-categories {
    --mg-accent: var(--global-palette-highlight, var(--global-palette2, #db1321));
    --mg-border: #dde3e9;
    --mg-line: var(--global-palette7, #edf2f7);
    --mg-pill-bg: var(--global-palette7, #edf2f7);
}

.widget .wc-block-product-categories-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.widget .wc-block-product-categories-list-item {
    display: flex;
    flex-wrap: wrap;            /* nested list drops to the next line */
    align-items: center;
    gap: 6px;
    padding: 5px 0;
}

/* Subtle separator lines between items */
.widget .wc-block-product-categories-list-item + .wc-block-product-categories-list-item {
    border-top: 1px solid var(--mg-line);
}

.widget .wc-block-product-categories-list-item > a {
    flex: 1;
    min-width: 0;
    padding: 3px 0;
    text-decoration: none;
    color: inherit;
    transition: color 0.15s ease;
}

.widget .wc-block-product-categories-list-item > a:hover {
    color: var(--mg-accent);
}

/* --- Product count pill -------------------------------------------------- */
.widget .wc-block-product-categories-list-item-count {
    margin-left: auto;
    flex: 0 0 auto;
}

.widget .wc-block-product-categories-list-item-count span[aria-hidden] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--mg-pill-bg);
    color: var(--global-palette5, #4a5568);
    font-size: 0.75rem;
    line-height: 1.4;
    transition: background 0.15s ease, color 0.15s ease;
}

/* No theme-added parentheses around the number */
.widget .wc-block-product-categories-list-item-count::before,
.widget .wc-block-product-categories-list-item-count::after,
.widget .wc-block-product-categories-list-item-count span[aria-hidden]::before,
.widget .wc-block-product-categories-list-item-count span[aria-hidden]::after {
    content: none;
}

/* Parents with subcategories: chevron only, no count pill */
.mg-cat-list li.mg-cat-has-children > .wc-block-product-categories-list-item-count {
    display: none;
}

/* --- Chevron toggle (added by JS on categories with children) ------------- */
.widget .wc-block-product-categories .mg-cat-toggle {
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 6px;
    box-shadow: none;
    cursor: pointer;
    color: var(--global-palette6, #718096);
}

.widget .wc-block-product-categories .mg-cat-toggle:hover,
.widget .wc-block-product-categories .mg-cat-toggle:focus {
    background: var(--mg-pill-bg);
    box-shadow: none;
    color: var(--mg-accent);
}

.widget .wc-block-product-categories .mg-cat-toggle::before {
    content: "";
    display: block;
    width: 7px;
    height: 7px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg) translate(-1px, -1px);
    transition: transform 0.15s ease;
}

.widget .wc-block-product-categories li.mg-cat-open > .mg-cat-toggle::before {
    transform: rotate(225deg) translate(-2px, -2px);
}

/* --- Subcategories: collapsed by default, indented when open -------------- */
.widget .wc-block-product-categories-list-item > .wc-block-product-categories-list {
    flex-basis: 100%;
    margin: 4px 0 4px 10px;
    padding-left: 12px;
    border-left: 1px solid var(--mg-border);
}

.mg-cat-list li.mg-cat-has-children:not(.mg-cat-open) > .wc-block-product-categories-list {
    display: none;
}

/* --- Current category + open ancestors ------------------------------------ */
.widget .wc-block-product-categories li.mg-cat-current > a,
.widget .wc-block-product-categories li.mg-cat-trail > a {
    color: var(--mg-accent);
    font-weight: 700;
}

.widget .wc-block-product-categories li.mg-cat-current > .wc-block-product-categories-list-item-count span[aria-hidden] {
    background: var(--mg-accent);
    color: #fff;
}

/* --- Mobile: compact category selector box --------------------------------
   The toggle button (added by JS) shows the active category; tapping it
   expands the list inside the same box — same pattern as the checkout
   shipping method selector. Desktop never sees the button.              */
.widget .wc-block-product-categories .mg-cat-mobile-toggle {
    display: none;
}

@media (max-width: 1024px) {
    /* Kadence places the sidebar via desktop-only grid rules; below
       1025px the container falls back to DOM order (loop first, sidebar
       after). Flex + order moves the sidebar above the products, where
       the compact category selector belongs. Loads on shop archives only. */
    .has-sidebar .content-container {
        display: flex;
        flex-direction: column;
    }

    .has-sidebar .content-container > .primary-sidebar {
        order: -1;
        width: 100%;
        padding-top: 0.5rem;
        padding-bottom: 0;
    }

    .widget .wc-block-product-categories.mg-cat-list {
        border: 1px solid var(--mg-border);
        border-radius: 12px;
        background: #fff;
        overflow: hidden;
    }

    .widget .wc-block-product-categories .mg-cat-mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        width: 100%;
        margin: 0;
        padding: 12px 14px;
        background: #fff;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        cursor: pointer;
        font-weight: 600;
        color: var(--global-palette3, #1a202c);
        text-align: left;
    }

    .widget .wc-block-product-categories .mg-cat-mobile-toggle:hover,
    .widget .wc-block-product-categories .mg-cat-mobile-toggle:focus {
        background: #fff;
        color: var(--mg-accent);
        box-shadow: none;
    }

    .widget .wc-block-product-categories .mg-cat-mobile-toggle::after {
        content: "";
        flex: 0 0 auto;
        width: 8px;
        height: 8px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: rotate(45deg) translate(-2px, -2px);
        transition: transform 0.15s ease;
    }

    .widget .wc-block-product-categories.mg-cat-mobile-open .mg-cat-mobile-toggle::after {
        transform: rotate(225deg) translate(-2px, -2px);
    }

    /* Collapsed by default; expanding reveals the list in the same box */
    .widget .mg-cat-list:not(.mg-cat-mobile-open) > .wc-block-product-categories-list {
        display: none;
    }

    .widget .mg-cat-list > .wc-block-product-categories-list {
        border-top: 1px solid var(--mg-border);
        padding: 6px 14px 10px;
    }
}
