/* Mini App «Мій Магазин». Кольори — з теми Telegram (themeParams), з запасними значеннями. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f3f2f0);
  --text: var(--tg-theme-text-color, #17171a);
  --hint: var(--tg-theme-hint-color, #8b8b93);
  --link: var(--tg-theme-link-color, #2f6fed);
  --accent: var(--tg-theme-button-color, #1f1f24);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --danger: var(--tg-theme-destructive-text-color, #d64545);
  --sale: #e0463b;
  --ok: #2e9e5b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 18px rgba(0, 0, 0, .06);
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg2); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  padding-bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }
img { display: block; max-width: 100%; }
a { color: var(--link); text-decoration: none; }
a.card, a.cat, a.hero, a.order-card, a.chip { color: inherit; }
a.hero, a.card { display: block; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Layout --- */
#view { min-height: 60vh; }
.page { padding: 12px 14px 8px; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.section { background: var(--section); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 2px 10px; }
.section-title h2 { font-size: 19px; font-weight: 700; }
.section-title a { font-size: 14px; }

/* --- Header --- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--bg2); padding: 10px 14px 8px; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.brand-logo { width: 38px; height: 38px; border-radius: 12px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 800; font-size: 17px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-tag { font-size: 12.5px; color: var(--hint); }
.search { display: flex; align-items: center; gap: 8px; background: var(--section); border-radius: 12px;
  padding: 0 12px; height: 42px; }
.search input { border: 0; outline: 0; background: transparent; flex: 1; height: 100%; }
.search svg { width: 18px; height: 18px; color: var(--hint); flex: none; }

/* --- Banners --- */
.demo-banner { display: flex; gap: 10px; align-items: flex-start; background: #fff4d6; color: #5e4500;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; font-size: 13.5px; }
.demo-banner b { display: block; font-size: 14px; margin-bottom: 2px; }
.hero { position: relative; border-radius: var(--radius); overflow: hidden; padding: 20px 18px; color: #fff;
  background: linear-gradient(120deg, #2a2a33 0%, #4b4453 55%, #8a6a5a 100%); margin-bottom: 12px; }
.hero h1 { font-size: 22px; margin-bottom: 6px; }
.hero p { margin: 0 0 14px; opacity: .85; font-size: 14px; max-width: 75%; }
.hero .pill { display: inline-block; background: #fff; color: #222; border-radius: 999px; padding: 8px 14px;
  font-weight: 600; font-size: 14px; }
.hero::after { content: "🇺🇦"; position: absolute; right: 16px; bottom: 10px; font-size: 44px; opacity: .9; }

/* --- Categories --- */
.cats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.cat { background: var(--section); border-radius: var(--radius); padding: 14px; min-height: 74px;
  display: flex; flex-direction: column; justify-content: space-between; box-shadow: var(--shadow); }
.cat b { font-size: 15px; }
.cat span { font-size: 22px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 6px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--section); font-size: 14px;
  border: 1px solid transparent; white-space: nowrap; }
.chip.active { background: var(--accent); color: var(--accent-text); }

/* --- Product grid --- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.hscroll { display: grid; grid-auto-flow: column; grid-auto-columns: 44%; gap: 10px; overflow-x: auto;
  scroll-snap-type: x mandatory; scrollbar-width: none; margin: 0 -14px; padding: 0 14px 4px; }
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; }
.card { position: relative; background: var(--section); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); }
.card .img { position: relative; aspect-ratio: 4 / 5; background: var(--bg2); }
.card .img img { width: 100%; height: 100%; object-fit: cover; }
.card .body { padding: 9px 10px 11px; display: flex; flex-direction: column; gap: 4px; }
.card .title { font-size: 13.5px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; min-height: 2.5em; }
.card.soldout .img img { opacity: .45; }
.price { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.price b { font-size: 15.5px; }
.price s { color: var(--hint); font-size: 12.5px; }
.price.sale b { color: var(--sale); }
.dots { display: flex; gap: 4px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--sep); }
.badges { position: absolute; left: 8px; top: 8px; display: flex; flex-direction: column; gap: 4px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 7px; border-radius: 6px; background: #fff; color: #111;
  letter-spacing: .02em; }
.badge.sale { background: var(--sale); color: #fff; }
.badge.new { background: #1f1f24; color: #fff; }
.badge.out { background: rgba(0,0,0,.6); color: #fff; }
.fav { position: absolute; right: 6px; top: 6px; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.85); display: grid; place-items: center; color: #222; }
.fav svg { width: 18px; height: 18px; }
.fav.on { color: var(--sale); }
.fav.on svg path { fill: currentColor; }

/* --- Product page --- */
.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  margin: -12px -14px 0; background: var(--bg2); }
.gallery::-webkit-scrollbar { display: none; }
.gallery img { flex: none; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; scroll-snap-align: center; }
.gallery-dots { display: flex; justify-content: center; gap: 6px; margin: 8px 0 2px; }
.gallery-dots i { width: 6px; height: 6px; border-radius: 3px; background: var(--sep); transition: .2s; }
.gallery-dots i.on { width: 16px; background: var(--text); }
.p-head { padding: 12px 2px 4px; }
.p-head h1 { font-size: 20px; margin-bottom: 8px; }
.p-head .price b { font-size: 22px; }
.p-head .price s { font-size: 15px; }
.opt-label { display: flex; justify-content: space-between; margin: 4px 0 10px; font-size: 14px; }
.opt-label b { font-weight: 600; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 2px solid transparent; padding: 3px; }
.swatch i { display: block; width: 100%; height: 100%; border-radius: 50%; border: 1px solid var(--sep); }
.swatch.active { border-color: var(--text); }
.sizes { display: flex; gap: 8px; flex-wrap: wrap; }
.size { min-width: 52px; height: 42px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--sep);
  font-weight: 600; background: var(--bg); }
.size.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.size:disabled { color: var(--hint); text-decoration: line-through; opacity: .6; }
.size.shake { animation: shake .35s; border-color: var(--danger); }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.low { color: #c46a00; font-size: 13px; margin-top: 8px; }
.desc { white-space: pre-line; font-size: 14.5px; }
.facts { display: grid; gap: 8px; font-size: 14px; }
.facts div { display: flex; gap: 10px; }
.facts span:first-child { width: 22px; flex: none; }

/* --- Lists / cart --- */
.line { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--sep); }
.line:last-child { border-bottom: 0; }
.line img { width: 74px; height: 92px; object-fit: cover; border-radius: 10px; background: var(--bg2); flex: none; }
.line .title { font-size: 14.5px; font-weight: 500; }
.line.bad { opacity: .6; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--sep); border-radius: 10px; height: 34px; }
.stepper button { width: 34px; height: 100%; font-size: 18px; }
.stepper span { min-width: 22px; text-align: center; font-weight: 600; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; color: var(--hint); }
.icon-btn svg { width: 18px; height: 18px; }
.totals { display: grid; gap: 8px; font-size: 14.5px; }
.totals div { display: flex; justify-content: space-between; gap: 10px; }
.totals .grand { font-size: 18px; font-weight: 700; padding-top: 8px; border-top: 1px solid var(--sep); }
.progress { height: 6px; border-radius: 3px; background: var(--bg2); overflow: hidden; margin-top: 8px; }
.progress i { display: block; height: 100%; background: var(--ok); border-radius: 3px; transition: width .3s; }

