:root {
  --bg: var(--tg-theme-bg-color, #fff);
  --text: var(--tg-theme-text-color, #000);
  --hint: var(--tg-theme-hint-color, #8b8b8b);
  --card: var(--tg-theme-secondary-bg-color, #f4f4f5);
  --accent: var(--tg-theme-button-color, #2ea6ff);
  --accent-text: var(--tg-theme-button-text-color, #fff);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 24px;
}

header {
  position: sticky; top: 0; z-index: 10;
  background: var(--bg);
  padding: 10px 12px 6px;
  border-bottom: 1px solid rgba(128,128,128,.15);
}

.search-row { display: flex; gap: 8px; align-items: center; }

#search {
  flex: 1; padding: 10px 12px; font-size: 15px;
  border: none; border-radius: 10px;
  background: var(--card); color: var(--text);
}
#search:focus { outline: 2px solid var(--accent); }

.icon-btn {
  border: none; background: var(--card); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer;
}

.chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 0 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 16px;
  background: var(--card); color: var(--text);
  font-size: 13px; white-space: nowrap; border: none; cursor: pointer;
}
.chip.active { background: var(--accent); color: var(--accent-text); }
.chip .count { opacity: .6; margin-left: 4px; font-size: 12px; }

main { padding: 10px 12px; }
.summary { color: var(--hint); font-size: 13px; margin-bottom: 10px; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.card {
  background: var(--card); border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column;
}
.card img { width: 100%; aspect-ratio: 1/1; object-fit: cover; background: rgba(128,128,128,.12); }
.card .no-photo { width: 100%; aspect-ratio: 1/1; display: grid; place-items: center; font-size: 30px; opacity: .35; }
.card-body { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-size: 13px; line-height: 1.3; max-height: 3.9em; overflow: hidden; }
.prices { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.price-final { font-weight: 700; font-size: 15px; }
.price-old { color: var(--hint); text-decoration: line-through; font-size: 12px; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgba(46,166,255,.15); color: var(--accent); }
.badge.free { background: rgba(52,199,89,.18); color: #34c759; }
.meta { color: var(--hint); font-size: 11px; margin-top: auto; }
.actions { display: flex; gap: 6px; margin-top: 6px; }
.actions a, .actions button {
  flex: 1; text-align: center; text-decoration: none; font-size: 12px;
  padding: 7px 4px; border-radius: 8px; border: none; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
}
.actions .secondary { background: rgba(128,128,128,.2); color: var(--text); }

.loader, .empty { text-align: center; color: var(--hint); padding: 20px; font-size: 14px; }
.hidden { display: none !important; }

.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; z-index: 20; }
.sheet-body { width: 100%; background: var(--bg); border-radius: 16px 16px 0 0; padding: 16px; max-height: 80vh; overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.hint { color: var(--hint); font-size: 13px; margin: 4px 0 12px; }
.sub-add { display: flex; gap: 8px; margin-bottom: 12px; }
.sub-add input { flex: 1; padding: 10px; border-radius: 10px; border: none; background: var(--card); color: var(--text); }
.sub-add button { padding: 10px 14px; border-radius: 10px; border: none; background: var(--accent); color: var(--accent-text); cursor: pointer; }
.subs-list { display: flex; flex-direction: column; gap: 8px; }
.sub-item { display: flex; justify-content: space-between; align-items: center; background: var(--card); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.sub-item button { border: none; background: transparent; color: #ff3b30; font-size: 16px; cursor: pointer; }


/* Второй ряд: сортировка и фильтры */
.chips.filters { padding-top: 2px; }
.chip.toggle.on { background: var(--accent); color: var(--accent-text); }
.sep { flex: 0 0 1px; background: rgba(128,128,128,.3); margin: 4px 2px; }
.badge.new { background: rgba(255,59,48,.15); color: #ff3b30; }
.fav-btn.on { background: var(--accent); color: var(--accent-text); }
