/**
 * Веб-клиент «Горячих Скидок».
 *
 * Палитры повторяют мобильное приложение (mobile/src/theme.ts): одна и та же
 * светлая и тёмная схема, поэтому веб и приложение выглядят одинаково.
 * Тема переключается атрибутом data-theme на <html>.
 */

:root {
  --accent: #ff5a1f;
  --accent-soft: #ffede6;
  --accent-contrast: #ffffff;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f2f4f7;
  --text: #111827;
  --muted: #6b7280;
  --faint: #9ca3af;
  --border: #e5e7eb;
  --skeleton: #e8edf3;
  --toast-bg: #111827;
  --toast-text: #ffffff;
  --benefit: #059669;
  --benefit-soft: #e6f4ee;
  --topbar-bg: rgba(245, 246, 248, 0.88);
  --radius-card: 18px;
  --radius-media: 12px;
  --radius-badge: 8px;
  --radius-pill: 999px;
  --shadow-card: 0 6px 16px rgba(15, 23, 42, 0.06);
  --shadow-floating: 0 4px 14px rgba(15, 23, 42, 0.18);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --accent-soft: #3a2018;
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-muted: #262a34;
  --text: #f9fafb;
  --muted: #9ca3af;
  --faint: #6b7280;
  --border: #2e333f;
  --skeleton: #242833;
  --toast-bg: #f9fafb;
  --toast-text: #0f1115;
  --benefit: #34d399;
  --benefit-soft: #1b3a2f;
  --topbar-bg: rgba(15, 17, 21, 0.88);
  --shadow-card: 0 6px 18px rgba(0, 0, 0, 0.35);
  --shadow-floating: 0 4px 14px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Атрибут hidden должен побеждать display из классов (.promo, .viewer) */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  transition: background-color 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

button { font-family: inherit; }

/* --- Шапка канала -------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 8px 16px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar__row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
}

/* Строка фильтров: в приложении она тоже под шапкой канала. */
.topbar__filters {
  display: flex;
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  border-radius: var(--radius-media);
  -webkit-tap-highlight-color: transparent;
}

.brand:active { opacity: 0.7; }

.brand__avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface-muted);
  flex: 0 0 42px;
}

.brand__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand__title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand__subtitle {
  font-size: 12px;
  color: var(--muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.icon-button:active { background: var(--surface-muted); }

/* --- Поиск и фильтр «Избранное» ------------------------------------------ */
.search-shell {
  display: none;
  position: relative;
  flex: 1;
  min-width: 0;
}

.search {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}

.search::placeholder { color: var(--faint); }

.search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search__clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--faint);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}

.search__clear:active { background: var(--surface-muted); }

/* Поиск раскрывается вместо названия канала — как анимация в мобильной шапке. */
.topbar--search .brand { display: none; }
.topbar--search .search-shell { display: block; }
.topbar--search #refresh-button { display: none; }

.filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.filter__icon { flex: 0 0 16px; }

.filter--active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 800;
}

.filter--active .filter__icon { fill: currentColor; }