/* --- Forms --- */
.field { margin-bottom: 12px; position: relative; }
.field label { display: block; font-size: 13px; color: var(--hint); margin: 0 0 5px 2px; }
.input { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--sep); background: var(--bg);
  padding: 0 12px; outline: 0; }
textarea.input { height: 76px; padding: 10px 12px; resize: none; }
.input:focus { border-color: var(--link); }
.field.error .input { border-color: var(--danger); }
.field .err { color: var(--danger); font-size: 12.5px; margin: 4px 2px 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.with-btn { display: flex; gap: 8px; }
.with-btn .input { flex: 1; }
.btn { height: 46px; padding: 0 16px; border-radius: 12px; background: var(--accent); color: var(--accent-text);
  font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.secondary { background: var(--bg2); color: var(--text); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.options { display: grid; gap: 8px; }
.option { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; border: 1px solid var(--sep);
  background: var(--bg); text-align: left; width: 100%; }
.option .radio { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--sep); flex: none; }
.option.active { border-color: var(--accent); }
.option.active .radio { border: 6px solid var(--accent); }
.option b { display: block; font-weight: 600; }
.option small { color: var(--hint); }
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 15; background: var(--bg); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15); max-height: 290px; overflow-y: auto; margin-top: 4px; }
.suggest button { display: block; width: 100%; text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--sep); }
.suggest button:last-child { border-bottom: 0; }
.suggest small { display: block; color: var(--hint); }

