/* Gift Scout Mini App — дизайн-система.
   Токены сначала, компоненты потом. Никаких размерных ограничений:
   статика идёт через Nginx с gzip. */

:root {
  /* Поверхности */
  --bg: #08090b;
  --surface: #12141a;
  --surface-2: #191c24;
  --surface-3: #21252f;
  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.14);

  /* Текст */
  --text: #f2f4f8;
  --text-dim: #a7aebc;
  --text-mute: #6e7686;

  /* Смысловые */
  --gold: #f5c518;
  --gold-dim: rgba(245, 197, 24, 0.14);
  --gold-line: rgba(245, 197, 24, 0.38);
  --ink: #14110a;
  --up: #35d07f;
  --up-dim: rgba(53, 208, 127, 0.14);
  --down: #ff5f6d;
  --down-dim: rgba(255, 95, 109, 0.13);
  --info: #4c9fff;
  --info-dim: rgba(76, 159, 255, 0.13);

  /* Классы отбора */
  --cls-m: #b07cff;
  --cls-b: #8f9bb3;
  --cls-r: #4c9fff;
  --cls-c: #ff9f43;

  /* Шкала отступов */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --pad: 16px;

  /* Типографика */
  --t-caption: 11px;
  --t-small: 12px;
  --t-body: 14px;
  --t-lead: 16px;
  --t-title: 20px;
  --t-hero: 30px;

  /* Радиусы и тени */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-pill: 999px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);

  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: var(--t-body);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--tg-theme-bg-color, var(--bg));
  color: var(--tg-theme-text-color, var(--text));
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

button,
.chip,
.card {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 650;
  border-radius: var(--r-md);
  padding: 10px 14px;
  transition: transform 0.12s var(--ease), background 0.16s var(--ease), opacity 0.16s var(--ease);
}

button:active {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.42;
  cursor: default;
}

.hidden {
  display: none !important;
}

#app {
  max-width: 760px;
  margin: 0 auto;
}

/* ---------- Шапка ---------- */

.head {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(10px + env(safe-area-inset-top)) var(--pad) var(--s2);
  background: linear-gradient(180deg, var(--bg) 74%, rgba(8, 9, 11, 0.82) 100%);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.mark {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  display: grid;
  place-items: center;
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid var(--gold-line);
  font-weight: 800;
}

.brand-text {
  flex: 1;
  min-width: 0;
}

.brand strong {
  display: block;
  font-size: var(--t-lead);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-sub {
  color: var(--text-mute);
  font-size: var(--t-caption);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-pill);
  padding: 4px 9px;
  white-space: nowrap;
}

.search-row {
  display: flex;
  gap: var(--s2);
}

.search {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--s2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 0 var(--s3);
  min-height: 44px;
  transition: border-color 0.16s var(--ease);
}

.search:focus-within {
  border-color: var(--gold-line);
}

.search input {
  width: 100%;
  background: 0;
  border: 0;
  color: var(--text);
  font: inherit;
  outline: none;
  padding: 11px 0;
}

.ghost {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  min-height: 44px;
}

.ghost:active {
  background: var(--surface-3);
}

.primary {
  background: var(--gold);
  color: var(--ink);
  font-weight: 750;
}

.chips {
  display: flex;
  gap: var(--s2);
  padding: var(--s3) 0 2px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 8px 14px;
  font-size: var(--t-small);
  font-weight: 600;
  color: var(--text-dim);
  white-space: nowrap;
}

.chip.on {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: var(--gold-line);
}

.chip-count {
  display: inline-block;
  margin-left: 5px;
  font-size: 10px;
  opacity: 0.75;
}

/* ---------- Вид ---------- */

.view {
  padding: 0 var(--pad) var(--s5);
  animation: fade 0.2s var(--ease);
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s2);
  color: var(--text-mute);
  font-size: var(--t-small);
  margin: var(--s3) 0 var(--s3);
  min-height: 18px;
}

.meta button {
  padding: 2px 8px;
  font-size: var(--t-caption);
  color: var(--text-dim);
}

