:root {
  color-scheme: light dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #111111);
}

.header {
  padding: 20px 16px 12px;
  text-align: center;
}

.header h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.header p {
  margin: 0;
  color: var(--tg-theme-hint-color, #8e8e93);
  font-size: 14px;
}

.search-wrap {
  padding: 0 16px 10px;
}

.search-wrap input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 14px;
  border-radius: 12px;
  border: none;
  background: var(--tg-theme-secondary-bg-color, #e5e5ea);
  color: var(--tg-theme-text-color, #111);
  font-size: 14px;
  outline: none;
}

.search-wrap input::placeholder {
  color: var(--tg-theme-hint-color, #8e8e93);
}

.categories {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 12px;
  scrollbar-width: none;
}
.categories::-webkit-scrollbar { display: none; }

.category-chip {
  flex: 0 0 auto;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--tg-theme-secondary-bg-color, #e5e5ea);
  color: var(--tg-theme-text-color, #111);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid transparent;
}

.category-chip.active {
  border-color: var(--tg-theme-button-color, #2481cc);
  font-weight: 600;
}

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

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

.card {
  background: var(--tg-theme-secondary-bg-color, #ffffff);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.card-img {
  aspect-ratio: 1 / 1;
  background: var(--tg-theme-bg-color, #eee);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.no-img {
  font-size: 36px;
  opacity: 0.4;
}

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

.card-category {
  font-size: 11px;
  color: var(--tg-theme-hint-color, #8e8e93);
}

.card-body h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
  min-height: 2.6em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-body .desc {
  margin: 0;
  font-size: 12px;
  color: var(--tg-theme-hint-color, #8e8e93);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

.price {
  font-weight: 700;
  font-size: 14px;
}

.card-footer button {
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #ffffff);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.card-footer button:active {
  opacity: 0.8;
}

.card-img, .card-body h3 {
  cursor: pointer;
}

/* ---- Modal (тафсилоти пурраи маҳсулот) ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.15s ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--tg-theme-bg-color, #ffffff);
  border-radius: 18px 18px 0 0;
  padding: 16px;
  box-sizing: border-box;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--tg-theme-secondary-bg-color, #e5e5ea);
  color: var(--tg-theme-text-color, #111);
  font-size: 16px;
  cursor: pointer;
  z-index: 2;
}

.modal-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 14px;
  overflow: hidden;
  background: var(--tg-theme-secondary-bg-color, #eee);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px;
}

.modal-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-category {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #8e8e93);
  margin-bottom: 4px;
}

.modal-id {
  font-size: 11px;
  color: var(--tg-theme-hint-color, #8e8e93);
  margin-bottom: 10px;
}

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

.modal .modal-desc {
  font-size: 14px;
  line-height: 1.5;
  color: var(--tg-theme-text-color, #111);
  margin: 0 0 14px;
  white-space: pre-wrap;
}

.modal .modal-link {
  display: block;
  font-size: 13px;
  color: var(--tg-theme-link-color, #2481cc);
  margin-bottom: 14px;
  word-break: break-all;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: var(--tg-theme-bg-color, #ffffff);
  padding-top: 8px;
}

.modal-footer .price {
  font-size: 20px;
  font-weight: 700;
}

.modal-footer button {
  border: none;
  border-radius: 12px;
  padding: 12px 20px;
  background: var(--tg-theme-button-color, #2481cc);
  color: var(--tg-theme-button-text-color, #ffffff);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.modal-footer button:active {
  opacity: 0.85;
}
