/* ============================================================================
   XMART — MOBILE & TABLET RESPONSIVE REDESIGN (UI-ONLY)
   ----------------------------------------------------------------------------
   RULES OF THIS FILE (STRICT):
   1. Every rule lives inside a media query of (max-width: 1023px).
      Desktop (>= 1024px) is NEVER touched — zero desktop rules exist here.
   2. No markup, routes, data, or backend behaviour is changed.
      Only visual treatment (colors, spacing, radius, positioning) of
      EXISTING elements is restyled at mobile/tablet widths.
   3. Marker classes added to Blade templates:
        .xm-smartbar  -> the existing black category/search bar in the header
        .xm-fab       -> the existing live-chat floating button
        #xm-app-nav   -> NEW bottom app navigation (mobile/tablet only)
   ============================================================================ */


/* ============================================================================
   SHARED LAYER — MOBILE (<= 767px) AND TABLET (768-1023px)
   ============================================================================ */
@media (max-width: 1023px) {

    /* --- App-style bottom navigation (Home | Categories | Cart | Orders | Account) --- */
    :root {
        --xm-nav-h: 68px;
        --xm-brand: #0e9a8b;          /* Xmart teal — matches brand-600 */
        --xm-brand-deep: #0f4a4a;
        --xm-ink: #0f172a;
    }

    /* Reserve space so the fixed nav NEVER covers page content (incl. footer) */
    html body {
        padding-bottom: calc(var(--xm-nav-h) + env(safe-area-inset-bottom, 0px)) !important;
    }

    #xm-app-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        /* sits BELOW the sticky website header, but above normal page flow;
           url overlays (mini-cart drawer z-10000, chat z-9999) still cover it */
        z-index: 9400;
        height: calc(var(--xm-nav-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        background: rgba(255, 255, 255, 0.97);
        -webkit-backdrop-filter: blur(14px);
        backdrop-filter: blur(14px);
        border-top: 2px solid rgba(14, 154, 139, 0.55);
        border-radius: 0;
        box-shadow: 0 -4px 20px rgba(14, 154, 139, 0.15), 0 -1px 6px rgba(14, 154, 139, 0.10);
    }

    #xm-app-nav a {
        position: relative;
        flex: 1 1 0;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        padding-top: 9px;
        gap: 3px;
        overflow: visible;
        text-decoration: none;
        color: #64748b;
        font-family: 'Plus Jakarta Sans', sans-serif;
        font-size: 10px;
        font-weight: 700;
        line-height: 1.1;
        white-space: nowrap;
        letter-spacing: 0.01em;
        -webkit-tap-highlight-color: transparent;
        transition: color .18s ease;
    }

    #xm-app-nav a .xm-ico {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 30px;
        border-radius: 999px;
        background: transparent;
        flex-shrink: 0;
        transition: background .18s ease, color .18s ease, transform .18s ease;
    }

    #xm-app-nav a .xm-ico .fa-solid,
    #xm-app-nav a .xm-ico .fa-regular {
        font-size: 17px;
        line-height: 1;
    }

    #xm-app-nav a.active {
        color: var(--xm-brand-deep);
    }

    #xm-app-nav a.active .xm-ico {
        background: rgba(14, 154, 139, 0.12);
        color: var(--xm-brand);
    }

    #xm-app-nav a:active .xm-ico {
        transform: scale(0.92);
    }

    /* Cart badge — reuses the live .js-cart-count updater already on the site */
    #xm-app-nav .xm-badge {
        position: absolute;
        top: -2px;
        right: 12px;
        background: #ef4444;
        color: #fff;
        font-size: 9.5px;
        font-weight: 800;
        min-width: 16px;
        height: 16px;
        padding: 0 3px;
        border-radius: 999px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 0 0 2px #fff;
    }

    /* --- Elements hidden on request for mobile + tablet --- */

    /* 1) Login pill: redundant — the bottom-nav "Account" item sends guests
          to the same /login page. Hidden only below 1024px. */
    .glass-header a[href="/login"] {
        display: none !important;
    }

    /* 2) All-Categories pill + its mega drawer: category browsing is fully
          covered by the bottom-nav "Categories" item -> /categories page.
          (Desktop nav links live in the same container but are lg-only,
          i.e. already hidden below 1024px, so nothing is lost.) */
    .xm-smartbar > div:first-child > div:first-child {
        display: none !important;
    }

    /* 3) Mini-cart edge tab (green "0 items" tab): overlaps content; the
          bottom-nav Cart icon with its live badge is the cart entry point. */
    #mini-cart-tab {
        display: none !important;
    }

    /* --- Toast floats above the bottom nav --- */
    #toast {
        bottom: calc(var(--xm-nav-h) + env(safe-area-inset-bottom, 0px) + 18px) !important;
        z-index: 11000 !important;
        max-width: min(92vw, 420px);
    }

    /* --- Keep existing header overlays ABOVE the bottom nav --- */
    /* (mobile hamburger drawer + category mega-drawer; pure stacking order only) */
    .glass-header .fixed.inset-0,
    .xm-smartbar .absolute.top-full {
        z-index: 9900 !important;
    }

    /* --- Live-chat FAB above the bottom nav so both stay reachable --- */
    .xm-fab {
        bottom: calc(var(--xm-nav-h) + env(safe-area-inset-bottom, 0px) + 14px) !important;
        right: 12px !important;
    }

    /* --- Full-width, safe images / no sideways overflow anywhere --- */
    img, video, iframe {
        max-width: 100%;
    }

    body, main, footer {
        overflow-x: clip;
    }

    /* --- Sticky header stays on TOP of the bottom nav and page content --- */
    .glass-header {
        background-color: rgba(255, 255, 255, 0.97) !important;
        z-index: 9500 !important;
    }

    /* --- Top-right action cluster: compact, equal-height, app-bar chips --- */
    .glass-header .flex.items-center.gap-4.lg\:gap-6 {
        gap: 7px !important;
        align-items: center !important;
    }

    /* Cart chip: tidy green icon chip, no oversized pill */
    .glass-header a[href="/cart"] {
        height: 36px !important;
        padding: 0 10px !important;
        border-radius: 12px !important;
        gap: 0 !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .glass-header a[href="/cart"] > div > .fa-bag-shopping {
        font-size: 17px;
    }

    /* Wishlist: circular ghost chip, same height as siblings */
    .glass-header a[href="/wishlist"] {
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
        border-radius: 999px !important;
        background: #f8fafc;
    }

    .glass-header a[href="/wishlist"] > .fa-heart {
        font-size: 16px;
    }

    /* Login chip: compact pill, vertically centered with the others */
    .glass-header a[href="/login"] {
        height: 34px !important;
        padding: 0 13px !important;
        border-radius: 999px !important;
        font-size: 11.5px !important;
        gap: 5px !important;
        align-items: center !important;
    }

    /* Avatar button in the account cluster: no inconsistent chevon spacing */
    .glass-header .relative > button.flex.items-center.gap-2 {
        height: 38px !important;
        padding: 0 !important;
        gap: 5px !important;
    }


    /* --- Footer: breathing room above bottom nav gradient edge --- */
    footer {
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)) !important;
    }
}


