/* Цвета берутся из темы Telegram: приложение подхватывает светлую или тёмную
   схему пользователя и не навязывает свою. Значения после запятой — запасные,
   на случай открытия вне Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #1a1a1a);
  --muted: var(--tg-theme-hint-color, #8a8f98);
  --card: var(--tg-theme-secondary-bg-color, #f4f4f6);
  --accent: var(--tg-theme-button-color, #2f81f7);
  --accent-fg: var(--tg-theme-button-text-color, #ffffff);
  --good: #1a7f37;

  /* Быстрый старт, мягкое торможение: линейная кривая выглядит механической */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --fast: 160ms;
  --slow: 280ms;

  /* Тени вместо границ: они ложатся на любой фон, а сплошная линия
     на тёмной теме выглядит грязной */
  --lift: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 12px 12px 32px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-wrap: pretty;
}

h1, h2 {
  font-size: 18px;
  margin: 0 0 2px;
  font-weight: 650;
  text-wrap: balance;
}

.muted { color: var(--muted); font-size: 13px; margin: 0; }
.is-hidden { display: none !important; }

/* Экран появляется сдвигом и прозрачностью — оба свойства обрабатываются
   композитором и не вызывают пересчёта вёрстки */
.screen { animation: screen-in var(--slow) var(--ease) both; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.head { display: flex; flex-direction: column; gap: 2px; margin-bottom: 14px; }

/* Зона касания не меньше 40px по высоте, иначе попасть трудно */
.back {
  align-self: flex-start;
  min-height: 40px;
  padding: 8px 12px 8px 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 15px;
  cursor: pointer;
  transition: opacity var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.back:active { opacity: 0.6; transform: scale(0.96); }

.controls { display: flex; gap: 8px; margin-bottom: 12px; }

#search, #sort {
  min-height: 44px;
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: var(--card);
  color: var(--fg);
  font-size: 15px;
  font-family: inherit;
}
#search { flex: 1 1 auto; min-width: 0; }
#sort { flex: 0 0 auto; max-width: 42%; padding-right: 8px; }

.list { display: flex; flex-direction: column; gap: 8px; }

/* Внешний радиус 14 = внутренний 8 + отступ 6: вложенные скруглeния
   должны быть концентрическими, иначе углы выглядят смазанными */
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--lift);
  cursor: pointer;
  /* только transform и opacity — остальное вызывает reflow */
  transition: transform var(--fast) var(--ease), opacity var(--fast) var(--ease);
  animation: row-in var(--slow) var(--ease) both;
}
/* Отклик на касание обязателен: без него интерфейс кажется сломанным */
.row:active { transform: scale(0.96); }

@keyframes row-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* Каскад читается как одно движение. Дальше десятой строки задержка
   превращается в ожидание, поэтому ограничиваем. */
.row:nth-child(1)  { animation-delay: 0ms; }
.row:nth-child(2)  { animation-delay: 25ms; }
.row:nth-child(3)  { animation-delay: 50ms; }
.row:nth-child(4)  { animation-delay: 75ms; }
.row:nth-child(5)  { animation-delay: 100ms; }
.row:nth-child(6)  { animation-delay: 125ms; }
.row:nth-child(7)  { animation-delay: 150ms; }
.row:nth-child(8)  { animation-delay: 175ms; }
.row:nth-child(9)  { animation-delay: 200ms; }
.row:nth-child(10) { animation-delay: 225ms; }

.row-name {
  /* flex: 1 обязателен: без него длинное название распирает строку
     и выталкивает цену за край экрана */
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-seller {
  color: var(--muted);
  font-size: 12px;
  white-space: normal;
}
/* Цены обновляются на месте: моноширинные цифры не дают строке дёргаться */
.row-price {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}
.row-price.is-low { color: var(--good); }

/* Скелет держит ту же высоту, что и будущая строка: без этого список
   дёргается при загрузке и попасть пальцем невозможно */
.skeleton {
  height: 56px;
  border-radius: 14px;
  background: var(--card);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(127, 127, 127, 0.12), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

.chart {
  height: 260px;
  margin: 4px 0 14px;
  animation: screen-in var(--slow) var(--ease) both;
}

/* Своя легенда: встроенная в uPlot накладывается на кнопки периодов */
.legend {
  display: flex;
  gap: 16px;
  margin: 0 0 14px 2px;
  color: var(--muted);
  font-size: 12px;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.mark { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }
.mark-seed {
  background: repeating-linear-gradient(90deg, #9aa4b2 0 4px, transparent 4px 7px);
}
.mark-live { background: var(--accent); height: 3px; }

.periods { display: flex; gap: 6px; margin-bottom: 16px; }
.periods button {
  flex: 1;
  min-height: 40px;
  padding: 10px 4px;
  border: none;
  border-radius: 11px;
  background: var(--card);
  color: var(--fg);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: transform var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
.periods button:active { transform: scale(0.96); }
.periods button.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  box-shadow: var(--lift);
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
}
.stat {
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--lift);
  animation: row-in var(--slow) var(--ease) both;
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value {
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.wide {
  width: 100%;
  min-height: 48px;
  padding: 13px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  box-shadow: var(--lift);
  transition: transform var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
.wide:active { transform: scale(0.96); }

.section {
  margin: 22px 0 2px;
  font-size: 14px;
  font-weight: 650;
  color: var(--fg);
}
.section-note { margin: 0 0 10px; }

/* Неподтверждённые кандидаты приглушены: иначе они выглядят
   равноправными с проверенными предложениями */
.row.is-maybe {
  opacity: 0.72;
  box-shadow: none;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 36px 16px;
  text-wrap: pretty;
}

.banner {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 10px 10px 14px;
  margin-bottom: 12px;
  border-radius: 14px;
  background: #d9342b;
  color: #fff;
  box-shadow: var(--lift);
  animation: screen-in var(--fast) var(--ease) both;
}
.banner button {
  min-height: 36px;
  padding: 8px 14px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: transform var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
.banner button:active { transform: scale(0.96); }

/* Для части людей движение на экране вызывает тошноту и головокружение.
   Системную настройку уважаем без исключений. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
