/**
 * Catalog Category Page - Mobile Layout (≤768px)
 * Mobile-specific ordering and layout for category pages
 */

@media (max-width: 768px) {
    /* =================================
       Mobile: Force Column Layout
       ================================= */
    .catalog-category-view .page-main,
    .catalogsearch-result-index .page-main {
        padding: 0px 1% !important;
    }

    /* Columns must be flex for order to work */
    .catalog-category-view .columns,
    .catalogsearch-result-index .columns {
        display: flex !important;
        flex-direction: column !important;
    }

    /* =================================
       Mobile: Sidebar (Filters)
       ================================= */
    .catalog-category-view .sidebar.sidebar-main,
    .catalogsearch-result-index .sidebar.sidebar-main {
        width: 100% !important;
        order: 1 !important;
    }

    /* =================================
       Mobile: Main Content Area - Must be flex for child ordering
       ================================= */
    .catalog-category-view .column.main,
    .catalogsearch-result-index .column.main {
        width: 100% !important;
        order: 2 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    /* =================================
       Mobile: Element Ordering Inside .column.main
       Removed CSS order properties - using Magento XML layout instead
       ================================= */

    /* Spacing adjustments only */
    .page-layout-2columns-left .column.main > .page-title-wrapper {
        margin-bottom: 1rem !important;
    }

    .page-layout-2columns-left .column.main > .toolbar.toolbar-products:not(.toolbar-bottom) {
        margin-bottom: 1rem !important;
    }

    /* Products Wrapper Inside Category Block */
    .catalog-category-view .products.wrapper,
    .catalogsearch-result-index .products.wrapper {
        margin-bottom: 1rem;
    }

    /* Bottom Toolbar spacing - order controlled by XML layout */
    .page-layout-2columns-left .column.main > .toolbar-bottom {
        margin-top: 1.5rem !important;
        margin-bottom: 0 !important;
    }

    /* =================================
       Mobile: Toolbar Styling - COMPACT SINGLE ROW
       ================================= */
    .toolbar.toolbar-products {
        background: #f8f9fa;
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    .toolbar-row {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.5rem !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    /* Hide view mode buttons on mobile */
    .toolbar-viewmode {
        display: none !important;
    }

    /* Hide item count text */
    .toolbar-amount {
        display: none !important;
    }

    /* Hide sort/limiter labels */
    .toolbar-sorter label,
    .toolbar-limiter label {
        display: none !important;
    }

    /* Left section - just pagination */
    .toolbar-left {
        display: none !important;
    }

    /* Center section - pagination */
    .toolbar-center {
        flex: 1 !important;
        display: flex !important;
        justify-content: center !important;
    }

    /* Right section - sort dropdown only */
    .toolbar-right {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.5rem !important;
        align-items: center !important;
    }

    /* Sort dropdown - compact */
    .toolbar-sorter {
        margin: 0 !important;
    }

    .toolbar-sorter select {
        padding: 0.5rem;
        font-size: 0.8125rem;
        border: 1px solid #d0d0d0;
        border-radius: 4px;
        background: white;
        min-height: 36px;
        max-width: 120px;
    }

    /* Limiter - hide completely on mobile */
    .toolbar-limiter {
        display: none !important;
    }

    /* Pagination styling - compact */
    .toolbar .pages {
        margin: 0;
    }

    .toolbar .pages .items {
        display: flex;
        gap: 0.25rem;
        justify-content: center;
        flex-wrap: nowrap;
    }

    .toolbar .pages .item a,
    .toolbar .pages .item strong {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 36px;
        min-height: 36px;
        padding: 0.375rem;
        border: 1px solid #d0d0d0;
        border-radius: 4px;
        background: white;
        font-size: 0.875rem;
        text-decoration: none;
        color: #333;
        transition: all 0.2s;
    }

    .toolbar .pages .item strong,
    .toolbar .pages .item.current strong {
        background: var(--era-navy, #1e3a5f);
        color: white;
        border-color: var(--era-navy, #1e3a5f);
        font-weight: 600;
    }

    .toolbar .pages .item a:hover {
        background: #f0f0f0;
        border-color: #999;
    }

    /* Previous/Next buttons */
    .toolbar .pages .action.previous,
    .toolbar .pages .action.next {
        min-width: 36px;
        min-height: 36px;
    }

    /* Hide page numbers except current and adjacent */
    .toolbar .pages .item:not(.current):not(.pages-item-previous):not(.pages-item-next) {
        display: none;
    }

    .toolbar .pages .item.current {
        display: flex;
    }

    /* =================================
       Mobile: Floating Filter Button (FAB)
       ================================= */

    .bi::before, [class^="bi-"]::before, [class*=" bi-"]::before {
        margin-left: 5px;
        margin-top: 2px;
    }

    /* Create floating filter button - MUST override all sidebar positioning */
    body .catalog-category-view .sidebar.sidebar-main .filter-toggle,
    body .catalogsearch-result-index .sidebar.sidebar-main .filter-toggle,
    body .catalog-category-view .sidebar .filter-toggle,
    body .catalogsearch-result-index .sidebar .filter-toggle,
    body .catalog-category-view .filter-toggle,
    body .catalogsearch-result-index .filter-toggle,
    body .sidebar.sidebar-main .filter-toggle,
    body .sidebar .filter-toggle,
    body .filter-toggle,
    .catalog-category-view .sidebar.sidebar-main .filter-toggle,
    .catalogsearch-result-index .sidebar.sidebar-main .filter-toggle,
    .catalog-category-view .sidebar .filter-toggle,
    .catalogsearch-result-index .sidebar .filter-toggle,
    .catalog-category-view .filter-toggle,
    .catalogsearch-result-index .filter-toggle,
    .sidebar.sidebar-main .filter-toggle,
    .sidebar .filter-toggle,
    .filter-toggle {
        position: fixed !important;
        inset: auto 20px !important;
        width: 50px !important;
        height: 50px !important;
        border-radius: 50% !important;
        background: var(--era-red, #e4002a) !important;
        color: white !important;
        border: 1px solid #000 !important;
        box-shadow: 0 4px 12px rgba(228, 0, 42, 0.4) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 1040 !important;
        padding: 0 !important;
        margin: 0 !important;
        transition: all 0.3s ease !important;
        transform: none !important;
    }

    .sidebar .filter-toggle i,
    .filter-toggle i {
        margin: 0 !important;
    }

    .sidebar .filter-toggle:hover,
    .sidebar .filter-toggle:active,
    .filter-toggle:hover,
    .filter-toggle:active {
        background: var(--era-navy, #1e3a5f) !important;
        transform: scale(1.1) !important;
        box-shadow: 0 6px 16px rgba(30, 58, 95, 0.5) !important;
    }

    .sidebar .filter-toggle i,
    .filter-toggle i {
        font-size: 1.5rem !important;
        margin: 0 !important;
    }

    /* Hide the text inside button, show only icon */
    .sidebar .filter-toggle,
    .filter-toggle {
        font-size: 0 !important;
        line-height: 0 !important;
    }
}
