:root {
  --theme-primary: #166534;
  --theme-primary-hover: #124a29;
  --theme-primary-soft: #eaf5ee;
  --theme-page: #f5f7f5;
  --theme-surface: #ffffff;
  --theme-text: #172b22;
  --theme-muted: #65736c;
  --theme-subtle: #7a8a82;
  --theme-border: #dce5df;
  --theme-danger: #c43d3d;
  --theme-warning: #d6a72c;
  --theme-success: #2f9562;
  --theme-radius-control: 6px;
  --theme-radius-card: 8px;
  --theme-control-height: 48px;
  --theme-shadow: 0 10px 28px rgba(25, 55, 42, .08);
  --theme-font: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  min-width: 320px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  font-family: var(--theme-font);
  color: var(--theme-text);
  background: var(--theme-page);
}
body {
  min-width: 320px;
  margin: 0;
  font-family: var(--theme-font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--theme-text);
  background: var(--theme-page);
}
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { color: inherit; cursor: pointer; transition: color .2s, background-color .2s, border-color .2s, box-shadow .2s, transform .2s; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
input, select, textarea { transition: border-color .2s, box-shadow .2s, background-color .2s; }
:focus-visible { outline: 3px solid rgba(47, 149, 98, .22); outline-offset: 2px; }

.navbar {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  border-top: 3px solid var(--theme-primary);
  border-bottom: 1px solid var(--theme-border);
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 4px 18px rgba(24, 61, 44, .06);
}
.nav-container {
  width: calc(100% - 20px);
  margin: 0 auto;
  padding: 10px 0 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}
.nav-left { min-width: 0; display: flex; align-items: center; gap: 9px; }
.nav-logo { width: 36px; height: 36px; flex: 0 0 36px; border-radius: var(--theme-radius-control); object-fit: cover; }
.nav-title { margin: 0; font-size: 16px; font-weight: 800; white-space: nowrap; }
.nav-links { justify-self: end; display: flex; align-items: center; gap: 2px; padding-left: 10px; border-left: 1px solid var(--theme-border); }
.nav-link { display: inline-flex; align-items: center; min-height: 34px; padding: 6px 8px; border-radius: 5px; font-size: 12px; font-weight: 700; }
.nav-support { gap: 7px; }
.nav-support svg { width: 17px; height: 17px; color: #229ed9; }

.nav-search-container { position: relative; grid-column: 1 / -1; grid-row: 2; }
.search-box {
  width: 100%;
  height: 44px;
  padding: 10px 14px 10px 42px;
  border: 1px solid #cfdad4;
  border-radius: 6px;
  background: #f8faf9;

  font-size: 16px;
}
.search-box:focus { outline: 0; border-color: var(--theme-primary); background: #fff; }
.search-icon { position: absolute; top: 50%; left: 14px; z-index: 1; width: 16px; height: 16px; font-size: 0; color: #718078; transform: translateY(-50%); }
.search-icon::before { content: ""; position: absolute; inset: 0 4px 4px 0; border: 2px solid currentColor; border-radius: 50%; }
.search-icon::after { content: ""; position: absolute; right: 0; bottom: 1px; width: 7px; height: 2px; background: currentColor; transform: rotate(45deg); transform-origin: right center; }

.container { width: calc(100% - 20px); margin: 0 auto; padding: 12px 0 36px; }
.catalog-shell { scroll-margin-top: 110px; }

.catalog-categories { padding: 16px 14px 0; border: 1px solid var(--theme-border); border-radius: 8px 8px 0 0; background: #fff; }
.category-title-row { margin-bottom: 10px; display: flex; align-items: center; gap: 16px; }
.category-title-row h2 { margin: 0; font-size: 15px; }
.categories { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.category-btn {
  min-height: 38px;
  min-width: 0;
  padding: 8px 14px;
  border: 1px solid #dce5df;
  border-radius: 5px;
  color: #59665f;
  background: #f8faf9;
  font-size: 12px;
  text-align: center;
  overflow-wrap: anywhere;
}
.category-btn:hover { color: var(--theme-primary-hover); border-color: #bfd7c8; background: var(--theme-primary-soft); }
.category-btn.active { color: #fff; border-color: var(--theme-primary); background: var(--theme-primary); }

.categories.collapsed .category-btn:nth-child(n + 13) { display: none; }

.categories-toggle {
  width: 100%;
  min-height: 36px;
  margin: 10px 0 12px;
  padding: 6px 12px;
  border: 1px dashed #cfdad4;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--theme-primary);
  background: #f8faf9;
  font-size: 12px;
  font-weight: 700;
}
.categories-toggle:hover { border-color: var(--theme-primary); background: var(--theme-primary-soft); }
.categories-toggle::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .2s;
}
.categories-toggle.expanded::after { transform: rotate(-135deg) translate(-2px, -2px); }

.catalog-heading {
  margin: 0;
  padding: 18px 14px 14px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-right: 1px solid var(--theme-border);
  border-left: 1px solid var(--theme-border);
  background: #f7f9f8;
}
.catalog-heading h2 { margin: 0; font-size: 20px; }
.result-count { margin-top: 4px; display: block; color: var(--theme-muted); font-size: 13px; }
.sort-select { min-width: 124px; width: 124px; min-height: 38px; padding: 0 10px; border: 1px solid var(--theme-border); border-radius: 6px; color: var(--theme-text); background: #fff; font-size: 12px; }

.catalog-main {
  padding: 0 14px 20px;
  border: 1px solid var(--theme-border);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: #f7f9f8;
}
.products { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.empty-state { grid-column: 1 / -1; padding: 30px; color: var(--theme-subtle); text-align: center; }

.product-card {
  position: relative;
  min-width: 0;
  min-height: 282px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #dce5df;
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 3px 12px rgba(24, 70, 49, .06);
  transition: box-shadow .3s;
}
.product-card:active { box-shadow: 0 8px 18px rgba(24, 70, 49, .14); }
.product-image-container {
  position: relative;
  flex: 0 0 138px;
  width: 100%;
  height: 138px;
  padding: 18px;
  border-bottom: 1px solid #e7eee9;
  background: #f7f9f8;
}
.product-image { width: 100%; height: 100%; border-radius: 5px; object-fit: contain; background: #f1f3f5; }
.product-category-label {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1;
  max-width: calc(100% - 20px);
  padding: 4px 7px;
  overflow: hidden;
  border-radius: 4px;
  color: #885414;
  background: #fff2df;
  font-size: 10px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.product-info { width: 100%; flex: 1; min-width: 0; padding: 11px; display: flex; flex-direction: column; }
.product-name {
  min-height: 40px;
  margin-bottom: 10px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.product-commerce { margin-bottom: 10px; display: flex; align-items: flex-end; justify-content: space-between; gap: 5px; }
.product-price { color: var(--theme-danger); font-size: 16px; font-weight: 800; line-height: 1.2; }
.product-sales { color: var(--theme-muted); font-size: 9px; white-space: nowrap; }
.stock-container { margin-top: auto; }
.stock-text { margin-bottom: 5px; display: flex; justify-content: space-between; color: var(--theme-muted); font-size: 10px; }
.stock-progress { width: 100%; height: 4px; overflow: hidden; border-radius: 4px; background: #e7f0ea; }
.stock-bar { height: 100%; border-radius: inherit; background: var(--theme-success); transition: width .3s; }
.stock-bar.low-stock { background: var(--theme-danger); }
.stock-bar.medium-stock { background: var(--theme-warning); }

.store-footer { color: #d9e8df; background: #173b2d; }
.store-footer-inner { width: calc(100% - 32px); margin: 0 auto; padding: 28px 0; display: flex; flex-direction: column; align-items: flex-start; gap: 24px; }
.footer-brand { display: flex; align-items: center; gap: 12px; }
.footer-logo { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 8px; }
.footer-brand strong { color: #fff; font-size: 20px; }
.footer-brand p { margin: 7px 0 0; color: #afc8bb; font-size: 13px; }
.footer-links { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.footer-links a { color: #d9e8df; font-size: 13px; }
.footer-links a:hover { color: #fff; }
.footer-meta { padding: 15px 24px; border-top: 1px solid rgba(255, 255, 255, .1); color: #92ad9f; font-size: 12px; text-align: center; }

.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: var(--theme-primary);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  font-size: 20px;
}
.back-to-top:hover { background: var(--theme-primary-hover); }

.dialog-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(16, 49, 35, .42); }
.dialog { width: min(420px, 100%); padding: 24px 20px; border: 1px solid var(--theme-border); border-radius: var(--theme-radius-card); background: var(--theme-surface); box-shadow: 0 20px 50px rgba(11, 45, 31, .24); }
.dialog h2 { margin: 0 0 10px; color: var(--theme-text); font-size: 22px; }
.dialog p { margin: 0 0 20px; color: var(--theme-muted); font-size: 16px; line-height: 1.65; }
.dialog .primary-btn { min-height: var(--theme-control-height); padding: 0 22px; border: 0; border-radius: var(--theme-radius-control); display: inline-flex; align-items: center; justify-content: center; color: #fff; background: var(--theme-primary); font-weight: 700; }
.dialog .primary-btn:hover { background: var(--theme-primary-hover); }

@media (max-width: 360px) {
  .nav-title { font-size: 14px; }
  .nav-logo { width: 32px; height: 32px; flex-basis: 32px; }
  .catalog-heading h2 { font-size: 18px; }
  .sort-select { min-width: 110px; width: 110px; }
  .products { gap: 8px; }
  .product-card { min-height: 250px; }
  .product-image-container { flex-basis: 118px; height: 118px; padding: 14px; }
  .product-name { min-height: 36px; font-size: 12px; }
  .product-price { font-size: 15px; }
  .product-sales { display: none; }
}

@media (min-width: 769px) {
  .nav-container,
  .container,
  .store-footer-inner {
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