/* ============================================================================
   MOBILE ONLY (<= 767px) — APP-LIKE HEADER + LAYOUT POLISH
   ============================================================================ */
@media (max-width: 767px) {

    /* ---- Bottom nav floats as a DOCK on phones too (like the tablet/iPad
       reference) — gains clearance above WebView gesture strips and the
       system navigation band inside APK/WebView apps ---- */
    :root {
        --xm-nav-h: 62px;
    }

    #xm-app-nav {
        left: 50%;
        transform: translateX(-50%);
        width: min(460px, calc(100% - 20px));
        border-radius: 999px;
        border: 1px solid rgba(14, 154, 139, 0.25);
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        padding-bottom: 0;
        height: var(--xm-nav-h);
        display: flex;
        align-items: stretch;
        justify-content: space-between;
        padding: 0 8px;
        box-shadow: 0 8px 28px rgba(14, 154, 139, 0.12), 0 2px 8px rgba(14, 154, 139, 0.08);
    }

    #xm-app-nav a {
        font-size: 10px;
    }

    /* Content clearance below the floating dock */
    html body {
        padding-bottom: calc(var(--xm-nav-h) + 30px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .xm-fab {
        bottom: calc(var(--xm-nav-h) + 40px + env(safe-area-inset-bottom, 0px)) !important;
        right: 14px !important;
    }

    #toast {
        bottom: calc(var(--xm-nav-h) + 48px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* ---- Convert the black category/search strip into a white app search bar ---- */
    /* Structure kept 100% intact: same buttons, same drawer, same search form. */
    .xm-smartbar {
        background: #ffffff !important;
        border-top: 1px solid #f1f5f9 !important;
        box-shadow: none !important;
    }

    .xm-smartbar > div:first-child {
        flex-wrap: wrap;
        row-gap: 7px;
        padding-top: 8px;
        padding-bottom: 9px;
    }

    /* Row 1: All-Categories pill (its own row) */
    .xm-smartbar > div:first-child > div:first-child {
        order: 0;
    }

    .xm-smartbar > div:first-child > div:first-child > div > button {
        border-radius: 999px !important;
        padding: 8px 14px !important;
        gap: 6px !important;
        font-size: 12.5px !important;
        box-shadow: 0 1px 4px rgba(14, 154, 139, 0.18);
    }

    .xm-smartbar > div:first-child > div:first-child > div > button > .fa-solid {
        font-size: 12px;
    }

    /* Row 2: search pill stretches full width */
    .xm-smartbar > div:first-child > div:last-child {
        width: 100% !important;
        max-width: none !important;
    }

    .xm-smartbar > div:first-child > div:last-child form {
        max-width: none !important;
        margin-left: 0 !important;
    }

    .xm-smartbar input[name="q"] {
        background: #f1f5f9 !important;
        border-color: #e8eef4 !important;
        color: var(--xm-ink) !important;
        border-radius: 999px !important;
        padding-top: 9px !important;
        padding-bottom: 9px !important;
        font-size: 13px !important;
    }

    .xm-smartbar input[name="q"]::placeholder {
        color: #94a3b8 !important;
        opacity: 1;
    }

    .xm-smartbar input[name="q"]:focus {
        background: #ffffff !important;
        border-color: var(--xm-brand) !important;
        box-shadow: 0 0 0 3px rgba(14, 154, 139, 0.15) !important;
    }

    .xm-smartbar input[name="q"] + button[type="submit"] {
        border-radius: 999px !important;
        right: 5px !important;
    }

    /* ---- Top main header row: app-bar proportions ---- */
    .glass-header > div:first-child {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .glass-header .flex.items-center.gap-4.md\:gap-8 {
        gap: 10px !important;
    }

    /* Compact logo mark like a native app bar */
    .glass-header a[href="/"] > img,
    .glass-header .mr-auto img {
        height: 46px !important;
        width: auto !important;
        max-width: 200px !important;
        object-fit: contain !important;
    }

    .glass-header .w-10.h-10.rounded-xl {
        width: 36px !important;
        height: 36px !important;
        border-radius: 12px !important;
    }

    .glass-header .font-display.font-extrabold {
        font-size: 19px !important;
    }

    /* Right-side actions: touch-friendly pills */
    .glass-header .flex.items-center.gap-4.lg\:gap-6 {
        gap: 8px !important;
    }

    .glass-header .flex.items-center.gap-4.lg\:gap-6 a,
    .glass-header .flex.items-center.gap-4.lg\:gap-6 button {
        -webkit-tap-highlight-color: transparent;
    }

    /* ---- Category mega-drawer: full-screen-friendly side sheet ---- */
    .xm-smartbar .absolute.top-full {
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
    }

    .xm-smartbar .flex.items-stretch.bg-white {
        box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18) !important;
        border-radius: 20px !important;
    }

    .xm-smartbar .w-72 {
        width: min(88vw, 320px) !important;
    }

    /* ---- Content density: native-feeling paddings ---- */
    main .container {
        padding-left: 14px !important;
        padding-right: 14px !important;
        max-width: 100% !important;
    }

    /* ---- Product cards: slightly larger imagery, easier taps ---- */
    main .grid {
        gap: 12px;
    }

    /* Product-card add-to-cart buttons: larger tap targets on tablets/phones */
    main button.bg-brand-50.border-brand-200 {
        padding-top: 9px;
        padding-bottom: 9px;
    }

    /* ---- Buttons across the app get a native minimum tap height ---- */
    main a.text-center.bg-brand-600,
    main button.w-full.bg-brand-600 {
        box-shadow: 0 6px 18px rgba(14, 154, 139, 0.22);
    }

    /* ---- Announcement-retired spacing + general section rhythm ---- */
    main section + section,
    main div + section {
        margin-top: 4px;
    }

    /* ---- Flash-sale & banner strips: consistent edge radius ---- */
    main .rounded-2xl.border-slate-100 {
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    }
}


/* ============================================================================
   TABLET ONLY (768-1023px) — TABLET-OPTIMIZED MULTI-COLUMN LAYOUT
   (Not a stretched phone: wider gutters, stronger cards, dual-panel feel)
   ============================================================================ */
@media (min-width: 768px) and (max-width: 1023px) {

    /* ---- Header: comfortable two-row app bar ---- */
    .glass-header > div:first-child {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .glass-header .mr-auto img {
        height: 56px !important;
        width: auto !important;
        max-width: 250px !important;
        object-fit: contain !important;
    }

    /* ---- White category/search strip with roomier pills ---- */
    .xm-smartbar {
        background: #ffffff !important;
        border-top: 1px solid #f1f5f9 !important;
        box-shadow: none !important;
    }

    .xm-smartbar > div:first-child {
        gap: 16px;
        padding-top: 8px;
        padding-bottom: 10px;
    }

    .xm-smartbar > div:first-child > div:first-child > div > button {
        border-radius: 999px !important;
        padding: 10px 18px !important;
        box-shadow: 0 1px 6px rgba(14, 154, 139, 0.22);
    }

    .xm-smartbar input[name="q"] {
        background: #f1f5f9 !important;
        border-color: #e8eef4 !important;
        color: var(--xm-ink) !important;
        border-radius: 999px !important;
        padding-top: 10px !important;
        padding-bottom: 10px !important;
        font-size: 14px !important;
    }

    .xm-smartbar input[name="q"]::placeholder {
        color: #94a3b8 !important;
        opacity: 1;
    }

    /* Category drawer behaves like a floating dual-panel sheet on tablet */
    .xm-smartbar .flex.items-stretch.bg-white {
        box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16) !important;
        border-radius: 22px !important;
    }

    /* ---- Page gutters scale up for tablet reading comfort ---- */
    main .container {
        padding-left: 26px !important;
        padding-right: 26px !important;
    }

    main .grid {
        gap: 18px;
    }

    /* Slightly larger product cards on tablet for grid comfort */
    main .text-xs.sm\:text-sm.font-bold {
        font-size: 14px !important;
    }

    /* ---- Bottom nav on tablet: floats as a centered pill dock, reference-like ---- */
    :root {
        --xm-nav-h: 76px;
    }

    #xm-app-nav {
        left: 50%;
        transform: translateX(-50%);
        width: min(560px, calc(100% - 40px));
        border-radius: 999px;
        border: 1px solid rgba(14, 154, 139, 0.25);
        bottom: 14px;
        padding-bottom: 0;
        /* BUGFIX: dock was 50px (nav-h - 26) which clipped the 53px-tall
           items — icon pill, label and highlight chip got squeezed. */
        height: calc(var(--xm-nav-h) - 8px);
        align-items: stretch;
        justify-content: space-between;
        padding: 0 10px;
        box-shadow: 0 8px 28px rgba(14, 154, 139, 0.12), 0 2px 8px rgba(14, 154, 139, 0.08);
    }

    #xm-app-nav a {
        font-size: 11px;
        padding-top: 8px;
        gap: 4px;
    }

    #xm-app-nav a .xm-ico {
        width: 46px;
        height: 32px;
    }

    #xm-app-nav a .xm-ico .fa-solid,
    #xm-app-nav a .xm-ico .fa-regular {
        font-size: 18px;
    }

    html body {
        padding-bottom: calc(var(--xm-nav-h) + 24px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .xm-fab {
        bottom: calc(var(--xm-nav-h) + 24px + env(safe-area-inset-bottom, 0px)) !important;
        right: 20px !important;
    }

    #toast {
        bottom: calc(var(--xm-nav-h) + 24px + env(safe-area-inset-bottom, 0px) + 14px) !important;
    }
}


