/* Цвета берём из темы Telegram — витрина сама становится светлой или тёмной */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #0a84ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #0a84ff);
  --danger: var(--tg-theme-destructive-text-color, #ff3b30);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --tile: #f6f6f8;            /* фон картинок товаров — совпадает с фоном самих картинок */
  --radius: 18px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img { display: block; }

.screen { padding: 12px 16px calc(96px + env(safe-area-inset-bottom)); animation: in .22s ease; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- шапка каталога ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
.top h1 { font-size: 28px; line-height: 1.1; letter-spacing: -0.02em; margin: 0; }
.top .sub { color: var(--hint); font-size: 14px; margin-top: 2px; }
.icon-btn {
  position: relative; flex: none; width: 42px; height: 42px; border-radius: 50%;
  background: var(--card); display: grid; place-items: center;
}
.icon-btn svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

.search {
  display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 12px;
  padding: 0 12px; height: 42px; margin-bottom: 12px;
}
.search svg { width: 18px; height: 18px; color: var(--hint); flex: none; }
.search input { border: 0; outline: 0; background: none; width: 100%; height: 100%; font-size: 16px; }
.search input::placeholder { color: var(--hint); }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--card);
  font-size: 14px; font-weight: 500; white-space: nowrap; transition: background .15s, color .15s;
}
.chip.on { background: var(--text); color: var(--bg); }

/* ---------- сетка товаров ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card {
  background: var(--card); border-radius: var(--radius); overflow: hidden; text-align: left;
  display: flex; flex-direction: column; transition: transform .12s;
}
.card:active { transform: scale(.97); }
.card .pic { background: var(--tile); aspect-ratio: 1; overflow: hidden; }
.card .pic img { width: 100%; height: 100%; object-fit: cover; transform: scale(1.04); }
.card .info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.card .name { font-weight: 600; font-size: 15px; line-height: 1.2; }
.card .price { font-size: 14px; color: var(--hint); }
.card .price b { color: var(--text); font-weight: 600; }
.card.out { opacity: .55; }
.tag {
  align-self: flex-start; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); margin-bottom: 2px;
}
.section-title { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; margin: 18px 2px 10px; }
.section-title:first-child { margin-top: 4px; }

/* ---------- карточка товара ---------- */
.hero { background: var(--tile); border-radius: 24px; overflow: hidden; margin-bottom: 16px; }
.hero img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.p-name { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; margin: 0 2px 2px; line-height: 1.15; }
.p-note { color: var(--accent); font-size: 14px; font-weight: 600; margin: 0 2px 6px; }
.p-price { font-size: 22px; font-weight: 600; margin: 4px 2px 0; }
.p-price small { color: var(--hint); font-size: 14px; font-weight: 400; margin-left: 6px; }

.block { background: var(--card); border-radius: var(--radius); padding: 14px; margin-top: 14px; }
.block h3 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--hint); text-transform: uppercase; letter-spacing: .05em; }
.block h3 span { text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 500; margin-left: 4px; }

.colors { display: flex; flex-wrap: wrap; gap: 12px; }
.dot {
  width: 36px; height: 36px; border-radius: 50%; position: relative;
  box-shadow: inset 0 0 0 1px var(--line), inset 0 0 0 1.5px rgba(127,127,127,.25);
}
.dot::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%;
  border: 2px solid transparent; transition: border-color .15s;
}
.dot.on::after { border-color: var(--accent); }

.mem { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.opt {
  border-radius: 14px; padding: 10px 12px; text-align: left;
  box-shadow: inset 0 0 0 1.5px var(--line); transition: box-shadow .15s, background .15s;
}
.opt .m { font-weight: 600; font-size: 16px; }
.opt .p { font-size: 13px; color: var(--hint); }
.opt.on { box-shadow: inset 0 0 0 2px var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.opt:disabled { opacity: .4; }
.opt:disabled .p { text-decoration: none; }

.perks { display: grid; gap: 10px; }
.perk { display: flex; gap: 12px; align-items: center; font-size: 14px; }
.perk i { font-style: normal; font-size: 20px; width: 28px; text-align: center; }

/* ---------- оформление ---------- */
.summary { display: flex; gap: 12px; align-items: center; }
.summary img { width: 72px; height: 72px; border-radius: 14px; background: var(--tile); object-fit: cover; }
.summary .t { font-weight: 600; }
.summary .s { color: var(--hint); font-size: 14px; }
.summary .pr { font-weight: 600; margin-top: 2px; }
.field { display: block; margin-top: 12px; }
.field span { display: block; font-size: 13px; color: var(--hint); margin: 0 2px 6px; }
.field input {
  width: 100%; height: 48px; border-radius: 12px; border: 0; outline: 0; padding: 0 14px;
  background: var(--bg); font-size: 17px;
}
.field input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.link-btn { color: var(--link); font-size: 14px; font-weight: 500; margin: 8px 2px 0; }
.error { color: var(--danger); font-size: 14px; margin: 10px 2px 0; min-height: 1em; }
.fine { color: var(--hint); font-size: 12px; margin: 14px 4px 0; text-align: center; }

/* ---------- результат / заказы / пусто ---------- */
.center { text-align: center; padding-top: 12vh; }
.big-icon {
  width: 88px; height: 88px; border-radius: 50%; margin: 0 auto 18px; display: grid; place-items: center;
  background: color-mix(in srgb, #34c759 16%, transparent); color: #34c759; font-size: 44px;
}
.center h2 { font-size: 26px; margin: 0 0 8px; letter-spacing: -0.01em; }
.center p { color: var(--hint); margin: 0 auto 22px; max-width: 300px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 48px; padding: 0 22px;
  border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.btn.ghost { background: var(--card); color: var(--link); }

.order { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.order .row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.order .num { font-weight: 600; }
.order .st { font-size: 13px; padding: 3px 8px; border-radius: 8px; background: var(--bg); white-space: nowrap; }
.order .what { margin-top: 6px; }
.order .meta { color: var(--hint); font-size: 13px; margin-top: 2px; }
.empty { color: var(--hint); text-align: center; padding: 40px 0; }

.contacts { margin-top: 18px; }
.contacts a { color: var(--link); text-decoration: none; }

/* ---------- кнопка вне Telegram ---------- */
.fallback-main {
  position: fixed; left: 16px; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); height: 52px;
  border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 17px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.fallback-main:disabled { opacity: .6; }

.loader { display: grid; place-items: center; height: 80vh; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
