:root {
  color-scheme: light dark;
  --tg-theme-bg-color: #f4f4f5;
  --tg-theme-secondary-bg-color: #ffffff;
  --tg-theme-text-color: #17181a;
  --tg-theme-hint-color: #7b7e84;
  --tg-theme-link-color: #2f80ed;
  --tg-theme-button-color: #3390ec;
  --tg-theme-button-text-color: #ffffff;
  --bg: var(--tg-theme-bg-color);
  --surface: var(--tg-theme-secondary-bg-color);
  --surface-raised: color-mix(in srgb, var(--surface) 92%, var(--text) 8%);
  --text: var(--tg-theme-text-color);
  --muted: var(--tg-theme-hint-color);
  --accent: var(--tg-theme-button-color);
  --accent-text: var(--tg-theme-button-text-color);
  --border: color-mix(in srgb, var(--muted) 22%, transparent);
  --accent-soft: color-mix(in srgb, var(--accent) 13%, var(--surface));
  --success: #2a9d68;
  --success-soft: color-mix(in srgb, var(--success) 13%, var(--surface));
  --danger: #e05252;
  --danger-soft: color-mix(in srgb, var(--danger) 12%, var(--surface));
  --warning: #d78a20;
  --radius-sm: 10px;
  --radius: 12px;
  --safe-top: max(12px, var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: max(12px, var(--tg-safe-area-inset-bottom, 0px));
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-width: 320px; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; }
.app-shell { width: min(100%, 800px); margin: 0 auto; min-height: 100vh; min-height: 100dvh; position: relative; }
.screen { min-height: 100vh; min-height: 100dvh; padding: var(--safe-top) 16px calc(88px + var(--safe-bottom)); animation: enter .18s ease-out; }
.screen.no-nav { padding-bottom: calc(24px + var(--safe-bottom)); }
@keyframes enter { from { opacity: .4; transform: translateY(3px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 52px; gap: 12px; }
.brand { min-width: 0; }
.brand h1, .page-title { margin: 0; font-size: 22px; line-height: 1.2; font-weight: 700; letter-spacing: -.3px; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--text); }
.icon-btn:active { background: var(--border); transform: scale(.96); }
.icon-btn svg, .nav-item svg, .search-icon, .small-icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.back-row { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.back-row .page-title { font-size: 20px; }

.search-box { height: 46px; display: flex; align-items: center; gap: 10px; background: var(--surface); border: 1px solid transparent; border-radius: var(--radius); padding: 0 13px; margin: 10px 0 16px; color: var(--muted); }
.search-box:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 16px; }
.search-box input::placeholder { color: var(--muted); }
.clear-btn { border: 0; background: var(--border); color: var(--muted); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin: 22px 0 12px; }
.section-head h2 { margin: 0; font-size: 18px; }
.section-head span { font-size: 13px; color: var(--muted); }

.product-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.product-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; overflow: hidden; min-width: 0; cursor: pointer; transition: transform .16s ease, border-color .16s ease; }
.product-card:active { transform: scale(.985); border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.product-card.out { opacity: .68; }
.product-media { aspect-ratio: 1; background-image: url('./assets/products.png'); background-size: 300% 200%; background-repeat: no-repeat; background-color: #edeff1; border-bottom: 1px solid var(--border); }
.sprite-0 { background-position: 0% 0%; } .sprite-1 { background-position: 50% 0%; } .sprite-2 { background-position: 100% 0%; }
.sprite-3 { background-position: 0% 100%; } .sprite-4 { background-position: 50% 100%; } .sprite-5 { background-position: 100% 100%; }
.product-info { padding: 10px 10px 12px; min-height: 126px; display: flex; flex-direction: column; }
.product-name { font-size: 15px; line-height: 1.25; font-weight: 600; margin: 0 0 7px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.price { font-size: 17px; line-height: 1.2; font-weight: 700; font-variant-numeric: tabular-nums; }
.wholesale { color: var(--accent); font-size: 13px; margin-top: 3px; }
.card-bottom { margin-top: auto; min-height: 36px; display: flex; align-items: end; justify-content: space-between; gap: 6px; }
.stock { font-size: 12px; color: var(--muted); }
.stock.low { color: var(--warning); } .stock.none { color: var(--danger); }
.add-btn { width: 36px; height: 36px; flex: none; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-text); font-size: 24px; line-height: 1; display: grid; place-items: center; cursor: pointer; }
.add-btn:disabled { background: var(--border); color: var(--muted); cursor: default; }
.mini-stepper { height: 36px; display: grid; grid-template-columns: 34px 28px 34px; align-items: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); overflow: hidden; font-weight: 700; }
.mini-stepper button { height: 36px; border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 21px; }
.mini-stepper span { text-align: center; font-size: 14px; color: var(--text); }

.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 800px); min-height: calc(64px + var(--safe-bottom)); padding: 5px 24px var(--safe-bottom); display: grid; grid-template-columns: repeat(3, 1fr); background: color-mix(in srgb, var(--surface) 95%, transparent); border-top: 1px solid var(--border); backdrop-filter: blur(14px); }
.nav-item { position: relative; min-height: 54px; border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; cursor: pointer; }
.nav-item.active { color: var(--accent); }
.cart-count { position: absolute; top: 2px; left: calc(50% + 7px); min-width: 18px; height: 18px; padding: 0 5px; background: var(--accent); color: var(--accent-text); border-radius: 9px; font-size: 11px; display: grid; place-items: center; border: 2px solid var(--surface); }

