:root {
  --bg: #edf2f7;
  --surface: #ffffff;
  --text: #101725;
  --muted: #607084;
  --line: #d8e2ee;
  --accent: #15528b;
  --accent-soft: #e7f0fb;
  --ok: #1f7f50;
  --ok-soft: #e9f8ef;
  --warn: #8b3a29;
  --warn-soft: #fbeeea;
  --card-bg: #ffffff;
  --card-border: #dbe5ef;
  --card-title: #2a3b51;
  --card-price: #152f4e;
  --card-muted: #7f90a5;
  --card-fallback-bg: #eef3f8;
  --card-shadow: 0 1px 3px rgba(15, 35, 60, 0.08);
  --product-title: #1a2e47;
  --product-meta: #637488;
  --product-price: #15385f;
  --product-extra: #506179;
  --product-description: #253449;
  --product-badge-bg: #e7f6ee;
  --product-badge-text: #1f7f50;
  --product-badge-border: #bfe1ce;
  --product-hero-fallback: #8fa3b8;
  --product-thumb-bg: #f6fbff;
  --product-thumb-border: #c8d9ea;
  --order-btn-bg: #1e5f99;
  --order-btn-bg-hover: #184f81;
  --order-btn-text: #ffffff;
  --order-btn-shadow: 0 2px 6px rgba(16, 45, 76, 0.24);
  --tg-safe-top: 0px;
  --tg-safe-bottom: 0px;
  --safe-top: max(env(safe-area-inset-top), var(--tg-safe-top));
  --safe-bottom: max(env(safe-area-inset-bottom), var(--tg-safe-bottom));
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
}

body.is-telegram {
  background: var(--bg);
}

body.theme-light {
  --card-bg: #ffffff;
  --card-border: #dbe5ef;
  --card-title: #2a3b51;
  --card-price: #152f4e;
  --card-muted: #7f90a5;
  --card-fallback-bg: #eef3f8;
  --card-shadow: 0 1px 3px rgba(15, 35, 60, 0.08);
  --product-title: #1a2e47;
  --product-meta: #637488;
  --product-price: #15385f;
  --product-extra: #506179;
  --product-description: #253449;
  --product-badge-bg: #e7f6ee;
  --product-badge-text: #1f7f50;
  --product-badge-border: #bfe1ce;
  --product-hero-fallback: #8fa3b8;
  --product-thumb-bg: #f6fbff;
  --product-thumb-border: #c8d9ea;
  --order-btn-bg: #1e5f99;
  --order-btn-bg-hover: #184f81;
  --order-btn-text: #ffffff;
  --order-btn-shadow: 0 2px 6px rgba(16, 45, 76, 0.24);
}

body.theme-dark {
  --card-bg: #242a33;
  --card-border: #363f4c;
  --card-title: #e8edf4;
  --card-price: #f7fbff;
  --card-muted: #9da8b8;
  --card-fallback-bg: #2e3642;
  --card-shadow: 0 1px 4px rgba(2, 6, 11, 0.45);
  --product-title: #eef3fa;
  --product-meta: #a9b5c6;
  --product-price: #f8fbff;
  --product-extra: #bcc6d5;
  --product-description: #d8e0eb;
  --product-badge-bg: #21553a;
  --product-badge-text: #e7fff1;
  --product-badge-border: #2f6d4d;
  --product-hero-fallback: #a0acc0;
  --product-thumb-bg: #303947;
  --product-thumb-border: #445164;
  --order-btn-bg: #2f7fd3;
  --order-btn-bg-hover: #3b8ee3;
  --order-btn-text: #f7fbff;
  --order-btn-shadow: 0 2px 8px rgba(4, 16, 30, 0.5);
}

