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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
  padding-bottom: 80px;
}

header {
  position: sticky;
  top: 0;
  background: var(--tg-theme-bg-color, #fff);
  border-bottom: 1px solid var(--tg-theme-hint-color, #ddd);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

header h1 { font-size: 17px; font-weight: 600; flex: 1; }

#back-btn {
  display: none;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--tg-theme-link-color, #2481cc);
  padding: 0 6px 0 0;
}

/* ── Views ── */
.view { display: none; padding: 12px 16px; }
.view.active { display: block; }

/* ── Category list ── */
.category-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.category-card {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 14px;
  padding: 20px 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: opacity 0.15s;
}

.category-card:active { opacity: 0.6; }

/* ── Item list ── */
.item-list { display: flex; flex-direction: column; gap: 10px; }

.item-card {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.item-info { flex: 1; }
.item-name { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.item-price { font-size: 14px; color: var(--tg-theme-link-color, #2481cc); font-weight: 600; }
.item-stock { font-size: 12px; color: var(--tg-theme-hint-color, #999); margin-top: 2px; }

.add-btn {
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.add-btn:active { opacity: 0.7; }
.add-btn:disabled { opacity: 0.35; cursor: default; }

/* ── Cart view ── */
.cart-list { display: flex; flex-direction: column; gap: 10px; }

.cart-item {
  background: var(--tg-theme-secondary-bg-color, #f4f4f5);
  border-radius: 14px;
  padding: 12px 14px;
}

.cart-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.cart-item-name { font-size: 15px; font-weight: 600; }
.cart-item-subtotal { font-size: 14px; color: var(--tg-theme-link-color, #2481cc); font-weight: 600; }

.cart-item-controls { display: flex; align-items: center; gap: 10px; }

.qty-btn {
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 8px;
  width: 30px;
  height: 30px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-label { font-size: 15px; font-weight: 600; min-width: 20px; text-align: center; }

.remove-btn {
  background: none;
  border: none;
  color: #ff3b30;
  font-size: 13px;
  cursor: pointer;
  margin-left: auto;
}

.cart-total {
  margin-top: 16px;
  font-size: 17px;
  font-weight: 700;
  text-align: right;
}

.empty-msg {
  text-align: center;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 60px;
  font-size: 15px;
}

/* ── Cart FAB ── */
#cart-fab {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 50px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: none;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  z-index: 20;
}

#cart-fab.visible { display: flex; }

#cart-fab-count {
  background: #ff3b30;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loading {
  text-align: center;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 60px;
  font-size: 15px;
}
