/* TG Place — прототип мини-аппа.
   Все цвета — переменные: светлая тема на :root, тёмная — [data-theme="dark"].
   Акцент — бирюзовый из баннера «TG PLACE». */

:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #11161c;
  --muted: #6a7280;
  --line: #e4e7ec;
  --chip: #e8ecf0;
  --accent: #1f8599;
  --accent-text: #ffffff;
  --accent-soft: rgba(31, 133, 153, 0.11);
  --accent-glow: rgba(31, 133, 153, 0.28);
  --avatar-bg: linear-gradient(135deg, #2aa0b4, #17697a);
  --hero-bg: linear-gradient(135deg, #22a1b6 0%, #16707f 100%);
  --danger: #d64545;
  --shadow: 0 1px 2px rgba(17, 22, 28, 0.05), 0 4px 16px rgba(17, 22, 28, 0.04);
  --sheet-shadow: 0 -8px 40px rgba(17, 22, 28, 0.18);
  --bar-shadow: 0 8px 28px rgba(17, 22, 28, 0.12);
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d0f12;
  --surface: #171a1f;
  --surface-2: #1d2127;
  --text: #eef1f4;
  --muted: #8a93a0;
  --line: #262b32;
  --chip: #1f2329;
  --accent: #3bb3c8;
  --accent-text: #06181c;
  --accent-soft: rgba(59, 179, 200, 0.14);
  --accent-glow: rgba(59, 179, 200, 0.22);
  --avatar-bg: linear-gradient(135deg, #2e9fb3, #145f6d);
  --hero-bg: linear-gradient(135deg, #1d8698 0%, #0f4a55 100%);
  --danger: #f06b6b;
  --shadow: none;
  --sheet-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
  --bar-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 28px);
}

/* --- шапка --- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 16px 10px;
}

.brand h1 { margin: 0; font-size: 26px; line-height: 1.1; letter-spacing: -0.02em; font-weight: 750; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn .i-sun { display: none; }
[data-theme="dark"] .icon-btn .i-sun { display: block; }
[data-theme="dark"] .icon-btn .i-moon { display: none; }

/* --- плашка тематик: листается вбок --- */

.chips {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 16px 10px;
  background: var(--bg);
  scroll-snap-type: x proximity;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--chip);
  white-space: nowrap;
  font-size: 14px;
  font-weight: 550;
  scroll-snap-align: start;
  transition: background 0.15s, color 0.15s;
}
.chip small { color: var(--muted); font-weight: 500; font-size: 12px; }
.chip.is-active { background: var(--accent); color: var(--accent-text); }
.chip.is-active small { color: inherit; opacity: 0.75; }

/* --- список каналов --- */

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 8px;
  color: var(--muted);
  font-size: 13px;
}

.sort {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--accent);
  font-weight: 600;
  font-size: 13px;
}
.sort svg { width: 16px; height: 16px; }

/* minmax(0, 1fr): иначе строка сетки растягивается по самому длинному
   названию, и карточки вылезают за край экрана */
.channels { list-style: none; margin: 0; padding: 0 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }

.card {
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform 0.12s;
}
.card:active { transform: scale(0.985); }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.card-top .avatar { margin-top: 2px; }

/* Нижняя строка карточки на всю ширину: метки слева, «Подробнее» справа */
.card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.more {
  flex: none;
  display: inline-flex; align-items: center; gap: 4px;
  height: 34px;
  padding: 0 10px 0 12px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: transform 0.12s, opacity 0.12s;
}
.more svg { width: 16px; height: 16px; stroke-width: 2.2; }
.more:active { transform: scale(0.96); opacity: 0.9; }

/* Аватар без фото — один фирменный бирюзовый для всех каналов */
.avatar {
  width: 48px; height: 48px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--avatar-bg);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
  object-fit: cover;
}
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }

