:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2a7de1);
  --button: var(--tg-theme-button-color, #2a7de1);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #d93b3b);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 18px; margin: 18px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }
.stack > * + * { margin-top: 10px; }

button, .button {
  display: block; width: 100%; border: 0; border-radius: var(--radius); padding: 14px 16px;
  font: inherit; font-weight: 600; background: var(--button); color: var(--button-text); cursor: pointer;
  text-align: center;
}
button.secondary { background: var(--bg2); color: var(--text); }
button.link { background: none; color: var(--link); padding: 8px; font-weight: 500; }
button.danger { background: none; color: var(--danger); padding: 6px 8px; width: auto; font-weight: 500; }
button:disabled { opacity: .45; }

.card {
  display: flex; gap: 14px; align-items: center; width: 100%; text-align: left; background: var(--bg2);
  color: var(--text); border-radius: var(--radius); padding: 14px; font-weight: 400;
}
.card .icon { font-size: 30px; flex: none; }
.card b { display: block; font-size: 17px; }
.card span { color: var(--hint); font-size: 14px; }

input, textarea {
  width: 100%; border: 1px solid transparent; border-radius: 12px; padding: 12px 14px; font: inherit;
  background: var(--bg2); color: var(--text); outline: none;
}
input:focus, textarea:focus { border-color: var(--button); }
textarea { min-height: 70px; resize: vertical; }

.preview { width: 100%; border-radius: var(--radius); background: var(--bg2); display: block; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.thumb { position: relative; border-radius: 12px; overflow: hidden; background: var(--bg2); aspect-ratio: 3 / 4; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .tag {
  position: absolute; left: 4px; right: 4px; bottom: 4px; font-size: 11px; background: rgba(0, 0, 0, .55);
  color: #fff; border-radius: 6px; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb .x {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; padding: 0; border-radius: 13px;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 15px; line-height: 26px;
}

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  width: auto; display: inline-block; padding: 10px 14px; border-radius: 20px; background: var(--bg2);
  color: var(--text); font-weight: 500;
}
.chip.primary { background: var(--button); color: var(--button-text); }

.variant { margin-bottom: 18px; }
.variant .label { font-size: 13px; color: var(--hint); margin: 6px 2px; }

.price-row { display: grid; grid-template-columns: 1fr 130px 34px; gap: 6px; margin-bottom: 6px; }
.price-row button { padding: 0; background: none; color: var(--hint); font-size: 20px; }

.spinner {
  width: 44px; height: 44px; margin: 40px auto 16px; border-radius: 50%;
  border: 4px solid var(--bg2); border-top-color: var(--button); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--bg2); }
.list-item > div { flex: 1; min-width: 0; }
.list-item small { color: var(--hint); display: block; }
.list-item button { width: auto; padding: 8px 12px; }

.stat { background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; }
.stat b { font-size: 20px; }

/* сканер */
.scanner { position: fixed; inset: 0; background: #000; z-index: 10; display: flex; flex-direction: column; }
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .frame {
  position: absolute; left: 10%; right: 10%; top: 32%; height: 22%; border: 3px solid rgba(255, 255, 255, .9);
  border-radius: 16px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); pointer-events: none;
}
.scanner .bar { padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); background: #000; color: #fff; }
.scanner .bar p { margin: 0 0 10px; text-align: center; font-size: 15px; }
.scanner .bar .row button { padding: 12px 8px; font-size: 15px; }
.scanner .bar button.secondary { background: #2a2a2e; color: #fff; }
.scanner .error { color: #ffb4b4; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 20;
  background: rgba(30, 30, 32, .94); color: #fff; padding: 12px 14px; border-radius: 12px; font-size: 15px;
}
.hidden { display: none !important; }