.section-title {
  font-size: var(--t-caption);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin: var(--s5) 0 var(--s2);
  font-weight: 700;
}

/* ---------- Сетка карточек ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--s3);
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: transform 0.14s var(--ease), border-color 0.16s var(--ease);
}

.card:active {
  transform: scale(0.985);
}

.card.signal {
  border-color: var(--gold-line);
}

.art {
  aspect-ratio: 1;
  background: linear-gradient(150deg, var(--surface-2), var(--surface-3));
  position: relative;
}

.art img,
.art .ph {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.art .ph {
  display: grid;
  place-items: center;
  color: var(--gold);
  font-size: 30px;
  opacity: 0.5;
}

.tag-row {
  position: absolute;
  left: var(--s2);
  top: var(--s2);
  right: var(--s2);
  display: flex;
  gap: 5px;
  align-items: flex-start;
  pointer-events: none;
}

.tag {
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.03em;
  border-radius: var(--r-sm);
  padding: 4px 7px;
  background: rgba(6, 7, 9, 0.78);
  backdrop-filter: blur(6px);
  color: var(--text);
  white-space: nowrap;
}

.tag.cls {
  margin-left: auto;
}

.tag.cls-M {
  background: var(--cls-m);
  color: var(--ink);
}
.tag.cls-B {
  background: var(--cls-b);
  color: var(--ink);
}
.tag.cls-R {
  background: var(--cls-r);
  color: #fff;
}
.tag.cls-C {
  background: var(--cls-c);
  color: var(--ink);
}

.tag.up {
  background: var(--up);
  color: var(--ink);
}

.card-body {
  padding: var(--s2) var(--s3) var(--s3);
}

.card-name {
  font-size: var(--t-body);
  font-weight: 700;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-sub {
  color: var(--text-mute);
  font-size: var(--t-caption);
  margin: 3px 0 var(--s2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.price {
  min-height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 750;
  font-size: var(--t-body);
}

.price.up {
  background: var(--gold);
  color: var(--ink);
}

.price small {
  font-size: var(--t-caption);
  font-weight: 650;
  opacity: 0.8;
}

/* ---------- Скелетоны ---------- */

.skeleton {
  border-radius: var(--r-lg);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 300% 100%;
  animation: shimmer 1.25s linear infinite;
}

.skeleton.card-sk {
  aspect-ratio: 0.78;
}

@keyframes shimmer {
  from {
    background-position: 150% 0;
  }
  to {
    background-position: -150% 0;
  }
}

/* ---------- Пустые состояния ---------- */

.empty {
  text-align: center;
  padding: var(--s6) var(--s4);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  grid-column: 1 / -1;
}

.empty-mark {
  font-size: 30px;
  opacity: 0.4;
  margin-bottom: var(--s2);
}

.empty h3 {
  margin: 0 0 var(--s1);
  font-size: var(--t-lead);
}

.hint {
  color: var(--text-mute);
  font-size: var(--t-small);
  line-height: 1.5;
  margin: 0;
}

.err {
  color: var(--down);
}

.more {
  width: 100%;
  margin: var(--s3) 0 var(--s2);
}

/* ---------- PnL ---------- */

.pnl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
  margin: var(--s3) 0 var(--s4);
}

.pnl > div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s3);
}

