/*
 * XM storefront visual layer.
 * All rules stay isolated from the upstream Tokyo stylesheet for easy rollback.
 */

:root {
    --xm-bg: #f4f4f4;
    --xm-surface: #ffffff;
    --xm-surface-soft: #fafafa;
    --xm-text: #171b22;
    --xm-muted: #68717c;
    --xm-border: #e8eaed;
    --xm-orange: #ff6a21;
    --xm-orange-dark: #e95610;
    --xm-orange-soft: #fff1e8;
}

body.tokyo-theme {
    background: var(--xm-bg);
    color: var(--xm-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
}

.xm-market-utility {
    display: none;
}

.xm-market-utility-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: min(1680px, calc(100% - 32px));
    min-height: 30px;
    margin: 0 auto;
    padding: 0 8px;
}

.tokyo-nav-shell {
    top: 0;
    padding: 0;
    border-bottom: 1px solid #eceef1;
    background: var(--xm-surface);
}

.tokyo-nav-wrap,
.tokyo-shell {
    width: min(1680px, calc(100% - 32px));
}

.tokyo-nav {
    position: relative;
    min-height: 72px;
    padding: 0 8px;
    border: 0;
    border-radius: 0;
    background: var(--xm-surface);
    box-shadow: none;
    backdrop-filter: none;
}

.tokyo-brand-wrap {
    height: 72px;
}

.tokyo-brand-mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    border: 0;
}

.tokyo-brand-chip::after {
    background: linear-gradient(90deg, var(--xm-orange), rgba(255, 106, 33, 0));
}

.tokyo-brand-name {
    color: #111318;
    font-size: 1.22rem;
    letter-spacing: -0.025em;
}

.tokyo-nav .navbar-collapse,
.tokyo-nav-main {
    position: static;
}

.tokyo-nav-links {
    position: static;
    min-height: 42px;
    padding: 0 8px;
    gap: 4px;
    border-top: 0;
}

.tokyo-nav-link {
    min-height: 42px;
    padding: 0 14px;
    border-radius: 0;
    color: #4e5661;
    font-size: 14px;
    font-weight: 700;
}

.tokyo-nav-link:hover,
.tokyo-nav-link.is-active {
    background: transparent;
    color: var(--xm-orange-dark);
    box-shadow: none;
}

.tokyo-nav-tools {
    position: static;
    gap: 10px;
}

.tokyo-button,
.tokyo-lang-chip,
.tokyo-user-chip {
    border-radius: 6px;
}

.tokyo-button-dark {
    border-color: var(--xm-orange);
    background: var(--xm-orange);
}

.tokyo-button-dark:hover {
    border-color: var(--xm-orange-dark);
    background: var(--xm-orange-dark);
    color: #fff;
}

.tokyo-main {
    margin-top: 0;
    padding-bottom: 44px;
}

.tokyo-shop-layout {
    grid-template-columns: 300px minmax(0, 1fr) 280px;
    gap: 28px;
    margin-top: 20px;
}

.panel {
    border: 0;
    border-radius: 0;
    background: var(--xm-surface);
    box-shadow: none;
}

.tokyo-sidebar-panel {
    grid-column: 1;
    grid-row: 1;
    top: 92px;
    max-height: calc(100vh - 112px);
    overflow: hidden;
}

.tokyo-index-heading {
    min-height: 58px;
    padding: 12px 18px;
}

.tokyo-index-heading .panel-kicker,
.tokyo-catalog-heading .panel-kicker {
    display: none;
}

.tokyo-index-panel-title {
    color: var(--xm-text);
    font-size: 17px;
    font-weight: 750;
    letter-spacing: -0.02em;
}

.tokyo-sidebar-panel .panel-body {
    padding: 8px 0 12px;
}

.tokyo-category-tree {
    max-height: calc(100vh - 186px);
    gap: 0;
    padding: 0;
}

.tokyo-category-node {
    gap: 0;
}

.tokyo-category-row {
    padding-left: calc(var(--tokyo-depth) * 14px);
}

