/*
 * China Kanta mobile navigation.
 *
 * Scoped to the ck- prefixed classes rendered by
 * components/storefront/mobile-top-nav.blade.php and mobile-tab-bar.blade.php,
 * so nothing here can reach the desktop header. Colour comes from the brand
 * tokens already compiled into the Vite bundle; geometry lives here because
 * these utilities are not in the built Tailwind output.
 */

:root {
    --ck-brand: #e31e24;
    --ck-ink: #171719;
    --ck-muted: #555555;
    --ck-line: #eeeeee;
    /*
     * Everything that used to float in the bottom strip of the screen measures its
     * clearance from this one variable, so the bar's height is stated once and the
     * iOS home indicator and the Android gesture bar are both included.
     */
    --ck-tabbar-h: calc(56px + env(safe-area-inset-bottom, 0px));
    --ck-bottom-inset: 0px;
    /*
     * The app's web view draws full screen, under the clock, so the page has to
     * reserve that band itself and viewport-fit=cover is what makes env() report
     * a real number. In a plain browser tab the browser already kept the layout
     * clear of the status bar and this resolves to 0.
     */
    --ck-top-inset: env(safe-area-inset-top, 0px);
}

@media (max-width: 1023.98px) {
    :root {
        --ck-bottom-inset: var(--ck-tabbar-h);
    }
}

/* ---------- L1: primary tabs ---------- */

/*
 * The sticky header is the first painted element on a phone, so the status-bar
 * band is reserved here rather than on the nav itself: the header also holds the
 * slide-down menu and the category sheet, and all of them need to clear the clock
 * while the bar is pinned.
 *
 * The band is offset by the 12px the tab row already carries, because that padding
 * sits below this one — reserving the full inset on top of it pushed the tabs a
 * second status bar down, which reads as a dead white strip under the clock.
 */
@media (max-width: 1023.98px) {
    .ck-appbar {
        padding-top: max(calc(var(--ck-top-inset) - 12px), 0px);
    }
}

.ck-mnav {
    background: #fff;
}

.ck-mnav-tabs {
    display: flex;
    align-items: center;
    gap: 22px;
    overflow-x: auto;
    padding: 0 14px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.ck-mnav-tabs::-webkit-scrollbar {
    display: none;
}

.ck-mnav-tab {
    position: relative;
    flex: 0 0 auto;
    padding: 12px 0 11px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    color: var(--ck-ink);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    transition: color 160ms ease;
}

.ck-mnav-tab::after {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;
    bottom: 2px;
    height: 3px;
    border-radius: 3px;
    background: var(--ck-brand);
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.ck-mnav-tab.is-active {
    color: var(--ck-brand);
}

.ck-mnav-tab.is-active::after {
    transform: scaleX(1);
}

.ck-mnav-tab:active {
    opacity: 0.65;
}

/* ---------- L2: search ---------- */

.ck-mnav-search {
    position: relative;
    padding: 2px 12px 10px;
}

.ck-mnav-search input[type="search"] {
    padding-left: 2.6rem;
}

.ck-mnav-camera {
    position: absolute;
    left: 20px;
    top: 50%;
    z-index: 25;
    display: flex;
    width: 30px;
    height: 30px;
    margin-top: -15px;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    color: var(--ck-muted);
    -webkit-tap-highlight-color: transparent;
}

.ck-mnav-camera:active {
    background: #f3f4f6;
}

/* ---------- L3: category strip ---------- */

.ck-mnav-catrow {
    position: relative;
    display: flex;
    align-items: center;
    border-top: 1px solid var(--ck-line);
}

.ck-mnav-cats {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: 8px;
    overflow-x: auto;
    padding: 9px 12px 11px 14px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.ck-mnav-cats::-webkit-scrollbar {
    display: none;
}

.ck-mnav-chip {
    flex: 0 0 auto;
    padding: 6px 13px;
    border: 1px solid var(--ck-line);
    border-radius: 9999px;
    background: #fff;
    font-size: 13px;
    line-height: 1.15;
    color: var(--ck-muted);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.ck-mnav-chip:active {
    background: #f7f7f7;
}

.ck-mnav-chip.is-active {
    border-color: var(--ck-ink);
    color: var(--ck-ink);
    font-weight: 700;
}

.ck-mnav-expand {
    flex: 0 0 auto;
    display: flex;
    width: 46px;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    border: 0;
    background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, #fff 38%);
    color: var(--ck-ink);
    -webkit-tap-highlight-color: transparent;
}

/* ---------- L3 sheet: full category list ---------- */

.ck-cat-sheet {
    position: fixed;
    /*
     * The bottom inset is not cosmetic. This sheet lives inside the sticky
     * header, whose z-30 makes a stacking context, so the sheet's own 9995 only
     * orders it against its siblings: the body-level tab bar (z-60) still paints
     * over the last 57px. Stopping the sheet at the bar keeps the bottom chip
     * rows both visible and tappable.
     */
    inset: 0 0 var(--ck-tabbar-h, 0px) 0;
    z-index: 9995;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    background: rgba(17, 17, 19, 0.45);
}

.ck-cat-sheet-panel {
    max-height: 78vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 20px 20px 0 0;
    background: #fff;
    padding: 14px 14px calc(18px + env(safe-area-inset-bottom, 0px));
}

.ck-cat-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--ck-line);
}

.ck-cat-group + .ck-cat-group {
    margin-top: 16px;
}

.ck-cat-group-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--ck-ink);
    display: block;
    padding: 4px 0 8px;
}