.filter__badge {
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.filter--active .filter__badge {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* --- Баннеры ------------------------------------------------------------- */
.banner {
  width: calc(100% - 32px);
  max-width: 688px;
  margin: 10px auto 0;
  padding: 10px 14px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.banner--offline { background: var(--accent-soft); color: var(--accent); }
.banner--error { background: var(--accent-soft); color: var(--accent); }

/* --- Лента --------------------------------------------------------------- */
/* Одна колонка и та же ширина 720 px, что в мобильном приложении. */
.feed {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  padding: 12px 16px 8px;
}

.skeletons {
  display: grid;
  gap: 12px;
}

/* --- Компактная карточка -------------------------------------------------- */
.card {
  display: flex;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.card__media {
  position: relative;
  flex: 0 0 100px;
  width: 100px;
  min-height: 105px;
  align-self: stretch;
  padding: 0;
  border: 0;
  border-radius: var(--radius-media);
  background: var(--surface-muted);
  overflow: hidden;
  cursor: zoom-in;
}

.card__media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card__media--empty {
  cursor: default;
  background: var(--accent-soft);
}

.card__media--empty img { display: none; }

.card__media--empty::after {
  content: "%";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 800;
  color: var(--accent);
}

.card__media--empty .card__expand { display: none; }

.card__expand {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: rgba(17, 24, 39, 0.55);
  color: #ffffff;
  font-size: 10px;
  font-weight: 700;
  pointer-events: none;
}

.card__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card__shop {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card__time {
  margin-left: auto;
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
}

/* Сердце в правом верхнем углу карточки — как в мобильном DealCard. */
.card__fav {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.card__fav svg { fill: none; stroke: currentColor; stroke-width: 2; }

.card__fav--active {
  background: var(--accent-soft);
  color: var(--accent);
}

.card__fav--active svg { fill: currentColor; }

.card__fav:active { opacity: 0.7; }

.card__title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 20px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card__description {
  margin: 0;
  font-size: 13px;
  line-height: 18px;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-line;
}

/* Цена одна — в мобильной карточке старой цены нет. */
.card__price {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.promo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  margin-top: 2px;
  padding: 5px 12px;
  border: 1px dashed var(--accent);
  border-radius: var(--radius-badge);
  background: var(--accent-soft);
  color: var(--text);
  cursor: pointer;
}

.promo__label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--muted);
}

.promo__code {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.6px;
  color: var(--accent);
}

.promo--copied { border-color: var(--benefit); background: var(--benefit-soft); }
.promo--copied .promo__label { color: var(--benefit); }
.promo--copied .promo__code { color: var(--benefit); }

.card__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.action--icon {
  width: 34px;
  padding: 0;
  flex: 0 0 34px;
}

.action--primary {
  flex: 1;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 800;
}

.action:active { opacity: 0.75; }

/* --- Хвост ленты: автоподгрузка и статусы -------------------------------- */
.feed-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  padding: 4px 16px 8px;
}

/** Пиксель-«сторож»: IntersectionObserver догружает следующую страницу. */
.feed-sentinel {
  width: 100%;
  height: 1px;
}

.feed-status { margin: 0; color: var(--faint); font-size: 12px; text-align: center; }

.footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
  max-width: 720px;
  margin-inline: auto;
  padding: 20px 16px calc(28px + env(safe-area-inset-bottom));
  color: var(--faint);
  font-size: 12px;
  text-align: center;
}

.footer p { margin: 0; max-width: 42ch; }
.footer a { color: var(--text); }
.footer__links { display: flex; gap: 10px; }

/* --- Заглушки ------------------------------------------------------------ */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 48px 24px;
  text-align: center;
}

.empty__emoji { font-size: 44px; line-height: 1; }

.empty__title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.empty__message {
  margin: 0;
  max-width: 34ch;
  font-size: 14px;
  line-height: 20px;
  color: var(--muted);
}

.empty__action {
  margin-top: 8px;
  padding: 12px 24px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.empty__action:active { opacity: 0.85; }

/* --- Заглушки и уведомления --------------------------------------------- */
.skeleton {
  height: 130px;
  border-radius: var(--radius-card);
  background: var(--skeleton);
  animation: shimmer 1.4s infinite ease-in-out;
}

@keyframes shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: var(--radius-pill);
  background: var(--toast-bg);
  color: var(--toast-text);
  box-shadow: var(--shadow-floating);
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast--visible { opacity: 1; transform: translate(-50%, 0); }

/* --- Полноэкранный просмотр фото ---------------------------------------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.92);
  animation: viewer-in 0.18s ease-out;
}

@keyframes viewer-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.viewer__backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-out;
}

.viewer__image {
  position: relative;
  width: 100%;
  height: 80%;
  padding: 0 16px;
  object-fit: contain;
}

.viewer__close {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top));
  right: 16px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.viewer__close:focus-visible,
.icon-button:focus-visible,
.filter:focus-visible,
.card__fav:focus-visible,
.empty__action:focus-visible,
.search__clear:focus-visible,
.action:focus-visible,
.promo:focus-visible,
.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .toast { transition: none; }
  .viewer { animation: none; }
  body { transition: none; }
  .filter, .card__fav { transition: none; }
}