body.is-modal-open,
body.is-viewer-open,
body.is-sheet-open {
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.miniapp-shell {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: calc(6px + var(--safe-top)) 10px calc(16px + var(--safe-bottom));
}

.miniapp-head {
  margin-bottom: 8px;
}

.miniapp-brand {
  margin: 0 0 1px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.miniapp-head h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.catalog-topbar {
  margin-bottom: 10px;
}

.catalog-search {
  position: relative;
  display: block;
  margin-bottom: 8px;
}

.catalog-search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: #7a8ca3;
  font-size: 14px;
  pointer-events: none;
}

.catalog-search input {
  width: 100%;
  height: 38px;
  border: 1px solid #cfd9e6;
  border-radius: 12px;
  padding: 0 12px 0 30px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
}

.catalog-search input:focus {
  outline: 2px solid rgba(21, 82, 139, 0.18);
  border-color: rgba(21, 82, 139, 0.36);
}

.catalog-filters-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 1px 0 3px;
  scrollbar-width: none;
}

.catalog-filters-row::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  flex: 0 0 auto;
  height: 32px;
  max-width: 48vw;
  border: 1px solid #cfd9e6;
  border-radius: 999px;
  background: #fff;
  color: #2d3f55;
  font-size: 13px;
  font-weight: 600;
  padding: 0 12px;
  line-height: 30px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.filter-pill.is-active {
  border-color: color-mix(in srgb, var(--accent) 56%, #b8cce1 44%);
  background: color-mix(in srgb, var(--accent-soft) 65%, #ffffff 35%);
  color: #11385f;
}

.filter-pill:active {
  transform: scale(0.985);
}

.filter-pill:focus-visible {
  outline: 2px solid rgba(21, 82, 139, 0.24);
  outline-offset: 1px;
}

.miniapp-meta {
  margin-bottom: 10px;
}

#catalogSummary {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.catalog-card {
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: var(--card-bg);
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px;
  cursor: pointer;
  min-width: 0;
  box-shadow: var(--card-shadow);
}

.catalog-card:active {
  transform: scale(0.996);
}

.catalog-card:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, #c7dcf3 60%);
  outline-offset: 1px;
}

.catalog-card-image-wrap {
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--card-fallback-bg);
  aspect-ratio: 1 / 1;
  overflow: hidden;
  position: relative;
}

.catalog-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.catalog-card-image.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--card-muted);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.catalog-card-image-wrap.has-image .catalog-card-image.fallback {
  display: none;
}

.catalog-card-body {
  min-width: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  color: #3f4e61;
  background: #f8fafc;
  line-height: 1.2;
}

.chip.is-stock {
  border-color: #bfe1ce;
  background: var(--ok-soft);
  color: var(--ok);
}

.chip.is-empty {
  border-color: #ebc3b8;
  background: var(--warn-soft);
  color: var(--warn);
}

.catalog-card-price {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--card-price);
  line-height: 1.15;
}

.catalog-card-title {
  margin: 0;
  font-size: 12px;
  line-height: 1.3;
  font-weight: 500;
  color: var(--card-title);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  min-height: calc(1.3em * 2);
}

.catalog-actions {
  margin-top: 12px;
}

.load-more-btn {
  width: 100%;
  height: 42px;
  border: 1px solid #b8cbe0;
  border-radius: 11px;
  background: #e8f1fb;
  color: #123d65;
  font-weight: 600;
  cursor: pointer;
}

.load-more-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.catalog-empty {
  border: 1px dashed #c5d5e5;
  border-radius: 12px;
  background: #f8fbff;
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  font-size: 14px;
}

.catalog-empty.is-error {
  border-color: #e5b9ac;
  background: #fff6f3;
  color: #8b3a29;
}

.catalog-card.is-skeleton {
  cursor: default;
}

.catalog-card.is-skeleton:active {
  transform: none;
}

.skeleton-image {
  border-radius: 12px;
  background: linear-gradient(90deg, #eef3f9 25%, #f7fafe 45%, #eef3f9 65%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s linear infinite;
}

.skeleton-line {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #eef3f9 25%, #f7fafe 45%, #eef3f9 65%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.3s linear infinite;
}

.skeleton-line.lg {
  width: 92%;
}

.skeleton-line.md {
  width: 54%;
  margin-top: 2px;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.filter-sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
}

.filter-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 15, 28, 0.45);
}

.filter-sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(64dvh, 460px);
  border-radius: 16px 16px 0 0;
  background: var(--surface);
  padding: 10px 10px calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

.filter-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.filter-sheet-head h2 {
  margin: 0;
  font-size: 16px;
}

