/*
|--------------------------------------------------------------------------
| BeanJars Mobile Main Menu
|--------------------------------------------------------------------------
| Scope: Main Menu / Homepage only
| Purpose: Mobile/tablet-only Main Menu UI overrides
| Rule: Desktop CSS remains untouched and protected
|--------------------------------------------------------------------------
*/

/* =========================================================
   Mobile/Tablet Main Menu: selected-category layout safety
   Purpose: prevent right-side viewport cut when sidebar appears
   Desktop: protected because this applies only up to 1024px
   ========================================================= */

@media (max-width: 1024px) {
    .marketplace-layout.has-sidebar {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;

        gap: 18px;
        padding-left: 12px;
        padding-right: 12px;
    }

    .marketplace-layout.has-sidebar .marketplace-sidebar {
        width: 210px;
        padding-left: 0;
        box-sizing: border-box;
    }

        .marketplace-layout.has-sidebar .marketplace-content {
        min-width: 0;
        box-sizing: border-box;
    }

            .marketplace-layout.has-sidebar .container.marketplace-content {
        flex: 1 1 0;
        width: auto;
        max-width: none;
        min-width: 0;
        margin-left: 0;
        margin-right: 0;
    }

    .marketplace-layout.has-sidebar .ad-item-link,
    .marketplace-layout.has-sidebar .ad-item {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .marketplace-layout.has-sidebar .ad-item .info {
        min-width: 0;
    }
}

/* =========================================================
   Wide Tablet Main Menu: selected-category layout breathing space
   Purpose: prevent content panel from sitting flush against right edge
   Desktop: protected because this applies only from 1025px to 1280px
   ========================================================= */

@media (min-width: 1025px) and (max-width: 1280px) {
    .marketplace-layout.has-sidebar {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;

        padding-left: 16px;
        padding-right: 28px;
    }

    .marketplace-layout.has-sidebar .container.marketplace-content {
        flex: 1 1 0;
        min-width: 0;
        max-width: none;
        box-sizing: border-box;
    }
}

/* =========================================================
   Mobile/Tablet Main Menu: homepage 2-column ad cards
   Purpose: keep homepage ad cards in 2 columns on supported mobile/tablet widths
   Desktop: protected because this applies only from 340px to 850px
   ========================================================= */

@media (min-width: 340px) and (max-width: 850px) {
    .marketplace-layout:not(.has-sidebar) .container.marketplace-content {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px;
        align-items: stretch;
    }

    .marketplace-layout:not(.has-sidebar) .ad-item-link {
        width: 100%;
        max-width: 100%;
        margin: 0;
        display: block;
    }

    .marketplace-layout:not(.has-sidebar) .ad-item {
        width: 100%;
        height: 100%;
        margin: 0;
        flex-direction: column;
        align-items: stretch;
        box-sizing: border-box;
    }

        .marketplace-layout:not(.has-sidebar) .container.marketplace-content .ad-item img {
        width: 100%;
        height: clamp(150px, 24vw, 190px);
        max-width: 100%;
        object-fit: contain;
        object-position: center;
        background-color: #f3f4f6;
        background-image: repeating-linear-gradient(
            45deg,
            rgba(209, 213, 219, 0.55) 0,
            rgba(209, 213, 219, 0.55) 1px,
            transparent 1px,
            transparent 12px
        );
        border-radius: 8px;
        display: block;
        flex-shrink: 0;
    }

    .marketplace-layout:not(.has-sidebar) .pagination {
        grid-column: 1 / -1;
        display: none;
    }
}

/* =========================================================
   Mobile/Tablet Main Menu: homepage canvas breathing space
   Purpose: keep the white ads canvas below the horizontal category row
   Desktop: protected because this applies only up to 850px
   ========================================================= */

@media (max-width: 850px) {
    .marketplace-layout:not(.has-sidebar) .container.marketplace-content {
        margin-top: 18px;
    }
}

/* =========================================================
   Mobile Phone Main Menu: homepage canvas side breathing space
   Purpose: prevent the white ads canvas from sitting flush against phone edges
   Desktop/tablet: protected because this applies only up to 600px
   ========================================================= */

@media (max-width: 600px) {
    .marketplace-layout:not(.has-sidebar) .container.marketplace-content {
        width: calc(100% - 24px);
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
    }
}

/* =========================================================
   Mobile/Tablet Main Menu: medium tablet canvas breathing space
   Purpose: keep tablet ads canvas safely below the horizontal category row
   Phones/desktop: protected because this applies only from 601px to 850px
   ========================================================= */

@media (min-width: 601px) and (max-width: 850px) {
    .marketplace-layout:not(.has-sidebar) .container.marketplace-content {
        margin-top: 18px;
    }
}

/* =========================================================
   Tablet Main Menu: homepage content alignment
   Purpose: visually align Type/Sort row and ads canvas under category grid
   Desktop: protected because this applies only from 851px to 1279px
   ========================================================= */

@media (min-width: 851px) and (max-width: 1279px) {
    .filters-sticky-bar .filter-row,
    .marketplace-layout:not(.has-sidebar) .container.marketplace-content {
        width: 90%;
        max-width: 1100px;
        margin-left: calc(5% + 6px);
        margin-right: calc(5% - 6px);
        box-sizing: border-box;
    }
}

/* =========================================================
   Asus Zenbook Fold Main Menu: category canvas top breathing space
   Purpose: prevent category canvas from touching the orange header
   Desktop/other mobile models: protected by narrow viewport range
   ========================================================= */

@media (min-width: 851px) and (max-width: 900px) {
    .filter-bar .main-category-grid {
        margin-top: 14px;
    }
}

/* =========================================================
   Mobile Phone Main Menu: trust badge containment
   Purpose: keep Buyer Protection badge inside narrow 2-column cards
   Desktop/tablet: protected because this applies only up to 480px
   ========================================================= */

@media (max-width: 380px) {
    .marketplace-layout:not(.has-sidebar) .ad-item .ad-trust-badge--protected,
    .marketplace-layout:not(.has-sidebar) .ad-item .ad-trust-badge--meetup {
        max-width: 100%;
        padding: 4px 8px;
        font-size: 9px;
        gap: 4px;
        box-sizing: border-box;
    }
}

/* =========================================================
   Nest Hub Max Main Menu: homepage ads canvas alignment
   Purpose: move the lower ads canvas slightly right for visual balance
   Desktop: protected because this applies only at 1280px viewport width
   ========================================================= */

@media (width: 1280px) {
    .marketplace-layout:not(.has-sidebar) .container.marketplace-content {
        width: calc(100% - 200px);
        max-width: 1080px;
        margin-left: auto;
        margin-right: auto;
        box-sizing: border-box;
    }
}

/* =========================================================
   Mobile Main Menu: horizontal main category row
   Purpose: show 10 main categories as finite horizontal scroll on mobile homepage
   Desktop: protected because this applies only up to 850px
   ========================================================= */

@media (max-width: 850px) {
    body {
        padding-top: 132px;
    }

    .filters-sticky-bar {
        display: block;
        position: relative;
        top: auto;
        z-index: auto;
        padding: 0 0 14px;
        background: #f0f2f5;
    }

    .filters-sticky-bar .filter-bar {
        display: flex;
        margin: 0;
        gap: 0;
    }

    .filter-bar .main-category-grid {
        width: 100%;
        max-width: none;
        margin: 0;
        padding: 4px 12px 8px;

        display: flex;
        gap: 14px;

        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;

        background: transparent;
        border-radius: 0;
        box-shadow: none;
        box-sizing: border-box;
    }

    .filter-bar .main-category-card {
        flex: 0 0 74px;
        min-height: auto;
        padding: 0;

        gap: 6px;

        border: none;
        border-radius: 0;
        background: transparent;
        box-shadow: none;

        scroll-snap-align: start;
    }

    .filter-bar .main-category-card__icon {
        width: 46px;
        height: 46px;
        font-size: 22px;
    }

    .filter-bar .main-category-card__label {
        font-size: 10px;
        line-height: 1.2;
    }

    .filter-bar .filter-row {
        display: none;
    }
}

/* =========================================================
   Mobile Category Browser Page
   Purpose: Page 2 mobile category selection layout only
   Desktop/global: protected by wrapper class and max-width 850px
   ========================================================= */

@media (max-width: 850px) {
    .mobile-category-browser {
        min-height: calc(100vh - 132px);
        background: #f0f2f5;
        box-sizing: border-box;
    }

        .mobile-category-browser__header {
        display: grid;
        grid-template-columns: 112px minmax(0, 1fr);
        align-items: center;
        min-height: 64px;
        padding: 14px 14px 12px;
        background: #f0f2f5;
        box-sizing: border-box;
    }

       .mobile-category-browser__back {
        width: 38px;
        height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: #0F9F9A;
        color: #ffffff;
        text-decoration: none;
        box-shadow: 0 3px 10px rgba(15, 23, 42, 0.14);
    }

    .mobile-category-browser__back-icon {
        width: 22px;
        height: 22px;
        display: block;
        fill: none;
        stroke: currentColor;
        stroke-width: 2.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

        .mobile-category-browser__title {
        grid-column: 2;
        justify-self: center;
        margin: 0;
        color: #0F9F9A;
        font-size: 24px;
        line-height: 1.2;
        font-weight: 800;
        text-align: center;
    }

    .mobile-category-browser__layout {
        display: grid;
        grid-template-columns: 112px minmax(0, 1fr);
        gap: 0;
        width: 100%;
        box-sizing: border-box;
    }

    .mobile-category-browser__main-list {
        display: flex;
        flex-direction: column;
        gap: 2px;
        max-height: calc(100vh - 210px);
        overflow-y: auto;
        background: #ffffff;
        border-right: 1px solid #e5e7eb;
        box-sizing: border-box;
    }

    .mobile-category-browser__main-link {
        display: flex;
        align-items: center;
        gap: 6px;
        min-height: 46px;
        padding: 8px 8px;
        color: #374151;
        font-size: 11px;
        line-height: 1.2;
        font-weight: 700;
        text-decoration: none;
        border-left: 4px solid transparent;
        box-sizing: border-box;
    }

    .mobile-category-browser__main-link.is-active {
        background: #fff3ed;
        color: #0F9F9A;
        border-left-color: #0F9F9A;
    }

    .mobile-category-browser__main-icon {
        flex: 0 0 auto;
        font-size: 15px;
    }

    .mobile-category-browser__subcategories {
        min-width: 0;
        padding: 0 12px 18px;
        box-sizing: border-box;
    }

    .mobile-category-browser__group {
        margin-bottom: 18px;
    }

    .mobile-category-browser__group-title {
        margin: 10px 0 10px;
        color: #111827;
        font-size: 14px;
        line-height: 1.3;
        font-weight: 800;
    }

    .mobile-category-browser__grid {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px;
    }

    .mobile-category-browser__card {
        min-width: 0;
        min-height: 86px;
        padding: 10px 6px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        gap: 7px;
        background: #ffffff;
        border-radius: 14px;
        color: #374151;
        text-align: center;
        text-decoration: none;
        box-shadow: 0 2px 8px rgba(15, 23, 42, 0.07);
        box-sizing: border-box;
    }

    .mobile-category-browser__card-icon {
        width: 38px;
        height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: #fff3ed;
        font-size: 19px;
    }

    .mobile-category-browser__card-label {
        max-width: 100%;
        color: #374151;
        font-size: 10.5px;
        line-height: 1.2;
        font-weight: 700;
        overflow-wrap: anywhere;
    }
}

/* =========================================================
   Mobile Category Result Back Button
   Purpose: Page 3 mobile result navigation back to Page 2 only
   Desktop/global: protected by max-width 850px
   ========================================================= */

@media (max-width: 850px) {
    .mobile-category-result-topbar {
        width: calc(100% - 24px);
        margin: 0 auto;
        padding: 10px 0 0;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        background: #f0f2f5;
        box-sizing: border-box;
    }

        .mobile-category-result-back__link {
        width: 38px;
        height: 38px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: #0F9F9A;
        color: #ffffff;
        text-decoration: none;
        box-shadow: 0 3px 10px rgba(15, 23, 42, 0.14);
    }

    .mobile-category-result-back__icon {
        width: 22px;
        height: 22px;
        display: block;
        fill: none;
        stroke: currentColor;
        stroke-width: 2.8;
        stroke-linecap: round;
        stroke-linejoin: round;
    }

            .mobile-category-result-sort {
        display: inline-flex;
        align-items: center;
        margin-left: auto;
    }

    .mobile-category-result-sort__select {
        height: 34px;
        max-width: 108px;
        padding: 0 10px;
        border: 1px solid #e5e7eb;
        border-radius: 999px;
        background: #ffffff;
        color: #374151;
        font-size: 12px;
        font-weight: 800;
        box-shadow: 0 3px 10px rgba(15, 23, 42, 0.10);
        box-sizing: border-box;
    }
}

/* =========================================================
   Tablet Mobile Category Result: topbar canvas alignment
   Purpose: align Sort control with the right edge of the ads canvas
   Phones/desktop: protected because this applies only from 601px to 850px
   ========================================================= */

@media (min-width: 601px) and (max-width: 850px) {
    .mobile-category-result-topbar {
        width: calc(100% - 48px);
        max-width: 720px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* =========================================================
   Mid Tablet Mobile Category Result: topbar fine alignment
   Purpose: align Sort control on Galaxy Tab S4 / iPad Mini range
   Phones/iPad Air/desktop: protected by narrow viewport range
   ========================================================= */

@media (min-width: 700px) and (max-width: 800px) {
    .mobile-category-result-topbar {
        width: calc(100% - 64px);
        max-width: 680px;
    }
}
