/* Цвета — из темы Telegram; запасные значения только для браузера при отладке. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f6);
  --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, #7c7c85);
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --radius: 16px;
  --safe-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom, 0px));
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #101013;
    --card: #1b1b20;
    --text: #f3f3f5;
    --hint: #8d8d97;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 100%/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-align: left; cursor: pointer; }
button { transition: transform 120ms var(--ease-out), opacity 120ms var(--ease-out); }
button:active { transform: scale(.97); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.back:active, .reset:active { transform: none; opacity: .5; }
.row:active { transform: none; opacity: .6; }
.price, .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.notice { padding: 48px 24px; text-align: center; color: var(--hint); }

/* ── Витрина ───────────────────────────────────────────────── */
.top { padding: 18px 16px 10px; }
.top h1 { margin: 0; font-size: 1.875rem; line-height: 1.1; font-weight: 750; letter-spacing: -.02em; }
.top p { margin: 4px 0 0; color: var(--hint); font-size: .8125rem; }
.top h1.brand { display: flex; align-items: center; gap: 8px; white-space: nowrap;
  font-size: clamp(1.25rem, 6.6vw, 1.875rem); }
.brand img { flex: none; width: 2.5rem; height: 2.5rem; }

.search { padding: 4px 16px 10px; }
.search input {
  width: 100%; height: 42px; padding: 0 14px; border: 0; outline: 0; border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit;
}
.search input::placeholder { color: var(--hint); }

.list { margin: 6px 16px 24px; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 14px; position: relative;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 82px; right: 0; height: 1px; background: var(--line);
}
.list.plain .row + .row::before { left: 14px; }
.row .thumb { flex: none; width: 56px; height: 56px; display: flex; align-items: center; justify-content: center; }
.row .thumb .glyph, .row .thumb .photo { max-width: 100%; max-height: 100%; }
.row .body { flex: 1; min-width: 0; }
.row .name { display: block; font-weight: 550; overflow-wrap: anywhere; }
.row .meta { display: block; margin-top: 2px; color: var(--hint); font-size: .8125rem; }
.row .price { flex: none; font-weight: 600; }
.row .price small { color: var(--hint); font-weight: 400; font-size: .75rem; }

