:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16181c);
  --hint: var(--tg-theme-hint-color, #8a8f98);
  --link: var(--tg-theme-link-color, #e0446f);
  --button: var(--tg-theme-button-color, #e0446f);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f7f7f9);
  --accent: #f4879e;
  --accent-light: #fde7ec;
  --star: #f5a623;
  --radius: 16px;
}

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

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}

.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.brand { font-size: 18px; font-weight: 800; letter-spacing: -0.3px; }
.topbar-icons { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  border: none;
  background: var(--secondary-bg);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}
.cart-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--link);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

#searchInput {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.08);
  font-size: 15px;
  background: var(--secondary-bg);
  color: var(--text);
}

.sort-toggle { display: flex; gap: 8px; }
.sort-btn {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 10px;
  background: var(--secondary-bg);
  color: var(--hint);
  font-size: 13px;
  font-weight: 700;
}
.sort-btn.active { background: var(--button); color: var(--button-text); }

.category-bar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 14px;
  background: var(--bg);
}
.category-chip {
  flex-shrink: 0;
  padding: 7px 15px;
  border-radius: 18px;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.category-chip.active { background: var(--button); color: var(--button-text); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 14px;
}

/* ---- Product Card (matches reference design) ---- */
.product-card {
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
}
.product-card .img-wrap {
  background: #fff;
  padding: 10px;
}
.product-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
}
.product-card .info { padding: 0 10px 12px; display: flex; flex-direction: column; gap: 5px; flex: 1; }

.stars { font-size: 11px; letter-spacing: 1px; color: var(--star); }
.stars .off { color: #e2e2e5; }

.product-card .name {
  font-size: 12.5px;
  font-weight: 800;
  text-transform: uppercase;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  letter-spacing: 0.2px;
}

.price-row { display: flex; align-items: baseline; gap: 6px; margin-top: 2px; }
.price-now { font-size: 15px; font-weight: 800; color: var(--link); }
.price-was { font-size: 12px; color: var(--hint); text-decoration: line-through; }

.stock-row {
  margin-top: 4px;
  font-size: 10px;
  color: var(--hint);
  display: flex;
  justify-content: space-between;
}
.stock-bar {
  height: 4px;
  background: var(--accent-light);
  border-radius: 2px;
  margin-top: 3px;
  overflow: hidden;
}
.stock-bar-fill { height: 100%; background: var(--accent); }

.add-cart-btn {
  margin-top: 8px;
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 9px 0;
  border-radius: 20px;
}
.add-cart-btn:active { opacity: 0.85; }

.loading, .empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--hint);
  padding: 40px 0;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--bg);
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 22px 16px 28px;
  position: relative;
}
.modal-content h3 { font-size: 17px; margin-bottom: 14px; }
.close-btn {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  font-size: 26px;
  color: var(--hint);
  line-height: 1;
}

.detail-images { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 14px; scroll-snap-type: x mandatory; }
.detail-images img {
  width: 84%;
  flex-shrink: 0;
  border-radius: 14px;
  aspect-ratio: 1/1;
  object-fit: contain;
  background: #fff;
  scroll-snap-align: start;
  border: 1px solid rgba(0,0,0,0.05);
}

.detail-name { font-size: 19px; font-weight: 800; margin-bottom: 4px; text-transform: uppercase; }
.detail-price-row { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.detail-price-now { font-size: 20px; font-weight: 800; color: var(--link); }
.detail-price-was { font-size: 15px; color: var(--hint); text-decoration: line-through; }
.detail-stars { margin-bottom: 10px; font-size: 14px; }
.detail-description { font-size: 14.5px; color: var(--text); line-height: 1.55; margin-bottom: 18px; white-space: pre-wrap; }
.detail-stock { font-size: 12px; color: var(--hint); margin-bottom: 18px; }

.order-btn, #submitOrderBtn, .add-cart-btn-lg {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--button);
  color: var(--button-text);
  font-size: 15.5px;
  font-weight: 800;
}
.add-cart-btn-lg { background: var(--accent); margin-bottom: 10px; }

/* Cart */
.cart-items { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.cart-item { display: flex; gap: 10px; align-items: center; }
.cart-item img { width: 54px; height: 54px; border-radius: 10px; object-fit: contain; background: #fff; border: 1px solid rgba(0,0,0,0.06); }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name { font-size: 13px; font-weight: 700; }
.cart-item-price { font-size: 12.5px; color: var(--hint); }
.qty-controls { display: flex; align-items: center; gap: 8px; }
.qty-controls button {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.1);
  background: var(--secondary-bg); font-size: 15px; font-weight: 700; color: var(--text);
}
.qty-controls span { font-size: 13px; font-weight: 700; min-width: 16px; text-align: center; }
.remove-item-btn { background: none; border: none; color: var(--hint); font-size: 18px; padding: 0 4px; }

.cart-footer { border-top: 1px solid rgba(0,0,0,0.07); padding-top: 14px; }
.cart-total-row { display: flex; justify-content: space-between; font-size: 16px; font-weight: 800; margin-bottom: 12px; }

.checkout-summary { background: var(--secondary-bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 13px; }
.checkout-summary .line { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--hint); }
.checkout-summary .total-line { display: flex; justify-content: space-between; font-weight: 800; color: var(--text); margin-top: 8px; padding-top: 8px; border-top: 1px dashed rgba(0,0,0,0.1); }

#orderForm { display: flex; flex-direction: column; gap: 10px; }
#orderForm label { font-size: 13px; color: var(--hint); }
#phoneInput {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  font-size: 15px;
  background: var(--secondary-bg);
  color: var(--text);
  margin-bottom: 8px;
}

.success-msg { text-align: center; padding: 20px 0; font-size: 15px; }
.hidden { display: none !important; }