.tokyo-category-link {
    min-height: 44px;
    padding: 8px 14px 8px 20px;
    border: 0;
    border-radius: 0;
    color: #4e5661;
    font-size: 15px;
    font-weight: 600;
}

@media (min-width: 1200px) {
    .tokyo-nav-shell {
        height: 72px;
        box-sizing: border-box;
    }
}

.tokyo-category-link:hover {
    border-color: transparent;
    background: #fff7f1;
    color: var(--xm-orange-dark);
    box-shadow: none;
}

.tokyo-category-link.is-active {
    border-color: transparent;
    background: var(--xm-orange-soft);
    color: var(--xm-orange-dark);
    box-shadow: none;
}

.tokyo-category-icon {
    width: 26px;
    height: 26px;
    flex-basis: 26px;
    border: 0;
    border-radius: 5px;
}

.tokyo-category-toggle {
    border: 0;
    background: transparent;
}

.tokyo-category-count {
    background: transparent;
    color: #78808a;
}

.tokyo-catalog-panel {
    grid-column: 2;
    grid-row: 1;
    border: 0;
    background: transparent;
    box-shadow: none;
}

.tokyo-catalog-heading {
    min-height: 106px;
    padding: 18px 20px;
    margin-bottom: 16px;
    border: 0;
    border-radius: 0;
    background: var(--xm-surface);
}

.tokyo-catalog-heading .tokyo-index-panel-title {
    font-size: 18px;
}

.tokyo-catalog-tools {
    top: 28px;
    right: 20px;
    width: min(100%, 360px);
}

.tokyo-search-combo {
    border-color: #dfe3e8;
    border-radius: 6px;
}

.tokyo-searchbox-combo {
    border-radius: 6px;
}

.tokyo-search-combo .tokyo-button {
    border-radius: 5px;
}

.tokyo-catalog-body {
    padding: 0;
}

.xm-sort-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 12px;
}

.xm-sort-bar-label {
    color: #68717c;
    font-size: 12px;
    font-weight: 700;
}

.xm-sort-toggle {
    display: inline-flex;
    overflow: hidden;
    border: 1px solid var(--xm-border);
    border-radius: 6px;
    background: var(--xm-surface);
}

.xm-sort-option {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    gap: 6px;
    border: 0;
    background: transparent;
    color: #536471;
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
}

.xm-sort-option + .xm-sort-option {
    border-left: 1px solid var(--xm-border);
}

.xm-sort-option i {
    font-size: 12px;
}

.xm-sort-option:hover {
    background: var(--xm-surface-soft);
    color: var(--xm-text);
}

.xm-sort-option.is-active {
    background: var(--xm-orange);
    color: #fff;
}

.tokyo-table-wrap {
    min-height: 0;
    overflow: hidden;
    border-color: var(--xm-border);
    border-radius: 8px;
    background: var(--xm-surface);
    box-shadow: 0 1px 3px rgba(15, 20, 25, 0.04);
}

.tokyo-commodity-col-price {
    width: 92px;
}

.tokyo-commodity-col-stock {
    width: 88px;
}

.tokyo-commodity-col-action {
    width: 96px;
}

.tokyo-commodity-table thead th {
    height: 42px;
    padding: 9px 12px;
    border-bottom-color: var(--xm-border);
    background: var(--xm-surface-soft);
    color: #68717c;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
}

.tokyo-commodity-table thead th:nth-child(2),
.tokyo-commodity-table thead th:nth-child(3),
.tokyo-commodity-table tbody td:nth-child(2),
.tokyo-commodity-table tbody td:nth-child(3) {
    text-align: center;
}

.tokyo-commodity-table thead th:nth-child(4),
.tokyo-commodity-table tbody td:nth-child(4) {
    padding-right: 20px;
    text-align: right;
}

.tokyo-commodity-table tbody tr {
    min-height: 96px;
}

.tokyo-commodity-table tbody td {
    height: 96px;
    padding: 10px 14px;
    border-bottom-color: var(--xm-border);
}

.tokyo-commodity-row:hover {
    background: var(--xm-surface-soft);
}