.pnl span {
  display: block;
  color: var(--text-mute);
  font-size: var(--t-caption);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.pnl b {
  font-size: var(--t-lead);
  display: block;
  margin-top: 3px;
}

.up-text {
  color: var(--up);
}
.down-text {
  color: var(--down);
}
.gold-text {
  color: var(--gold);
}

/* ---------- Таббар ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(8, 9, 11, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px var(--s2) calc(8px + env(safe-area-inset-bottom));
  max-width: 760px;
  margin: 0 auto;
}

.tabbar button {
  color: var(--text-mute);
  font-size: var(--t-caption);
  font-weight: 650;
  padding: 7px 4px;
  display: grid;
  gap: 3px;
  justify-items: center;
}

.tabbar .ic {
  font-size: 17px;
  line-height: 1;
}

.tabbar button.on {
  color: var(--gold);
}

/* ---------- Bottom sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.66);
  display: grid;
  align-items: end;
  animation: veil 0.18s var(--ease);
}

@keyframes veil {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.sheet-card {
  background: var(--surface);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  border-top: 1px solid var(--line-strong);
  padding: var(--s3) var(--pad) calc(var(--s4) + env(safe-area-inset-bottom));
  max-height: 93vh;
  overflow: auto;
  box-shadow: var(--shadow);
  animation: rise 0.24s var(--ease);
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}

@keyframes rise {
  from {
    transform: translateY(24px);
  }
  to {
    transform: none;
  }
}

.grabber {
  width: 38px;
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--line-strong);
  margin: 0 auto var(--s3);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s3);
  margin-bottom: var(--s3);
}

.sheet-head h2 {
  margin: 0;
  font-size: var(--t-title);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.sheet-head .sub {
  color: var(--text-mute);
  font-size: var(--t-small);
  margin-top: 2px;
}

.icon-x {
  font-size: var(--t-lead);
  color: var(--text-mute);
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: var(--r-pill);
  flex: none;
}

/* ---------- Блок плюса в карточке лота ---------- */

.verdict {
  border-radius: var(--r-lg);
  padding: var(--s4);
  margin-bottom: var(--s3);
  border: 1px solid var(--line);
  background: var(--surface-2);
}

.verdict.good {
  background: var(--up-dim);
  border-color: rgba(53, 208, 127, 0.4);
}

.verdict.bad {
  background: var(--down-dim);
  border-color: rgba(255, 95, 109, 0.32);
}

.verdict-top {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
}

.verdict-num {
  font-size: var(--t-hero);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

.verdict-label {
  font-size: var(--t-small);
  color: var(--text-dim);
}

.verdict-why {
  margin-top: var(--s2);
  font-size: var(--t-small);
  color: var(--text-dim);
  line-height: 1.5;
}

.math {
  display: grid;
  gap: 5px;
  margin-top: var(--s3);
  padding-top: var(--s3);
  border-top: 1px solid var(--line);
  font-size: var(--t-small);
}

.math div {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
}

.math span {
  color: var(--text-mute);
}

.math b {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.math .total b {
  color: var(--gold);
}

.conf-bar {
  height: 5px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
  margin-top: var(--s2);
}

.conf-bar i {
  display: block;
  height: 100%;
  background: var(--gold);
  border-radius: var(--r-pill);
  transition: width 0.3s var(--ease);
}

/* ---------- Пары ключ-значение ---------- */

.kv-group {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: var(--s3);
}

.kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s3);
  background: var(--surface-2);
  padding: 11px var(--s3);
  font-size: var(--t-body);
  border-bottom: 1px solid var(--line);
}

.kv:last-child {
  border-bottom: 0;
}

.kv span {
  color: var(--text-mute);
  font-size: var(--t-caption);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  flex: none;
}

.kv b {
  text-align: right;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: var(--s3);
}

.pills .tag {
  position: static;
  background: var(--surface-3);
  color: var(--text-dim);
}

/* ---------- Книги площадок ---------- */

.book {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--s3);
  margin-bottom: var(--s2);
}

.book.exit {
  border-color: var(--gold-line);
  background: var(--gold-dim);
}

.book-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: var(--t-body);
  margin-bottom: 6px;
}

.book-head .exit-flag {
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.05em;
  color: var(--gold);
}

.book-nums {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s2);
}

.book-nums div {
  text-align: center;
}

.book-nums span {
  display: block;
  color: var(--text-mute);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.book-nums b {
  font-size: var(--t-small);
  font-variant-numeric: tabular-nums;
}

/* ---------- Хронология ---------- */

.timeline {
  position: relative;
  padding-left: var(--s4);
  margin-bottom: var(--s3);
}

.timeline::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--line-strong);
}

.tl-row {
  position: relative;
  padding: var(--s2) 0;
}

.tl-row::before {
  content: "";
  position: absolute;
  left: calc(-1 * var(--s4) + 1px);
  top: 15px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-mute);
}

