/**
 * Mobile bottom navigation + categories modal.
 */

:root {
    --katabam-mnav-height: 62px;
    --katabam-mnav-bubble: 42px;
    --katabam-mnav-notch-y: 18px;
    --katabam-mnav-icon-rest-y: 27.75px;
    --katabam-mnav-bg: #ffffff;
    --katabam-mnav-muted: rgba(8, 24, 42, 0.5);
    --katabam-cat-surface: var(--katabam-footer-bg, #f0f4f8);
    --katabam-cat-surface-hover: #e6ecf2;
    --katabam-cat-header-tint: rgba(110, 190, 69, 0.08);
    --katabam-cat-close-bg: rgba(8, 24, 42, 0.06);
    --katabam-cat-badge-bg: rgba(110, 190, 69, 0.14);
    --katabam-cat-chevron-bg: rgba(110, 190, 69, 0.12);
    --katabam-cat-backdrop: rgba(8, 24, 42, 0.52);
}

@media (max-width: 768px) {
    /* Safari: anything outside <body> (below the page while the toolbar collapses, rubber-banding) shows the
       root background — make it the bar's colour so the bar never looks like it floats over a gap. */
    html {
        background-color: var(--katabam-mnav-bg);
    }

    body {
        min-height: 100vh;
        min-height: 100dvh;
    }

    body {
        padding-bottom: calc(var(--katabam-mnav-height) + env(safe-area-inset-bottom, 0px));
    }

    body.mobile-nav-open,
    body.katabam-cat-modal-open {
        overflow: hidden;
    }
}

.katabam-mnav {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 190;
    display: none;
    background: transparent;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    overflow: visible;
    pointer-events: none;
    /* own compositor layer: iOS repaints a fixed bar (and its SVG drop-shadow) on every scroll frame otherwise */
    transform: translate3d(0, 0, 0);
    -webkit-transform: translate3d(0, 0, 0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* the home-indicator strip below the bar is part of the bar (it used to be transparent and showed the page scrolling under it) */
.katabam-mnav::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    height: calc(env(safe-area-inset-bottom, 0px) + 2px);
    background: var(--katabam-mnav-bg);
}

/* iOS 26 Safari floats its toolbar over the page and clips fixed content at the toolbar's top edge, so the page shows
   under it. Safari tints that area from the colour of a fixed element touching the bottom edge — the bar itself has a
   transparent box (its shape is an SVG), so this small solid strip, in the bar's colour, is what Safari samples. */
.katabam-mnav-edge {
    display: none;
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    height: 28px;
    z-index: 189;
    background-color: var(--katabam-mnav-bg);
    pointer-events: none;
}

@media (max-width: 768px) {
    .katabam-mnav-edge {
        display: block;
    }
}

/* Safari: when the toolbar collapses the bar can lift off the screen edge for a moment — the fill below it
   (same colour as the bar) means no page content or blank gap is ever visible under it, like Digikala. */
.katabam-mnav::after {
    content: '';
    position: absolute;
    inset-inline: 0;
    top: calc(100% - 3px);
    height: 163px;
    background: var(--katabam-mnav-bg);
}

@media (max-width: 768px) {
    .katabam-mnav {
        display: block;
    }
}

.katabam-mnav__bar {
    position: relative;
    height: var(--katabam-mnav-height);
    overflow: visible;
    pointer-events: auto;
}

.katabam-mnav__shape {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    color: var(--katabam-mnav-bg);
    pointer-events: none;
    filter: drop-shadow(0 -4px 18px rgba(8, 24, 42, 0.12));
    transform: translateZ(0);
}

.katabam-mnav__shape path {
    transition: d 0.38s cubic-bezier(0.34, 1.15, 0.64, 1);
}

.katabam-mnav__bubble {
    position: absolute;
    top: calc(var(--katabam-mnav-notch-y) - (var(--katabam-mnav-bubble) / 2));
    width: var(--katabam-mnav-bubble);
    height: var(--katabam-mnav-bubble);
    margin-left: calc(var(--katabam-mnav-bubble) / -2);
    border-radius: 50%;
    background: var(--katabam-mnav-bg);
    box-shadow: 0 4px 14px rgba(8, 24, 42, 0.14);
    transition: left 0.38s cubic-bezier(0.34, 1.15, 0.64, 1);
    pointer-events: none;
    z-index: 2;
}

.katabam-mnav__list {
    position: relative;
    z-index: 3;
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(var(--mnav-cols, 4), minmax(0, 1fr));
    height: 100%;
    gap: 0;
}

.katabam-mnav__item {
    margin: 0;
    min-width: 0;
}

.katabam-mnav__btn {
    all: unset;
    box-sizing: border-box;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 0.15rem;
    width: 100%;
    height: 100%;
    padding: 0 0.15rem 0.45rem;
    cursor: pointer;
    color: var(--katabam-mnav-muted);
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}

.katabam-mnav__icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    isolation: isolate;
    transition:
        transform 0.32s cubic-bezier(0.34, 1.15, 0.64, 1),
        color 0.2s ease;
}

.katabam-mnav__icon-wrap::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--katabam-primary);
    opacity: 0;
    pointer-events: none;
    z-index: 0;
    transform: scale(0.92);
}

.katabam-mnav__icon-wrap.is-pulsing::after {
    animation: katabam-mnav-icon-pulse 0.72s ease-out forwards;
}

@keyframes katabam-mnav-icon-pulse {
    0% {
        opacity: 0.34;
        transform: scale(0.92);
    }

    100% {
        opacity: 0;
        transform: scale(2.35);
    }
}

