/* Витрина чайного магазина. Цвета берутся из темы Telegram с запасными значениями. */

:root {
  --bg: var(--tg-theme-bg-color, #f7f4ee);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #2c2418);
  --hint: var(--tg-theme-hint-color, #8a7f6d);
  --accent: var(--tg-theme-button-color, #5d8a4a);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #c0392b;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 90px;
}

.hidden { display: none !important; }
.muted { color: var(--hint); font-size: 14px; }

/* Шапка */
.header {
  padding: 14px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.header-title {
  font-size: 20px;
  font-weight: 700;
}

/* Категории */
.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px 12px;
  scrollbar-width: none;
}
.categories::-webkit-scrollbar { display: none; }
.cat-chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 20px;
  border: none;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.cat-chip.active {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

/* Товары */
.products {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 4px 16px 16px;
}
.product {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.1s;
}
.product:active { transform: scale(0.97); }
.product-photo {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  background: linear-gradient(135deg, #e8ddc8, #d4e2c8);
  overflow: hidden;
}
.product-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.product-info { padding: 10px 12px 12px; }
.product-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-price {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}

/* Кнопки */
.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:disabled { opacity: 0.5; }
.btn-secondary {
  padding: 10px 14px;
  border: none;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

/* Нижняя панель корзины */
.cart-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
  z-index: 20;
}

/* Корзина */
#cart-items { padding: 8px 16px; }
.cart-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}
.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; font-size: 14px; }
.cart-item-price { color: var(--hint); font-size: 13px; margin-top: 2px; }
.cart-qty {
  display: flex;
  align-items: center;
  gap: 10px;
}
.cart-qty button {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.empty { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }

/* Форма */
.form { padding: 8px 16px 16px; }
.form label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
}
.form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.form input:focus { border-color: var(--accent); }

.delivery-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.toggle {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}
.toggle.active {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.promo-row { display: flex; gap: 8px; margin-top: 6px; }
.promo-row input { flex: 1; margin-top: 0; }
.promo-result {
  margin: -6px 0 14px;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--card);
}
.promo-result.ok { color: var(--accent); }
.promo-result.err { color: var(--danger); }

.totals {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 14px;
  line-height: 1.8;
}
.totals .grand {
  font-size: 17px;
  font-weight: 700;
  border-top: 1px solid var(--bg);
  padding-top: 8px;
  margin-top: 6px;
}
.totals .discount { color: var(--accent); }

/* Модалка товара */
.modal { position: fixed; inset: 0; z-index: 50; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.modal-card {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  animation: slide-up 0.25s ease;
}
@keyframes slide-up {
  from { transform: translateY(40%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-photo {
  height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 90px;
  background: linear-gradient(135deg, #e8ddc8, #d4e2c8);
  overflow: hidden;
}
.modal-photo img { width: 100%; height: 100%; object-fit: cover; }
.modal-body { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
.modal-body h3 { font-size: 18px; margin-bottom: 6px; }
.modal-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin: 12px 0;
}
.qty-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 14px;
  font-size: 18px;
  font-weight: 600;
}
.qty-row button {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  font-size: 18px;
  cursor: pointer;
}

/* Успех */
.success { text-align: center; padding: 70px 24px; }
.success-icon { font-size: 64px; margin-bottom: 16px; }
.success h2 { margin-bottom: 8px; }
.success p { margin-bottom: 8px; }
.success .btn-primary { margin-top: 24px; max-width: 280px; }

/* Загрузка */
.loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 17px;
  z-index: 100;
}
