/* Мини-приложение «Закупки». Цвета берутся из темы Telegram; запасные значения — для обычного браузера. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #eef0f4);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #15191e);
  --hint: var(--tg-theme-hint-color, #77818c);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --on-accent: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2a7de1);
  --line: rgba(127, 135, 145, .22);
  --soft: rgba(127, 135, 145, .12);
  --good: #1e9b57;  --good-bg: rgba(30, 155, 87, .14);
  --warn: #c98200;  --warn-bg: rgba(217, 144, 0, .16);
  --bad: #d64545;   --bad-bg: rgba(214, 69, 69, .14);
  --info-bg: rgba(42, 125, 225, .13);
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-secondary-bg-color, #0f1318);
    --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #1a2028));
    --text: var(--tg-theme-text-color, #eef1f4);
    --hint: var(--tg-theme-hint-color, #8b96a3);
    --good: #3dc47e; --warn: #f0ad2e; --bad: #f06a6a;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; text-align: inherit; }
a { color: var(--link); text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hint { color: var(--hint); }
.small { font-size: 13px; }
.good { color: var(--good); } .warn { color: var(--warn); } .bad { color: var(--bad); }

/* ---------- каркас: на телефоне один столбец, на широком экране — список и карточка рядом */
#app { height: 100dvh; display: flex; flex-direction: column; }
#primary { flex: 1; overflow-y: auto; padding: 12px 12px calc(var(--nav-h) + var(--safe-bottom) + 16px); }
#secondary {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto;
  transform: translateX(102%); transition: transform .22s ease; padding: 12px 12px 110px;
}
#secondary.open { transform: none; }
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
#nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--hint); font-size: 11px; font-weight: 500; position: relative;
}
#nav button.on { color: var(--accent); }
#nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#nav .badge {
  position: absolute; top: 6px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: var(--on-accent); font-size: 11px; line-height: 17px; text-align: center;
}

@media (min-width: 980px) {
  #app { display: grid; grid-template-columns: 84px minmax(360px, 440px) 1fr; }
  #nav { position: static; height: auto; flex-direction: column; justify-content: flex-start; gap: 4px; padding: 14px 8px;
         border-top: 0; border-right: 1px solid var(--line); }
  #nav button { flex: none; height: 62px; border-radius: 14px; }
  #nav button.on { background: var(--info-bg); }
  #primary { padding: 16px; border-right: 1px solid var(--line); }
  #secondary { position: static; transform: none; transition: none; padding: 16px 20px 110px; }
  .only-mobile { display: none !important; }
  .pane { max-width: 860px; margin: 0 auto; }
}

/* ---------- общие детали */
.head { display: flex; align-items: center; gap: 10px; margin: 2px 2px 12px; }
.head h1 { font-size: 22px; font-weight: 700; flex: 1; letter-spacing: -.2px; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: var(--surface); color: var(--accent); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 10px; font-weight: 600; font-size: 14px; color: var(--hint); text-align: center; white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .18), 0 0 0 1px var(--line); }
.seg .count { font-weight: 500; opacity: .7; margin-left: 4px; }