.tl-row.hot::before {
  background: var(--gold);
}

.tl-top {
  display: flex;
  justify-content: space-between;
  gap: var(--s2);
  font-size: var(--t-body);
}

.tl-top b {
  font-variant-numeric: tabular-nums;
}

.tl-sub {
  color: var(--text-mute);
  font-size: var(--t-caption);
  margin-top: 2px;
}

/* ---------- Воронка ---------- */

.funnel {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: var(--s4);
}

.fn-row {
  padding: 10px var(--s3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

.fn-row:last-child {
  border-bottom: 0;
}

.fn-top {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  font-size: var(--t-small);
  margin-bottom: 5px;
}

.fn-top b {
  font-variant-numeric: tabular-nums;
  flex: none;
}

.fn-bar {
  height: 4px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}

.fn-bar i {
  display: block;
  height: 100%;
  background: var(--info);
  border-radius: var(--r-pill);
}

/* ---------- Кнопки действий ---------- */

.cta {
  display: grid;
  gap: var(--s2);
  margin-top: var(--s4);
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(18, 20, 26, 0) 0%, var(--surface) 34%);
  padding-top: var(--s3);
}

.cta .primary,
.cta .ghost {
  min-height: 48px;
  font-size: var(--t-body);
}

.cta-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

/* ---------- Формы ---------- */

label {
  display: block;
  font-size: var(--t-caption);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-mute);
  margin: var(--s3) 0;
  font-weight: 650;
}

input,
select {
  width: 100%;
  margin-top: 6px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px var(--s3);
  font: inherit;
  text-transform: none;
  letter-spacing: normal;
  outline: none;
  transition: border-color 0.16s var(--ease);
}

input:focus,
select:focus {
  border-color: var(--gold-line);
}

/* ---------- Аккордеон фильтров ---------- */

.acc {
  border-bottom: 1px solid var(--line);
}

.acc-h {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--s4) 0;
  font-size: var(--t-caption);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.acc-h .caret {
  transition: transform 0.18s var(--ease);
  color: var(--text-mute);
}

.acc.open .acc-h {
  color: var(--gold);
}

.acc.open .acc-h .caret {
  transform: rotate(180deg);
}

.acc-b {
  display: none;
  padding-bottom: var(--s3);
  max-height: 46vh;
  overflow: auto;
}

.acc.open .acc-b {
  display: block;
  animation: fade 0.18s var(--ease);
}

.pick label {
  display: flex;
  gap: var(--s3);
  align-items: center;
  color: var(--text);
  font-size: var(--t-body);
  text-transform: none;
  letter-spacing: normal;
  padding: 11px 0;
  margin: 0;
  border-bottom: 1px solid var(--line);
  font-weight: 550;
}

.pick label:last-child {
  border-bottom: 0;
}

.pick input {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: none;
  accent-color: var(--gold);
}

.pick .aside {
  margin-left: auto;
  color: var(--text-mute);
  font-size: var(--t-caption);
  font-variant-numeric: tabular-nums;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s2);
}

.sheet-actions {
  display: flex;
  gap: var(--s2);
  margin-top: var(--s4);
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(18, 20, 26, 0) 0%, var(--surface) 34%);
  padding-top: var(--s3);
}

.sheet-actions .ghost,
.sheet-actions .primary {
  flex: 1;
  min-height: 48px;
}

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--r-pill);
  padding: 11px var(--s4);
  font-size: var(--t-small);
  font-weight: 600;
  box-shadow: var(--shadow);
  max-width: calc(100% - 2 * var(--pad));
  animation: toast-in 0.22s var(--ease);
}

.toast.ok {
  border-color: rgba(53, 208, 127, 0.5);
}

.toast.err {
  border-color: rgba(255, 95, 109, 0.5);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 10px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.credit {
  font-size: var(--t-caption);
  color: var(--text-mute);
  margin-top: var(--s5);
  line-height: 1.5;
  text-align: center;
}

@media (min-width: 560px) {
  .grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