/* ── Плитки ────────────────────────────────────────────────── */
.top h1.long { font-size: 1.375rem; line-height: 1.2; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 6px 16px 24px; }
.tiles.with-bar { padding-bottom: calc(96px + var(--safe-bottom)); }
.tile {
  position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 12px;
  background: var(--card); border-radius: var(--radius); cursor: pointer;
  transition: transform 120ms var(--ease-out);
}
.tile:active { transform: scale(.97); }
.check:active { transform: scale(.9); }
.tile.on { box-shadow: inset 0 0 0 2px var(--accent); }
.tile .pic {
  display: flex; align-items: center; justify-content: center; height: 128px; margin-bottom: 8px;
}
.tile .pic .photo, .tile .pic .glyph { max-width: 100%; max-height: 100%; }
.photo { display: block; object-fit: contain; }
.tile .name { font-weight: 600; font-size: .9375rem; line-height: 1.25; overflow-wrap: anywhere; }
.tile .meta { color: var(--hint); font-size: .78125rem; }
.tile .price { margin-top: 3px; font-weight: 700; font-size: 1rem; }
.tile .price small { color: var(--hint); font-weight: 400; font-size: .75rem; }
.check {
  position: absolute; top: 8px; right: 8px; z-index: 1; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: .9375rem; font-weight: 700;
  background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line);
}
.tile.on .check { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.row.pick { cursor: pointer; }
.row.pick .check { position: static; flex: none; }
.row.pick.on .check { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.bar-space { height: calc(80px + var(--safe-bottom)); }
.back { display: inline-block; padding: 14px 16px 0; color: var(--accent); }
.dot.inline { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; }
.reset { display: block; margin: 10px 16px 0; color: var(--accent); font-size: .875rem; }
.shown { margin-top: 8px; }
.sheet-pic { display: flex; justify-content: center; height: 150px; margin-bottom: 12px; }
.sheet-pic .photo, .sheet-pic .glyph { max-width: 100%; max-height: 100%; }

/* ── Фильтры ───────────────────────────────────────────────── */
.group { padding: 14px 16px 2px; }
.group h3 { margin: 0 0 8px; font-size: .8125rem; font-weight: 550; color: var(--hint); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; flex-direction: column; justify-content: center; gap: 2px; min-height: 48px;
  max-width: 100%; padding: 7px 11px; background: var(--card); border-radius: 12px;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chip .label { display: flex; align-items: center; gap: 7px; font-weight: 550; font-size: .9375rem; overflow-wrap: anywhere; }
.chip .cost { color: var(--hint); font-size: .75rem; }
.chip.on { box-shadow: inset 0 0 0 2px var(--accent); }
.chip.on .cost { color: var(--accent); }
.chip.off { opacity: .45; }
.dot {
  flex: none; width: 16px; height: 16px; border-radius: 50%;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, #000 16%, transparent);
}

.buy {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: color-mix(in srgb, var(--card) 72%, transparent);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 -1px 0 var(--line);
}
.buy .body { flex: 1; min-width: 0; }
.buy .meta { margin-top: 2px; color: var(--hint); font-size: .8125rem; overflow-wrap: anywhere; }
.buy .more {
  flex: none; padding: 11px 14px; border-radius: 12px; background: var(--accent);
  color: var(--on-accent); font-weight: 600; font-size: .9375rem;
}

/* ── Лист снизу ────────────────────────────────────────────── */
.sheet { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet[hidden] { display: none; }
.shade {
  position: absolute; inset: 0; background: rgba(0, 0, 0, .4); opacity: 0;
  transition: opacity 320ms var(--ease-out);
}
.sheet.open .shade { opacity: 1; }
.panel {
  position: relative; max-height: 78vh; overflow-y: auto; padding: 0 16px calc(18px + var(--safe-bottom));
  background: var(--bg); border-radius: 20px 20px 0 0;
  transform: translateY(100%); transition: transform 320ms var(--ease-drawer);
}
.sheet.open .panel { transform: none; }
.grab { position: sticky; top: 0; height: 26px; margin: 0 -16px; touch-action: none; background: var(--bg); cursor: grab; }
.grab::after {
  content: ""; position: absolute; top: 9px; left: 50%; width: 36px; height: 5px; margin-left: -18px;
  border-radius: 3px; background: var(--line);
}
.sheet-pic { touch-action: none; }
.sheet h3 { margin: 0; font-size: 1.1875rem; font-weight: 700; letter-spacing: -.01em; }
.sheet .sub { margin: 4px 0 12px; color: var(--hint); font-size: .875rem; }
.sheet .list { margin: 0; }
.sheet .watch + .list { margin-top: 10px; }
.sheet .row .link { color: var(--accent); }
.ask-price { margin: 0 0 14px; font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; }
.ask {
  width: 100%; padding: 14px 16px; border-radius: 12px; background: var(--accent);
  color: var(--on-accent); font-weight: 600; font-size: 1rem; text-align: center;
}
.ask[disabled] { opacity: .6; }
.watch {
  display: block; width: 100%; margin-top: 10px; padding: 12px 16px; border-radius: 12px; text-align: center;
  font-weight: 600; font-size: .9375rem; color: var(--accent); box-shadow: inset 0 0 0 1px var(--line);
}
.watch.on { color: var(--hint); }
.watch[disabled] { opacity: .6; }
.model-watch { padding: 2px 16px 0; }
.model-watch .watch { margin-top: 0; }
.list .watching { background: none; }
.unwatch { flex: none; color: var(--accent); font-size: .875rem; padding: 6px 2px; }
.note {
  display: block; width: 100%; margin: 0 0 10px; padding: 12px 14px; border: 0; outline: 0;
  border-radius: 12px; background: var(--card); color: var(--text); font: inherit; font-size: 1rem;
  resize: vertical; box-shadow: inset 0 0 0 1px var(--line);
}
.note:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.ask-note { margin: 10px 0 0; color: var(--hint); font-size: .8125rem; text-align: center; }
.ask-done { margin: 0; padding: 12px 0 4px; font-weight: 600; text-align: center; }
.own-price { margin: 0 0 4px; }
.own-price .ask-price { margin-bottom: 0; }
.hidden-note { margin: 10px 0 0; color: #e5484d; font-size: .8125rem; }
.own-note { margin: 2px 0 0; color: var(--hint); font-size: .8125rem; }
.own-label { display: block; margin: 4px 0 6px; color: var(--hint); font-size: .8125rem; }
.own-input {
  width: 100%; height: 46px; padding: 0 14px; border: 0; outline: 0; border-radius: 12px;
  background: var(--card); color: var(--text); font: inherit; font-size: 1.25rem; font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--line);
}
.own-input:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.own-hint { margin: 8px 0 12px; color: var(--hint); font-size: .8125rem; }
.own-hint.loss { color: #e5484d; }

/* ── Корзина и заявки ──────────────────────────────────────── */
.buy[data-act] { cursor: pointer; }
.buy .name { font-weight: 600; }
.stepper { flex: none; display: flex; align-items: center; gap: 4px; }
.stepper button {
  width: 34px; height: 34px; border-radius: 10px; text-align: center; font-size: 1.125rem; font-weight: 600;
  color: var(--accent); box-shadow: inset 0 0 0 1px var(--line);
}
.stepper button[disabled] { opacity: .35; }
.stepper .num { min-width: 22px; text-align: center; font-weight: 600; }
.actions { padding: 0 16px calc(24px + var(--safe-bottom)); }
.total { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 12px; }
.total span { color: var(--hint); }
.total b { font-size: 1.375rem; font-weight: 700; letter-spacing: -.01em; }
.section { margin: 18px 16px 8px; font-size: .8125rem; font-weight: 550; color: var(--hint); }
.section + .list { margin-top: 0; }
.card { margin: 0 16px 10px; padding: 12px 14px; background: var(--card); border-radius: var(--radius); }
.card header { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card .meta { color: var(--hint); font-size: .8125rem; }
.status { flex: none; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.status.new { background: color-mix(in srgb, #f5a524 20%, transparent); color: #b06f00; }
.status.taken { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.status.done { background: color-mix(in srgb, var(--hint) 16%, transparent); color: var(--hint); }
.lead-client { margin: 0 0 8px; font-weight: 600; overflow-wrap: anywhere; }
.lead-line { display: flex; justify-content: space-between; gap: 12px; margin: 0 0 6px; }
.lead-line > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.lead-line .meta { display: block; margin-top: 1px; }
.lead-line .num { flex: none; font-weight: 600; }
.lead-line.sum { margin-top: 8px; padding-top: 8px; box-shadow: 0 -1px 0 var(--line); color: var(--hint); }
.lead-line.sum .num { color: var(--text); }
.lead-note { margin: 6px 0; color: var(--hint); font-size: .875rem; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.card-actions .ask, .card-actions .watch { flex: 1 1 auto; width: auto; margin: 0; padding: 10px 12px; font-size: .9375rem; }
.card-error:empty { display: none; }
.watch.subscribe {
  color: #e5484d; background: color-mix(in srgb, #e5484d 14%, transparent); box-shadow: none;
}
.info-btn {
  flex: none; margin-left: auto; padding: 5px 10px; border: 0; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
  font: inherit; font-size: .75rem; font-weight: 650; cursor: pointer;
}
.info-btn:active { opacity: .6; }
.card.info { padding: 14px 16px 4px; font-size: .9375rem; line-height: 1.45; }
.card.info p { margin: 0 0 14px; }
.card.info b { font-size: 1rem; }
.card.info a { color: var(--accent); cursor: pointer; }
.lead-line s { margin-right: 4px; color: var(--hint); font-weight: 400; font-size: .8125rem; }
.lead-price { margin-top: 10px; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 12px 16px 0; }
.stat { padding: 12px 14px; background: var(--card); border-radius: var(--radius); }
.stat b { display: block; font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
.stat span { color: var(--hint); font-size: .8125rem; }
.stat-note { margin: 10px 16px 0; color: var(--hint); font-size: .8125rem; white-space: normal; }
@media (prefers-color-scheme: dark) { .status.new { color: #f5a524; } }

@media (prefers-reduced-motion: reduce) {
  .panel { transform: none; opacity: 0; transition: opacity 200ms ease; }
  .sheet.open .panel { opacity: 1; }
  button, .tile { transition: none; }
  button:active, .tile:active, .check:active { transform: none; opacity: .6; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .buy { background: var(--card); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
