/* ------------------
    Mobile Responsive & UX
------------------ */

/* Base Toggle: Hidden on Desktop */
.mobile-menu-toggle,
.mobile-filter-toggle,
.sidebar-header-mobile {
    display: none;
}

@media screen and (max-width: 900px) {

    html,
    body {
        overflow-x: hidden;
        width: 100%;
        position: relative;
    }

    /* --- Global Layout --- */
    main {
        padding: 0;
        overflow-x: hidden;
        width: 100%;
    }

    .section-title {
        padding: 0 1rem;
        font-size: 1.5rem;
        text-align: center;
        margin-bottom: 1.5rem;
    }

    /* --- Header Layout (Mobile Grid) --- */
    header {
        display: grid;
        grid-template-columns: 50px 1fr 1fr;
        /* Toggle | Logo | Icons */
        grid-template-areas:
            "toggle logo icons"
            "search search search";
        padding: 0.8rem 0.5rem;
        align-items: center;
        background: var(--white);
        position: sticky;
        top: 0;
        z-index: 1100;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
        gap: 10px 0;
        width: 100%;
        box-sizing: border-box;
    }

    /* 1. Toggle Button (Left) */
    .mobile-menu-toggle {
        grid-area: toggle;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        width: 44px;
        height: 44px;
        background: transparent;
        border: none;
        cursor: pointer;
        padding: 0;
        margin-left: 5px;
        z-index: 1101;
        position: relative;
    }

    .mobile-menu-toggle span {
        display: block;
        width: 24px;
        height: 2px;
        background-color: var(--primary-color);
        border-radius: 2px;
        transition: all 0.3s ease-in-out;
        position: absolute;
    }

    .mobile-menu-toggle span:nth-child(1) {
        transform: translateY(-8px);
    }

    .mobile-menu-toggle span:nth-child(2) {
        opacity: 1;
    }

    .mobile-menu-toggle span:nth-child(3) {
        transform: translateY(8px);
    }

    .mobile-menu-toggle.active span:nth-child(1) {
        transform: translateY(0) rotate(45deg);
    }

    .mobile-menu-toggle.active span:nth-child(2) {
        opacity: 0;
    }

    .mobile-menu-toggle.active span:nth-child(3) {
        transform: translateY(0) rotate(-45deg);
    }

    /* 2. Logo (Center) */
    header img {
        grid-area: logo;
        height: 40px;
        width: auto;
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        margin: 0;
    }

    /* 3. Icons (Right) */
    .header-links {
        grid-area: icons;
        justify-self: end;
        display: flex;
        gap: 0.8rem;
        margin-right: 5px;
        align-items: center;
    }

    .header-links .link-text {
        display: none;
    }

    .header-links a .material-icons-outlined {
        font-size: 1.6rem;
        color: var(--primary-color)
    }

    /* 4. Search Bar (row 2) */
    .search-bar {
        grid-area: search;
        width: 100%;
        display: flex;
        margin: 0;
    }

    .search-bar input {
        width: 100%;
        padding: 0.7rem 1rem;
        font-size: 0.95rem;
        border-radius: 50px 0 0 50px;
        border: 1px solid #dfe6e9;
        border-right: none;
        background: #f1f2f6;
    }

    .search-bar button {
        border-radius: 0 50px 50px 0;
        padding: 0 1.2rem;
        background-color: var(--accent-color);
        color: white;
        border: none;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .search-bar button .search-text {
        display: none;
    }

    .search-bar button .search-icon {
        display: block !important;
        font-size: 1.2rem;
    }


    /* --- Mobile Filter Sidebar --- */
    main.page-catalog {
        padding: 1rem 15px !important;
        margin: 0 !important;
    }

    .catalog-layout {
        display: block !important;
        position: relative;
    }

    .mobile-filter-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        width: 100%;
        padding: 12px;
        background-color: var(--white);
        border: 1px solid #dfe6e9;
        border-radius: 8px;
        margin: 10px 0 20px 0;
        font-weight: 600;
        color: var(--primary-color);
        cursor: pointer;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        transition: all 0.2s ease;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        font-size: 0.9rem;
    }

    .mobile-filter-toggle:active {
        background-color: #f1f2f6;
        transform: translateY(1px);
    }

    .catalog-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        bottom: 0;
        width: 85%;
        max-width: 320px;
        background: white;
        z-index: 2000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 0;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.15);
        overflow-y: auto;
        height: 100vh;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
    }

    .catalog-sidebar.open {
        transform: translateX(0);
    }

    .sidebar-header-mobile {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 20px;
        border-bottom: 1px solid #eee;
        background: #f9f9f9;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .sidebar-header-mobile h3 {
        margin: 0;
        font-size: 1.1rem;
        font-weight: 700;
        text-transform: uppercase;
        color: var(--primary-color);
    }

    .close-sidebar {
        background: white;
        border: 1px solid #eee;
        cursor: pointer;
        padding: 5px;
        color: #333;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        width: 32px;
        height: 32px;
        transition: all 0.2s;
    }

    .close-sidebar:hover {
        background-color: #e74c3c;
        color: white;
        border-color: #e74c3c;
    }

    /* Backdrop */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1999;
        opacity: 0;
        transition: opacity 0.3s ease;
        pointer-events: none;
        backdrop-filter: blur(2px);
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* Lock body scroll */
    body.sidebar-open {
        overflow: hidden;
    }

    /* Widget spacing in sidebar */
    .catalog-sidebar .sidebar-widget {
        border-left: none;
        border-right: none;
        border-radius: 0;
        margin-bottom: 10px;
        border-top: none;
    }

    /* --- Side Navigation (Drawer) --- */
    nav.main-nav {
        display: block;
        position: fixed;
        top: 0;
        left: -100%;
        width: 75%;
        max-width: 300px;
        height: 100vh;
        background-color: var(--primary-color);
        padding-top: 130px;
        /* Space for header */
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        box-shadow: 4px 0 15px rgba(0, 0, 0, 0.1);
        display: flex;
        flex-direction: column;
    }

    nav.main-nav.open {
        left: 0;
    }

    nav.main-nav ul {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        width: 100%;
    }

    nav.main-nav li {
        width: 100%;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }

    nav.main-nav a {
        display: block;
        padding: 1.2rem 2rem;
        font-size: 1.1rem;
        color: rgba(255, 255, 255, 0.9);
        width: 100%;
        text-align: left;
    }

    nav.main-nav a:hover {
        background: rgba(255, 255, 255, 0.05);
        color: var(--white);
    }

    /* Backdrop */
    body.menu-open::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
        backdrop-filter: blur(2px);
    }

    /* --- Content Adjustments --- */

    /* Carousel */
    .carousel {
        margin: 0 0 2rem 0;
        border-radius: 0;
        box-shadow: none;
        width: 100%;
    }

    .carousel-item {
        height: 220px;
    }

    /* Scrolling Products (Home) */
    .products-grid {
        display: flex;
        overflow-x: auto;
        padding: 10px 1rem 2rem;
        margin: 0;
        gap: 1rem;
        width: 100%;
        box-sizing: border-box;
    }

    .products-grid::-webkit-scrollbar {
        display: none;
    }

    .product-card {
        min-width: 200px;
        /* Smaller for mobile */
    }

    /* Grid Products (Catalogue) */
    .catalogue-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding: 0 0 2rem;
        overflow: visible;
    }

    @media screen and (max-width: 360px) {
        .catalogue-grid {
            grid-template-columns: 1fr;
        }
    }

    .catalogue-grid .product-card {
        width: 100%;
        min-width: 0;
        margin: 0;
        border-radius: 8px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
    }

    .catalogue-grid .product-image {
        height: 140px;
        padding: 10px;
    }

    .catalogue-grid .product-info {
        padding: 0.8rem;
    }

    .catalogue-grid .product-content {
        padding: 10px;
    }

    .catalogue-grid .product-title {
        font-size: 0.85rem;
        margin-bottom: 4px;
        height: 2.6em;
        /* Limit height */
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .catalogue-grid .meta-label,
    .catalogue-grid .meta-value {
        font-size: 0.75rem;
    }

    .catalogue-grid .product-price-box {
        margin-top: 10px;
        margin-bottom: 5px;
    }

    .catalogue-grid .price-val {
        font-size: 1.1rem;
    }

    .catalogue-grid .btn-block-cart {
        padding: 8px;
        font-size: 0.8rem;
    }

    /* Cart */
    .cart-popup {
        top: 70px;
        right: 2%;
        left: 2%;
        width: 96%;
    }
}

/* --- Cart & Quote Detail Responsive --- */
.cart-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.cart-items-container {
    padding: 1rem;
    overflow-x: auto;
}

.cart-table th,
.cart-table td {
    white-space: nowrap;
    padding: 0.8rem 0.5rem;
}

.cart-summary-sticky {
    position: static;
    width: 100%;
    margin-top: 1rem;
}

.quote-history-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

.quote-history-item>div:last-child {
    align-self: flex-end;
    width: 100%;
}

.quote-history-item .btn-primary {
    text-align: center;
    display: block;
}

/* --- Invoice / Quote View Responsive --- */
/* --- Invoice / Quote View Responsive --- */
/* Only minor adjustments for small screens, keeping table structure */
.invoice-box {
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
}

/* Allow horizontal scroll if table is too wide, instead of breaking layout */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Optional: Compact padding on mobile */
@media screen and (max-width: 600px) {
    .invoice-box {
        padding: 10px;
    }

    .header-top {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 20px;
    }

    .invoice-details {
        text-align: center;
    }

    th,
    td {
        padding: 8px 5px !important;
        font-size: 0.8rem !important;
    }
}

/* Add standard property for line-clamp */
.catalogue-grid .product-title {
    line-clamp: 2;
}