:root {
  /* Telegram-driven tokens — overwritten at runtime from Telegram.WebApp.themeParams (see app.js applyTheme()) */
  --bg-color: #ffffff;
  --text-color: #14161a;
  --hint-color: #8b8f97;
  --link-color: #059669;
  --button-color: #059669;
  --button-text-color: #ffffff;
  --secondary-bg-color: #f4f5f7;
  --section-separator-color: #ececef;
  --destructive-color: #e5484d;

  /* Brand tokens — a deliberate identity layer independent of Telegram's theme,
     so the shop reads as its own product rather than "generic Telegram UI". */
  --brand: #059669;
  --brand-dark: #047857;
  --brand-soft: #e7f8f1;
  --brand-text-on-brand: #ffffff;

  --radius-xl: 22px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-card: 0 1px 2px rgba(20, 22, 26, 0.04), 0 6px 16px rgba(20, 22, 26, 0.06);
  --shadow-float: 0 4px 10px rgba(5, 150, 105, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-soft: rgba(5, 150, 105, 0.16);
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-color);
  color: var(--text-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

img {
  display: block;
}

/* --- Header --- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 16px;
  background: var(--bg-color);
  border-bottom: 1px solid var(--section-separator-color);
}

.app-header h1 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  border: none;
  background: var(--secondary-bg-color);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  font-size: 17px;
  line-height: 1;
  color: var(--text-color);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cart-icon-btn {
  font-size: 18px;
}

.cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--destructive-color);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-color);
}

.app-content {
  padding: 14px 16px calc(100px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.state-message {
  text-align: center;
  color: var(--hint-color);
  padding: 56px 16px;
  font-size: 15px;
}

/* --- Hero banner (catalog root) --- */

.hero-card {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: var(--brand-text-on-brand);
  border-radius: var(--radius-xl);
  padding: 22px 20px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-float);
}

.hero-card-title {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 6px;
}

.hero-card-subtitle {
  font-size: 14px;
  opacity: 0.92;
  margin: 0;
  line-height: 1.4;
}

/* --- Category chips --- */

.chip-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 18px;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--secondary-bg-color);
  color: var(--text-color);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.chip.chip-brand {
  background: var(--brand);
  color: var(--brand-text-on-brand);
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.section-title .section-title-hint {
  font-size: 12px;
  font-weight: 500;
  color: var(--hint-color);
}

/* --- Product grid --- */

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

.product-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: 1px solid var(--section-separator-color);
  box-shadow: var(--shadow-card);
  padding: 0;
  text-align: left;
  color: var(--text-color);
}

.product-card.out-of-stock {
  opacity: 0.5;
}

.product-card-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--secondary-bg-color) center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint-color);
  font-size: 30px;
}

.product-card-body {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.product-card-name {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
  min-height: 2.6em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-card-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.product-card-price {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--text-color);
  letter-spacing: -0.01em;
}

.product-card-stock {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--destructive-color);
}

.quick-add-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: none;
  background: var(--brand);
  color: var(--brand-text-on-brand);
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(5, 150, 105, 0.35);
}

.quick-add-btn:active {
  transform: scale(0.92);
}

.quick-add-btn.added {
  background: var(--text-color);
}

/* --- Product detail --- */

.product-detail-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-xl);
  background: var(--secondary-bg-color) center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint-color);
  font-size: 44px;
  margin-bottom: 18px;
}

.product-detail-name {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
}

.product-detail-price {
  font-size: 19px;
  font-weight: 800;
  color: var(--brand);
  margin: 0 0 14px;
}

.product-detail-description {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--hint-color);
  white-space: pre-wrap;
  margin: 0 0 16px;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--secondary-bg-color);
  border-radius: 999px;
  padding: 4px;
}

.stepper-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: var(--bg-color);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.stepper-value {
  min-width: 34px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}

.primary-btn {
  display: block;
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--brand-text-on-brand);
  font-size: 15.5px;
  font-weight: 700;
  box-shadow: var(--shadow-float);
}

.primary-btn:disabled {
  opacity: 0.5;
  box-shadow: none;
}

.secondary-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--section-separator-color);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-color);
  font-size: 15px;
  font-weight: 700;
  margin-top: 8px;
}

/* A fixed action bar pinned to the bottom of the screen — used on the product
   detail page (stepper + add-to-cart) and reused visually by .cart-summary. */
.sticky-actionbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg-color);
  border-top: 1px solid var(--section-separator-color);
}

.sticky-actionbar .primary-btn {
  flex: 1;
}

/* --- Cart --- */

.cart-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--section-separator-color);
}

.cart-item-image {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-md);
  background: var(--secondary-bg-color) center/cover no-repeat;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hint-color);
  font-size: 22px;
}

.cart-item-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cart-item-name {
  font-size: 14px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cart-item-price {
  font-size: 12.5px;
  color: var(--hint-color);
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}

.cart-item-controls .stepper {
  padding: 2px;
}

.cart-item-controls .stepper-btn {
  width: 28px;
  height: 28px;
  font-size: 15px;
}

.cart-item-controls .stepper-value {
  min-width: 26px;
  font-size: 14px;
}

.remove-btn {
  border: none;
  background: transparent;
  color: var(--destructive-color);
  font-size: 12.5px;
  font-weight: 600;
  padding: 4px 0;
  align-self: flex-start;
}

.cart-summary {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-color);
  border-top: 1px solid var(--section-separator-color);
}

.cart-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 14px;
  color: var(--hint-color);
  margin-bottom: 10px;
}

.cart-summary-row .total-value {
  font-weight: 800;
  font-size: 18px;
  color: var(--text-color);
}

/* --- Checkout form --- */

.form-field {
  margin-bottom: 14px;
}

.form-field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--hint-color);
  margin-bottom: 6px;
}

.form-field input,
.form-field textarea {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--section-separator-color);
  background: var(--secondary-bg-color);
  color: var(--text-color);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}

.form-field input:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--brand);
}

.order-success {
  text-align: center;
  padding: 40px 16px 16px;
}

.order-success .icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--brand-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
}

.order-success h2 {
  font-size: 19px;
  margin: 0 0 8px;
}

/* --- Toast --- */

#toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 100px;
  padding: 13px 16px;
  background: var(--text-color);
  color: var(--bg-color);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  z-index: 100;
  box-shadow: var(--shadow-card);
}
