/* ============================================================================
   AGROBOX - MOBILE RESPONSIVE IMPROVEMENTS v4
   ============================================================================ */


/* ============================================================================
   1. MEILISEARCH INPUT — LARGER ON DESKTOP, COMPACT ON MOBILE
   ============================================================================ */

.meilisearch-wrapper {
    min-width: 0 !important;
    width: 100%;
    max-width: 100%;
    padding: 0;
}

/* Allow the search container to grow and fill available header space */
.meilisearch-container {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 800px;
}

/* The right group needs to also grow to fill space between logo and icons */
.wp-block-group.is-content-justification-right.is-nowrap.wp-block-group-is-layout-flex {
    flex: 1 1 auto;
    min-width: 0;
}

/* On large screens let the form stretch fully */
.wp-block-group.alignwide .meilisearch-form,
.meilisearch-form {
    max-width: 100% !important;
    width: 100% !important;
}

/* Desktop: bigger, more prominent */
.meilisearch-input {
    padding: 0.75rem 3.25rem 0.75rem 2.75rem;
    font-size: 1.0625rem; /* ~17px */
    height: 48px;
    width: 100%;
}

.meilisearch-icon {
    left: 0.875rem;
    width: 22px;
    height: 22px;
}

.meilisearch-clear {
    right: 0.75rem;
}

@media (max-width: 1024px) {
    .meilisearch-input {
        font-size: 1rem;
        height: 44px;
        padding: 0.625rem 3rem 0.625rem 2.5rem;
    }
}

@media (max-width: 768px) {
    /* Wrap header flex so search drops to its own row */
    .wp-block-group.alignwide.is-nowrap {
        flex-wrap: wrap !important;
        align-items: center;
    }

    .wp-block-site-title {
        flex: 0 0 auto;
    }

    .wp-block-group.is-content-justification-right.is-nowrap {
        flex-wrap: wrap !important;
        width: 100%;
        gap: 8px;
        justify-content: flex-end !important;
    }

    .meilisearch-container {
        flex: 1 1 100%;
        order: 10;
        width: 100%;
    }

    .meilisearch-input {
        font-size: 16px; /* prevents iOS zoom */
        height: 40px;
        padding: 0.5rem 2.75rem 0.5rem 2.25rem;
    }

    .meilisearch-icon {
        left: 0.625rem;
        width: 18px;
        height: 18px;
    }

    .meilisearch-results {
        left: 0;
        right: 0;
        max-height: 70vh;
        overflow-y: auto;
    }

    .meilisearch-results-grid {
        grid-template-columns: 1fr !important;
    }

    .meilisearch-categories-column {
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
    }
}

@media (max-width: 480px) {
    .meilisearch-input { height: 38px; }
    .meilisearch-results { max-height: 60vh; }
}


/* ============================================================================
   2. CUSTOM CATEGORY MENU — DESKTOP vs MOBILE
   ============================================================================ */

/* ── Desktop: horizontal bar ── */
.custom-category-menu {
    background: #2c5aa0;
    width: 100%;
}

.custom-category-menu-wrapper {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

.custom-category-menu-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0;
}

.custom-category-menu-item {
    margin: 0;
}

.custom-category-menu-link {
    display: block;
    padding: 12px 18px;
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.2s;
}

.custom-category-menu-link:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

/* Hamburger button: hidden on desktop by default (JS injects it unconditionally) */
.custom-menu-hamburger {
    display: none;
}

/* ── Mobile: hide the bar, show hamburger ── */
@media (max-width: 768px) {
    /* Hide the horizontal nav bar entirely */
    .custom-category-menu {
        display: none;
    }

    /* Hamburger button — injected by JS, placed in the header */
    .custom-menu-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        background: none;
        border: 1px solid #e0e0e0;
        border-radius: 6px;
        cursor: pointer;
        color: #333;
        padding: 0;
        flex-shrink: 0;
        transition: background 0.2s, border-color 0.2s;
    }

    .custom-menu-hamburger:hover {
        background: #f0f0f0;
        border-color: #bbb;
    }

    /* Three bars icon */
    .custom-menu-hamburger .hb-bar {
        display: block;
        width: 20px;
        height: 2px;
        background: #333;
        border-radius: 2px;
        position: absolute;
        transition: all 0.28s ease;
    }

    .custom-menu-hamburger .hb-wrap {
        position: relative;
        width: 20px;
        height: 14px;
    }

    .custom-menu-hamburger .hb-bar:nth-child(1) { top: 0; }
    .custom-menu-hamburger .hb-bar:nth-child(2) { top: 6px; }
    .custom-menu-hamburger .hb-bar:nth-child(3) { top: 12px; }

    /* Animate to X when open */
    .custom-menu-hamburger.is-open .hb-bar:nth-child(1) {
        top: 6px;
        transform: rotate(45deg);
    }
    .custom-menu-hamburger.is-open .hb-bar:nth-child(2) {
        opacity: 0;
        transform: scaleX(0);
    }
    .custom-menu-hamburger.is-open .hb-bar:nth-child(3) {
        top: 6px;
        transform: rotate(-45deg);
    }

    /* Backdrop overlay */
    .custom-menu-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        z-index: 9998;
    }

    .custom-menu-backdrop.is-visible {
        display: block;
    }

    /* Slide-in drawer */
    .custom-menu-drawer {
        position: fixed;
        top: 0;
        left: -100%;
        width: min(300px, 82vw);
        height: 100vh;
        background: #fff;
        z-index: 9999;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        display: flex;
        flex-direction: column;
    }

    .custom-menu-drawer.is-open {
        left: 0;
    }

    /* Drawer header */
    .custom-menu-drawer-header {
        background: #2c5aa0;
        color: #fff;
        padding: 16px 20px;
        font-size: 16px;
        font-weight: 700;
        flex-shrink: 0;
    }

    /* Drawer nav list */
    .custom-menu-drawer ul {
        list-style: none;
        margin: 0;
        padding: 8px 0;
        flex: 1;
    }

    .custom-menu-drawer li {
        border-bottom: 1px solid #f0f0f0;
    }

    .custom-menu-drawer a {
        display: block;
        padding: 14px 20px;
        font-size: 15px;
        color: #333;
        text-decoration: none;
        transition: background 0.15s, color 0.15s;
    }

    .custom-menu-drawer a:hover {
        background: #f0f5ff;
        color: #2c5aa0;
    }
}