/* ============================================================================
   SMALL-PHONE GUARDS (<= 379px) — 320/360 width safety
   ============================================================================ */
@media (max-width: 379px) {
    :root {
        --xm-nav-h: 56px;
    }

    #xm-app-nav {
        width: calc(100% - 14px);
        height: var(--xm-nav-h);
        bottom: calc(9px + env(safe-area-inset-bottom, 0px));
        padding: 0 5px;
    }

    #xm-app-nav a {
        font-size: 9px;
    }

    #xm-app-nav a .xm-ico {
        width: 36px;
        height: 28px;
    }

    #xm-app-nav a .xm-ico .fa-solid,
    #xm-app-nav a .xm-ico .fa-regular {
        font-size: 15px;
    }

    html body {
        padding-bottom: calc(56px + 26px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .xm-fab {
        bottom: calc(56px + 34px + env(safe-area-inset-bottom, 0px)) !important;
    }

    #toast {
        bottom: calc(56px + 40px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .xm-smartbar input[name="q"] {
        font-size: 12.5px !important;
    }

    footer {
        padding-bottom: 1.25rem !important;
    }
}


/* ============================================================================
   SAFETY NET (any <= 1023px) — kill residual horizontal scroll sources
   ============================================================================ */
@media (max-width: 1023px) {
    html, body {
        max-width: 100vw;
        overflow-x: hidden;
    }
}
