:root {
  color-scheme: light;
  --bg: var(--tg-theme-bg-color, #f3f5f9);
  --panel: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #17212b);
  --muted: var(--tg-theme-hint-color, #75808d);
  --accent: var(--tg-theme-button-color, #7c3aed);
  --accent-2: #ff3d71;
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(23, 33, 43, 0.09);
  --shadow: 0 10px 28px rgba(20, 28, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 61, 113, 0.13), transparent 26rem),
    linear-gradient(180deg, #fbfcff 0%, var(--bg) 22rem);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

body.cart-open {
  overflow: hidden;
}

body.detail-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shop-header {
  display: none;
  padding: calc(8px + env(safe-area-inset-top)) 12px 6px;
  background: #fbfcff;
  border-bottom: 1px solid var(--line);
}

.header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-button {
  display: none;
  width: 100%;
  min-height: 48px;
  margin: 2px 0 10px;
  border: 0;
  border-radius: 10px;
  padding: 0 17px;
  background: linear-gradient(135deg, #17212b 0%, var(--accent) 100%);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 14px 30px rgba(20, 28, 40, 0.28);
}

.admin-button[hidden] {
  display: none;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.05;
  letter-spacing: 0;
}

.round-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  box-shadow: var(--shadow);
}

.search {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 10px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(20, 28, 40, 0.05);
}

.search-icon {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
}

.search input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.page {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 8px 12px 0;
}

.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 9px;
  scrollbar-width: none;
}

.categories::-webkit-scrollbar {
  display: none;
}

.category-chip {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(20, 28, 40, 0.05);
}

.category-chip.active {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
}

.promo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 86px;
  border-radius: 8px;
  padding: 16px;
  background: linear-gradient(135deg, #7c3aed 0%, #ff3d71 100%);
  color: #ffffff;
  cursor: pointer;
  box-shadow: var(--shadow);
}

.promo.active {
  outline: 0;
}

.promo p,
.promo strong {
  display: block;
  margin: 0;
}

.promo > div {
  min-width: 0;
}

.promo p {
  opacity: 0.86;
  font-size: 13px;
}

.promo strong {
  margin-top: 3px;
  font-size: 22px;
}

.promo-search {
  flex: 0 1 260px;
  width: min(260px, 48%);
  min-height: 40px;
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), 0 8px 22px rgba(33, 12, 68, 0.14);
  backdrop-filter: blur(10px);
}

.promo-search .search-icon,
.promo-search input {
  color: #ffffff;
}

.promo-search input::placeholder {
  color: rgba(255, 255, 255, 0.78);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 1px 10px;
}

.section-title h2 {
  margin: 0;
  font-size: 21px;
}

.section-title a {
  display: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
}

.status {
  padding: 28px 8px;
  color: var(--muted);
  text-align: center;
}

.status:empty {
  display: none;
}

.catalog {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.category-section {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.category-row-title {
  margin: 0 1px;
  color: var(--text);
  font-size: 19px;
  line-height: 1.2;
}

.product-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 44%;
  gap: 10px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 1px 9px;
  scroll-padding-inline: 1px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
}

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

.product-card {
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 9px 24px rgba(20, 28, 40, 0.07);
  cursor: pointer;
  scroll-snap-align: start;
}

.photo-wrap {
  position: relative;
  aspect-ratio: 1 / 1.02;
  background: linear-gradient(180deg, #eef2f7 0%, #e4e9f2 100%);
}

.photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.badge {
  position: absolute;
  left: 8px;
  top: 8px;
  max-width: calc(100% - 16px);
  border-radius: 999px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-nav {
  position: absolute;
  top: 50%;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(20, 28, 40, 0.14);
  transform: translateY(-50%);
}

.photo-nav[hidden],
.photo-dots[hidden] {
  display: none;
}

.photo-prev {
  left: 7px;
}

.photo-next {
  right: 7px;
}

.photo-dots {
  position: absolute;
  left: 50%;
  bottom: 8px;
  display: flex;
  gap: 4px;
  transform: translateX(-50%);
}

.photo-dots span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 0 1px 4px rgba(20, 28, 40, 0.2);
}

.photo-dots span.active {
  width: 15px;
  background: #ffffff;
}

.product-body {
  display: grid;
  gap: 7px;
  padding: 11px;
}

.category {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.product-card h3 {
  min-height: 38px;
  margin: 0;
  font-size: 15px;
  line-height: 1.32;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.description {
  min-height: 35px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-footer {
  display: grid;
  gap: 8px;
  margin-top: 2px;
}

.price {
  color: var(--text);
  font-size: 17px;
  line-height: 1.15;
}

.cart-button,
.submit-order {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 750;
  white-space: nowrap;
}

.product-footer .cart-button {
  width: 100%;
  min-width: 0;
}

.cart-button.added {
  background: #16a34a;
}

.product-detail {
  position: fixed;
  inset: 0;
  z-index: 45;
  pointer-events: none;
  visibility: hidden;
}

.product-detail.open {
  pointer-events: auto;
  visibility: visible;
}

.product-detail-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 28, 0.42);
  opacity: 0;
  transition: opacity 180ms ease;
}

.product-detail.open .product-detail-backdrop {
  opacity: 1;
}

.product-detail-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(90vh, 760px);
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  background: var(--panel);
  box-shadow: 0 -18px 44px rgba(20, 28, 40, 0.22);
  transform: translateY(100%);
  transition: transform 220ms ease;
}

.product-detail.open .product-detail-panel {
  transform: translateY(0);
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 34px;
  height: 34px;
  box-shadow: 0 8px 20px rgba(20, 28, 40, 0.18);
}

.detail-photo-wrap {
  position: relative;
  aspect-ratio: 1 / 0.86;
  background: linear-gradient(180deg, #eef2f7 0%, #e4e9f2 100%);
  cursor: pointer;
  user-select: none;
  touch-action: pan-y;
}

.detail-photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-body {
  display: grid;
  gap: 10px;
  padding: 14px 14px calc(16px + env(safe-area-inset-bottom));
}

.detail-body h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.18;
}

.detail-description {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.detail-footer {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  margin-top: 2px;
  padding-top: 10px;
  background: var(--panel);
}

.detail-price {
  color: var(--text);
  font-size: 22px;
  line-height: 1.1;
}

.detail-footer .cart-button {
  min-width: 132px;
  min-height: 42px;
}

.cart-bar {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 20;
}

.cart-fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #ffffff;
  box-shadow: 0 16px 34px rgba(78, 36, 138, 0.28);
  backdrop-filter: blur(16px);
}

.cart-fab:active {
  transform: translateY(1px) scale(0.98);
}

.cart-icon {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#cartSummary {
  position: absolute;
  top: -4px;
  right: -3px;
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  padding: 0 5px;
  background: #16a34a;
  color: #ffffff;
  font-size: 12px;
  line-height: 1;
  box-shadow: 0 7px 16px rgba(20, 28, 40, 0.22);
}

.cart-badge:empty,
.cart-badge.is-empty {
  display: none;
}

.cart-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  visibility: hidden;
}

.cart-drawer.open {
  pointer-events: auto;
  visibility: visible;
}

.cart-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 28, 0.38);
  opacity: 0;
  transition: opacity 180ms ease;
}

.cart-drawer.open .cart-backdrop {
  opacity: 1;
}

.cart-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(84vh, 680px);
  overflow-y: auto;
  border-radius: 16px 16px 0 0;
  padding: 12px 12px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  box-shadow: 0 -18px 44px rgba(20, 28, 40, 0.2);
  transform: translateY(100%);
  transition: transform 220ms ease;
}

