/* Catalog-only layout, using the shared light/dark theme tokens. */
html:has(.storefront) .shop-search { display: none; }
html:has(.storefront) .shop-nav { gap: 24px; }
html:has(.storefront) .shop-nav__list { gap: 4px; }

.storefront-sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:root[data-app-theme] main.storefront {
    max-width: 1180px; padding: 28px 12px 72px; color: var(--foreground);
}
.catalog-search {
    display: flex; align-items: center; gap: 10px; grid-area: search;
    padding: 5px 5px 5px 16px; min-width: 0; margin: 0;
    border: 1px solid var(--input); border-radius: 10px; background: var(--card);
    transition: border-color .16s, box-shadow .16s;
}
.catalog-search:focus-within { border-color: var(--ring); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring) 18%, transparent); }
.catalog-search > svg { width: 19px; height: 19px; flex: 0 0 auto; color: var(--muted-foreground); }
:root[data-app-theme] .catalog-search input {
    width: 100%; min-width: 0; height: 38px; padding: 0; border: 0;
    background: transparent; color: var(--foreground); outline: 0 !important; box-shadow: none !important;
}
.catalog-search input::placeholder { color: var(--muted-foreground); }
.catalog-search button, .catalog-state button {
    flex: 0 0 auto; min-height: 38px; padding: 0 18px; border: 0; border-radius: 6px;
    background: var(--primary); color: var(--primary-foreground); font-weight: 500; cursor: pointer;
}
.catalog-search button:hover, .catalog-state button:hover { opacity: .85; }
.catalog-layout { display: grid; grid-template-columns: 188px minmax(0, 1fr); grid-template-areas: "categories search" "categories results"; gap: 20px 32px; align-items: start; }
.catalog-sidebar { grid-area: categories; position: sticky; top: 102px; }
/* A short, flat catalog does not need a permanent navigation rail. */
.storefront--compact .catalog-layout { grid-template-columns: minmax(0, 1fr) minmax(260px, 380px); grid-template-areas: "categories search" "results results"; gap: 28px; }
.storefront--compact .catalog-sidebar { position: static; align-self: center; min-width: 0; }
:root[data-app-theme] .storefront--compact .catalog-sidebar h2 { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.storefront--compact .catalog-categories { flex-direction: row; flex-wrap: wrap; max-height: none; overflow: visible; gap: 8px; }
.storefront--compact .catalog-categories .switch-category { flex: 0 0 auto; }
:root[data-app-theme] .catalog-sidebar h2 { margin: 0 0 14px; padding: 0 12px; color: var(--muted-foreground); font-size: 12px; font-weight: 500; line-height: 1.5; }
.catalog-categories { display: flex; flex-direction: column; gap: 5px; max-height: calc(100dvh - 170px); overflow-y: auto; padding: 3px; margin: -3px; }
.catalog-categories .switch-category {
    display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px 12px;
    border: 1px solid transparent; border-radius: 8px; color: var(--muted-foreground);
    font-size: 14px; line-height: 1.5; transition: background .16s, color .16s;
}
.catalog-categories .switch-category:hover { color: var(--foreground); background: var(--muted); }
.catalog-categories .switch-category.is-primary { background: var(--secondary); color: var(--foreground); font-weight: 600; border-color: var(--border); }
.catalog-categories .category-icon { width: 19px; height: 19px; border-radius: 4px; object-fit: contain; flex: 0 0 auto; }
.catalog-categories .category-label { overflow-wrap: anywhere; }
.catalog-categories .category-child { padding-left: 30px; font-size: 13px; }
.catalog-categories .category-child .category-icon { width: 16px; height: 16px; }
.catalog-results { grid-area: results; min-width: 0; }
.catalog-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 20px; min-height: 36px; }
.catalog-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 10px; min-width: 0; }
:root[data-app-theme] #catalog-title { font-size: 18px; line-height: 1.5; margin: 0; overflow-wrap: anywhere; }
#catalog-count { font-size: 12px; color: var(--muted-foreground); overflow-wrap: anywhere; }
.catalog-controls { display: flex; align-items: center; flex-shrink: 0; gap: 18px; }
.catalog-controls[hidden] { display: none; }
.catalog-stock { display: inline-flex; align-items: center; gap: 7px; margin: 0; font-size: 12px; color: var(--muted-foreground); cursor: pointer; white-space: nowrap; }
.catalog-stock input { width: 15px; height: 15px; margin: 0; accent-color: var(--primary); }
:root[data-app-theme] #catalog-sort { max-width: 172px; min-height: 36px; border: 1px solid var(--border); border-radius: 7px; padding: 6px 9px; background-color: var(--card); color: var(--foreground); font-size: 12px !important; cursor: pointer; }
.catalog-clear-search { padding: 7px 0; margin: -8px 0 14px; border: 0; background: none; color: var(--muted-foreground); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.catalog-clear-search[hidden] { display: none; }
.storefront .item-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin: 0; }
.storefront .item-list > * { min-width: 0; }
.storefront .product-card {
    display: flex; flex-direction: column; position: relative; min-width: 0; overflow: hidden;
    border: 1px solid var(--border); border-radius: 12px; color: var(--foreground); background: var(--card);
    transition: border-color .18s, box-shadow .18s, transform .18s;
}
.storefront .product-card:hover { border-color: var(--ring); box-shadow: var(--shadow-md); transform: translateY(-2px); color: var(--foreground); }
.product-media { min-width: 0; aspect-ratio: 16 / 10; position: relative; display: grid; place-items: center; overflow: hidden; background: var(--muted); border-bottom: 1px solid var(--border); }
.product-media img { display: block; position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--muted); transition: transform .24s; }
.product-media img.is-fallback-cover { object-fit: cover; }
.product-card:hover .product-media img { transform: scale(1.035); }
.product-media > svg, .product-cover-fallback, .product-cover-fallback svg { width: 40px; height: 40px; color: var(--muted-foreground); }
.product-recommend { position: absolute; top: 12px; left: 12px; padding: 3px 8px; font-size: 12px; border: 1px solid var(--border); border-radius: 5px; background: var(--card); color: var(--foreground); }
.product-body { display: flex; flex: 1; min-width: 0; flex-direction: column; gap: 10px; padding: 16px; }
.product-category { color: var(--muted-foreground); font-size: 12px; line-height: 1.4; }
.product-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.product-tags:empty { display: none; }
.product-tags .acg-tag, .product-tags .badge-soft { font-size: 12px; line-height: 1.5; padding: 2px 6px; margin: 0; }
.storefront .product-tags .acg-tag { color: var(--tag-ink, var(--foreground)); background: color-mix(in srgb, var(--tag-ink, var(--foreground)) 10%, var(--card)); }
.storefront .acg-tag--blue { --tag-ink: #1d4ed8; }
.storefront .acg-tag--green { --tag-ink: #166534; }
.storefront .acg-tag--red { --tag-ink: #b91c1c; }
.storefront .acg-tag--orange { --tag-ink: #9a3412; }
.storefront .acg-tag--purple { --tag-ink: #7e22ce; }
.storefront .acg-tag--cyan { --tag-ink: #155e75; }
.storefront .acg-tag--gray { --tag-ink: var(--muted-foreground); }
:root[data-theme="dark"] .storefront .acg-tag--blue { --tag-ink: #93c5fd; }
:root[data-theme="dark"] .storefront .acg-tag--green { --tag-ink: #86efac; }
:root[data-theme="dark"] .storefront .acg-tag--red { --tag-ink: #fca5a5; }
:root[data-theme="dark"] .storefront .acg-tag--orange { --tag-ink: #fdba74; }
:root[data-theme="dark"] .storefront .acg-tag--purple { --tag-ink: #d8b4fe; }
:root[data-theme="dark"] .storefront .acg-tag--cyan { --tag-ink: #67e8f9; }
:root[data-app-theme] .product-title { margin: 0; font-size: 15px; line-height: 1.55; font-weight: 600; overflow-wrap: anywhere; }
.product-delivery { font-size: 12px; color: var(--muted-foreground); }
.product-meta { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px 10px; font-size: 12px; line-height: 1.6; color: var(--muted-foreground); }
.product-meta > span:first-child { display: inline-flex; align-items: center; gap: 5px; }
.stock-dot { display: inline-block; width: 5px; height: 5px; border-radius: 50%; background: var(--md-success); }
.is-sold-out .stock-dot { background: var(--muted-foreground); }
.is-sold-out .product-media img { opacity: .6; }
.product-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-top: 4px; margin-top: auto; }
.product-purchase { display: flex; flex-direction: column; gap: 4px; }
.product-meta { padding-top: 10px; border-top: 1px solid var(--border); }
.product-price { display: flex; align-items: baseline; gap: 3px; color: var(--foreground); font-size: 22px; line-height: 1.3; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.product-price > span { font-size: 13px; font-weight: 500; letter-spacing: 0; }
.product-action { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border: 1px solid var(--border); border-radius: 50%; color: var(--muted-foreground); flex-shrink: 0; }
.product-action svg { width: 15px; height: 15px; }
.product-card:hover .product-action { color: var(--primary-foreground); background: var(--primary); border-color: var(--primary); }
.storefront .item-list.is-single { grid-template-columns: minmax(0, 760px); }
.item-list.is-single .product-card { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: stretch; }
/* Let the text set the row height without an image aspect ratio widening its grid track. */
.item-list.is-single .product-media { width: 100%; min-height: 280px; aspect-ratio: auto; height: auto; border-bottom: 0; border-right: 1px solid var(--border); }
.item-list.is-single .product-body { padding: 24px; gap: 14px; }
:root[data-app-theme] .item-list.is-single .product-title { font-size: 20px; line-height: 1.5; }
.item-list.is-single .product-price { font-size: 28px; }
.item-list.is-single .product-action { width: 36px; height: 36px; }
.catalog-state { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; min-height: 280px; padding: 36px 24px !important; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted-foreground); text-align: center; }
.catalog-state-icon, .catalog-state-icon svg { width: 36px; height: 36px; opacity: .65; }
.catalog-state p { margin: 0; max-width: 440px; overflow-wrap: anywhere; }
.catalog-state h3 { color: var(--foreground); margin: 0; }
.catalog-state button { margin-top: 4px; }
.product-skeleton { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; min-height: 280px; animation: catalog-pulse 1.5s ease-in-out infinite alternate; }
.skeleton-line { height: 12px; margin: 0 0 14px; background: var(--muted); border-radius: 4px; }
.skeleton-line.is-short { width: 45%; }
@keyframes catalog-pulse { to { opacity: .45; } }
.storefront :is(a, button, input, select):focus-visible { outline: 2px solid var(--ring); outline-offset: 3px; }

@media (max-width: 991px) {
    :root[data-app-theme] main.storefront { padding-top: 24px; }
    .catalog-layout { grid-template-columns: 160px minmax(0, 1fr); gap: 24px; }
    .storefront .item-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
    .catalog-toolbar { align-items: flex-start; flex-direction: column; }
    .catalog-controls { width: 100%; justify-content: space-between; }
}
@media (max-width: 767px) {
    :root[data-app-theme] main.storefront { padding: 20px 16px 44px; }
    html:has(.storefront) .shop-nav { gap: 8px; }
    .catalog-search { width: 100%; }
    :root[data-app-theme] .catalog-search input { font-size: 16px !important; }
    .catalog-layout, .storefront--compact .catalog-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "search" "categories" "results"; gap: 20px; }
    .catalog-sidebar { position: static; }
    :root[data-app-theme] .catalog-sidebar h2 { padding: 0; margin-bottom: 12px; }
    .catalog-categories { flex-direction: row; overflow-x: auto; overflow-y: hidden; max-height: none; gap: 8px; padding-bottom: 8px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
    .storefront--compact .catalog-categories { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; }
    .catalog-categories .switch-category { flex: 0 0 auto; min-height: 42px; padding: 9px 12px; border-color: var(--border); font-size: 13px; }
    .catalog-categories .category-label { white-space: nowrap; }
    .catalog-categories .category-child { padding-left: 12px; }
    .catalog-categories .category-child .category-label::before { content: '↳ '; opacity: .5; }
    .catalog-toolbar { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 14px; margin-bottom: 16px; }
    .catalog-heading { gap: 8px; }
    .catalog-controls { width: auto; gap: 12px; margin-left: auto; }
    :root[data-app-theme] #catalog-title { font-size: 16px; }
    .storefront .item-list { gap: 12px; }
    .product-body { padding: 12px; gap: 8px; }
    :root[data-app-theme] .product-title { font-size: 14px; }
    .product-price { font-size: 20px; }
    .product-media { aspect-ratio: 1.25; }
    .product-bottom { padding-top: 10px; }
    .catalog-state { min-height: 240px; }
    .item-list.is-single .product-card { display: flex; }
    .item-list.is-single .product-media { min-height: 0; aspect-ratio: 16 / 10; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
    .item-list.is-single .product-body { padding: 20px; gap: 14px; }
    :root[data-app-theme] .item-list.is-single .product-title { font-size: 18px; }
}
@media (max-width: 420px) {
    .catalog-controls { width: 100%; margin: 0; }
    .product-body { padding: 10px; }
    .product-price { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
    .storefront *, .storefront *::before, .storefront *::after { animation: none !important; transition: none !important; }
}