.card { background: var(--surface); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; display: block; width: 100%; }
.card + .section-title { margin-top: 18px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--hint); margin: 16px 6px 8px; display: flex; align-items: center; gap: 8px; }
.section-title .grow { flex: 1; }
.link-btn { color: var(--link); font-weight: 600; font-size: 14px; text-transform: none; letter-spacing: 0; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; background: var(--soft); white-space: nowrap; }
.chip.good { background: var(--good-bg); } .chip.warn { background: var(--warn-bg); } .chip.bad { background: var(--bad-bg); }
.chip.info { background: var(--info-bg); color: var(--link); }
.chip.plain { font-weight: 500; color: var(--hint); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: 12px; font-weight: 600; background: var(--soft); text-align: center; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:active, .card.tap:active, .seg button:active { opacity: .7; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--hint); padding: 44px 20px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ---------- список закупок */
.tender { cursor: pointer; }
.tender.active { outline: 2px solid var(--accent); }
.tender .title { font-weight: 600; font-size: 15.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tender .top { display: flex; gap: 10px; align-items: flex-start; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; background: var(--line); }
.dot.good { background: var(--good); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.tender .meta { display: flex; align-items: center; gap: 8px; margin: 10px 0 0 20px; flex-wrap: wrap; }
.tender .sum { font-weight: 700; font-size: 16px; }
.tender .extra { margin: 8px 0 0 20px; }
.tender .note { margin: 8px 0 0 20px; font-size: 13px; color: var(--hint); display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.day { font-size: 15px; font-weight: 700; margin: 18px 6px 8px; }
.day:first-of-type { margin-top: 4px; }

/* ---------- карточка закупки */
.hero h2 { font-size: 19px; line-height: 1.28; font-weight: 700; letter-spacing: -.1px; }
.hero .big { font-size: 26px; font-weight: 750; letter-spacing: -.4px; margin-top: 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin-top: 12px; }
.kv dt { color: var(--hint); } .kv dd { margin: 0; }
.clamp { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; -webkit-line-clamp: 3; cursor: pointer; }
.kv .clamp { -webkit-line-clamp: 2; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--soft); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--hint); }
.stat .value { font-size: 17px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lines { margin-top: 12px; }
.line { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.line .name { color: var(--hint); } .line .val { font-weight: 600; text-align: right; }
.offer { display: flex; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.offer:first-child { border-top: 0; padding-top: 2px; }
.offer .rank { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--soft); font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.offer.me .rank { background: var(--accent); color: var(--on-accent); }
.offer .who { font-weight: 600; }
.offer .what { font-size: 13px; color: var(--hint); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.position h4 { font-size: 15.5px; font-weight: 600; line-height: 1.3; }
.position .qty { margin-top: 4px; color: var(--hint); font-size: 14px; }
.pick { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--soft); font-size: 14px; }
.pick .pname { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pick .tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--hint); margin-bottom: 3px; }
.specs { margin: 10px 0 0; padding: 0; list-style: none; font-size: 13.5px; }
.specs li { padding: 5px 0; border-top: 1px solid var(--line); }
.specs li:first-child { border-top: 0; }
textarea, input[type=text], input[type=search], input[type=number] {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 11px 12px; outline: none;
}
textarea { resize: vertical; min-height: 64px; }
textarea:focus, input:focus { border-color: var(--accent); }
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 10px 12px calc(10px + var(--safe-bottom));
  background: var(--surface); border-top: 1px solid var(--line); display: flex; gap: 8px;
}
.bar .btn { flex: 1; min-height: 46px; }
@media (min-width: 980px) { .bar { position: sticky; bottom: -110px; margin: 16px -20px -110px; padding-bottom: 12px; } }

/* ---------- подбор */
.toolbar { position: sticky; top: -12px; z-index: 5; background: var(--bg); padding: 8px 0 10px; margin: -4px 0 4px; }
.search-row { display: flex; gap: 8px; }
.scroll-x { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0 2px; scrollbar-width: none; }
.scroll-x::-webkit-scrollbar { display: none; }
.filter { flex: none; padding: 7px 12px; border-radius: 999px; background: var(--surface); font-size: 14px; font-weight: 600; color: var(--hint); border: 1px solid transparent; }
.filter.on { color: var(--accent); border-color: var(--accent); background: var(--info-bg); }
.model h4 { font-size: 15px; font-weight: 600; line-height: 1.3; margin-top: 8px; }
.model .price-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.model .price { font-size: 21px; font-weight: 750; letter-spacing: -.3px; }
.model .supplier-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.supplier { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--soft); font-weight: 600; font-size: 13.5px; }
.supplier.ok { background: var(--good-bg); color: var(--good); }
.tier { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 3px 8px; border-radius: 6px; background: var(--soft); color: var(--hint); }
.tier.exact, .tier.full { background: var(--good-bg); color: var(--good); }
.tier.hint { background: var(--info-bg); color: var(--link); }
.tier.likely { background: var(--warn-bg); color: var(--warn); }
.verdicts { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.verdict { font-size: 12.5px; padding: 2px 8px; border-radius: 6px; background: var(--soft); color: var(--hint); }
.verdict.yes { background: var(--good-bg); color: var(--good); }
.model .actions { display: flex; gap: 8px; margin-top: 12px; }
.model .actions .btn { flex: 1; }
.variants { margin-top: 10px; }
.variant { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.variant .vprice { font-weight: 700; }
.variant .vname { font-size: 12.5px; color: var(--hint); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.foot { font-size: 12.5px; color: var(--hint); padding: 6px; line-height: 1.5; }

/* ---------- лист снизу и всплывающее сообщение */
#sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; }
#sheet[hidden] { display: none; }
.sheet { width: 100%; max-width: 560px; max-height: 88dvh; overflow-y: auto; background: var(--surface); border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + var(--safe-bottom)); animation: up .2s ease; }
@media (min-width: 980px) { #sheet { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet .grip { width: 38px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.sheet .stack > * + * { margin-top: 10px; }
.copy-box { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-bottom) + 18px); transform: translate(-50%, 20px); z-index: 60; opacity: 0; pointer-events: none;
  background: rgba(20, 24, 30, .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; transition: all .2s ease; max-width: 88vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.skeleton { border-radius: var(--radius); height: 96px; margin-bottom: 10px; background: linear-gradient(90deg, var(--soft) 25%, var(--line) 37%, var(--soft) 63%); background-size: 400% 100%; animation: shimmer 1.2s ease infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
