/* ==========================================================================
   Mobile fixes (phones, <= 767px). Loaded LAST on every page.
   1. Wider navbar that scales with the device and never overlaps itself
   2. Page content shares the navbar's edges (so cards line up with it)
   3. Machine pages + spare parts page: product cards two per row
   4. Home "image with content block" (#about): smaller, tidier card
   Desktop / tablet (>= 768px) is not affected.
   ========================================================================== */

@media (max-width: 767px) {

    :root {
        /* distance between the screen edge and the navbar / page content.
           ~5.5% of the screen width: 21px on a 390px phone, 16px on a 320px phone */
        --m-edge: clamp(14px, 5.5vw, 28px);
        --m-gap: clamp(8px, 2.8vw, 14px);
    }

    html,
    body {
        overflow-x: hidden;
    }

    html body #home.w3l-banner {
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
        grid-template-rows: 1fr auto !important;
    }

    html body #home + .trusted-brands,
    html body #home + .trusted-brands.reveal-section {
        margin-top: 0 !important;
        transform: none !important;
    }

    /* ---------- 1 + 2. Navbar and page content share the same edges ---------- */
    #site-header>.container,
    body .container,
    .machine-products-section .container,
    .products-page .w3l-grids-block-5 .container,
    .w3l-banner .container,
    .w3l-banner .banner-content>.container {
        width: 100% !important;
        max-width: none !important;
        padding-left: var(--m-edge) !important;
        padding-right: var(--m-edge) !important;
    }

    #site-header .navbar {
        flex-wrap: nowrap;
        gap: 6px;
        width: 100%;
        min-width: 0;
        padding-left: clamp(10px, 3.4vw, 16px) !important;
        padding-right: clamp(10px, 3.4vw, 16px) !important;
    }

    /* the collapsed menu must still drop below the bar, full width */
    #site-header .navbar-collapse {
        flex: 1 0 100%;
        order: 5;
        min-width: 0;
    }

    /* logo scales with the screen instead of a fixed 138px */
    #site-header .navbar-brand {
        flex: 0 1 auto !important;
        min-width: 0;
        margin-right: 0;
        margin-inline-end: auto;
    }

    #site-header .site-logo {
        width: clamp(104px, 37vw, 150px) !important;
        height: auto !important;
        max-height: none !important;
        aspect-ratio: 138 / 34;
        object-fit: contain !important;
    }

    /* language button + theme switch + burger: fixed size, never shrink, tight gaps */
    #site-header .mobile-nav-tools {
        flex: 0 0 auto;
        gap: clamp(4px, 1.8vw, 9px) !important;
        margin-left: 0 !important;
        min-width: 0;
    }

    #site-header .mobile-nav-tools .mobile-lang-toggle {
        min-width: 32px !important;
        min-height: 32px !important;
        padding: 0 clamp(7px, 2.4vw, 10px) !important;
        font-size: 14px !important;
    }

    #site-header .navbar-toggler {
        flex: 0 0 auto;
    }

    /* very small phones (<= 340px) */
    @media (max-width: 340px) {
        #site-header .site-logo {
            width: 96px !important;
        }

        #site-header .mobile-nav-tools .mobile-lang-toggle {
            min-width: 28px !important;
            min-height: 28px !important;
            padding: 0 6px !important;
            font-size: 13px !important;
        }
    }

    /* ---------- 3. Product cards: two per row, edges aligned with the navbar ---------- */
    .machine-products-section .machine-products-row,
    .machine-products-section #product-grid.row,
    .machine-products-section .row.machine-products-row,
    .products-page .products-results #product-grid,
    .products-page #product-grid.row,
    .products-results #product-grid {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: var(--m-gap) !important;
        margin: 0 !important;
        width: 100%;
        align-items: stretch;
    }

    /* grid items: no bootstrap column widths/gutters/margins */
    .machine-products-section .machine-products-row>[class*="col-"],
    .machine-products-section #product-grid>[class*="col-"],
    .products-results #product-grid>[class*="col-"],
    .products-results #product-grid>.product-item {
        flex: none !important;
        width: auto !important;
        max-width: none !important;
        min-width: 0;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* equal-height cards, compact content so two fit side by side */
    .machine-products-section .coursecard-single,
    .products-results .coursecard-single {
        height: 100%;
        margin: 0 !important;
        display: flex;
        flex-direction: column;
        border-radius: 14px;
        overflow: hidden;
    }

    .machine-products-section .coursecard-single .grids5-info,
    .products-results .coursecard-single .grids5-info {
        aspect-ratio: 1 / 1;
        height: auto !important;
        min-height: 0 !important;
        overflow: hidden;
    }

    .machine-products-section .coursecard-single .grids5-info img,
    .products-results .coursecard-single .grids5-info img {
        width: 100% !important;
        height: 100% !important;
        min-height: 0 !important;
        object-fit: cover;
    }

    .machine-products-section .content-main-top,
    .products-results .content-main-top {
        padding: 10px 10px 12px !important;
        flex: 1 1 auto;
        display: flex;
        flex-direction: column;
        min-width: 0;
    }

    .machine-products-section .content-top,
    .products-results .content-top {
        margin: 0 !important;
    }

    .machine-products-section .content-main-top h4,
    .products-results .content-main-top h4 {
        font-size: clamp(.82rem, 3.5vw, .95rem) !important;
        line-height: 1.3;
        margin: 6px 0 0 !important;
        overflow-wrap: anywhere;
    }

    .machine-products-section .content-main-top h4 a,
    .products-results .content-main-top h4 a {
        font-size: inherit !important;
    }

    .machine-products-section .top-content-border,
    .products-results .top-content-border {
        margin-top: auto !important;
        padding-top: 8px !important;
        gap: 6px;
        flex-wrap: wrap;
    }

    .machine-products-section .top-content-border h6,
    .products-results .top-content-border h6 {
        font-size: .78rem !important;
        margin: 0 !important;
        overflow-wrap: anywhere;
    }

    .machine-products-section .top-content-border li,
    .products-results .top-content-border li {
        font-size: .72rem !important;
        list-style: none;
        white-space: nowrap;
    }

    /* ---------- 4. Home: "image with content block" (#about) ---------- */
    #about.w3l-servicesblock {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
        margin-bottom: 0 !important;
    }

    #about .container {
        padding-bottom: 8px !important;
    }

    #about .about-card.about-card-photo {
        padding: 18px 16px 16px !important;
        border-radius: 18px !important;
        min-height: 0 !important;
    }

    #about .about-card.about-card-photo .company-glass-card {
        padding: 0 !important;
    }

    #about .about-card.about-card-photo .title-style {
        font-size: clamp(1.25rem, 6.2vw, 1.55rem) !important;
        line-height: 1.25 !important;
        margin-bottom: 10px !important;
    }

    #about .about-card.about-card-photo .about-rule {
        margin: 0 0 12px !important;
    }

    #about .about-card.about-card-photo .about-text {
        font-size: clamp(.84rem, 3.7vw, .94rem) !important;
        line-height: 1.6 !important;
        margin-bottom: 10px !important;
    }

    #about .about-card.about-card-photo .about-actions {
        max-width: none !important;
        width: 100%;
        margin: 6px 0 14px !important;
    }

    #about .about-card.about-card-photo .about-text {
        text-align: start !important;
        text-justify: none !important;
        letter-spacing: normal !important;
        word-spacing: normal !important;
    }

    #about .about-card.about-card-photo .about-actions .btn,
    html[dir="rtl"] #about .about-card.about-card-photo .about-actions .btn,
    html[lang="ar"] #about .about-card.about-card-photo .about-actions .btn {
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        min-height: 42px;
        height: 42px;
        padding: 0 16px !important;
        font-size: .92rem !important;
    }

    #about .about-card.about-card-photo ul.about-features {
        padding: 2px 12px !important;
        margin: 0 !important;
        border-radius: 14px !important;
    }

    #about .about-card.about-card-photo ul.about-features li {
        padding: 10px 0 !important;
        gap: 12px !important;
        align-items: center;
    }

    #about .about-card.about-card-photo .about-icon {
        flex: 0 0 38px;
        width: 38px !important;
        height: 38px !important;
        font-size: .9rem;
    }

    #about .about-card.about-card-photo .about-feature-text {
        font-size: clamp(.8rem, 3.5vw, .9rem) !important;
        line-height: 1.35 !important;
    }

    #about .about-card.about-card-photo .about-feature-line {
        margin-top: 5px !important;
    }
}