.filter-sheet-close {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f7fafd;
  font-size: 19px;
  line-height: 1;
}

.filter-sheet-options {
  overflow: auto;
  display: grid;
  gap: 6px;
}

.filter-sheet-option {
  width: 100%;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: #24364b;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  padding: 0 12px;
}

.filter-sheet-option.is-active {
  border-color: color-mix(in srgb, var(--accent) 58%, #b8cce1 42%);
  background: color-mix(in srgb, var(--accent-soft) 66%, #ffffff 34%);
  color: #11385f;
}

.filter-sheet-option.is-disabled {
  opacity: 0.58;
}

.product-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.product-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(6, 15, 28, 0.6);
}

.product-modal-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(94dvh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 14px 12px calc(14px + var(--safe-bottom));
}

.product-modal-close {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f7fafd;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

#productModalBody {
  overflow: auto;
  padding-top: 8px;
}

.product-hero {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f2f6fb;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  position: relative;
  margin: 0 0 10px;
}

.product-hero.is-clickable {
  cursor: zoom-in;
}

.product-hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.product-hero-image.fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--product-hero-fallback);
  font-size: 28px;
  font-weight: 700;
}

.product-hero.has-image .product-hero-image.fallback {
  display: none;
}

.product-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.product-thumb {
  border: 1px solid var(--product-thumb-border);
  border-radius: 10px;
  padding: 0;
  background: var(--product-thumb-bg);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  height: 64px;
}

.product-thumb-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--product-hero-fallback);
  font-size: 20px;
  font-weight: 700;
}

.product-thumb-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: relative;
  z-index: 1;
}

.product-thumb.has-image .product-thumb-fallback {
  display: none;
}

.product-thumb.active {
  border-color: #2e76b5;
  box-shadow: 0 0 0 1px rgba(46, 118, 181, 0.28) inset;
}

.product-title {
  margin: 0 34px 4px 0;
  font-size: 22px;
  line-height: 1.2;
  color: var(--product-title);
}

.product-meta {
  margin: 0 0 8px;
  color: var(--product-meta);
  font-size: 14px;
}

.product-price {
  margin: 0 0 8px;
  font-size: clamp(24px, 5.8vw, 32px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--product-price);
}

.product-status-row {
  margin: 0 0 8px;
}

.product-status-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--product-badge-border);
  background: var(--product-badge-bg);
  color: var(--product-badge-text);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.product-status-badge.is-empty {
  background: color-mix(in srgb, #f6f8fb 75%, var(--surface) 25%);
  border-color: #c7d1dd;
  color: #5f6f82;
}

.product-extra {
  margin: 0 0 4px;
  color: var(--product-extra);
  font-size: 13px;
  line-height: 1.35;
}

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

.product-order-wrap {
  margin-top: 12px;
}

.product-order-btn {
  width: 100%;
  min-height: 46px;
  border: none;
  border-radius: 12px;
  background: var(--order-btn-bg);
  color: var(--order-btn-text);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: var(--order-btn-shadow);
}

.product-order-btn:active {
  transform: scale(0.995);
}

.product-order-btn:hover {
  background: var(--order-btn-bg-hover);
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 110;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 8, 18, 0.88);
}

.image-viewer-card {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 12px calc(16px + var(--safe-bottom));
}

.image-viewer-close {
  position: absolute;
  top: calc(8px + var(--safe-top));
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  background: rgba(7, 18, 30, 0.6);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.image-viewer-image {
  width: auto;
  height: auto;
  max-width: min(100%, 900px);
  max-height: min(84vh, 900px);
  border-radius: 12px;
  object-fit: contain;
  background: #0c1b2d;
}

@media (min-width: 420px) {
  .catalog-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 560px) {
  .miniapp-shell {
    padding-left: 14px;
    padding-right: 14px;
  }

  .filter-pill {
    max-width: 260px;
  }
}

@media (min-width: 860px) {
  .product-modal-card {
    max-width: 760px;
    margin: 0 auto;
    border-radius: 16px 16px 0 0;
    padding-left: 14px;
    padding-right: 14px;
  }

  .filter-sheet-card {
    max-width: 520px;
    margin: 0 auto;
  }
}