/* --- Orders --- */
.order-card { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--section);
  border-radius: var(--radius); margin-bottom: 10px; box-shadow: var(--shadow); width: 100%; text-align: left; }
.order-card img { width: 54px; height: 66px; object-fit: cover; border-radius: 8px; background: var(--bg2); }
.status { display: inline-block; font-size: 12.5px; padding: 3px 8px; border-radius: 6px; background: var(--bg2); }
.status.awaiting_payment { background: #fff1d6; color: #7a5200; }
.status.new, .status.confirmed { background: #e7efff; color: #1f4fb8; }
.status.shipped, .status.arrived { background: #e9f6ee; color: #1d7a45; }
.status.delivered { background: #e3f3e8; color: #186b3b; }
.status.cancelled, .status.returned { background: #f6e6e6; color: #9b2c2c; }
.success-box { text-align: center; padding: 26px 16px; }
.success-box .big { font-size: 56px; margin-bottom: 6px; }
.timeline { border-left: 2px solid var(--sep); margin-left: 6px; padding-left: 14px; }

/* --- Empty / skeleton --- */
.empty { text-align: center; padding: 50px 20px; color: var(--hint); }
.empty .big { font-size: 54px; margin-bottom: 8px; }
.skeleton { background: linear-gradient(90deg, var(--section) 25%, var(--bg2) 50%, var(--section) 75%);
  background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: var(--radius); }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- Bottom nav --- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; background: var(--bg);
  border-top: 1px solid var(--sep); height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--hint); font-size: 11px; position: relative; }
.nav a svg { width: 24px; height: 24px; }
.nav a.active { color: var(--text); }
.nav .count { position: absolute; top: 6px; left: 50%; margin-left: 6px; background: var(--sale); color: #fff;
  border-radius: 9px; min-width: 18px; height: 18px; font-size: 11px; font-weight: 700; display: grid;
  place-items: center; padding: 0 5px; }

/* --- Sheet / modal --- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; animation: fade .15s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(16px + var(--safe-b)); max-height: 85vh; overflow-y: auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--sep); margin: 0 auto 12px; }
.sheet h3 { font-size: 18px; margin-bottom: 12px; }
table.sizes-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.sizes-table th, table.sizes-table td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--sep); }

/* --- Toast --- */
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: rgba(20,20,24,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  z-index: 60; max-width: 90vw; animation: fade .2s; }

/* --- Fallback main button (браузер без Telegram) --- */
.fake-main { position: fixed; left: 14px; right: 14px; bottom: calc(var(--nav-h) + var(--safe-b) + 10px); z-index: 25;
  height: 50px; border-radius: 14px; background: var(--accent); color: var(--accent-text); font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.2); }
body.has-fake-main { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 76px); }
body.has-fake-main .toast { bottom: calc(var(--nav-h) + var(--safe-b) + 72px); }