.tokyo-commodity-anchor {
    gap: 12px;
}

.tokyo-commodity-thumb {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    border: 0;
    border-radius: 0;
    background-color: transparent;
}

.tokyo-commodity-copy {
    gap: 3px;
}

.tokyo-commodity-name {
    color: var(--xm-text);
    font-size: 15px;
    font-weight: 650;
    line-height: 21px;
    letter-spacing: 0;
}

.tokyo-commodity-tags {
    gap: 5px;
}

.tokyo-pill,
.tokyo-tag {
    min-height: 17px;
    padding: 0 6px;
    font-size: 10px;
}

.tokyo-commodity-muted {
    color: var(--xm-text);
    font-size: 13px;
    font-weight: 750;
}

.tokyo-commodity-price-main {
    color: var(--xm-text);
    font-size: 14px;
    font-weight: 750;
}

.tokyo-commodity-action-link,
.tokyo-commodity-action-disabled {
    width: 60px;
    min-height: 30px;
    padding: 0 8px;
    border-radius: 6px;
    font-size: 12px;
}

.tokyo-commodity-action-link {
    background: var(--xm-orange);
}

.tokyo-commodity-action-link:hover {
    background: var(--xm-orange-dark);
    color: #fff;
}

.tokyo-commodity-action-link i,
.tokyo-commodity-action-disabled i {
    display: none;
}

.xm-quick-panel {
    position: sticky;
    top: 92px;
    grid-column: 3;
    grid-row: 1;
    align-self: start;
    overflow: hidden;
}

.xm-quick-heading {
    display: flex;
    align-items: center;
    min-height: 58px;
    padding: 12px 14px;
    gap: 10px;
    border-bottom: 1px solid #ededed;
}

.xm-quick-heading-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border-radius: 8px;
    background: var(--xm-orange-soft);
    color: var(--xm-orange);
    font-size: 18px;
}

.xm-quick-heading h2 {
    font-size: 15px;
}

.xm-quick-heading p {
    margin: 2px 0 0;
    color: #78808a;
    font-size: 11px;
}

.xm-quick-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
}

.xm-quick-card {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    min-width: 0;
    min-height: 72px;
    padding: 10px 7px;
    gap: 6px;
    border: 1px solid #ececec;
    border-radius: 7px;
    background: var(--xm-surface-soft);
    color: #48515b;
    font-size: 12px;
    text-align: center;
    transition: border-color 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.xm-quick-card:hover {
    border-color: #ffd2bb;
    background: #fff5ef;
    color: #ef5b17;
}

.xm-quick-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--xm-orange);
    font-size: 21px;
}