.cart-drawer.open .cart-panel {
  transform: translateY(0);
}

.cart-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.cart-panel-header h2 {
  margin: 0;
  font-size: 22px;
}

.cart-items {
  display: grid;
  gap: 8px;
}

.cart-empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px 10px;
  background: var(--panel);
  color: var(--muted);
  text-align: center;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel);
}

.cart-item h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.25;
}

.cart-item-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.quantity-control {
  display: grid;
  grid-template-columns: 30px 26px 30px;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 2px;
  background: #f7f8fb;
}

.quantity-control button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
}

.quantity {
  display: grid;
  place-items: center;
  min-height: 30px;
  border-radius: 7px;
  background: #ffffff;
  color: #17212b;
  text-align: center;
  font-size: 14px;
  font-weight: 800;
}

.remove-button {
  grid-column: 1 / -1;
  justify-self: start;
  border: 0;
  background: transparent;
  color: var(--accent-2);
  padding: 0;
  font-size: 13px;
  font-weight: 650;
}

.cart-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 9px 0;
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--panel);
  box-shadow: 0 7px 22px rgba(20, 28, 40, 0.06);
}

.cart-total span {
  color: var(--muted);
}

.cart-total strong {
  font-size: 18px;
}

.order-form {
  display: grid;
  gap: 8px;
}

