:root {
  --bg: #eef2f7;
  --card: #ffffff;
  --text: #171a21;
  --muted: #6b7280;
  --border: #d9dfeb;
  --chip: #f5f7fb;
  --chip-active: #111827;
  --chip-active-text: #ffffff;
  --primary: #2563eb;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.12);
  --radius-xl: 22px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  overflow-x: hidden;
}

body {
  min-height: 100vh;
}

.app-shell {
  width: min(100%, 760px);
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 14px 30px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 10px 6px 12px;
}

.brand-block {
  text-align: center;
}

.brand-title {
  font-size: clamp(24px, 5vw, 34px);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand-subtitle {
  font-size: 14px;
  color: var(--muted);
}

.build-badge {
  margin-top: 4px;
  font-size: 11px;
  color: #8b95a7;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.expand-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border: 1px solid var(--border);
  background: #ffffff;
  color: #334155;
  border-radius: 12px;
  width: 38px;
  height: 38px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.expand-btn.hidden {
  display: none;
}

.content {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.search-panel,
.product-card {
  background: var(--card);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  min-width: 0;
}

.search-panel {
  padding: 14px;
}

.toolbar-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 52px;
  gap: 10px;
  align-items: center;
}

.toolbar-row > * {
  min-width: 0;
}

.search-wrap {
  min-width: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 16px;
  height: 48px;
  font-size: 22px;
  cursor: pointer;
}

.search-wrap input,
.filters-grid select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  background: #fbfcff;
  border-radius: 16px;
  height: 48px;
  padding: 0 16px;
  font-size: 16px;
}

.filters-panel {
  margin-top: 12px;
}

.filters-panel.hidden,
.loading-row.hidden,
.empty-state.hidden,
.detail-panel.hidden,
.description.hidden {
  display: none;
}

.filters-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.filters-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.chips-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-top: 12px;
}

.chip {
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--chip);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
}

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

.results-meta {
  padding: 2px 4px;
  color: var(--muted);
  font-size: 14px;
}

.catalog {
  display: grid;
  gap: 16px;
}

.product-card {
  overflow: hidden;
}

.carousel {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: var(--carousel-height, min(calc(var(--app-vh) * 0.55), 56vw));
  min-height: 180px;
  max-height: 520px;
  padding: 10px;
  background: #f3f4f6;
  overflow: hidden;
  touch-action: pan-y;
  transition: height 240ms cubic-bezier(0.22, 1, 0.36, 1);
}

.main-photo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  opacity: 1;
  transform: scale(1);
  transition: opacity 180ms ease, transform 240ms ease;
}

.main-photo.is-loading {
  opacity: 0.3;
  transform: scale(0.985);
}

.main-photo.is-error {
  opacity: 0.75;
  filter: saturate(0.2);
}

.carousel.zoomed .main-photo {
  transform: scale(1.45);
  cursor: zoom-out;
}

.photo-index {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  background: rgba(17, 24, 39, 0.62);
  color: #ffffff;
  font-size: 12px;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
}

.photo-index.hidden {
  display: none;
}

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

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
}

.dot.active {
  background: #ffffff;
}

.card-body {
  padding: 16px;
}

.title-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.item-title {
  margin: 0;
  font-size: clamp(22px, 5vw, 31px);
  line-height: 1.08;
  letter-spacing: -0.03em;
  word-break: break-word;
}

.item-part {
  margin-top: 8px;
  font-size: 18px;
  font-weight: 600;
}

.item-meta {
  margin-top: 8px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

.item-price {
  margin-top: 12px;
  font-size: clamp(26px, 6vw, 34px);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.tag {
  padding: 8px 12px;
  border-radius: 999px;
  background: #f4f6fb;
  border: 1px solid var(--border);
  font-size: 13px;
}

.detail-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.detail-grid {
  display: grid;
  gap: 8px;
}

.detail-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  font-size: 14px;
}

.detail-key {
  color: var(--muted);
}

.description {
  margin-top: 12px;
  padding: 12px;
  background: #f9fbff;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
}

.actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
}

.manager-btn {
  background: #0f766e;
  color: #ffffff;
}

