:root {
  --accent: #a8734a;
  --accent-dark: #8b5e3c;
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1c1c1c);
  --hint: var(--tg-theme-hint-color, #8a8a8a);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f5f2ee);
  --border: #e7e1da;
}

* { box-sizing: border-box; }

/*
 * Мобильный Telegram (Android/iOS WebView) не наследует шрифт и рисует свой
 * нативный внешний вид у <button>/<input> поверх наших стилей, если не
 * сбросить appearance явно. В десктопном браузере (Telegram Web / Chrome)
 * этого не видно — там UA-стили уже нормализованы, поэтому там всё выглядело
 * нормально, а в самом приложении кнопки/чипы смотрелись "как на старом сайте".
 */
button, input, select {
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 0;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 24px;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.topbar__title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

.cart-btn {
  position: relative;
  border: none;
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 18px;
  cursor: pointer;
}

.cart-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent-dark);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.search-row {
  padding: 10px 16px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
}

.category-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 16px 12px;
  scrollbar-width: none;
}

.category-row::-webkit-scrollbar { display: none; }

/* На компьютере (мышь, есть hover) показываем тонкий скроллбар на горизонтальных
   лентах — иначе на десктопе непонятно, что категории/полки вообще листаются
   (свайпа нет, а колесо мыши по умолчанию крутит только страницу вниз). */
@media (hover: hover) and (pointer: fine) {
  .category-row,
  .featured-shelf__row {
    scrollbar-width: thin;
  }
  .category-row::-webkit-scrollbar,
  .featured-shelf__row::-webkit-scrollbar {
    display: block;
    height: 6px;
  }
  .category-row::-webkit-scrollbar-thumb,
  .featured-shelf__row::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
  }
}

.category-chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.category-chip.active {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #fff;
}

.featured-shelf {
  padding: 4px 0 12px;
}

.featured-shelf__title {
  margin: 0;
  padding: 0 16px 8px;
  font-size: 15px;
  font-weight: 700;
}

.featured-shelf__row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 0 16px 4px;
  scrollbar-width: none;
}

.featured-shelf__row::-webkit-scrollbar { display: none; }

.shelf-card {
  flex: 0 0 auto;
  width: 128px;
  background: var(--secondary-bg);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
}

.shelf-card__img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #eee;
}

.shelf-card__name {
  padding: 8px 8px 2px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.shelf-card__price {
  padding: 0 8px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-dark);
}

.price-old {
  text-decoration: line-through;
  color: var(--hint);
  font-size: 12px;
  font-weight: 500;
  margin-right: 6px;
}

.price-new {
  color: #c0392b;
}

.catalog {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 4px 16px 16px;
}

.state-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--hint);
  padding: 32px 0;
}

.product-card {
  background: var(--secondary-bg);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  border: 1px solid var(--border);
}

.product-card__img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #eee;
}

.product-card__body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.product-card__name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.product-card__price {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-top: auto;
}

.product-card__stock {
  font-size: 12px;
  color: var(--hint);
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  padding: 4px 16px 20px;
}

.load-more-btn {
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.sheet[hidden] { display: none; }

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  padding: 20px 16px 28px;
}

.sheet__close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: var(--secondary-bg);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 14px;
  cursor: pointer;
}

.sheet__title {
  margin: 0 0 12px;
  font-size: 18px;
}

.pd-img {
  width: 100%;
  border-radius: 14px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: #eee;
  margin-bottom: 12px;
}

.pd-name {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 6px;
}

.pd-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-bottom: 10px;
}

.pd-desc {
  font-size: 14px;
  color: var(--text);
  opacity: 0.85;
  line-height: 1.5;
  margin-bottom: 16px;
}

.pd-add {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--accent-dark);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.pd-add:disabled {
  background: var(--hint);
  cursor: not-allowed;
}

.cart-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item__name {
  flex: 1;
  font-size: 14px;
}

.cart-item__qty {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  font-size: 14px;
  cursor: pointer;
}

.cart-item__price {
  font-size: 14px;
  font-weight: 700;
  min-width: 64px;
  text-align: right;
}

.cart-total {
  margin-top: 14px;
  font-size: 16px;
  font-weight: 700;
  text-align: right;
}

.checkout-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cf-input {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 15px;
}

.cf-submit {
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--accent-dark);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.cf-submit:disabled {
  background: var(--hint);
  cursor: not-allowed;
}

.pay-now-btn {
  width: 100%;
  margin-top: 12px;
  background: #2fa84f;
}

/* Подсказка под выбором способа получения (адрес самовывоза) */
.cf-note {
  margin-top: -4px;
  font-size: 13px;
  color: var(--hint);
}
.cf-input:disabled { opacity: 0.6; }

/* Экран после оформления заказа (оплата) */
.pay-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg, #fff);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  overflow-y: auto;
}
.pay-overlay__card { width: 100%; max-width: 380px; text-align: center; }
.pay-overlay__icon {
  width: 64px; height: 64px; margin: 0 auto 16px;
  border-radius: 50%; background: var(--secondary-bg);
  display: flex; align-items: center; justify-content: center; font-size: 32px;
}
.pay-overlay h2 { font-size: 20px; margin: 0 0 8px; }
.pay-overlay__sum { font-size: 16px; margin: 0 0 18px; }
.pay-overlay__pay { display: block; text-decoration: none; text-align: center; font-size: 17px; padding: 16px; }
.pay-overlay__hint { font-size: 13px; color: var(--hint); line-height: 1.5; margin: 14px 0 20px; }
.pay-overlay__back {
  width: 100%; padding: 13px; border-radius: 14px;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  font-size: 15px; cursor: pointer;
}
.pay-overlay__link {
  margin-top: 10px; background: none; border: none; color: var(--hint);
  font-size: 13px; text-decoration: underline; cursor: pointer;
}