.ck-cat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ck-cat-sheet-all {
    display: block;
    margin-top: 20px;
    padding: 12px;
    border: 1px solid var(--ck-line);
    border-radius: 12px;
    background: #f7f7f8;
    text-align: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--ck-ink);
}

/* ---------- L4: homepage shortcuts ---------- */

.ck-quick {
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    padding: 4px 12px 14px;
}

/* Phone only, for the same cascade reason as the bottom bar. */
@media (max-width: 1023.98px) {
    .ck-quick {
        display: grid;
    }
}

.ck-quick-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    min-height: 44px;
    padding: 8px 2px;
    border-radius: 12px;
    text-align: center;
    -webkit-tap-highlight-color: transparent;
}

.ck-quick-item:active {
    background: #f7f7f7;
}

.ck-quick-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: #f7f7f8;
    color: var(--ck-brand);
}

.ck-quick-label {
    font-size: 10.5px;
    line-height: 1.2;
    color: var(--ck-ink);
    font-weight: 500;
}

/* ---------- fixed bottom bar ---------- */

.ck-tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9990;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    background: #fff;
    border-top: 1px solid var(--ck-line);
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/*
 * The bar is switched on here rather than by the lg:hidden utility on the
 * element: this stylesheet is linked after the Tailwind bundle, so at equal
 * specificity a plain `display: grid` above would win and the desktop layout
 * would grow a second navigation.
 */
@media (max-width: 1023.98px) {
    .ck-tabbar {
        display: grid;
    }
}

.ck-tab {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 56px;
    padding: 7px 2px 6px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.15;
    color: var(--ck-muted);
    background: none;
    border: 0;
    -webkit-tap-highlight-color: transparent;
    transition: color 140ms ease;
}

.ck-tab:active .ck-tab-icon {
    transform: scale(0.9);
}

.ck-tab.is-active {
    color: var(--ck-brand);
}

.ck-tab-icon {
    display: block;
    width: 24px;
    height: 24px;
    transition: transform 120ms ease;
}

.ck-tab-badge {
    position: absolute;
    top: 5px;
    left: calc(50% + 5px);
    display: flex;
    min-width: 17px;
    height: 17px;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border-radius: 9999px;
    background: var(--ck-brand);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
}

/* ---------- scroll collapse ---------- */

/*
 * The collapsing strip shortens the sticky header, which moves everything below
 * it up. Chrome would then "helpfully" subtract the same distance from the
 * scroll position, and the next scroll event would look like a swipe upward and
 * reopen the strip — an endless flip-flop. Anchoring is off on phones so the
 * gesture is the only thing that decides whether the strip is open.
 */
@media (max-width: 1023.98px) {
    html {
        overflow-anchor: none;
    }
}

.ck-mnav-collapse {
    overflow: hidden;
    max-height: 64px;
    overflow-anchor: none;
    transition:
        max-height 260ms cubic-bezier(0.22, 1, 0.36, 1),
        opacity 200ms ease;
}

.ck-mnav.is-shrunk .ck-mnav-collapse {
    max-height: 0;
    opacity: 0;
}

/* ---------- clearance for the fixed bar ---------- */

body {
    padding-bottom: var(--ck-bottom-inset);
}

/* ---------- dark mode ---------- */

html[data-theme="dark"] .ck-mnav,
html[data-theme="dark"] .ck-tabbar,
html[data-theme="dark"] .ck-cat-sheet-panel,
html[data-theme="dark"] .ck-mnav-chip,
html[data-theme="dark"] .ck-quick-icon {
    background-color: #17171a;
}

html[data-theme="dark"] .ck-mnav-chip {
    color: #d1d5db;
}

html[data-theme="dark"] .ck-tab,
html[data-theme="dark"] .ck-mnav-tab {
    color: #d1d5db;
}

html[data-theme="dark"] .ck-tab.is-active,
html[data-theme="dark"] .ck-mnav-tab.is-active,
html[data-theme="dark"] .ck-quick-icon {
    color: var(--ck-brand);
}

html[data-theme="dark"] .ck-mnav-chip.is-active {
    border-color: #e5e7eb;
    color: #f9fafb;
}

html[data-theme="dark"] .ck-cat-group-name,
html[data-theme="dark"] .ck-quick-label {
    color: #f3f4f6;
}

html[data-theme="dark"] .ck-mnav-catrow,
html[data-theme="dark"] .ck-cat-sheet-head {
    border-color: #2a2a2e;
}

html[data-theme="dark"] .ck-mnav-chip,
html[data-theme="dark"] .ck-quick-item:active,
html[data-theme="dark"] .ck-mnav-camera:active {
    border-color: #2a2a2e;
    background-color: #1f1f23;
}

html[data-theme="dark"] .ck-mnav-expand {
    background: linear-gradient(to right, rgba(23, 23, 26, 0) 0%, #17171a 38%);
}

@media (prefers-reduced-motion: reduce) {
    .ck-mnav-tab::after,
    .ck-mnav-collapse,
    .ck-tab-icon,
    .ck-mnav-tab {
        transition: none;
    }
}
