/*
    Phone bottom bar and categories sheet, shared by every theme that includes
    theme-default::storefront.partials.mobile-bar (Doc/05-theme-system.md,
    Mobile navigation).

    Shown below 761px only. A theme sets a few custom properties on :root:

        --mobile-bar-accent    active item, badge, the raised Home button
        --mobile-bar-ink       labels and icons            (default: #22252b)
        --mobile-bar-muted     secondary text              (default: #7b8089)
        --mobile-bar-line      borders                     (default: #ebedf1)
        --mobile-bar-surface   bar and sheet background    (default: #fff)

    Hover and press follow the motion system tokens when they are present.
*/

:root {
    --mobile-bar-h: 62px;
}

.mobile-bar,
.category-sheet {
    --_accent: var(--mobile-bar-accent, #de1849);
    --_ink: var(--mobile-bar-ink, #22252b);
    --_muted: var(--mobile-bar-muted, #7b8089);
    --_line: var(--mobile-bar-line, #ebedf1);
    --_surface: var(--mobile-bar-surface, #fff);
}

.mobile-bar { display: none; }

@media (max-width: 760px) {
    /* The bar must never cover the end of the page. */
    body:has(> .mobile-bar) {
        padding-bottom: calc(var(--mobile-bar-h) + env(safe-area-inset-bottom, 0px));
    }

    /* Lift the back-to-top button clear of the bar. */
    body:has(> .mobile-bar) .motion-top {
        bottom: calc(var(--mobile-bar-h) + 14px + env(safe-area-inset-bottom, 0px));
    }

    .mobile-bar {
        position: fixed;
        z-index: 60;
        right: 0;
        bottom: 0;
        left: 0;
        display: grid;
        height: calc(var(--mobile-bar-h) + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        grid-auto-columns: minmax(0, 1fr);
        grid-auto-flow: column;
        align-items: stretch;
        border-top: 1px solid var(--_line);
        background: var(--_surface);
        box-shadow: 0 -6px 18px rgb(17 24 39 / 6%);
        font-family: inherit;
    }
}

.mobile-bar__item {
    position: relative;
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 2px 4px;
    border: 0;
    background: none;
    color: var(--_ink);
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color var(--motion-fast, 150ms) var(--motion-ease-out, ease-out);
}

.mobile-bar__item:active { color: var(--_accent); }
.mobile-bar__item[aria-current="page"],
.mobile-bar__item[aria-expanded="true"] { color: var(--_accent); }

.mobile-bar__item:focus-visible {
    outline: 2px solid var(--_accent);
    outline-offset: -4px;
    border-radius: 10px;
}

.mobile-bar__icon {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.mobile-bar__label {
    max-width: 100%;
    overflow: hidden;
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-bar__icon-wrap { position: relative; display: inline-flex; }

.mobile-bar__badge {
    position: absolute;
    top: -6px;
    left: 13px;
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border: 2px solid var(--_surface);
    border-radius: 9px;
    background: var(--_accent);
    color: #fff;
    font-size: 9.5px;
    font-weight: 800;
    line-height: 13px;
    text-align: center;
}

.mobile-bar__badge[hidden] { display: none; }

/* Home: a raised round button carrying the shop's logo. */
.mobile-bar__item--home { justify-content: flex-end; }

.mobile-bar__home {
    display: grid;
    width: 52px;
    height: 52px;
    margin-top: -26px;
    overflow: hidden;
    place-items: center;
    border: 3px solid var(--_surface);
    border-radius: 50%;
    background: var(--_accent);
    box-shadow: 0 4px 14px rgb(17 24 39 / 18%);
    color: #fff;
    transition: transform var(--motion-fast, 150ms) var(--motion-ease-out, ease-out);
}

.mobile-bar__item--home:active .mobile-bar__home { transform: scale(var(--motion-press, .96)); }
.mobile-bar__home img { width: 100%; height: 100%; object-fit: contain; background: var(--_surface); }
.mobile-bar__home img + .mobile-bar__icon { display: none; }

/* --------------------------------------------------------- the sheet */

.category-sheet {
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: min(82vh, 720px);
    margin: auto 0 0;
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: 18px 18px 0 0;
    background: var(--_surface);
    color: var(--_ink);
    font-family: inherit;
}

.category-sheet::backdrop { background: rgb(17 24 39 / 45%); }

.category-sheet[open] {
    display: flex;
    flex-direction: column;
    animation: category-sheet-up var(--motion-base, 220ms) var(--motion-ease-out, ease-out);
}

@keyframes category-sheet-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .category-sheet[open] { animation: none; }
}

/* The page behind the sheet stays put. */
html:has(.category-sheet[open]) { overflow: hidden; }

.category-sheet__panel {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
}

.category-sheet__head {
    display: flex;
    flex: 0 0 auto;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 18px 12px;
    border-bottom: 1px solid var(--_line);
}

.category-sheet__head h2 { margin: 0; font-size: 17px; font-weight: 800; }
.category-sheet__head p { margin: 2px 0 0; color: var(--_muted); font-size: 12px; }

.category-sheet__close,
.category-sheet__toggle {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    border: 0;
    background: none;
    color: var(--_muted);
    cursor: pointer;
}

.category-sheet__close { width: 36px; height: 36px; border-radius: 50%; background: var(--mobile-bar-mist, #f5f6f8); }
.category-sheet__close svg,
.category-sheet__toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.category-sheet__list,
.category-sheet__children { margin: 0; padding: 0; list-style: none; }

.category-sheet__list {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 0 calc(16px + env(safe-area-inset-bottom, 0px));
}

.category-sheet__item { border-bottom: 1px solid var(--_line); }
.category-sheet__row { display: flex; align-items: stretch; }

.category-sheet__link,
.category-sheet__children a {
    display: block;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    color: var(--_ink);
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.category-sheet__link { padding: 14px 18px; font-size: 14px; font-weight: 600; }
.category-sheet__toggle { width: 52px; border-left: 1px solid var(--_line); }
.category-sheet__toggle svg { transition: transform var(--motion-fast, 150ms) var(--motion-ease-out, ease-out); }
.category-sheet__toggle[aria-expanded="true"] { color: var(--_accent); }
.category-sheet__toggle[aria-expanded="true"] svg { transform: rotate(90deg); }

.category-sheet__children { padding: 0 0 8px; background: var(--mobile-bar-mist, #f5f6f8); }
.category-sheet__children[hidden] { display: none; }
.category-sheet__children a { padding: 10px 18px 10px 32px; font-size: 13px; }

.category-sheet a[aria-current="page"] { color: var(--_accent); font-weight: 700; }
.category-sheet__empty { margin: 0; padding: 24px 18px; color: var(--_muted); font-size: 13px; }

/* Never on a wide screen, even if it was left open while the window grew. */
@media (min-width: 761px) {
    .category-sheet { display: none !important; }
}