.detail-media { aspect-ratio: 1.35; margin: 4px -16px 0; background-image: url('./assets/products.png'); background-size: 300% 200%; background-repeat: no-repeat; background-color: #edeff1; border-block: 1px solid var(--border); }
.detail-body { padding-top: 18px; }
.detail-title { font-size: 22px; margin: 0 0 5px; }
.detail-price { font-size: 17px; font-weight: 600; }
.description { color: var(--muted); font-size: 15px; line-height: 1.45; margin: 12px 0 22px; }
.subheading { margin: 20px 0 10px; font-size: 17px; }
.tiers { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tier { min-height: 58px; display: grid; grid-template-columns: 54px 1fr auto; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.tier:last-child { border-bottom: 0; }
.tier.current { background: var(--accent-soft); }
.tier.next { background: color-mix(in srgb, var(--surface) 93%, var(--accent) 7%); }
.tier-label { font-size: 12px; color: var(--muted); }
.tier.current .tier-label { color: var(--accent); font-weight: 700; }
.tier-range { font-size: 14px; }
.tier-price { font-weight: 700; font-variant-numeric: tabular-nums; }
.qty-block { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.qty-selector { height: 48px; display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; background: var(--bg); border-radius: var(--radius-sm); overflow: hidden; }
.qty-selector button { height: 48px; border: 0; background: transparent; color: var(--accent); font-size: 25px; cursor: pointer; }
.qty-selector button:active { background: var(--accent-soft); }
.qty-selector strong { text-align: center; font-size: 18px; }
.price-calc { margin-top: 14px; display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.unit-calc { color: var(--muted); font-size: 14px; }
.total-label { font-size: 12px; color: var(--muted); text-align: right; }
.total-value { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.tier-note { margin-top: 12px; border-radius: 9px; padding: 10px 12px; font-size: 14px; background: var(--accent-soft); color: var(--text); }
.tier-note.success { background: var(--success-soft); color: var(--success); font-weight: 600; }

.primary-btn, .secondary-btn, .danger-btn { width: 100%; min-height: 48px; border-radius: var(--radius-sm); border: 0; padding: 11px 16px; font-weight: 650; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px; }
.primary-btn { background: var(--accent); color: var(--accent-text); }
.primary-btn:active { filter: brightness(.92); transform: scale(.995); }
.primary-btn:disabled { opacity: .45; cursor: default; }
.secondary-btn { background: var(--surface); color: var(--accent); border: 1px solid var(--border); }
.danger-btn { background: var(--danger-soft); color: var(--danger); }
.sticky-action { position: sticky; bottom: calc(8px + var(--safe-bottom)); z-index: 12; margin-top: 18px; background: color-mix(in srgb, var(--bg) 92%, transparent); padding-top: 8px; backdrop-filter: blur(10px); }

.cart-list { margin: 8px -16px 0; background: var(--surface); border-block: 1px solid var(--border); }
.cart-item { display: grid; grid-template-columns: 76px 1fr; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.cart-item:last-child { border-bottom: 0; }
.cart-thumb { width: 76px; aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--border); }
.cart-top { display: flex; justify-content: space-between; gap: 8px; }
.cart-name { font-size: 15px; font-weight: 650; }
.remove { border: 0; background: transparent; color: var(--muted); width: 32px; height: 32px; cursor: pointer; }
.cart-unit { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.cart-controls { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cart-line-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.summary { margin-top: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.summary-row { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 10px; font-size: 14px; }
.summary-row:last-child { margin-bottom: 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: 18px; font-weight: 750; }
.summary-row span:first-child { color: var(--muted); }

.empty-state, .error-state, .success-state { min-height: 65vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 28px 18px; }
.state-icon { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); background: var(--surface); margin-bottom: 18px; }
.state-icon svg { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.success-state .state-icon { background: var(--success-soft); color: var(--success); font-size: 32px; }
.empty-state h2, .error-state h2, .success-state h2 { margin: 0 0 8px; font-size: 21px; }
.empty-state p, .error-state p, .success-state p { margin: 0 0 22px; max-width: 330px; color: var(--muted); line-height: 1.45; }
.state-action { width: min(100%, 330px); }
.order-number { color: var(--text) !important; font-weight: 700; font-size: 17px; }

.form-section { margin: 16px 0 22px; }
.form-section h2 { font-size: 17px; margin: 0 0 10px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, .textarea, .select { width: 100%; min-height: 46px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); padding: 11px 12px; outline: 0; font-size: 16px; }
.textarea { min-height: 86px; resize: vertical; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.radio-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.radio-option { min-height: 54px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); cursor: pointer; }
.radio-option:last-child { border-bottom: 0; }
.radio-option input { width: 20px; height: 20px; accent-color: var(--accent); }
.notice { font-size: 13px; color: var(--muted); line-height: 1.4; padding: 11px 12px; background: var(--surface); border-radius: 10px; border: 1px solid var(--border); }

.confirm-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.confirm-card h2 { margin: 0 0 14px; font-size: 18px; }
.confirm-total { padding: 15px 0; margin: 14px 0; border-block: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.confirm-total strong { font-size: 22px; }
.meta-row { display: grid; grid-template-columns: 105px 1fr; gap: 12px; font-size: 14px; margin: 10px 0; }
.meta-row span:first-child { color: var(--muted); }

.admin-toolbar { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.admin-toolbar .search-box { margin: 10px 0; }
.admin-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.admin-row { display: grid; grid-template-columns: 56px 1fr 44px; gap: 11px; padding: 10px; align-items: center; border-bottom: 1px solid var(--border); }
.admin-row:last-child { border-bottom: 0; }
.admin-thumb { width: 56px; aspect-ratio: 1; border-radius: 9px; border: 1px solid var(--border); }
.admin-title { font-size: 14px; font-weight: 650; }
.admin-meta { font-size: 13px; color: var(--muted); margin-top: 3px; }
.upload-box { height: 150px; border: 1.5px dashed var(--border); background: var(--surface); border-radius: var(--radius); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); cursor: pointer; }
.upload-box svg { width: 30px; height: 30px; stroke: currentColor; fill: none; }
.tier-editor { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.tier-editor-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 14px; font-weight: 650; }
.tier-fields { display: grid; grid-template-columns: 1fr 1.25fr; gap: 10px; }
.preview-box { background: var(--accent-soft); border-radius: var(--radius); padding: 13px; font-size: 14px; line-height: 1.65; }
.category-row { min-height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; border-bottom: 1px solid var(--border); }
.category-row:last-child { border-bottom: 0; }
.drag { color: var(--muted); letter-spacing: -2px; margin-right: 10px; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.28); display: flex; align-items: end; justify-content: center; animation: fade .16s ease; }
.sheet { width: min(100%, 800px); max-height: 82vh; overflow: auto; padding: 10px 16px calc(18px + var(--safe-bottom)); background: var(--surface); border-radius: 16px 16px 0 0; animation: up .2s ease-out; }
.sheet-handle { width: 38px; height: 4px; border-radius: 2px; background: var(--border); margin: 0 auto 15px; }
.sheet h2 { margin: 0 0 14px; font-size: 19px; }
.menu-btn { width: 100%; min-height: 48px; display: flex; align-items: center; gap: 12px; border: 0; border-bottom: 1px solid var(--border); background: transparent; text-align: left; cursor: pointer; }
.menu-btn:last-child { border-bottom: 0; }
.menu-btn.danger { color: var(--danger); }
@keyframes fade { from { opacity: 0; } } @keyframes up { from { transform: translateY(18px); } }
.toast-root { position: fixed; z-index: 60; left: 50%; bottom: calc(82px + var(--safe-bottom)); transform: translateX(-50%); width: min(calc(100% - 32px), 420px); pointer-events: none; }
.toast { background: color-mix(in srgb, var(--text) 92%, transparent); color: var(--bg); padding: 12px 14px; border-radius: 10px; font-size: 14px; text-align: center; animation: toast .2s ease; }
@keyframes toast { from { opacity: 0; transform: translateY(8px); } }

.skeleton { position: relative; overflow: hidden; background: var(--border); border-radius: 8px; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 72%, transparent), transparent); animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-search { height: 46px; margin: 12px 0 16px; }.sk-chips { display: flex; gap: 8px; }.sk-chip { width: 76px; height: 36px; border-radius: 18px; }.sk-card { height: 274px; border-radius: 13px; }

@media (min-width: 620px) {
  .screen { padding-inline: 24px; }
  .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .chips { margin-inline: -24px; padding-inline: 24px; }
  .detail-media { margin-inline: 0; border: 1px solid var(--border); border-radius: 14px; }
  .cart-list { margin-inline: 0; border: 1px solid var(--border); border-radius: var(--radius); }
}
@media (min-width: 760px) { .product-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 350px) { .product-grid { gap: 8px; }.product-info { padding-inline: 8px; }.mini-stepper { grid-template-columns: 30px 24px 30px; } }