.btn {
  height: 46px;
  border: none;
  border-radius: 14px;
  padding: 0 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.secondary {
  background: #eef3ff;
  color: #1d4ed8;
}

.actions .btn {
  flex: 1;
  background: #eef3ff;
  color: #1d4ed8;
}

.loading-row,
.empty-state {
  text-align: center;
  padding: 24px 12px;
  color: var(--muted);
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px 10px 24px;
  }

  .search-panel {
    padding: 12px;
  }

  .toolbar-row {
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    gap: 8px;
  }

  .icon-btn,
  .search-wrap input {
    height: 44px;
  }

  .icon-btn {
    font-size: 20px;
    border-radius: 14px;
  }

  .search-wrap input {
    font-size: 15px;
    padding: 0 12px;
  }

  .chips-row {
    gap: 7px;
    padding-top: 10px;
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .chip {
    padding: 8px 11px;
    font-size: 13px;
  }

  .carousel {
    height: var(--carousel-height, min(calc(var(--app-vh) * 0.5), 72vw));
    min-height: 160px;
    max-height: 300px;
    padding: 8px;
  }

  .card-body {
    padding: 14px;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .btn.secondary,
  .btn.primary {
    width: min(92%, 340px);
  }

  .actions .btn {
    flex: none;
    height: 52px;
    border-radius: 16px;
    font-size: 19px;
  }

}


/* ===== Telegram Desktop / short viewport fixes ===== */
:root {
  --app-vh: 100vh;
}

body.telegram-desktop {
  background: linear-gradient(180deg, #f8fbff 0%, #edf3fa 100%);
}

body.telegram-desktop .app-shell {
  max-width: 1120px;
  padding: 20px 18px 28px;
}

body.telegram-desktop .topbar {
  justify-content: flex-start;
  padding: 8px 6px 14px;
}

body.telegram-desktop .brand-block {
  text-align: left;
}

body.telegram-desktop .expand-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

body.telegram-desktop .brand-title {
  font-size: clamp(32px, 4vw, 46px);
}

body.telegram-desktop .brand-subtitle {
  font-size: 15px;
}

body.telegram-desktop .content {
  gap: 16px;
}

body.telegram-desktop .search-panel {
  padding: 16px;
}

body.telegram-desktop .toolbar-row {
  grid-template-columns: 50px minmax(0, 1fr) 50px;
}

body.telegram-desktop .icon-btn,
body.telegram-desktop .search-wrap input,
body.telegram-desktop .filters-grid select {
  height: 50px;
}

body.telegram-desktop .filters-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

body.telegram-desktop .catalog {
  gap: 18px;
}

body.telegram-desktop .product-card {
  border-radius: 20px;
}

body.telegram-desktop .carousel {
  height: var(--carousel-height, min(calc(var(--app-vh) * 0.62), 44vw));
  min-height: 240px;
  max-height: 520px;
  border-radius: 20px;
  padding: 10px;
}

body.telegram-desktop .card-body {
  padding: 18px;
}

body.telegram-desktop .item-title {
  font-size: clamp(24px, 2.8vw, 34px);
}

body.telegram-desktop .item-part {
  font-size: 20px;
}

body.telegram-desktop .item-meta {
  font-size: 15px;
}

body.telegram-desktop .item-price {
  font-size: clamp(30px, 3.4vw, 40px);
}

body.telegram-desktop .detail-row {
  grid-template-columns: 160px 1fr;
}

body.telegram-desktop .actions {
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
}

body.telegram-desktop .btn.secondary {
  min-width: 164px;
}

body.telegram-desktop .actions .btn {
  flex: none;
  width: min(92%, 340px);
  height: 52px;
  border-radius: 16px;
  font-size: 19px;
}

body.telegram-mobile .app-shell {
  padding: 12px 10px 24px;
}

body.telegram-mobile .search-panel {
  padding: 12px;
}

@media (min-width: 900px) {
  body.telegram-desktop .product-card {
    display: grid;
    grid-template-columns: minmax(320px, 44%) 1fr;
  }

  body.telegram-desktop .carousel {
    border-radius: 20px 0 0 20px;
  }
}

@media (min-width: 561px) and (max-height: 820px) {
  body.telegram-desktop .app-shell {
    padding: 10px 10px 18px;
  }

  body.telegram-desktop .content {
    gap: 10px;
  }

  body.telegram-desktop .search-panel {
    padding: 10px;
  }

  body.telegram-desktop .toolbar-row {
    grid-template-columns: 44px 1fr 44px;
    gap: 8px;
  }

  body.telegram-desktop .icon-btn,
  body.telegram-desktop .search-wrap input,
  body.telegram-desktop .filters-grid select {
    height: 42px;
  }

  body.telegram-desktop .carousel {
    height: var(--carousel-height, min(calc(var(--app-vh) * 0.42), 52vw));
    min-height: 130px;
    max-height: 300px;
    padding: 6px;
  }

  body.telegram-desktop .card-body {
    padding: 12px;
  }

  body.telegram-desktop .item-title {
    font-size: clamp(18px, 3.2vw, 24px);
  }

  body.telegram-desktop .item-part {
    margin-top: 6px;
    font-size: 16px;
  }

  body.telegram-desktop .item-meta {
    margin-top: 6px;
    font-size: 13px;
  }

  body.telegram-desktop .item-price {
    margin-top: 8px;
    font-size: clamp(22px, 3.4vw, 28px);
  }

  body.telegram-desktop .tags {
    margin-top: 10px;
    gap: 6px;
  }

  body.telegram-desktop .tag {
    padding: 6px 10px;
    font-size: 12px;
  }

  body.telegram-desktop .actions {
    margin-top: 12px;
    gap: 8px;
  }

  body.telegram-desktop .btn {
    height: 40px;
    font-size: 14px;
  }
}