/* ============================================================================
   3. LEFT SIDEBAR — COLLAPSIBLE, CLOSED BY DEFAULT ON MOBILE
   ============================================================================ */

.sidebar-mobile-toggle {
    display: none;
}

@media (max-width: 768px) {
    .category-page-inner {
        grid-template-columns: 1fr !important;
        padding: 12px 12px !important;
        gap: 16px !important;
    }

    .category-sidebar {
        position: static !important;
        width: 100%;
    }

    .category-sidebar-inner {
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }

    .category-sidebar-title {
        display: none;
    }

    /* Show toggle button */
    .sidebar-mobile-toggle {
        display: flex;
        width: 100%;
        background: #2c5aa0;
        color: #fff;
        border: none;
        border-radius: 6px 6px 0 0;
        padding: 12px 16px;
        font-size: 15px;
        font-weight: 600;
        cursor: pointer;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        transition: background 0.2s;
    }

    .sidebar-mobile-toggle:hover { background: #1e3d6f; }

    .sidebar-mobile-toggle .toggle-arrow {
        font-size: 11px;
        transition: transform 0.3s ease;
        flex-shrink: 0;
    }

    .sidebar-mobile-toggle.is-open .toggle-arrow {
        transform: rotate(180deg);
    }

    /* Hidden by default — JS adds .is-open to .category-sidebar to show */
    .category-sidebar .category-menu {
        display: none;
        border: 1px solid #e0e0e0;
        border-top: none;
        border-radius: 0 0 6px 6px;
        background: #f9f9f9;
        padding: 12px;
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .category-sidebar.is-open .category-menu {
        display: block;
    }

    .category-link {
        font-size: 14px !important;
        padding: 8px 10px !important;
    }

    .category-menu-list.level-1,
    .category-menu-list.level-2 {
        margin-left: 14px !important;
    }
}

@media (max-width: 480px) {
    .category-sidebar .category-menu { max-height: 50vh; }
    .category-link { font-size: 13px !important; padding: 7px 8px !important; }
}


/* ============================================================================
   4. GENERAL MOBILE IMPROVEMENTS
   ============================================================================ */

@media (max-width: 768px) {
    body { overflow-x: hidden; }

    .category-page-container,
    .category-content { max-width: 100%; overflow-x: hidden; }

    .category-products .product .button,
    .category-products .product .added_to_cart {
        min-height: 40px !important;
        font-size: 13px !important;
    }

    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="tel"], input[type="search"],
    select, textarea {
        font-size: 16px !important;
    }

    table, .woocommerce-cart table.cart {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 480px) {
    .wp-block-site-title a { font-size: 1.2rem !important; }

    .wp-block-template-part[data-area="header"],
    header.wp-block-group { padding: 10px 12px !important; }

    .pagination-list { gap: 4px; }
    .pagination-link { padding: 6px 10px; font-size: 13px; min-width: 36px; }
}

@media (max-width: 360px) {
    .category-products .products { grid-template-columns: repeat(1, 1fr) !important; }
    .subcategories-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (hover: none) and (pointer: coarse) {
    .subcategory-card:hover,
    .category-products .product:hover,
    .category-card:hover { transform: none; }
}

.meilisearch-results,
.category-sidebar .category-menu,
.custom-menu-drawer { -webkit-overflow-scrolling: touch; }

.sidebar-mobile-toggle:focus-visible,
.custom-menu-hamburger:focus-visible {
    outline: 2px solid #2c5aa0;
    outline-offset: 2px;
}