.katabam-mnav__icon {
    position: relative;
    z-index: 1;
    display: block;
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.6;
}

.katabam-mnav__label {
    display: block;
    max-width: 100%;
    font-size: 0.66rem;
    line-height: 1.2;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: color 0.2s ease, font-weight 0.2s ease;
}

.katabam-mnav__item.is-active .katabam-mnav__btn {
    color: var(--katabam-primary);
}

.katabam-mnav__item.is-active .katabam-mnav__icon-wrap {
    transform: translateY(calc(var(--katabam-mnav-notch-y) - var(--katabam-mnav-icon-rest-y)));
    z-index: 4;
}

.katabam-mnav__item.is-active .katabam-mnav__icon {
    stroke-width: 2;
}

.katabam-mnav__item.is-active .katabam-mnav__label {
    color: var(--katabam-primary);
    font-weight: 700;
}

/* Categories modal */
.katabam-cat-modal {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: flex;
    align-items: stretch;
    justify-content: center;
    pointer-events: none;
}

.katabam-cat-modal.is-open {
    pointer-events: auto;
}

.katabam-cat-modal__backdrop {
    position: absolute;
    inset: 0;
    background: var(--katabam-cat-backdrop);
    opacity: 0;
    transition: opacity 0.28s ease;
}

.katabam-cat-modal.is-open .katabam-cat-modal__backdrop {
    opacity: 1;
}

.katabam-cat-modal__panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--katabam-bg, #ffffff);
    border-radius: 0;
    box-shadow: none;
    transform: translateY(100%);
    transition: transform 0.34s cubic-bezier(0.22, 1, 0.36, 1);
    overflow: hidden;
}

.katabam-cat-modal.is-open .katabam-cat-modal__panel {
    transform: translateY(0);
}

.katabam-cat-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1rem 0.85rem;
    border-bottom: 1px solid var(--katabam-border, #e8e8e8);
    background:
        linear-gradient(180deg, var(--katabam-cat-header-tint) 0%, transparent 100%),
        var(--katabam-bg, #ffffff);
}

.katabam-cat-modal__heading {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.katabam-cat-modal__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: var(--katabam-cat-badge-bg);
    color: var(--katabam-primary);
    flex-shrink: 0;
}

.katabam-cat-modal__badge-icon,
.katabam-cat-modal__close-icon,
.katabam-cat-card__chevron-icon,
.katabam-cat-modal__empty-icon {
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.5;
}

.katabam-cat-modal__title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--katabam-secondary, #082442);
}

.katabam-cat-modal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: var(--katabam-cat-close-bg);
    color: var(--katabam-secondary, #082442);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.katabam-cat-modal__close:hover,
.katabam-cat-modal__close:focus-visible {
    background: var(--katabam-cat-badge-bg);
    color: var(--katabam-primary);
}

.katabam-cat-modal__body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.9rem 0.9rem calc(1rem + env(safe-area-inset-bottom, 0px));
}

.katabam-cat-modal__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
}

.katabam-cat-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.8rem 0.85rem;
    border-radius: 14px;
    background: var(--katabam-cat-surface);
    border: 1px solid var(--katabam-border, #e8e8e8);
    color: inherit;
    text-decoration: none;
    transition:
        transform 0.2s ease,
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        background-color 0.2s ease;
}

.katabam-cat-card:hover,
.katabam-cat-card:focus-visible {
    transform: translateY(-1px);
    border-color: rgba(110, 190, 69, 0.4);
    background: var(--katabam-cat-surface-hover);
    box-shadow: 0 8px 20px rgba(8, 24, 42, 0.07);
}

.katabam-cat-card--featured {
    grid-column: 1 / -1;
    padding: 0.9rem 1rem;
    background:
        linear-gradient(135deg, rgba(110, 190, 69, 0.12) 0%, rgba(110, 190, 69, 0.04) 100%),
        var(--katabam-cat-surface);
    border-color: rgba(110, 190, 69, 0.28);
}

.katabam-cat-card__content {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    flex: 1;
}

.katabam-cat-card__name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--katabam-secondary, #082442);
    line-height: 1.35;
}

.katabam-cat-card--featured .katabam-cat-card__name {
    font-size: 0.96rem;
}

.katabam-cat-card__count {
    font-size: 0.74rem;
    color: var(--katabam-text-muted, #5c5c5c);
}

.katabam-cat-card__chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--katabam-cat-chevron-bg);
    color: var(--katabam-primary);
    flex-shrink: 0;
}

.katabam-cat-modal__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 220px;
    text-align: center;
    color: var(--katabam-text-muted, #5c5c5c);
}

.katabam-cat-modal__shop-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 1rem;
    border-radius: 999px;
    background: var(--katabam-primary);
    color: #ffffff;
    text-decoration: none;
    font-weight: 600;
}

@media (min-width: 769px) {
    .katabam-cat-modal {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .site-scroll-fab {
        bottom: calc(var(--katabam-mnav-height) + 0.65rem + env(safe-area-inset-bottom, 0px));
    }
}

@media (prefers-reduced-motion: reduce) {
    .katabam-mnav__shape path,
    .katabam-mnav__bubble,
    .katabam-mnav__icon-wrap,
    .katabam-cat-modal__panel,
    .katabam-cat-modal__backdrop,
    .katabam-cat-card {
        transition: none !important;
    }

    .katabam-mnav__icon-wrap.is-pulsing::after {
        animation: none !important;
    }
}


/* Hide the mobile navigation edge while the product purchase bar replaces it. */
@media (max-width: 768px) {
    body.single-product:has(#katabam-product-root #mbar.on) .katabam-mnav-edge {
        display: none;
    }
}