.checkout-back {
  margin: 0 0 10px;
  border: 0;
  padding: 4px 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 700;
}

.order-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.order-form input,
.order-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: var(--panel);
  color: var(--text);
  outline: 0;
  resize: vertical;
}

.order-form input:focus,
.order-form textarea:focus {
  border-color: rgba(124, 58, 237, 0.6);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.12);
}

.form-error {
  min-height: 18px;
  margin: 0;
  color: var(--accent-2);
  font-size: 13px;
}

.submit-order {
  width: 100%;
  min-height: 44px;
  font-size: 15px;
}

.submit-order:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 80;
  width: min(360px, calc(100% - 28px));
  border-radius: 8px;
  padding: 12px 14px;
  background: #17212b;
  color: #ffffff;
  text-align: center;
  box-shadow: 0 12px 32px rgba(20, 28, 40, 0.22);
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.admin-panel {
  position: fixed;
  inset: 0;
  z-index: 90;
  visibility: hidden;
  pointer-events: none;
}

.admin-panel.open {
  visibility: visible;
  pointer-events: auto;
}

.admin-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 28, 0.48);
  opacity: 0;
  transition: opacity 180ms ease;
}

.admin-panel.open .admin-backdrop { opacity: 1; }

.admin-sheet {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 14px 12px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  transform: translateY(100%);
  transition: transform 220ms ease;
}

.admin-panel.open .admin-sheet { transform: translateY(0); }

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.admin-header h2 { margin: 0; font-size: 22px; }
.admin-header .eyebrow { margin: 0 0 3px; }

.admin-product-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.admin-product-item {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: var(--panel);
}

.admin-product-item img {
  width: 58px;
  height: 58px;
  border-radius: 8px;
  object-fit: cover;
  background: #eef2f7;
}

.admin-product-info { min-width: 0; }
.admin-product-info strong { display: block; }
.admin-product-info p { margin: 3px 0 8px; color: var(--muted); font-size: 12px; }
.admin-product-actions { display: flex; gap: 7px; }
.admin-product-actions button { min-height: 32px; border: 0; border-radius: 7px; padding: 0 10px; font-weight: 700; }
.admin-edit { background: var(--accent); color: var(--accent-text); }
.admin-delete { background: #fee2e2; color: #b91c1c; }

.admin-form { display: grid; gap: 11px; }
.admin-form label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; }
.admin-form input, .admin-form textarea, .admin-form select { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 11px; background: var(--panel); color: var(--text); outline: 0; }
.admin-form input:focus, .admin-form textarea:focus, .admin-form select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 58, 237, .12); }
.admin-add-category { min-height: 40px; border: 1px dashed var(--accent); border-radius: 8px; background: rgba(124, 58, 237, .07); color: var(--accent); font-weight: 750; }
.new-category-box { display: grid; gap: 8px; border-radius: 9px; padding: 10px; background: rgba(124, 58, 237, .06); }
.new-category-box[hidden] { display: none; }
.new-category-actions { display: flex; gap: 8px; }
.new-category-actions button { min-height: 36px; border: 0; border-radius: 7px; padding: 0 14px; font-weight: 700; }
.admin-photo-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.admin-photo { position: relative; aspect-ratio: 1; }
.admin-photo img { width: 100%; height: 100%; border-radius: 8px; object-fit: cover; }
.admin-photo button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border: 0; border-radius: 50%; background: rgba(185,28,28,.9); color: white; }

@media (min-width: 700px) {
  .product-row {
    grid-auto-columns: 27%;
  }

  .cart-bar {
    right: calc((100% - min(980px, 100%)) / 2 + 16px);
  }

  .product-detail-panel {
    left: 50%;
    width: min(560px, 100%);
    border-radius: 18px 18px 0 0;
    transform: translate(-50%, 100%);
  }

  .product-detail.open .product-detail-panel {
    transform: translate(-50%, 0);
  }

  .cart-panel {
    left: 50%;
    width: min(520px, 100%);
    transform: translate(-50%, 100%);
    border-radius: 18px 18px 0 0;
  }

  .cart-drawer.open .cart-panel {
    transform: translate(-50%, 0);
  }
}

@media (max-width: 360px) {
  .promo {
    align-items: stretch;
    flex-direction: column;
  }

  .promo-search {
    width: 100%;
    flex-basis: auto;
  }

  .product-row {
    gap: 8px;
    grid-auto-columns: 46%;
  }

  .product-body {
    padding: 9px;
  }

  .product-footer .cart-button {
    font-size: 13px;
  }
}