.xm-quick-name {
    max-width: 100%;
    overflow: hidden;
    font-weight: 600;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.xm-mobile-stock,
.xm-mobile-price,
.xm-mobile-chevron,
.xm-mobile-bottom-nav {
    display: none;
}

@media (max-width: 1199px) {
    .xm-market-utility {
        display: none;
    }

    .tokyo-nav-shell {
        top: 0;
    }

    .tokyo-nav {
        min-height: 0;
    }

    .tokyo-nav-links,
    .tokyo-nav-tools {
        position: static;
    }

    .tokyo-shop-layout {
        grid-template-columns: 1fr;
    }

    .tokyo-sidebar-panel,
    .xm-quick-panel,
    .tokyo-catalog-panel {
        grid-column: 1;
        grid-row: auto;
    }

    .xm-quick-panel {
        position: static;
    }
}

@media (max-width: 767px) {
    body.tokyo-theme {
        font-size: 14px;
        background:
            radial-gradient(ellipse at 16% 0%, rgba(255, 255, 255, 0.68) 0 12%, transparent 42%),
            radial-gradient(ellipse at 84% 0%, rgba(112, 157, 176, 0.34) 0 14%, transparent 44%),
            #d8e5eb;
        background-attachment: fixed;
    }

    .tokyo-nav-shell {
        position: sticky;
        top: 0;
        z-index: 1030;
        padding: 0;
    }

    .tokyo-nav-wrap,
    .tokyo-shell {
        width: 100%;
    }

    .tokyo-nav {
        min-height: 56px;
        padding: 4px 16px;
        border-radius: 0;
    }

    .tokyo-brand-wrap {
        height: 48px;
    }

    .tokyo-brand-mark {
        width: 32px;
        height: 32px;
        flex-basis: 32px;
    }

    .tokyo-brand-name {
        font-size: 15px;
    }

    .tokyo-brand-chip::after {
        height: 2px;
    }

    .tokyo-nav-toggle {
        width: 44px;
        height: 44px;
        flex-basis: 44px;
        border-radius: 8px;
    }

    .tokyo-nav .navbar-collapse {
        margin-top: 4px;
        padding-bottom: 12px;
    }

    .tokyo-nav-link,
    .tokyo-lang-chip,
    .tokyo-user-chip {
        border-radius: 8px;
    }

    .tokyo-main {
        margin-top: 0;
        padding: 12px 16px 92px;
    }

    .tokyo-shop-layout {
        display: flex;
        flex-direction: column;
        /* 基础样式里的 align-items: start 是给桌面端 grid 布局用的（grid 下它管纵向）。
         * 这里一改成 flex column，同一个属性就变成管横向了，子面板会退化成
         * 按内容宽度收缩：分类里没有商品时整块内容区（标题/筛选/搜索框）会跟着变窄。
         * 显式声明 stretch，让面板始终撑满容器宽度，与有商品时保持一致。 */
        align-items: stretch;
        gap: 12px;
        margin-top: 0;
    }

    .tokyo-sidebar-panel {
        position: fixed;
        top: auto;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1050;
        width: 100%;
        max-width: 100%;
        max-height: 82dvh;
        border-radius: 24px 24px 0 0;
        visibility: hidden;
        transform: translateY(104%);
        transition: transform 0.22s ease, visibility 0.22s ease;
    }

    body.tokyo-mobile-drawer-open .tokyo-sidebar-panel {
        visibility: visible;
        transform: translateY(0);
    }

    .tokyo-category-tree {
        max-height: calc(82dvh - 82px);
    }

    .tokyo-index-heading {
        min-height: 58px;
    }

    .xm-quick-panel {
        order: 1;
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 8px;
    }

    .tokyo-catalog-panel {
        order: 2;
        /* 基础样式给了它 align-self: start，同样是为桌面端 grid 写的。
         * 手机端父级是 flex column，这条会盖过父级的 stretch，
         * 让面板按内容宽度收缩 —— 空分类时整块内容区跟着变窄的直接原因。 */
        align-self: stretch;
    }

    /* 手机端便捷入口：横向单行滑动，首屏刚好 4 个，多出来的往右排，靠手指左右滑 */
    .xm-quick-grid {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 8px;
        padding: 12px;
        scroll-snap-type: x proximity;
        scroll-padding: 0 12px;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .xm-quick-grid::-webkit-scrollbar {
        display: none;
    }

    .xm-quick-card {
        /* 基准宽度=四等分，开满 4 个正好占满一行；不足 4 个时自动放大补满，超过 4 个则溢出可滑动 */
        flex: 1 0 calc((100% - 24px) / 4);
        min-width: 0;
        min-height: 72px;
        padding: 10px 4px;
        border-radius: 7px;
        scroll-snap-align: start;
    }

    .xm-quick-icon {
        font-size: 19px;
    }

    .xm-quick-name {
        display: -webkit-box;
        overflow: hidden;
        font-size: 11px;
        line-height: 14px;
        text-overflow: clip;
        white-space: normal;
        word-break: break-all;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .tokyo-catalog-heading {
        min-height: auto;
        padding: 14px;
        margin-bottom: 12px;
        border-radius: 8px;
    }

    .tokyo-catalog-heading .panel-kicker {
        display: none;
    }

    .tokyo-catalog-tools {
        gap: 8px;
    }

    .tokyo-mobile-filter-trigger {
        min-height: 40px;
        border-radius: 6px;
    }

    .tokyo-searchbox-combo {
        min-height: 40px;
        border-radius: 6px;
    }

    .tokyo-search-combo .tokyo-button {
        min-height: 38px;
        border-radius: 6px;
    }

    .tokyo-table-wrap {
        border-radius: 8px;
    }

    .xm-sort-bar {
        justify-content: space-between;
        gap: 8px;
        margin-bottom: 10px;
    }

    .xm-sort-toggle {
        flex: 0 1 auto;
        min-width: 0;
    }

    .xm-sort-option {
        min-height: 34px;
        padding: 0 10px;
        gap: 5px;
        white-space: nowrap;
    }

    .tokyo-commodity-table tbody tr {
        min-height: 76px;
        padding: 0;
        border-bottom-color: var(--xm-border);
    }

    .tokyo-commodity-table tbody td {
        height: auto;
        padding: 12px 14px;
    }

    .tokyo-commodity-main {
        padding: 12px 16px 12px 14px !important;
    }

    .tokyo-commodity-anchor {
        display: grid;
        grid-template-columns: 40px minmax(0, 1fr) auto 16px;
        gap: 8px;
    }

    .tokyo-commodity-thumb {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
        grid-column: 1;
        border-radius: 0;
    }

    .tokyo-commodity-copy {
        grid-column: 2;
        gap: 1px;
    }

    .tokyo-commodity-name {
        font-size: 13px;
        line-height: 18px;
        -webkit-line-clamp: 2;
        display: -webkit-box;
        overflow: hidden;
        white-space: normal;
        -webkit-box-orient: vertical;
    }

    .tokyo-commodity-tags {
        display: none;
    }

    .tokyo-pill,
    .tokyo-tag {
        flex: 0 0 auto;
        min-height: 16px;
        padding: 0 4px;
        font-size: 9px;
    }

    .tokyo-commodity-anchor > .xm-mobile-price {
        display: block;
        grid-column: 3;
        align-self: center;
        color: var(--xm-text);
        font-size: 14px;
        font-weight: 750;
        white-space: nowrap;
    }

    .tokyo-commodity-anchor > .xm-mobile-chevron {
        display: inline-flex;
        grid-column: 4;
        align-self: center;
        color: #87909a;
        font-size: 12px;
    }

    .xm-mobile-stock {
        display: block;
        color: #68717c;
        font-size: 10.5px;
        font-weight: 600;
        line-height: 16px;
    }

    .tokyo-pill-mobile-only,
    .tokyo-commodity-tags .tokyo-pill-mobile-only,
    .tokyo-pill.tokyo-pill-mobile-meta,
    .tokyo-pill.tokyo-pill-mobile-price,
    .tokyo-pill.tokyo-pill-mobile-member {
        display: none !important;
    }

    .xm-mobile-bottom-nav {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1040;
        display: flex;
        min-height: calc(64px + env(safe-area-inset-bottom, 0px));
        padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
        border-top: 1px solid rgba(207, 217, 222, 0.92);
        background: rgba(232, 240, 244, 0.94);
        box-shadow: 0 -4px 18px rgba(15, 20, 25, 0.06);
        backdrop-filter: blur(14px);
    }

    .xm-mobile-bottom-nav a,
    .xm-mobile-bottom-nav button,
    .xm-mobile-bottom-nav .tokyo-mobile-filter-trigger {
        position: relative;
        display: flex;
        min-width: 0;
        min-height: 64px;
        flex: 1 1 0;
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 4px;
        padding: 4px 0;
        border: 0;
        border-radius: 0;
        background: transparent;
        color: #536471;
        font: inherit;
        font-size: 11px;
        font-weight: 650;
    }

    .xm-mobile-bottom-nav i {
        font-size: 20px;
    }

    .xm-mobile-bottom-nav .is-active {
        color: var(--xm-orange-dark);
    }

    .xm-mobile-bottom-nav .is-active::before {
        position: absolute;
        top: 3px;
        width: 28px;
        height: 3px;
        border-radius: 999px;
        background: var(--xm-orange);
        content: "";
    }
}
