/* Phone only (< 768px): app-style bottom tab bar.
 * The desktop row is hidden; #navbar becomes a transparent dock holding a floating glass tab bar
 * (Home · Market · Sales · Cart · More). "More" opens the menu as a sheet above the bar.
 * Loaded last in components/header.php so it wins over the base navbar rules. */
.app-tabbar {
    display: none;
}

@media (max-width: 767px) {
    :root {
        --tb-h: 64px;
        --tb-gap: 10px;
        --tb-safe: env(safe-area-inset-bottom, 0px);
        /* Total screen height the dock occupies */
        --tb-total: calc(var(--tb-h) + var(--tb-gap) + var(--tb-safe));
    }

    body {
        padding-bottom: calc(var(--tb-total) + 8px);
    }

    /* ── Dock container ── */
    #navbar {
        top: auto !important;
        bottom: 0 !important;
        display: flex;
        flex-direction: column;
        padding: 0 12px calc(var(--tb-gap) + var(--tb-safe)) !important;
        pointer-events: none;
    }

    html body.home-bw-theme #navbar,
    html body.home-bw-theme #navbar.scrolled,
    html[data-theme="light"] body.home-bw-theme #navbar,
    html[data-theme="light"] body.home-bw-theme #navbar.scrolled {
        background: transparent !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        border: 0 !important;
        box-shadow: none !important;
    }

    /* Desktop row (logo, links, theme) is replaced by the tab bar */
    #navbar > .mx-auto {
        display: none !important;
    }

    /* ── Tab bar ── */
    body.home-bw-theme #navbar .app-tabbar {
        pointer-events: auto;
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
        align-items: center;
        height: var(--tb-h);
        padding: 0 6px;
        border-radius: 24px;
        background: rgba(0, 0, 0, 0.9);
        backdrop-filter: blur(24px) saturate(1.5);
        -webkit-backdrop-filter: blur(24px) saturate(1.5);
        border: 1px solid rgba(255, 255, 255, 0.09);
        box-shadow:
            0 12px 40px rgba(0, 0, 0, 0.55),
            inset 0 1px 0 rgba(255, 255, 255, 0.06);
    }

    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 4px;
        width: auto;
        height: 100%;
        min-width: 0;
        padding: 0;
        border: 0;
        border-radius: 18px;
        background: transparent !important;
        box-shadow: none !important;
        color: rgba(255, 255, 255, 0.5);
        text-decoration: none;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.2s ease, transform 0.15s ease;
    }

    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item:active {
        transform: scale(0.92);
    }

    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item.is-active,
    body.home-bw-theme #navbar .app-tabbar .mobile-menu-btn.is-open {
        color: #fff;
    }

    /* Icon sits in a pill that lights up for the current tab */
    .app-tabbar__icon {
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 52px;
        height: 30px;
        border-radius: 999px;
        transition: background-color 0.25s ease;
    }

    .app-tabbar__icon svg {
        width: 22px;
        height: 22px;
    }

    .app-tabbar__item.is-active .app-tabbar__icon,
    .mobile-menu-btn.is-open .app-tabbar__icon {
        background: rgba(255, 255, 255, 0.13);
    }

    /* Center tab (Sales): raised round button that breaks out of the bar */
    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item--center {
        justify-content: flex-end;
        padding-bottom: 9.5px; /* label baseline matches the other tabs */
    }

    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item--center .app-tabbar__icon {
        position: absolute;
        top: -22px;
        left: 50%;
        width: 56px;
        height: 56px;
        margin-left: -28px;
        border-radius: 50%;
        background: #fff;
        color: #0a0a0a;
        box-shadow:
            0 0 0 5px rgba(16, 16, 19, 0.92),
            0 10px 26px rgba(0, 0, 0, 0.55);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item--center .app-tabbar__icon svg {
        width: 24px;
        height: 24px;
        stroke-width: 2.2;
    }

    body.home-bw-theme #navbar .app-tabbar .app-tabbar__item--center.is-active .app-tabbar__icon {
        box-shadow:
            0 0 0 5px rgba(16, 16, 19, 0.92),
            0 0 0 7px rgba(255, 255, 255, 0.22),
            0 10px 26px rgba(0, 0, 0, 0.55);
    }

    html[data-theme="light"] body.home-bw-theme #navbar .app-tabbar .app-tabbar__item--center .app-tabbar__icon {
        background: var(--mono-ink-bg, var(--theme-ink));
        color: #fff;
        box-shadow:
            0 0 0 5px var(--theme-paper),
            0 10px 24px rgba(0, 0, 0, 0.28);
    }

    html[data-theme="light"] body.home-bw-theme #navbar .app-tabbar .app-tabbar__item--center.is-active .app-tabbar__icon {
        box-shadow:
            0 0 0 5px var(--theme-paper),
            0 0 0 7px color-mix(in oklch, var(--theme-ink) 22%, transparent),
            0 10px 24px rgba(0, 0, 0, 0.28);
    }

    .app-tabbar__label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-family: 'DM Sans', system-ui, sans-serif;
        font-size: 10.5px;
        font-weight: 600;
        line-height: 1;
        letter-spacing: 0.01em;
    }

    .site-rtl .app-tabbar__label {
        font-family: 'Noto Sans Arabic', 'DM Sans', system-ui, sans-serif;
        font-size: 11px;
    }

    .app-tabbar__badge {
        position: absolute;
        top: -3px;
        inset-inline-end: 6px;
        min-width: 17px;
        height: 17px;
        padding: 0 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
        background: #fff;
        color: #000;
        font: 700 10px/1 'DM Sans', system-ui, sans-serif;
        box-shadow: 0 0 0 2px rgba(16, 16, 19, 0.9);
    }

    /* "More" button keeps its 3-bar → X morph, tinted like the other tabs */
    body.home-bw-theme #navbar .app-tabbar .mobile-menu-btn__bar {
        background: currentColor !important;
    }

    /* ── Light theme: monochrome ink, mirrors the dark bar ── */
    html[data-theme="light"] body.home-bw-theme #navbar .app-tabbar {
        background: color-mix(in oklch, var(--theme-surface) 88%, transparent);
        border-color: var(--theme-line);
        box-shadow:
            0 12px 36px rgba(0, 0, 0, 0.14),
            inset 0 1px 0 rgba(255, 255, 255, 0.7);
    }

    html[data-theme="light"] body.home-bw-theme #navbar .app-tabbar .app-tabbar__item {
        color: color-mix(in oklch, var(--theme-ink) 52%, transparent) !important;
        background: transparent !important;
        border: 0 !important;
        box-shadow: none !important;
    }

    html[data-theme="light"] body.home-bw-theme #navbar .app-tabbar .app-tabbar__item.is-active,
    html[data-theme="light"] body.home-bw-theme #navbar .app-tabbar .mobile-menu-btn.is-open {
        color: var(--theme-ink) !important;
    }

    html[data-theme="light"] .app-tabbar__item.is-active .app-tabbar__icon,
    html[data-theme="light"] .mobile-menu-btn.is-open .app-tabbar__icon {
        background: color-mix(in oklch, var(--theme-ink) 8%, transparent);
    }

    html[data-theme="light"] .app-tabbar__badge {
        background: var(--theme-ink);
        color: #fff;
        box-shadow: 0 0 0 2px var(--theme-paper);
    }

    /* ── "More" sheet: rises above the tab bar ── */
    #navbar .mobile-menu {
        pointer-events: auto;
    }

    #navbar .mobile-menu__panel {
        margin: 0 0 32px; /* clears the raised center button */
        border-radius: 24px;
        max-height: calc(100vh - var(--tb-total) - 24px);
        overflow-y: auto;
        overscroll-behavior: contain;
        transform: translateY(14px) scale(0.98);
        transform-origin: bottom center;
    }

    @supports (height: 100svh) {
        #navbar .mobile-menu__panel {
            max-height: calc(100svh - var(--tb-total) - 24px);
        }
    }

    #navbar .mobile-menu.is-open .mobile-menu__panel {
        transform: none;
    }

    body.home-bw-theme #navbar .mobile-menu__panel {
        background: rgba(16, 16, 19, 0.97);
    }

    /* ── Sheet rows (.mm-row: section links, theme, language) read like the tab bar; the current page gets the lit plate ── */
    body.home-bw-theme #mobile-menu .mm-row {
        color: rgba(255, 255, 255, 0.84);
    }

    body.home-bw-theme #mobile-menu .mm-row:hover,
    body.home-bw-theme #mobile-menu .mm-row:active,
    body.home-bw-theme #mobile-menu .mm-lang[open] > .mm-row {
        color: #fff;
        background: rgba(255, 255, 255, 0.04);
    }

    body.home-bw-theme #mobile-menu .mm-row.is-current {
        color: #fff;
        background: rgba(255, 255, 255, 0.07);
    }

    body.home-bw-theme #mobile-menu .mm-row .nav-icon-plate {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.16);
    }

    body.home-bw-theme #mobile-menu .mm-row.is-current .nav-icon-plate {
        background: #fff;
        border-color: #fff;
        color: #000;
    }

    html[data-theme="light"] body.home-bw-theme #mobile-menu .mm-row {
        color: var(--theme-ink);
    }

    html[data-theme="light"] body.home-bw-theme #mobile-menu .mm-row.is-current,
    html[data-theme="light"] body.home-bw-theme #mobile-menu .mm-lang[open] > .mm-row {
        background: rgba(0, 0, 0, 0.05);
    }

    html[data-theme="light"] body.home-bw-theme #mobile-menu .mm-row.is-current .nav-icon-plate {
        background: var(--theme-ink);
        border-color: var(--theme-ink);
    }

    html[data-theme="light"] body.home-bw-theme #mobile-menu .mm-row.is-current .nav-icon-plate svg {
        color: #fff;
    }

    /* ── Language row (components/lang_picker.php, mobile): current language on the right, list opens in place ── */
    .mm-lang__sum {
        list-style: none;
        cursor: pointer;
    }

    .mm-lang__sum::-webkit-details-marker {
        display: none;
    }

    .mm-lang__now {
        display: inline-flex;
        align-items: center;
        gap: 7px;
        max-width: 48%;
        font-size: 12.5px;
        font-weight: 600;
        opacity: 0.85;
    }

    .mm-lang__now-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mm-lang__chev {
        font-size: 9px;
        opacity: 0.6;
        transition: transform 0.2s ease;
    }

    .mm-lang[open] .mm-lang__chev {
        transform: rotate(180deg);
    }

    .mm-lang__list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 2px;
        margin: 4px 4px 6px;
        padding: 6px;
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid rgba(255, 255, 255, 0.06);
    }

    .mm-lang__opt {
        display: flex;
        align-items: center;
        gap: 9px;
        min-height: 42px;
        padding: 0 10px;
        border-radius: 10px;
        font-size: 13px;
        font-weight: 500;
        color: rgba(255, 255, 255, 0.68);
        transition: color 0.2s ease, background 0.2s ease;
    }

    .mm-lang__opt:active,
    .mm-lang__opt.is-active {
        color: #fff;
        background: rgba(255, 255, 255, 0.08);
    }

    .mm-lang__name {
        flex: 1;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mm-lang__tick {
        font-size: 10px;
    }

    html[data-theme="light"] .mm-lang__opt:active,
    html[data-theme="light"] .mm-lang__opt.is-active {
        color: var(--theme-ink);
    }

    html[data-theme="light"] .mm-lang__list {
        background: rgba(0, 0, 0, 0.025);
        border-color: var(--theme-line);
    }

    html[data-theme="light"] .mm-lang__opt {
        color: var(--theme-muted);
    }

    html[data-theme="light"] .mm-lang__opt:active,
    html[data-theme="light"] .mm-lang__opt.is-active {
        background: rgba(0, 0, 0, 0.05);
    }

    /* Dim the page behind the open sheet (tap on it closes — handled in main.js) */
    body::after {
        content: '';
        position: fixed;
        inset: 0;
        z-index: 49;
        background: rgba(0, 0, 0, 0.5);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    body:has(#mobile-menu.is-open)::after {
        opacity: 1;
        visibility: visible;
    }

    html[data-theme="light"] body:has(#mobile-menu.is-open)::after {
        background: rgba(0, 0, 0, 0.25);
    }

    /* ── Page clearance: nothing to clear at the top any more ── */
    .dash-page,
    .sv {
        padding-top: 20px;
    }

    /* Home full-screen sections: reserve the dock at the bottom instead of the bar at the top */
    body.home-bw-theme .hcm {
        padding-top: 0;
        padding-bottom: var(--tb-total);
    }

    body.home-bw-theme .hm {
        --hm-pad-top: clamp(16px, calc(var(--hm-screen) * .03), 28px);
        padding-bottom: clamp(16px, calc(var(--hm-screen) * .03), 28px);
    }

    body.home-bw-theme .home-cta-sec {
        padding-top: 32px;
        padding-bottom: 32px;
    }

    /* ── Floating buttons sit above the dock ── */
    body #lc-widget {
        bottom: calc(var(--tb-total) + 12px);
        --lc-offset: calc(var(--tb-total) + 100px);
    }

    body .scroll-top-btn {
        bottom: calc(var(--tb-total) + 82px);
    }

    /* White mode: chat bubble is black like every other accent on the white page */
    html[data-theme="light"] body.home-bw-theme #lc-widget #lc-toggle {
        color: #fff !important;
        background: var(--mono-ink-bg, var(--theme-ink)) !important;
        border-color: var(--theme-ink) !important;
        box-shadow: 0 10px 24px rgba(0, 0, 0, 0.26) !important;
    }

    html[data-theme="light"] body.home-bw-theme #lc-widget #lc-toggle :is(i, svg) {
        color: #fff !important;
    }

    /* The open sheet covers the area the floating buttons occupy */
    body:has(#mobile-menu.is-open) #lc-widget,
    body:has(#mobile-menu.is-open) .scroll-top-btn {
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }
}

@media (max-width: 767px) and (prefers-reduced-motion: reduce) {
    #navbar .mobile-menu__panel,
    #navbar .mobile-menu.is-open .mobile-menu__panel {
        transform: none;
    }

    .app-tabbar__item,
    .app-tabbar__icon {
        transition: none !important;
    }
}