.card-main { flex: 1; min-width: 0; }
.card-row { display: flex; align-items: center; gap: 8px; }
.card-title {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 5px;
  font-weight: 650;
  font-size: 15.5px;
}
.card-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.verified { width: 16px; height: 16px; flex: none; color: var(--accent); stroke-width: 2.2; }
.card-meta { margin-top: 3px; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-tags { display: flex; gap: 6px; flex-wrap: wrap; min-width: 0; }
.tag {
  font-size: 12px; font-weight: 550;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}
.tag.good { background: var(--accent-soft); color: var(--accent); }

.price {
  flex: none;
  padding: 3px 8px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.price.none { background: var(--surface-2); color: var(--muted); font-weight: 550; }

.empty {
  margin: 40px 24px;
  text-align: center;
  color: var(--muted);
}
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* --- корзина --- */

.cart-list { list-style: none; margin: 0; padding: 0 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.cart-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.cart-item .avatar { width: 40px; height: 40px; font-size: 15px; }
.cart-item .card-main div:last-child { color: var(--muted); font-size: 13px; margin-top: 2px; }
.remove {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--muted);
}
.remove svg { width: 18px; height: 18px; }

.summary {
  margin: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid; gap: 6px;
}
.summary-row { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; }
.summary-row.total { color: var(--text); font-size: 17px; font-weight: 700; padding-top: 6px; border-top: 1px solid var(--line); margin-top: 4px; }

.btn {
  display: flex; align-items: center; justify-content: center;
  width: calc(100% - 24px);
  margin: 0 12px;
  height: 50px;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 16px;
}
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.btn:active { opacity: 0.85; }

/* --- профиль --- */

.profile { padding: 0 12px; display: grid; gap: 12px; }

/* Шапка профиля — в фирменном бирюзовом, как баннер бота */
.hero {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 16px;
  border-radius: 20px;
  background: var(--hero-bg);
  color: #fff;
}
.hero .avatar { background: rgba(255, 255, 255, 0.18); border: 2px solid rgba(255, 255, 255, 0.35); }
.hero-text { min-width: 0; display: grid; gap: 2px; justify-items: start; }
.hero-text b { font-size: 19px; line-height: 1.2; }
.hero-text span { opacity: 0.8; font-size: 14px; }
.role {
  margin-top: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-style: normal;
  font-size: 12px;
  font-weight: 650;
}

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile {
  padding: 12px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: left;
}
.tile b { display: block; font-size: 20px; line-height: 1.1; }
.tile span { color: var(--muted); font-size: 12.5px; }

.group {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.group-title {
  margin: 0;
  padding: 12px 16px 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px 10px 16px;
  text-align: left;
}
.row + .row { border-top: 1px solid var(--line); }
.row-icon {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}
.row-icon svg { width: 20px; height: 20px; }
.row-text { flex: 1; min-width: 0; display: grid; }
.row-text b { font-weight: 600; font-size: 15px; }
.row-text small { color: var(--muted); font-size: 12.5px; }
.row em {
  min-width: 22px; height: 22px; padding: 0 7px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--accent);
  color: var(--accent-text);
  font-style: normal; font-size: 12px; font-weight: 700;
}
.chevron { width: 18px; height: 18px; flex: none; color: var(--muted); opacity: 0.7; }

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin: 6px 12px 12px;
  border-radius: 12px;
  background: var(--chip);
}
.segmented button {
  height: 34px;
  border-radius: 9px;
  font-size: 14px;
  font-weight: 550;
  color: var(--muted);
}
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Вход в админку — заметная плашка, видна только админам */
.admin-entry {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 12px 12px 12px 14px;
  text-align: left;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}
.admin-entry .row-icon { background: var(--accent); color: var(--accent-text); }
.admin-entry .row-text b { color: var(--accent); }

.footnote { margin: 4px 16px 8px; text-align: center; color: var(--muted); font-size: 12px; }

/* «Как работает гарант» */
.sheet-title { margin: 0 0 14px; font-size: 20px; }
.steps { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 14px; }
.step { display: flex; gap: 12px; align-items: flex-start; }
.step-n {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700; font-size: 14px;
}
.step b { display: block; margin-top: 3px; }
.step p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.sheet .btn { width: 100%; margin: 0; }

/* --- нижнее меню --- */

/* Нижнее меню — плавающая панель со скруглёнными углами, отступ от краёв
   и от низа экрана (с учётом «чёлки» снизу на iPhone) */
.tabbar {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 456px;
  margin: 0 auto;
  height: var(--tabbar-h);
  padding: 6px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--bar-shadow);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  border-radius: 18px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.tab.is-active { background: var(--accent-soft); color: var(--accent); }
.tab-icon { position: relative; display: grid; }
.badge {
  position: absolute;
  top: -4px; right: -9px;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
  border: 2px solid var(--surface);
}

/* --- карточка канала снизу --- */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0, 0, 0, 0.45);
  animation: fade 0.18s ease-out;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 31;
  max-width: 480px;
  margin: 0 auto;
  max-height: 88vh;
  overflow-y: auto;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--sheet-shadow);
  animation: rise 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet-grip { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }

.sheet-head { display: flex; align-items: center; gap: 14px; }
.sheet-head h2 { margin: 0; font-size: 20px; line-height: 1.2; }
.sheet-head a { color: var(--accent); text-decoration: none; font-size: 14px; }

/* minmax(0, 1fr): длинное значение (контакт, ссылка) обрезается многоточием,
   а не растягивает плитку за край экрана */
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 16px 0; }
.stat { min-width: 0; padding: 10px; border-radius: 12px; background: var(--surface-2); }
.stat b { display: block; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat span { color: var(--muted); font-size: 12px; }

.formats { display: grid; gap: 8px; margin-bottom: 14px; }
.format {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.format b { display: block; }
.format span { color: var(--muted); font-size: 13px; }
.format button {
  flex: none;
  height: 36px; padding: 0 14px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 650; font-size: 14px;
}
.format button.in-cart { background: var(--accent-soft); color: var(--accent); }

.note { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* --- всплывашка --- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  z-index: 40;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px; font-weight: 550;
  animation: fade 0.18s ease-out;
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
